/* CanopyAI - design tokens */
:root {
  --bg: #fbfcfa;
  --surface: #ffffff;
  --surface-2: #f2f5f1;
  --surface-3: #e8ede6;
  --sidebar: #f4f7f3;
  --border: #e1e7df;
  --border-strong: #cdd6ca;
  --text: #142019;
  --text-2: #3b4a41;
  --muted: #6a7870;
  --accent: #15803d;
  --accent-hover: #116b33;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3e8;
  --accent-ring: rgba(21, 128, 61, .28);
  --danger: #dc2626;
  --warn: #b45309;
  --user-bubble: #e3f3e8;
  --user-ink: #0f2a19;
  --code-bg: #f3f6f2;
  --scrim: rgba(10, 20, 14, .38);
  --shadow-sm: 0 1px 2px rgba(16, 24, 20, .06);
  --shadow: 0 1px 2px rgba(16, 24, 20, .05), 0 6px 20px rgba(16, 24, 20, .07);
  --shadow-lg: 0 10px 40px rgba(16, 24, 20, .16);
  --radius: 14px;
  --sb-w: 272px;
  --content-w: 780px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1210; --surface: #141a17; --surface-2: #1a221e; --surface-3: #232d28; --sidebar: #101614;
    --border: #253029; --border-strong: #34413a;
    --text: #e6ece8; --text-2: #c2ccc6; --muted: #8f9d95;
    --accent: #22c55e; --accent-hover: #4ade80; --accent-ink: #04210f; --accent-soft: #14301f; --accent-ring: rgba(34, 197, 94, .3);
    --danger: #f87171; --warn: #fbbf24; --user-bubble: #1b3426; --user-ink: #e9f7ee; --code-bg: #0f1513;
    --scrim: rgba(0, 0, 0, .55);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.3); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1210; --surface: #141a17; --surface-2: #1a221e; --surface-3: #232d28; --sidebar: #101614;
  --border: #253029; --border-strong: #34413a;
  --text: #e6ece8; --text-2: #c2ccc6; --muted: #8f9d95;
  --accent: #22c55e; --accent-hover: #4ade80; --accent-ink: #04210f; --accent-soft: #14301f; --accent-ring: rgba(34, 197, 94, .3);
  --danger: #f87171; --warn: #fbbf24; --user-bubble: #1b3426; --user-ink: #e9f7ee; --code-bg: #0f1513;
  --scrim: rgba(0, 0, 0, .55);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.3); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.6 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
code, pre, .mono { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
::selection { background: var(--accent-ring); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ---------- buttons ---------- */
.icon-btn {
  border: 0; background: none; width: 36px; height: 36px; border-radius: 10px;
  display: inline-grid; place-items: center; color: var(--muted); transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.recording { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--danger) 12%, transparent); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); padding: 9px 16px; border-radius: 10px;
  font-weight: 500; font-size: 14px; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.primary.running { background: var(--text); border-color: var(--text); color: var(--surface); }
.btn.danger-ghost { color: var(--danger); }
.btn.danger-ghost:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.full { width: 100%; margin-top: 10px; }

/* ---------- sidebar ---------- */
.sidebar {
  width: var(--sb-w); flex-shrink: 0; display: flex; flex-direction: column; gap: 6px;
  background: var(--sidebar); border-right: 1px solid var(--border); padding: 12px 10px;
  transition: margin-left .22s ease, transform .22s ease;
}
.app.sb-collapsed .sidebar { margin-left: calc(-1 * var(--sb-w)); }
.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 8px 6px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex-shrink: 0; box-shadow: 0 2px 8px var(--accent-ring); }
.logo svg { width: 18px; height: 18px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.015em; }

.new-chat {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 12px;
  font-weight: 600; font-size: 14px; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.new-chat:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.new-chat svg { color: var(--accent); }

.sb-search { display: flex; align-items: center; gap: 8px; padding: 0 10px; margin: 4px 0 2px; border-radius: 10px; color: var(--muted); border: 1px solid transparent; }
.sb-search:focus-within { background: var(--surface); border-color: var(--border); }
.sb-search svg { width: 16px; height: 16px; }
.sb-search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; padding: 8px 0; font: inherit; font-size: 13.5px; color: var(--text); }
.sb-search input::-webkit-search-cancel-button { filter: grayscale(1); }

