/* Neutral greys so the ocean carries the colour. The accent is ink, not a hue:
   near-black on the light page, near-white on the dark one. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --input: #ffffff;
  --border: #e1e4e8;
  --text: #1c1f24;
  --strong: #0e1013;
  --muted: #6b7079;
  --user-bubble: #e8eaee;
  --user-text: #1c1f24;
  --accent: #2b2e34;
  --on-accent: #ffffff;
  --error: #c21f1f;
  --ok: #2e8b57;
  --shadow: 0 4px 18px rgb(20 24 32 / 0.07);
  --hover: rgb(30 36 48 / 0.06);
  --active: rgb(30 36 48 / 0.09);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181b;
    --surface: #1f2024;
    --input: #232428;
    --border: #33353a;
    --text: #d7d9dd;
    --strong: #f3f4f6;
    --muted: #8e9198;
    --user-bubble: #2d2f34;
    --user-text: #e6e8eb;
    --accent: #e3e5e8;
    --on-accent: #17181b;
    --error: #ff736b;
    --ok: #5cc28a;
    --shadow: 0 4px 18px rgb(0 0 0 / 0.3);
    --hover: rgb(255 255 255 / 0.05);
    --active: rgb(255 255 255 / 0.09);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #17181b;
  --surface: #1f2024;
  --input: #232428;
  --border: #33353a;
  --text: #d7d9dd;
  --strong: #f3f4f6;
  --muted: #8e9198;
  --user-bubble: #2d2f34;
  --user-text: #e6e8eb;
  --accent: #e3e5e8;
  --on-accent: #17181b;
  --error: #ff736b;
  --ok: #5cc28a;
  --shadow: 0 4px 18px rgb(0 0 0 / 0.3);
  --hover: rgb(255 255 255 / 0.05);
  --active: rgb(255 255 255 / 0.09);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.muted { color: var(--muted); }

/* ---------- Aquarium (see fish.js) ---------- */
.fish {
  position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0;
  pointer-events: none; transition: opacity 0.6s ease;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}
@media (min-width: 761px) {
  body.has-sidebar .fish { left: 280px; width: calc(100% - 280px); }
}
.cover, .boot, .login, .app { position: relative; z-index: 1; }

.error { color: var(--error); font-size: 14px; margin: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---------- Boot ---------- */
.boot { height: 100%; display: grid; place-items: center; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Calculator cover (see cover.js) ---------- */
.cover {
  min-height: 100%; padding: 24px 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  font-variant-numeric: tabular-nums;
}
.calc {
  position: relative; width: min(340px, 100%);
  background: var(--surface); border: 1px solid var(--border); border-radius: 26px;
  box-shadow: var(--shadow); padding: 18px;
}
.calc-code {
  position: absolute; top: 10px; left: 14px;
  background: none; border: 0; padding: 2px 4px;
  font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); opacity: 0.45;
}
.calc-code:hover, .cover.is-code .calc-code { opacity: 1; }
.calc-display { text-align: right; padding: 18px 6px 14px; min-width: 0; }
.calc-line { font-size: 14px; color: var(--muted); min-height: 21px; overflow-wrap: anywhere; }
.calc-screen { font-size: 40px; line-height: 1.2; font-weight: 300; overflow-wrap: anywhere; min-height: 48px; }
.cover.is-code .calc-screen { letter-spacing: 0.15em; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.calc-key {
  height: 54px; border: 0; border-radius: 14px;
  background: var(--hover); font-size: 20px;
  transition: filter 0.1s ease, transform 0.05s ease;
}
.calc-key:active { transform: scale(0.96); }
.calc-key:hover { filter: brightness(0.96); }
.calc-key-fn { height: 42px; font-size: 15px; background: transparent; border: 1px solid var(--border); }
.calc-key-util { background: var(--active); }
.calc-key-op { background: var(--accent); color: var(--on-accent); font-size: 24px; }
.calc-key-wide { grid-column: span 2; }
.calc-recent { width: min(340px, 100%); }
.calc-recent h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 6px 6px; text-transform: uppercase; letter-spacing: 0.06em; }
.calc-history { list-style: none; margin: 0; padding: 0; }
.calc-history button {
  width: 100%; display: flex; justify-content: space-between; gap: 12px;
  background: none; border: 0; border-radius: 10px; padding: 7px 8px; text-align: left;
}
.calc-history button:hover { background: var(--hover); }
.calc-history-expr { color: var(--muted); overflow-wrap: anywhere; min-width: 0; }
.calc-history-result { font-weight: 600; }

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--accent); color: var(--on-accent); border: 0; border-radius: 12px;
  padding: 11px 18px; font-weight: 600;
}
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.btn-link { background: none; border: 0; color: var(--accent); padding: 6px 4px; font-weight: 500; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border: 0; border-radius: 10px; background: none; color: var(--accent);
}
.icon-btn:hover { background: var(--hover); }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px;
  text-align: center; padding: 28px 20px;
  /* A frosted panel so passing sharks never sit under the form. */
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  border-radius: 22px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 32px; letter-spacing: -0.02em; }
.login-card p { margin: -8px 0 6px; }
.brand-mark {
  width: 56px; height: 56px; margin: 0 auto 4px; border-radius: 16px;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center;
  font-size: 28px; font-weight: 700;
}
.field { display: flex; flex-direction: column; gap: 4px; text-align: left; font-size: 14px; color: var(--muted); }
.field input, .search {
  width: 100%; background: var(--input); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; font-size: 16px;
}
.field input:focus, .search:focus, .composer-box:focus-within {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--active);
}

