/* Peak AI — chat UI, vanilla CSS. Theme via [data-theme] on <html>. */

/* Icons that point in a direction (back arrow, send arrow, logout arrow): tag
   with .icon--directional and they flip horizontally when the page is RTL.
   Pure horizontal-mirror via scaleX(-1) — works on any single-path SVG without
   editing the path data. Code-block forced LTR so source stays readable. */
.icon--directional { display: inline-block; vertical-align: middle; }
[dir="rtl"] .icon--directional { transform: scaleX(-1); }
[dir="rtl"] pre, [dir="rtl"] code,
[dir="rtl"] .msg__body pre, [dir="rtl"] .msg__body code { direction: ltr; text-align: start; }
[dir="rtl"] .katex, [dir="rtl"] .katex-display { direction: ltr; }

:root, [data-theme="dark"] {
    --bg:           #0f0f10;
    --bg-elev:      #17171a;
    --bg-elev-2:    #1f1f23;
    --bg-hover:     #25252a;
    --border:       #2a2a30;
    --text:         #ececf1;
    --text-muted:   #9a9aa6;
    --text-dim:     #6b6b78;
    --accent:       #7aa6ff;
    --accent-bg:    #1f2b4d;
    --danger:       #ef6868;
    --user-bubble:  #2a2a30;
    --code-bg:      #0b0b0c;
    --shadow:       0 8px 24px rgba(0,0,0,.4);
    --radius:       12px;
    --rail-w:       260px;
    --header-h:     52px;
}

[data-theme="light"] {
    --bg:           #ffffff;
    --bg-elev:      #f6f7f9;
    --bg-elev-2:    #ececf0;
    --bg-hover:     #e4e5e9;
    --border:       #dfe1e6;
    --text:         #1a1a1d;
    --text-muted:   #5e6068;
    --text-dim:     #92949c;
    --accent:       #2563eb;
    --accent-bg:    #e0e9ff;
    --danger:       #d63030;
    --user-bubble:  #f0f0f4;
    --code-bg:      #f4f5f7;
    --shadow:       0 8px 24px rgba(20,20,30,.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
    line-height: 1.55;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── layout shell ─────────────────────────────────────────────────────── */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}
.app__body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: var(--rail-w) 1fr;
    transition: grid-template-columns .18s ease;
}
.app.sidebar-collapsed .app__body {
    grid-template-columns: 0 1fr;
}

/* ── topbar ────────────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h, 56px);
    flex-shrink: 0;
    display: flex; align-items: center;
    gap: 12px;
    padding: 0 14px 0 8px;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    z-index: 30;
}
.topbar__menu, .topbar__theme {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    border-radius: 8px;
    transition: background .12s, color .12s;
    flex-shrink: 0;
}
.topbar__menu:hover, .topbar__theme:hover {
    background: var(--bg-hover);
    color: var(--text);
}
.topbar__brand {
    display: inline-flex; align-items: center; gap: 10px;
    color: var(--text);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 8px;
}
.topbar__brand:hover { text-decoration: none; background: var(--bg-hover); }
.topbar__mark {
    width: 28px; height: 28px;
    object-fit: contain;
    flex-shrink: 0;
}
.topbar__name { font-weight: 600; letter-spacing: .01em; }

/* Theme-aware brand icon — `icon.svg` is the dark mark (use on light bg);
   `icon-light.svg` is the light mark (use on dark bg). One renders per theme. */
.brand-icon { display: none; }
[data-theme="dark"]  .brand-icon--for-dark  { display: inline-block; }
[data-theme="light"] .brand-icon--for-light { display: inline-block; }

/* ── sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
    background: var(--bg-elev);
    border-inline-end: 1px solid var(--border);
    display: flex; flex-direction: column;
    min-width: 0;
    overflow: hidden;
}
/* Collapsed: sidebar visually gone but stays in the DOM (animatable + screen-reader friendly). */
.app.sidebar-collapsed .sidebar {
    border-inline-end-color: transparent;
}
.sidebar__top {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column;
    gap: 8px;
}
.conv-search-wrap {
    position: relative;
    display: flex; align-items: center;
}
.conv-search-ico {
    position: absolute;
    inset-inline-start: 10px;
    color: var(--text-dim);
    pointer-events: none;
}
.conv-search {
    flex: 1; min-width: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    padding: 7px 10px 7px 30px;
    outline: none;
    transition: border-color .12s, background .12s;
}
.conv-search:focus { border-color: var(--text-dim); background: var(--bg-elev-2); }
.conv-search::placeholder { color: var(--text-dim); }
.conv-search::-webkit-search-cancel-button { display: none; }
.btn-new {
    width: 100%;
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-weight: 500;
    transition: background .12s;
}
.btn-new:hover { background: var(--bg-hover); }
.btn-new .plus { font-size: 18px; line-height: 1; color: var(--text-muted); }

.conversations {
    flex: 1; overflow-y: auto;
    padding: 8px;
    outline: none;
}
.conv-group {
    padding: 12px 8px 4px;
    color: var(--text-dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
}
.conv-item {
    display: flex; align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    margin-bottom: 2px;
    position: relative;
    transition: background .12s;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-elev-2); }
