:root {
  --bg: #0e1013;
  --panel: #161a20;
  --panel-2: #1c2129;
  --line: #262c36;
  --text: #e4e7ec;
  --muted: #8b939f;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --accent: #58a6ff;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-size: 13px; }

code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 2px 6px;
  border-radius: 4px;
  color: #c9d1d9;
}

/* ---------- login ---------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px 24px;
}

.login-box h1 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.login-box p { margin: 0 0 18px; }

.login-box input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
}

.login-box input:focus { border-color: var(--accent); }

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

.btn:hover { background: #262c36; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.warn { color: var(--warn); border-color: #4a3a10; }
.btn.warn.active { background: #3a2c08; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
.btn.tiny { padding: 3px 9px; font-size: 12px; }

.login-box button[type=submit] {
  width: 100%;
  margin-top: 12px;
  background: var(--accent);
  border: none;
  color: #06121f;
  font-weight: 600;
  padding: 10px;
  border-radius: 6px;
  cursor: pointer;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(139,147,159,.12);
}
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(63,185,80,.15); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(210,153,34,.15); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px rgba(248,81,73,.15); }

.topbar-actions { display: flex; gap: 8px; }

/* ---------- stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.stat {
  background: var(--bg);
  padding: 14px 20px;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-value.ok { color: var(--ok); }
.stat-value.warn { color: var(--warn); }
.stat-value.bad { color: var(--bad); }

/* ---------- panel ---------- */

.panel {
  margin: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--muted);
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 9px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 11px 16px;
  border-bottom: 1px solid #1d222a;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #191e26; }

td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.tag.ok { color: var(--ok); border-color: #1f4a26; background: #10231a; }
.tag.warn { color: var(--warn); border-color: #4a3a10; background: #241d09; }
.tag.bad { color: var(--bad); border-color: #5c2020; background: #26110f; }
.tag.idle { color: var(--muted); border-color: var(--line); background: var(--panel-2); }

.mono { font-family: var(--mono); font-size: 12px; }
.ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bar {
  position: relative;
  width: 64px;
  height: 4px;
  background: #232932;
  border-radius: 2px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
}
.bar > i {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--ok);
  border-radius: 2px;
}
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- endpoints ---------- */

.endpoints {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1px;
  background: var(--line);
}

.ep { background: var(--panel); padding: 14px 16px; }
.ep-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.ep code { display: inline-block; word-break: break-all; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 10px 16px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  z-index: 50;
}
.toast.ok { border-color: #1f4a26; color: var(--ok); }
.toast.bad { border-color: #5c2020; color: var(--bad); }

@media (max-width: 720px) {
  .panel { margin: 12px; }
  .topbar { padding: 10px 12px; }
  .stat { padding: 10px 12px; }
  th, td { padding: 8px 10px; }
}

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .62);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}

.modal-box {
  width: 100%;
  max-width: 520px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 90vh;
  overflow: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--panel);
}

.modal-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

#add-form { padding: 16px 18px 18px; }

.field { margin-bottom: 14px; }

.field > label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input, .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 12px;
}

.field textarea { resize: vertical; margin-top: 8px; line-height: 1.45; }
.field input:focus, .field textarea:focus { border-color: var(--accent); outline: none; }
.field input[type=file] { padding: 6px 8px; cursor: pointer; }

.radios { display: flex; gap: 16px; margin-bottom: 8px; font-size: 12px; }
.radios label { display: flex; align-items: center; gap: 5px; color: var(--text); cursor: pointer; }

.hint { font-size: 11px; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }
.req { color: var(--bad); }

/* proxy input + connectivity test button on one line */
.proxy-row { display: flex; gap: 8px; align-items: center; }
.proxy-row input { flex: 1 1 auto; min-width: 0; }
.proxy-row .btn { flex: 0 0 auto; white-space: nowrap; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

/* radios must not wrap mid-label */
.radios { flex-wrap: wrap; row-gap: 8px; }
.radios label { white-space: nowrap; flex: 0 0 auto; }

/* ---------- oauth link box ---------- */

.link-box {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
}

.link-box a {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  word-break: break-all;
  text-decoration: none;
  margin-bottom: 9px;
  line-height: 1.5;
}

.link-box a:hover { text-decoration: underline; }
.link-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- live test panel ---------- */

.test-panel { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; }

.test-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.test-row select,
.test-panel input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 12px;
  outline: none;
  min-width: 180px;
}

.test-row select:focus,
.test-panel input:focus { border-color: var(--accent); }

.test-panel input { width: 100%; min-width: 0; }

.test-result {
  margin: 0;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow: auto;
  color: #c9d1d9;
}

