/* ---------- design tokens ---------- */
:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f5f6f9;
  --surface-3: #e8ebf1;
  --line: #dfe3ea;
  --line-soft: #ebeef3;
  --text: #13161c;
  --text-2: #3d4450;
  --text-3: #5f6776;
  --accent: #0f766e;
  --accent-hover: #0c5f58;
  --accent-soft: #d6f0eb;
  --on-accent: #ffffff;
  --on-accent-soft: #0a3f3a;
  --ok: #17803d;
  --ok-soft: #dcf4e3;
  --warn: #9a5a06;
  --warn-soft: #fcefd3;
  --bad: #b42318;
  --bad-soft: #fde3df;
  --inverse: #1c2028;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-2: 0 1px 2px rgba(16, 24, 40, 0.06), 0 14px 36px -18px rgba(16, 24, 40, 0.22);
  --r-card: 20px;
  --r-pill: 999px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #0f1216;
    --surface: #161a20;
    --surface-2: #1c2129;
    --surface-3: #262c36;
    --line: #2b313b;
    --line-soft: #222831;
    --text: #eceff3;
    --text-2: #b4bcc8;
    --text-3: #818a98;
    --accent: #5fd0c1;
    --accent-hover: #86dccf;
    --accent-soft: #163d39;
    --on-accent: #062825;
    --on-accent-soft: #c7f3ec;
    --ok: #7ee2a0;
    --ok-soft: #163522;
    --warn: #f2c46d;
    --warn-soft: #3a2d12;
    --bad: #ff9d94;
    --bad-soft: #3d1d1a;
    --inverse: #eceff3;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 14px 36px -18px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #161a20;
    --surface-2: #1c2129;
    --surface-3: #262c36;
    --line: #2b313b;
    --line-soft: #222831;
    --text: #eceff3;
    --text-2: #b4bcc8;
    --text-3: #818a98;
    --accent: #5fd0c1;
    --accent-hover: #86dccf;
    --accent-soft: #163d39;
    --on-accent: #062825;
    --on-accent-soft: #c7f3ec;
    --ok: #7ee2a0;
    --ok-soft: #163522;
    --warn: #f2c46d;
    --warn-soft: #3a2d12;
    --bad: #ff9d94;
    --bad-soft: #3d1d1a;
    --inverse: #eceff3;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 14px 36px -18px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }
.small { font-size: 13px; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.err-text { color: var(--bad); }
.bad-text { color: var(--bad); }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }

