/* resp-salary-attendance — responsive layout for the attendance pages. Loaded after app.css.
   Covers: Attendance (month sheet + day list), AttendanceImport wizard, AttendanceCodes (+ dialog), Devices.
   Mobile-first breakpoints used: 640px (phones), 900px (tablets), 1200px (small desktops). */

/* ═════════════ Attendance page: filter card ═════════════ */
.ap-filters { min-width: 0; }
.ap-filters .rz-form-field { min-width: 0; }

@media (max-width: 640px) {
    .ap-filters { gap: 0.6rem !important; }
    /* date pickers / dropdowns share rows two by two, buttons fill their own row */
    .ap-filters > .rz-form-field { flex: 1 1 calc(50% - 0.6rem); }
    .ap-filters .rz-form-field .rz-dropdown,
    .ap-filters .rz-form-field .rz-datepicker { width: 100% !important; min-width: 0 !important; }
    .ap-filters > .rz-button { flex: 1 1 calc(50% - 0.6rem); min-height: 2.6rem; }
    .ap-filters > .ap-spacer { display: none; }
    .ap-filters > .rz-selectbar { flex: 1 1 100%; display: flex; }
    .ap-filters > .rz-selectbar .rz-button { flex: 1 1 0; min-height: 2.6rem; justify-content: center; white-space: nowrap; font-size: 0.74rem; padding-inline: 0.4rem; letter-spacing: 0; }
}

