/* ───────── Tokens ───────── */
:root {
    --bg: #f6f4f0;
    --surface: #ffffff;
    --surface-2: #faf9f6;
    --border: #e7e3dc;
    --border-strong: #d6d0c5;
    --text: #1f1d1a;
    --text-2: #5f5a52;
    --text-3: #8f897e;
    --accent: #2f5bd3;
    --accent-hover: #2349b3;
    --accent-soft: #eaf0fd;
    --success: #1f7a4d;
    --success-soft: #e5f4ec;
    --warning: #9a6200;
    --warning-soft: #fdf2dc;
    --danger: #b3261e;
    --danger-soft: #fce9e7;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(31, 29, 26, .04), 0 2px 8px rgba(31, 29, 26, .04);
    --shadow-lg: 0 12px 40px rgba(31, 29, 26, .16);
    --header-h: 56px;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
button { font: inherit; color: inherit; }
h1:focus { outline: none; }
.muted { color: var(--text-3); }

/* ───────── Shell & header ───────── */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.app-header {
    height: var(--header-h);
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand:hover { color: var(--text); }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions form { margin: 0; }
.header-link { color: var(--text-2); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 8px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-link:hover { background: var(--surface); color: var(--text); }
.header-button { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-size: 14px; cursor: pointer; color: var(--text); text-decoration: none; }
.header-button:hover { background: var(--surface-2); color: var(--text); }
.header-button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Account / static pages */
.page-main { flex: 1; padding: 24px 16px 48px; }
.page-card { max-width: 960px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow); }
.page-card h1 { font-size: 26px; font-weight: 650; letter-spacing: -.01em; }
.page-card .btn-primary, .btn.btn-primary { background: var(--accent); border-color: var(--accent); }

/* ───────── Buttons ───────── */
.btn-primary, .btn-ghost, .btn-danger {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border-radius: 999px; padding: 9px 18px; font-weight: 550; font-size: 14px; cursor: pointer;
    border: 1px solid transparent; text-decoration: none; transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #8f1e18; }
.btn-ghost.small { padding: 6px 12px; font-size: 13px; }
button:disabled, .btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0 0 0 6px; font-size: 13px; }

.icon-btn {
    width: 32px; height: 32px; display: inline-grid; place-items: center; flex: none;
    border-radius: 8px; border: none; background: transparent; color: var(--text-2); cursor: pointer; position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.icon-actions { display: flex; gap: 2px; }
.visually-hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

/* ───────── Workspace ───────── */
.workspace-main { flex: 1; min-height: 0; min-width: 0; padding: 0 16px 16px; display: flex; }
.workspace {
    /* min-width: 0 stops long file names from stretching the layout wider than the screen */
    flex: 1; min-height: 0; min-width: 0; display: grid; gap: 14px;
    grid-template-columns: 250px minmax(280px, 340px) minmax(0, 1fr);
    height: calc(100dvh - var(--header-h) - 16px);
}
.workspace-loading { margin: 80px auto; color: var(--text-2); display: flex; align-items: center; gap: 12px; }

.panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 18px 18px 10px; }
.panel-head-text { min-width: 0; }
.panel-title { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); margin: 0; }
.panel-title.folder-title { font-size: 18px; text-transform: none; letter-spacing: -.01em; color: var(--text); word-break: break-word; }
.panel-sub { margin: 4px 0 0; color: var(--text-2); font-size: 13px; }

/* Folders */
.folder-list { list-style: none; margin: 0; padding: 4px 10px; overflow-y: auto; flex: 1; }
.folder-item {
    width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
    background: none; border: none; text-align: left; cursor: pointer; color: var(--text-2);
}
.folder-item:hover { background: var(--surface-2); color: var(--text); }
.folder-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count { font-size: 12px; color: var(--text-3); background: var(--surface-2); border-radius: 999px; padding: 0 8px; }
.folder-item.active .folder-count { background: #fff; color: var(--accent); }
.add-folder { margin: 10px 14px 16px; }

/* Documents */
.panel-docs { overflow-y: auto; overflow-x: hidden; }
.upload-actions { padding: 4px 16px 10px; display: flex; flex-direction: column; gap: 8px; }
.dropzone {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
    border: 1.5px dashed var(--border-strong); border-radius: 14px; padding: 18px 12px; color: var(--text-2);
    cursor: pointer; background: var(--surface-2); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone small { color: var(--text-3); font-size: 12px; }
.dropzone-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.upload-folder { align-self: center; position: relative; }

.doc-list { list-style: none; margin: 0; padding: 0 10px 16px; }
.doc-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 8px; border-radius: var(--radius-sm); margin: 0 6px; }
.panel-docs > .doc-item { margin: 0 16px; }
.doc-item:hover { background: var(--surface-2); }
.doc-item.has-error { background: var(--danger-soft); }
.doc-icon { color: var(--text-3); margin-top: 2px; }
.doc-type {
    flex: none; width: 38px; height: 26px; margin-top: 1px; border-radius: 6px; display: grid; place-items: center;
    font-size: 10px; font-weight: 700; letter-spacing: .03em; background: #eef0f3; color: #4b5563;
}
.type-pdf { background: #fde8e6; color: #b3261e; }
.type-docx { background: #e6eefc; color: #2349b3; }
.type-md, .type-markdown { background: #ede9fe; color: #5b3fb8; }
.doc-body { flex: 1; min-width: 0; }
.doc-name { display: block; font-weight: 550; color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.doc-name:hover { color: var(--accent); text-decoration: underline; }
.doc-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 12px; color: var(--text-3); margin-top: 3px; }
.doc-error { font-size: 12.5px; color: var(--danger); margin-top: 4px; }
.doc-actions { display: flex; opacity: .55; transition: opacity .15s; }
.doc-item:hover .doc-actions, .doc-actions:focus-within { opacity: 1; }
.doc-actions .icon-btn { width: 28px; height: 28px; }

.badge {
    display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600;
    padding: 1px 8px; border-radius: 999px; background: #eef0f3; color: #4b5563;
}
.badge-ready { background: var(--success-soft); color: var(--success); }
.badge-processing, .badge-uploading { background: var(--warning-soft); color: var(--warning); }
.badge-failed { background: var(--danger-soft); color: var(--danger); }
.dot-pulse { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

.empty-panel { margin: 24px 16px; padding: 24px; text-align: center; color: var(--text-3); border-radius: 14px; background: var(--surface-2); }
.empty-panel p { margin: 8px 0 0; font-size: 14px; }
.notice { margin: 4px 16px 8px; font-size: 13px; color: var(--text-2); background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }

/* Chat */
.panel-chat { position: relative; }
.chat-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 24px 8px; flex-wrap: wrap; }
.chat-title { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -.015em; }
.chat-sub { margin: 2px 0 0; color: var(--text-2); font-size: 14px; }
.chat-head-actions { display: flex; gap: 8px; align-items: center; }
.scope-pill {
    margin: 4px 24px 0; align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; max-width: calc(100% - 48px);
    font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 12px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.history { position: relative; }
.history-menu {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: 300px; max-height: 340px; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px;
}
.history-row { display: flex; align-items: center; border-radius: 8px; }
.history-row:hover, .history-row.active { background: var(--surface-2); }
.history-item { flex: 1; min-width: 0; display: flex; gap: 8px; justify-content: space-between; background: none; border: none; padding: 8px 10px; text-align: left; cursor: pointer; font-size: 13.5px; }
.history-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-date { color: var(--text-3); font-size: 12px; flex: none; }

.chat-scroll { flex: 1; overflow-y: auto; padding: 16px 24px; display: flex; flex-direction: column; gap: 18px; scroll-behavior: smooth; }
.chat-empty { margin: auto; text-align: center; max-width: 440px; color: var(--text-2); }
.chat-empty-icon { width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.suggestions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.suggestion { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; text-align: left; cursor: pointer; font-size: 14px; color: var(--text); }
.suggestion:hover { border-color: var(--accent); background: var(--accent-soft); }

.msg { display: flex; gap: 12px; max-width: 820px; width: 100%; }
.msg-user { justify-content: flex-end; align-self: flex-end; }
.msg-user .bubble { background: var(--accent-soft); color: #18306f; padding: 10px 16px; border-radius: 18px 18px 4px 18px; max-width: 85%; white-space: pre-wrap; word-break: break-word; }
.msg-ai { align-self: flex-start; }
.ai-avatar { flex: none; width: 30px; height: 30px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; margin-top: 2px; }
.ai-body { min-width: 0; flex: 1; }
.answer { word-break: break-word; }
.answer p { margin: 0 0 10px; }
.answer p:last-child { margin-bottom: 0; }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 22px; }
.answer li { margin: 3px 0; }
.answer h3, .answer h4, .answer h5, .answer h6 { font-size: 15px; font-weight: 650; margin: 14px 0 6px; }
.answer code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 4px; font-size: 13px; }

.sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.sources-label { font-size: 12px; font-weight: 650; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; margin-right: 4px; }
.source-chip {
    display: inline-flex; align-items: center; gap: 6px; max-width: 280px; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 999px; padding: 3px 12px 3px 4px; font-size: 13px;
}
.source-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.source-chip.deleted { opacity: .6; text-decoration: line-through; }
.source-num { width: 20px; height: 20px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; display: grid; place-items: center; flex: none; }
.source-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.typing { display: flex; align-items: center; gap: 4px; color: var(--text-3); padding-top: 6px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
.typing em { margin-left: 8px; font-size: 13px; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }

.chat-error { margin: 0 24px 8px; display: flex; gap: 8px; align-items: center; background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 8px 12px; font-size: 13.5px; }

.composer {
    margin: 0 24px; display: flex; align-items: flex-end; gap: 8px; background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: 22px; padding: 8px 8px 8px 18px; transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea { flex: 1; border: none; outline: none; resize: none; font: inherit; background: transparent; padding: 6px 0; max-height: 200px; color: var(--text); }
.composer textarea:disabled { background: transparent; color: var(--text-3); }
.send-btn { width: 38px; height: 38px; flex: none; border-radius: 50%; border: none; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; }
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.composer-hint { margin: 6px 24px 14px; font-size: 12px; color: var(--text-3); text-align: center; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
.spinner.small { width: 16px; height: 16px; border-color: rgba(255,255,255,.4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty hero */
.empty-hero { margin: 6vh auto; max-width: 560px; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 40px; box-shadow: var(--shadow); text-align: center; }
.empty-hero-icon { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.empty-hero h1 { font-size: 26px; font-weight: 650; margin: 0 0 8px; }
.empty-hero p { color: var(--text-2); }
.steps { text-align: left; margin: 20px auto 28px; max-width: 400px; color: var(--text-2); padding-left: 20px; }
.steps li { margin: 6px 0; }

/* Drawer, kai-modal, kai-toast */
.drawer-backdrop, .kai-backdrop { position: fixed; inset: 0; background: rgba(31, 29, 26, .28); z-index: 40; animation: fade .15s; }
.drawer {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 41; background: var(--surface);
    box-shadow: var(--shadow-lg); padding: 22px; overflow-y: auto; animation: slide .2s ease-out;
}
.drawer-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.drawer-kicker { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
.drawer-title { font-size: 18px; margin: 4px 0 0; word-break: break-word; }
.excerpt-label { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.excerpt { margin: 0 0 20px; background: var(--surface-2); border-left: 3px solid var(--accent); border-radius: 0 10px 10px 0; padding: 12px 14px; font-size: 14px; color: var(--text-2); white-space: pre-wrap; }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.kai-modal {
    position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(460px, calc(100vw - 32px));
    background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 24px; animation: fade .15s;
}
.kai-modal h2 { font-size: 19px; margin: 0 0 14px; word-break: break-word; }
.kai-modal p { color: var(--text-2); font-size: 14px; }
.kai-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13.5px; font-weight: 550; }
.field input, .field textarea {
    font: inherit; font-weight: 400; border: 1px solid var(--border-strong); border-radius: 10px; padding: 9px 12px; outline: none; background: var(--surface);
}
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; font-size: 13.5px; }
.kai-toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; background: var(--text); color: #fff; border-radius: 12px; padding: 10px 16px; font-size: 14px; box-shadow: var(--shadow-lg); }
.kai-toast .link-btn { color: #b8c8f5; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }

.mobile-tabs { display: none; }

/* Public page: just the search/chat, centred */
.workspace.public { grid-template-columns: minmax(0, 880px); justify-content: center; }
.scope-select { margin: 4px 24px 0; display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); align-self: flex-start; max-width: calc(100% - 48px); }
.scope-select select {
    font: inherit; font-size: 14px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border-strong);
    border-radius: 999px; padding: 6px 30px 6px 12px; max-width: 100%; text-overflow: ellipsis; cursor: pointer;
}

/* Admin / collections additions */
.header-link.active { background: var(--surface); color: var(--text); font-weight: 550; }
.header-link.subtle { font-size: 13px; color: var(--text-3); }
.header-link .short { display: none; }
@media (max-width: 520px) {
    .header-link .long { display: none; }
    .header-link .short { display: inline; }
    .brand-name { display: none; }
}
.field.compact { margin-bottom: 0; font-size: 12.5px; }
.field.compact input { padding: 7px 10px; font-size: 13.5px; }
.doc-group {
    display: flex; align-items: center; gap: 6px; margin: 12px 8px 2px; padding: 0 6px;
    font-size: 12px; font-weight: 650; color: var(--text-3); letter-spacing: .02em;
}
.docs-caption { margin: 0 18px 4px; font-size: 13px; }
.folder-flag { width: 18px; height: 18px; border-radius: 50%; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.dot-pulse.warn { color: var(--warning); background: var(--warning); }
.small-note { font-size: 12.5px; margin: -6px 0 12px; }
.panel-sub code, .kai-modal code { font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 4px; color: var(--text-2); }
.upload-row { margin: 0 16px; }

/* ───────── Responsive ───────── */
@media (max-width: 1100px) {
    .workspace { grid-template-columns: 220px minmax(260px, 300px) minmax(0, 1fr); }
}

@media (max-width: 860px) {
    .app-header { padding: 0 16px; }
    /* Header: keep navigation, drop the account email; short labels on phones */
    .header-link.account { display: none; }
    .header-actions { gap: 4px; }
    .header-link.nav { padding: 8px 10px; }
    .header-button { padding: 8px 12px; }
    .desktop-only { display: none; }

    /* Inputs at 16px so iOS Safari doesn't zoom the page when they're focused */
    input, textarea, select, .composer textarea, .field input, .field textarea, .field.compact input { font-size: 16px !important; }

    /* Comfortable touch targets (~40-44px) */
    .icon-btn, .doc-actions .icon-btn { width: 40px; height: 40px; }
    .folder-item { padding: 12px 12px; }
    .source-chip { padding: 6px 12px 6px 6px; min-height: 40px; }
    .brand-mark { width: 36px; height: 36px; }
    .btn-ghost.small { padding: 9px 14px; }
    .send-btn { width: 44px; height: 44px; }
    .doc-item { padding: 10px 6px; }
    .doc-actions { flex-wrap: wrap; justify-content: flex-end; max-width: 84px; }

    /* Dialogs near the top so the on-screen keyboard doesn't cover them */
    .kai-modal { top: 16px; transform: translateX(-50%); max-height: calc(100dvh - 32px); overflow-y: auto; }
    .kai-toast { width: calc(100vw - 32px); bottom: calc(76px + env(safe-area-inset-bottom)); }
    .workspace-main { padding: 0 8px 0; }
    .workspace { display: flex; flex-direction: column; height: calc(100dvh - var(--header-h)); gap: 0; }
    .workspace > .panel { display: none; flex: 1; border-radius: var(--radius) var(--radius) 0 0; }
    .workspace[data-tab="folders"] > .panel-folders,
    .workspace[data-tab="docs"] > .panel-docs,
    .workspace[data-tab="chat"] > .panel-chat, .workspace.public > .panel-chat { display: flex; }
    .workspace.public { padding-bottom: env(safe-area-inset-bottom); }
    .scope-select { margin-left: 16px; }
    .mobile-tabs {
        display: flex; flex: none; background: var(--surface); border-top: 1px solid var(--border);
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    }
    .mobile-tabs button {
        flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px;
        background: none; border: none; padding: 6px; border-radius: 10px; color: var(--text-3); cursor: pointer;
    }
    .mobile-tabs button.active { color: var(--accent); background: var(--accent-soft); }
    .chat-head, .chat-scroll { padding-left: 16px; padding-right: 16px; }
    .composer, .chat-error { margin-left: 12px; margin-right: 12px; }
    .scope-pill { margin-left: 16px; }
    .chat-title { font-size: 19px; }
    .doc-actions { opacity: 1; }
    .history-menu { width: min(300px, calc(100vw - 32px)); }
    .page-card { padding: 20px; }
    .empty-hero { padding: 28px 20px; margin: 16px; }
}

/* ───────── Template bits kept for Identity pages ───────── */
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; }

#blazor-error-ui {
    color-scheme: light only; background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box; display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; border-radius: 10px; }
.blazor-error-boundary::after { content: "An error has occurred." }

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder { color: var(--bs-secondary-color); text-align: end; }
.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder { text-align: start; }

/* ───────── Medical calculators ───────── */
.workspace.public { grid-template-columns: 260px minmax(0, 880px); }
.panel-calcs { padding: 18px 14px; gap: 6px; overflow-y: auto; }
.calc-head { display: flex; align-items: center; gap: 10px; padding: 0 4px 8px; }
.calc-head .panel-title { margin: 0; }
.calc-head-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #2f5bd3, #7c3aed); box-shadow: 0 4px 12px rgba(79, 70, 229, .3); flex: none; }
.calc-head-sub { margin: 0; font-size: 12.5px; color: var(--text-3); }
.calc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.calc-link {
    width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; cursor: pointer; font: inherit; color: var(--text);
    border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: var(--surface);
    transition: transform .15s, box-shadow .15s, border-color .15s;
}
.calc-link:hover, .calc-link:focus-visible { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(31, 29, 26, .08); outline: none; }
.calc-link.bmi:hover, .calc-link.bmi:focus-visible { border-color: #14b8a6; }
.calc-link.crcl:hover, .calc-link.crcl:focus-visible { border-color: #8b5cf6; }
.calc-badge { flex: none; width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-weight: 750; font-size: 13px; letter-spacing: .02em; }
.calc-link.bmi .calc-badge, .calc-modal.bmi .calc-modal-head { background: linear-gradient(135deg, #0ea5a4, #22c55e); }
.calc-link.crcl .calc-badge, .calc-modal.crcl .calc-modal-head { background: linear-gradient(135deg, #6366f1, #a855f7); }
.calc-link-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.calc-link-text strong { font-size: 14px; font-weight: 620; }
.calc-link-text small { font-size: 12.5px; color: var(--text-3); }
.calc-arrow { font-size: 22px; color: var(--text-3); }
.calc-disclaimer { margin: 12px 4px 0; font-size: 11.5px; line-height: 1.45; color: var(--text-3); }

.calc-modal {
    position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); display: flex; flex-direction: column;
    background: var(--surface); border-radius: 20px; box-shadow: 0 24px 64px rgba(31, 29, 26, .28); overflow: hidden; animation: calcpop .18s ease-out;
}
@keyframes calcpop { from { opacity: 0; transform: translate(-50%, -48%) scale(.98); } }
.calc-modal-head { color: #fff; padding: 20px 22px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex: none; }
.calc-modal-head h2 { margin: 2px 0 0; font-size: 19px; font-weight: 680; line-height: 1.25; }
.calc-modal-kicker { font-size: 11.5px; text-transform: uppercase; letter-spacing: .1em; opacity: .85; font-weight: 650; }
.calc-close { width: 36px; height: 36px; border-radius: 50%; border: none; background: rgba(255, 255, 255, .2); color: #fff; font-size: 22px; line-height: 1; cursor: pointer; flex: none; }
.calc-close:hover { background: rgba(255, 255, 255, .32); }
.calc-modal-body { padding: 20px 22px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.calc-modal-body > * { flex-shrink: 0; }
.calc-modal.bmi { --calc: #0d9488; --calc-soft: #e6f7f5; }
.calc-modal.crcl { --calc: #7c3aed; --calc-soft: #f1ebfe; }

.seg { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; font: inherit; font-size: 14px; border: none; background: none; border-radius: 9px; padding: 9px 8px; cursor: pointer; color: var(--text-2); font-weight: 550; }
.seg button.on { background: var(--calc); color: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .12); }
.seg.small button { font-size: 13px; padding: 8px 6px; }
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.calc-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); min-width: 0; }
.calc-field small { font-weight: 400; color: var(--text-3); }
.calc-input { display: flex; align-items: center; border: 1.5px solid var(--border-strong); border-radius: 12px; background: var(--surface); overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.calc-input:focus-within { border-color: var(--calc); box-shadow: 0 0 0 3px var(--calc-soft); }
.calc-input input { flex: 1; min-width: 0; border: none; outline: none; font: inherit; font-size: 16px; font-weight: 500; padding: 10px 12px; background: none; color: var(--text); }
.calc-input em, .calc-input select { font-style: normal; font-size: 13px; color: var(--text-2); background: var(--surface-2); border: none; border-left: 1px solid var(--border); padding: 0 12px; align-self: stretch; display: flex; align-items: center; font-weight: 550; }
.calc-input select { font-family: inherit; cursor: pointer; outline: none; }
.calc-go { font: inherit; font-size: 15px; font-weight: 650; color: #fff; border: none; border-radius: 12px; padding: 12px; cursor: pointer; background: var(--calc); box-shadow: 0 6px 16px color-mix(in srgb, var(--calc) 35%, transparent); }
.calc-go:hover { filter: brightness(1.08); }
.calc-modal.bmi .calc-go { background: linear-gradient(135deg, #0ea5a4, #16a34a); }
.calc-modal.crcl .calc-go { background: linear-gradient(135deg, #6366f1, #9333ea); }

.calc-result { border-radius: 14px; padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; border: 1px solid; animation: fade .2s; }
.calc-result-main { display: flex; align-items: baseline; gap: 6px; }
.calc-value { font-size: 34px; font-weight: 750; letter-spacing: -.02em; line-height: 1; }
.calc-unit { font-size: 14px; font-weight: 600; opacity: .8; }
.calc-pill { font-size: 13px; font-weight: 650; padding: 5px 12px; border-radius: 999px; background: rgba(255, 255, 255, .7); }
.tone-good { background: #e7f6ee; border-color: #b7e2c9; color: #146c43; }
.tone-info { background: #e8f1fd; border-color: #bcd3f6; color: #1d4ed8; }
.tone-warn { background: #fdf3df; border-color: #f2d8a2; color: #8a5300; }
.tone-bad { background: #fdeceb; border-color: #f4c3bf; color: #a3231b; }

.bmi-scale { position: relative; display: flex; flex: none; height: 10px; border-radius: 999px; overflow: visible; margin: 2px 2px 6px; }
.bmi-scale span:first-child { border-radius: 999px 0 0 999px; }
.bmi-scale span:nth-child(6) { border-radius: 0 999px 999px 0; }
.bmi-scale .seg-u { flex: 6.5; background: #60a5fa; } .bmi-scale .seg-h { flex: 6.5; background: #34d399; }
.bmi-scale .seg-o { flex: 5; background: #fbbf24; } .bmi-scale .seg-1 { flex: 5; background: #fb923c; }
.bmi-scale .seg-2 { flex: 5; background: #f87171; } .bmi-scale .seg-3 { flex: 8; background: #dc2626; }
.bmi-scale i { position: absolute; top: -5px; width: 20px; height: 20px; margin-left: -10px; border-radius: 50%; background: #fff; border: 3px solid var(--text); box-shadow: 0 2px 6px rgba(0, 0, 0, .2); transition: left .3s; }

.calc-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.calc-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); padding: 6px 10px; border-bottom: 1px solid var(--border); }
.calc-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.calc-table tr.hit td { background: var(--calc-soft); color: var(--calc); font-weight: 650; }
.calc-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.calc-stats div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; }
.calc-stats small { font-size: 12px; color: var(--text-3); }
.calc-stats strong { font-size: 16px; }
.calc-warn { font-size: 13px; background: var(--warning-soft); color: var(--warning); border-radius: 10px; padding: 8px 12px; }
.calc-note { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--text-3); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }

@media (max-width: 1100px) { .workspace.public { grid-template-columns: 230px minmax(0, 1fr); } }
@media (max-width: 860px) {
    /* Phones: calculators become a compact strip above the chat */
    .workspace.public > .panel-calcs { display: flex; flex: none; border-radius: var(--radius); margin: 8px 0; padding: 10px; overflow: visible; }
    .panel-calcs .calc-head, .panel-calcs .calc-disclaimer, .calc-link-text small, .calc-arrow { display: none; }
    .calc-list { flex-direction: row; gap: 8px; }
    .calc-list li { flex: 1; min-width: 0; }
    .calc-link { padding: 8px; gap: 8px; min-height: 44px; }
    .calc-badge { width: 36px; height: 36px; font-size: 11.5px; border-radius: 10px; }
    .calc-link-text strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .calc-modal { top: 12px; transform: translateX(-50%); max-height: calc(100dvh - 24px); animation: fade .15s; }
    .calc-grid { grid-template-columns: 1fr; }
    .calc-modal-head, .calc-modal-body { padding-left: 16px; padding-right: 16px; }
    .calc-stats { grid-template-columns: 1fr 1fr 1fr; }
    .calc-stats div { padding: 8px; }
}
.calc-link-text .sm { display: none; }
@media (max-width: 860px) { .calc-link-text .lg { display: none; } .calc-link-text .sm { display: inline; } }

.calc-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ───────── Admin: users ───────── */
.users-head h1 { margin: 0 0 4px; }
.users-head .muted { margin: 0 0 20px; max-width: 640px; }
.users-add { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 24px; display: flex; flex-direction: column; gap: 12px; }
.users-add-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; }
.users-add-grid.two { grid-template-columns: 1fr auto; margin-bottom: 8px; }
.users-add-grid .field { margin: 0; }
.users-check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); }
.users-check input { width: 18px; height: 18px; }
.users-add-actions { display: flex; }
.users-add .small-note { margin: 0; }
.users-created { background: var(--success-soft); color: var(--success); border-radius: 10px; padding: 10px 12px; font-size: 14px; word-break: break-word; }
.users-created code { font-size: 14px; background: #fff; border-radius: 6px; padding: 1px 6px; color: var(--text); }
.users-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.users-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.users-row:first-child { border-top: none; }
.users-who { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.users-avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none; }
.users-meta { display: flex; flex-direction: column; min-width: 0; }
.users-email { font-weight: 550; overflow-wrap: anywhere; }
.users-tags { display: flex; gap: 6px; margin-top: 2px; }
.users-tag { font-size: 11.5px; font-weight: 650; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }
.users-tag.admin { background: #f1ebfe; border-color: #ddd0fb; color: #6d28d9; }
.users-tag.locked { background: var(--danger-soft); border-color: #f4c3bf; color: var(--danger); }
.users-tag.you { background: var(--accent-soft); border-color: #c9d7f8; color: var(--accent); }
.users-actions { display: flex; gap: 8px; }
.btn-ghost.danger-text { color: var(--danger); }
@media (max-width: 640px) {
    .users-add-grid { grid-template-columns: 1fr; }
    .users-add-grid.two { grid-template-columns: 1fr; }
    .users-actions { width: 100%; }
    .users-actions .btn-ghost { flex: 1; min-height: 40px; }
}
/* Calculator list: compact text cards (overrides the earlier card styles) */
.panel-calcs { padding: 14px 12px; }
.calc-title { padding: 0 4px 10px; }
.calc-list { gap: 6px; }
.calc-link {
    display: block; padding: 10px 12px; border-radius: 10px; gap: 0; font-size: 14px; font-weight: 550; line-height: 1.3;
    border: 1px solid var(--border); border-left: 3px solid var(--accent); background: var(--surface);
}
.calc-link.bmi { border-left-color: #14b8a6; }
.calc-link.crcl { border-left-color: #8b5cf6; }
.calc-link:hover, .calc-link:focus-visible { transform: none; background: var(--surface-2); box-shadow: none; }
@media (max-width: 860px) {
    /* Phones: one swipeable row of chips above the chat */
    .workspace.public > .panel-calcs { padding: 8px; }
    .panel-calcs .calc-title { display: none; }
    .calc-list { flex-direction: row; gap: 6px; overflow-x: auto; scrollbar-width: none; }
    .calc-list li { flex: none; }
    .calc-link { white-space: nowrap; padding: 9px 12px; min-height: 40px; }
}
/* ───────── Admin: drug data ───────── */
.dd-intro { max-width: 720px; margin: 0 0 18px; }
.dd-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px; margin-bottom: 22px; }
.dd-card p { margin: 0; }
.dd-status { display: flex; align-items: center; gap: 12px; }
.dd-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dd-dot.ok { background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
.dd-dot.off { background: var(--text-3); }
.dd-progress { display: flex; align-items: center; gap: 10px; color: var(--accent); font-weight: 550; }
.dd-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.dd-upload { cursor: pointer; position: relative; }
.dd-upload.disabled { opacity: .5; pointer-events: none; }
.dd-h2 { margin: 6px 0 10px; }
.dd-tables { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; margin-bottom: 22px; }
.dd-table { display: flex; justify-content: space-between; gap: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.dd-table span { color: var(--text-2); }
.dd-code { background: #1f1d1a; color: #f3efe7; border-radius: 10px; padding: 12px 14px; font-size: 12.5px; overflow-x: auto; margin: 0; }
.small { font-size: 13px; }
.source-chip.external .source-num { background: #e8f1fd; color: #1d4ed8; }
/* Header on small phones: four admin links + sign out on one line */
.header-button { white-space: nowrap; }
@media (max-width: 420px) {
    .header-actions { gap: 0; }
    .header-link.nav { padding: 8px 7px; font-size: 13.5px; }
    .header-button { padding: 7px 10px; font-size: 13.5px; }
    .brand-mark { width: 32px; height: 32px; }
}
/* ───────── Drug label comparison ───────── */
.page-main:has(.cmp-page) { padding: 12px 12px 32px; }
.page-card:has(.cmp-page) { max-width: none; padding: 20px; }
.cmp-page { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.cmp-hero h1 { margin: 0 0 6px; }
.cmp-hero p { margin: 0; max-width: 820px; }
.cmp-card { border: 1px solid var(--border); border-radius: 14px; padding: 18px; background: var(--surface); min-width: 0; }
.cmp-step { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 650; margin: 0 0 12px; }
.cmp-step span { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; flex: none; }

.cmp-search { position: relative; }
.cmp-search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.cmp-search-input { width: 100%; border: 1px solid var(--border-strong); border-radius: 12px; padding: 12px 44px 12px 42px; font: inherit; font-size: 15.5px; background: var(--surface); }
.cmp-search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cmp-search-spin { position: absolute; right: 14px; top: 50%; margin-top: -9px; }
.cmp-results { margin-top: 8px; border: 1px solid var(--border); border-radius: 12px; max-height: 420px; overflow-y: auto; background: var(--surface); box-shadow: var(--shadow); }
.cmp-result { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.cmp-result:last-child { border-bottom: 0; }
.cmp-result:hover { background: var(--surface-2); }
.cmp-result.added { background: var(--accent-soft); }
.cmp-result-main { all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cmp-result-main:disabled { cursor: default; }
.cmp-result-name { font-weight: 650; }
.cmp-result-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--text-2); }
.cmp-appl { font-variant-numeric: tabular-nums; font-weight: 550; }
.cmp-result-products { font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-result-tags { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.cmp-tag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); white-space: nowrap; }
.cmp-tag.ok { background: var(--success-soft); border-color: transparent; color: var(--success); }
.cmp-tag.warn { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.cmp-add { border: 1px solid var(--accent); color: var(--accent); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.cmp-add:hover:not(:disabled) { background: var(--accent); color: #fff; }
.cmp-add:disabled { border-color: var(--border-strong); color: var(--text-3); opacity: 1; }
.cmp-empty { padding: 14px; color: var(--text-2); }
.cmp-more { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; }

.cmp-selected { margin-top: 14px; }
.cmp-selected-head { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.cmp-hint { margin: 6px 0 0; }
.cmp-chips { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.cmp-chip { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; column-gap: 8px; align-items: center; background: var(--accent-soft); border: 1px solid #cfdcfa; border-radius: 12px; padding: 6px 6px 6px 12px; max-width: 100%; }
.cmp-chip-name { font-weight: 650; font-size: 14px; grid-column: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-chip-sub { font-size: 12px; color: var(--text-2); grid-column: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-chip-x { grid-column: 2; grid-row: 1 / span 2; border: 0; background: transparent; font-size: 20px; line-height: 1; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; color: var(--text-2); }
.cmp-chip-x:hover { background: #fff; color: var(--danger); }

.cmp-sec-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.cmp-sec-head p { margin: -6px 0 0; }
.cmp-sec-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.cmp-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.cmp-group { border: 1px solid var(--border); border-radius: 12px; padding: 4px 12px 10px; margin: 0; min-width: 0; background: var(--surface-2); }
.cmp-group-legend { float: left; width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 6px 0; margin: 0; font-size: 14px; }
.cmp-group-toggle { all: unset; cursor: pointer; font-weight: 650; display: inline-flex; align-items: center; gap: 6px; }
.cmp-group-toggle:focus-visible { outline: 2px solid var(--accent); border-radius: 4px; }
.cmp-group .chev { display: inline-block; transition: transform .15s; font-size: 16px; color: var(--text-3); }
.cmp-group .chev.open { transform: rotate(90deg); }
.cmp-count { font-size: 12px; font-weight: 550; color: var(--text-3); }
.cmp-checks { clear: both; display: flex; flex-direction: column; gap: 2px; }
.cmp-check { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.cmp-check:hover { background: var(--surface); }
.cmp-check.on { background: var(--accent-soft); }
.cmp-check input { width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.cmp-topic { font-size: 11px; color: var(--text-3); margin-left: auto; white-space: nowrap; }
.cmp-go { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.cmp-go .form-error { flex-basis: 100%; }
.cmp-go-btn { padding: 12px 22px; font-size: 15px; }
.cmp-prep { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.cmp-prep li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cmp-prep .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); flex: none; }
.cmp-prep li.bad .dot { background: var(--danger); }
.cmp-prep .spinner { width: 14px; height: 14px; }

.cmp-res-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.cmp-res-head .cmp-step { margin: 0; }
.cmp-views { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 999px; padding: 3px; background: var(--surface-2); }
.cmp-views button { border: 0; background: transparent; border-radius: 999px; padding: 6px 14px; font-size: 13.5px; font-weight: 550; cursor: pointer; color: var(--text-2); }
.cmp-views button.on { background: var(--accent); color: #fff; }
.cmp-find { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.cmp-find input { border: 1px solid var(--border-strong); border-radius: 10px; padding: 7px 12px; font: inherit; font-size: 14px; width: min(320px, 100%); }
.cmp-find input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cmp-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.cmp-tab { flex: none; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-size: 13.5px; font-weight: 550; cursor: pointer; white-space: nowrap; color: var(--text); }
.cmp-tab:hover { background: var(--surface-2); }
.cmp-tab.on { background: var(--text); border-color: var(--text); color: #fff; }
.cmp-tab-wrap { display: inline-flex; align-items: center; flex: none; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); }
.cmp-tab-wrap .cmp-tab { border: 0; background: transparent; }
.cmp-tab-wrap.on { background: var(--text); border-color: var(--text); }
.cmp-tab-wrap.on .cmp-tab, .cmp-tab-wrap.on .cmp-tab-new { color: #fff; }
.cmp-tab-new { text-decoration: none; padding: 4px 10px 4px 2px; font-size: 13px; color: var(--text-2); }
.cmp-tab-new:hover { color: var(--accent); }
.cmp-now { font-size: 15px; font-weight: 650; margin: 10px 0; }

.cmp-cols { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.cmp-col { border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column; min-width: 0; background: var(--surface); }
.cmp-col-head { padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: 12px 12px 0 0; }
.cmp-col-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cmp-col-title .cmp-tab-new { padding: 2px 6px; }
.cmp-col-name { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.cmp-col-sub { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 12.5px; color: var(--text-2); }
.cmp-col-ver { font-size: 12px; color: var(--text-3); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.cmp-col-body { padding: 12px 14px; overflow-y: auto; max-height: 72vh; }
.cmp-drug-view { border: 1px solid var(--border); border-radius: 12px; margin-top: 8px; }
.cmp-drug-view > .cmp-col-head { border-radius: 12px 12px 0 0; }
.cmp-toc { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.cmp-drug-sec { padding: 14px; border-bottom: 1px solid var(--border); scroll-margin-top: 12px; }
.cmp-drug-sec:last-child { border-bottom: 0; }
.cmp-drug-sec > h3 { font-size: 16px; font-weight: 700; margin: 0 0 8px; }

.cmp-status { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; margin-bottom: 10px; }
.cmp-status.none { background: var(--surface-2); border: 1px dashed var(--border-strong); color: var(--text-2); }
.cmp-status.bad { background: var(--danger-soft); color: var(--danger); }
.cmp-status.warn { background: var(--warning-soft); color: var(--warning); }
.cmp-status.info { background: var(--accent-soft); color: #23439c; }
.cmp-passage { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px dashed var(--border); }
.cmp-passage:last-child { border-bottom: 0; margin-bottom: 0; }
.cmp-passage.related { border-left: 3px solid var(--warning-soft); padding-left: 10px; }
.cmp-src { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.cmp-src-sec { font-weight: 650; color: var(--accent); }
.cmp-src-page { font-variant-numeric: tabular-nums; }
.cmp-src-in { color: var(--text-3); }
.cmp-text { font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.cmp-text.clamped { max-height: 420px; overflow: hidden; -webkit-mask-image: linear-gradient(#000 75%, transparent); mask-image: linear-gradient(#000 75%, transparent); }
.cmp-expand { padding: 4px 0; }
.cmp-note { font-size: 12px; color: var(--warning); margin: 6px 0 0; }
.cmp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cmp-actions .btn-ghost.small { padding: 4px 10px; font-size: 12.5px; }
.cmp-foot { margin: 14px 0 0; }
.cmp-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow-lg); z-index: 50; }
mark.cmp-hit { background: #ffe58a; color: inherit; padding: 0 1px; border-radius: 2px; }

/* Label text (server-generated, escaped HTML) */
.lbl p { margin: 0 0 8px; }
.lbl p.lbl-h { font-weight: 650; margin-top: 10px; }
.lbl p.lbl-bullet { padding-left: 14px; text-indent: -12px; }
.lbl ul, .lbl ol { margin: 0 0 8px; padding-left: 20px; }
.lbl li > p { margin-bottom: 2px; }
.lbl h4.lbl-sub { font-size: 14px; font-weight: 700; margin: 14px 0 6px; color: var(--text); }
.lbl h4.lbl-sub.lvl2, .lbl h4.lbl-sub.lvl3 { font-size: 13.5px; font-weight: 650; color: var(--text-2); }
.lbl-table { overflow-x: auto; margin: 6px 0 10px; }
.lbl table { border-collapse: collapse; font-size: 12.5px; min-width: 100%; }
.lbl th, .lbl td { border: 1px solid var(--border-strong); padding: 4px 6px; vertical-align: top; text-align: left; }
.lbl th { background: var(--surface-2); font-weight: 650; }
.lbl caption { caption-side: top; text-align: left; font-weight: 650; padding-bottom: 4px; }

@media (max-width: 980px) { .cmp-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) {
    .page-card:has(.cmp-page) { padding: 16px; }
    .cmp-card { padding: 14px; }
    .cmp-groups { grid-template-columns: minmax(0, 1fr); }
    .cmp-result { grid-template-columns: minmax(0, 1fr) auto; }
    .cmp-result-tags { display: none; }
    /* Phones: stacked cards instead of side-by-side columns. */
    .cmp-cols { grid-auto-flow: row; grid-auto-columns: auto; overflow-x: visible; }
    .cmp-col-body { max-height: none; }
    .cmp-sec-tools .btn-ghost.small { padding: 5px 10px; }
}