.rail {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 8px;
  padding: 22px 16px 18px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 20px;
  font-weight: 700; font-size: 17px; letter-spacing: -0.01em;
}
.mark {
  width: 34px; height: 34px; border-radius: 12px;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  height: 44px; padding: 0 16px;
  border-radius: var(--r-pill);
  color: var(--text-2); font-weight: 500;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.nav a:hover { background: var(--surface-3); color: var(--text); }
.nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav a.active { background: var(--accent-soft); color: var(--on-accent-soft); font-weight: 650; }
.nav .ico {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.side-foot {
  display: none;
  margin-top: auto; padding: 14px 16px;
  border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-1);
}
.side-foot-label { display: block; font-size: 12px; color: var(--text-3); font-weight: 600; margin-bottom: 4px; }
.endpoint { font-family: var(--mono); font-size: 12px; color: var(--text-2); word-break: break-all; }

.content { min-width: 0; padding: 36px 48px 120px; }
#view { max-width: 1180px; margin: 0 auto; }

@keyframes pageIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.page { animation: pageIn 0.42s var(--ease) both; }

/* ---------- headings & surfaces ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 24px;
  margin-bottom: 28px;
}
.page-head h1 { margin: 0; font-size: 32px; line-height: 1.15; font-weight: 700; letter-spacing: -0.025em; }
.sub { color: var(--text-2); margin: 8px 0 0; max-width: 640px; font-size: 15px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-card);
  padding: 24px;
  box-shadow: var(--shadow-1);
  min-width: 0;
}
.panel h2 { margin: 0 0 16px; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .spacer { flex: 1; }

.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.split { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.form-panel { position: sticky; top: 24px; }

.count {
  font-size: 12px; font-weight: 700; line-height: 22px;
  padding: 0 10px; border-radius: var(--r-pill);
  background: var(--surface-3); color: var(--text-2);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 20px;
  border: 0; border-radius: var(--r-pill);
  background: var(--surface-3); color: var(--text);
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background 0.2s var(--ease), box-shadow 0.2s var(--ease), transform 0.12s var(--ease), opacity 0.2s;
}
.btn:hover { box-shadow: inset 0 0 0 999px rgba(127, 127, 127, 0.1); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; box-shadow: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); box-shadow: none; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-3); box-shadow: none; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.danger:hover { box-shadow: inset 0 0 0 999px rgba(180, 35, 24, 0.08); }
.btn.sm { height: 34px; padding: 0 14px; font-size: 13px; }
.btn.icon-btn { width: 36px; height: 36px; padding: 0; flex: none; }
.btn.muted-btn { background: transparent; color: var(--text-2); }
.btn.clear-log { background: transparent; color: var(--bad); }
.btn.clear-log:hover { background: var(--bad-soft); box-shadow: none; }
.btn.add-target {
  width: 100%; margin-top: 10px; height: 40px;
  background: transparent; color: var(--text-2);
  border: 1.5px dashed var(--line);
}
.btn.add-target:hover { background: var(--surface-2); box-shadow: none; }

/* ---------- fab ---------- */
.fab {
  position: fixed; right: 44px; bottom: 36px; z-index: 20;
  height: 56px; padding: 0 26px 0 20px;
  display: inline-flex; align-items: center; gap: 10px;
  border: 0; border-radius: 20px;
  background: var(--accent); color: var(--on-accent);
  font-weight: 650; font-size: 15px; cursor: pointer;
  box-shadow: 0 16px 32px -12px var(--accent), 0 4px 12px rgba(0, 0, 0, 0.12);
  animation: pageIn 0.45s var(--ease) both;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.fab:hover { transform: translateY(-2px); }
.fab.compact { width: 56px; padding: 0; justify-content: center; }
.fab.compact span { display: none; }
.fab:active { transform: scale(0.96); }
.fab:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; min-width: 0; }
.field > label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 600; color: var(--text-2); padding-left: 6px;
}
.form-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }

input[type="text"], input[type="url"], input[type="password"], input[type="number"], select {
  height: 46px; width: 100%; min-width: 0;
  padding: 0 18px;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--surface-2); outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
select {
  -webkit-appearance: none; appearance: none; cursor: pointer;
  padding-right: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%237a828f' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 18px center;
}
input[readonly] { opacity: 0.75; }
textarea {
  width: 100%; min-height: 96px; resize: vertical;
  padding: 12px 18px; line-height: 1.5;
  border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface-2); outline: none;
  font-family: var(--mono); font-size: 13px;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.field.sys textarea { min-height: 120px; font-family: var(--font); font-size: 14px; }
.hint { font-size: 12.5px; color: var(--text-3); padding-left: 6px; }
.form-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; }

.switch { position: relative; display: inline-flex; width: 48px; height: 28px; flex: none; cursor: pointer; }
.switch input {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1;
}
.switch .track {
  position: absolute; inset: 0; border-radius: var(--r-pill);
  background: var(--surface-3); border: 1px solid var(--line);
  transition: background 0.3s var(--ease), border-color 0.3s var(--ease);
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #ffffff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.35s var(--ease), width 0.2s var(--ease);
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch:active .track::after { width: 26px; }
.switch input:checked:active + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 4px; font-size: 14px; color: var(--text-2); font-weight: 500; }