.conv-item__title {
    flex: 1; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-size: 14px;
}
.conv-item__menu {
    width: 24px; height: 24px;
    display: none; align-items: center; justify-content: center;
    border-radius: 4px;
    color: var(--text-muted);
}
.conv-item:hover .conv-item__menu,
.conv-item.active .conv-item__menu { display: flex; }
.conv-item__menu:hover { color: var(--text); background: rgba(255,255,255,.06); }
.conv-empty {
    padding: 16px;
    color: var(--text-dim);
    text-align: center;
    font-size: 13px;
}

.sidebar__bottom {
    border-top: 1px solid var(--border);
    padding: 10px;
}
.user-pill {
    display: flex; align-items: center; gap: 10px;
    padding: 8px;
    border-radius: 10px;
    transition: background .12s;
}
.user-pill:hover { background: var(--bg-hover); }
.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--accent-bg);
    color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 13px;
    flex-shrink: 0;
    overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-pill__info { flex: 1; min-width: 0; }
.user-pill__name {
    font-size: 13px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-pill__email {
    font-size: 11px; color: var(--text-dim);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-pill__action {
    display: flex; align-items: center; justify-content: center;
    width: 28px; height: 28px;
    border-radius: 6px;
    color: var(--text-muted);
}
.user-pill__action:hover { color: var(--text); background: var(--bg-hover); text-decoration: none; }

/* ── main chat ────────────────────────────────────────────────────────── */
.chat {
    display: flex; flex-direction: column;
    min-width: 0;
    min-height: 0;   /* fit grid cell instead of growing past .app's overflow:hidden */
    background: var(--bg);
}
.chat__header {
    height: var(--header-h);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
}
.model-pill {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 10px 6px 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 999px;
    font: inherit; font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: background .12s, border-color .12s;
}
.model-pill:hover { background: var(--bg-hover); border-color: var(--text-dim); }
.model-pill[aria-expanded="true"] { background: var(--bg-hover); border-color: var(--accent); }
.model-pill .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 8px #4ade80aa;
}
.model-pill svg { color: var(--text-muted); }

.model-menu {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 6px;
    z-index: 100;
    min-width: 260px;
}
.model-menu__item {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    width: 100%;
    text-align: start;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text);
    font: inherit; font-size: 14px;
    cursor: pointer;
    transition: background .12s;
}
.model-menu__item:hover { background: var(--bg-hover); }
.model-menu__item.is-current { background: var(--accent-bg); }
.model-menu__item.is-current svg { color: var(--accent); }
.model-menu__main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.model-menu__name { font-weight: 500; }
.model-menu__hint { font-size: 12px; color: var(--text-muted); }
.spacer { flex: 1; }

.empty-state {
    flex: 1;
    min-height: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 24px;
    text-align: center;
}
/* `display: flex` above outranks the UA `[hidden] { display: none }`,
   so the JS-driven .hidden toggle would silently fail without this. */
