/* ==========================================================================
   Script Assessment and Plans | app styles
   Hand-written (no build step). Colors, fonts and shapes follow the original
   React app's Tailwind theme: primary #0193BA, ink #1C202E, Manrope for text,
   Poppins for headings, round inputs and buttons, white bordered cards.
   ========================================================================== */

@font-face {
    font-family: "Manrope";
    font-style: normal;
    font-weight: 200 800;
    font-display: swap;
    src: url("/fonts/manrope-latin.woff2") format("woff2");
}
@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("/fonts/poppins-400-latin.woff2") format("woff2");
}
@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("/fonts/poppins-500-latin.woff2") format("woff2");
}
@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("/fonts/poppins-600-latin.woff2") format("woff2");
}

:root {
    --primary-50: #EAFAFF;
    --primary-100: #C5F3FF;
    --primary-700: #0193BA;
    --primary-800: #007391;
    --primary-900: #005268;
    --ink: #1C202E;
    --ink-2: #3F4559;
    --muted: #6B7280;
    --muted-2: #9CA3AF;
    --line: #E5E7EB;
    --line-2: #D1D5DB;
    --soft: #F3F4F6;
    --surface: #FFFFFF;
    --page: #FBFBFB;
    --danger: #F87171;
    --danger-ink: #B91C1C;
    --danger-bg: #FEF2F2;
    --ok-ink: #15803D;
    --ok-bg: #F0FDF4;
    --warn-ink: #C2410C;
    --warn-bg: #FFF7ED;
    --focus: #CCFBF1;
    --ghost: #9CA3AF;
    --radius: 16px;
    --font: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-head: "Poppins", "Manrope", ui-sans-serif, system-ui, sans-serif;
    --shadow-float: 0 10px 30px -8px rgba(28, 32, 46, 0.22), 0 2px 6px rgba(28, 32, 46, 0.08);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--page);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

img, svg { display: block; max-width: 100%; }
img { height: auto; }

a { color: var(--primary-700); }
a:hover { color: var(--primary-800); }

h1, h2, h3, h4 { margin: 0; font-weight: 500; }
p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

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

.skip-link {
    position: absolute; left: 16px; top: -48px; z-index: 100;
    background: var(--surface); padding: 8px 14px; border-radius: 8px;
}
.skip-link:focus { top: 12px; }

/* Icons ------------------------------------------------------------------- */
.icon { width: 20px; height: 20px; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; }
.icon-md { width: 24px; height: 24px; }
.icon-lg { width: 32px; height: 32px; }
.icon-nav { width: 22px; height: 22px; stroke-width: 2; }

/* Text -------------------------------------------------------------------- */
.page-title {
    font-family: var(--font-head);
    font-weight: 400;
    font-size: 24px;
    line-height: 30px;
    color: var(--ink);
}
.section-title {
    font-family: var(--font-head);
    font-weight: 500;
    font-size: 18px;
    line-height: 26px;
    color: var(--ink);
}
.muted { color: var(--muted); }
.small { font-size: 14px; line-height: 20px; }
.tiny { font-size: 12px; line-height: 16px; }
.lead { font-size: 18px; line-height: 28px; color: var(--ink-2); }
.text-danger { color: var(--danger-ink); }
.text-ok { color: var(--ok-ink); }
.nowrap { white-space: nowrap; }

@media (min-width: 1024px) {
    .page-title { font-size: 34px; line-height: 40px; }
}