/* ---------- chips, badges, pills ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 11px; border-radius: var(--r-pill);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.model {
  font-family: var(--mono); font-weight: 500; font-size: 12px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text-2);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tone-0 { background: #d6f0eb; color: #0a4f47; }
.tone-1 { background: #dce7ff; color: #1d3f8f; }
.tone-2 { background: #fcefd3; color: #7a4a05; }
.tone-3 { background: #e4e9f1; color: #334155; }
.tone-4 { background: #fde3e8; color: #8a1f35; }
.tone-5 { background: #dcf4e3; color: #14532d; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tone-0 { background: #163d38; color: #9ef0e2; }
  .tone-1 { background: #1b2a4a; color: #b5ccff; }
  .tone-2 { background: #3a2d12; color: #f2d48f; }
  .tone-3 { background: #232b37; color: #c3ccd9; }
  .tone-4 { background: #3d1a25; color: #ffb3c1; }
  .tone-5 { background: #163522; color: #9fe9b5; }
}
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600;
  background: var(--surface-3); color: var(--text-2); white-space: nowrap;
}
.pill .d { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- settings: provider list ---------- */
.list { display: flex; flex-direction: column; gap: 12px; }
.item {
  display: flex; align-items: center; gap: 18px;
  padding: 18px 20px; border-radius: 18px;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  transition: background 0.2s var(--ease);
}
.item:hover { background: var(--surface-3); }
.item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item-head .name { font-weight: 650; font-size: 16px; margin-right: 2px; }
.detail { font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 12px; flex: none; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.kv { display: flex; flex-direction: column; gap: 8px; padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.kv:last-child { border-bottom: 0; padding-bottom: 0; }
.kv:first-of-type { padding-top: 0; }
.kv .k { font-size: 13px; color: var(--text-3); font-weight: 600; }
.code-box {
  font-family: var(--mono); font-size: 13px; color: var(--text-2);
  background: var(--surface-2); padding: 10px 14px; border-radius: 14px; word-break: break-all;
}

/* ---------- routes ---------- */
.route-card { display: flex; flex-direction: column; }
.route-name { margin: 0; font-family: var(--mono); font-size: 16px; font-weight: 700; }
.route-steps { display: flex; flex-direction: column; gap: 10px; }
.step { display: flex; align-items: center; gap: 10px; min-width: 0; }
.step .n {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--on-accent-soft);
  font-size: 12px; font-weight: 700;
}
.step .target { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; flex-wrap: wrap; }
.step select { flex: 1; min-width: 0; }
.model-name { font-family: var(--mono); font-size: 13px; color: var(--text-2); }

/* ---------- empty states ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  padding: 48px 24px; color: var(--text-2);
}
.empty strong { color: var(--text); font-size: 16px; margin-top: 4px; }
.empty > div:not(.glyph) { max-width: 380px; font-size: 14px; color: var(--text-3); }
.empty .glyph {
  width: 60px; height: 60px; border-radius: 22px; margin-bottom: 8px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--on-accent-soft);
}

/* ---------- playground ---------- */
.play { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; align-items: start; }
.play-side { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.endpoint-box {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface-2); border-radius: 16px; padding: 12px 14px;
  font-size: 13px; color: var(--text-2); word-break: break-all;
}
.chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; height: calc(100vh - 210px); min-height: 540px; }
.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line-soft);
}
.model-pick { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.model-pick select { max-width: 460px; }
.label-inline { font-size: 13px; font-weight: 600; color: var(--text-3); white-space: nowrap; }

.thread { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.thread .empty { margin: auto; }
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 76%; animation: pageIn 0.3s var(--ease) both; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.who { font-size: 12px; font-weight: 600; color: var(--text-3); padding: 0 12px; }
.msg .body {
  padding: 12px 18px; border-radius: 22px;
  white-space: pre-wrap; word-break: break-word; line-height: 1.6;
}
.msg.user .body { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 8px; }
.msg.assistant .body { background: var(--surface-2); border: 1px solid var(--line-soft); border-bottom-left-radius: 8px; }
.msg.error .body { background: var(--bad-soft); color: var(--bad); }
.cursor::after {
  content: ""; display: inline-block; width: 7px; height: 14px; margin-left: 4px;
  background: currentColor; border-radius: 2px; vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.stats { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 0 6px; margin-top: 2px; font-size: 12px; color: var(--text-3); }
.stats b { font-family: var(--mono); font-weight: 600; color: var(--text-2); }
.stats .chip { height: 22px; font-size: 11.5px; }

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 14px 16px 16px; border-top: 1px solid var(--line-soft);
}
.composer textarea {
  flex: 1; min-height: 50px; max-height: 200px;
  padding: 14px 22px; border-radius: 26px; resize: none;
  font-family: var(--font); font-size: 15px;
}
.send {
  width: 52px; height: 52px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); cursor: pointer;
  box-shadow: 0 10px 22px -10px var(--accent);
  transition: transform 0.15s var(--ease), opacity 0.2s, background 0.2s;
}
.send:hover { transform: scale(1.05); background: var(--accent-hover); }
.send:active { transform: scale(0.95); }
.send:disabled { opacity: 0.4; transform: none; box-shadow: none; cursor: default; }
.send:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- usage ---------- */
.stat-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--r-card); padding: 20px 22px; box-shadow: var(--shadow-1);
}
.stat .k { font-size: 13px; color: var(--text-3); font-weight: 600; }
.stat .v {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2;
  margin-top: 8px; font-variant-numeric: tabular-nums;
}
.trend { margin-bottom: 20px; }
.trend-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 8px; flex-wrap: wrap; }
.trend-head .k { font-size: 13px; color: var(--text-3); font-weight: 600; }
.trend-head .big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.trend-stats { display: flex; gap: 6px; flex-wrap: wrap; }
.spark svg { width: 100%; height: 150px; display: block; overflow: visible; }
.spark path.line {
  fill: none; stroke: var(--accent); stroke-width: 2.4;
  stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: draw 1.2s var(--ease) 0.15s forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }
