/* ==========================================================================
   API Gate traffic panel
   Palette: validated categorical slots 1-2 (blue / orange) in both modes,
   status ramp for the quota meter, recessive chrome for grid & axes.
   ========================================================================== */

:root {
  color-scheme: light;
  --surface-1: #ffffff;
  --surface-2: #f1f3f6;
  --page: #f6f7f9;
  --text-primary: #1c2026;
  --text-secondary: #4b5260;
  --text-muted: #767f8c;
  --grid: #e8ebf0;
  --axis: #c4cad4;
  --border: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.16);
  --brand: #354d68;
  --brand-hover: #293c52;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-1-soft: #cde2fb;
  /* categorical slots for the composition donut, in fixed order */
  --slot-1: #2a78d6;
  --slot-2: #eb6834;
  --slot-3: #1baf7a;
  --slot-4: #eda100;
  --slot-5: #e87ba4;
  --slot-6: #008300;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 18px -12px rgba(15, 23, 42, .12);
  --radius: 12px;
  --radius-sm: 8px;
  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1b1f25;
    --surface-2: #232830;
    --page: #14171b;
    --text-primary: #e7eaef;
    --text-secondary: #b8bfca;
    --text-muted: #8b94a1;
    --grid: #2a3039;
    --axis: #3a414d;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.17);
    --brand: #4c6c91;
    --brand-hover: #5a7da6;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-1-soft: #184f95;
  --slot-1: #3987e5;
  --slot-2: #d95926;
  --slot-3: #199e70;
  --slot-4: #c98500;
  --slot-5: #d55181;
  --slot-6: #008300;
    --good: #0ca30c;
    --good-text: #3ebd85;
    --warning: #fab219;
    --critical: #ef6e6e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .32), 0 8px 22px -14px rgba(0, 0, 0, .65);
  }

}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1b1f25;
  --surface-2: #232830;
  --page: #14171b;
  --text-primary: #e7eaef;
  --text-secondary: #b8bfca;
  --text-muted: #8b94a1;
  --grid: #2a3039;
  --axis: #3a414d;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.17);
  --brand: #4c6c91;
  --brand-hover: #5a7da6;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-1-soft: #184f95;
  --slot-1: #3987e5;
  --slot-2: #d95926;
  --slot-3: #199e70;
  --slot-4: #c98500;
  --slot-5: #d55181;
  --slot-6: #008300;
  --good: #0ca30c;
  --good-text: #3ebd85;
  --warning: #fab219;
  --critical: #ef6e6e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .32), 0 8px 22px -14px rgba(0, 0, 0, .65);
}

* { box-sizing: border-box; }

/* the body grows with the page: held to one screen, it would be the box the sticky MedAI
   bar is confined to, and the bar would scroll away a screen down, leaving the tab row
   under it hanging */
html { height: 100%; touch-action: manipulation; }
body { min-height: 100%; touch-action: manipulation; }
a, button, input, select, textarea, label, summary, [role="button"], [role="menuitem"], [role="menuitemradio"],
a *, button *, [role="button"] *, [role="menuitem"] *, [role="menuitemradio"] * { touch-action: manipulation; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
a { color: var(--series-1); }
[hidden] { display: none !important; }

/* ── buttons & controls ─────────────────────────────────────────── */
.btn {
  font: inherit;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-primary); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; padding: 10px; }

input, select, textarea {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}
select { cursor: pointer; }

.theme-toggle {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-1);
  cursor: pointer;
  position: relative;
  flex: none;
}
.theme-toggle::before {
  content: "";
  position: absolute; inset: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  box-shadow: inset -4px -3px 0 0 var(--surface-1);
}
.theme-toggle:hover::before { background: var(--text-primary); }
.theme-toggle-float { position: fixed; top: 18px; right: 18px; }

/* ── login ──────────────────────────────────────────────────────── */
.login {
  min-height: calc(100vh - 61px);     /* the bar above is 60px + its 1px rule */
  min-height: calc(100dvh - 61px);
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--page);
}
.login-card {
  width: min(400px, 100%);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 15px;
  box-shadow: var(--shadow);
  padding: 32px 28px 26px;
  text-align: left;
}
.login-mark { margin-bottom: 16px; line-height: 0; }
.login-card h1 { font-size: 22px; }
.login-err {      /* also the rename dialog's error line */
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--critical);
  display: flex; gap: 6px; align-items: flex-start;
}
.login-err::before { content: "!"; font-weight: 700; }

.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }
.field input, .field select { width: 100%; }

.suffix { color: var(--text-secondary); font-size: 13px; white-space: nowrap; }

.switch { display: flex; align-items: center; gap: 9px; margin: 12px 0; font-size: 13.5px; cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--series-1); cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); cursor: pointer; }
.check input { accent-color: var(--series-1); }

/* ── shell ──────────────────────────────────────────────────────── */
/* The MedAI bar on top is the one every MedAI page shares (medai-nav.css, mounted by
   panel-nav.js); here it only gets the panel's palette and full width. Under it, one
   row: the panel's own pages on the left, account / refresh on the right. */