/* ═════════════ Month sheet (AttendanceSheetEditor) ═════════════ */
.att { min-width: 0; }
.att-scroll { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
/* wide screens: the table stretches over the card instead of leaving a gap on the right */
.att-table { min-width: 100%; }
.att-bar { row-gap: 0.5rem; }
.att-help kbd { color: inherit; background: var(--bg-base); }
.att-month__label { min-width: 8.5rem; }
/* the theme's "light" text buttons are near-white on a white card: make them readable */
.att .att-month .rz-button.rz-variant-text.rz-light { color: var(--brand-primary); font-weight: 700; }
.ap-filters .rz-button.rz-variant-text.rz-light { color: var(--text-secondary); font-weight: 600; }
.att .att-month .rz-button.rz-variant-text.rz-light:disabled, .ap-filters .rz-button.rz-variant-text.rz-light:disabled { opacity: 0.45; }

/* tablets and below: roomier cells, fewer sticky columns so the days stay visible */
@media (max-width: 900px) {
    .att-no { display: none; }
    .att-ecode { left: 0; }
    .att-ename { left: 3.6rem; min-width: 9rem; }
    .att-day { min-width: 2.5rem; }
    .att-cell { min-width: 2.5rem; height: 2.5rem; font-size: 0.82rem; }
    .att-cell.is-long { font-size: 0.64rem; }
    .att-tot { min-width: 2.4rem; }
}

@media (max-width: 640px) {
    .att { padding: 0.5rem; gap: 0.5rem; }

    /* toolbar: month nav on its own row, full-width search, then the save bar */
    .att-bar { gap: 0.5rem; }
    .att-month { flex: 1 1 100%; flex-wrap: nowrap; gap: 0.35rem; }
    .att-month__label { flex: 1 1 auto; min-width: 0; font-size: 0.95rem; white-space: nowrap; }
    .att-month .rz-button { min-height: 2.6rem; min-width: 2.6rem; flex: 0 0 auto; }
    .att-month .rz-button.rz-variant-text { padding-inline: 0.5rem; }
    .att-search { flex: 1 1 100%; width: 100%; min-height: 2.6rem; font-size: 1rem; }
    .att-spacer { display: none; }
    .att-bar > .rz-button { min-height: 2.6rem; }
    .att-bar > .rz-button:last-child { flex: 1 1 9rem; }
    .att-bar > .att-chip { min-height: 2.6rem; padding: 0.3rem 0.9rem; }

    /* palette: code-only chips (full name stays in the tooltip), tappable size */
    .att-palette { gap: 0.4rem; }
    .att-palette__label { flex: 1 1 100%; margin: 0; }
    .att-code { min-height: 2.6rem; padding: 0.2rem 0.45rem; }
    .att-code__text { min-width: 2.2rem; padding: 0.25rem 0.5rem; }
    .att-code__label { display: none; }
    .att-code--legend { min-height: 0; }
    .att-code--legend .att-code__label { display: inline; }
    .att-typed { margin-left: 0; }

    /* the sheet: only the name column is sticky, narrow enough to leave room for days */
    .att-scroll { max-height: 72vh; border-radius: 8px; }
    .att-ecode { display: none; }
    .att-ename {
        left: 0; width: 6.75rem; min-width: 6.75rem; max-width: 6.75rem; overflow: hidden; text-overflow: ellipsis;
        font-size: 0.78rem; padding: 0 0.4rem !important;
    }
    .att-help { font-size: 0.74rem; }
}

/* ═════════════ Day list + Devices grids (AppDataGrid with Class="ap-grid ...") ═════════════ */
.ap-grid .rz-data-grid-data { max-width: 100%; }
/* fixed-width columns would squeeze the unsized first column to nothing: keep the table wide and scroll inside the card */
.ap-grid--days .rz-grid-table { min-width: 36rem; }
.ap-grid--devices .rz-grid-table { min-width: 76rem; }

@media (max-width: 900px) {
    /* a 320px frozen actions column would cover a tablet: let it scroll with the rest */
    .ap-grid--devices .rz-frozen-cell { position: static !important; }
}

@media (max-width: 640px) {
    .ap-quick .rz-button { min-height: 2.6rem; }
    .ap-grid--days .rz-grid-table { min-width: 34rem; }

    /* devices: one card per device instead of a seven column table */
    .ap-grid--devices .rz-data-grid-data { overflow-x: visible; }
    .ap-grid--devices .rz-grid-table { min-width: 0; table-layout: auto; }
    .ap-grid--devices .rz-grid-table,
    .ap-grid--devices .rz-grid-table tbody,
    .ap-grid--devices .rz-grid-table tr,
    .ap-grid--devices .rz-grid-table td { display: block; width: auto; }
    .ap-grid--devices .rz-grid-table colgroup,
    .ap-grid--devices .rz-grid-table thead { display: none; }
    .ap-grid--devices .rz-grid-table tbody tr:not(.rz-datatable-emptymessage-row) {
        display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.35rem 0.75rem; align-items: center;
        margin: 0.6rem; padding: 0.75rem 0.85rem; border: 1px solid var(--border-subtle);
        border-radius: var(--radius-md, 10px); background: var(--bg-surface);
    }
    .ap-grid--devices .rz-grid-table tbody tr:not(.rz-datatable-emptymessage-row) > td {
        display: block; width: auto !important; padding: 0; border: 0; border-right: 0; min-width: 0; text-align: left;
        overflow-wrap: anywhere; white-space: normal; background: transparent !important;
    }
    .ap-grid--devices .rz-grid-table tbody tr:not(.rz-datatable-emptymessage-row):hover > td { background: transparent !important; }
    .ap-grid--devices .rz-grid-table tbody tr:not(.rz-datatable-emptymessage-row) > td:nth-child(1) { grid-column: 1; grid-row: 1; font-weight: 700; font-size: 1rem; }
    .ap-grid--devices .rz-grid-table tbody tr:not(.rz-datatable-emptymessage-row) > td:nth-child(6) { grid-column: 2; grid-row: 1; overflow: visible; }
    .ap-grid--devices .rz-grid-table tbody tr:not(.rz-datatable-emptymessage-row) > td:nth-child(n+2):nth-child(-n+5) {
        grid-column: 1 / -1; position: relative; padding: 0.3rem 0 0 6.2rem; border-top: 1px dashed var(--border-subtle);
        font-size: 0.85rem; text-align: right; overflow: visible; min-height: 1.6rem;
    }
    .ap-grid--devices .rz-grid-table tbody td:nth-child(n+2):nth-child(-n+5)::before {
        position: absolute; left: 0; top: 0.42rem; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em;
        text-transform: uppercase; color: var(--text-secondary);
    }
    .ap-grid--devices .rz-grid-table tbody td:nth-child(2)::before { content: "Type"; }
    .ap-grid--devices .rz-grid-table tbody td:nth-child(3)::before { content: "Key"; }
    .ap-grid--devices .rz-grid-table tbody td:nth-child(4)::before { content: "Polling"; }
    .ap-grid--devices .rz-grid-table tbody td:nth-child(5)::before { content: "Last seen"; }
    .ap-grid--devices .rz-grid-table tbody tr:not(.rz-datatable-emptymessage-row) > td:nth-child(7) {
        grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.5rem; padding-top: 0.5rem; border-top: 1px dashed var(--border-subtle); overflow: visible;
    }
    .ap-grid--devices .rz-grid-table tbody td:nth-child(7) .rz-button { flex: 1 1 auto; min-height: 2.6rem; justify-content: center; }
    .ap-grid--devices .rz-grid-table .rz-datatable-emptymessage-row,
    .ap-grid--devices .rz-grid-table .rz-datatable-emptymessage { display: block; width: auto; padding: 0.9rem; border: 0; }
}

/* ═════════════ Import wizard ═════════════ */
.aimp-steps { margin-bottom: 1rem; }
.aimp-table-wrap, .aimp-grid-wrap, .acodes-table-wrap { max-width: 100%; -webkit-overflow-scrolling: touch; }

/* rule cards: tidy 2 x 2 grid on desktop, one column on phones, equal heights */
.aimp-rules { grid-template-columns: 1fr; gap: 0.9rem; }
.aimp-rule {
    min-width: 0; padding: 0.8rem 0.9rem; border: 1px solid var(--border-subtle); border-radius: var(--radius-md, 10px);
    background: var(--bg-surface-alt, var(--bg-base)); gap: 0.55rem;
}
@media (min-width: 641px) {
    .aimp-rules { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* summary counts fill their row */
.aimp-counts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
.aimp-count { min-width: 0; }
.aimp-count:last-child:nth-child(odd) { grid-column: 1 / -1; }
@media (min-width: 641px) {
    .aimp-counts { grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); }
    .aimp-count:last-child:nth-child(odd) { grid-column: auto; }
}

/* preview grid lives in a bordered scroller */
.aimp-grid-wrap { border: 1px solid var(--border-subtle); border-radius: 8px; max-height: 70vh; }
.aimp-grid th { position: sticky; top: 0; z-index: 2; background: var(--bg-surface-alt, var(--bg-surface)); }
.aimp-grid th.is-sun { background: color-mix(in srgb, #607d8b 16%, var(--bg-surface)); }
.aimp-grid th.aimp-grid__name { z-index: 3; }

/* tables scroll inside their card instead of squashing */
@media (max-width: 900px) {
    .aimp-table { min-width: 34rem; }
    .aimp-table--emp { min-width: 46rem; }
    .aimp-table--totals { min-width: 40rem; }
    .aimp-table:not(.aimp-table--emp):not(.aimp-table--tokens) td { white-space: nowrap; }
    .acodes-table { min-width: 0; font-size: 0.84rem; }
    .acodes-table th, .acodes-table td { padding-inline: 0.4rem; }
    .acodes-table th { white-space: normal; }
}

@media (max-width: 640px) {
    /* steps: numbered dots, only the current step shows its name */
    .aimp-steps { flex-wrap: nowrap; gap: 0.5rem; align-items: center; overflow-x: auto; padding-bottom: 0.15rem; }
    .aimp-step { flex: 0 0 auto; }
    .aimp-step:not(.is-current) .aimp-step__name { display: none; }
    .aimp-step__no { width: 1.9rem; height: 1.9rem; }
    .aimp-step.is-current .aimp-step__name { white-space: nowrap; }

    .aimp-monthbar { padding: 0.55rem 0.7rem; flex-wrap: wrap; }
    .aimp-monthbar > .rz-icon, .aimp-monthbar > i { flex: 0 0 auto; }
    .aimp-monthbar > span:nth-child(2) { flex: 1 1 0; min-width: 0; }
    .aimp-monthbar__file { flex: 1 1 100%; max-width: 100%; margin-left: 0; order: 3; }
    .aimp-monthbar .rz-button { min-height: 2.4rem; }
    .aimp-found__month .rz-button { min-height: 2.2rem; }

    .aimp-month-pick, .aimp-month-row { gap: 0.5rem; }
    .aimp-month-pick > span:first-child { flex: 1 1 100%; }
    .aimp-month-pick .rz-dropdown, .aimp-month-pick .rz-numeric { flex: 1 1 8rem; }
    .aimp-month-row .rz-dropdown { flex: 1 1 8rem; }
    .aimp-month-row .rz-numeric { flex: 1 1 6rem; }
    .aimp-month-pick .rz-button { flex: 1 1 100%; min-height: 2.6rem; }
    .aimp-file { max-width: 100%; }

    /* stacked rows instead of a wide table: employees (step 2) and codes in the file (step 3) */
    .aimp-table--emp, .aimp-table--tokens { min-width: 0; }
    .aimp-table--emp thead, .aimp-table--tokens thead { display: none; }
    .aimp-table--emp, .aimp-table--emp tbody, .aimp-table--tokens, .aimp-table--tokens tbody { display: block; }
    .aimp-table--emp tr, .aimp-table--tokens tr {
        display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.35rem 0.75rem; align-items: center;
        padding: 0.7rem 0.8rem; margin-bottom: 0.6rem; border: 1px solid var(--border-subtle); border-radius: var(--radius-md, 10px);
        background: var(--bg-surface);
    }
    .aimp-table--emp td, .aimp-table--tokens td { display: block; padding: 0; border: 0; min-width: 0; }
    /* employees: [code ........ row n] / name / in the system / match to */
    .aimp-table--emp td:nth-child(2) { grid-column: 1; grid-row: 1; font-size: 1rem; }
    .aimp-table--emp td:nth-child(1) { grid-column: 2; grid-row: 1; font-size: 0.76rem; color: var(--text-secondary); }
    .aimp-table--emp td:nth-child(1)::before { content: "Row "; }
    .aimp-table--emp td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; font-weight: 600; overflow-wrap: anywhere; }
    .aimp-table--emp td:nth-child(4) { grid-column: 1 / -1; grid-row: 3; }
    .aimp-table--emp td:nth-child(5) { grid-column: 1 / -1; grid-row: 4; margin-top: 0.15rem; }
    .aimp-table--emp td:nth-child(5)::before {
        content: "Match to"; display: block; margin-bottom: 0.25rem; font-size: 0.72rem; font-weight: 700;
        letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-secondary);
    }
    .aimp-table--emp td .rz-dropdown, .aimp-table--tokens td .rz-dropdown, .aimp-table--tokens td .rz-textbox { width: 100% !important; }
    /* tokens: [file text ...... n days] / meaning */
    .aimp-table--tokens td:nth-child(1) { grid-column: 1; grid-row: 1; }
    .aimp-table--tokens td:nth-child(2) { grid-column: 2; grid-row: 1; font-size: 0.8rem; color: var(--text-secondary); }
    .aimp-table--tokens td:nth-child(2)::after { content: " days"; }
    .aimp-table--tokens td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; }
    .aimp-table--tokens .aimp-map > * { flex: 1 1 100%; min-width: 0; }
    .aimp-table--tokens .aimp-map .aimp-mini { flex: 1 1 auto; min-height: 2.4rem; }

    /* rules */
    .aimp-rule { padding: 0.7rem 0.75rem; }
    .aimp-rule .rz-datepicker { width: 100%; }
    .aimp-radio-col .rz-radio-button-list-item, .aimp-rule .rz-radio-button-list-item { min-height: 2.2rem; }
    .aimp-actions-row .rz-button { flex: 1 1 100%; min-height: 2.6rem; }

    /* preview grid: narrower name column */
    .aimp-grid-wrap { max-height: 65vh; }
    .aimp-grid__name { min-width: 7rem; max-width: 7.5rem; overflow: hidden; text-overflow: ellipsis; }
    .aimp-grid th, .aimp-grid td { padding: 0.28rem 0.3rem; min-width: 1.9rem; }

    /* wizard navigation: big, side by side */
    .aimp-nav { position: sticky; bottom: 0; z-index: 5; padding: 0.6rem 0; background: var(--bg-base); }
    .aimp-nav .rz-button { flex: 1 1 0; min-height: 2.8rem; line-height: 1.2; }
    .aimp-nav .rz-button:first-child { flex: 0 0 auto; }
    .aimp-result { line-height: 1.6; }
}

/* ═════════════ Attendance codes ═════════════ */
.acodes-intro { max-width: 62rem; }

@media (max-width: 640px) {
    .acodes-intro { font-size: 0.9rem; margin-bottom: 0.75rem; }
    .acodes-table { min-width: 0; }
    .acodes-table thead { display: none; }
    .acodes-table, .acodes-table tbody { display: block; }
    .acodes-table tr {
        display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.35rem 0.75rem; align-items: center;
        padding: 0.75rem 0.85rem; margin-bottom: 0.6rem; border: 1px solid var(--border-subtle);
        border-radius: var(--radius-md, 10px); background: var(--bg-surface);
    }
    .acodes-table td { display: block; padding: 0; border: 0; min-width: 0; }
    .acodes-table td:nth-child(1) { grid-column: 1; grid-row: 1; }
    .acodes-table td:nth-child(2) { grid-column: 2; grid-row: 1; font-weight: 600; }
    /* detail rows: label on the left, value on the right */
    .acodes-table tr > td:nth-child(n+3):nth-child(-n+6) {
        grid-column: 1 / -1; position: relative; padding: 0.35rem 0 0 6.2rem; border-top: 1px dashed var(--border-subtle);
        font-size: 0.85rem; text-align: right; min-height: 1.6rem;
    }
    .acodes-table td:nth-child(n+3):nth-child(-n+6)::before {
        position: absolute; left: 0; top: 0.5rem; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em;
        text-transform: uppercase; color: var(--text-secondary);
    }
    .acodes-table td:nth-child(3)::before { content: "Counts as"; }
    .acodes-table td:nth-child(4)::before { content: "Unpaid"; }
    .acodes-table td:nth-child(5)::before { content: "Flags"; }
    .acodes-table td:nth-child(6)::before { content: "Other spellings"; }
    .acodes-table td:nth-child(5):not(:has(*)), .acodes-table td:nth-child(6):empty { display: none; }
    .acodes-table td.acodes-actions {
        grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 0.5rem; padding-top: 0.45rem; border-top: 1px dashed var(--border-subtle);
    }
    .acodes-table td.acodes-actions:not(:has(*)) { display: none; }
    .acodes-table td.acodes-actions .rz-button { min-height: 2.5rem; min-width: 2.5rem; }
    .acodes-table td .acode-tag { margin-left: 0; margin-right: 0.3rem; }
}

/* ═════════════ Attendance code dialog (inner layout only; dialog size is set elsewhere) ═════════════ */
.acd { min-width: 0; }
.acd-chip { min-height: 2.5rem; }
@media (max-width: 640px) {
    .acd-chip { flex: 1 1 calc(50% - 0.4rem); min-height: 2.6rem; justify-content: center; }
    .acd-color-input { width: 100%; height: 2.6rem; }
    .acd-footer { flex-direction: column-reverse; }
    .acd-footer .rz-button { width: 100%; min-height: 2.7rem; }
}

/* ═════════════ Devices ═════════════ */
.app-code-block { max-width: 100%; overflow-x: auto; }
@media (max-width: 640px) {
    .app-code-block { font-size: 0.74rem; }
}