.spark-empty { font-size: 14px; color: var(--text-3); padding: 28px 0; }

.table-card { padding: 0; overflow: hidden; }
/* Tabel lebar di HP: bisa digeser, TAPI kasih bayangan tepi supaya jelas
   masih ada kolom di kanan. Tanpa ini user mengira tabel sudah habis. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; position: relative; }
.table-wrap.scrollable::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 32px;
  pointer-events: none;
  background: linear-gradient(to left, rgba(0,0,0,.14), transparent);
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3);
  padding: 14px 18px; background: var(--surface-2);
  border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
td { padding: 14px 18px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr { transition: background 0.15s; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr.sub-row:hover td { background: transparent; }
tbody tr.sub-row td { padding-top: 0; }
th.num, td.num { text-align: right; font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.table-card .empty { padding: 56px 24px; }

/* ---------- skeleton ---------- */
.skel {
  position: relative; overflow: hidden;
  background: var(--surface-3); border-radius: 12px;
}
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.skel-row { height: 60px; border-radius: 18px; margin-bottom: 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 32px; z-index: 50;
  max-width: min(560px, 90vw);
  padding: 12px 22px; border-radius: var(--r-pill);
  background: var(--inverse); color: var(--bg);
  font-size: 14px; font-weight: 500;
  box-shadow: 0 16px 36px -10px rgba(0, 0, 0, 0.35);
  opacity: 0; pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.25s var(--ease), transform 0.3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--bad); color: #ffffff; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .stat-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; left: 12px; right: 12px; bottom: 12px; top: auto;
    height: auto; flex-direction: row; padding: 8px; gap: 0; z-index: 30;
    background: var(--surface); border: 1px solid var(--line-soft);
    border-radius: 28px; box-shadow: var(--shadow-2);
  }
  .brand, .side-foot { display: none; }
  .nav { flex-direction: row; flex: 1; justify-content: space-around; }
  .nav a { flex-direction: column; justify-content: center; height: 56px; gap: 3px; padding: 0 8px; font-size: 11px; border-radius: 22px; flex: 1; }
  .nav a span { font-size: 11.5px; }
  .content { padding: 24px 16px 140px; }
  .split, .grid-2, .play { grid-template-columns: minmax(0, 1fr); }
  .form-panel { position: static; }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chat { height: auto; min-height: 520px; }
  .fab { right: 16px; bottom: 100px; }
  .page-head h1 { font-size: 26px; }
}


