/*
 * The portal's global styles: design tokens, base elements, the page frame, and the pieces several components share.
 * A component's own styles live beside it in its .razor.css (Blazor CSS isolation), and use these tokens.
 *
 * Ported from the client's mockups (source-docs/SP_Disposal_Enquiry_Mockup.html, then source-docs/Mockup_Latest_From_Client.html).
 * Deliberate departures for WCAG 2.1 AA (ADR 0003) are marked "AA:".
 *
 * Layers, lowest first. Component styles are unlayered, so they win over all of these, as a component's own look should.
 */
@layer tokens, base, layout, components, utilities;

/*
 * Inter, the mockup's typeface, served from the portal itself (no third-party request): one variable font for every
 * weight the portal uses (including 650 and 750), Latin only. SIL Open Font License; see fonts/inter/OFL.txt.
 * Until it loads, and for characters outside it (e.g. arrows, ✓), the system's UI font shows.
 */
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("fonts/inter/InterVariable-latin.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@layer tokens {
    :root {
        /* Brand and primary actions */
        --color-primary: #2563eb;
        --color-primary-hover: #1d4ed8;
        --color-primary-active: #1e40af;
        --color-primary-muted: #93c5fd;
        --color-primary-border: #bfdbfe;
        --color-primary-subtle: #dbeafe;
        --color-primary-soft: #eff6ff;
        --color-primary-tint: #f8fbff;
        --color-navy: #17263a;

        /* Text */
        --color-text: #172033;
        --color-text-secondary: #334155;
        /* AA: mockup used #64748b, which falls below 4.5:1 on the grey step circles and tinted panels. */
        --color-text-muted: #475569;
        /* AA: browsers' default placeholder colours vary and some fall below 4.5:1. */
        --color-text-placeholder: #64748b;
        /* Text and icons on a solid colour fill. */
        --color-text-on-fill: #fff;

        /* Surfaces */
        --color-bg: #f7f9fc;
        --color-bg-sign-in: #f4f7fb;
        --color-surface: #fff;
        --color-surface-subtle: #fafbfc;
        --color-surface-muted: #f8fafc;
        --color-surface-disabled: #f1f5f9;
        --color-surface-pressed: #e2e8f0;

        /* Borders and dividers */
        --color-border: #dbe2ea;
        --color-border-strong: #cbd5e1;
        --color-border-subtle: #edf1f5;
        --color-border-faint: #f1f5f9;
        /* AA: the mockup's #cbd5e1 field border was 1.5:1; fields need 3:1 against white to be seen (1.4.11). */
        --color-border-field: #7c8799;

        /* Danger: errors, problems, and actions that lose something */
        --color-danger: #b91c1c;
        --color-danger-hover: #991b1b;
        --color-danger-strong: #7f1d1d;
        --color-danger-border: #fca5a5;
        --color-danger-subtle: #fee2e2;
        --color-danger-soft: #fef2f2;
        --color-required: #dc2626;

        /* Success */
        --color-success: #16a34a;
        --color-success-strong: #166534;
        --color-success-border-strong: #15803d;
        --color-success-accent: #86efac;
        --color-success-border: #bbf7d0;
        --color-success-subtle: #dcfce7;
        --color-success-soft: #f0fdf4;

        /* Warning: something to finish before going on */
        --color-warning: #b45309;
        --color-warning-strong: #92400e;
        --color-warning-border: #fde68a;
        --color-warning-subtle: #fef3c7;
        --color-warning-soft: #fffbeb;

        /* Caution: an Item Import with rows to fix */
        --color-caution-strong: #9a3412;
        --color-caution-border: #fed7aa;
        --color-caution-soft: #fff7ed;

        /* Typography: rem, so text follows the officer's browser text size */
        --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        --text-2xs: 0.6875rem; /* 11px */
        --text-xs: 0.75rem; /* 12px */
        --text-sm: 0.8125rem; /* 13px */
        --text-base: 0.875rem; /* 14px */
        --text-md: 1rem; /* 16px */
        --text-lg: 1.0625rem; /* 17px */
        --text-xl: 1.1875rem; /* 19px */
        --text-2xl: 1.4375rem; /* 23px */
        --text-3xl: 1.5625rem; /* 25px */
        /* Every signed-in page's title: the table or form below it is what the page is for. */
        --text-page-title: 1.3125rem; /* 21px */
        --weight-medium: 500;
        --weight-semibold: 600;
        --weight-strong: 650;
        --weight-bold: 700;
        --weight-heavy: 750;
        --weight-black: 800;

        /* Corners */
        --radius-xs: 4px;
        --radius-sm: 6px;
        --radius-md: 8px;
        --radius-lg: 10px;
        --radius-xl: 12px;
        --radius-2xl: 14px;
        --radius-3xl: 16px;
        --radius-full: 999px;

        /* Elevation */
        --shadow-card: 0 8px 30px rgba(15, 23, 42, .06);
        --shadow-popover: 0 8px 24px rgba(15, 23, 42, .12);
        --shadow-dialog: 0 24px 64px rgba(15, 23, 42, .22), 0 2px 6px rgba(15, 23, 42, .08);
        --shadow-banner: 0 -4px 16px rgba(15, 23, 42, .08);
        --color-backdrop: rgba(15, 23, 42, .5);

        /* Interaction. A click shows at once in the browser, before the server's answer re-renders anything. */
        /* AA: the mockup had no focus styling; keyboard users need a visible focus indicator. */
        --focus-ring: 3px solid var(--color-primary);
        --transition-press: background-color .12s, border-color .12s, transform .06s;

        /* Control sizes. Touch targets on a phone are at least 44 by 44px. */
        --control-height: 42px;
        /* Compact controls on a wide screen: the page header's buttons, the Dashboard's filters and pager. */
        --control-height-md: 36px;
        --control-height-sm: 32px;
        --touch-target: 44px;
    }
}

