/* ==========================================================================
   cdxx OCR — 面板识别服务 / 共用样式表
   识别页与后台配置页共用。浅色 + 深色两套主题，全部走 class，
   页面里不写内联 style，以便服务端下发严格 CSP（style-src 'self'）。
   ========================================================================== */

:root {
  color-scheme: light;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #fafbfd;
  --surface-sunken: #f0f2f6;

  --border: #e6e9ef;
  --border-strong: #d3d8e0;

  --text: #14161b;
  --text-muted: #5b6270;
  --text-faint: #8b919d;

  --accent: #165dff;
  --accent-hover: #0d4ad9;
  --accent-soft: #eaf1ff;
  --accent-ring: rgba(22, 93, 255, .16);

  --ok: #0d7355;
  --ok-soft: #e2f5ee;
  --ok-line: #b3e3d1;

  --warn: #8a5308;
  --warn-soft: #fdf2dd;
  --warn-line: #efd8a6;

  --bad: #b02227;
  --bad-soft: #fdeceb;
  --bad-line: #f2c5c3;

  --mark-nick: #d4380d;
  --mark-power: #b98600;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px -12px rgba(16, 24, 40, .18);
  --shadow-lg: 0 24px 60px -20px rgba(16, 24, 40, .3);

  --radius: 14px;
  --radius-sm: 9px;
  --radius-xs: 6px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0e1014;
    --surface: #161920;
    --surface-alt: #1b1f27;
    --surface-sunken: #12151b;

    --border: #252a34;
    --border-strong: #363d49;

    --text: #e7eaf0;
    --text-muted: #a1a9b6;
    --text-faint: #757d8b;

    --accent: #4d8dff;
    --accent-hover: #6fa2ff;
    --accent-soft: #16233c;
    --accent-ring: rgba(77, 141, 255, .24);

    --ok: #4ed0a4;
    --ok-soft: #102b25;
    --ok-line: #1f5145;

    --warn: #e3b064;
    --warn-soft: #2e2410;
    --warn-line: #55411b;

    --bad: #f38084;
    --bad-soft: #331719;
    --bad-line: #5c2a2d;

    --mark-nick: #ff8a5c;
    --mark-power: #f0c24b;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow: 0 1px 3px rgba(0, 0, 0, .55), 0 10px 30px -14px rgba(0, 0, 0, .8);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .85);
  }
}

* { box-sizing: border-box; }

/* `hidden` must beat every layout rule below. Without this, `.dropzone`
   (display:flex), `.admin-layout` (display:grid) and `.gate` (display:grid)
   would keep showing an element the script had just hidden. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.spacer { flex: 1 1 auto; }

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

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent), #4d8dff);
  box-shadow: var(--shadow-sm);
  flex: none;
}
.brand-mark svg { width: 18px; height: 18px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 14px; font-weight: 600; letter-spacing: .2px; }
.brand-text em {
  font-style: normal;
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 620px) {
  .brand-text em { display: none; }
}

/* ------------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.6;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}
.badge.ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.badge.ok .dot { background: var(--ok); }
.badge.warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.badge.warn .dot { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }
.badge.bad { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }
.badge.bad .dot { background: var(--bad); }

@keyframes pulse { 50% { opacity: .35; } }

/* ------------------------------------------------------------------ buttons */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  cursor: pointer;
  white-space: nowrap;
  transition: background .14s, border-color .14s, color .14s, box-shadow .14s;
}
.btn:hover { background: var(--surface-sunken); border-color: var(--text-faint); }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.ghost { border-color: transparent; color: var(--text-muted); background: transparent; }
.btn.ghost:hover { background: var(--surface-sunken); color: var(--text); border-color: transparent; }

.btn.danger { color: var(--bad); border-color: var(--bad-line); }
.btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }

.btn.sm { padding: 4px 10px; font-size: 12.5px; }

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

.layout {
  display: grid;
  grid-template-columns: minmax(320px, .95fr) minmax(420px, 1.05fr);
  gap: 16px;
  padding: 18px 20px 48px;
  align-items: start;
  max-width: 1560px;
  margin: 0 auto;
}
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
}

.admin-layout {
  display: grid;
  gap: 16px;
  padding: 18px 20px 96px;
  max-width: 1000px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}
.card-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .2px;
}
.card-head .sub { font-size: 12px; color: var(--text-faint); }

.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

/* ---------------------------------------------------------------- dropzone */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 40px 20px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text-muted);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s;
}
.dropzone:hover,
.dropzone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone.dragging { transform: scale(.995); }
.dropzone[aria-busy="true"] { pointer-events: none; opacity: .75; }

.dz-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: 8px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.dz-icon svg { width: 22px; height: 22px; }

.dropzone strong { font-size: 14px; font-weight: 600; color: var(--text); }
.dropzone .dz-sub { font-size: 12.5px; }
.dropzone .dz-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 6px; }

/* ----------------------------------------------------------------- preview */

