:root {
    color-scheme: light;
    --ink: #101d13;
    --ink-soft: #314638;
    --muted: #586b5e;
    --green: #087f23;
    --green-dark: #05631a;
    --green-soft: #e8f6e8;
    --cream: #f5f9f3;
    --surface: #ffffff;
    --surface-soft: #f7faf7;
    --line: #d4e2d5;
    --line-strong: #aabdac;
    --danger: #a32431;
    --warning: #8a5700;
    --info: #1559a6;
    --purple: #6a3cac;
    --white: #ffffff;
    --focus: #087f23;
    --focus-ring: #05631a;
    --shadow-sm: 0 1px 3px rgb(16 43 24 / 8%);
    --shadow-md: 0 12px 32px rgb(16 43 24 / 10%);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-pill: 999px;
    --control-height: 46px;
    --topbar-height: 76px;
    --sidebar-width: 260px;
    --content-width: 1240px;
    --space-1: .25rem;
    --space-2: .5rem;
    --space-3: .75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--cream);
    font-synthesis: none;
    text-rendering: optimizeLegibility;
}

*, *::before, *::after { box-sizing: border-box; }

html {
    min-width: 320px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: linear-gradient(145deg, #eef8ed, #fbfcf8);
    color: var(--ink);
    font: 400 1rem/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    overflow-wrap: break-word;
}

img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
button, [role="button"] { touch-action: manipulation; }

.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

h1, h2, h3, h4, p { margin-top: 0; }
h1, h2, h3, h4 { color: var(--ink); line-height: 1.18; text-wrap: balance; }
h1 { font-size: clamp(1.85rem, 4vw, 2.75rem); letter-spacing: -.035em; }
h2 { font-size: clamp(1.25rem, 2vw, 1.55rem); letter-spacing: -.018em; }
h3 { font-size: 1.08rem; }

a {
    color: var(--green-dark);
    text-decoration: none;
}

a:hover { color: var(--green); text-decoration: none; }

:where(a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])):focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
    border-color: var(--focus);
}

::selection { background: #bce6c3; color: #061d0b; }

.skip-link {
    position: fixed;
    z-index: 2000;
    top: 8px;
    left: 8px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--ink);
    color: var(--white);
    font-weight: 800;
    transform: translateY(-160%);
    transition: transform .16s ease;
}

.skip-link:not(:focus-visible) {
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    transform: none;
}

.skip-link:focus-visible {
    width: auto;
    height: auto;
    padding: 10px 14px;
    margin: 0;
    overflow: visible;
    clip: auto;
    clip-path: none;
    color: var(--white);
    text-decoration: none;
    transform: translateY(0);
}

.topbar {
    position: sticky;
    z-index: 900;
    top: 0;
    min-height: var(--topbar-height);
    background: rgb(255 255 255 / 96%);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 10px clamp(16px, 4vw, 56px);
    box-shadow: 0 2px 16px rgb(0 102 0 / 5%);
    backdrop-filter: blur(12px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--ink);
    text-decoration: none;
}

.brand:hover { color: var(--ink); }
.brand-logo { width: 52px; height: 52px; object-fit: contain; }
.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    background: var(--green);
    color: var(--white);
    font-weight: 800;
    box-shadow: inset 0 -4px 0 var(--green-dark);
}
.brand span:last-child { display: grid; }
.brand small { color: var(--muted); font-size: .75rem; }

.page-shell {
    width: min(var(--content-width), calc(100% - 32px));
    min-width: 0;
    margin: 40px auto;
}

.auth-card {
    width: min(520px, 100%);
    margin: 5vh auto;
    background: rgb(255 255 255 / 96%);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: clamp(24px, 5vw, 48px);
    box-shadow: 0 22px 60px rgb(28 65 48 / 12%);
}

.eyebrow {
    margin-bottom: var(--space-2);
    color: var(--green-dark);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .12em;
    font-weight: 850;
}

.muted { color: var(--muted); line-height: 1.65; }
.meta { color: var(--muted); font-size: .82rem; line-height: 1.45; }