.panel-nav {
  --bg: var(--surface-1); --surface: var(--surface-1); --fg: var(--text-primary); --fg-2: var(--text-secondary);
  --muted: var(--text-muted); --line: var(--border);
  --brand: #374f6a; --brand-soft: rgba(55, 79, 106, .08);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; line-height: 1.6;
}
:root[data-theme="dark"] .panel-nav { --brand: #5b7ca3; --brand-soft: rgba(120, 155, 195, .12); }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .panel-nav { --brand: #5b7ca3; --brand-soft: rgba(120, 155, 195, .12); }
}
.panel-nav .mn-in { max-width: none; padding: 0 24px; }
.theme-toggle-float { display: none; }          /* the bar has the theme button */
.tabs { display: flex; gap: 2px; margin-left: 6px; }
.tab {
  font: inherit; font-size: 13.5px;
  background: none; border: 0;
  color: var(--text-secondary);
  padding: 6px 12px; border-radius: var(--radius-sm);
  cursor: pointer;
}
.tab:hover { background: var(--surface-2); color: var(--text-primary); }
.tab.is-active { color: var(--text-primary); background: var(--surface-2); font-weight: 600; }
.topbar-actions[hidden] { display: none !important; }   /* app.js state only, see index.html */
.whoami { font-size: 12.5px; color: var(--text-secondary); }
.whoami b { color: var(--text-primary); font-weight: 600; }
.badge {
  display: inline-block; margin-left: 6px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .02em;
  padding: 1px 6px; border-radius: 999px;
  color: var(--series-1);
  background: color-mix(in srgb, var(--series-1) 14%, transparent);
}

.filterbar {
  position: sticky; top: 60px; z-index: 19;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--page);
  border-bottom: 1px solid var(--border);
}
.filter-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.filterbar .tabs { margin-left: -6px; min-width: 0; }

.user-picker { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-secondary); }

/* ── account combobox ───────────────────────────────────────────────
   A <select> cannot be searched, and by name — display name, login or email — is how
   people actually look for each other. */
.combo { position: relative; display: flex; align-items: center; }
/* a person in front and a chevron behind: it reads as a picker, not a bare text box */
.combo::before, .combo::after {
  content: ""; position: absolute; top: 50%; width: 15px; height: 15px; transform: translateY(-50%);
  background: var(--text-muted); pointer-events: none;
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
}
.combo::before { left: 10px; --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 21a8 8 0 0 1 16 0'/%3E%3C/svg%3E"); }
.combo::after { right: 9px; --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
.combo input {
  width: 260px; max-width: 42vw; height: 32px; padding: 0 30px 0 32px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1);
  font-size: 13px; text-overflow: ellipsis; transition: border-color .12s ease, box-shadow .12s ease;
}
.combo input:hover { border-color: var(--border-strong); }
.combo input:focus-visible {
  outline: none; border-color: var(--series-1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--series-1) 18%, transparent);
}
.combo-list {
  position: absolute; z-index: 60; top: calc(100% + 4px); right: 0;
  width: min(360px, 86vw); max-height: 320px; overflow-y: auto;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 4px;
  scrollbar-width: thin;
}
.combo-opt {
  display: grid; grid-template-columns: 1fr auto; gap: 0 8px;
  padding: 6px 8px; border-radius: 6px; cursor: pointer; line-height: 1.35;
}
.combo-opt:hover, .combo-opt.is-active { background: var(--surface-2); }
.combo-opt.is-current { box-shadow: inset 2px 0 0 var(--series-1); }
/* 全部用户 is a scope, not an account — set it apart from the names below it */
.combo-opt.combo-all .combo-name { color: var(--series-1); }
.combo-name {
  /* every cell is placed explicitly: an item with a definite grid-row (the id below)
     is placed in an earlier pass, and auto-placement then put it in column 1 — which
     read as "#24 … Max" instead of "Max … #24" */
  grid-column: 1; grid-row: 1;
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.combo-sub {
  grid-column: 1; grid-row: 2; font-size: 11.5px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.combo-id {
  grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 11px;
  color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.combo-empty { padding: 10px 8px; font-size: 12px; color: var(--text-muted); text-align: center; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 24px 72px; }
.view { display: flex; flex-direction: column; gap: 18px; }

/* ── cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px 22px;
  box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  
  .panel-nav .mn-in { padding: 0 14px; }
  .filterbar { padding: 10px 14px; }
  .wrap { padding: 16px 14px 60px; }

}

/* Phone: five tabs plus the brand do not fit at desktop sizing, and the browser's answer
   — wrapping every label onto two lines — turns the bar into three rows of fragments.
   Tighten the type and let the strip scroll sideways instead. */
@media (max-width: 720px) {
  .filterbar { top: 54px; }
  .login { min-height: calc(100% - 54px); }
}
@media (max-width: 560px) {
  .filterbar .tabs {
    flex: 1 1 100%; min-width: 0; margin: 0 -2px; padding-right: 18px;
    overflow-x: auto; scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 20px), transparent 100%);
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 20px), transparent 100%);
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 6px 10px; font-size: 13px; white-space: nowrap; }
  .filterbar { padding: 8px 12px; gap: 8px; }
  .filter-right { width: 100%; margin-left: 0; gap: 8px; justify-content: flex-end; }
  .user-picker { flex: 1 1 auto; min-width: 0; }
  .combo { flex: 1 1 auto; min-width: 0; }
  .combo input { width: 100%; max-width: none; height: 38px; border-radius: 10px; }
  .combo-list { left: 0; right: auto; width: min(340px, calc(100vw - 24px)); }
  /* hide the 查看账户 label only — descendant spans are the combo options' text
     (.combo-name/.combo-sub/.combo-id), which must keep rendering on phones */
  .user-picker > span { display: none; }
}