.conv-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.conv-group { font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 14px 10px 4px; letter-spacing: .02em; }
.conv { position: relative; display: flex; align-items: center; border-radius: 9px; color: var(--text-2); }
.conv:hover { background: var(--surface-3); }
.conv.active { background: var(--surface-3); color: var(--text); }
.conv .open { flex: 1; min-width: 0; display: flex; border: 0; background: none; padding: 8px 10px; text-align: left; font-size: 13.5px; color: inherit; border-radius: 9px; }
.conv.active .open { font-weight: 500; }
.conv .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .acts { display: none; gap: 1px; padding-right: 4px; }
.conv:hover .acts, .conv.active .acts, .conv:focus-within .acts { display: flex; }
.conv .acts button { width: 26px; height: 26px; display: grid; place-items: center; border: 0; background: none; border-radius: 7px; color: var(--muted); padding: 0; }
.conv .acts button:hover { background: var(--surface); color: var(--text); }
.conv .acts .del:hover { color: var(--danger); }
.conv .acts svg { width: 14px; height: 14px; }
.conv-empty { color: var(--muted); font-size: 13px; padding: 18px 10px; text-align: center; }

.sb-foot { border-top: 1px solid var(--border); padding-top: 8px; display: flex; flex-direction: column; gap: 1px; }
.sb-label { font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 4px 10px 4px; }
.sb-divider { height: 1px; background: var(--border); margin: 6px 0; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 9px; font-size: 13.5px; color: var(--text-2); text-align: left; }
.nav-item svg { width: 16px; height: 16px; color: var(--muted); }
.nav-item:hover { background: var(--surface-3); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-item.active svg { color: var(--accent); }

.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 40; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 14px; flex-shrink: 0;
  border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
}
#openSidebar { display: none; }
.app.sb-collapsed #openSidebar { display: inline-grid; }
.top-title { font-weight: 600; font-size: 14.5px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.model-pick { display: flex; align-items: center; gap: 6px; padding: 0 4px 0 10px; height: 36px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--muted); }
.model-pick:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.model-pick svg { width: 16px; height: 16px; }
.model-pick select { border: 0; background: transparent; color: var(--text); font: 500 13px Inter, system-ui, sans-serif; padding: 6px 2px; max-width: 240px; outline: none; cursor: pointer; }
.model-pick select option { background: var(--surface); color: var(--text); }
.status { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: 999px; font-size: 12.5px; color: var(--muted); white-space: nowrap; background: var(--surface); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.status.ok .dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.status.bad { color: var(--danger); }
.status.bad .dot { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 15%, transparent); }

/* ---------- views ---------- */
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; }