.empty-state[hidden], .messages[hidden] { display: none !important; }
.empty-state .logo {
    font-size: 14px; font-weight: 600;
    color: var(--accent);
    letter-spacing: .02em;
    margin-bottom: 12px;
}
.empty-state h1 {
    font-size: 28px; font-weight: 600;
    margin: 0 0 32px;
    color: var(--text);
}
.starters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 240px));
    gap: 10px;
    max-width: 520px; width: 100%;
}
.starter {
    text-align: start;
    padding: 14px 16px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: background .12s, border-color .12s;
}
.starter:hover { background: var(--bg-hover); border-color: var(--text-dim); }
.starter__title { font-size: 14px; font-weight: 500; }
.starter__sub  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── messages ─────────────────────────────────────────────────────────── */
.messages {
    flex: 1; overflow-y: auto;
    min-height: 0;   /* required for overflow-y:auto to actually scroll inside a flex column */
    padding: 24px 0 96px;
    scroll-behavior: smooth;
}
.msg {
    max-width: 768px;
    margin: 0 auto 18px;
    padding: 0 24px;
    display: flex;
    gap: 14px;
}
.msg--user { justify-content: flex-end; }
.msg__avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--bg-elev);
    color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600;
    flex-shrink: 0;
}
.msg--assistant .msg__avatar {
    background: linear-gradient(135deg, var(--accent), #a78bff);
    color: #0a0a0a;
}
.msg__col {
    flex: 0 1 auto; min-width: 0;
    max-width: 100%;
}
.msg--assistant .msg__col { flex: 1; }
.msg__body {
    min-width: 0;
    padding-top: 3px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.msg--user .msg__body {
    background: var(--user-bubble);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 16px;
    border-bottom-right-radius: 4px;
    max-width: 560px;
}
.msg__body p { margin: 0 0 8px; }
.msg__body p:last-child { margin-bottom: 0; }
.msg__body h1, .msg__body h2, .msg__body h3 {
    margin: 16px 0 6px;
}
.msg__body h1 { font-size: 22px; }
.msg__body h2 { font-size: 18px; }
.msg__body h3 { font-size: 16px; }
.msg__body ul, .msg__body ol { margin: 4px 0 8px; padding-inline-start: 22px; }
.msg__body li { margin: 2px 0; }
.msg__body code {
    background: var(--bg-elev-2);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
}
.msg__body pre.code {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0;
    overflow: hidden;
    margin: 10px 0;
    position: relative;
}
.msg__body pre.code .code__head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 10px 6px 14px;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
}
.msg__body pre.code .code__lang {
    font-size: 11px; font-weight: 500;
    text-transform: lowercase;
    letter-spacing: .02em;
}
.msg__body pre.code .copy {
    padding: 4px 8px;
    background: transparent;
    border: 0;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: background .12s, color .12s;
}
.msg__body pre.code .copy:hover { background: var(--bg-hover); color: var(--text); }
/* Bare copy button (when code block has no language → no header bar). */
.msg__body pre.code > .copy {
    position: absolute; top: 8px; right: 8px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    opacity: 0;
}
.msg__body pre.code:hover > .copy { opacity: 1; }

.msg__body pre.code code {
    display: block;
    background: none; padding: 12px 14px;
    overflow-x: auto;
    font-size: 13px; line-height: 1.55;
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Syntax-highlight palette — works in both dark and light themes via vars. */
.hl-k { color: #ff79c6; }   /* keyword (pink) */
.hl-s { color: #a3e635; }   /* string (lime) */
.hl-n { color: #fbbf24; }   /* number (amber) */
.hl-c { color: var(--text-dim); font-style: italic; }
.hl-t { color: #7aa6ff; }   /* HTML tag (accent) */
[data-theme="light"] .hl-k { color: #c026d3; }
[data-theme="light"] .hl-s { color: #15803d; }
[data-theme="light"] .hl-n { color: #b45309; }
[data-theme="light"] .hl-t { color: #2563eb; }
.msg__body blockquote {
    border-inline-start: 3px solid var(--accent);
    padding: 6px 14px;
    margin: 10px 0;
    color: var(--text-muted);
    background: rgba(122, 166, 255, .05);
    /* Rounded corners on the trailing (border-less) side, mirrors with dir. */
    border-start-start-radius: 0;
    border-end-start-radius: 0;
    border-start-end-radius: 8px;
    border-end-end-radius: 8px;
}
.msg__body blockquote br + br { display: block; content: ''; margin-top: 4px; }
.msg__body a { color: var(--accent); }
/* External-link icon — appears after links that open in a new tab,
   except inside our own structural cards (sources card already has its own host badge). */
.msg__body a[target="_blank"]:not(.sources-card__list a)::after {
    content: " ↗";
    font-size: .85em;
    color: var(--text-dim);
    margin-inline-start: 1px;
}

/* Comfortable max-width on the assistant's prose so long answers don't
   sprawl edge-to-edge on wide monitors. Code blocks and tables stay
   full-width (they have their own scroll/overflow handling). */
.msg--assistant .msg__prose { max-width: 68ch; }
.msg--assistant .msg__prose > pre.code,
.msg--assistant .msg__prose > .table-wrap { max-width: none; }

.msg__body hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* Tables wrap in a scroller so wide tables don't break the layout. */
.msg__body .table-wrap {
    margin: 10px 0;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.msg__body table {
    border-collapse: collapse;
    margin: 0;
    width: 100%;
    font-size: 13px;
}
.msg__body th, .msg__body td {
    padding: 8px 12px;
    text-align: start;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.msg__body th {
    background: var(--bg-elev);
    font-weight: 600;
    color: var(--text);
}
.msg__body tbody tr:last-child td { border-bottom: 0; }
.msg__body tbody tr:hover { background: var(--bg-hover); }

/* KaTeX containers — match the surrounding text color and keep math from
   breaking the column on overflow. */
.msg__body .katex { font-size: 1.05em; color: inherit; }
.msg__body .katex-display {
    margin: 12px 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 0;
}
.msg__body .katex-error { color: var(--danger); }

.msg__cursor {
    display: inline-block;
    width: 6px; height: 14px;
    background: var(--text-muted);
    margin-inline-start: 2px;
    vertical-align: middle;
    animation: cursor-blink 1s steps(2) infinite;
}
@keyframes cursor-blink { 50% { opacity: 0; } }

/* ── thinking dots (pre-first-token) ─────────────────────────────── */
.msg__thinking {
    display: inline-flex; gap: 4px; align-items: center;
    padding: 6px 2px;
}
.msg__thinking .dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--text-dim);
    animation: thinking-bounce 1.2s infinite ease-in-out both;
}
.msg__thinking .dot:nth-child(1) { animation-delay: -0.32s; }
.msg__thinking .dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes thinking-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: .5; }
    40%           { transform: scale(1);   opacity: 1; }
}

/* ── per-message hover actions ───────────────────────────────────── */
.msg__actions {
    display: flex; gap: 6px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity .12s;
}
.msg--user .msg__actions { justify-content: flex-end; }
.msg:hover .msg__actions,
.msg__actions:focus-within { opacity: 1; }
.msg__action {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 8px;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    font-size: 12px;
    transition: background .12s, color .12s;
}
.msg__action:hover { background: var(--bg-hover); color: var(--text); }
.msg__action svg { display: block; }
.msg__action-lbl { line-height: 1; }
.msg__action--accent { color: var(--accent); }
.msg__action--accent:hover { color: var(--accent); background: var(--accent-bg); }

/* ── inline edit (Edit & resend on user messages) ────────────────── */
.msg__edit {
    width: 100%;
    min-height: 60px;
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--accent);
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit; font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
}
.msg__edit-actions {
    display: flex; gap: 8px; justify-content: flex-end;
    margin-top: 6px;
}
.btn-ghost, .btn-primary {
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px; font-weight: 500;
    transition: background .12s, opacity .12s;
}
.btn-ghost { color: var(--text-muted); background: transparent; }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover { opacity: .85; }

/* ── composer side buttons (attach / mic / search) ───────────────── */
.btn-attach, .btn-mic, .btn-search {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    border-radius: 8px;
    align-self: flex-end;
    transition: background .12s, color .12s;
    flex-shrink: 0;
}
.btn-attach:hover, .btn-mic:hover, .btn-search:hover { background: var(--bg-hover); color: var(--text); }

.btn-mic.is-listening {
    color: var(--danger);
    background: rgba(239, 104, 104, .12);
    animation: mic-pulse 1.4s ease-in-out infinite;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 104, 104, .35); }
    50%      { box-shadow: 0 0 0 6px rgba(239, 104, 104, 0); }
}

.btn-search.is-on {
    color: var(--accent);
    background: var(--accent-bg);
}
.btn-search.is-on:hover { background: var(--accent-bg); }

.btn-mic.is-disabled { opacity: .4; }
.btn-mic.is-disabled:hover { background: transparent; color: var(--text-muted); }

/* ── sources card (above assistant reply when web search was used) ─── */
.sources-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 10px;
    overflow: hidden;
    max-width: 560px;
}
.sources-card__head {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 12px;
    background: var(--bg-elev-2);
    color: var(--text-muted);
    font-size: 12px; font-weight: 500;
    border-bottom: 1px solid var(--border);
}
.sources-card__head svg { color: var(--accent); }
.sources-card__list {
    list-style: none;
    margin: 0; padding: 4px 0;
}
.sources-card__list li { display: block; }
.sources-card__list a {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: baseline;
    gap: 8px;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
    transition: background .12s;
}
.sources-card__list a:hover { background: var(--bg-hover); text-decoration: none; }
.sources-card__num   { color: var(--accent); font-weight: 600; font-size: 12px; }
.sources-card__title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sources-card__host  { color: var(--text-dim); font-size: 11px; }

/* ── document artifacts (assistant emits <document> blocks) ──────── */
.doc-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin: 10px 0;
    overflow: hidden;
    max-width: 520px;
}
.doc-card--inflight { border-style: dashed; }

.doc-card__head {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
}
.doc-card__icon {
    width: 38px; height: 38px;
    border-radius: 9px;
    background: var(--accent-bg);
    color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.doc-card__meta {
    min-width: 0;
    flex: 1;
}
.doc-card__title {
    font-size: 14px; font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.doc-card__sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-card__actions {
    display: flex; gap: 4px;
    padding: 0 10px 10px;
}
.doc-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 10px;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text-muted);
    font-size: 12px;
    text-decoration: none;
    transition: background .12s, color .12s, border-color .12s;
}
.doc-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--text-dim);
    text-decoration: none;
}

/* Inflight indeterminate progress bar (while the closing tag hasn't arrived). */
.doc-card__bar {
    height: 3px;
    background: var(--bg-elev-2);
    overflow: hidden;
    position: relative;
}
.doc-card__bar span {
    position: absolute;
    top: 0; left: -30%;
    width: 30%;
    height: 100%;
    background: var(--accent);
    animation: doc-bar 1.2s infinite ease-in-out;
}
@keyframes doc-bar {
    0%   { left: -30%; }
    100% { left: 100%; }
}

/* legacy attachment styles below (kept) */

.attachments {
    max-width: 768px;
    margin: 0 auto 8px;
    display: flex; flex-wrap: wrap; gap: 6px;
    padding: 0 12px;
}
.attachment {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 8px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    color: var(--text);
    max-width: 280px;
}
.attachment svg { color: var(--text-muted); flex-shrink: 0; }
.attachment__name {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 180px;
}
.attachment__size { color: var(--text-dim); font-size: 11px; }
.attachment__remove {
    width: 18px; height: 18px;
    border-radius: 50%;
    color: var(--text-muted);
    font-size: 14px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    transition: background .12s, color .12s;
}
.attachment__remove:hover { background: var(--bg-hover); color: var(--text); }

/* drag overlay over the entire composer area */
.composer-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center; justify-content: center;
    background: rgba(122, 166, 255, .12);
    border: 2px dashed var(--accent);
    border-radius: 16px;
    pointer-events: none;
    z-index: 5;
}
.composer-wrap.drop-target .composer-overlay {
    display: flex;
}
.composer-overlay__inner {
    color: var(--accent);
    font-size: 14px; font-weight: 500;
    background: var(--bg-elev);
    padding: 8px 16px;
    border-radius: 999px;
}