@layer base {
    * { box-sizing: border-box; }
    body { margin: 0; background: var(--color-bg); font-family: var(--font-sans); color: var(--color-text); }
    button, input, select, textarea { font: inherit; }

    :focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
    /* Headings only take focus from script (page and section changes), to be read out; they are not controls. */
    h1:focus, h2:focus { outline: none; }

    /* The page behind does not scroll while a dialog is open. */
    html:has(.modal[open]) { overflow: hidden; }
}

@layer layout {
    /* Page frame */
    .app { max-width: 1180px; margin: 0 auto; padding: 20px 24px 40px; }
    .card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-xl); padding: 22px; }
    /* Page not found and Access denied (not in the mockup) */
    .empty { text-align: center; padding: 48px 22px; }

    /* Page header: the title, who is signed in, and Sign out */
    .top { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 16px; }
    .top h1 { font-size: var(--text-page-title); line-height: 1.25; margin: 0; }
    .top p { font-size: var(--text-sm); color: var(--color-text-muted); margin: 4px 0 0; }
    .top-actions { display: flex; align-items: center; gap: 12px; }
    .top-actions form { display: contents; }
    .login-name { font-size: var(--text-sm); font-weight: var(--weight-strong); color: var(--color-text-secondary); padding: 0 4px; }

    /* Pages standing alone, outside the page frame: sign-in, the Development-only fake officer picker, and the error page */
    .login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--color-bg-sign-in); }
    .login-card { width: min(430px, 100%); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-3xl); padding: 42px; box-shadow: var(--shadow-card); text-align: center; }
    .login h1 { font-size: var(--text-2xl); margin: 0 0 8px; }
    .login p { font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.5; margin: 0 0 28px; }
    .login .login-note { font-size: var(--text-xs); margin: 18px 0 0; }
    .login .login-error { color: var(--color-danger-strong); background: var(--color-danger-soft); border: 1px solid var(--color-danger-border); border-radius: var(--radius-md); padding: 10px 12px; margin: -12px 0 20px; }
    .ms-btn { width: 100%; min-height: 48px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); background: var(--color-surface); color: var(--color-text); cursor: pointer; font-size: var(--text-base); font-weight: var(--weight-strong); display: flex; align-items: center; justify-content: center; gap: 10px; }
    /* Microsoft's own logo colours. */
    .ms-icon { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; width: 18px; height: 18px; }
    .ms-icon i { display: block; }
    .ms-icon i:nth-child(1) { background: #f25022; }
    .ms-icon i:nth-child(2) { background: #7fba00; }
    .ms-icon i:nth-child(3) { background: #00a4ef; }
    .ms-icon i:nth-child(4) { background: #ffb900; }
    .officer-picker { display: grid; gap: 10px; }
    .officer-email { display: block; font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--color-text-muted); }
    .error-card { text-align: left; }
    .error-card h1, .error-card > p { text-align: center; }
    .error-card .request-id { font-size: var(--text-xs); color: var(--color-text-muted); text-align: center; word-break: break-all; }
    .error-card .btn { width: 100%; }

    @media (max-width: 760px) {
        .app { padding: 18px 14px 30px; }
        .card { padding: 16px; }
        .top { flex-direction: column; align-items: stretch; gap: 14px; }
        .top-actions { width: 100%; flex-wrap: wrap; }
        .top-actions .btn { flex: 1; }
        .login-card { padding: 32px 24px; }
    }
}

@layer components {
    /* Buttons: every full-size button 14px; the small ones in tight spots (row actions, Review Edit, Clear filters,
       date presets, Sign out) set their own smaller size. */
    .btn { border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); border-radius: var(--radius-md); padding: 9px 14px; min-height: var(--control-height); font-size: var(--text-base); cursor: pointer; font-weight: var(--weight-strong); transition: var(--transition-press); }
    .btn.primary { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-text-on-fill); }
    .btn.danger { background: var(--color-danger); border-color: var(--color-danger); color: var(--color-text-on-fill); }
    /* AA: the mockup faded disabled buttons to .45 opacity (2.8:1); a grey fill keeps the label at 6.9:1. */
    .btn:disabled { background: var(--color-surface-disabled); color: var(--color-text-muted); cursor: not-allowed; }
    /* Submit in progress: stays readable while disabled, with a spinner. */
    /* AA: keeps its full colours, as .8 opacity took the label to 3.6:1. */
    .btn.primary[aria-busy="true"]:disabled { background: var(--color-primary); color: var(--color-text-on-fill); cursor: progress; }
    .btn:not(:disabled):hover { background: var(--color-surface-muted); border-color: var(--color-border-strong); }
    .btn.primary:not(:disabled):hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
    .btn.danger:not(:disabled):hover { background: var(--color-danger-hover); border-color: var(--color-danger-hover); }
    .btn:not(:disabled):active { background: var(--color-surface-pressed); transform: translateY(1px); }
    .btn.primary:not(:disabled):active { background: var(--color-primary-active); border-color: var(--color-primary-active); }
    .btn.danger:not(:disabled):active { background: var(--color-danger-strong); border-color: var(--color-danger-strong); }
    /* Links styled as buttons (the mockup only had <button>s). */
    /* A page header's buttons, beside its title, and other compact controls on a wide screen; 44px on a phone. */
    .btn.compact { min-height: var(--control-height-md); padding: 6px 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
    a.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center; text-decoration: none; }
    /* Line icons (Icon.razor) sit on the text's middle and never shrink. */
    .icon { flex: none; vertical-align: -0.2em; }

    /* Form fields, shared by every step's fields */
    .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
    .full { grid-column: 1 / -1; }
    /* Fields sized to their content, side by side in one grid row, the grid's gap apart; they wrap on a narrow screen. */
    .field-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 15px; }
    .field label, .field legend { display: block; font-size: var(--text-xs); font-weight: var(--weight-bold); color: var(--color-text-secondary); margin-bottom: 6px; }
    /* AA: radio questions are fieldsets with a legend (the mockup used an unassociated label). */
    fieldset.field, fieldset.field-row { border: 0; margin: 0; padding: 0; min-width: 0; }
    .field legend { padding: 0; }
    .req { color: var(--color-required); }
    input, select, textarea { width: 100%; min-height: var(--control-height); border: 1px solid var(--color-border-field); border-radius: var(--radius-md); padding: 9px 10px; background: var(--color-surface); color: var(--color-text); font-size: var(--text-sm); }
    /* Short values get one shared width, not the column, so they line up down the form: a date and time (the proposed
       collection dates, with room for dd/mm/yyyy, hh:mm am and the picker) and a short number (the storage days). */
    input[type="datetime-local"], input.input-short { width: 15rem; max-width: 100%; }
    /* The calendar icon is the only way to open the picker: a 20px icon in a 32px target, negative margins so the
       control keeps its height (Chromium and Edge; Firefox draws its own). */
    input[type="datetime-local"]::-webkit-calendar-picker-indicator {
        width: 20px; height: 20px; padding: 6px; margin: -6px -6px -6px 4px;
        border-radius: var(--radius-md); cursor: pointer;
    }
    input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover { background-color: var(--color-surface-disabled); }
    ::placeholder { color: var(--color-text-placeholder); opacity: 1; }
    textarea { min-height: 76px; resize: vertical; }
    select:disabled { background: var(--color-surface-disabled); cursor: not-allowed; }
    /* A question's choices sit just under it, as close as a field under its label: no control's height of their own,
       which left blank space above and below every row of radios. */
    .choices { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; padding: 2px 0; }
    /* At least 24px to click on a wide screen (the size WCAG 2.2 asks); 44px on a phone, below. */
    .choices label { display: flex; align-items: center; gap: 6px; min-height: 24px; font-size: var(--text-sm); font-weight: var(--weight-medium); }
    .choices input { width: 16px; min-height: 16px; }
    .help { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 5px; }
    /* Blazor's validation */
    .validation-message { color: var(--color-danger); font-size: var(--text-xs); margin-top: 5px; }
    .invalid { border-color: var(--color-danger); }

    /* The foot of a Dashboard filter's panel: what it shows, and Clear (as the CRM's filters). */
    .panel-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--color-border-subtle); padding: 8px 14px; font-size: var(--text-xs); color: var(--color-text-muted); }
    .panel-foot .clear { border: 0; background: none; padding: 6px 4px; color: var(--color-primary-active); font-size: var(--text-xs); font-weight: var(--weight-strong); cursor: pointer; }
    .panel-foot .clear:disabled { color: var(--color-text-muted); cursor: default; }

    /* A busy wait, beside the words saying what for. */
    .spinner { display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* Blazor's error boundary, around a part of a page that failed to render. */
    .blazor-error-boundary { background: var(--color-danger-soft); border: 1px solid var(--color-danger-border); border-radius: var(--radius-xl); padding: 14px 16px; color: var(--color-danger-strong); font-size: var(--text-base); }
    .blazor-error-boundary::after { content: "Something went wrong showing this part of the page. Reload the page to try again."; }

    @media (prefers-reduced-motion: reduce) {
        .btn { transition: none; }
        .spinner { animation-duration: 2.4s; }
    }

    @media (max-width: 760px) {
        .btn, .btn.compact { min-height: var(--touch-target); min-width: var(--touch-target); }
        /* iOS zooms into a field whose text is smaller than 16px when it takes focus. */
        input, select, textarea { font-size: var(--text-md); }
        .grid { grid-template-columns: 1fr; }
        .full { grid-column: auto; }
        /* Each choice a finger-sized row, the rows touching: the 44px already keeps them apart. */
        .choices { row-gap: 0; padding: 0; }
        .choices label { min-height: var(--touch-target); }
        /* Short inputs and the proposed dates as wide as every other field, rather than a short box in a wide column. */
        input[type="datetime-local"], input.input-short { width: 100%; }
        .field-row > .field { flex: 1 1 100%; }

        /*
         * Tables of Items show as stacked cards, each value labelled from its cell's data-label, in place of the header row.
         * AA: the header row is only hidden visually, and the markup's explicit roles keep the table, so screen readers still
         * read each value with its column header (1.3.1); the shown labels are given empty alternative text so they are not
         * read twice, where browsers support it.
         */
        .stack-table { min-width: 0; }
        .stack-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
        .stack-table, .stack-table tbody, .stack-table tfoot, .stack-table tr, .stack-table td { display: block; }
        .stack-table td[data-label] { display: grid; grid-template-columns: 9.5em minmax(0, 1fr); gap: 10px; word-break: break-word; }
        .stack-table td[data-label]::before { content: attr(data-label); color: var(--color-text-muted); font-size: var(--text-xs); font-weight: var(--weight-strong); }
        .stack-table td[data-label]::before { content: attr(data-label) / ""; }
    }
}

@layer utilities {
    /* Read by screen readers but not shown. */
    .visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
}
