/* ==========================================================================
   RHK Sniper Console — 设计令牌 + 组件样式
   · 零外部资源（CSP default-src 'self'）：系统字体、内联 SVG 图标、data: 小图
   · 暗色为默认；app.js 在首帧前给 <html> 写入 data-theme="dark|light"
   · 状态色（ok / warn / danger / info）永远与图标或文字成对出现，不单靠颜色传达
   ========================================================================== */

:root {
  color-scheme: dark;

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

  --bg: #0a0d12;
  --bg-elev: #0f131a;
  --surface: #131821;
  --surface-2: #19202b;
  --surface-3: #212a38;
  --field: #0c1016;
  --border: #232c3a;
  --border-strong: #313c4e;
  --border-hover: #45526a;

  --text: #e8edf3;
  --text-2: #aeb8c6;
  --text-3: #7f8a9b;

  --accent: #f0b232;
  --accent-hover: #ffc64d;
  --accent-ink: #1b1403;
  --accent-text: #f2bd4b;
  --accent-soft: rgba(240, 178, 50, 0.14);
  --accent-line: rgba(240, 178, 50, 0.45);

  --ok: #3fb950;
  --ok-text: #56d364;
  --ok-soft: rgba(63, 185, 80, 0.14);
  --ok-line: rgba(63, 185, 80, 0.4);

  --warn: #d9a21b;
  --warn-text: #e8b84a;
  --warn-soft: rgba(217, 162, 27, 0.15);
  --warn-line: rgba(217, 162, 27, 0.45);

  --danger: #f85149;
  --danger-text: #ff8179;
  --danger-soft: rgba(248, 81, 73, 0.14);
  --danger-line: rgba(248, 81, 73, 0.5);
  --danger-fill: #d1332f;
  --danger-fill-hover: #e5443f;

  --info: #58a6ff;
  --info-text: #79b8ff;
  --info-soft: rgba(88, 166, 255, 0.14);
  --info-line: rgba(88, 166, 255, 0.4);

  --neutral-soft: rgba(139, 150, 168, 0.16);
  --row-hover: rgba(255, 255, 255, 0.025);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.02) inset, 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-pop: 0 18px 48px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
  --focus-ring: 0 0 0 3px rgba(240, 178, 50, 0.3);
  --page-glow: radial-gradient(1100px 420px at 12% -8%, rgba(240, 178, 50, 0.07), transparent 62%);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b96a8' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f3f4f6;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --surface-3: #eceff3;
  --field: #ffffff;
  --border: #e0e4ea;
  --border-strong: #cbd2db;
  --border-hover: #a9b3c1;

  --text: #151a21;
  --text-2: #4a5565;
  --text-3: #667085;

  --accent: #f0b232;
  --accent-hover: #e3a31f;
  --accent-ink: #1b1403;
  --accent-text: #8a5a00;
  --accent-soft: #fff3d6;
  --accent-line: #e0a82e;

  --ok: #1a7f37;
  --ok-text: #116329;
  --ok-soft: #dafbe1;
  --ok-line: #8fd3a0;

  --warn: #9a6700;
  --warn-text: #7d4e00;
  --warn-soft: #fff1c7;
  --warn-line: #e3bd5c;

  --danger: #cf222e;
  --danger-text: #a40e26;
  --danger-soft: #ffe9e7;
  --danger-line: #f3a8a3;
  --danger-fill: #cf222e;
  --danger-fill-hover: #b91c27;

  --info: #0969da;
  --info-text: #0550ae;
  --info-soft: #ddf0ff;
  --info-line: #8cc4f5;

  --neutral-soft: #eceff3;
  --row-hover: rgba(15, 23, 42, 0.03);

  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-pop: 0 18px 48px rgba(16, 24, 40, 0.18), 0 2px 8px rgba(16, 24, 40, 0.1);
  --focus-ring: 0 0 0 3px rgba(240, 178, 50, 0.35);
  --page-glow: radial-gradient(1100px 420px at 12% -8%, rgba(240, 178, 50, 0.1), transparent 62%);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--page-glow), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