/* 预览按图自身宽高比排布，覆盖框的百分比坐标才能与像素严格对齐 */
.preview-wrap {
  position: relative;
  display: block;
  width: min(100%, calc(64vh * var(--preview-aspect, 1.6)));
  aspect-ratio: var(--preview-aspect, 1.6);
  margin: 0 auto;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
}
.preview-wrap img { display: block; width: 100%; height: 100%; object-fit: contain; }

.overlay { position: absolute; inset: 0; pointer-events: none; }
.overlay .box {
  position: absolute;
  border: 1px solid rgba(22, 93, 255, .5);
  border-radius: 2px;
  transition: background .1s, border-color .1s, box-shadow .1s;
}
.overlay .box.title { border-color: rgba(13, 115, 85, .7); }
.overlay .box.nickname {
  border: 2px solid var(--mark-nick);
  background: color-mix(in srgb, var(--mark-nick) 12%, transparent);
}
.overlay .box.power {
  border: 2px solid var(--mark-power);
  background: color-mix(in srgb, var(--mark-power) 14%, transparent);
}
.overlay .box.active {
  background: var(--accent-ring);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-ring);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.legend .lg { display: inline-flex; align-items: center; gap: 5px; }
.legend .lg::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid rgba(22, 93, 255, .5);
}
.legend .lg-nick::before { border: 2px solid var(--mark-nick); }
.legend .lg-power::before { border: 2px solid var(--mark-power); }
.legend .lg-title::before { border-color: rgba(13, 115, 85, .7); }

/* ------------------------------------------------------------------ metrics */

.metric-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metric {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.metric .label {
  display: block;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: .3px;
  margin-bottom: 3px;
}
.metric .value {
  display: block;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}
.metric .value.sm { font-size: 13.5px; font-weight: 500; }
.metric .value.dim { color: var(--text-faint); font-weight: 500; }
.metric .value.warn { color: var(--warn); }
.metric .value.bad { color: var(--bad); }
.metric.accent { border-color: var(--ok-line); background: var(--ok-soft); }

/* -------------------------------------------------------------- field grid */

.field-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 720px) {
  .field-columns { grid-template-columns: 1fr; }
}

.field-col {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.field-col-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  letter-spacing: .3px;
}

.field {
  display: grid;
  grid-template-columns: minmax(70px, auto) 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 6px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.field-col > .field:last-child { border-bottom: 0; }
.field:hover { background: var(--accent-soft); }

.field .k {
  color: var(--text-muted);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.field .k .tag {
  flex: none;
  padding: 0 4px;
  border-radius: 3px;
  font-size: 10px;
  line-height: 15px;
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid var(--warn-line);
}
.field .v {
  text-align: right;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
  font-feature-settings: "tnum";
}
.field .v.empty { color: var(--text-faint); }
.field .v .num { font-weight: 500; }
.field .v .unit { color: var(--text-muted); font-size: 12px; margin-left: 1px; }
/* Prefix tier ("无敌:1.95E+76") sits before the figure, so it needs the gap on
   the other side. */
.field .v .unit.pre { margin-left: 0; margin-right: 3px; }
.field.is-missing { opacity: .5; }
.field.is-inferred .k { color: var(--text-faint); }

/* ------------------------------------------------------------------ notices */

.notice {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  line-height: 1.65;
  border: 1px solid transparent;
  margin-bottom: 12px;
}
.notice:last-child { margin-bottom: 0; }
.notice.info { background: var(--accent-soft); border-color: var(--accent-ring); color: var(--text); }
.notice.ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.notice.warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.notice.bad { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }

.empty-hint {
  margin: 0;
  padding: 26px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--text-faint);
}

/* ---------------------------------------------------------------- raw boxes */

.raw-box {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.raw-box summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--surface-alt);
  user-select: none;
}
.raw-box summary:hover { color: var(--text); }
.raw-box pre {
  margin: 0;
  padding: 12px;
  font: 12px/1.7 var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 320px;
  overflow: auto;
  color: var(--text-muted);
  background: var(--surface);
}

.timing {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-faint);
}
.timing b { font-weight: 500; color: var(--text-muted); }

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 15, 20, .45);
  backdrop-filter: blur(2px);
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-card .card-head h2 { font-size: 14px; }

/* --------------------------------------------------------------- token bar */

