/* HydraSafe Sales Agent - shared styles for chat, admin, login and setup */

:root {
  --bg: #ffffff;
  --bg-sidebar: #f7f8f7;
  --bg-hover: #eceeed;
  --bg-active: #e2e6e4;
  --bg-input: #f3f4f3;
  --bg-bubble: #eef1ef;
  --bg-card: #ffffff;
  --bg-code: #f3f4f3;
  --text: #111413;
  --text-muted: #59605c;
  --text-faint: #858c88;
  --border: #e1e4e2;
  --border-strong: #c9cecb;
  --accent: #236c3c;
  --accent-hover: #1b5730;
  --accent-text: #ffffff;
  --accent-soft: #e4f0e8;
  --teal: #2f5c66;
  --brand-grad: linear-gradient(90deg, #236c3c, #2f5c66);
  --warn-bg: #fbf1d9;
  --warn-text: #6e4b00;
  --danger: #b42318;
  --danger-bg: #fcebe9;
  --info-bg: #e7eff1;
  --info-text: #2a525b;
  --ok-bg: #e4f0e8;
  --ok-text: #1d5a32;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 28px rgba(0, 0, 0, 0.08);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f2120;
    --bg-sidebar: #161817;
    --bg-hover: #2a2d2b;
    --bg-active: #323633;
    --bg-input: #2b2e2c;
    --bg-bubble: #2f3331;
    --bg-card: #252826;
    --bg-code: #2a2d2b;
    --text: #ebeeec;
    --text-muted: #b0b7b3;
    --text-faint: #858d89;
    --border: #353936;
    --border-strong: #4a4f4c;
    --accent: #3f9d62;
    --accent-hover: #4cb172;
    --accent-text: #0d1a12;
    --accent-soft: #1c3325;
    --teal: #6aaab8;
    --brand-grad: linear-gradient(90deg, #52b97a, #6aaab8);
    --warn-bg: #3a2f13;
    --warn-text: #f1cd77;
    --danger: #f2877d;
    --danger-bg: #3a1e1b;
    --info-bg: #1d3035;
    --info-text: #94c7d2;
    --ok-bg: #1c3325;
    --ok-text: #8fd3a8;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1f2120;
  --bg-sidebar: #161817;
  --bg-hover: #2a2d2b;
  --bg-active: #323633;
  --bg-input: #2b2e2c;
  --bg-bubble: #2f3331;
  --bg-card: #252826;
  --bg-code: #2a2d2b;
  --text: #ebeeec;
  --text-muted: #b0b7b3;
  --text-faint: #858d89;
  --border: #353936;
  --border-strong: #4a4f4c;
  --accent: #3f9d62;
  --accent-hover: #4cb172;
  --accent-text: #0d1a12;
  --accent-soft: #1c3325;
  --teal: #6aaab8;
  --brand-grad: linear-gradient(90deg, #52b97a, #6aaab8);
  --warn-bg: #3a2f13;
  --warn-text: #f1cd77;
  --danger: #f2877d;
  --danger-bg: #3a1e1b;
  --info-bg: #1d3035;
  --info-text: #94c7d2;
  --ok-bg: #1c3325;
  --ok-text: #8fd3a8;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The HydraSafe wordmark, drawn through its alpha so it follows the theme's gradient */
.wordmark {
  display: inline-block;
  aspect-ratio: 640 / 131;
  height: 22px;
  background: var(--brand-grad);
  -webkit-mask: url("hydrasafe-wordmark.png") no-repeat center / contain;
  mask: url("hydrasafe-wordmark.png") no-repeat center / contain;
}

/* ---------- buttons, inputs, badges ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--bg-card); color: var(--text);
  font-size: 14px; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text-muted);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn svg, .btn svg { width: 18px; height: 18px; flex: none; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.input, .field input, .field textarea, .field select {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--bg); color: var(--text);
}
.field textarea { min-height: 84px; resize: vertical; }
.input:focus, .field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-muted); margin-bottom: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-error { min-height: 20px; margin: 0 0 12px; color: var(--danger); font-size: 14px; }
.form-ok { color: var(--ok-text); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.6; white-space: nowrap;
  background: var(--bg-hover); color: var(--text-muted);
}
.badge svg { width: 13px; height: 13px; }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--info-bg); color: var(--info-text); }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }

dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 24px; border: 1px solid var(--border); border-radius: 18px;
  background: var(--bg-card); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
dialog p.lead { margin: 0 0 18px; color: var(--text-muted); font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow); z-index: 50;
}

/* ---------- login / setup ---------- */
.auth-page { display: grid; place-items: center; min-height: 100%; padding: 24px 16px; background: var(--bg-sidebar); }
.auth-card {
  width: min(400px, 100%); padding: 32px 28px 24px;
  border: 1px solid var(--border); border-radius: 20px; background: var(--bg-card); box-shadow: var(--shadow);
}
.auth-card .wordmark { height: 30px; display: block; margin: 0 auto 6px; }
.auth-card .sub { margin: 0 0 24px; text-align: center; color: var(--text-muted); font-size: 14px; }
.auth-card h1 { margin: 0 0 6px; font-size: 20px; }
.auth-card .btn.primary { width: 100%; min-height: 42px; }
.auth-foot { margin-top: 18px; text-align: center; font-size: 12px; color: var(--text-faint); }

/* ---------- chat layout ---------- */
.layout { display: flex; height: 100dvh; overflow: hidden; }
.sidebar {
  display: flex; flex-direction: column; width: 272px; flex: none;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
}
.sb-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 8px 16px; }
.brand { display: flex; flex-direction: column; gap: 2px; text-decoration: none; }
.brand-sub { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }
.new-chat {
  display: flex; align-items: center; gap: 10px; margin: 6px 10px 10px; padding: 9px 12px;
  border: 1px solid var(--border-strong); border-radius: 12px; background: var(--bg-card);
  font-size: 14px; font-weight: 500;
}
.new-chat:hover { background: var(--bg-hover); }
.new-chat svg { width: 18px; height: 18px; }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.conv-group { margin: 14px 8px 4px; font-size: 12px; font-weight: 600; color: var(--text-faint); }
.conv-item { position: relative; display: flex; align-items: center; border-radius: 10px; }
.conv-item a {
  flex: 1; min-width: 0; padding: 7px 10px; border-radius: 10px;
  color: var(--text); font-size: 14px; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item:hover, .conv-item.active { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-active); }
.conv-item .icon-btn { width: 28px; height: 28px; margin-right: 4px; opacity: 0; }
.conv-item:hover .icon-btn, .conv-item.active .icon-btn, .conv-item .icon-btn:focus-visible { opacity: 1; }
.conv-item input { flex: 1; min-width: 0; margin: 2px 4px; padding: 5px 8px; border: 1px solid var(--accent); border-radius: 8px; background: var(--bg); }
.conv-empty { margin: 16px 12px; color: var(--text-faint); font-size: 13px; }

.sb-bottom { position: relative; padding: 8px; border-top: 1px solid var(--border); }
.user-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 0; border-radius: 12px;
  background: transparent; text-align: left;
}
.user-btn:hover { background: var(--bg-hover); }
.avatar {
  display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%;
  background: var(--brand-grad); color: #fff; font-size: 13px; font-weight: 700;
}
.user-name { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu {
  position: absolute; left: 8px; right: 8px; bottom: calc(100% - 2px); padding: 6px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--bg-card); box-shadow: var(--shadow); z-index: 20;
}
.menu a, .menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 9px;
  background: transparent; color: var(--text); font-size: 14px; text-align: left; text-decoration: none;
}
.menu a:hover, .menu button:hover { background: var(--bg-hover); }
.menu svg { width: 17px; height: 17px; color: var(--text-muted); }
.menu .sep { height: 1px; margin: 5px 4px; background: var(--border); }
.conv-menu { position: fixed; left: auto; right: auto; bottom: auto; width: 180px; }

.main { position: relative; display: flex; flex-direction: column; flex: 1; min-width: 0; }
.topbar { display: none; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.topbar-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.scrim { display: none; }

.thread { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.messages { max-width: 780px; margin: 0 auto; padding: 28px 24px 24px; }
.msg { margin-bottom: 26px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  max-width: 80%; padding: 10px 16px; border-radius: 20px 20px 6px 20px;
  background: var(--bg-bubble); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.assistant { display: flex; gap: 14px; }
.msg .mark {
  width: 30px; height: 30px; flex: none; margin-top: 2px; border-radius: 50%;
  background: var(--brand-grad); display: grid; place-items: center;
}
.msg .mark svg { width: 17px; height: 17px; color: #fff; }
.msg .body { flex: 1; min-width: 0; }
.msg .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.msg .actions { display: flex; gap: 2px; margin-top: 6px; margin-left: -8px; }
.msg .actions .icon-btn { width: 32px; height: 32px; }
.msg .actions .icon-btn svg { width: 16px; height: 16px; }
.msg .actions .icon-btn.done { color: var(--accent); }
.msg .error {
  padding: 10px 14px; border-radius: 12px; background: var(--danger-bg); color: var(--danger); font-size: 14px;
}
.msg .error .btn { margin-top: 8px; }
.source {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 12px; color: var(--text-muted); background: var(--bg);
}
.source svg { width: 12px; height: 12px; }
.sources-label { font-size: 12px; color: var(--text-faint); margin-right: 2px; }
.flag-note { margin-top: 8px; font-size: 13px; color: var(--text-faint); }

.thinking { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 14px; padding-top: 4px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }
.streaming > :last-child::after {
  content: ""; display: inline-block; width: 8px; height: 1em; margin-left: 2px; vertical-align: -2px;
  border-radius: 2px; background: var(--accent); animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .dots i, .streaming > :last-child::after { animation: none; } .thread { scroll-behavior: auto; } }

.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100%; padding: 32px 24px; text-align: center; }
.empty .wordmark { height: 34px; margin-bottom: 18px; }
.empty h1 { margin: 0 0 8px; font-size: 26px; font-weight: 650; letter-spacing: -0.01em; }
.empty p { max-width: 520px; margin: 0 0 28px; color: var(--text-muted); }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: min(640px, 100%); }
.suggestion {
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--bg-card); text-align: left; font-size: 14px; color: var(--text);
}
.suggestion:hover { background: var(--bg-hover); }
.suggestion small { display: block; color: var(--text-faint); font-size: 12px; margin-top: 2px; }

.composer { padding: 0 24px 14px; }
.composer-box {
  display: flex; align-items: flex-end; gap: 8px; max-width: 780px; margin: 0 auto; padding: 8px 8px 8px 18px;
  border: 1px solid var(--border-strong); border-radius: 26px; background: var(--bg-input); box-shadow: var(--shadow);
}
.composer-box:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1; min-height: 28px; max-height: 220px; margin: 6px 0; padding: 0; border: 0; outline: 0;
  background: transparent; resize: none; line-height: 1.5;
}
.send-btn {
  display: grid; place-items: center; width: 38px; height: 38px; flex: none; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
}
.send-btn:disabled { background: var(--border-strong); color: var(--bg); cursor: default; }
.send-btn svg { width: 18px; height: 18px; }
.composer-note { max-width: 780px; margin: 8px auto 0; text-align: center; font-size: 12px; color: var(--text-faint); }

/* ---------- rendered markdown ---------- */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h3, .md h4, .md h5, .md h6 { margin: 20px 0 8px; line-height: 1.3; }
.md h3 { font-size: 18px; }
.md h4 { font-size: 16px; }
.md h5, .md h6 { font-size: 15px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 24px; }
.md li { margin: 3px 0; }
.md li > p { margin: 0 0 4px; }
.md li > ul, .md li > ol { margin: 4px 0 4px; }
.md code { padding: 1px 5px; border-radius: 5px; background: var(--bg-code); font: 0.9em var(--mono); }
.md pre { margin: 0 0 12px; padding: 12px 14px; border-radius: 12px; background: var(--bg-code); overflow-x: auto; }
.md pre code { padding: 0; background: none; font-size: 13px; }
.md blockquote { margin: 0 0 12px; padding: 2px 14px; border-left: 3px solid var(--border-strong); color: var(--text-muted); }
.md hr { margin: 18px 0; border: 0; border-top: 1px solid var(--border); }
.md .table-wrap { margin: 0 0 14px; overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
.md table { width: 100%; border-collapse: collapse; font-size: 14px; }
.md th, .md td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.md th { background: var(--bg-sidebar); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }
.md .al-center { text-align: center; }
.md .al-right { text-align: right; }
.md a { overflow-wrap: anywhere; }

/* ---------- admin ---------- */
.admin { min-height: 100%; background: var(--bg-sidebar); }
.admin-top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 24px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.admin-top .brand { flex-direction: row; align-items: center; gap: 10px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text-muted); font-size: 14px; font-weight: 500; white-space: nowrap;
}
.tab:hover { background: var(--bg-hover); color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.tab .count { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 12px; line-height: 20px; text-align: center; }
.admin-main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.admin-main h1 { margin: 0 0 4px; font-size: 22px; }
.admin-main .lead { margin: 0 0 20px; color: var(--text-muted); font-size: 14px; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.card { padding: 18px 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); }
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 14px; font-size: 15px; }
.stat-label { font-size: 13px; color: var(--text-muted); }
.stat-value { margin-top: 4px; font-size: 28px; font-weight: 650; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat-sub { margin-top: 2px; font-size: 13px; color: var(--text-faint); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.spacer { flex: 1; }

.chart { position: relative; }
.chart-plot { display: flex; align-items: flex-end; gap: 2px; height: 150px; padding-top: 8px; border-bottom: 1px solid var(--border-strong); }
.chart-col { position: relative; flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: default; }
.chart-col:hover { background: var(--bg-hover); border-radius: 4px 4px 0 0; }
.chart-bar { width: 100%; min-height: 0; border-radius: 4px 4px 0 0; background: var(--accent); }
.chart-axis { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--text-faint); }
.chart-tip {
  position: absolute; z-index: 5; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-card); box-shadow: var(--shadow); font-size: 13px; white-space: nowrap; pointer-events: none;
}
.chart-tip b { display: block; margin-bottom: 2px; }
.chart-max { position: absolute; top: 0; right: 0; font-size: 12px; color: var(--text-faint); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 5px 12px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--bg-card);
  font-size: 13px; color: var(--text-muted);
}
.chip:hover { background: var(--bg-hover); }
.chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip .n { margin-left: 4px; color: var(--text-faint); font-weight: 400; }