.form-stack { display: grid; gap: 18px; margin-top: 28px; }
.form-stack label, .field { display: grid; gap: 7px; font-weight: 700; font-size: .9rem; }
.form-stack small, .field small { color: var(--muted); font-weight: 400; }

:where(main, .form-stack, .form-grid, .toolbar, .field) :where(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select,
    textarea
) {
    width: 100%;
    max-width: 100%;
    min-height: var(--control-height);
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--ink);
    background: var(--surface);
    box-shadow: inset 0 1px 1px rgb(16 43 24 / 3%);
}

:where(main, .form-stack, .form-grid, .toolbar, .field) textarea {
    min-height: 112px;
    resize: vertical;
}

:where(main, .form-stack, .form-grid, .toolbar, .field) select { padding-right: 36px; }
:where(main, .form-stack, .form-grid, .toolbar, .field) select[multiple] { min-height: 8rem; padding-right: 12px; }
:where(main, .form-stack, .form-grid, .toolbar, .field) select[multiple] option { padding: 7px; }

:where(main, .form-stack, .form-grid, .toolbar, .field) :where(input, select, textarea):hover:not(:disabled) {
    border-color: #839c88;
}

:where(main, .form-stack, .form-grid, .toolbar, .field) :where(input, select, textarea):disabled,
:where(main, .form-stack, .form-grid, .toolbar, .field) :where(input, select, textarea)[readonly] {
    color: #66736a;
    background: #f0f4f0;
    cursor: not-allowed;
    opacity: 1;
}

input[type="file"] { padding-block: 7px !important; }
input[type="file"]::file-selector-button {
    margin-right: 10px;
    border: 0;
    border-radius: 7px;
    padding: 7px 10px;
    background: var(--green-soft);
    color: var(--green-dark);
    font-weight: 750;
    cursor: pointer;
}

.checkbox, .check {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) !important;
    align-items: start;
    gap: 9px !important;
    font-weight: 600 !important;
}

:where(.checkbox, .check) :where(input[type="checkbox"], input[type="radio"]) {
    width: 19px;
    height: 19px;
    min-height: 0;
    margin: 1px 0 0;
    accent-color: var(--green);
}