/* file pills inside rendered user messages */
.msg__files {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-bottom: 6px;
}
.msg__file {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 8px;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    color: var(--text);
    max-width: 240px;
}
.msg__file svg { color: var(--text-muted); flex-shrink: 0; }
.msg__file-name {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg--user .msg__file { background: rgba(0,0,0,.18); }
.msg__text { white-space: pre-wrap; word-wrap: break-word; }

/* legacy single Copy button (kept for backwards compat — empty rule) */
.msg__copy { display: none; }

/* ── skeleton loader (history fetch) ─────────────────────────────── */
.msg--skel { pointer-events: none; }
.msg--skel.msg--user { justify-content: flex-end; }
.skel-line {
    height: 10px;
    background: var(--bg-elev-2);
    border-radius: 6px;
    margin: 6px 0;
    max-width: 480px;
    background: linear-gradient(90deg, var(--bg-elev) 0%, var(--bg-hover) 50%, var(--bg-elev) 100%);
    background-size: 200% 100%;
    animation: skel-shimmer 1.4s infinite;
}
@keyframes skel-shimmer {
    0%   { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* ── sticky conversation title in header ─────────────────────────── */
.chat__title {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-inline-start: 4px;
    opacity: 0;
    animation: title-fade .2s forwards;
}
.chat__title:empty { display: none; }
@keyframes title-fade { to { opacity: 1; } }

.msg__error {
    color: var(--danger);
    background: rgba(239,104,104,.08);
    border: 1px solid rgba(239,104,104,.2);
    padding: 10px 12px;
    border-radius: 8px;
}

.msg__copy {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-dim);
    opacity: 0;
    transition: opacity .12s, color .12s;
}
.msg:hover .msg__copy { opacity: 1; }
.msg__copy:hover { color: var(--text); }

/* ── composer ─────────────────────────────────────────────────────────── */
.composer-wrap {
    border-top: 1px solid transparent;
    background: linear-gradient(to top, var(--bg) 70%, rgba(15,15,16,0));
    padding: 12px 24px 14px;
    position: relative;
    flex-shrink: 0;
}
.composer {
    max-width: 768px;
    margin: 0 auto;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 16px;
    display: flex; align-items: flex-end;
    padding: 10px 12px 10px 16px;
    gap: 8px;
    transition: border-color .12s;
}
.composer:focus-within { border-color: var(--text-dim); }
.composer textarea {
    flex: 1; min-width: 0;
    background: transparent; border: 0; outline: none;
    color: var(--text);
    font: inherit; font-size: 15px; line-height: 1.5;
    resize: none;
    max-height: 200px;
    padding: 6px 0;
}
.composer textarea::placeholder { color: var(--text-dim); }
.composer__actions {
    position: relative;
    display: flex; align-items: center; justify-content: flex-end; gap: 6px;
    min-width: 32px; min-height: 32px;
}
/* Send + Stop occupy the same cell; opacity crossfades between them. */
.composer__actions .btn-send,
.composer__actions .btn-stop {
    position: absolute;
    inset: auto 0 0 auto;
    transition: opacity .16s ease, transform .16s ease, background .12s, color .12s;
}
.composer__actions .btn-stop  { opacity: 0; transform: scale(.92); pointer-events: none; visibility: hidden; }
.composer__actions .btn-send  { opacity: 1; transform: scale(1);  pointer-events: auto; visibility: visible; }
.composer__actions.is-streaming .btn-send {
    opacity: 0; transform: scale(.92); pointer-events: none; visibility: hidden;
}
.composer__actions.is-streaming .btn-stop {
    opacity: 1; transform: scale(1);  pointer-events: auto; visibility: visible;
}

.btn-send, .btn-stop {
    height: 32px;
    padding: 0;
    width: 32px;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--text);
    color: var(--bg);
    cursor: pointer;
    flex-shrink: 0;
}
.btn-send:disabled { opacity: .25; cursor: not-allowed; }
.btn-send:not(:disabled):hover { opacity: .85; }

/* Stop: red-tinted, expands to a labeled pill on viewports wide enough to fit. */
.btn-stop {
    background: rgba(239,104,104,.12);
    color: var(--danger);
    border: 1px solid rgba(239,104,104,.35);
    gap: 6px;
}
.btn-stop:hover {
    background: rgba(239,104,104,.2);
    border-color: rgba(239,104,104,.55);
}
.btn-stop__lbl {
    display: none;
    font-size: 13px; font-weight: 500;
    line-height: 1;
}
@media (min-width: 560px) {
    .composer__actions.is-streaming { min-width: 92px; }   /* reserve room for the expanded pill */
    .btn-stop { width: auto; padding: 0 12px 0 10px; }
    .btn-stop__lbl { display: inline; }
}

.composer__hint {
    max-width: 768px; margin: 8px auto 0;
    color: var(--text-dim);
    font-size: 11px;
    text-align: center;
}

/* ── scrollbar (firefox+webkit) ───────────────────────────────────────── */
.conversations, .messages, .composer textarea {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.conversations::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 8px; }
.conversations::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.conversations::-webkit-scrollbar-thumb:hover, .messages::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* (mobile drawer rules live at the bottom inside the @media block) */

/* ── conversation rename input ─────────────────────────────────────── */
.conv-item__edit {
    flex: 1; min-width: 0;
    background: var(--bg);
    border: 1px solid var(--accent);
    color: var(--text);
    font: inherit; font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    outline: none;
}

/* ── floating menu (rename / delete dropdown) ──────────────────────── */
.conv-menu {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 4px;
    min-width: 140px;
    z-index: 100;
}
.conv-menu button {
    display: block; width: 100%;
    text-align: start;
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
}
.conv-menu button:hover { background: var(--bg-hover); }
.conv-menu .conv-menu__danger { color: var(--danger); }
.conv-menu .conv-menu__danger:hover { background: rgba(239,104,104,.12); }

/* ── toasts ────────────────────────────────────────────────────────── */
#peak-toasts {
    position: fixed;
    bottom: 24px; left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex; flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex; align-items: center;
    gap: 14px;
    font-size: 14px;
    pointer-events: auto;
    opacity: 0; transform: translateY(8px);
    transition: opacity .18s, transform .18s;
    max-width: 480px;
}
.toast--in { opacity: 1; transform: translateY(0); }
.toast--error { border-color: rgba(239,104,104,.5); }
.toast__action {
    color: var(--accent);
    font-weight: 500;
    padding: 2px 4px;
    border-radius: 4px;
}
.toast__action:hover { background: var(--bg-hover); }