.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bg-sidebar);
  color: var(--text-muted); font-size: 12px; font-weight: 600; text-align: left; white-space: nowrap;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--bg-hover); }
table.data .q { max-width: 520px; }
table.data .q div { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .nowrap { white-space: nowrap; }
.table-empty { padding: 40px 16px; text-align: center; color: var(--text-faint); }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; display: flex; flex-direction: column;
  width: min(720px, 100vw); border-left: 1px solid var(--border); background: var(--bg); box-shadow: var(--shadow);
}
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { flex: 1; margin: 0; font-size: 16px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px; }
.drawer-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.drawer-scrim { position: fixed; inset: 0; z-index: 29; background: rgba(0, 0, 0, 0.3); }
.section { margin-bottom: 22px; }
.section h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.box { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-card); }
.box.question { white-space: pre-wrap; background: var(--bg-bubble); border-color: transparent; }
.convo .turn { margin-bottom: 10px; }
.convo .turn .who { font-size: 12px; color: var(--text-faint); margin-bottom: 3px; }
.convo .turn.flagged .box { border-color: var(--accent); }
details summary { cursor: pointer; color: var(--text-muted); font-size: 14px; }
.password-box {
  display: flex; align-items: center; gap: 8px; margin: 6px 0 16px; padding: 10px 12px;
  border: 1px dashed var(--accent); border-radius: 12px; background: var(--accent-soft); font: 16px var(--mono);
}
.password-box span { flex: 1; overflow-wrap: anywhere; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; width: min(300px, 86vw);
    transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  .layout.nav-open .sidebar { transform: none; }
  .layout.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(0, 0, 0, 0.35); }
  .topbar { display: flex; }
  .messages { padding: 18px 16px 16px; }
  .msg.user .bubble { max-width: 88%; }
  .msg.assistant { gap: 10px; }
  .msg .mark { width: 26px; height: 26px; }
  .composer { padding: 0 12px 10px; }
  .suggestions { grid-template-columns: minmax(0, 1fr); }
  .empty h1 { font-size: 22px; }
  .admin-top { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .admin-main { padding: 16px; }
  .grid.cols-4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .conv-item .icon-btn { opacity: 1; }
}
@media (min-width: 761px) { #closeSidebar { display: none; } }
.menu .danger, .menu .danger svg { color: var(--danger); }
.row h1 { margin: 0; }