/* polish pass: contrast, wrapping, table headers, alignment */
.endpoint, code, .mono { white-space: nowrap; overflow-x: auto; overflow-wrap: normal; }
input::placeholder, textarea::placeholder { color: var(--text-3); opacity: 1; }
.field label, label { color: var(--text-2); }
th { color: var(--text-2); font-weight: 600; }
.count, .badge-count { color: var(--text-2); }
.card-sub, .subtitle, .page-sub, .muted { color: var(--text-2); text-wrap: balance; }
.btn.clear-log, .btn.muted-btn { padding-inline: 14px; }
.side-foot { display: none; }



/* ===== final playground / endpoint / table fixes ===== */
.split { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: stretch; }
.split > section, .split > .panel { display: flex; flex-direction: column; min-width: 0; }
.split > .chat { height: 100%; }
.endpoint-box { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.endpoint-box .mono { flex: 1 1 200px; min-width: 0; white-space: normal; overflow-wrap: anywhere; word-break: break-word; font-size: 13px; line-height: 1.5; }
table th, th { font-family: var(--font); font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--text-2); }
table th .mono { font-family: var(--font); }
.play { align-items: stretch !important; }
.play > * { min-height: 0; }
.play .card:first-child { display: flex; flex-direction: column; }
.endpoint-box .mono { flex: 1 1 auto; white-space: nowrap !important; overflow-wrap: normal !important; word-break: normal !important; font-size: 11.5px; overflow-x: auto; }