/* Buttons ----------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 24px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: var(--primary-700);
    color: #FFFFFF;
    font-size: 18px;
    font-weight: 500;
    line-height: 24px;
    text-decoration: none;
    white-space: nowrap;
    transition: opacity 0.15s;
}
.btn:hover { color: #FFFFFF; opacity: 0.85; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.35; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-md { padding: 10px 20px; font-size: 16px; }
.btn-sm { padding: 6px 14px; font-size: 14px; line-height: 20px; }
.btn-outline { background: var(--surface); color: var(--primary-700); border-color: var(--primary-700); }
.btn-outline:hover { color: var(--primary-800); }
.btn-deep { background: var(--primary-800); }
.btn-danger { background: var(--danger); }
.btn-quiet { background: transparent; color: var(--ink-2); border-color: var(--line-2); }
.btn-quiet:hover { color: var(--ink); background: var(--soft); opacity: 1; }
.btn .icon { width: 18px; height: 18px; }

.link-btn {
    padding: 0;
    border: 0;
    background: none;
    color: var(--primary-700);
    font-size: 14px;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.link-btn:hover { color: var(--primary-800); }
.link-btn-danger { color: var(--danger-ink); }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
}
.icon-btn:hover { background: var(--soft); color: var(--ink); }

/* Forms ------------------------------------------------------------------- */
.form { display: flex; flex-direction: column; gap: 24px; }
.form-row { display: grid; gap: 24px; }
@media (min-width: 1024px) { .form-row-2 { grid-template-columns: 1fr 1fr; gap: 12px; } }

.field { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.label { font-size: 16px; font-weight: 600; color: var(--ink); }
.label-hint { font-weight: 400; color: var(--muted); font-size: 14px; }
@media (min-width: 1024px) { .page-auth .label { font-size: 20px; } }

.input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 14px 18px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
}
.input-wrap:focus-within { box-shadow: 0 0 0 3px var(--focus); }
.input-wrap.has-error { border-color: #EF4444; }
.input-wrap.has-error:focus-within { box-shadow: 0 0 0 3px #FEE2E2; }
.input-wrap input,
.input-wrap select {
    flex: 1;
    min-width: 0;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 16px;
    line-height: 22px;
}
.input-wrap input::placeholder { color: var(--muted-2); }
.input-wrap .icon-btn { width: 28px; height: 28px; color: var(--primary-700); }
@media (min-width: 1024px) { .page-auth .input-wrap input { font-size: 18px; } }

.input, .select, .textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    background: var(--surface);
    font-size: 15px;
    line-height: 22px;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary-700); box-shadow: 0 0 0 3px var(--focus); }
.textarea { resize: vertical; min-height: 120px; }
.has-error .input, .input.has-error, .select.has-error, .textarea.has-error { border-color: #EF4444; }

.field-error { color: var(--danger-ink); font-size: 14px; line-height: 20px; }
.field-hint { color: var(--muted); font-size: 14px; line-height: 20px; }

.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary-700); }

.form-alert {
    padding: 12px 16px;
    border: 1px solid #FECACA;
    border-radius: 12px;
    background: var(--danger-bg);
    color: var(--danger-ink);
    font-size: 15px;
}
.form-note {
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--soft);
    color: var(--ink-2);
    font-size: 15px;
}

.checklist {
    margin: 0;
    padding: 12px 20px;
    border-radius: 12px;
    background: var(--soft);
    font-size: 14px;
    line-height: 22px;
    color: var(--ink);
}
.checklist ul { margin: 4px 0 0; padding-left: 20px; }
.checklist li.is-met { color: #16A34A; }
@media (min-width: 1024px) { .page-auth .checklist { font-size: 17px; line-height: 28px; } }

.turnstile { display: flex; flex-direction: column; align-items: center; gap: 8px; }

/* Top bar ------------------------------------------------------------------ */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
    background: var(--page);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}
.topbar-logo img { height: 36px; width: auto; }
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }

.topnav { order: 3; width: 100%; overflow-x: auto; }
.topnav ul { display: flex; margin: 0; padding: 0; list-style: none; }
.topnav li { border-right: 1px solid var(--line); }
.topnav li:last-child { border-right: 0; }
.topnav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 2px 14px;
    color: var(--muted-2);
    font-size: 13px;
    font-weight: 300;
    text-decoration: none;
    white-space: nowrap;
}
.topnav a:hover { color: var(--ink-2); }
.topnav a.is-active { color: var(--primary-700); font-weight: 600; }

