/* shop-web styles: dark theme, system fonts, no framework, no CDN. */

/* Palette and shared tokens in one place so the whole portal stays consistent.
   color-scheme:dark makes NATIVE controls (the provider <select>'s dropdown
   list, scrollbars) render dark instead of a jarring OS-light popup. */
:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --panel: #121722;
  --panel-2: #0d1119;
  --border: #1f2735;
  --border-2: #2a3446;
  --text: #e6eaf2;
  --muted: #8b94a7;
  --accent: #4f8cff;
  --accent-2: #3a6fd8;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  /* Secondary hues for the request-record icons/chips (2026-10-14): info
     blue and two purples the operator's reference uses; kept as vars so the
     whole palette stays swappable from :root alone. */
  --info: #58a6ff;
  --purple: #a371f7;
  --purple-soft: #d2a8ff;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 20px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

/* Layout: centered column, sticky-free nav, quiet footer. */
.container { max-width: 1280px; margin: 0 auto; padding: 26px 0 60px; }
.nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1280px; margin: 0 auto; padding: 18px 20px; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 17px; }
.nav-links a { color: var(--muted); text-decoration: none; margin-left: 18px; font-size: 14.5px; }
.nav-links a:hover { color: var(--text); }
.footer { max-width: 1280px; margin: 0 auto; padding: 20px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); }

h1 { font-size: 26px; margin: 8px 0 6px; }
h2 { font-size: 12.5px; margin: 0 0 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
h3 { font-size: 16px; margin: 0; }
p { margin: .4em 0; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .95em; }
.hidden { display: none; }
.note { font-size: 12.5px; margin: 10px 0 0; }
.linkline { margin: 18px 0; }
.big { font-size: 22px; font-weight: 700; }

/* Cards: the one surface everything sits on. */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin: 16px 0; }

/* Buttons and inputs. */
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px; font-size: 14.5px; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; border: 1px solid var(--border-2); color: var(--muted); font-weight: 500; padding: 7px 12px; font-size: 13px; border-radius: 8px; cursor: pointer; }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.key-form { display: flex; gap: 10px; flex-wrap: wrap; }
.key-form input { flex: 1; min-width: 220px; background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text); border-radius: 10px; padding: 11px 13px; font-family: var(--mono); font-size: 14px; }
.key-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.search { width: 100%; background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text); border-radius: 10px; padding: 11px 13px; font-size: 15px; margin: 14px 0; }
.search:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* /models toolbar: search box + API-type + provider dropdowns on one row
   (stacked on narrow phones). The selects reuse .search chrome; width:auto
   keeps them hugging their longest option instead of stretching. */
.models-toolbar { display: flex; gap: 10px; align-items: center; margin: 14px 0; }
.models-toolbar .search { margin: 0; flex: 1 1 auto; min-width: 0; }
.provider-select, .type-select { flex: 0 0 auto; width: auto; cursor: pointer; padding-right: 28px; }
@media (max-width: 620px) { .models-toolbar { flex-direction: column; align-items: stretch; } }

/* Key display: masked key row with reveal + copy. */
.keyrow { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; margin-top: 6px; }
.keybox { flex: 1; min-width: 200px; display: flex; align-items: center; font-family: var(--mono); font-size: 13.5px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; overflow-wrap: anywhere; }

/* Status badges. */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.badge.active { background: rgba(63,185,80,.14); color: var(--green); }
.badge.exhausted { background: rgba(248,81,73,.14); color: var(--red); }
.badge.disabled { background: rgba(139,148,167,.15); color: var(--muted); }

/* Per-request success mark in the Recent requests table: ✓ green / ✗ red,
   with the gateway's error text on hover (title attr, set in JS). */
.ok-mark { color: var(--green); font-weight: 700; cursor: default; }
.fail-mark { color: var(--red); font-weight: 700; cursor: help; }

/* Quota progress bar: green <70%, amber <90%, red >=90%/exhausted. */
.bar { height: 10px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); overflow: hidden; margin: 6px 0 12px; }
.bar > div { height: 100%; border-radius: 6px; }
.bar.ok > div { background: var(--green); }
.bar.warn > div { background: var(--amber); }
.bar.bad > div { background: var(--red); }

/* Stat grids and label/value rows. */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
.kv .k { color: var(--muted); font-size: 12.5px; }
.kv .v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-variant-numeric: tabular-nums; }
.row span:first-child { color: var(--muted); }
.row.total { font-weight: 700; }
.rows { margin-top: 6px; }
.rows .row { border-bottom: 1px solid var(--border); }
.rows .row:last-child { border-bottom: 0; }