.button {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 10px 16px;
    color: var(--ink);
    background: #edf2ef;
    font: inherit;
    font-weight: 800;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.button:hover:not(:disabled):not([aria-disabled="true"]) { text-decoration: none; transform: translateY(-1px); }
.button.primary { background: var(--green); color: var(--white); box-shadow: 0 8px 18px rgb(8 127 35 / 14%); }
.button.primary:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--green-dark); color: var(--white); }
.button.secondary { background: #edf2ef; color: var(--ink); border-color: #dce5df; }
.button.secondary:hover:not(:disabled):not([aria-disabled="true"]) { background: #e1eae4; color: var(--ink); }
.button.ghost { background: transparent; color: var(--green-dark); border-color: var(--line-strong); }
.button.ghost:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--green-soft); }
.button.danger { background: #fff0f1; color: var(--danger); border-color: #f2cbd0; }
.button.danger:hover:not(:disabled):not([aria-disabled="true"]) { background: #f9dfe2; color: #801a25; }
.button.small { min-height: 36px; padding: 7px 11px; font-size: .82rem; }

.button:disabled, .button[aria-disabled="true"], button:disabled {
    cursor: not-allowed;
    opacity: .58;
    transform: none;
    box-shadow: none;
}

.error { color: var(--danger); font-size: .84rem; }
.notice {
    padding: 14px 17px;
    border: 1px solid #e5d395;
    border-radius: 11px;
    margin-bottom: 24px;
    color: #684900;
    background: #fff8dc;
}
.notice.success { border-color: #b9dfc8; background: #e6f6ed; color: #135936; }
.notice.error-box, .error-box {
    border: 2px solid #b42318;
    border-left-width: 7px;
    background: #fff1f0;
    color: #8f1d18;
    box-shadow: 0 8px 22px rgb(180 35 24 / 12%);
}
.notice.error-box::before, .error-box::before {
    content: "Action needed";
    display: block;
    margin-bottom: .45rem;
    color: #b42318;
    font-size: .78rem;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.notice.error-box:focus, .notice.error-box:focus-visible, .error-box:focus, .error-box:focus-visible {
    outline: 3px solid #f4a29a;
    outline-offset: 3px;
    box-shadow: 0 8px 22px rgb(180 35 24 / 18%);
}
.error-box strong { color: #7a1712; }
.error-box ul { margin-bottom: 0; }

.user-menu { display: flex; align-items: center; gap: 15px; min-width: 0; }
.user-menu > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu form { margin: 0; }

.welcome-panel, .empty-state {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: clamp(24px, 4vw, 42px);
}
.welcome-panel { display: flex; justify-content: space-between; gap: 24px; }
.empty-state { margin-top: 20px; padding-block: clamp(40px, 7vw, 70px); text-align: center; color: var(--muted); }
.empty-state p { color: var(--muted); }

[aria-busy="true"], .is-loading { cursor: progress; }
.button[aria-busy="true"], .button.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.button[aria-busy="true"]::after, .button.is-loading::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    color: var(--white);
    animation: ui-spin .7s linear infinite;
}

@keyframes ui-spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
    .topbar { padding-inline: 12px; }
    .brand small, .user-menu > span { display: none; }
    .brand-logo { width: 44px; height: 44px; }
    .page-shell { width: min(100% - 24px, var(--content-width)); margin: 22px auto; }
    .welcome-panel { display: block; }
}

@media (min-width: 1025px) {
    :root {
        --topbar-height: 68px;
        --sidebar-width: 272px;
        --content-width: 1360px;
    }

    .topbar {
        min-height: var(--topbar-height);
        padding: 7px clamp(22px, 2.4vw, 40px);
    }

    .brand { gap: 10px; }
    .brand-logo { width: 46px; height: 46px; }
    .brand strong { font-size: .96rem; }
    .brand small { font-size: .69rem; }
    .user-menu { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (forced-colors: active) {
    .button, .panel, .notice, input, select, textarea { border: 1px solid CanvasText; }
}

/* S1-S5: compact received-letter workflow */
.case-stepper { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
.case-step { display: flex; align-items: center; gap: .55rem; color: var(--muted, #607064); padding: .65rem; border-radius: .75rem; background: #f4f7f4; }
.case-step span { display: grid; place-items: center; flex: 0 0 1.8rem; width: 1.8rem; height: 1.8rem; border-radius: 50%; background: #dfe7e0; font-weight: 800; }
.case-step.is-complete, .case-step.is-current { color: #063d19; background: #e7f5e9; }
.case-step.is-complete span, .case-step.is-current span { color: #fff; background: #078b29; }
.case-step.is-current { box-shadow: inset 0 0 0 2px #078b29; }
@media (max-width: 760px) { .case-stepper { grid-template-columns: 1fr 1fr; } .case-step { font-size: .88rem; } }

/* F1-F5: governed online forms */
.public-form-card { max-width: 920px; margin-inline: auto; }
.form-section { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0 0; padding: 1.35rem 0 0; min-width: 0; }
.form-section:first-of-type { border-top: 0; padding-top: .5rem; }
.form-section > legend { display: grid; gap: .25rem; width: 100%; padding: 0; font-size: clamp(1.2rem, 2.3vw, 1.65rem); font-weight: 800; }
.form-progress { height: .55rem; overflow: hidden; border-radius: 999px; background: #dfe9e1; margin-top: 1rem; }
.form-progress > div { height: 100%; border-radius: inherit; background: var(--primary); transition: width .2s ease; }
.form-question { cursor: grab; border-inline-start: 4px solid var(--primary); }
.form-question:active { cursor: grabbing; }
.record-list { display: grid; gap: 1rem; margin-block: 1rem; }
.public-form-card .choice-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
@media (max-width: 760px) {
    .public-form-card { border-radius: var(--radius-lg); }
    .form-section > legend { font-size: 1.2rem; }
    .public-form-card .sticky-form-actions { align-items: stretch; }
    .public-form-card .sticky-form-actions .button { width: 100%; }
}