/* ── settings modal ────────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 150;
    padding: 16px;
    backdrop-filter: blur(2px);
    animation: fade-in .15s;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 480px;
    max-height: 90vh; overflow-y: auto;
}
.modal__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal__header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal__close {
    width: 28px; height: 28px;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 22px;
    display: flex; align-items: center; justify-content: center;
}
.modal__close:hover { background: var(--bg-hover); color: var(--text); }
.modal__body { padding: 12px 20px 20px; }

.settings-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: 0; }
.settings-row--meta { color: var(--text-muted); }
.settings-row__label { font-size: 14px; font-weight: 500; }
.settings-row__hint  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.segmented {
    display: inline-flex;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
}
.segmented__btn {
    padding: 6px 12px;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 13px;
    transition: background .12s, color .12s;
}
.segmented__btn.is-active {
    background: var(--text);
    color: var(--bg);
}
.segmented__btn:not(.is-active):hover { color: var(--text); }

.btn-link {
    display: inline-flex; align-items: center;
    padding: 8px 14px;
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px; font-weight: 500;
    text-decoration: none;
    transition: background .12s;
}
.btn-link:hover { background: var(--bg-hover); text-decoration: none; color: var(--text); }

.btn-danger {
    padding: 8px 14px;
    background: rgba(239,104,104,.1);
    color: var(--danger);
    border: 1px solid rgba(239,104,104,.3);
    border-radius: 8px;
    font-size: 13px; font-weight: 500;
    transition: background .12s;
}
.btn-danger:hover { background: rgba(239,104,104,.2); }

@media (max-width: 768px) {
    .app__body { grid-template-columns: 1fr; }
    .app.sidebar-collapsed .app__body { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; top: var(--topbar-h, 56px); left: 0; bottom: 0;
        width: var(--rail-w);
        max-width: 85vw;
        transform: translateX(-100%);
        transition: transform .2s;
        z-index: 20;
        box-shadow: var(--shadow);
    }
    .app.sidebar-open .sidebar { transform: translateX(0); }
    .app.sidebar-open::after {
        content: "";
        position: fixed; top: var(--topbar-h, 56px); inset: var(--topbar-h, 56px) 0 0 0;
        background: rgba(0,0,0,.5);
        z-index: 15;
    }
    .topbar__name { display: none; }
    .starters { grid-template-columns: 1fr; }
    .empty-state h1 { font-size: 24px; }
    .msg { padding: 0 16px; }
    .composer-wrap { padding: 10px 12px 12px; }
}

/* ─────────────────────────────────────────────────────────────────────
 * Settings + admin shell — used by /settings and /admin/api-requests.
 * Two-column layout: left rail (nav) + main content area. Reuses the
 * existing .topbar, .segmented, .btn-primary, .btn-ghost variables.
 * ───────────────────────────────────────────────────────────────────── */

