/* Base + shared components. Single-class selectors keep specificity flat. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--t-base);
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01" on;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: var(--t-2xl); letter-spacing: -0.025em; }
h2 { font-size: var(--t-xl); letter-spacing: -0.02em; }
h3 { font-size: var(--t-md); }
p { margin: 0; }
a { color: inherit; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
code, kbd, pre, .mono { font-family: var(--font-mono); font-size: 0.92em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.soft { color: var(--ink-2); }
.small { font-size: var(--t-sm); }
.xs { font-size: var(--t-xs); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-xs); }

/* ---------- icons ---------- */
.ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.ico-sm { width: 15px; height: 15px; }
.ico-lg { width: 22px; height: 22px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px;
  border: 1px solid var(--line-2); border-radius: var(--r);
  background: var(--surface); color: var(--ink);
  font-weight: 500; font-size: var(--t-base); line-height: 1;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--btn); border-color: var(--btn); color: var(--btn-ink); }
.btn-primary:hover { background: var(--btn-hover); border-color: var(--btn-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-sm { height: 32px; padding: 0 12px; font-size: var(--t-sm); border-radius: var(--r-sm); gap: 6px; }
.btn-lg { height: 46px; padding: 0 22px; font-size: var(--t-md); border-radius: var(--r-lg); }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn-block { width: 100%; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; align-content: start; }
.field + .field { margin-top: 16px; }
.field > * { min-width: 0; }
.label { font-size: var(--t-sm); font-weight: 500; color: var(--ink-2); }
.hint { font-size: var(--t-xs); color: var(--ink-3); }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237c8296' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent); }
.input-sm, .select.input-sm { height: 32px; font-size: var(--t-sm); border-radius: var(--r-sm); }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .btn { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.input-affix { position: relative; }
.input-affix .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.input-affix .input { padding-left: 36px; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--t-sm); }
.check input { width: 16px; height: 16px; accent-color: var(--btn); margin: 0; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: var(--t-sm); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 34px; height: 20px; border-radius: var(--r-pill); background: var(--line-2); position: relative; transition: background-color .15s; flex: none; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--btn); }
.switch input:checked + .switch-track::after { transform: translateX(14px); background: var(--btn-ink); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }

input[type="range"] { width: 100%; accent-color: var(--btn); }

/* ---------- segmented control / module tabs ---------- */
.seg {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface-2); border-radius: var(--r);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg-item {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 14px; border: 0; border-radius: 7px;
  background: transparent; color: var(--ink-2); font-weight: 500; font-size: var(--t-sm);
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.seg-item:hover { color: var(--ink); }
.seg-item[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-soft), 0 0 0 1px var(--line); }
.seg-count { font-size: var(--t-xs); color: var(--ink-3); font-variant-numeric: tabular-nums; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--ink-3); }
.dot-chat { background: var(--chat); }
.dot-image { background: var(--image); }
.dot-video { background: var(--video); }
.dot-audio { background: var(--audio); }

/* underline tabs (secondary navigation inside a page) */
.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab { padding: 10px 0; border: 0; background: none; color: var(--ink-3); font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }

