.today-entry-toolbar { display: flex; align-items: center; gap: 12px; margin: 14px 0; }
.today-entry-switch { display: flex; gap: 8px; margin: 0; flex: none; }
.today-entry-toolbar #todaySearch { flex: 1; width: auto; min-width: 0; min-height: 44px; padding: 10px 14px; border-radius: 10px; }
#todayStaffLegend[hidden], .today-entry-toolbar #todaySearch[hidden] { display: none; }
@media(max-width: 600px) { .today-entry-toolbar { flex-wrap: wrap; gap: 8px; } .today-entry-toolbar #todaySearch { flex-basis: 100%; } }
.today-entry-switch button { min-height: 44px; padding: 9px 16px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: #334155; font: inherit; font-weight: 600; }
.today-entry-switch button[aria-pressed="true"] { color: #fff; border-color: #1d4ed8; background: #1d4ed8; }
.today-entry-switch button:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
.visitor-list-note { color: #475569; font-size: 14px; line-height: 1.5; }
.today-visitors-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 14px; }
.visitor-record, .visitor-view-auth { min-width: 0; border: 1px solid #dbe3ed; border-radius: 12px; padding: 18px; background: #fff; }
.visitor-record header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.visitor-record h3 { margin: 0; color: #17243a; font-size: 17px; line-height: 1.4; font-weight: 700; overflow-wrap: anywhere; }
.visitor-record time { flex-shrink: 0; font-size: 14px; color: #475569; font-variant-numeric: tabular-nums; }
.visitor-type-label { display: inline-block; padding: 3px 9px; border-radius: 6px; background: #eaf3ff; color: #174c89; font-size: 12px; font-weight: 600; }
.visitor-record dl { margin: 14px 0 0; }
.visitor-record dt { margin-top: 12px; color: #475569; font-size: 12px; font-weight: 600; }
.visitor-record dd { margin: 3px 0 0; color: #17243a; font-size: 16px; line-height: 1.5; overflow-wrap: anywhere; }
.visitor-list-message { margin: 0; padding: 20px; border: 1px solid #dbe3ed; border-radius: 12px; color: #475569; }
.visitor-view-auth { max-width: 480px; margin-bottom: 16px; }
.visitor-view-auth label { display: block; margin-bottom: 8px; font-weight: 600; }
.visitor-view-auth input { font-size: 16px; }
.visitor-view-auth button { min-height: 44px; margin-top: 12px; }

/* Compact records for touch screens; desktop retains its full table. */
@media (max-width: 1023px) {
    #historyDetailsSection, #todayAttendance .today-table-shell {
        width: 100%; max-width: 100%; height: auto; min-height: 0; max-height: none;
        overflow: visible; border: 0; border-radius: 0; padding-bottom: 0;
    }
    #todayAttendance { height: auto; min-height: 0; max-height: none; overflow: visible; }
    #todayAttendance .today-table-shell::after { display: none; }
    .attendance-adaptive-table, #todayTable { display: block; width: 100%; min-width: 0; margin-bottom: 0; }
    .attendance-adaptive-table thead {
        position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
        overflow: hidden; clip-path: inset(50%); white-space: nowrap;
    }
    .attendance-adaptive-table tbody { display: grid; gap: 14px; }
    .attendance-adaptive-table tbody tr {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 4px 16px; padding: 16px; border: 1px solid #dbe3ed;
        border-radius: 12px; background: #fff;
    }
    .attendance-adaptive-table tbody tr.table-warning,
    #todayTable tbody tr.half-day { background: #fffbeb; border-color: #eadcb2; }
    .attendance-adaptive-table tbody tr.table-success { background: #f0fdf4; border-color: #b9d9c5; }
    #todayTable tbody tr.short-shift { background: #fff7f7; border-color: #edc9ce; }
    /* Desktop colours each table cell; mobile uses one quiet card surface. */
    #todayBody tr.half-day > td,
    #todayBody tr.short-shift > td {
        background-color: transparent !important;
        color: #17243a;
    }
    .attendance-adaptive-table tbody td,
    #todayTable tbody td {
        display: block; min-width: 0 !important; max-width: none !important;
        width: auto; height: auto; border: 0 !important; padding: 8px 0;
        background: transparent !important; box-shadow: none !important;
        white-space: normal !important; overflow-wrap: anywhere;
        text-align: left !important; font-size: 16px; line-height: 1.45;
        font-variant-numeric: tabular-nums;
    }
    .attendance-adaptive-table tbody td::before {
        content: attr(data-label); display: block; margin-bottom: 3px;
        color: #475569; font-size: 12px; font-weight: 600; line-height: 1.4;
    }
    .attendance-adaptive-table tbody td[data-field="day"] { display: none; }
    .attendance-adaptive-table tbody td[data-field="date"],
    .attendance-adaptive-table tbody td[data-field="staff-name"] {
        order: -2; font-weight: 700; padding-top: 0; padding-bottom: 12px;
    }
    .attendance-adaptive-table tbody td[data-field="date"]::before { content: attr(data-weekday); }
    .attendance-adaptive-table tbody td[data-field="staff-name"]::before { display: none; }
    .attendance-adaptive-table tbody td[data-field="status"] {
        order: -1; text-align: right !important; padding-top: 0; padding-bottom: 12px;
        align-self: center;
    }
    .attendance-adaptive-table tbody td[data-field="status"]::before { display: none; }
    #todayTable tbody td[data-field="status"] { text-align: right !important; }
    .attendance-adaptive-table tbody td[data-field="status"] .status-badge { white-space: normal; line-height: 1.4; }
    .attendance-adaptive-table tbody td[data-field="remark"],
    .attendance-adaptive-table tbody td[data-field="reason"],
    .attendance-adaptive-table tbody td[data-field="location"] { grid-column: 1 / -1; }
    .attendance-adaptive-table tbody td[data-field="remark"],
    .attendance-adaptive-table tbody td[data-field="reason"] { border-top: 1px solid #e2e8f0 !important; margin-top: 4px; }
    .attendance-adaptive-table tbody td[data-field="remark"][data-empty="true"],
    .attendance-adaptive-table tbody td[data-field="reason"][data-empty="true"],
    .attendance-adaptive-table tbody td[data-field="location"][data-empty="true"] { display: none; }
    #todayTable tbody td[data-field="location"][data-empty="true"],
    #todayTable tbody td[data-field="remark"][data-empty="true"] { display: none; }
    .attendance-adaptive-table tbody .attendance-record-message { display: block; padding: 20px; }
    .attendance-adaptive-table tbody .attendance-record-message td::before { display: none; }
    .attendance-adaptive-table tfoot {
        display: block; margin-top: 20px; padding: 14px 16px;
        border-radius: 12px; background: #f2f6fb;
    }
    .attendance-adaptive-table tfoot tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; }
    .attendance-adaptive-table tfoot th, .attendance-adaptive-table tfoot td {
        display: block; min-width: 0; max-width: none; border: 0;
        background: transparent; padding: 7px 0; white-space: normal;
        font-size: 15px; text-align: left;
    }
    .attendance-adaptive-table tfoot td[colspan] { display: none; }
    .attendance-adaptive-table tfoot .history-staff-name { grid-column: 1 / -1; padding-bottom: 10px; font-weight: 700; }
    .attendance-adaptive-table tfoot tr:last-child { border-top: 1px solid #cbd5e1; margin-top: 6px; padding-top: 6px; }
    .attendance-adaptive-table tfoot tr:last-child td { font-weight: 700; }
}

@media (max-width: 767px) {
    .main-card, #attendanceHistoryCard, .active-qr-card, #notificationArea {
        width: 100%; max-width: 100%; margin-inline: auto;
    }
    .main-card { padding: 24px 18px; margin-block: 20px; }
    #attendanceHistoryCard { padding: 20px 16px; margin-block: 24px; }
    .active-qr-card { margin-block: 16px 24px; }
    .active-qr-heading, .active-qr-toggle { min-width: 0; }
    .active-qr-heading small { font-size: 12px; }
    .active-qr-toggle { gap: 4px; font-size: 12px; }
    #clock { font-size: clamp(27px, 7vw, 36px); }
    .history-toolbar { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
    .history-toolbar > * { width: 100% !important; min-width: 0; min-height: 44px; margin: 0; }
    .history-toolbar > select, .history-toolbar > input { grid-column: span 3; font-size: 16px; }
    .history-toolbar > input { border-radius: 10px; padding: 10px; }
    .history-toolbar > button { grid-column: span 2; padding-inline: 6px; font-size: 14px; }
    #attendanceHistoryCard .nav-link, #showDetailsBtn, #ruleButton { min-height: 44px; }
    .summary-card { min-width: 0; min-height: 112px; padding: 12px !important; }
    .summary-card-heading { align-items: flex-start; min-width: 0; }
    .summary-card-heading small { min-width: 0; overflow-wrap: anywhere; font-size: 12px; }
    .summary-card > small { font-size: 12px; }
    .summary-card strong { font-size: 20px; }
    .summary-info-button { width: 28px; height: 28px; flex-basis: 28px; margin-top: -3px; }
    .today-date-navigation { gap: 8px; }
    .today-date-navigation .btn { width: 44px; height: 44px; }
    #todaySelectedDate { min-width: 0; flex: 1; font-size: 15px; white-space: normal; }
    .status-legend { justify-content: flex-start !important; }
    .status-legend .status-badge { white-space: normal; text-align: left; }
    .pending-checkout-notice, #pendingCheckoutNotice { max-width: 100%; white-space: normal; }
    #employeeInput, .modal .form-control, #todaySearch { min-width: 0; font-size: 16px; }
    .secondary-actions .secondary-action-btn { min-width: 0; min-height: 48px; }
    .toast-container { max-width: calc(100vw - 24px); }
}
#myHistory:not(.show-arrival-time) .history-arrival-column { display: none !important; }
#todayTable:not(.show-arrival-time) .today-arrival-column { display: none !important; }

@media (max-width: 767px) {
    #myHistory .attendance-adaptive-table tbody { gap: 8px; }
    #myHistory .attendance-adaptive-table tbody tr {
        padding: 10px 12px; gap: 2px 8px; border-radius: 10px;
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
    #myHistory .attendance-adaptive-table tbody td {
        padding: 4px 0; font-size: 15px; line-height: 1.35;
    }
    #myHistory .attendance-adaptive-table tbody td::before {
        margin-bottom: 3px; font-size: 10px; line-height: 1.3;
    }
    #myHistory .attendance-adaptive-table tbody td[data-field="date"],
    #myHistory .attendance-adaptive-table tbody td[data-field="status"] {
        padding-top: 0; padding-bottom: 5px;
        grid-column: span 2;
    }
    #myHistory .attendance-adaptive-table tbody td[data-field="check-in"],
    #myHistory .attendance-adaptive-table tbody td[data-field="check-out"],
    #myHistory .attendance-adaptive-table tbody td[data-field="working-hours"],
    #myHistory .attendance-adaptive-table tbody td[data-field="leave-hours"] {
        grid-column: span 1; font-size: 14px; font-variant-numeric: tabular-nums;
        overflow-wrap: normal;
    }
    .attendance-adaptive-table .attendance-time-period { font-size: .75em; font-weight: 400; }
    #myHistory .attendance-adaptive-table tbody td[data-field="check-in"],
    #myHistory .attendance-adaptive-table tbody td[data-field="check-out"] { white-space: nowrap; }
    #myHistory .attendance-adaptive-table tbody td[data-field="arrival-time"],
    #myHistory .attendance-adaptive-table tbody td[data-field="location"],
    #myHistory .attendance-adaptive-table tbody td[data-field="remark"],
    #myHistory .attendance-adaptive-table tbody td[data-field="reason"] { grid-column: 1 / -1; }
    #myHistory .attendance-adaptive-table tbody td[data-field="remark"],
    #myHistory .attendance-adaptive-table tbody td[data-field="reason"] {
        margin-top: 3px; padding-top: 5px; padding-bottom: 0;
    }
    #myHistory .attendance-adaptive-table tbody td[data-field="status"] .status-badge {
        padding: 3px 8px; font-size: 11px;
    }
}

#todayStaffLegend .status-badge > span::before { content: ' · '; }
/* Keep the phone legend orderly and daily records compact without hiding fields. */
@media (max-width: 767px) {
    #staffSignOut { text-align: center; -webkit-appearance: none; appearance: none; }
    #staffSignOut span { display: block; text-align: center; }
    #todayStaffLegend {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px; margin-bottom: 12px;
    }
    #todayStaffLegend .status-badge {
        display: block; padding: 9px 10px; border-radius: 8px;
        font-size: 12px; line-height: 1.45; white-space: normal;
        background: #f8fafc; border: 1px solid #e2e8f0; color: #475569;
    }
    #todayStaffLegend .status-badge strong { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #17243a; margin-bottom: 2px; }
    #todayStaffLegend .status-badge strong::before { content: ''; width: 7px; height: 7px; border-radius: 50%; flex: none; background: #64748b; }
    #todayStaffLegend .status-full-day strong::before { background: #248469; }
    #todayStaffLegend .status-short-shift strong::before { background: #c94353; }
    #todayStaffLegend .status-half-day strong::before { background: #c37b12; }
    #todayStaffLegend .status-no-work strong::before { background: #c37b12; }
    #todayStaffLegend .status-open strong::before { background: #0891b2; }
    #todayStaffLegend .status-full-day { background: #d1e7dd; border-color: #c2ddcf; }
    #todayStaffLegend .status-short-shift { background: #f8d7da; border-color: #efc7ce; }
    #todayStaffLegend .status-half-day,
    #todayStaffLegend .status-no-work { background: #ffe5b4; border-color: #f2d59e; }
    #todayStaffLegend .status-neutral { background: #e2e8f0; border-color: #d4dde8; }
    #todayStaffLegend .status-open { background: #cff4fc; border-color: #bce8f2; }
    #todayStaffLegend .status-badge > span { display: block; font-weight: 400; padding-left: 13px; }
    #todayStaffLegend .status-badge > span::before { content: none; }
    #todayTable tbody { gap: 8px; }
    #todayTable tbody tr { padding: 12px; gap: 2px 10px; grid-template-columns: repeat(6, minmax(0, 1fr)); }
    #todayTable tbody td { grid-column: span 2; }
    #todayTable tbody td[data-field="staff-name"] { grid-column: span 4; }
    #todayTable tbody td[data-field="status"] { grid-column: span 2; }
    #todayTable tbody td[data-field="arrival-time"],
    #todayTable tbody td[data-field="remark"],
    #todayTable tbody td[data-field="reason"],
    #todayTable tbody td[data-field="location"] { grid-column: 1 / -1; }
    #todayTable tbody td { padding: 4px 0; font-size: 15px; line-height: 1.35; }
    #todayTable tbody td[data-field="check-in"],
    #todayTable tbody td[data-field="check-out"],
    #todayTable tbody td[data-field="working-hours"] {
        font-family: inherit; font-size: 15px !important; font-weight: 400;
        line-height: 1.4; font-variant-numeric: tabular-nums;
    }
    #todayTable tbody td::before { font-size: 11px; margin-bottom: 2px; }
    #todayTable tbody td[data-field="staff-name"],
    #todayTable tbody td[data-field="status"] { padding-bottom: 6px; }
    #todayTable tbody td[data-field="staff-name"] { font-size: 16px; }
    #todayTable tbody td[data-field="remark"],
    #todayTable tbody td[data-field="reason"] { margin-top: 3px; padding-top: 6px; }
    #todayTable tbody td[data-field="status"] .status-badge { font-size: 11px; padding: 3px 8px; }
}