.token-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.token-bar input {
  flex: 1 1 200px;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text);
}
.token-bar input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.token-bar input[readonly] { background: var(--surface-sunken); color: var(--text-muted); font-family: var(--mono); font-size: 12.5px; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

/* ---------------------------------------------------------------- admin bits */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.stat {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.stat .label { display: block; font-size: 11px; color: var(--text-faint); margin-bottom: 3px; }
.stat .value { display: block; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .value.sm { font-size: 13px; font-weight: 500; }

.form-section { margin-bottom: 24px; }
.form-section:last-child { margin-bottom: 0; }
.form-section h3 {
  margin: 0 0 3px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-section h3::before {
  content: "";
  width: 3px;
  height: 13px;
  border-radius: 2px;
  background: var(--accent);
  flex: none;
}
.form-section p.desc {
  margin: 0 0 14px 11px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.field-row { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-row label { font-size: 12.5px; color: var(--text-muted); }
.field-row label .restart {
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 3px;
  font-size: 10px;
  line-height: 15px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-ring);
}
.field-row input,
.field-row select,
.field-row textarea {
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.field-row textarea {
  resize: vertical;
  min-height: 62px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
}
.field-row input:focus,
.field-row select:focus,
.field-row textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.field-row .help { font-size: 11.5px; color: var(--text-faint); line-height: 1.5; }

.gate {
  display: grid;
  place-items: center;
  padding: 56px 20px;
}
.gate-card {
  width: 100%;
  max-width: 440px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.gate-card h2 { margin: 0 0 6px; font-size: 16px; }
.gate-card p { margin: 0 0 18px; font-size: 12.5px; color: var(--text-muted); line-height: 1.7; }
.gate-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
}
.gate-icon svg { width: 22px; height: 22px; }
.gate-card .token-bar { margin-bottom: 12px; }
.gate-card .check { justify-content: center; }
.gate-card #connect-note:not(:empty) { margin-top: 16px; }

.savebar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 24px -14px rgba(16, 24, 40, .35);
}
.savebar .state { font-size: 12.5px; color: var(--text-muted); }
.savebar .state.dirty { color: var(--warn); font-weight: 500; }

/* --------------------------------------------------------------- feedback */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  z-index: 90;
  max-width: min(92vw, 520px);
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--surface);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--accent-ring);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin .7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================== login page */

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

.login-card {
  width: 100%;
  max-width: 384px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.login-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 24px 18px;
  text-align: center;
}
.login-head h1 { margin: 6px 0 0; font-size: 17px; font-weight: 600; }
.login-head p { margin: 0; font-size: 12.5px; color: var(--text-muted); }

.login-form { display: grid; gap: 13px; padding: 0 24px 24px; }
.login-form .field-row label { font-weight: 500; }
.login-form .btn { width: 100%; padding: 9px 14px; }
.login-form .check { justify-content: flex-start; }

.login-foot {
  padding: 11px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 11.5px;
  color: var(--text-faint);
  text-align: center;
}

/* ============================================================== admin shell */

.admin-shell {
  display: grid;
  grid-template-columns: 196px minmax(0, 1fr);
  gap: 16px;
  padding: 18px 20px 96px;
  max-width: 1180px;
  margin: 0 auto;
  align-items: start;
}

@media (max-width: 900px) {
  .admin-shell { grid-template-columns: 1fr; padding-bottom: 110px; }
}

.side-nav {
  position: sticky;
  top: 62px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

@media (max-width: 900px) {
  .side-nav {
    position: static;
    flex-direction: row;
    overflow-x: auto;
    gap: 4px;
  }
}

.nav-item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-sunken); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  border-color: var(--accent-ring);
  color: var(--accent);
  font-weight: 500;
}
.nav-item .n-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border-strong);
  flex: none;
}
.nav-item.active .n-dot { background: var(--accent); }
.nav-item .n-badge {
  margin-left: auto;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 10.5px;
  line-height: 16px;
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid var(--warn-line);
}

.admin-main { display: grid; gap: 16px; min-width: 0; }

.module-head { margin: 0 0 4px; }
.module-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.module-head p { margin: 4px 0 0; font-size: 12.5px; color: var(--text-muted); line-height: 1.7; }

/* ================================================================== tables */

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

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.table th {
  text-align: left;
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: .2px;
  color: var(--text-muted);
  padding: 8px 10px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-alt); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table .muted { color: var(--text-faint); }

/* =================================================================== pills */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 17px;
  white-space: nowrap;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.pill.ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.pill.warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.pill.bad { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }
.pill.info { background: var(--accent-soft); border-color: var(--accent-ring); color: var(--accent); }

/* ============================================================= credentials */

.key-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
}
.key-box .key-label { font-size: 11.5px; color: var(--text-muted); flex: none; }
.key-box code {
  flex: 1 1 240px;
  min-width: 0;
  font: 12.5px/1.6 var(--mono);
  word-break: break-all;
  color: var(--text);
}

/* ==================================================================== logs */

.log-view {
  margin: 0;
  max-height: 300px;
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  font: 12px/1.65 var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
}

/* ============================================================= inline form */

.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  align-items: end;
}
.inline-form .btn { height: 34px; }

/* ============================================================= code sample */

.code-sample {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  font: 12px/1.7 var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
  overflow-x: auto;
}

/* A module is hidden until its nav item is selected; `[hidden]` at the top of
   this file is what makes that work, since `.card` would otherwise win. */
.card.module[hidden] { display: none !important; }

/* ========================================================== admin extras */

.stack { display: grid; gap: 14px; }

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

.card-sub { font-size: 12.5px; color: var(--text-muted); }

.muted { color: var(--text-faint); }

/* Backing store for an integration: one bordered block per API client, so the
   editable fields, the usage counters and the destructive actions stay in one
   place instead of being smeared across a wide table. */
.client-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.client-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.client-head strong { font-size: 13.5px; }
.client-head .key-hint {
  font: 12px/1.5 var(--mono);
  color: var(--text-faint);
  word-break: break-all;
}
.usage-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.usage-line b { font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }

.client-card .btn-row { margin-top: 12px; }