/* ---------- App layout ---------- */
.app { height: 100%; display: flex; }
.sidebar {
  width: 280px; flex: none; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar-head { display: flex; align-items: center; gap: 6px; padding: 14px 12px 8px 10px; }
.sidebar-title { flex: 1; font-weight: 650; font-size: 17px; }
.sidebar .search { margin: 0 12px 8px; width: auto; padding: 8px 12px; font-size: 15px; border-radius: 10px; }
.conversation-list { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
.sidebar-empty { flex: 1; padding: 24px 20px; text-align: center; color: var(--muted); font-size: 14px; }

.conversation {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
}
.conversation:hover, .conversation:focus-within { background: var(--hover); }
.conversation.active { background: var(--active); }
.conversation .pin { width: 13px; height: 13px; color: var(--accent); }
.conversation-text { flex: 1; min-width: 0; }
.conversation-title { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-date { display: block; font-size: 12px; color: var(--muted); }
.conversation-actions { display: none; gap: 2px; }
.conversation:hover .conversation-actions,
.conversation:focus-within .conversation-actions,
.conversation.menu-open .conversation-actions { display: flex; }
.conversation-actions button {
  width: 28px; height: 28px; display: grid; place-items: center;
  border: 0; border-radius: 7px; background: none; color: var(--muted);
}
.conversation-actions button:hover { background: var(--hover); color: var(--text); }
.conversation-actions button.delete:hover { color: var(--error); }
.conversation-actions svg { width: 15px; height: 15px; }

.sidebar-foot { border-top: 1px solid var(--border); padding: 8px; }
.account-btn {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 0; border-radius: 10px; background: none; text-align: left;
}
.account-btn:hover { background: var(--hover); }
.account-btn svg { color: var(--muted); }
.avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center;
  font-size: 14px; font-weight: 600; text-transform: uppercase;
}
.account-email { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.main.is-empty .topbar { border-bottom-color: transparent; }
.chat-title { flex: 1; min-width: 0; text-align: right; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.model-picker { position: relative; }
.model-button {
  display: flex; align-items: center; gap: 4px; border: 0; background: none;
  font-weight: 650; font-size: 17px; padding: 6px 10px; border-radius: 10px;
}
.model-button:hover { background: var(--hover); }
.model-button svg { width: 16px; height: 16px; color: var(--muted); }
.model-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; min-width: 290px;
  list-style: none; margin: 0; padding: 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}

.model-option {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border: 0; border-radius: 10px; background: none; text-align: left;
}
.model-option:hover { background: var(--hover); }
.model-option-text { flex: 1; }
.model-option-name { display: block; font-weight: 600; }
.model-option-desc { display: block; font-size: 13px; color: var(--muted); }
.model-option .check { color: var(--accent); visibility: hidden; }
.model-option[aria-selected="true"] .check { visibility: visible; }

/* ---------- Messages ---------- */
.messages { flex: 1; overflow-y: auto; padding: 28px 16px 12px; }
.message { max-width: 760px; margin: 0 auto 18px; }
.message.user { display: flex; justify-content: flex-end; }
.bubble {
  max-width: min(78%, 560px); background: var(--user-bubble); color: var(--user-text);
  padding: 10px 15px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere;
}
/* Answers read like notes, not a feed: roomy lines, quiet headings that sit closer to
   what follows than to what came before, and lists with soft grey markers. */
.assistant { overflow-wrap: anywhere; line-height: 1.7; }
.assistant > * { margin: 0 0 14px; }
.assistant > :last-child { margin-bottom: 0; }
.assistant h1, .assistant h2, .assistant h3 {
  color: var(--strong); font-weight: 600; line-height: 1.35; letter-spacing: -0.01em; margin: 26px 0 8px;
}
.assistant > :first-child { margin-top: 0; }
.assistant h1 { font-size: 19px; }
.assistant h2 { font-size: 17.5px; }
.assistant h3 { font-size: 16px; }
.assistant strong { color: var(--strong); font-weight: 600; }
.assistant ul, .assistant ol { padding-left: 1.5em; }
.assistant li { margin: 0 0 6px; padding-left: 0.3em; }
.assistant li:last-child { margin-bottom: 0; }
.assistant li::marker { color: var(--muted); }
.assistant ol > li::marker { font-variant-numeric: tabular-nums; font-weight: 500; }
.assistant code {
  font: 14px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--hover); padding: 1px 5px; border-radius: 5px;
}
.assistant a { color: var(--accent); }

.thinking { max-width: 760px; margin: 0 auto 18px; display: flex; align-items: center; gap: 10px; color: var(--muted); }
.thinking .spinner { width: 16px; height: 16px; border-width: 2px; }

/* The fish that delivers a sent message, and what it carries (see messenger.js). */
.messenger, .messenger-cargo, .messenger-trail { position: fixed; top: 0; left: 0; pointer-events: none; will-change: transform; }
.messenger { z-index: 41; }
.messenger canvas { display: block; }
.messenger-cargo { z-index: 40; max-width: none; margin: 0; }
.messenger-trail { z-index: 39; font: 12px ui-monospace, Menlo, monospace; color: var(--muted); }
.hero.is-ghost { display: block; position: fixed; z-index: 38; margin: 0; padding: 0; text-align: center; pointer-events: none; }
.hero.is-ghost span { display: inline-block; }

/* ---------- Empty chat ---------- */
.hero { display: none; }
.main.is-empty .messages { display: none; }
.main.is-empty .hero { display: block; margin-top: auto; padding: 0 16px 22px; text-align: center; }
.main.is-empty .composer { margin-bottom: auto; padding-bottom: 14vh; }
.hero h1 { margin: 0 0 8px; font-size: clamp(26px, 4vw, 36px); font-weight: 500; letter-spacing: -0.025em; }
.hero p { margin: 0; }
/* Sharks sometimes cut across the heading; a soft halo keeps it readable. */
.hero h1, .hero p, .hint, .login-card h1, .login-card p, .login-card .field, .login-card .btn-link {
  text-shadow: 0 0 6px var(--bg), 0 0 14px var(--bg), 0 0 22px var(--bg);
}

/* ---------- Composer ---------- */
.composer { padding: 8px 16px 12px; }
.composer > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.composer .error { margin-bottom: 8px; }
.composer-box {
  display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 26px;
  box-shadow: var(--shadow);
}
.composer-box textarea {
  flex: 1; border: 0; outline: none; background: none; resize: none;
  padding: 9px 0; max-height: 180px; line-height: 1.45;
}
.send-btn {
  width: 38px; height: 38px; flex: none; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center;
}
.send-btn:disabled { background: var(--border); cursor: default; }
.send-btn svg { stroke-width: 2.5; }
.hint { font-size: 12px; text-align: center; margin-top: 6px; margin-bottom: 0; }

/* ---------- Dialogs ---------- */
.sheet {
  width: min(520px, calc(100% - 32px)); max-height: min(720px, calc(100% - 48px));
  padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--bg); color: var(--text); box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgb(0 0 0 / 0.35); }
.sheet-small { width: min(400px, calc(100% - 32px)); }
.sheet-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-body { padding: 16px 18px 20px; }
.group { margin-bottom: 20px; }
.group:last-child { margin-bottom: 0; }
.group h3 { margin: 0 0 6px 4px; font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.group > .row, .group > div:not(.segmented) {
  background: var(--surface);
}
.group > :nth-child(2) { border-top-left-radius: 12px; border-top-right-radius: 12px; }
.group > :last-child { border-bottom-left-radius: 12px; border-bottom-right-radius: 12px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 11px 14px; border: 0; border-bottom: 1px solid var(--border);
  background: var(--surface); text-align: left; font-size: 15px;
}
.group > :last-child, .group > div > .row:last-child { border-bottom: 0; }
.row-btn { color: var(--accent); }
.row-btn:hover { background: var(--hover); }
.row-btn.danger { color: var(--error); }
.row .muted { font-size: 14px; }
.status-ok { color: var(--ok); }
.status-bad { color: var(--error); }

#settings-models .model-option { border-radius: 0; border-bottom: 1px solid var(--border); padding: 11px 14px; }
#settings-models .model-option:last-child { border-bottom: 0; }

.segmented { display: flex; padding: 3px; gap: 3px; background: var(--hover); border-radius: 11px; }
.segmented button { flex: 1; border: 0; background: none; padding: 7px; border-radius: 8px; font-size: 14px; }
.segmented button[aria-checked="true"] { background: var(--surface); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); font-weight: 600; }

.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 13px; background: var(--border); transition: background 0.15s; pointer-events: none; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgb(0 0 0 / 0.2);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:disabled + span { opacity: 0.5; }
.user-meta { min-width: 0; }
.user-meta small { display: block; color: var(--muted); font-size: 12px; }

.palettes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; background: none !important; }
.palette {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-size: 13px;
}
.palette:hover { background: var(--hover); }
.palette[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--active); font-weight: 600; }
.palette-swatch { display: grid; grid-template-columns: repeat(4, 12px); gap: 2px; }
.palette-swatch span { width: 12px; height: 12px; border-radius: 2px; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* ---------- Wide screens: chats can be pushed off to the side ---------- */
@media (min-width: 761px) {
  .sidebar { transition: margin-left 0.2s ease; }
  .app.sidebar-collapsed .sidebar { margin-left: -281px; visibility: hidden; transition: margin-left 0.2s ease, visibility 0s 0.2s; }
  .app.sidebar-collapsed .only-narrow { display: inline-grid; }
}

/* ---------- Narrow screens: sidebar becomes a drawer ---------- */
.only-narrow { display: none; }
.scrim { display: none; }
@media (max-width: 760px) {
  .only-narrow { display: inline-grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(300px, 86vw);
    transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgb(0 0 0 / 0.3); }
  .conversation-actions { display: flex; }
  .chat-title { display: none; }
  .topbar { justify-content: space-between; }
  .messages { padding: 18px 16px 8px; }
  .hint { display: none; }
  .bubble { max-width: 86%; }
}
