@font-face {
    font-family: 'Public Sans';
    src: url('/fonts/public-sans.woff2') format('woff2');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

:root {
    color-scheme: light;
    --bg: #F5F7F9;
    --surface: #FFFFFF;
    --surface-muted: #EEF2F5;
    --border: #DDE3E8;
    --field-border: #8A99A6;
    --text: #14212B;
    --muted: #4A5A67;
    --accent: #0B6E79;
    --accent-strong: #08464E;
    --accent-soft: #E6F1F2;
    --warn: #8A4B00;
    --warn-soft: #FFF3E0;
    --danger: #A12A2A;
    --danger-soft: #FCEBEB;
    --radius: 14px;
    --font: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.015em; }
h1 { font-size: clamp(28px, 5vw, 36px); margin: 0 0 8px; }
h2 { font-size: 22px; margin: 0 0 8px; }
h3 { font-size: 18px; margin: 0 0 6px; }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 16px; top: 16px; z-index: 100; padding: 8px 12px; background: var(--surface); }
.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header-inner {
    max-width: 1120px; margin: 0 auto; padding: 14px 16px;
    display: flex; align-items: center; justify-content: space-between; gap: 8px 24px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); text-decoration: none; }
.brand span { color: var(--text); font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.space-name { font-size: 18px; font-weight: 700; color: var(--accent); text-decoration: none; padding-left: 12px; border-left: 2px solid var(--border); }
.header-search { flex: 1 1 220px; max-width: 420px; margin-left: auto; }
.header-search input {
    width: 100%; height: 40px; padding: 0 14px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg); font-size: 15px;
}
.user-nav { display: flex; align-items: center; gap: 14px; font-size: 15px; font-weight: 600; }
.user-nav a { text-decoration: none; }
.inline-form { display: inline; margin: 0; }
@media (max-width: 700px) {
    .header-search { order: 3; flex-basis: 100%; max-width: none; }
    .site-header-inner { justify-content: flex-start; }
    .user-nav { margin-left: auto; }
}
.space-disclaimer { background: var(--warn-soft); color: #4A2E00; font-size: 14px; }
.space-disclaimer div { max-width: 1120px; margin: 0 auto; padding: 8px 16px; }

/* Layout */
.site-main { flex: 1 0 auto; width: 100%; max-width: 1120px; margin: 0 auto; padding: 28px 16px 48px; }
.page-intro { margin-bottom: 24px; }
.page-intro p { margin: 0; color: var(--muted); max-width: 680px; }
.panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 22px; margin-bottom: 20px; min-width: 0;
}
.panel > p { color: var(--muted); }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.panel-grid .panel { margin-bottom: 0; }
.with-sidebar { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.with-sidebar > .sidebar { flex: 1 1 220px; position: sticky; top: 16px; }
.with-sidebar > .content { flex: 999 1 560px; min-width: 0; }
@media (max-width: 800px) { .with-sidebar > .sidebar { position: static; } }
.toc { display: flex; flex-direction: column; gap: 2px; padding: 8px; }
.toc a { padding: 10px 12px; border-radius: 10px; text-decoration: none; font-weight: 600; color: #3A4A57; }
.toc a:hover { background: var(--accent-soft); color: var(--accent-strong); }
.sources { font-size: 14px; color: var(--muted); }
.sources ul { margin: 6px 0 0; padding-left: 20px; }
.note { padding: 12px 16px; border-radius: 10px; background: var(--warn-soft); color: #4A2E00; font-size: 15px; }

/* Buttons and fields */
.button {
    display: inline-flex; align-items: center; justify-content: center;
    height: 48px; padding: 0 22px; border: 0; border-radius: 12px;
    background: var(--accent); color: #FFFFFF; font-weight: 700; cursor: pointer; text-decoration: none;
}
.button:hover { background: var(--accent-strong); color: #FFFFFF; }
.search-form .button { height: 52px; }
.link-button { padding: 0; border: 0; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin: 16px 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.field input, .field select {
    height: 48px; padding: 0 12px; border: 1.5px solid var(--field-border); border-radius: 10px;
    background: var(--surface); font-size: 18px; width: 100%;
}
.result { padding: 18px 20px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-strong); }
.result-label { font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.result-value { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.result-working { font-size: 15px; color: #24343F; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.formula { font-size: 14px; color: var(--muted); margin: 12px 0 0; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.abbr { font-weight: 700; white-space: nowrap; }
td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.group-row td { background: var(--bg); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.flag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.flag.do-not-use { background: var(--danger-soft); color: var(--danger); }
.flag.error-prone { background: var(--warn-soft); color: var(--warn); }
.filter-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 14px; }
.filter-bar input {
    flex: 1 1 260px; height: 48px; padding: 0 14px; border: 1.5px solid var(--field-border);
    border-radius: 10px; background: var(--surface); font-size: 16px;
}
.filter-count { font-size: 14px; color: var(--muted); }

/* Drug lookup */
.drug-result { margin-top: 20px; }
.drug-result h2 { margin-bottom: 2px; }
.drug-meta { font-size: 14px; color: var(--muted); margin: 0 0 14px; }
.label-section { margin-top: 14px; }
.label-section p { white-space: pre-line; margin: 4px 0 0; font-size: 15px; }
.label-section.is-boxed { border: 2px solid var(--text); border-radius: 10px; padding: 12px 14px; }
details.label-section summary { cursor: pointer; font-weight: 700; padding: 6px 0; }

/* Legal */
.prose { max-width: 760px; }
.prose h2 { margin-top: 28px; }
.prose li { margin-bottom: 4px; }

/* Footer */
.site-footer { background: var(--surface); border-top: 1px solid var(--border); }
.site-footer-inner {
    max-width: 1120px; margin: 0 auto; padding: 24px 16px calc(28px + env(safe-area-inset-bottom));
    display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px 24px; font-size: 14px; color: var(--muted);
}
.site-footer p { margin: 0; max-width: 520px; }
.site-footer strong { color: var(--text); }
.legal-nav { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }

/* Consent banner */
.consent {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
}
.consent-inner {
    max-width: 760px; margin: 0 auto; padding: 18px 20px;
    display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
    background: var(--text); color: #F5F7F9; border-radius: 14px; box-shadow: 0 8px 28px rgba(20, 33, 43, 0.25);
}
.consent p { margin: 0; flex: 1 1 300px; font-size: 15px; }
.consent a { color: #9ED8DE; }
.consent-actions { display: flex; gap: 8px; }
.consent button {
    width: 104px; height: 44px; border: 1.5px solid #9ED8DE; border-radius: 10px;
    background: transparent; color: #F5F7F9; font-weight: 700; cursor: pointer;
}
.consent button[data-consent="granted"] { background: #9ED8DE; color: var(--text); }

/* Buttons */
.button-small { height: 36px; padding: 0 14px; border-radius: 10px; font-size: 14px; }
.button-secondary { background: var(--surface); color: var(--accent-strong); border: 1.5px solid var(--border); }
.button-secondary:hover { background: var(--accent-soft); color: var(--accent-strong); }
.danger { color: var(--danger); }
.button.danger { background: var(--danger); color: #FFFFFF; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.empty { color: var(--muted); padding: 12px 0; }
.narrow { max-width: 640px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; }
.errors { padding: 12px 16px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); }
.errors p { margin: 0 0 4px; font-weight: 700; }
.errors ul { margin: 0; padding-left: 20px; }

/* Hub and space */
.hero { padding: 24px 0 8px; max-width: 720px; }
.hero h1 { font-size: clamp(30px, 5vw, 42px); }
.hero p { font-size: 18px; color: var(--muted); }
.space-grid { list-style: none; padding: 0; margin: 0 0 32px; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.space-card {
    display: flex; flex-direction: column; gap: 4px; padding: 20px; height: 100%;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: var(--text);
}
.space-card:hover { border-color: var(--accent); color: var(--text); }
.space-card-title { font-size: 20px; font-weight: 700; color: var(--accent-strong); }
.space-card-tagline { color: var(--muted); font-size: 15px; }
.space-card-meta { font-size: 13px; color: var(--muted); margin-top: auto; padding-top: 8px; }
.space-intro { margin-bottom: 24px; }
.space-intro p { color: var(--muted); font-size: 17px; margin: 0; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 24px; }
.sheet-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.sheet-card a {
    display: flex; flex-direction: column; gap: 3px; padding: 14px 16px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; text-decoration: none; color: var(--text);
}
.sheet-card a:hover { border-color: var(--accent); color: var(--text); }
.sheet-card-kind { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.sheet-card-title { font-size: 17px; font-weight: 700; }
.sheet-card-summary { font-size: 15px; color: var(--muted); }
.sheet-card-meta { font-size: 13px; color: var(--muted); }

/* Sheet */
.sheet { max-width: 820px; }
.sheet-kind { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.sheet-summary { font-size: 18px; color: var(--muted); margin: 0 0 6px; }
.sheet-meta { font-size: 14px; color: var(--muted); margin: 0; }
.score { font-weight: 700; color: var(--muted); }
.sheet-footer { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; align-items: flex-start; }
.report summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.report form { margin-top: 10px; max-width: 480px; }
textarea {
    width: 100%; padding: 10px 12px; border: 1.5px solid var(--field-border); border-radius: 10px; background: var(--surface); font: inherit; resize: vertical;
}
.field textarea { font-size: 15px; font-weight: 400; }

/* Markdown */
.prose { overflow-wrap: anywhere; }
.prose h1, .prose h2, .prose h3 { margin: 1.4em 0 0.5em; }
.prose table { width: auto; min-width: 50%; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; display: block; overflow-x: auto; }
.prose code { background: var(--surface-muted); padding: 1px 5px; border-radius: 5px; font-size: 0.92em; }
.prose pre { background: var(--surface-muted); padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { margin: 0; padding: 4px 16px; border-left: 3px solid var(--border); color: var(--muted); }
.prose img { max-width: 100%; }

/* Calculator */
.calc-widget { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin: 20px 0; }
.calc-widget h3 { margin-top: 0; }
.calc-widget .fields { margin-top: 0; }
.unit { font-weight: 400; color: var(--muted); }
.calc-results { display: flex; flex-direction: column; gap: 8px; }
.calc-result { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; padding: 12px 16px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-strong); }
.calc-result-label { font-weight: 600; }
.calc-result-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.calc-band { font-size: 18px; }

/* Editor */
.editor { display: flex; flex-direction: column; gap: 14px; }
.editor-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.preview { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 18px; min-height: 120px; }
.preview-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.advanced summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.builder { display: flex; flex-direction: column; gap: 16px; }
.builder-section { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.builder-section h2 { font-size: 18px; margin: 0 0 4px; }
.builder-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; align-items: end; padding: 12px 0; border-top: 1px solid var(--border); }
.builder-row .field input, .builder-row .field select { height: 42px; font-size: 15px; }
.builder-row .wide { grid-column: 1 / -1; }
.builder-error { color: var(--danger); font-size: 14px; grid-column: 1 / -1; }
.history li { margin-bottom: 8px; }
.report-list { padding-left: 20px; }
.report-list li { margin-bottom: 18px; }
.search-form { display: flex; gap: 8px; max-width: 620px; margin-bottom: 12px; }
.search-form input { flex: 1 1 auto; min-width: 0; height: 48px; padding: 0 16px; border: 1.5px solid var(--field-border); border-radius: 12px; background: var(--surface); font-size: 16px; }
.sources { font-size: 14px; color: var(--muted); margin-top: 28px; }