/* ---------- chat ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.thread { flex: 1; overflow-y: auto; padding: 28px 24px 16px; }
.thread > * { max-width: var(--content-w); margin-left: auto; margin-right: auto; }

/* welcome screen (Gemini / Claude style: greeting + centred composer when the chat is empty) */
.welcome { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 0 0 26px; animation: rise .35s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.welcome .logo { width: 48px; height: 48px; border-radius: 15px; margin-bottom: 20px; }
.welcome .logo svg { width: 24px; height: 24px; }
.welcome h1 { font-size: 34px; line-height: 1.25; letter-spacing: -.03em; margin: 0; font-weight: 600; color: var(--muted); }
.welcome .grad { background: linear-gradient(90deg, var(--accent), #0ea5a4 60%, #2563eb); -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 700; }

.suggestions { display: none; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: var(--content-w); margin: 0 auto; padding: 4px 24px 0; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 15px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: 13.5px; font-weight: 500;
  transition: border-color .15s, background .15s, color .15s; white-space: nowrap;
}
.chip-btn svg { width: 16px; height: 16px; color: var(--accent); }
.chip-btn:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }

.chat.is-empty { justify-content: center; }
.chat.is-empty .thread { flex: 0 0 auto; overflow: visible; padding-top: 0; padding-bottom: 0; }
.chat.is-empty .suggestions { display: flex; }
.chat.is-empty .disclaimer { display: none; }
.chat.is-empty .composer { padding-bottom: 14px; }
.chat.is-empty .to-bottom { display: none; }

/* messages */
.msg { display: flex; gap: 14px; margin-bottom: 26px; animation: rise .25s ease; }
.msg.user { flex-direction: column; align-items: flex-end; gap: 2px; }
.u-acts { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.msg.user:hover .u-acts, .u-acts:focus-within { opacity: 1; }
.u-acts .icon-btn { width: 30px; height: 30px; border-radius: 8px; }
.u-acts .icon-btn svg { width: 15px; height: 15px; }
.edit-box { margin: 0 auto 26px; width: 100%; background: var(--surface); border: 1px solid var(--accent); border-radius: 18px; padding: 12px 14px; box-shadow: 0 0 0 3px var(--accent-ring); }
.thread .edit-box textarea, .thread .edit-box textarea:focus { outline: none; border: 0; box-shadow: none; background: none; padding: 0; resize: none; font-size: 15px; }
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.edit-actions .btn { padding: 7px 14px; border-radius: 999px; font-size: 13.5px; }
.avatar { width: 30px; height: 30px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex-shrink: 0; margin-top: 2px; }
.avatar svg { width: 16px; height: 16px; }
.bubble { max-width: 100%; min-width: 0; }
.msg.user .bubble {
  background: var(--user-bubble); color: var(--user-ink); padding: 10px 16px; border-radius: 20px 20px 6px 20px;
  max-width: 78%; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.assistant .bubble { flex: 1; }
.media { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 8px; }
.media img { width: 112px; height: 84px; object-fit: cover; border-radius: 10px; cursor: zoom-in; display: block; }
.media audio { height: 38px; max-width: 260px; }
.media .lost { font-size: 12px; color: var(--muted); padding: 6px 10px; border: 1px dashed var(--border-strong); border-radius: 8px; }

.content { word-wrap: break-word; overflow-wrap: anywhere; color: var(--text); }
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content p { margin: 0 0 12px; }
.content h1, .content h2, .content h3, .content h4 { margin: 18px 0 8px; line-height: 1.3; letter-spacing: -.01em; }
.content h1 { font-size: 21px; } .content h2 { font-size: 18px; } .content h3 { font-size: 16px; } .content h4 { font-size: 15px; }
.content a { color: var(--accent); text-underline-offset: 2px; }
.content strong { font-weight: 600; }
.content blockquote { margin: 10px 0; padding: 2px 14px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.content hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.content code { background: var(--code-bg); border: 1px solid var(--border); padding: 1px 5px; border-radius: 6px; font-size: 13px; }
.content pre { position: relative; background: var(--code-bg); border: 1px solid var(--border); padding: 14px; border-radius: 12px; overflow-x: auto; font-size: 13px; line-height: 1.55; margin: 12px 0; }
.content pre code { background: none; border: 0; padding: 0; }
.content table { border-collapse: collapse; margin: 12px 0; display: block; overflow-x: auto; font-size: 14px; }
.content th, .content td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.content th { background: var(--surface-2); font-weight: 600; }
.content ul, .content ol { padding-left: 24px; margin: 6px 0 12px; }
.content li { margin: 3px 0; }
.copy-code {
  position: absolute; top: 8px; right: 8px; display: flex; align-items: center; gap: 5px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 7px; padding: 3px 8px; font: 500 11.5px Inter, sans-serif;
  opacity: 0; transition: opacity .15s;
}
.copy-code svg { width: 13px; height: 13px; }
.content pre:hover .copy-code, .copy-code:focus-visible { opacity: 1; }
.copy-code:hover { color: var(--text); }

.cursor > :last-child::after, .cursor:empty::after { content: ""; display: inline-block; width: 8px; height: 1.05em; background: var(--accent); border-radius: 2px; vertical-align: -2px; margin-left: 3px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.card { border: 1px solid var(--border); background: var(--surface); border-radius: 12px; margin: 0 0 12px; font-size: 13px; overflow: hidden; }
.card summary { padding: 9px 12px; cursor: pointer; display: flex; align-items: center; gap: 8px; color: var(--muted); list-style: none; user-select: none; }
.card summary::-webkit-details-marker { display: none; }
.card summary svg { width: 15px; height: 15px; }
.card summary b { color: var(--text); font-weight: 600; }
.card .badge { margin-left: auto; font-size: 11px; font-weight: 500; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); }
.card .badge.ok { background: var(--accent-soft); color: var(--accent); }
.card .badge.demo, .tag-demo { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); font-weight: 600; }
.tag-demo { font-size: 10.5px; padding: 1px 7px; border-radius: 5px; margin-left: 4px; vertical-align: 1px; }
.card pre { margin: 0; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--code-bg); overflow-x: auto; white-space: pre-wrap; font-size: 12px; }
.card.thinking .body { padding: 10px 12px; border-top: 1px solid var(--border); color: var(--muted); white-space: pre-wrap; font-size: 13px; max-height: 320px; overflow-y: auto; }

.meta { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 8px; align-items: center; min-height: 30px; }
.meta .icon-btn { width: 30px; height: 30px; border-radius: 8px; }
.meta .icon-btn svg { width: 15px; height: 15px; }
.meta .stats { font-size: 12px; color: var(--muted); margin-left: 6px; font-variant-numeric: tabular-nums; }
.meta .stats .warn { color: var(--warn); }
.hide-stats .meta .stats { display: none; }
.error { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; color: var(--danger); background: color-mix(in srgb, var(--danger) 7%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent); padding: 10px 14px; border-radius: 12px; font-size: 13.5px; white-space: pre-wrap; margin-top: 4px; }

.to-bottom {
  position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%); z-index: 5;
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  display: grid; place-items: center; box-shadow: var(--shadow); animation: fade .15s;
}
.to-bottom:hover { color: var(--text); border-color: var(--border-strong); }

/* ---------- composer ---------- */
.composer { padding: 6px 24px calc(14px + env(safe-area-inset-bottom)); }
.composer-inner { max-width: var(--content-w); margin: 0 auto; }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.attachments:empty { display: none; }
.att { position: relative; display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 5px 30px 5px 5px; font-size: 12.5px; box-shadow: var(--shadow-sm); animation: rise .2s; }
.att img { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; display: block; }
.att .aud { width: 46px; height: 46px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.att .nm { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.att .x { position: absolute; top: 5px; right: 5px; width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--surface-2); color: var(--muted); display: grid; place-items: center; padding: 0; }
.att .x:hover { background: var(--surface-3); color: var(--text); }
.att .x svg { width: 12px; height: 12px; }
.composer-box {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 22px; padding: 12px 10px 8px 16px;
  box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s;
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: var(--shadow), 0 0 0 3px var(--accent-ring); }
.composer-box textarea { display: block; width: 100%; border: 0; background: none; padding: 2px 0; resize: none; max-height: 220px; font: inherit; font-size: 15px; color: var(--text); outline: none; }
.composer-box textarea:focus { border: 0; box-shadow: none; background: none; }
.composer-box textarea::placeholder { color: var(--muted); }
.composer-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; gap: 8px; }
.composer-actions .left { display: flex; align-items: center; gap: 2px; margin-left: -8px; min-width: 0; }
.rec-timer { display: inline-flex; align-items: center; gap: 6px; color: var(--danger); font-size: 12.5px; font-weight: 500; font-variant-numeric: tabular-nums; margin-left: 6px; }
.rec-timer i { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: blink 1s steps(2) infinite; }
.mode-badge { font-size: 11.5px; color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 2px 8px; margin-left: 6px; white-space: nowrap; }
.send { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex-shrink: 0; transition: background .15s, opacity .15s, transform .1s; }
.send:hover:not(:disabled) { background: var(--accent-hover); }
.send:active:not(:disabled) { transform: scale(.94); }
.send .i-stop { display: none; }
.send.busy { background: var(--text); color: var(--surface); }
.send.busy .i-send { display: none; } .send.busy .i-stop { display: block; }
.send:disabled { opacity: .35; }
.trim-note { display: flex; align-items: flex-start; gap: 8px; margin: 8px 4px 0; font-size: 12.5px; color: var(--warn); }
.trim-note svg { width: 15px; height: 15px; margin-top: 2px; }
.linkish { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.disclaimer { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.disabled-mode .chat-only { opacity: .4; pointer-events: none; }

.drop-overlay { position: absolute; inset: 10px; z-index: 20; border: 2px dashed var(--accent); border-radius: 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); display: grid; place-items: center; pointer-events: none; animation: fade .15s; }
.drop-overlay div { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.drop-overlay svg { width: 34px; height: 34px; color: var(--accent); }
.drop-overlay b { font-size: 16px; }
.drop-overlay span { color: var(--muted); font-size: 13px; }

/* admin dialog */
.modal { border: 1px solid var(--border); border-radius: 18px; padding: 24px; width: min(380px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.modal::backdrop { background: var(--scrim); }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal p { margin: 0 0 16px; color: var(--muted); font-size: 13.5px; }
.modal .err { color: var(--danger); font-size: 13px; min-height: 1.2em; margin-top: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
a.nav-item { text-decoration: none; }

/* image viewer */
.lightbox { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.82); display: grid; place-items: center; padding: 24px; cursor: zoom-out; animation: fade .15s; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; box-shadow: var(--shadow-lg); }

/* ---------- settings drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: min(400px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; transform: translateX(105%); transition: transform .24s ease; visibility: hidden;
}
.app.settings-open .drawer { transform: none; visibility: visible; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 14px 22px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 16px; margin: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 8px 22px calc(24px + env(safe-area-inset-bottom)); }
.drawer section { padding: 16px 0; border-bottom: 1px solid var(--border); }
.drawer section:last-child { border-bottom: 0; }
.drawer h3 { font-size: 13px; font-weight: 600; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.tag-dev { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); padding: 1px 7px; border-radius: 5px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; line-height: 1.5; }
textarea, .input {
  width: 100%; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font: inherit; font-size: 14px; resize: vertical; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea:focus, .input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); background: var(--surface); }
.row { display: flex; justify-content: space-between; align-items: baseline; font-size: 13.5px; margin-top: 14px; }
.row:first-of-type { margin-top: 0; }
.row small { color: var(--muted); }
.row output { font-family: "JetBrains Mono", monospace; font-size: 12.5px; color: var(--text-2); background: var(--surface-2); padding: 0 7px; border-radius: 5px; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 8px 0 0; }
.range-legend { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); }
.switch { display: flex; align-items: flex-start; gap: 12px; margin: 12px 0; cursor: pointer; user-select: none; font-size: 14px; }
.switch small { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.4; margin-top: 1px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch > span { width: 36px; height: 21px; border-radius: 999px; background: var(--border-strong); position: relative; flex-shrink: 0; transition: background .15s; margin-top: 1px; }
.switch > span::after { content: ""; position: absolute; top: 2.5px; left: 2.5px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(15px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); padding: 3px; border-radius: 10px; }
.seg button { border: 0; background: none; padding: 7px 4px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- tests / bench panels ---------- */
.panel { flex: 1; overflow-y: auto; padding: 32px 28px; }
.panel > * { max-width: 1000px; margin-left: auto; margin-right: auto; }
.panel-head { display: flex; gap: 20px; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; margin-bottom: 22px; }
.panel-head h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.02em; }
.panel-head p { margin: 0; color: var(--muted); max-width: 540px; font-size: 14px; }
.panel-head code { font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.panel-actions { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.panel-actions .switch { margin: 0 0 9px; }
.panel-actions .input { width: 220px; }
.panel-actions .input.narrow { width: 96px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; }
.stat b { display: block; font-size: 28px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.pass b { color: var(--accent); } .stat.fail b { color: var(--danger); } .stat.xfail b { color: var(--warn); }
.progress { grid-column: 1 / -1; height: 5px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .3s; border-radius: 5px; }
.results { display: flex; flex-direction: column; gap: 4px; margin-bottom: 18px; }
.placeholder { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 48px 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--muted); }
.placeholder svg { width: 28px; height: 28px; }
.placeholder p { margin: 0; font-size: 14px; }
.group-title { font-size: 12px; text-transform: capitalize; color: var(--muted); font-weight: 600; margin: 16px 0 6px; }
.tr { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.tr .name { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr .pill { margin-left: auto; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; flex-shrink: 0; }
.pill.PASSED { background: var(--accent-soft); color: var(--accent); }
.pill.FAILED, .pill.ERROR { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.pill.XFAIL, .pill.XPASS { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.pill.SKIPPED { background: var(--surface-2); color: var(--muted); }
.log-wrap summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; font-size: 13.5px; }
.log { background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; font-size: 12.5px; overflow: auto; max-height: 440px; white-space: pre; margin: 0; color: var(--text-2); }
.log.tall { max-height: none; min-height: 320px; }

.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 90;
  background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 12px; font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-lg); max-width: calc(100vw - 32px); animation: toast .2s ease;
}
@keyframes toast { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- tablet / phone ---------- */
@media (max-width: 900px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 45; width: min(var(--sb-w), 84vw); transform: translateX(-100%); box-shadow: var(--shadow-lg); padding-top: calc(12px + env(safe-area-inset-top)); }
  .app.sb-collapsed .sidebar { margin-left: 0; }
  .app.sb-open .sidebar { transform: none; }
  #openSidebar { display: inline-grid; }
  .status-text { display: none; }
  .status { padding: 0; width: 36px; justify-content: center; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar { height: 52px; padding: 0 8px; gap: 4px; padding-top: env(safe-area-inset-top); height: calc(52px + env(safe-area-inset-top)); }
  .top-right { gap: 4px; }
  .status { border: 0; background: none; width: 28px; }
  .model-pick { padding-left: 8px; }
  .model-pick svg { display: none; }
  .model-pick select { max-width: 130px; font-size: 12.5px; }
  .thread { padding: 18px 14px 10px; }
  .composer { padding: 4px 10px calc(10px + env(safe-area-inset-bottom)); }
  .composer-box { border-radius: 20px; padding: 10px 8px 6px 14px; }
  .composer-box textarea, textarea, .input { font-size: 16px; } /* stops iOS zoom on focus */
  .kbd-hint { display: none; }
  .disclaimer { font-size: 11.5px; margin-top: 6px; }
  .chat.is-empty { justify-content: flex-start; }
  .chat.is-empty .thread { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: center; }
  .chat.is-empty .suggestions { order: 2; flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; padding: 0 10px 8px; max-width: 100%; scrollbar-width: none; }
  .chat.is-empty .suggestions::-webkit-scrollbar { display: none; }
  .chat.is-empty .composer { order: 3; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .welcome { padding-bottom: 0; }
  .welcome .logo { width: 42px; height: 42px; margin-bottom: 14px; }
  .welcome h1 { font-size: 26px; }
  .u-acts { opacity: 1; }
  .msg { gap: 10px; margin-bottom: 22px; }
  .msg.assistant .avatar { display: none; }
  .msg.user .bubble { max-width: 88%; }
  .media img { width: 88px; height: 66px; }
  .to-bottom { bottom: 130px; }
  .copy-code { opacity: 1; }
  .conv .acts { display: flex; }
  .panel { padding: 20px 14px; }
  .panel-head h2 { font-size: 19px; }
  .panel-actions { width: 100%; }
  .panel-actions .input, .field { width: 100%; flex: 1 1 140px; }
  .panel-actions .input.narrow { width: 100%; }
  .panel-actions .btn { flex: 1 1 100%; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .stat b { font-size: 24px; }
  .drawer-body { padding: 4px 18px calc(24px + env(safe-area-inset-bottom)); }

  /* Monitor phone rules (390px) */
  .mon-tiles { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
  .mon-tile { padding: 10px 12px !important; }
  .mon-tile-val { font-size: 22px !important; }
  .mon-charts { grid-template-columns: 1fr !important; }
  .mon-two-col { grid-template-columns: 1fr !important; }
  .mon-core-bars { grid-template-columns: repeat(4, 1fr) !important; }
  .mon-header { flex-direction: column !important; align-items: stretch !important; gap: 10px !important; }
  .mon-header-actions .btn { width: 100% !important; min-height: 40px !important; }
}

/* ---------- server monitor dashboard ---------- */
.mon-panel { max-width: 1140px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; padding: 24px 20px 48px; }
/* .panel > * centres children with auto margins, which stops them stretching in this flex column */
.mon-panel > * { margin-left: 0; margin-right: 0; max-width: none; }
.mon-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.mon-header-left { display: flex; flex-direction: column; gap: 4px; }
.mon-title-row { display: flex; align-items: center; gap: 12px; }
.mon-title-row h2 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.mon-live-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--muted); background: var(--surface); border: 1px solid var(--border); padding: 3px 10px; border-radius: 999px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; }
.live-dot.active { animation: livePulse 1.6s infinite; }
.live-dot.warn { background: var(--warn); }
.live-dot.paused { background: var(--muted); }
@keyframes livePulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .4; transform: scale(.85); } }
.mon-instance-line { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mon-header-actions { display: flex; align-items: center; gap: 8px; }
.mon-header-actions .btn { min-height: 38px; }

.mon-banner { background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 12px 16px; font-size: 13.5px; color: var(--text-2); text-align: center; }

.mon-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.mon-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px; transition: border-color .15s, box-shadow .15s; min-height: 110px;
}
.mon-tile.warning { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn); }
.mon-tile.danger { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.mon-tile-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.mon-tile-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.mon-tile-sub { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%; }
.mon-tile-val { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; display: flex; align-items: baseline; gap: 4px; margin: 2px 0 6px; }
.mon-tile-val small { font-size: 13px; font-weight: 500; color: var(--muted); }
.mon-tile.warning .mon-tile-val { color: var(--warn); }
.mon-tile.danger .mon-tile-val { color: var(--danger); }

.sparkline { width: 100%; height: 22px; margin-top: auto; overflow: visible; }
.sparkline path { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mon-tile.warning .sparkline path { stroke: var(--warn); }
.mon-tile.danger .sparkline path { stroke: var(--danger); }

.mon-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.mon-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.mon-card-head h3 { font-size: 14.5px; font-weight: 600; margin: 0; }
.mon-card-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.mon-core-bars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.core-bar-item { display: flex; flex-direction: column; gap: 4px; font-size: 11px; text-align: center; color: var(--muted); }
.core-bar-track { height: 46px; background: var(--surface-2); border-radius: 6px; display: flex; align-items: flex-end; overflow: hidden; padding: 2px; }
.core-bar-fill { width: 100%; background: var(--accent); border-radius: 4px; transition: height .25s ease; min-height: 2px; }
.core-bar-item.high .core-bar-fill { background: var(--warn); }

.mon-charts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.mon-chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; }
.mon-chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.mon-chart-head h4 { font-size: 13.5px; font-weight: 600; margin: 0; }
.mon-chart-readout { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart-container { width: 100%; height: 160px; position: relative; }
.chart-container svg { width: 100%; height: 100%; display: block; overflow: visible; }

.chart-grid-line { stroke: var(--border); stroke-dasharray: 3, 3; stroke-width: 1; }
.chart-axis-text { font-size: 10px; fill: var(--muted); stroke: none; font-family: "JetBrains Mono", monospace; } /* the global svg rule strokes icons; text must not inherit it */
.chart-path { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-path.c-green { stroke: var(--accent); }
.chart-path.c-blue { stroke: #3b82f6; }
.chart-path.c-purple { stroke: #a855f7; }
.chart-path.c-amber { stroke: var(--warn); }
.chart-area { opacity: .12; }
.chart-area.c-green { fill: var(--accent); }
.chart-area.c-blue { fill: #3b82f6; }
.chart-legend { display: flex; align-items: center; gap: 12px; margin-top: 6px; font-size: 11.5px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; }

.mon-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mon-services-list { display: flex; flex-direction: column; gap: 8px; }
.mon-service-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--surface-2); border-radius: 8px; font-size: 13px; }
.mon-service-left { display: flex; align-items: center; gap: 8px; }
.mon-service-name { font-weight: 600; font-family: "JetBrains Mono", monospace; font-size: 12.5px; }
.mon-service-right { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.mon-top-list { overflow-x: auto; max-height: 240px; }
.mon-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.mon-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); font-weight: 600; }
.mon-table td { padding: 6px 8px; border-bottom: 1px solid var(--surface-2); font-variant-numeric: tabular-nums; }
.mon-table td.pname { font-family: "JetBrains Mono", monospace; font-weight: 500; }

.mon-spec-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.spec-group { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.spec-group h5 { margin: 0 0 4px 0; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--text-2); }
.spec-dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; font-size: 12px; }
.spec-dl dt { color: var(--muted); white-space: nowrap; }
.spec-dl dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; word-break: break-word; color: var(--text); }

@media (max-width: 900px) {
  .mon-charts { grid-template-columns: 1fr; }
  .mon-two-col { grid-template-columns: 1fr; }
  .mon-core-bars { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