.app--settings .topbar__back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: var(--text-muted);
    margin-inline-end: 4px;
}
.app--settings .topbar__back:hover { background: var(--bg-hover); color: var(--text); }

.settings-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: calc(100vh - 56px);
    background: var(--bg);
}

.settings-nav {
    border-inline-end: 1px solid var(--border);
    background: var(--bg-elev);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.settings-nav__title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-dim);
    padding: 8px 10px 4px;
}
.settings-nav__title--sep { margin-top: 12px; }
.settings-nav__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    text-align: start;
    border-radius: 8px;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
}
.settings-nav__item:hover { background: var(--bg-hover); color: var(--text); }
.settings-nav__item.is-active {
    background: var(--accent-bg);
    color: var(--accent);
}

.settings-main {
    padding: 32px 40px;
    overflow-y: auto;
    width: 100%;
}

.settings-panel { display: none; }
.settings-panel.is-active { display: block; }

.settings-panel__head { margin-bottom: 20px; }
.settings-panel__head h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.settings-panel__head p  { margin: 0; color: var(--text-muted); font-size: 14px; }
.settings-panel__head--with-filters {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.settings-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
    margin-bottom: 14px;
}
.settings-card--pending { border-color: rgba(234, 179, 8, .4); }
.settings-card--ok      { border-color: rgba(34, 197, 94, .4); }
.settings-card--danger  { border-color: rgba(239, 104, 104, .4); }

