:root {
    color-scheme: light;
    --ink: #102a43;
    --muted: #526d82;
    --line: #c8d8e7;
    --surface: #ffffff;
    --canvas: #edf4f8;
    --brand: #007c91;
    --brand-dark: #005d6d;
    --accent: #ffb300;
    --danger: #a61b1b;
    --success: #176b42;
    --radius: 14px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    color: var(--ink);
    background: linear-gradient(160deg, #eaf4f8 0, #f7fafc 360px, var(--canvas) 100%);
    line-height: 1.45;
}

button, input { font: inherit; }

button {
    min-height: 44px;
    padding: 9px 13px;
    border: 1px solid #9db6c8;
    border-radius: 9px;
    color: var(--ink);
    background: #fff;
    font-weight: 700;
    cursor: pointer;
}

button:hover { border-color: var(--brand); background: #f2fbfc; }
button:focus-visible, input:focus-visible, summary:focus-visible, pre:focus-visible { outline: 3px solid #ffbc2f; outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .55; }
button.primary { border-color: var(--brand); color: #fff; background: var(--brand); }
button.primary:hover { background: var(--brand-dark); }

.page-shell { width: min(100%, 980px); margin: 0 auto; padding: 22px 14px 42px; }
.masthead { padding: 10px 3px 20px; }
.masthead-topline { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(29px, 8vw, 46px); line-height: 1.05; letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: 20px; letter-spacing: -.02em; }
.masthead > p:last-child { max-width: 670px; margin-bottom: 0; color: var(--muted); font-size: 16px; }
.eyebrow { margin-bottom: 4px; color: var(--brand-dark); font-size: 12px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }

.notice, .card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 5px 20px rgb(32 74 101 / 7%);
}
.notice { margin-bottom: 14px; padding: 12px 14px; border-left: 5px solid var(--accent); font-size: 14px; }
.card { margin-bottom: 14px; padding: 16px; }
.primary-card { border-color: #a9ccd5; box-shadow: 0 8px 28px rgb(20 91 107 / 10%); }
.stack { display: contents; }
.section-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.section-heading p { margin-bottom: 3px; }
.badge, .access-status { display: inline-block; flex: 0 0 auto; margin: 0; padding: 4px 8px; border-radius: 999px; color: var(--brand-dark); background: #e1f5f6; font-size: 12px; font-weight: 750; }
.access-status { max-width: 190px; text-align: right; }

fieldset { min-width: 0; margin: 0 0 16px; padding: 0; border: 0; }
legend { margin-bottom: 8px; font-weight: 800; }
label { display: grid; gap: 5px; color: #2d4a61; font-size: 14px; font-weight: 700; }
input { width: 100%; min-height: 44px; padding: 9px 10px; border: 1px solid #aebfce; border-radius: 8px; color: var(--ink); background: #fff; }
input:hover { border-color: #6e92aa; }
input[type="checkbox"], input[type="radio"] { width: 19px; min-height: 19px; margin: 0; accent-color: var(--brand); }
.field-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 11px; }
.compact-fields { margin-top: 4px; }
.segmented-control, .inline-checks { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented-control label, .inline-checks label, .check-grid label { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 9px; border: 1px solid #c6d4df; border-radius: 8px; background: #f9fcfd; }
.segmented-control label { flex: 1 1 170px; }
.check-grid { display: grid; grid-template-columns: 1fr; gap: 7px; }
code { padding: 1px 4px; border-radius: 4px; color: #29485f; background: #e4eef4; font-size: .9em; }
.help { margin: 0 0 15px; color: var(--muted); font-size: 13px; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.error { margin: 12px 0 0; padding: 10px; border-radius: 8px; color: #721c1c; background: #ffe8e8; font-weight: 700; }

.patient-search-form { margin: 0; }
.address-label { font-size: 15px; }
.address-label input { min-height: 52px; padding: 12px 13px; border-width: 2px; font-size: 16px; }
.patient-search-button { width: 100%; min-height: 50px; margin-top: 11px; font-size: 16px; }
.privacy-note { margin-top: 9px; margin-bottom: 0; }
.patient-status { margin-top: 13px; padding: 11px 12px; border-radius: 9px; color: var(--muted); background: #f1f7fa; font-size: 14px; }
.patient-status strong { display: block; margin-bottom: 2px; color: var(--ink); }
.coverage-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.coverage-summary.empty-state { display: block; }
.coverage-stat { padding: 10px; border: 1px solid #d2e0e8; border-radius: 9px; background: #f8fbfc; }
.coverage-stat strong { display: block; font-size: 21px; line-height: 1.1; }
.coverage-stat span { color: var(--muted); font-size: 12px; font-weight: 700; }
.coverage-address { grid-column: 1 / -1; padding: 10px; border-radius: 9px; color: #194e5d; background: #e9f7f8; font-size: 13px; }
.autocomplete-sticky { position: sticky; top: 0; z-index: 2; padding: 4px 0 8px; background: var(--surface); }
.autocomplete-sticky label { margin-bottom: 5px; }
.autocomplete-sticky input { min-height: 50px; padding: 11px 13px; border-width: 2px; font-size: 16px; }
.pharmacy-options { max-height: min(58vh, 520px); overflow-y: auto; overscroll-behavior: contain; border: 1px solid #b8ccd8; border-radius: 11px; background: #fff; box-shadow: 0 10px 28px rgb(25 59 81 / 12%); }
.pharmacy-option { display: grid; width: 100%; min-height: 74px; padding: 11px 12px; border: 0; border-bottom: 1px solid #d8e4ea; border-radius: 0; text-align: left; background: #fff; }
.pharmacy-option:last-child { border-bottom: 0; }
.pharmacy-option:hover, .pharmacy-option.active, .pharmacy-option[aria-selected="true"] { background: #eaf8f9; }
.option-topline { display: flex; align-items: start; justify-content: space-between; gap: 8px; }
.option-name { min-width: 0; color: var(--ink); font-size: 15px; font-weight: 850; }
.option-address, .option-meta { color: var(--muted); font-size: 12px; font-weight: 600; }
.option-address { margin-top: 3px; }
.option-meta { margin-top: 2px; }
.distance-badge { flex: 0 0 auto; padding: 3px 7px; border-radius: 999px; font-size: 11px; font-weight: 850; white-space: nowrap; }
.distance-badge.in-range { color: #0e5b36; background: #dff5e9; }
.distance-badge.out-range { color: #7a3b00; background: #ffedcf; }
.distance-badge.unavailable { color: #536878; background: #edf1f4; }
.selected-pharmacy { margin-top: 13px; padding: 13px; border: 1px solid #b7d4dc; border-radius: 10px; background: #f0fafb; }
.selected-pharmacy.empty-state { color: var(--muted); background: #f8fbfc; }
.selected-pharmacy h3 { margin: 0 0 5px; font-size: 17px; }
.selected-pharmacy p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.missing-pharmacy-probe, .advanced-diagnostics { margin-top: 14px; }
.missing-pharmacy-probe > summary, .advanced-diagnostics > summary { min-height: 48px; padding: 13px 15px; border: 1px solid #aabfcd; border-radius: 11px; color: var(--ink); background: #fff; box-shadow: 0 5px 20px rgb(32 74 101 / 7%); font-size: 16px; }
.missing-pharmacy-probe[open] > summary, .advanced-diagnostics[open] > summary { margin-bottom: 10px; border-color: var(--brand); }
.probe-card { margin-bottom: 0; }
.probe-card form { display: grid; grid-template-columns: 1fr; gap: 9px; }
.probe-card button { min-height: 48px; }
.probe-results { margin-top: 12px; }
.probe-result { margin-top: 8px; padding: 11px; border: 1px solid #d1dfe7; border-radius: 9px; background: #f8fbfc; }
.probe-result.alert { border-color: #e2a041; background: #fff7e8; }
.probe-result.ok { border-color: #8bc6a5; background: #effaf4; }
.probe-result h3 { margin: 0 0 4px; font-size: 15px; }
.probe-result p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.advanced-intro { margin: 0 4px 12px; color: var(--muted); font-size: 13px; }

.preview-card pre, .inspector pre {
    width: 100%; min-height: 50px;
    max-height: 280px;
    margin: 5px 0 14px;
    padding: 11px;
    overflow: auto;
    border: 1px solid #c3d5df;
    border-radius: 8px;
    color: #eaf5fa;
    background: #112e40;
    font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre-wrap;
    word-break: break-word;
}

.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.metric { min-width: 0; padding: 10px; border: 1px solid #d2e0e8; border-radius: 8px; background: #f8fbfc; }
.metric dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric dd { margin: 3px 0 0; overflow-wrap: anywhere; font-size: 16px; font-weight: 800; }
.empty-state { display: block; color: var(--muted); }
.table-wrap { margin-top: 16px; overflow-x: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px; border-bottom: 1px solid #d5e1e8; text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
.inspector { margin-top: 16px; }
summary { padding: 8px 0; color: var(--brand-dark); font-weight: 800; cursor: pointer; }

.result-list { position: relative; min-height: 52px; max-height: 520px; margin-top: 16px; overflow: auto; border: 1px solid #c7d8e3; border-radius: 10px; background: #f8fbfc; }
.full-list { max-height: 520px; }
.virtual-spacer { width: 1px; pointer-events: none; }
.virtual-layer { position: absolute; top: 0; right: 0; left: 0; }
.result-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; height: 84px; padding: 10px 11px; overflow: hidden; border-bottom: 1px solid #d3e0e7; background: #fff; }
.result-row:nth-child(even) { background: #f5fafb; }
.pharmacy-name { overflow: hidden; font-weight: 850; text-overflow: ellipsis; white-space: nowrap; }
.row-index, .pharmacy-detail { color: var(--muted); font-size: 12px; }
.pharmacy-detail { grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.render-presets { margin: 0 0 16px; }
.render-presets button { min-height: 39px; padding: 6px 10px; font-size: 13px; }

@media (min-width: 620px) {
    .page-shell { padding-right: 24px; padding-left: 24px; }
    .card { padding: 20px; }
    .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .compact-fields { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .check-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .patient-search-form .primary-card { padding: 22px; }
    .coverage-summary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .probe-card form { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
    .probe-card button { min-width: 170px; }
}

@media (min-width: 850px) {
    .field-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .field-grid label:nth-child(5), .field-grid label:nth-child(6), .field-grid label:nth-child(7), .field-grid label:nth-child(8) { grid-column: span 2; }
    .compact-fields { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .check-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