/* Tables survive only inside the Check Cost dialog; the request history
   itself moved to record cards (.req-*) on 2026-10-14. */
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
th { color: var(--muted); text-align: left; font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border-2); white-space: nowrap; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Inline alert (never window.alert). */
.alert { border-radius: 10px; padding: 12px 14px; margin: 16px 0; border: 1px solid rgba(248,81,73,.4); background: rgba(248,81,73,.08); color: #ffb4ae; }

/* Landing tiles. */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 22px 0; }
.tile { display: block; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-decoration: none; color: var(--text); }
.tile:hover { border-color: var(--accent); }
.tile .t { font-weight: 700; margin-bottom: 4px; }
.tile .d { color: var(--muted); font-size: 14px; }

/* Code blocks with a copy button (docs + landing). */
.codeblock { position: relative; margin: 12px 0; }
.codeblock pre { margin: 0; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px 76px 14px 14px; overflow-x: auto; }
.codeblock code { font-family: var(--mono); font-size: 12.8px; color: #c9d4e8; white-space: pre; }
.codeblock .copy { position: absolute; top: 8px; right: 8px; }

/* Toast (copy feedback). */
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px); background: #1c2433; border: 1px solid var(--border-2); color: var(--text); padding: 9px 16px; border-radius: 10px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Model catalog (/models) and the collapsible list on /customer. */
.models-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin: 18px 0; }
.model-card .desc { color: var(--muted); font-size: 13.5px; margin: 8px 0; }
.pill { display: inline-block; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); border-radius: 999px; padding: 1px 9px; font-size: 11.5px; margin: 8px 6px 0 0; }
.prices { margin-top: 10px; font-size: 13.5px; }
.models-details { padding-top: 14px; padding-bottom: 14px; }
.models-details summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.model-line { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; padding: 9px 0; border-bottom: 1px solid var(--border); }
.model-line:last-child { border-bottom: 0; }
.model-line .nm { font-weight: 600; }
.model-line .id { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.model-line .ds { color: var(--muted); font-size: 13px; flex: 1; min-width: 160px; }

/* Header rows inside cards (name + badge, name + copy). */
.header-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Phones: tighten paddings, keep the table scrollable. */
@media (max-width: 600px) {
  body { padding: 0 12px; }
  .nav { padding: 14px 12px; }
  .container { padding-top: 16px; }
  .card { padding: 16px; }
  h1 { font-size: 22px; }
  .nav-links a { margin-left: 12px; }
}

/* Authenticated customer view: the entry chrome (heading, intro, key-input
   card) steps aside once stats render — the visitor came for the numbers. */
main.authed > h1,
main.authed > p,
main.authed > section {
  display: none;
}

/* The authenticated stat row: quota · requests & tokens · costs · models
   link side by side, wrapping to one column on narrow screens. */
.cards-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  align-items: stretch;
}
@media (max-width: 900px) {
  .cards-row { grid-template-columns: 1fr; }
}
.cards-row .card { margin-bottom: 0; }
.card-link { display: flex; align-items: center; justify-content: center; }

/* Header left group: logout button sits leftmost of the brand, shown only
   while a key is remembered in this browser. */
.nav-left { display: flex; align-items: center; gap: 10px; }
#logout-btn { white-space: nowrap; }

/* Long unbroken names (a key named with a 200-char string, a model id)
   must WRAP inside their cell instead of pushing the card or table wider
   than the viewport — overflow-wrap:anywhere breaks anywhere, unlike
   break-word which still refuses mid-"word" runs without spaces. */
.header-row h3 { min-width: 0; overflow-wrap: anywhere; }
.header-row .badge { flex-shrink: 0; }
.model-line .nm, .model-line .id, .model-line .ds { overflow-wrap: anywhere; }

/* Docs playground: key + model + prompt + result. Same visual family as the
   customer key form, one column, roomy textarea. */
