:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --panel-2: #efefec;
  --text: #1c1c1a;
  --muted: #6d6d68;
  --border: #e2e2dd;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --danger: #b3412e;
  --ok: #2e9b58;
  --off: #b9b9b2;
  --bar-in: #9cc3b6;
  --bar-out: #2f6f5e;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --panel: #1c1c1b;
    --panel-2: #262624;
    --text: #ececea;
    --muted: #9a9a94;
    --border: #31312e;
    --accent: #5fb39a;
    --accent-text: #0d1f1a;
    --danger: #e0715d;
    --ok: #4cc27a;
    --off: #55554f;
    --bar-in: #2f5a4e;
    --bar-out: #5fb39a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
code, .mono { font-family: var(--mono); font-size: 0.9em; }
h2 { margin: 0 0 4px; font-size: 1.35rem; }
h3 { margin: 28px 0 10px; font-size: 0.95rem; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); }
[hidden] { display: none !important; }

.brand { font-weight: 700; letter-spacing: -0.02em; font-size: 1.1rem; }
.brand span { color: var(--accent); margin: 0 1px; }
.brand.big { font-size: 2rem; }

/* buttons & inputs */
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 0.85rem; }
.btn.block { width: 100%; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* login */
body.login { align-items: center; justify-content: center; padding: 16px; }
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card .brand { font-size: 1.8rem; }
.login-card .btn { margin-top: 12px; width: 100%; }

/* header */
.top {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.top form { margin: 0; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--panel-2); color: var(--text); }
.status { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--off); }
.status.on .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }

.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; }
.view.page { flex-direction: column; overflow-y: auto; padding: 28px max(18px, calc((100% - 1040px) / 2)); }

/* chat */
.chat { min-height: 0; }
.sidebar {
  width: 260px;
  border-right: 1px solid var(--border);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv-list li { display: flex; align-items: center; border-radius: 8px; }
.conv-list li:hover, .conv-list li.active { background: var(--panel-2); }
.conv-title {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 7px 10px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-del { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px 10px; font-size: 1.1rem; visibility: hidden; }
.conv-list li:hover .conv-del { visibility: visible; }
.conv-del:hover { color: var(--danger); }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 24px max(18px, calc((100% - 780px) / 2)); }
.empty { text-align: center; margin-top: 18vh; }
.msg { margin: 0 0 22px; }
.msg.user .body {
  background: var(--panel-2);
  border-radius: 14px;
  padding: 10px 14px;
  margin-left: auto;
  width: fit-content;
  max-width: 85%;
  white-space: pre-wrap;
}
.msg.assistant .body { overflow-wrap: anywhere; }
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body pre {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}
.msg.assistant .body :not(pre) > code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.msg.assistant .body table { border-collapse: collapse; }
.msg.assistant .body th, .msg.assistant .body td { border: 1px solid var(--border); padding: 4px 8px; }
.msg.pending .body::after { content: "●"; color: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.2; } }
.think { margin-bottom: 8px; font-size: 0.88rem; color: var(--muted); }
.think summary { cursor: pointer; user-select: none; }
.think-body { white-space: pre-wrap; border-left: 2px solid var(--border); padding: 4px 0 4px 12px; margin-top: 6px; max-height: 320px; overflow-y: auto; }

.composer {
  margin: 0 max(18px, calc((100% - 780px) / 2)) 18px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 14px;
  padding: 10px;
}
.composer textarea { width: 100%; border: 0; resize: none; padding: 6px; background: transparent; max-height: 240px; }
.composer textarea:focus { outline: none; }
.composer-bar { display: flex; align-items: center; gap: 10px; }
.composer-bar select { max-width: 280px; padding: 5px 8px; font-size: 0.85rem; }
.composer-bar .muted { flex: 1; }

/* pages */
.row { display: flex; gap: 10px; align-items: center; margin: 16px 0; flex-wrap: wrap; }
.row.spread { justify-content: space-between; margin-top: 0; }
.row input { flex: 1; min-width: 200px; max-width: 360px; }
.reveal { border: 1px solid var(--accent); border-radius: var(--radius); padding: 4px 16px; background: color-mix(in srgb, var(--accent) 8%, var(--panel)); }
.reveal code { word-break: break-all; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); padding: 8px; }
.table td { border-bottom: 1px solid var(--border); padding: 8px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.revoked td { color: var(--muted); text-decoration: line-through; }
.table tr.revoked td:last-child { text-decoration: none; }
.table tr.err td { color: var(--danger); }
.scroll-x { overflow-x: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 16px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile-label { color: var(--muted); font-size: 0.82rem; }
.tile-value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile-sub { color: var(--muted); font-size: 0.8rem; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 180px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.bar { flex: 1; min-width: 14px; max-width: 40px; height: 100%; display: flex; flex-direction: column; }
.bar-stack { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; }
.bar-in { background: var(--bar-in); border-radius: 0 0 3px 3px; }
.bar-out { background: var(--bar-out); border-radius: 3px 3px 0 0; }
.bar-label { font-size: 0.68rem; color: var(--muted); text-align: center; margin-top: 4px; white-space: nowrap; }

@media (max-width: 760px) {
  .top { gap: 10px; padding: 10px 16px; }
  .tabs { order: 3; flex-basis: 100%; }
  .sidebar { display: none; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
  .messages { padding: 16px; }
  .composer { margin: 0 16px 16px; }
}

/* API guide */
.guide p { max-width: 760px; }
.facts { display: grid; gap: 8px; margin: 16px 0 8px; }
.facts div { display: grid; grid-template-columns: 110px 1fr; gap: 12px; align-items: baseline; }
.facts code { overflow-wrap: anywhere; }
.notes { color: var(--muted); padding-left: 20px; margin: 8px 0 0; }
.notes li { margin: 4px 0; }
.notes a { color: var(--accent); }
.snippet { position: relative; }
.snippet pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 8px 0 0;
  font-size: 0.85rem;
  line-height: 1.5;
}
.snippet .copy { position: absolute; top: 8px; right: 8px; }
.tabs-inline { display: flex; gap: 4px; }
.tabs-inline button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.tabs-inline button.active { background: var(--panel-2); color: var(--text); }
.model-ids { padding-left: 20px; }
.model-ids li { margin: 4px 0; }
@media (max-width: 760px) {
  .facts div { grid-template-columns: 1fr; gap: 2px; }
}