.test-result.ok { border-color: #1f4a26; }
.test-result.bad { border-color: #5c2020; }

/* ---------- account cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 12px;
  padding: 14px 16px 16px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kind {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 2px 9px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.kind.pro    { color: #79c0ff; border-color: #1f3a5c; background: #0d1c2e; }
.kind.max    { color: #d2a8ff; border-color: #3d2a5c; background: #1b1226; }
.kind.max5   { color: #d2a8ff; border-color: #3d2a5c; background: #1b1226; }
.kind.max20  { color: #ffa657; border-color: #5c3a1a; background: #2a1a0c; }
.kind.unknown{ color: var(--muted); }

.card-id {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.card-email {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: 12px;
}
.card-meta dt { color: var(--muted); }
.card-meta dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-bars { display: flex; flex-direction: column; gap: 7px; }

.bar-row {
  display: grid;
  grid-template-columns: 24px 42px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}
.bar-row .bar { width: 100%; margin-left: 0; }

.card-foot {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  border-top: 1px solid var(--line);
  padding-top: 9px;
}

.card .row-actions { margin-top: auto; }

/* six actions per card: lay them out as a tidy 3x2 grid */
.card .row-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.card .row-actions .btn {
  padding: 5px 0;
  font-size: 11px;
  text-align: center;
}

/* ---------- per-card expand ---------- */

.card-expand {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 2px;
}

.model-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip .price { color: var(--muted); font-size: 10px; }

.test-mini { display: flex; gap: 6px; margin-bottom: 8px; }

.test-mini select,
.test-mini input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  padding: 5px 8px;
  font-family: var(--mono);
  font-size: 11px;
  outline: none;
}

.test-mini select { flex: 0 0 auto; max-width: 150px; }
.test-mini input { flex: 1 1 auto; min-width: 0; }

.card-expand .t-result { margin: 8px 0 0; max-height: 180px; }

.env-out {
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.75;
  white-space: pre-wrap;
  border-top: 1px solid var(--line);
  color: #c9d1d9;
}

.card .row-actions { grid-template-columns: repeat(4, 1fr); }

/* keep the send button on one line inside the mini test row */
.test-mini .t-send { flex: 0 0 auto; white-space: nowrap; padding-left: 12px; padding-right: 12px; }

/* show the exact model id under the selector so "which model did I pick" is unambiguous */
.t-model-id { margin: -2px 0 8px; font-family: var(--mono); font-size: 10px; }

/* clickable model chips */
.chip.clickable { cursor: pointer; transition: border-color .12s, background .12s; }
.chip.clickable:hover { border-color: var(--accent); background: #12233a; }
.chip.clickable:active { background: #0d1c2e; }

/* Native select popups render in-page in Chromium, so an ancestor with
   overflow:hidden clips them. The account panel must not clip. */
.panel.no-clip { overflow: visible; }
.panel.no-clip > .panel-head { border-radius: 8px 8px 0 0; }

/* ---------- custom model dropdown (native select gets clipped by ancestors) ---------- */

.msel { position: relative; flex: 0 0 auto; }

.msel-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  min-width: 130px;
}
.msel-btn:hover { border-color: var(--accent); }
.msel-btn i { color: var(--muted); font-style: normal; }

.msel-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 200;
  min-width: 100%;
  max-height: 260px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .55);
  display: flex;
  flex-direction: column;
  padding: 4px;
}

.msel-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text);
  padding: 6px 9px;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.msel-item small { color: var(--muted); font-family: var(--mono); font-size: 10px; }
.msel-item:hover { background: #232932; }
.msel-item.active { background: #12233a; }
.msel-item.active span { color: var(--accent); }

/* money on the card footer */
.card-foot .money { color: #7ee787; font-weight: 600; }

/* money columns in the card: 5H | pct | bar | $, same for 7D */
.bar-row { grid-template-columns: 24px 40px 1fr auto; }
.bar-row .money { color: #7ee787; font-weight: 600; text-align: right; min-width: 58px; }
.card-total { display: flex; justify-content: space-between; gap: 10px; }
.card-total .money { color: #7ee787; }

/* ---------- api key panel ---------- */

.key-gen { display: flex; gap: 8px; align-items: center; }

.key-gen select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  padding: 4px 8px;
  font-size: 11px;
  font-family: var(--mono);
  outline: none;
}

.keys-list { display: flex; flex-direction: column; }

.key-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid #1d222a;
  flex-wrap: wrap;
}
.key-row:last-child { border-bottom: none; }

.key-val {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  background: transparent;
  border: none;
  padding: 0;
}

.key-type { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ---------- request log ---------- */

.log-filter { display: flex; gap: 8px; align-items: center; }

.log-filter select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  padding: 4px 8px;
  font-size: 11px;
  font-family: var(--mono);
  outline: none;
}

.log-table { font-size: 12px; }
.log-table th, .log-table td { padding: 8px 14px; }
.log-table td .mono { font-size: 11px; }
.log-table .ellipsis { max-width: 260px; display: inline-block; vertical-align: middle; }

/* an old log line should read as background, not compete with the newest rows */
.log-table tbody tr:nth-child(n+21) { opacity: .6; }