.settings-card__row {
    display: flex;
    align-items: center;
    gap: 16px;
}
.settings-card__row--stack {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
}
.settings-card__info { flex: 1 1 auto; min-width: 0; }
.settings-card__label { font-size: 14px; font-weight: 500; color: var(--text); display: flex; align-items: center; gap: 8px; }
.settings-card__hint  { font-size: 13px; color: var(--text-muted); margin-top: 4px; line-height: 1.5; }
.settings-card__name  { font-size: 15px; font-weight: 600; }
.settings-card__sub   { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.settings-card__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--accent-bg);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex: 0 0 auto;
}
.settings-card__avatar img { width: 100%; height: 100%; object-fit: cover; }

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-dim);
}
.status-dot--pending { background: #eab308; box-shadow: 0 0 0 3px rgba(234,179,8,.18); }
.status-dot--ok      { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.status-dot--danger  { background: #ef6868; box-shadow: 0 0 0 3px rgba(239,104,104,.18); }

/* ── request form (API tab) ──────────────────────────────────────────── */
.request-form { display: flex; flex-direction: column; gap: 10px; }
.request-form textarea {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
    resize: vertical;
}
.request-form textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(122,166,255,.18);
}
.request-form__actions { display: flex; justify-content: flex-end; }

.request-quote {
    margin: 10px 0 0;
    padding: 10px 12px;
    background: var(--bg);
    border-inline-start: 3px solid var(--accent);
    border-radius: 4px;
    font-size: 13px;
    color: var(--text-muted);
    white-space: pre-wrap;
}

/* ── admin requests list ─────────────────────────────────────────────── */
.requests-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.requests-empty {
    padding: 32px;
    text-align: center;
    color: var(--text-muted);
    border: 1px dashed var(--border);
    border-radius: 12px;
}
.request-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
}
.request-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.request-card__who { min-width: 0; }
.request-card__name { font-size: 15px; font-weight: 600; }
.request-card__sub  { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.request-card__meta { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.request-card__status { flex: 0 0 auto; }
.request-card__decision { margin-top: 12px; }
.request-card__decision-label { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.request-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    color: var(--text-muted);
}
.request-card__actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    align-items: center;
}
.request-card__reason {
    flex: 1 1 auto;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font: inherit;
    min-width: 0;
}
.request-card__reason:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(122,166,255,.18);
}
.request-card__actions button { flex: 0 0 auto; }

@media (max-width: 720px) {
    .settings-shell { grid-template-columns: 1fr; }
    .settings-nav { border-inline-end: 0; border-bottom: 1px solid var(--border); flex-direction: row; overflow-x: auto; padding: 8px; gap: 4px; }
    .settings-nav__title { display: none; }
    .settings-nav__item { flex: 0 0 auto; }
    .settings-main { padding: 20px 16px; }
    .request-card__actions { flex-wrap: wrap; }
    .request-card__reason { width: 100%; flex-basis: 100%; }
}

/* ── API keys (settings → API tab, approved state) ───────────────────── */
.keys-section {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}
.keys-section__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.keys-section__head h2 { margin: 0; font-size: 15px; font-weight: 600; }

.keys-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.key-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.key-row--revoked { opacity: .6; }
.key-row__main { flex: 1 1 auto; min-width: 0; }
.key-row__name { font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.key-row__meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.key-row__meta code { background: var(--bg-elev-2); padding: 1px 6px; border-radius: 4px; font-size: 11px; }
.key-row__dot  { color: var(--text-dim); }
.key-row__tag {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(239,104,104,.18);
    color: #ef6868;
}
.btn-ghost--danger { color: #ef6868; }
.btn-ghost--danger:hover { background: rgba(239,104,104,.12); color: #ef6868; }

/* ── create-key modal extras (reuses .modal / .modal-backdrop) ────────── */
.modal__body[data-step="form"] input[type="text"] {
    width: 100%;
    margin-top: 6px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
}
.modal__body[data-step="form"] input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(122,166,255,.18);
}
.modal__hint { font-size: 13px; color: var(--text-muted); margin: 0 0 10px; line-height: 1.5; }
.modal__hint--warn {
    background: rgba(234,179,8,.12);
    border: 1px solid rgba(234,179,8,.32);
    color: var(--text);
    padding: 10px 12px;
    border-radius: 8px;
}
.modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}
.key-reveal {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
}
.key-reveal code {
    flex: 1 1 auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    word-break: break-all;
    color: var(--text);
}
.settings-card__hint code {
    background: var(--bg-elev-2);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
}

/* ── usage dashboard ─────────────────────────────────────────────────── */
.usage-dashboard { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.usage-loading { color: var(--text-muted); padding: 16px 0; }

.usage-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.usage-stat {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
}
.usage-stat__label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.usage-stat__value { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.usage-stat__sub   { font-size: 12px; color: var(--text-muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

.usage-chart-block {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 16px;
}
.usage-chart-block__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 10px;
}
.usage-chart-block__head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.usage-controls { display: flex; gap: 8px; }
.segmented--xs .segmented__btn { font-size: 11px; padding: 4px 8px; }

.usage-chart { width: 100%; height: 160px; display: block; }
.usage-chart .grid {
    stroke: var(--border);
    stroke-dasharray: 2 3;
    stroke-width: 1;
}
.usage-chart .axis {
    fill: var(--text-dim);
    font-size: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.usage-chart .bar { rx: 1.5; transition: opacity .12s; }
.usage-chart .bar:hover { opacity: .75; }
.usage-chart .bar--cost { fill: var(--accent); }
.usage-chart .bar--in   { fill: var(--accent); }
.usage-chart .bar--out  { fill: #a78bff; }

.usage-legend {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-muted);
}
.usage-legend .dot {
    display: inline-block;
    width: 8px; height: 8px; border-radius: 2px;
    margin-inline-end: 4px;
    vertical-align: middle;
}
.usage-legend .dot--in   { background: var(--accent); }
.usage-legend .dot--out  { background: #a78bff; }
.usage-legend .dot--cost { background: var(--accent); }

.usage-tables {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.usage-table {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    min-width: 0;
}
.usage-table h2 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.usage-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.usage-table th, .usage-table td {
    text-align: end;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}
.usage-table th:first-child, .usage-table td:first-child {
    text-align: start;
}
.usage-table th {
    font-weight: 500;
    color: var(--text-dim);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: .04em;
}
.usage-table tr:last-child td { border-bottom: 0; }
.usage-table__key { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.usage-table__key code {
    background: var(--bg-elev-2);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 10px;
    color: var(--text-dim);
    align-self: flex-start;
}

@media (max-width: 720px) {
    .usage-stats   { grid-template-columns: 1fr; }
    .usage-tables  { grid-template-columns: 1fr; }
    .usage-chart-block__head { flex-direction: column; align-items: flex-start; }
}

/* ── admin: user controls + audit log ────────────────────────────────── */
.request-form--inline {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.request-form--inline input[type="number"],
.request-form--inline input[type="text"] {
    flex: 1 1 240px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font: inherit;
    min-width: 180px;
}
.request-form--inline input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(122,166,255,.18);
}

#user-lookup-form input[type="number"] { width: 240px; flex: 0 0 auto; }

.admin-keys-table,
.admin-audit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.admin-keys-table th, .admin-keys-table td,
.admin-audit-table th, .admin-audit-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: start;
    vertical-align: middle;
}
.admin-keys-table th, .admin-audit-table th {
    font-weight: 500;
    color: var(--text-dim);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: .04em;
}
.admin-keys-table tr:last-child td,
.admin-audit-table tr:last-child td { border-bottom: 0; }
.admin-keys-table input[type="number"] {
    width: 110px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 8px;
    font: inherit;
    font-size: 12px;
}
.admin-audit-table code {
    background: var(--bg-elev-2);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11px;
    word-break: break-all;
}
.admin-audit-table {
    table-layout: fixed;
}
.admin-audit-table td:nth-child(6) { word-break: break-all; font-size: 12px; }

/* ── docs page ───────────────────────────────────────────────────────── */
.docs-main { padding: 32px 40px; max-width: none; }
.docs-section { margin-bottom: 40px; scroll-margin-top: 76px; }
.docs-section h1 { margin: 0 0 8px; font-size: 28px; font-weight: 600; letter-spacing: -.01em; }
.docs-section h2 { margin: 0 0 12px; font-size: 20px; font-weight: 600; padding-top: 8px; }
.docs-section h3 { margin: 18px 0 8px; font-size: 14px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.docs-section p, .docs-section li { color: var(--text-muted); line-height: 1.7; font-size: 14px; }
.docs-section code {
    background: var(--bg-elev-2);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--text);
}
.docs-lead { font-size: 16px; color: var(--text); margin-bottom: 24px; }
.docs-lead code { font-size: 13px; }

.docs-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 8px;
}
.docs-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
}
.docs-card__title { font-size: 11px; text-transform: uppercase; color: var(--text-dim); letter-spacing: .04em; font-weight: 600; margin-bottom: 6px; }
.docs-card code { display: block; word-break: break-all; }

.docs-section pre {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    overflow-x: auto;
    margin: 0 0 16px;
}
.docs-section pre code {
    background: transparent;
    padding: 0;
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--text);
}

.docs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin: 8px 0 0;
}
.docs-table th, .docs-table td {
    text-align: start;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.docs-table th {
    font-weight: 500;
    color: var(--text-dim);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: .04em;
}
.docs-section ul { padding-inline-start: 20px; margin: 8px 0 16px; }

.btn-primary--sm { font-size: 12px; padding: 6px 12px; }
.docs-card .btn-primary--sm { display: inline-block; }

.app--settings .topbar a.topbar__back { padding: 0 12px; width: auto; font-size: 13px; color: var(--text-muted); }
.app--settings .topbar a.topbar__back:hover { color: var(--text); }