:root[data-theme="dark"] .tone-0 { background: #163d38; color: #9ef0e2; }
:root[data-theme="dark"] .tone-1 { background: #1b2a4a; color: #b5ccff; }
:root[data-theme="dark"] .tone-2 { background: #3a2d12; color: #f2d48f; }
:root[data-theme="dark"] .tone-3 { background: #232b37; color: #c3ccd9; }
:root[data-theme="dark"] .tone-4 { background: #3d1a25; color: #ffb3c1; }
:root[data-theme="dark"] .tone-5 { background: #163522; color: #9fe9b5; }

/* ---------- topbar: language + theme + account ---------- */
.topbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.topbar[hidden] { display: none; }
.tb-group { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--line); }
.seg { appearance: none; border: 0; background: transparent; color: var(--text-3); font: inherit; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; height: 28px; min-width: 32px; padding: 0 10px; border-radius: var(--r-pill); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: background .2s var(--ease), color .2s var(--ease); }
.seg.icon { padding: 0; width: 32px; }
.seg:hover { color: var(--text); }
.seg[aria-pressed="true"] { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-1); }
.spacer { flex: 1 1 auto; }
.account { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.account[hidden] { display: none; }
.btn.sm { height: 30px; padding: 0 12px; font-size: 12.5px; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text-2); }
.btn.ghost:hover { color: var(--text); border-color: var(--text-3); }
.btn.wide { width: 100%; justify-content: center; }

/* ---------- banner ---------- */
.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-radius: 14px; margin-bottom: 18px; font-size: 13.5px; line-height: 1.5; border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2); }
.banner[hidden] { display: none; }
.banner em { display: block; font-style: normal; color: var(--text-3); margin-top: 4px; }
.banner.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.banner.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.banner > span { min-width: 0; flex: 1 1 260px; overflow-wrap: anywhere; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 60vh; display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 420px; padding: 26px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-pill); margin-bottom: 22px; }
.auth-tab { appearance: none; border: 0; background: transparent; color: var(--text-3); font: inherit; font-weight: 600; font-size: 13.5px; height: 34px; border-radius: var(--r-pill); cursor: pointer; }
.auth-tab.on { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-1); }
.auth-title { font-size: 24px; margin: 0 0 6px; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.auth-card .sub { margin-bottom: 18px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .field label { display: block; font-size: 12.5px; color: var(--text-3); margin-bottom: 6px; }
.auth-card input { width: 100%; height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font: inherit; font-size: 16px; }
.auth-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.auth-card .hint { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.auth-card .btn.primary { height: 46px; }
.auth-msg { font-size: 13px; line-height: 1.5; padding: 10px 12px; border-radius: 12px; margin-bottom: 14px; overflow-wrap: anywhere; }
.auth-msg.err { background: var(--bad-soft); color: var(--bad); }
.auth-msg.warn { background: var(--warn-soft); color: var(--warn); }
.auth-msg[hidden] { display: none; }

/* ---------- responsive guards ---------- */
html, body { max-width: 100%; overflow-x: hidden; }
.app, .content, .page, .panel { min-width: 0; max-width: 100%; }
.content { overflow-wrap: anywhere; }
img, svg, video, canvas { max-width: 100%; }
pre, code { overflow-x: auto; max-width: 100%; }

@media (max-width: 640px) {
  .topbar { gap: 8px; }
    .auth-card { padding: 20px; }
  .auth-title { font-size: 21px; }
}
@media (max-width: 380px) {
    .seg { min-width: 28px; padding: 0 8px; }
  .tb-group { padding: 2px; }
}

/* ===== mobile pass (phones/Android, <=900px) ===== */
@media (max-width: 900px) {
  .content {
    padding: calc(16px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) calc(150px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .rail {
    left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom)); padding: 6px; border-radius: 24px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  }
  .nav a { height: 56px; min-width: 0; padding: 0 4px; }
  .nav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .fab { right: max(14px, env(safe-area-inset-right)); bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(96px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); text-align: center; }

  /* topbar: 44px targets, one row */
  .topbar { flex-wrap: nowrap; gap: 8px; margin-bottom: 14px; }
  .seg { height: 40px; min-width: 40px; }
  .seg.icon { width: 40px; }
  .btn.sm { height: 40px; padding: 0 14px; }
  .account { margin-left: auto; }
  .spacer { display: none; }

  /* grids and forms: single column, inputs get full width */
  .split, .grid-2, .play, .form-row, .row-2, .field-row { grid-template-columns: minmax(0, 1fr) !important; }
  .split > section, .split > .panel, .split > .chat { min-width: 0; height: auto !important; }
  .split { gap: 16px; }
  .field, .field > *, input, select, textarea { min-width: 0; max-width: 100%; }
  input[type="text"], input[type="url"], input[type="password"], input[type="number"], input:not([type]), select { height: 48px; font-size: 16px; }
  textarea { font-size: 16px; }
  .btn { min-height: 44px; }
  .row, .form-foot, .actions, .btn-row { flex-wrap: wrap; }
  .form-foot > .btn, .form-foot > .row > .btn, .actions > .btn { flex: 1 1 auto; }

  /* cards: tighter padding, long text wraps */
  .panel, .card { padding: 18px; }
  .card-head { flex-wrap: wrap; gap: 8px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-head h1 { font-size: 24px; }
  .item, .target { flex-wrap: wrap; min-width: 0; }
  .item > *, .target > * { min-width: 0; }
  .detail, .mono, .endpoint { overflow-wrap: anywhere; white-space: normal; word-break: break-word; }

  /* usage: stats 2-up, table scrolls inside its own card */
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .table-wrap, .table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 560px; }

  /* modal-style overlays stay inside the viewport */
  .modal, .dialog, .sheet { max-height: calc(100dvh - 24px); overflow-y: auto; }

  /* playground chat */
  .chat-head { flex-wrap: wrap; }
  .composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

@media (max-width: 380px) {
  .stat-row { grid-template-columns: minmax(0, 1fr); }
  .nav a span { font-size: 10.5px; }
  .seg { min-width: 36px; padding: 0 8px; }
}

.auth-links { margin-top: 16px; text-align: center; }
.link-btn { appearance: none; border: 0; background: none; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; padding: 4px; }
.link-btn:hover { text-decoration: underline; }
.auth-msg.ok { color: var(--ok, #2e7d32); }