@media (min-width: 900px) {
    .topbar { padding: 18px 40px; flex-wrap: nowrap; }
    .topbar-logo img { height: 40px; }
    .topnav { order: 0; width: auto; margin: 0 auto; }
    .topnav a { flex-direction: row; gap: 8px; padding: 4px 14px; font-size: 18px; line-height: 28px; }
}

.user-button {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 8px 12px;
    border: 1px solid var(--primary-700);
    border-radius: 999px;
    background: var(--surface);
    color: var(--primary-700);
}
.user-button[aria-expanded="true"] { box-shadow: 0 0 0 3px var(--focus); }

/* Menus (dropdowns float above the page, so they get a shadow, not a border) */
.menu { position: relative; }
.menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 40;
    min-width: 220px;
    padding: 6px 0;
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-float);
}
.menu-panel-right { left: auto; right: 0; }
.menu-panel form { margin: 0; }
.menu-meta {
    padding: 10px 18px 12px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    font-size: 15px;
}
.menu-meta span { display: block; font-weight: 400; font-size: 13px; color: var(--muted); word-break: break-all; }
.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 18px;
    border: 0;
    background: none;
    color: var(--ink);
    font-size: 16px;
    text-align: left;
    text-decoration: none;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--soft); color: var(--ink); outline: none; }
.menu-item-danger, .menu-item-danger:hover { color: var(--danger-ink); }

/* Page shell ----------------------------------------------------------------- */
.page { width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; }
.page-wide { max-width: 1480px; }
.page-narrow { max-width: 760px; }
.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}
.page-head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.page-intro { margin: -12px 0 24px; color: var(--muted); max-width: 760px; }
@media (min-width: 900px) { .page { padding: 40px 40px 64px; } }

.site-footer { padding: 24px 16px 32px; text-align: center; font-size: 12px; color: var(--muted); }

.back-link { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 16px; font-weight: 600; text-decoration: none; }

/* Hairline-divided sections, used on Settings and in panels. */
.stack-section { padding: 28px 0; border-top: 1px solid var(--line); }
.stack-section:first-of-type { border-top: 0; padding-top: 0; }
.stack-section > .section-title { margin-bottom: 6px; }
.stack-section > .field-hint { margin-bottom: 18px; max-width: 760px; }

/* Auth pages ----------------------------------------------------------------- */
.auth { display: flex; min-height: 100vh; max-width: 1512px; margin: 0 auto; }
.auth-main { flex: 1; display: flex; }
.auth-inner {
    display: flex;
    flex-direction: column;
    gap: 40px;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: 64px 24px;
}
.auth-logo img { height: auto; width: 100%; max-width: 300px; margin: 0 auto; }
.auth-title { font-family: var(--font-head); font-weight: 500; font-size: 30px; line-height: 36px; color: var(--ink); }
.auth-text { font-family: var(--font-head); font-size: 18px; line-height: 28px; color: var(--ink); }
.auth-links { display: flex; justify-content: flex-end; margin-top: -10px; }
.auth-links a, .auth-alt { font-weight: 600; font-size: 15px; text-decoration: underline; text-underline-offset: 3px; }
.auth-alt { display: block; text-align: center; margin-top: -10px; }
.auth-back { display: inline-flex; align-items: center; gap: 4px; font-family: var(--font-head); color: var(--ink); text-decoration: none; }
.auth-back .icon { color: var(--primary-700); }
.auth-art { display: none; }
@media (min-width: 1024px) {
    .auth-main { flex: 0 0 40rem; }
    .auth-inner { justify-content: center; padding: 48px 112px; }
    .auth-logo img { margin: 0; max-width: 320px; }
    .auth-title { font-size: 36px; line-height: 44px; }
    .auth-art { display: flex; flex: 1; align-items: center; justify-content: center; padding: 32px; background: var(--primary-50); }
    .auth-art img { width: 100%; max-width: 680px; }
}