a { color: var(--info-text); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: var(--mono);
  font-size: 0.92em;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text);
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.muted { color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }
:root[data-theme="light"] .only-dark, :root:not([data-theme="light"]) .only-light { display: none; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 6px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
@supports (backdrop-filter: blur(8px)) or (-webkit-backdrop-filter: blur(8px)) {
  .topbar {
    background: color-mix(in srgb, var(--bg-elev) 86%, transparent);
    -webkit-backdrop-filter: saturate(140%) blur(12px);
    backdrop-filter: saturate(140%) blur(12px);
  }
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-right { flex-wrap: wrap; justify-content: flex-end; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  color: #1b1403;
  background: linear-gradient(140deg, #ffd470, #eda514);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18) inset, 0 4px 14px rgba(240, 178, 50, 0.28);
}
.brand-mark .icon { width: 17px; height: 17px; stroke-width: 2.4; }
.brand-mark-lg { width: 44px; height: 44px; border-radius: 13px; }
.brand-mark-lg .icon { width: 24px; height: 24px; }
.brand-name { font-size: 14px; font-weight: 800; letter-spacing: 0.1em; white-space: nowrap; }
.brand-name em { font-style: normal; color: var(--accent-text); }
.version-tag {
  padding: 1px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text-3);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.conn-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--neutral-soft);
  color: var(--text-2);
}
.conn-badge.ok { background: var(--ok-soft); color: var(--ok-text); }
.conn-badge.warn { background: var(--warn-soft); color: var(--warn-text); }
.conn-badge.danger { background: var(--danger-soft); color: var(--danger-text); }
.topbar-sep { width: 1px; height: 22px; background: var(--border-strong); }
.user-tag { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; white-space: nowrap; }

/* ---------- Status dots ---------- */
.dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--text-3);
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.danger { background: var(--danger); }
.dot.info { background: var(--info); }
.dot.accent { background: var(--accent); }
.conn-badge.ok .dot { background: var(--ok); }
.conn-badge.warn .dot { background: var(--warn); }
.conn-badge.danger .dot { background: var(--danger); }
.dot.pulse { position: relative; }
.dot.pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: inherit;
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(1); opacity: 0.7; }
  70%, 100% { transform: scale(2.6); opacity: 0; }
}