/* ---------- badges & chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: var(--r-pill);
  font-size: var(--t-xs); font-weight: 500; line-height: 1;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-chat { background: var(--chat-soft); color: var(--chat); }
.badge-image { background: var(--image-soft); color: var(--image); }
.badge-video { background: var(--video-soft); color: var(--video); }
.badge-audio { background: var(--audio-soft); color: var(--audio); }
.badge-outline { background: transparent; box-shadow: inset 0 0 0 1px var(--line-2); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px; border-radius: var(--r-pill);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
  font-size: var(--t-sm); cursor: pointer; white-space: nowrap;
}
.chip:hover { color: var(--ink); border-color: var(--ink-3); }
.chip[aria-pressed="true"] { background: var(--btn); border-color: var(--btn); color: var(--btn-ink); }

/* ---------- provider monogram ---------- */
.mono-logo {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: var(--r);
  background: var(--surface-2); color: var(--ink);
  font-weight: 700; font-size: 13px; letter-spacing: -0.02em;
  box-shadow: inset 0 0 0 1px var(--line);
}
.mono-logo-sm { width: 24px; height: 24px; font-size: 10px; border-radius: var(--r-sm); }
.mono-logo-lg { width: 48px; height: 48px; font-size: 16px; border-radius: var(--r-lg); }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.panel-pad { padding: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-head h3 { font-size: var(--t-md); }
.panel-body { padding: 20px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.table th {
  text-align: left; font-weight: 500; color: var(--ink-3);
  padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
  background: var(--surface);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }
.table tbody tr.is-click { cursor: pointer; }
.table tbody tr.is-click:hover td { background: var(--surface-2); }

/* ---------- code ---------- */
.code {
  position: relative; margin: 0;
  background: #161826; color: #e3e6f2;
  border-radius: var(--r-lg); padding: 16px 18px;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7;
  overflow-x: auto; white-space: pre;
}
:root[data-theme="dark"] .code { background: #0b0d14; box-shadow: inset 0 0 0 1px var(--line); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .code { background: #0b0d14; box-shadow: inset 0 0 0 1px var(--line); } }
.code .k { color: #a5a8ff; }
.code .s { color: #8fdcc9; }
.code .c { color: #7b8099; }
.code .n { color: #f6b26b; }
.code-copy { position: absolute; top: 10px; right: 10px; }
.code-copy .btn { background: rgba(255,255,255,.08); border-color: transparent; color: #e3e6f2; }
.code-copy .btn:hover { background: rgba(255,255,255,.16); }

.copy-field {
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 6px 0 14px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r);
  font-family: var(--font-mono); font-size: 13px;
}
.copy-field span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.stat { background: var(--surface); padding: 16px 20px; display: grid; gap: 4px; align-content: start; }
.stat-label { font-size: var(--t-sm); color: var(--ink-3); }
.stat-value { font-size: var(--t-xl); font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: var(--t-xs); color: var(--ink-3); }
.stat-hero { position: relative; overflow: hidden; padding-bottom: 44px; }
.stat-hero .stat-value { font-size: var(--t-2xl); letter-spacing: -0.03em; }
.spark { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 40px; }
.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--ink); }
.delta.down { color: var(--ok); }
.stat-warn .stat-value { color: var(--bad); }
@container page (max-width: 700px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- progress ---------- */
.progress { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--ink); transition: width .4s; }

/* ---------- empty state ---------- */
.empty { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 48px 20px; color: var(--ink-2); }
.empty .ico { width: 28px; height: 28px; color: var(--ink-3); }

/* ---------- overlay: modal + drawer ---------- */
.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(16, 18, 30, .42); display: flex; opacity: 0; transition: opacity .18s; }
.overlay.is-open { opacity: 1; }
.modal {
  margin: auto; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto;
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-pop);
  transform: translateY(8px); transition: transform .18s;
}
.overlay.is-open .modal { transform: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 24px 0; }
.modal-head h2 { font-size: var(--t-lg); }
.modal-body { padding: 16px 24px 24px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 24px; border-top: 1px solid var(--line); }
.drawer {
  margin-left: auto; width: min(560px, 100vw); height: 100%; overflow: auto;
  background: var(--surface); box-shadow: var(--shadow-pop);
  transform: translateX(24px); transition: transform .2s;
}
.overlay.is-open .drawer { transform: none; }
.drawer-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.drawer-body { padding: 24px; display: grid; gap: 24px; }

/* ---------- toast ---------- */
.toasts { position: fixed; z-index: 90; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--r-pill);
  background: var(--btn); color: var(--btn-ink); font-size: var(--t-sm); font-weight: 500;
  box-shadow: var(--shadow-pop); animation: toast-in .2s ease-out;
}
.toast-bad { background: var(--bad); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- dropdown menu ---------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; z-index: 60; top: calc(100% + 6px); right: 0; min-width: 200px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop); padding: 6px; display: none;
}
.menu.is-open { display: block; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: var(--r-sm); background: none;
  font-size: var(--t-sm); text-align: left; cursor: pointer; color: var(--ink); text-decoration: none;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item[aria-checked="true"]::after { content: ""; margin-left: auto; width: 6px; height: 6px; border-radius: 50%; background: var(--ink); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu-label { padding: 6px 10px 4px; font-size: var(--t-xs); color: var(--ink-3); }

/* ---------- logo ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.brand svg { width: 28px; height: 28px; }

/* ---------- banner ---------- */
.banner { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 8px 16px; font-size: var(--t-sm); background: var(--ink); color: var(--paper); }
.banner a { color: inherit; }
.banner .btn-ghost { color: inherit; height: 24px; width: 24px; padding: 0; }
.banner .btn-ghost:hover { background: rgba(255,255,255,.12); color: inherit; }

/* ---------- turnstile placeholder ---------- */
.turnstile { display: flex; align-items: center; gap: 10px; height: 64px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--surface-2); font-size: var(--t-sm); color: var(--ink-2); }
.turnstile-box { width: 22px; height: 22px; border-radius: 4px; border: 2px solid var(--ok); display: grid; place-items: center; color: var(--ok); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* Scrollbars follow the theme: thin, line-coloured thumb, no track. Chrome 121+ and Firefox use the
   standard properties; older WebKit falls back to the pseudo-elements below. */
html, body, .sidebar, .page, .drawer-body, .modal-body, .table-wrap, .menu, .textarea, .raw, pre, code {
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}
.sidebar:hover, .drawer-body:hover, .modal-body:hover, .table-wrap:hover, .menu:hover, .textarea:hover, .raw:hover { scrollbar-color: var(--ink-3) transparent; }
@supports not (scrollbar-color: auto) {
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--line-2); border: 3px solid transparent; border-radius: 10px; background-clip: content-box; }
  ::-webkit-scrollbar-thumb:hover { background-color: var(--ink-3); }
}