/* Guest message pages (404, no access, signed out) --------------------------- */
.guest {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    min-height: 100vh;
    padding: 64px 16px 96px;
    text-align: center;
    background: #F9FAFB;
}
.guest-art { width: 100%; max-width: 420px; }
.guest-title { font-family: var(--font-head); font-size: 34px; line-height: 42px; }
.guest-text { font-size: 20px; color: var(--muted-2); max-width: 560px; }
.guest-logo { height: 40px; width: auto; margin-top: auto; }
@media (min-width: 1024px) {
    .guest-title { font-size: 48px; line-height: 56px; }
    .guest-logo { position: fixed; left: 40px; bottom: 40px; }
}

/* Locked (no subscription yet) ------------------------------------------------ */
.locked { display: flex; flex-direction: column; align-items: center; gap: 28px; max-width: 900px; margin: 0 auto; text-align: center; }
.locked-bar {
    position: relative;
    width: 100%;
    padding: 18px 24px;
    border: 1px solid var(--line-2);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted-2);
    text-align: left;
    overflow: hidden;
}
.locked-bar span { filter: blur(3px); }
.locked-bar p {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    background: rgba(219, 219, 219, 0.35);
    color: var(--ink-2);
    font-size: 15px;
    text-align: center;
}
.locked-bar a { font-weight: 600; color: var(--ink-2); }
.locked-art { width: 80%; max-width: 420px; margin-top: 24px; }

/* Search bar ------------------------------------------------------------------- */
.searchbar {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 8px 8px 22px;
    border: 1px solid var(--line-2);
    border-radius: 999px;
    background: var(--surface);
}
.searchbar:focus-within { border-color: var(--primary-700); }
.searchbar input {
    flex: 1;
    min-width: 0;
    padding: 8px 0;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 16px;
}
.searchbar .btn { padding: 10px 16px; }
.searchbar-hint { margin-top: 10px; text-align: center; font-size: 14px; color: var(--muted); }

/* Search results (the old DiagnosisElement card) ------------------------------- */
.search-page { display: flex; flex-direction: column; gap: 28px; align-items: center; }
.search-page .page-title { text-align: center; }
.search-box { width: 100%; max-width: 1100px; }
.results { display: flex; flex-direction: column; gap: 28px; width: 100%; max-width: 1100px; }
.result {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}
.result-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.result-name { font-size: 20px; line-height: 28px; font-weight: 500; }
.result-name b { font-weight: 800; }
.result-meta { margin-top: 4px; font-size: 14px; color: var(--muted); }
.result-why { font-size: 14px; color: var(--muted); }
.result-actions { display: flex; align-items: flex-start; gap: 10px; flex-shrink: 0; }
.result-body.is-collapsed { max-height: 4.6em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent); }
.result-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    align-self: center;
    border: 0;
    background: none;
    color: var(--primary-700);
    font-size: 16px;
}
.result-toggle .icon { transition: transform 0.3s; }
.result-toggle[aria-expanded="true"] .icon { transform: rotate(180deg); }
.result-refs { padding-top: 16px; border-top: 1px solid var(--line); }
@media (min-width: 1024px) {
    .result { padding: 32px; }
    .result-name { font-size: 24px; line-height: 32px; }
}