#try-form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
#try-form input, #try-form select, #try-form textarea {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
}
#try-form textarea { resize: vertical; min-height: 44px; }
.try-out { margin-top: 12px; }
.try-out .reply { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.try-out .meta { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* Model availability strip: 24 hourly bars + uptime line. */
.avail { margin-top: 10px; }
.up-strip { display: flex; gap: 2px; height: 14px; align-items: stretch; }
.up-bar { flex: 1; border-radius: 2px; min-width: 2px; }
.up-ok { background: #2f9e6e; }
.up-warn { background: #c9a227; }
.up-bad { background: #d64545; }
.avail-line { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

/* /models — mock-style cards (structure only; colors inherit the shop's
   dark theme — the light graph-paper background was rejected 2026-10-10).
   The .rec-badge chip (absolute, overlapping the card top) was removed the
   same day; cards no longer need any positioned child. */
/* Cards are flex columns so the Uptime (SLA 24h) strip always sits at the
   BOTTOM of the card, aligned across every card in the same grid row —
   with tier toggles making some cards taller than others, an unanchored
   strip would drift up and down row by row (operator request 2026-10-11). */
.model-card { display: flex; flex-direction: column; }
.model-card .price-grid { flex: 0 0 auto; }
.model-card .avail { margin-top: auto; padding-top: 12px; }

/* Header: vendor circle + titles + copy. */
.m-head { display: flex; align-items: center; gap: 12px; }
.m-logo {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 50%; background: #FFFFFF; border: 1px solid var(--border-2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px; color: var(--accent);
}
.m-titles { min-width: 0; flex: 1; }
.m-titles h3 { font-size: 16.5px; }
.m-id { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.m-copy { flex-shrink: 0; }

/* Tier toggle row. */
.tier-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0 10px; }
.tier-lab { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--border-2); border-radius: 8px; overflow: hidden; }
.seg-btn {
  font: inherit; font-size: 12.5px; padding: 5px 12px; cursor: pointer;
  background: transparent; border: 0; color: var(--muted);
}
.seg-btn.sel { background: var(--accent); color: #fff; font-weight: 600; }

/* 2x2 pricing grid: bordered quadrants, bold credits, small-caps labels. */
.price-grid { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.price-grid.single { grid-template-columns: 1fr; }
.price-cell { padding: 12px 14px; background: var(--panel); }
.price-grid .price-cell:nth-child(2n) { border-left: 1px solid var(--border); }
.price-grid .price-cell:nth-child(n+3) { border-top: 1px solid var(--border); }
.price-grid.single .price-cell { border-left: 0 !important; border-top: 0 !important; }
.price-val { font-size: 16px; font-weight: 700; }
.price-lab { font-size: 10.5px; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; margin-top: 3px; }
.desc { margin-top: 12px; }

/* Uptime block. */
.avail { margin-top: 14px; }
.avail-head { display: flex; justify-content: space-between; align-items: baseline; }
.avail-lab { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.avail-lat { font-size: 12.5px; color: var(--text); font-variant-numeric: tabular-nums; }
.up-strip { gap: 3px; height: 20px; }
.up-bar { border-radius: 4px; min-width: 3px; }
.up-bar:hover { filter: brightness(1.25); }

/* Docs playground: searchable model picker (input + filtered dropdown). */
.model-picker { position: relative; }
.model-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  max-height: 240px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border-2); border-radius: 8px;
  box-shadow: 0 10px 24px rgba(0,0,0,.35);
}
.model-item { padding: 8px 12px; cursor: pointer; font-size: 13.5px; overflow-wrap: anywhere; }
.model-item:hover { background: var(--panel-2); }

/* Check Cost (/customer, 2026-10-13): one shared native <dialog> re-filled
   per row click; the per-record trigger itself is the .check-btn accent
   pill in the record-cards section below. */

/* The dialog itself. color-scheme:dark styles native dialog chrome dark,
   but the box still needs the shop's panel/border/radius. padding:0 on the
   <dialog> element is load-bearing: the .dlg-body child then covers the
   whole box, so the only click whose target IS the dialog is a BACKDROP
   click — exactly what the JS dismiss listener keys on. ::backdrop dims
   the page; Escape is native to showModal(). */
.cost-dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border-2); border-radius: var(--radius);
  padding: 0; width: min(640px, calc(100vw - 40px));
}
.cost-dialog::backdrop { background: rgba(4, 6, 10, .72); }
.cost-dialog .dlg-body { padding: 20px; }

/* Dialog innards: section titles reuse h2's small-caps card style with a
   touch more headroom; numeric table columns right-align. The global
   table{min-width:640px} rule is dropped here — the dialog is already
   width-capped and its 4 columns must not force it wider. */
.cost-dialog h2 { margin: 18px 0 10px; }
.cost-dialog table { min-width: 0; }
.cost-dialog th.num, .cost-dialog td.num { text-align: right; }
.dlg-sub { color: var(--muted); font-size: 13px; margin: 2px 0 4px; }
.dlg-sub .mono { font-size: 12px; overflow-wrap: anywhere; }
.cost-note { font-size: 12.5px; margin: 8px 0 0; }
.dlg-close { margin-top: 16px; }

/* Validation verdict: green/red reuse the row marks' palette; amber is the
   deliberate third state (prices unavailable / per-request / no detail). */
.cost-status { font-weight: 700; margin: 14px 0 0; }
.cost-status.ok { color: var(--green); }
.cost-status.bad { color: var(--red); }
.cost-status.na { color: var(--amber); }
.cost-delta { color: var(--muted); font-size: 12.5px; margin: 2px 0 0; }

/* Request record cards (/customer, 2026-10-14): the Recent-requests table
   became llmgate.app-style per-request records on the shop's own tokens —
   provider logo + model + badge chips + Check Cost on the head line, six
   icon stats below. Absent data renders NO chip, which retired the old
   hide-reasoning-column trick along with the table itself. */
.req-list { display: flex; flex-direction: column; gap: 10px; }
.req-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
}
.req-logo {
  width: 40px; height: 40px;
  border-radius: 9999px;
  border: 1px solid var(--border-2);
  background: #e9edf4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
/* models.dev marks are drawn DARK for light pages — so give the disc a
   LIGHT background and leave the logo untouched (operator call 2026-10-14:
   light disc + black mark, not a white silhouette). */
.req-logo img { width: 40px; height: 40px; object-fit: contain; padding: 6px; }
/* Fallback letter must be INK-dark to sit on the light disc. */
.req-logo-fallback { font-weight: 700; color: #2a3446; }
.req-main { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.req-head { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
/* min-width:0 lets the model name actually truncate inside the flex head;
   without it a nowrap flex item refuses to shrink below its full text. */
.req-name {
  min-width: 0;
  font-weight: 600;
  font-family: var(--mono);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Check Cost stays pinned right of the chips, never squeezed by them. */
.req-head .row-check { margin-left: auto; flex-shrink: 0; }
/* The per-card Check Cost trigger: an accent PILL in the chips' own visual
   language (tint + border, rounded full) rather than the plain ghost
   button — it is the one ACTION on the card, so it gets the one loud
   treatment: icon + label in accent blue, hover brightens with a soft
   halo ring, press sinks it. currentColor keeps the dollar icon in step
   with the text color through both states. */
.check-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 13px;
  border-radius: 999px;
  border: 1px solid rgba(79,140,255,.42);
  background: rgba(79,140,255,.12);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease,
              box-shadow .15s ease, color .15s ease, transform .05s ease;
}
.check-btn svg { width: 13px; height: 14px; }
.check-btn:hover {
  background: rgba(79,140,255,.24);
  border-color: rgba(79,140,255,.7);
  color: #8db4ff;
  box-shadow: 0 0 0 3px rgba(79,140,255,.16);
}
.check-btn:active { transform: scale(.96); }
.req-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border: 1px solid;
  white-space: nowrap;
  flex-shrink: 0;
}
.rb-reason { color: var(--amber); border-color: rgba(210,153,34,.45); background: rgba(210,153,34,.12); }
.rb-client { color: var(--accent); border-color: rgba(79,140,255,.45); background: rgba(79,140,255,.15); }
.rb-kind { color: var(--purple-soft); border-color: rgba(210,168,255,.35); background: rgba(210,168,255,.12); }
.rb-ok { color: var(--green); border-color: rgba(63,185,80,.45); background: rgba(63,185,80,.12); }
.rb-fail { color: var(--red); border-color: rgba(248,81,73,.45); background: rgba(248,81,73,.12); }
/* Mobile-first: stats pair up on phones and run one 6-across line from
   760px up — deliberately its own breakpoint: the six cells fit one line
   at 760px without cramping, independent of the wider card grids. */
.req-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 20px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
@media (min-width: 760px) { .req-stats { grid-template-columns: repeat(6, 1fr); } }
.req-stat { display: flex; align-items: center; gap: 6px; min-width: 0; }
.req-stat svg { flex-shrink: 0; }
.req-stat-label { color: var(--muted); }
.req-stat-value { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
/* The no-cache em-dash must stay muted even under .req-stat-value's text
   color — the compound selector outranks both plain helpers. */
.req-stat-value.muted { color: var(--muted); }
/* Cost is the LAST stat cell, so it right-flushes: its figure then sits
   exactly under the Check Cost pill's right edge on the head line above
   (operator alignment request 2026-10-14) — and cost figures down the
   whole list line up into a clean right-aligned column for scanning. */
.req-stats .req-stat:last-child { justify-content: flex-end; }