/* ---------- Status strip ---------- */
.statusbar {
  display: flex;
  gap: 8px;
  padding: 9px 20px;
  overflow-x: auto;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.statusbar::-webkit-scrollbar { display: none; }
.statusbar.is-stale { opacity: 0.55; }
.stat {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 4px 11px 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12px;
  white-space: nowrap;
}
.stat-k { color: var(--text-3); }
.stat-v { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .icon { width: 13px; height: 13px; color: var(--accent-text); }
.stat.danger { border-color: var(--danger-line); background: var(--danger-soft); }
.stat.danger .stat-v { color: var(--danger-text); }
.stat.warn { border-color: var(--warn-line); }

/* ---------- Layout ---------- */
.container { max-width: 1440px; margin: 0 auto; padding: 20px 20px 72px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.two-col-57 { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
.col-stack { display: grid; gap: 20px; min-width: 0; }
.col-stack > .card, .two-col > .card { margin-bottom: 0; }

/* ---------- Banners ---------- */
.banners { display: grid; gap: 10px; margin-bottom: 16px; }
.banners:empty { display: none; }
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  border: 1px solid var(--border-strong);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.banner > .icon { width: 17px; height: 17px; }
.banner-main { display: flex; flex: 1; flex-wrap: wrap; align-items: baseline; gap: 1px 12px; min-width: 0; }
.banner-title { font-weight: 650; white-space: nowrap; }
.banner-text { flex: 1 1 340px; min-width: 0; color: var(--text-2); font-size: 13px; }
.banner .btn { flex: none; }
.banner.danger { border-color: var(--danger-line); background: var(--danger-soft); }
.banner.danger > .icon, .banner.danger .banner-title { color: var(--danger-text); }
.banner.warn { border-color: var(--warn-line); background: var(--warn-soft); }
.banner.warn > .icon, .banner.warn .banner-title { color: var(--warn-text); }
.banner.info { border-color: var(--info-line); background: var(--info-soft); }
.banner.info > .icon, .banner.info .banner-title { color: var(--info-text); }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.tile {
  min-width: 0;
  padding: 14px 16px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
.tile-label { display: flex; align-items: center; gap: 7px; color: var(--text-2); font-size: 12.5px; }
.tile-label .icon { width: 14px; height: 14px; color: var(--text-3); }
.tile-value { margin-top: 4px; font-size: 26px; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; }
.tile-unit { margin-left: 4px; color: var(--text-3); font-size: 14px; font-weight: 500; letter-spacing: 0; }
.tile-sub { margin-top: 6px; color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { height: 6px; margin-top: 9px; border-radius: 999px; background: var(--info-soft); overflow: hidden; }
.meter-fill { height: 100%; min-width: 0; border-radius: 999px; background: var(--info); transition: width 0.3s ease; }
.meter.warn { background: var(--warn-soft); }
.meter.warn .meter-fill { background: var(--warn); }
.meter.danger { background: var(--danger-soft); }
.meter.danger .meter-fill { background: var(--danger); }
.meter.mini { width: 72px; height: 4px; margin-top: 6px; }

/* ---------- Tabs ---------- */
.tabs-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px 12px;
  border: 0;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: transparent;
}
.tab.is-active { color: var(--text); }
.tab.is-active::after { background: var(--accent-text); }
.tab.is-active .icon { color: var(--accent-text); }
.tab-count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--neutral-soft);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.tab-count:empty { display: none; }
.tab-count.warn { background: var(--warn-soft); color: var(--warn-text); }
.ticker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 44%;
  min-width: 0;
  margin-bottom: 8px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.ticker:hover { border-color: var(--border-hover); color: var(--text); }
.ticker-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Cards ---------- */
.card {
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 20px 14px;
}
.card-head h2 { font-size: 15.5px; font-weight: 650; }
.card-sub { margin-top: 3px; max-width: 86ch; color: var(--text-2); font-size: 12.5px; }
.card-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-body { padding: 4px 20px 20px; }

/* ---------- Forms ---------- */
.form { padding: 0 20px 20px; }
.form-section { min-width: 0; margin: 0; padding: 16px 0 18px; border: 0; border-top: 1px solid var(--border); }
.form-section legend {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px 0 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}
.step {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 11.5px;
  font-weight: 700;
}
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px; }
.form-section .grid { margin-top: 12px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
.field { min-width: 0; }
.field-end { display: flex; align-items: flex-end; }
.field > label, .field > .label, .login-card .field > label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 550;
}
.opt { margin-left: 4px; color: var(--text-3); font-size: 11.5px; font-weight: 400; }
.hint { margin-top: 6px; color: var(--text-3); font-size: 12px; line-height: 1.45; }
.hint:empty { display: none; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="tel"], input[type="time"], select {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input::placeholder { color: var(--text-3); opacity: 0.75; }
input:hover, select:hover, textarea:hover { border-color: var(--border-hover); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
input:disabled, select:disabled { opacity: 0.5; cursor: not-allowed; }
input.is-invalid, select.is-invalid, textarea.is-invalid { border-color: var(--danger); }
textarea {
  display: block;
  width: 100%;
  min-height: 78px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  resize: vertical;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
textarea::placeholder { color: var(--text-3); opacity: 0.75; }
input[type="number"], input[type="time"] { font-variant-numeric: tabular-nums; }
select {
  padding-right: 32px;
  -webkit-appearance: none;
  appearance: none;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 11px center;
  text-overflow: ellipsis;
}
.input-group { display: flex; gap: 8px; }
.input-group > input { flex: 1; min-width: 0; }
.affix { position: relative; }
.affix > span {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 13px;
  pointer-events: none;
}
.affix > input { padding-left: 25px; }
.input-tag-wrap { position: relative; }
.input-tag {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--neutral-soft);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 600;
}
.input-tag.ok { background: var(--ok-soft); color: var(--ok-text); }
.input-tag.danger { background: var(--danger-soft); color: var(--danger-text); }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--field);
}
.seg { position: relative; min-width: 0; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s ease, color 0.12s ease;
}
.seg:hover span { color: var(--text); }
.seg input:checked + span { background: var(--surface-3); color: var(--text); }
.seg-dry input:checked + span { background: var(--info-soft); color: var(--info-text); box-shadow: 0 0 0 1px var(--info-line) inset; }
.seg-live input:checked + span { background: var(--danger-fill); color: #fff; }
.seg input:focus-visible + span { box-shadow: var(--focus-ring); }
.mode-hint-wrap { display: flex; align-items: flex-end; }
.mode-hint { min-height: 38px; display: flex; align-items: center; color: var(--text-2); font-size: 12.5px; line-height: 1.45; }
.mode-hint.is-live { color: var(--danger-text); font-weight: 550; }

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.form-note { display: inline-flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 12.5px; }
.form-note .icon { width: 14px; height: 14px; }
.subform { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.subform:first-child, .info-box + .subform { margin-top: 14px; }
.subform h3 { margin-bottom: 12px; font-size: 13px; font-weight: 650; }
.subform .form-actions { margin-top: 16px; }

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.btn-danger { border-color: var(--danger-fill); background: var(--danger-fill); color: #fff; }
.btn-danger:hover { border-color: var(--danger-fill-hover); background: var(--danger-fill-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { border-color: transparent; background: var(--neutral-soft); color: var(--text); }
.btn-sm { height: 30px; padding: 0 10px; border-radius: 7px; font-size: 12.5px; }
.btn-lg { height: 42px; padding: 0 18px; font-size: 14px; }
.btn-icon { width: 30px; padding: 0; }
.btn .icon { width: 15px; height: 15px; }
.btn-sm .icon { width: 14px; height: 14px; }
.full { width: 100%; }
.btn-kill { border-color: var(--danger-line); background: transparent; color: var(--danger-text); }
.btn-kill:hover { border-color: var(--danger); background: var(--danger-soft); }
.btn-kill.is-engaged { border-color: var(--danger-fill); background: var(--danger-fill); color: #fff; animation: kill-blink 1.6s ease-in-out infinite; }
@keyframes kill-blink {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.55); }
  50% { box-shadow: 0 0 0 6px rgba(248, 81, 73, 0); }
}
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--text-3);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn-primary.is-loading::after { border-color: rgba(27, 20, 3, 0.3); border-top-color: var(--accent-ink); }
.btn-danger.is-loading::after, .btn-kill.is-engaged.is-loading::after { border-color: rgba(255, 255, 255, 0.4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

.filter { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 9px; background: var(--field); }
.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.filter-btn:hover { color: var(--text); }
.filter-btn.is-active { background: var(--surface-3); color: var(--text); }
.filter-btn .count { color: var(--text-3); font-size: 11.5px; font-variant-numeric: tabular-nums; }

/* ---------- Chips & callouts ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--neutral-soft);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.chip .icon { width: 12px; height: 12px; }
.chip.ok { background: var(--ok-soft); color: var(--ok-text); }
.chip.warn { background: var(--warn-soft); color: var(--warn-text); }
.chip.danger { background: var(--danger-soft); color: var(--danger-text); }
.chip.info { background: var(--info-soft); color: var(--info-text); }
.chip.accent { background: var(--accent-soft); color: var(--accent-text); }
.chip.solid-danger { background: var(--danger-fill); color: #fff; }
.tag {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text-2);
  font-size: 11.5px;
  line-height: 18px;
  white-space: nowrap;
}
.tag.warn { border-color: var(--warn-line); background: var(--warn-soft); color: var(--warn-text); }
.callout {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
}
.callout.danger { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger-text); }
.callout.warn { border-color: var(--warn-line); background: var(--warn-soft); color: var(--warn-text); }
.callout.info { border-color: var(--info-line); background: var(--info-soft); color: var(--info-text); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-align: left;
  white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--row-hover); }
thead th:first-child, tbody td:first-child { padding-left: 20px; }
thead th:last-child, tbody td:last-child { padding-right: 20px; }
.col-id { width: 64px; }
.col-act { width: 1%; text-align: right; }
td.cell-act { text-align: right; white-space: nowrap; }
td.cell-act .btn + .btn { margin-left: 6px; }
td.cell-id { color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.row-live td:first-child { box-shadow: 3px 0 0 var(--danger) inset; }
.t-name { font-weight: 650; word-break: break-word; }
.t-name a { color: inherit; }
.t-name a .icon { width: 12px; height: 12px; margin-left: 4px; color: var(--text-3); vertical-align: -1px; }
.t-meta { margin-top: 2px; color: var(--text-2); font-size: 12.5px; word-break: break-word; }
.t-sub { margin-top: 3px; color: var(--text-3); font-size: 12px; word-break: break-word; }
.t-sub .tag { margin-right: 4px; }
.sep { margin: 0 6px; color: var(--text-3); opacity: 0.6; }
.t-error {
  margin-top: 8px;
  padding: 7px 10px;
  border: 1px solid var(--danger-line);
  border-radius: 7px;
  background: var(--danger-soft);
  color: var(--danger-text);
  font-size: 12.5px;
  word-break: break-word;
}
.t-error b { font-weight: 650; }
.t-error .t-hint { display: block; margin-top: 2px; opacity: 0.9; }
.stock { display: inline-flex; align-items: center; gap: 7px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stage { margin-top: 5px; color: var(--text-2); font-size: 12.5px; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 650; }
.countdown.is-urgent { color: var(--danger-text); }
.countdown.is-over { color: var(--text-3); font-weight: 500; }
.money { font-weight: 650; font-variant-numeric: tabular-nums; }
td.cell-empty { padding: 0; }
.empty { padding: 34px 16px; color: var(--text-3); text-align: center; }
.empty .icon { width: 26px; height: 26px; margin-bottom: 8px; stroke-width: 1.6; opacity: 0.7; }
.empty-title { color: var(--text-2); font-weight: 600; }
.empty-hint { margin-top: 2px; font-size: 12.5px; }

/* ---------- Product / rule preview ---------- */
.product-preview, .preview-box {
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.product-preview { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.pp-main { min-width: 0; }
.pp-title { font-weight: 650; }
.pp-meta { margin-top: 2px; color: var(--text-3); font-size: 12.5px; }
.pp-stats { display: flex; gap: 22px; flex-wrap: wrap; }
.pp-stat > span { display: block; color: var(--text-3); font-size: 11.5px; }
.pp-stat > b { display: block; font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.pp-stat .chip { margin-top: 1px; font-size: 12px; }
.pv-head { margin-bottom: 8px; font-weight: 650; }
.pv-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.pv-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.pv-list li > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-right { display: inline-flex; align-items: center; gap: 10px; flex: none; }

/* ---------- Payment cards ---------- */
.pay-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 12px; }
.backup-cards { margin-top: 14px; }
.backup-cards:empty { display: none; }
.backup-head { margin-bottom: 8px; font-size: 13px; font-weight: 650; }
.backup-head .opt { margin-left: 8px; color: var(--text-3); font-size: 12px; font-weight: 400; }
.backup-list { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.pay-cards > .empty { grid-column: 1 / -1; }
.pay-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 128px;
  padding: 13px 15px;
  border-radius: 13px;
  color: #f4f6fa;
  background: linear-gradient(135deg, #3a4558, #1b212c);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.07) inset, 0 6px 16px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.pay-card::before {
  content: "";
  position: absolute;
  right: -46px;
  top: -46px;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
}
.pay-card.visa { background: linear-gradient(135deg, #2748b5, #121f5e); }
.pay-card.mastercard { background: linear-gradient(135deg, #8c2f1b, #2d1512); }
.pay-card.amex { background: linear-gradient(135deg, #127a86, #0b3a47); }
.pay-card.discover { background: linear-gradient(135deg, #96560f, #3a2208); }
.pay-card.jcb { background: linear-gradient(135deg, #1d6b3f, #0d3320); }
.pay-card.unionpay { background: linear-gradient(135deg, #a3262b, #123a63); }
.pc-top { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pc-brand { font-size: 13px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.pc-default { padding: 0 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.18); font-size: 11px; line-height: 18px; }
.pc-num { position: relative; font-family: var(--mono); font-size: 16px; letter-spacing: 0.1em; }
.pc-bottom { position: relative; display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; font-size: 11.5px; }
.pc-holder { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.92; }
.pc-label { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.75; }
.pc-exp { flex: none; font-family: var(--mono); opacity: 0.92; }
.pc-del {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  cursor: pointer;
}
.pc-del:hover { background: rgba(0, 0, 0, 0.5); }
.pc-del .icon { width: 13px; height: 13px; }
.pc-tools { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Item lists / info box ---------- */
.item-list { display: grid; gap: 8px; }
.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.item-main { min-width: 0; }
.item-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 650; }
.item-meta { margin-top: 2px; color: var(--text-3); font-size: 12.5px; word-break: break-word; }
.item-actions { display: inline-flex; gap: 6px; flex: none; }
.info-box {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13px;
}
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 5px 14px; margin: 10px 0 0; }
.kv dt { color: var(--text-3); white-space: nowrap; }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }
.info-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 650; }

/* ---------- Terminal ---------- */
.terminal {
  height: 380px;
  padding: 10px 12px;
  overflow: auto;
  border: 1px solid #1d2531;
  border-radius: var(--radius-sm);
  background: #07090d;
  color: #c9d1d9;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
}
.terminal-empty { color: #6e7681; }
.log-line { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 10px; }
.log-time { color: #6e7681; }
.log-lv { color: #8b949e; }
.log-msg { white-space: pre-wrap; word-break: break-word; }
.log-line.ok .log-lv, .log-line.ok .log-msg { color: #7ee787; }
.log-line.warn .log-lv, .log-line.warn .log-msg { color: #e3b341; }
.log-line.error .log-lv, .log-line.error .log-msg { color: #ff7b72; }
.terminal.only-issues .log-line.info, .terminal.only-issues .log-line.ok { display: none; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px 11px 13px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--info);
  border-radius: 10px;
  background: var(--surface-2);
  box-shadow: var(--shadow-pop);
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}
.toast > .icon { margin-top: 2px; color: var(--info-text); }
.toast.ok { border-left-color: var(--ok); }
.toast.ok > .icon { color: var(--ok-text); }
.toast.warn { border-left-color: var(--warn); }
.toast.warn > .icon { color: var(--warn-text); }
.toast.err { border-left-color: var(--danger); }
.toast.err > .icon { color: var(--danger-text); }
.toast-msg { flex: 1; min-width: 0; font-size: 13px; word-break: break-word; }
.toast-x { display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--text-3); cursor: pointer; }
.toast-x:hover { background: var(--neutral-soft); color: var(--text); }
.toast-x .icon { width: 13px; height: 13px; }
.toast.is-leaving { opacity: 0; transform: translateX(8px); transition: opacity 0.15s ease, transform 0.15s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- Modal ---------- */
dialog.modal {
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-pop);
  overflow: auto;
}
dialog.modal::backdrop { background: rgba(4, 6, 10, 0.62); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 20px 22px 0; }
.modal-head h2 { font-size: 16px; font-weight: 650; }
.modal-icon { display: grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); }
.modal-icon.danger { background: var(--danger-soft); color: var(--danger-text); }
.modal-icon .icon { width: 18px; height: 18px; }
.modal-body { padding: 12px 22px 4px; color: var(--text-2); font-size: 13.5px; }
.modal-body p + p { margin-top: 8px; }
.modal-body .kv { margin: 12px 0 4px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font-size: 13px; }
.modal-body .callout { margin: 12px 0 0; }
.modal-ack { margin: 14px 22px 0; color: var(--text); }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 18px 22px 20px; }

/* ---------- Detail dialog, timelines, small controls ---------- */
dialog.modal.modal-wide { width: min(680px, calc(100vw - 32px)); }
.modal-wide .modal-head { justify-content: space-between; }
.modal-scroll { max-height: min(70vh, 640px); padding-bottom: 22px; overflow: auto; }
.modal-body .kv dd .chip + .chip { margin-left: 6px; }
.info-h { margin: 18px 0 8px; color: var(--text); font-size: 13px; font-weight: 650; }
code.wrap { display: inline-block; white-space: pre-wrap; word-break: break-word; }
.tl { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; color: var(--text); font-size: 13px; }
.tl li { display: grid; grid-template-columns: 8.5em minmax(0, 1fr) 6.5em; align-items: center; gap: 12px; }
.tl-bar { height: 6px; border-radius: 999px; background: var(--info-soft); overflow: hidden; }
.tl-bar i { display: block; height: 100%; min-width: 2px; border-radius: 999px; background: var(--info); }
.tl-ms { color: var(--text-2); text-align: right; white-space: nowrap; }
.tl-stock li { grid-template-columns: 9.5em 5em minmax(0, 1fr); }
.tl-stock .tl-ms { text-align: left; }
.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--info-text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
.stock-btn { padding: 2px 6px; margin: -2px -6px; border: 0; border-radius: 6px; background: none; color: inherit; font: inherit; font-weight: 650; cursor: pointer; }
.stock-btn:hover { background: var(--neutral-soft); }
.acct-switch { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.acct-switch label { display: block; margin-bottom: 6px; color: var(--text-2); font-size: 12.5px; font-weight: 550; }
.acct-switch select { flex: 1; min-width: 0; }
.form-actions-right { display: inline-flex; gap: 10px; flex-wrap: wrap; }
.delivery-list { margin-top: 14px; }
.delivery-list:empty { display: none; }
.delivery-list h3 { margin-bottom: 8px; color: var(--text-2); font-size: 12.5px; font-weight: 600; }
.delivery-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
}
.delivery-row > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-sub { margin-top: 14px; color: var(--text-2); font-weight: 600; }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; padding: 24px; }
.login-shell { width: 100%; max-width: 408px; }
.login-card {
  padding: 30px 30px 26px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-pop);
}
.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 26px; }
.login-brand .brand-name { font-size: 16px; }
.login-version { margin-top: 1px; color: var(--text-3); font-size: 12px; }
.login-card h1 { font-size: 20px; font-weight: 650; }
.login-sub { margin: 4px 0 20px; color: var(--text-2); font-size: 13px; }
.login-card .field { margin-bottom: 14px; }
.login-card input { height: 42px; font-size: 14px; }
.login-card .btn-lg { margin-top: 6px; }
.login-foot { margin-top: 18px; color: var(--text-3); font-size: 12px; line-height: 1.6; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .ticker { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1080px) {
  .span-2 { grid-column: span 3; }
  .span-3 { grid-column: span 6; }
  .span-4 { grid-column: span 6; }
  .two-col, .two-col-57 { grid-template-columns: minmax(0, 1fr); }
  .two-col .span-4 { grid-column: span 4; }
  .mode-hint { min-height: 0; }
}
@media (max-width: 760px) {
  .topbar { padding: 8px 14px; }
  .statusbar { padding: 8px 14px; }
  .container { padding: 14px 14px 64px; }
  .btn-label, .user-tag, .topbar-sep, .version-tag { display: none; }
  .topbar-right { gap: 6px; }
  .card-head { padding: 16px 16px 12px; }
  .form { padding: 0 16px 16px; }
  .card-body { padding: 4px 16px 16px; }
  .span-2, .span-3 { grid-column: span 6; }
  .span-4, .span-5, .span-6, .span-7, .span-8, .two-col .span-4 { grid-column: span 12; }
  .two-col .span-4.keep-third { grid-column: span 4; }
  .tile-value { font-size: 22px; }
  .toasts { top: 62px; right: 12px; }
  .form-actions .btn-lg { width: 100%; }

  .table-stack thead { display: none; }
  .table-stack tbody tr { display: block; padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack tbody td { display: flex; gap: 12px; padding: 4px 0 !important; border: 0; }
  .table-stack tbody td::before { content: attr(data-label); flex: 0 0 5.2em; color: var(--text-3); font-size: 12px; }
  .table-stack tbody td > div { min-width: 0; flex: 1; }
  .table-stack td.cell-act { justify-content: flex-start; text-align: left; padding-top: 8px !important; }
  .table-stack td.cell-empty { display: block; }
  .table-stack td.cell-empty::before { content: none; }
  tr.row-live td:first-child { box-shadow: none; }
  .table-stack tr.row-live { box-shadow: 3px 0 0 var(--danger) inset; }
}
@media (max-width: 460px) {
  .brand-name { display: none; }
  .span-2, .span-3 { grid-column: span 12; }
  .tiles { gap: 10px; }
  .tile { padding: 12px 13px; }
  .pp-stats { gap: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