/* ── charts ─────────────────────────────────────────────────────── */
.chart { width: 100%; height: 250px; }

.chart svg { display: block; width: 100%; overflow: visible; }

.hit { fill: transparent; cursor: crosshair; }

.empty {
  display: grid; place-items: center; height: 100%; min-height: 120px;
  color: var(--text-muted); font-size: 13px; text-align: center;
}

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--text-muted);
  padding: 0 12px 8px 0; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td {
  padding: 9px 12px 9px 0;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}

table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: color-mix(in srgb, var(--text-primary) 3%, transparent); }
.num { text-align: right; font-variant-numeric: tabular-nums; padding-right: 12px !important; }
/* `table.data th` (0,1,2) outranks a bare `.num` (0,1,0), so a numeric header
   needs its own rule or it sits left of the right-aligned figures below it */
table.data th.num { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }
.dim { color: var(--text-muted); }
.nowrap { white-space: nowrap; }

.res { margin-top: 14px; }

.announce {
  display: flex; gap: 12px; align-items: flex-start;
  background: color-mix(in srgb, var(--brand) 7%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--brand) 22%, var(--border));
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 13.5px;
  line-height: 1.65;
}
.announce-icon {
  flex: none; width: 18px; height: 18px; margin-top: 2px;
  border-radius: 50%; background: var(--brand); color: #fff;
  font-size: 11.5px; font-weight: 700; line-height: 18px; text-align: center;
}
.announce-body { flex: 1; white-space: pre-wrap; word-break: break-word; }
.announce-time { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

textarea {
  width: 100%; resize: vertical; font-family: inherit; line-height: 1.6;
}

.form { margin-top: 18px; }

@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

/* ── toast ──────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 90;
  background: var(--text-primary); color: var(--surface-1);
  padding: 9px 16px; border-radius: 999px; font-size: 13px;
  box-shadow: 0 8px 30px -10px rgba(0,0,0,.5);
  animation: rise .18s ease;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px) } to { opacity: 1; transform: translate(-50%, 0) } }
.toast.is-error { background: var(--critical); color: #fff; }

@media (forced-colors: active) {
  .card { border: 1px solid CanvasText; }
  

}

/* Wide mode for the ported console: its user table has a dozen columns and its charts
   are time series, both of which read better with the screen than with a 1240px
   reading column. */
.wrap.is-wide { max-width: min(1920px, 96vw); }
@media (max-width: 760px) { .wrap.is-wide { max-width: none; } 
}

/* ── console frame (/panel/embed/) ──────────────────────────────────
   Framed by New API's console, under its title and tabs: no page background (New API's
   shows through), no outer padding, the full width it is given — the islands line up
   with New API's own pages. */
body[data-shell="embed"] { background: transparent; }
body[data-shell="embed"] .wrap { max-width: none; padding: 0 0 24px; }
body[data-shell="embed"] .filterbar { position: static; padding: 0 0 12px; background: none; border-bottom: 0; }
/* the frame is as tall as its page and scrolls with New API's (app.js): toasts go to the
   part of it on screen, which New API reports */
body[data-shell="embed"] [data-sonner-toaster] {
  --offset-top: calc(var(--medai-view-top, 0px) + 24px) !important;
  --mobile-offset-top: calc(var(--medai-view-top, 0px) + 16px) !important;
}

/* ── rename dialog (shell-level: must render without the console bundle) ── */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; padding: 24px;
  background: color-mix(in srgb, var(--page) 55%, transparent);
  backdrop-filter: blur(6px);
}
.overlay[hidden] { display: none; }
.dialog-card {
  width: min(420px, 100%);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 26px 26px 20px;
  text-align: left;
}
.dialog-card h2 { font-size: 17px; margin: 0 0 6px; }
.dialog-sub { color: var(--text-secondary); font-size: 13px; margin: 0 0 18px; line-height: 1.55; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@media (max-width: 768px), (pointer: coarse) {
  html, body { max-width: 100%; overflow-x: clip; }
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea, select { font-size: 16px !important; }
}