.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1px solid var(--primary-700);
    border-radius: 14px;
    background: var(--surface);
    color: var(--primary-700);
    font-weight: 500;
}
.copy-btn:hover { opacity: 0.85; }
.copy-btn.is-copied { background: var(--primary-700); color: #FFFFFF; }

.empty-state { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px 16px; text-align: center; }
.empty-state h2 { font-size: 24px; line-height: 32px; color: #111827; font-weight: 400; }
.empty-state p { color: var(--muted); }
.empty-state img { width: 70%; max-width: 380px; margin-top: 16px; }

/* Rendered library text ---------------------------------------------------------- */
.prose { font-size: 16px; line-height: 1.6; color: var(--ink); overflow-wrap: anywhere; }
.prose > * + * { margin-top: 0.75em; }
.prose ul, .prose ol { margin: 0.5em 0; padding-left: 1.4em; }
.prose li + li { margin-top: 0.2em; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 { font-size: 1.05em; font-weight: 700; }
.prose blockquote { margin: 0; padding-left: 14px; color: var(--ink-2); font-style: italic; }
.prose code { padding: 1px 5px; border-radius: 4px; background: var(--soft); font-size: 0.92em; }
.prose strong { font-weight: 700; }

/* Pagination (the old app's underline style) --------------------------------------- */
.pagination { display: flex; justify-content: center; gap: 4px; padding: 16px 0; }
.pagination a, .pagination span, .pagination button {
    min-width: 36px;
    height: 40px;
    padding: 8px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--muted);
    text-align: center;
    text-decoration: none;
    font-size: 16px;
}
.pagination a:hover, .pagination button:hover { border-bottom-color: var(--primary-700); color: #4B5563; }
.pagination .is-current { border-bottom-color: var(--primary-700); background: #F9FAFB; color: #374151; font-weight: 700; }

/* Tables ------------------------------------------------------------------------- */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; color: var(--muted); }
.table th { padding: 14px 12px; text-align: left; font-weight: 600; color: var(--muted-2); border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.table td { padding: 14px 12px; border-top: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.table tbody tr:first-child td { border-top: 0; }
.table td.wrap { white-space: normal; min-width: 220px; }
.table .strong { font-weight: 600; color: var(--ink); }
.table tr.is-clickable { cursor: pointer; }
.table tr.is-clickable:hover { background: #F9FAFB; }
.table .cell-actions { width: 1%; text-align: right; }
.table-empty td { padding: 40px 12px; text-align: center; white-space: normal; }

/* Status labels (the only pill-shaped labels: they are statuses) */
.status { display: inline-block; padding: 4px 10px; border-radius: 6px; font-size: 13px; font-weight: 600; }
.status-active { color: var(--ok-ink); background: var(--ok-bg); }
.status-pending { color: var(--warn-ink); background: var(--warn-bg); }
.status-expired { color: var(--danger-ink); background: var(--danger-bg); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.toolbar .search-input {
    flex: 1 1 240px;
    max-width: 360px;
    padding: 9px 18px;
    border: 1px solid var(--muted-2);
    border-radius: 999px;
    background: var(--surface);
}
.toolbar .search-input:focus { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.toolbar .select { width: auto; border-radius: 999px; padding: 9px 14px; }

/* Dialogs (modals float, so they get a shadow and no border) ------------------------------ */
dialog.modal {
    width: min(640px, calc(100vw - 24px));
    max-height: calc(100vh - 48px);
    padding: 0;
    border: 0;
    border-radius: 16px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-float);
}
dialog.modal-wide { width: min(960px, calc(100vw - 24px)); }
dialog.modal-narrow { width: min(480px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(107, 114, 128, 0.75); }
.modal-body { position: relative; padding: 32px 24px; }
.modal-title { font-family: var(--font-head); font-weight: 500; font-size: 26px; line-height: 34px; margin-bottom: 20px; padding-right: 40px; }
.modal-close { position: absolute; top: 14px; right: 14px; }
.modal-actions { display: flex; gap: 12px; margin-top: 28px; }
.modal-actions .btn { flex: 1; }
.modal-message { color: var(--ink-2); font-size: 16px; }
@media (min-width: 768px) { .modal-body { padding: 36px 40px; } .modal-title { font-size: 30px; line-height: 38px; } }

/* Toasts ------------------------------------------------------------------------------ */
/* Bottom left: the primary buttons (Save, Copy note) sit on the right, and
   the header stays clear. Clicks go through a toast to whatever is under it;
   only its action button (Undo) takes them. */
.toasts { position: fixed; bottom: 16px; left: 16px; z-index: 200; pointer-events: none; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 32px)); }
.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-float);
    font-size: 15px;
    animation: toast-in 0.2s ease-out;
}
.toast .icon { width: 22px; height: 22px; margin-top: 1px; }
.toast-success .icon { color: #16A34A; }
.toast-error .icon { color: #DC2626; }
.toast-text { flex: 1; }
.toast-action { border: 0; background: none; color: var(--primary-700); font-weight: 700; padding: 0; pointer-events: auto; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Spinner ------------------------------------------------------------------------------- */
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--primary-700); border-radius: 50%; animation: spin 0.8s linear infinite; }
.spinner-sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 32px; color: var(--muted); }

/* Skeleton rows while the library loads */
.skeleton { display: flex; flex-direction: column; gap: 18px; width: 100%; max-width: 1100px; }
.skeleton div { height: 120px; border-radius: var(--radius); background: var(--soft); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* Plans ------------------------------------------------------------------------------------ */
.plans-head { position: relative; display: flex; align-items: center; justify-content: center; margin-bottom: 28px; }
.plans-head .back-icon { position: absolute; left: 0; color: var(--primary-900); }
.plans-head .back-icon .icon { width: 40px; height: 40px; stroke-width: 1.25; }
.plans { display: grid; gap: 20px; max-width: 900px; margin: 0 auto; }
@media (min-width: 900px) { .plans { grid-template-columns: 1fr 1fr; } }
.plan {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 24px;
    border: 1px solid #E7E8EB;
    border-radius: var(--radius);
    background: var(--surface);
}
.plan-name { display: flex; justify-content: space-between; gap: 12px; font-weight: 700; }
.plan-recommended { color: #15803D; font-size: 13px; font-weight: 700; }
.plan-price { font-size: 30px; line-height: 36px; font-weight: 700; letter-spacing: 0.02em; }
.plan-features { display: flex; flex-direction: column; gap: 10px; padding: 8px 0 12px; margin: 0; list-style: none; font-size: 14px; font-weight: 300; }
.plan-features strong { font-weight: 700; }
.plan form { margin-top: auto; }
.plan .btn { width: 100%; padding: 10px; font-size: 16px; }
.plans-art { width: 70%; max-width: 420px; margin: 40px auto 0; }
.plans-note { max-width: 900px; margin: 0 auto 20px; }

/* Composer --------------------------------------------------------------------------------- */
.compose { display: grid; gap: 28px; align-items: start; }
@media (min-width: 1100px) { .compose { grid-template-columns: minmax(0, 1fr) 400px; } }
.compose-main { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.compose-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.compose-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.library-status { display: flex; align-items: center; gap: 8px; margin-top: -10px; font-size: 14px; color: var(--muted); }
.library-status .icon { width: 18px; height: 18px; }
.library-status.is-error { color: var(--danger-ink); }

.note-section { display: flex; flex-direction: column; gap: 8px; }
.note-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.note-label { font-family: var(--font-head); font-weight: 500; font-size: 18px; color: var(--ink); }
.note-label-hint { font-size: 13px; color: var(--muted); }

/* The textarea sits on top of a mirror that draws the gray completion text in
   exactly the same place. Both share every metric below. */
.note-field { position: relative; border: 1px solid var(--line-2); border-radius: 14px; background: var(--surface); }
.note-field:focus-within { border-color: var(--primary-700); box-shadow: 0 0 0 3px var(--focus); }
.note-input, .note-mirror {
    display: block;
    width: 100%;
    margin: 0;
    padding: 14px 16px;
    border: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 26px;
    letter-spacing: normal;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: normal;
    tab-size: 4;
}
.note-input {
    position: relative;
    z-index: 1;
    min-height: 106px;
    resize: none;
    overflow: hidden;
    border-radius: 14px;
    background: transparent;
    color: var(--ink);
    outline: none;
}
.note-input::placeholder { color: var(--muted-2); }
.note-mirror {
    position: absolute;
    inset: 0;
    z-index: 0;
    color: transparent;
    pointer-events: none;
    overflow: hidden;
}
.note-mirror .ghost { color: var(--ghost); }
.note-mirror .caret-mark { display: inline-block; width: 0; }

.suggest-list {
    position: absolute;
    z-index: 30;
    left: 12px;
    right: 12px;
    max-width: 640px;
    margin: 0;
    padding: 6px 0;
    list-style: none;
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-float);
}
.suggest-item { display: flex; flex-direction: column; gap: 2px; padding: 8px 14px; cursor: pointer; }
.suggest-item[aria-selected="true"], .suggest-item:hover { background: var(--primary-50); }
.suggest-text { font-size: 15px; line-height: 21px; color: var(--ink); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.suggest-text mark { background: none; color: var(--muted); }
.suggest-source { font-size: 12px; color: var(--muted); }
.suggest-foot { padding: 6px 14px 2px; border-top: 1px solid var(--line); margin-top: 4px; font-size: 12px; color: var(--muted); }

.keys-hint { font-size: 13px; color: var(--muted); }
.keys-hint kbd { padding: 1px 5px; border: 1px solid var(--line-2); border-radius: 4px; background: var(--surface); font-family: var(--font); font-size: 12px; }

/* The side panel: one bordered column, hairlines between items, no nested cards */
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
@media (min-width: 1100px) { .panel { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; } }
.panel-section { padding: 18px 20px; border-top: 1px solid var(--line); }
.panel-section:first-child { border-top: 0; }
.panel-section > .section-title { margin-bottom: 4px; }
.panel-search { position: relative; }
.panel-search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted-2); }
.panel-search input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    border: 1px solid var(--line-2);
    border-radius: 999px;
    background: var(--surface);
    font-size: 15px;
}
.panel-search input:focus { outline: none; border-color: var(--primary-700); box-shadow: 0 0 0 3px var(--focus); }
.panel-empty { padding-top: 6px; font-size: 14px; color: var(--muted); }

.sugg { padding: 12px 0; border-top: 1px solid var(--line); }
.sugg:first-of-type { border-top: 0; }
.sugg-name { padding: 0; border: 0; background: none; color: var(--ink); font-weight: 700; font-size: 16px; text-align: left; }
.sugg-name:hover { color: var(--primary-800); text-decoration: underline; text-underline-offset: 3px; }
.sugg-code { margin-left: 6px; font-size: 13px; color: var(--muted); font-weight: 400; }
.sugg-why { margin-top: 2px; font-size: 13px; line-height: 18px; color: var(--muted); }
.sugg-actions { display: flex; align-items: center; gap: 14px; margin-top: 8px; }

.refs { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
.refs-group + .refs-group { margin-top: 14px; }
.refs-group-name { font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.ref { font-size: 13px; line-height: 19px; color: var(--ink-2); }
.ref-note { margin-top: 3px; color: var(--muted); }
.ref-links { display: flex; gap: 12px; margin-top: 3px; font-weight: 600; }

/* Library admin ------------------------------------------------------------------------------ */
.layout-split { display: grid; gap: 28px; align-items: start; }
@media (min-width: 1100px) { .layout-split { grid-template-columns: minmax(0, 1fr) 300px; } }
.side-box { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.side-box + .side-box { margin-top: 20px; }
.cat-list { margin: 12px 0 16px; padding: 0; list-style: none; font-size: 14px; }
.cat-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); }
.cat-list li:first-child { border-top: 0; }
.cat-list .count { color: var(--muted); font-size: 13px; }
.inline-form { display: flex; gap: 8px; }
.inline-form .input { flex: 1; }

/* Diagnosis editor */
.editor { border: 1px solid var(--line-2); border-radius: 14px; background: var(--surface); overflow: hidden; }
.editor:focus-within { border-color: var(--primary-700); box-shadow: 0 0 0 3px var(--focus); }
.editor.has-error { border-color: #EF4444; }
.editor-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.editor-bar button { min-width: 34px; height: 32px; padding: 0 8px; border: 0; border-radius: 6px; background: none; color: var(--ink-2); font-size: 14px; }
.editor-bar button:hover { background: var(--soft); color: var(--ink); }
.editor-bar button[aria-pressed="true"] { background: var(--primary-50); color: var(--primary-800); }
.editor-bar .sep { width: 1px; height: 20px; margin: 0 4px; background: var(--line); }
.editor-bar .spacer { flex: 1; }
.editor textarea { display: block; width: 100%; min-height: 320px; padding: 16px; border: 0; outline: none; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; line-height: 22px; }
.editor .prose { min-height: 320px; padding: 16px 20px; }

.tags { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--surface); }
.tags:focus-within { border-color: var(--primary-700); box-shadow: 0 0 0 3px var(--focus); }
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 4px 3px 9px;
    border: 1px solid var(--line-2);
    border-radius: 6px;
    background: var(--surface);
    font-size: 14px;
    line-height: 20px;
}
.tag-text { padding: 0; border: 0; background: none; color: var(--ink); }
.tag.is-strong { border-color: var(--primary-700); }
.tag.is-strong .tag-text { font-weight: 800; color: var(--primary-900); }
.tag-remove { display: inline-flex; padding: 2px; border: 0; border-radius: 4px; background: none; color: var(--muted); }
.tag-remove:hover { background: var(--soft); color: var(--ink); }
.tag-remove .icon { width: 14px; height: 14px; }
.tags input { flex: 1 1 160px; min-width: 120px; padding: 4px; border: 0; outline: 0; font-size: 15px; background: transparent; }
.tag-suggestions { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 14px; }
.tag-suggestions button { padding: 0; border: 0; background: none; color: var(--primary-700); text-decoration: underline; text-underline-offset: 3px; }

.picked { margin: 0; padding: 0; list-style: none; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.picked li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-top: 1px solid var(--line); font-size: 14px; }
.picked li:first-child { border-top: 0; }
.picked .ref { flex: 1; font-size: 14px; }
.picked-actions { display: flex; gap: 2px; }
.picked-empty { padding: 14px; color: var(--muted); font-size: 14px; }

.picker-results { max-height: 320px; overflow-y: auto; margin-top: 12px; border: 1px solid var(--line); border-radius: 12px; }
.picker-results button { display: block; width: 100%; padding: 10px 14px; border: 0; border-top: 1px solid var(--line); background: var(--surface); text-align: left; font-size: 14px; color: var(--ink-2); }
.picker-results button:first-child { border-top: 0; }
.picker-results button:hover { background: var(--primary-50); }

.form-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; padding-top: 8px; }
.form-actions-right { display: flex; gap: 12px; margin-left: auto; }

.citation-form { display: grid; gap: 14px; }
@media (min-width: 640px) { .citation-form { grid-template-columns: repeat(6, 1fr); } .citation-form .span-6 { grid-column: span 6; } .citation-form .span-3 { grid-column: span 3; } .citation-form .span-2 { grid-column: span 2; } }
.lookup-row { display: flex; gap: 8px; }
.lookup-row .input { flex: 1; }

.import-report { margin-top: 16px; padding: 16px; border-radius: 12px; background: var(--soft); font-size: 14px; }
.import-report ul { margin: 6px 0 0; padding-left: 20px; }
.import-report details { margin-top: 10px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0 0 18px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.offline-page { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 80px 16px; text-align: center; }

.plain-link { color: inherit; text-decoration: none; }
.plain-link:hover { color: var(--primary-800); text-decoration: underline; }
.menu-panel-form { display: block; min-width: 280px; padding: 14px; }
.mt-sm { margin-top: 10px; }
.picked .ref-note { display: block; }
.toolbar-inline { margin: 0; }
.evidence-form { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 6px; }
.evidence-options { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
#evidence-results .refs { margin-top: 10px; }
#evidence-results .ref a { font-weight: 600; text-decoration: none; }
#evidence-results .ref a:hover { text-decoration: underline; }
