:root {
  --ink: #1a1714;
  --ink-soft: #5c564e;
  --paper: #f4efe6;
  --paper-2: #ebe4d4;
  --panel: #fffdf8;
  --line: #ddd4c2;
  --line-strong: #c9bda6;
  --accent: #b45309;
  --accent-dark: #9a3b09;
  --accent-soft: #f3e0c8;
  --ok: #3f6b4a;
  --ok-bg: #e4efe6;
  --danger: #9f2d2d;
  --danger-bg: #f8e4e0;
  --shadow: 0 18px 40px rgba(48, 36, 18, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 600px at 10% -10%, #fff8ea 0%, var(--paper) 45%);
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

#app { min-height: 100vh; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 36px 32px 28px;
  box-shadow: var(--shadow);
}
.login-kicker {
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}
.login-card h1 {
  margin: 8px 0 6px;
  font-size: 28px;
  font-weight: 650;
}
.login-card p.hint {
  margin: 0 0 24px;
  color: var(--ink-soft);
  font-size: 14px;
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.field textarea { min-height: 88px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
}
.btn:hover { background: #2b2621; }
.btn.primary { background: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
.btn.danger { background: var(--danger); }
.btn.sm { padding: 7px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.full { width: 100%; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 12px; }

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: #1c1814;
  color: #f4efe6;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
}
.brand { padding: 4px 10px 20px; }
.brand .kicker { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: #d6a36a; }
.brand h2 { margin: 6px 0 0; font-size: 20px; font-weight: 650; }
.nav { display: flex; flex-direction: column; gap: 6px; }
.nav a {
  padding: 10px 12px;
  border-radius: 10px;
  color: #d9d0c2;
}
.nav a:hover, .nav a.router-link-active {
  background: #2a241e;
  color: #fff;
}
.sidebar-foot {
  margin-top: auto;
  padding: 12px 10px 0;
  border-top: 1px solid #3a322a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: #cfc4b4;
}
.main { min-width: 0; padding: 28px 28px 48px; }
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.topbar h1 { margin: 0; font-size: 26px; }
.topbar .sub { margin: 6px 0 0; color: var(--ink-soft); font-size: 14px; }
.topbar > .btn { flex: 0 0 auto; white-space: nowrap; }
.toolbar { display: flex; gap: 10px; align-items: center; }
.search {
  min-width: 220px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 10px;
  padding: 9px 12px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.resource-table { overflow-x: auto; }
.resource-table table { min-width: 920px; }
.resource-table th, .resource-table td { white-space: nowrap; }
.resource-table td:nth-child(2) .muted { white-space: normal; min-width: 160px; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: top;
}
th { color: var(--ink-soft); font-weight: 600; background: #faf6ee; }
tr:last-child td { border-bottom: 0; }
.muted { color: var(--ink-soft); }
.ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.off { background: var(--danger-bg); color: var(--danger); }
.badge.dim { background: var(--paper-2); color: var(--ink-soft); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.usage-tags { display: flex; flex-wrap: wrap; gap: 4px; min-width: 120px; }

.empty { padding: 40px 16px; text-align: center; color: var(--ink-soft); }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 24, 20, 0.38);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.modal {
  width: min(920px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--panel);
  border-radius: 18px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 22px;
}
.modal h3 { margin: 0 0 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-2 .span-2 { grid-column: 1 / -1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.history-modal { width: min(1080px, 100%); }
.history-modal table { table-layout: fixed; }
.history-modal th:first-child { width: 190px; }
.history-modal th:nth-child(2), .history-modal th:nth-child(3) { width: 110px; }
.history-modal th:last-child { width: 140px; }
.history-json {
  max-height: 260px;
  overflow: auto;
  margin: 6px 0 0;
  padding: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0 16px; }
.modal-switch { display: flex; gap: 8px; margin: -4px 0 16px; }
.numbered-fields { display: grid; gap: 8px; }
.numbered-field { display: grid; grid-template-columns: 36px 1fr auto; gap: 8px; align-items: center; }
.numbered-field span { color: var(--ink-soft); font-weight: 600; text-align: center; }
.numbered-field input { border: 1px solid var(--line-strong); background: #fff; border-radius: 10px; padding: 8px 10px; }
.text-list, .reply-groups { display: grid; gap: 10px; }
.text-list-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: start; }
.text-list-row > span { padding-top: 10px; color: var(--ink-soft); font-weight: 600; text-align: center; }
.text-list-row textarea { min-height: 46px; border: 1px solid var(--line-strong); background: #fff; border-radius: 10px; padding: 8px 10px; font-family: inherit; }
.reply-key-add { display: flex; gap: 8px; margin-bottom: 10px; }
.reply-key-add input { min-width: 210px; border: 1px solid var(--line-strong); background: #fff; border-radius: 10px; padding: 8px 10px; }
.reply-group { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fffdf8; }
.reply-group-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
details summary { cursor: pointer; color: var(--ink-soft); font-size: 13px; margin-bottom: 10px; }
.redis-grid { display: grid; grid-template-columns: minmax(440px, 1.1fr) minmax(360px, .9fr); gap: 16px; align-items: start; }
.redis-grid > * { min-width: 0; }
.redis-keys { max-width: 100%; overflow-x: auto; }
.redis-keys td:first-child { cursor: pointer; }
.redis-keys tr.selected td { background: var(--accent-soft); }
.redis-value, .redis-editor { padding: 18px; margin-bottom: 16px; }
.redis-trends { margin-bottom: 16px; overflow: hidden; }
.channel-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.channel-metric {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.channel-metric span { display: block; color: var(--ink-soft); font-size: 12px; }
.channel-metric strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
  font-variant-numeric: tabular-nums;
}
.channel-metric small { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 12px; }
.funnel-pipeline {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.funnel-pipe-step {
  flex: 1 1 160px;
  min-width: 140px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.funnel-pipe-step span { display: block; color: var(--ink-soft); font-size: 12px; }
.funnel-pipe-step strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
  font-variant-numeric: tabular-nums;
}
.funnel-pipe-step small { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 12px; }
.funnel-pipe-arrow {
  display: flex;
  align-items: center;
  color: var(--accent);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 13px;
  padding: 0 2px;
}
.funnel-pipe-arrow span::before { content: "→ "; color: var(--ink-soft); font-weight: 400; }
.funnel-table td:last-child { color: var(--accent); }
.channel-day-table th:first-child, .channel-day-table td:first-child { min-width: 120px; }
.channel-link-table td:nth-child(2) { text-align: left; }
.channel-link-table a { color: var(--accent); text-decoration: underline; }
.muted { color: var(--ink-soft); font-size: 12px; }
.danger-text { color: var(--danger); font-size: 12px; margin-top: 4px; white-space: normal; }
.trend-section-head, .redis-raw-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.trend-section-head { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.trend-section-head h3, .redis-raw-head h3 { margin: 0; font-size: 16px; }
.trend-section-head p, .redis-raw-head p { margin: 4px 0 0; color: var(--ink-soft); font-size: 12px; }
.day-range-control { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 12px; }
.trend-controls { display: flex; align-items: center; gap: 10px; }
.day-range-control select, .trend-controls select {
  max-width: 360px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 8px;
  padding: 7px 10px;
}
.trend-table-scroll { max-width: 100%; overflow-x: auto; }
.trend-table-scroll table { width: max-content; min-width: 100%; }
.trend-table-scroll th, .trend-table-scroll td { min-width: 70px; white-space: nowrap; }
.trend-table-scroll th:first-child, .trend-table-scroll td:first-child { min-width: 220px; }
.package-trend-table tbody tr, .device-trend-table tbody tr, .channel-link-table tbody tr, .funnel-table tbody tr { cursor: pointer; }
.package-trend-table tbody tr.selected td, .device-trend-table tbody tr.selected td, .channel-link-table tbody tr.selected td { background: var(--accent-soft); }
.funnel-detail {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 0;
  border-top: 1px solid var(--line);
}
.funnel-detail .trend-table-scroll + .trend-table-scroll { border-left: 1px solid var(--line); }
@media (max-width: 1100px) {
  .funnel-detail { grid-template-columns: 1fr; }
  .funnel-detail .trend-table-scroll + .trend-table-scroll { border-left: 0; border-top: 1px solid var(--line); }
}
.package-trend-table th:not(:first-child), .package-trend-table td:not(:first-child),
.device-trend-table th:not(:first-child), .device-trend-table td:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.uid-chart { padding: 14px 18px 18px; }
.uid-chart svg { display: block; width: 100%; height: 270px; overflow: visible; color: var(--ink-soft); font: 11px sans-serif; }
.package-chart { border-bottom: 1px solid var(--line); }
.chart-grid-line { stroke: var(--line); stroke-width: 1; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; font-size: 12px; color: var(--ink-soft); }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.device-trend-table { border-top: 1px solid var(--line); }
.device-trend-table td.device-id { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.device-trend-table .mini-trend-column, .device-trend-table .mini-trend-cell { min-width: 156px; text-align: center; }
.mini-trend { width: 132px; height: 34px; margin: 0 auto; }
.mini-trend line { stroke: var(--line); stroke-width: 1; }
.mini-trend rect { fill: #3f6b4a; }
.redis-raw-head { margin: 26px 0 12px; }
.redis-data-controls { flex-wrap: wrap; justify-content: flex-end; }
.data-toggle { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-soft); font-size: 13px; white-space: nowrap; }
.data-toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.redis-key-label { border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 9px 10px; overflow-wrap: anywhere; }
.redis-value h3, .redis-editor h3 { margin: 0 0 12px; font-size: 15px; }
.redis-value pre { max-height: 470px; overflow: auto; margin: 0; white-space: pre-wrap; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.uid-comparison-scroll { max-width: 100%; margin-bottom: 14px; }
.uid-comparison { width: 100%; table-layout: fixed; border: 1px solid var(--line); }
.uid-comparison th, .uid-comparison td { padding: 10px 12px; }
.uid-comparison th:first-child { width: 76px; color: var(--ink-soft); }
.uid-comparison thead span, .uid-comparison thead strong { display: block; }
.uid-comparison thead span { margin-bottom: 3px; color: var(--ink-soft); font-size: 11px; font-weight: 500; }
.uid-comparison thead strong { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uid-comparison tbody td { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.more { margin: 12px; }
.ledger-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.ledger-filters input, .ledger-filters select {
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 8px;
  padding: 9px 10px;
}
.filter-date { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); font-size: 12px; }
.ledger-summary {
  display: flex;
  flex-wrap: wrap;
  border-block: 1px solid var(--line);
  margin-bottom: 14px;
}
.ledger-summary section {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 12px 18px;
  border-right: 1px solid var(--line);
  font-size: 13px;
}
.ledger-summary section > strong { font-size: 16px; }
.ledger-summary span { color: var(--ink-soft); white-space: nowrap; }
.ledger-summary b { color: var(--ink); margin-left: 4px; }
.ledger-summary section.ledger-total-cny {
  background: linear-gradient(90deg, rgba(255, 214, 102, 0.18), transparent 60%);
  border-left: 3px solid #f2b100;
  width: 100%;
}
.ledger-summary section.ledger-total-cny > strong { font-size: 17px; }
.ledger-summary section.ledger-total-cny b { font-size: 18px; font-variant-numeric: tabular-nums; }
.amount-income { color: var(--ok) !important; }
.amount-expense { color: var(--danger) !important; }
.amount-cell { white-space: nowrap; font-variant-numeric: tabular-nums; }
.ledger-table { overflow-x: auto; }
.ledger-table table { min-width: 1060px; }
.ledger-note { max-width: 260px; white-space: pre-wrap; overflow-wrap: anywhere; }
.ledger-pager-bar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft); font-size: 13px;
}
.ledger-pager-bar .pager-info b { color: var(--ink); font-variant-numeric: tabular-nums; }
.ledger-pager-bar .pager-controls { display: flex; gap: 8px; align-items: center; }
.ledger-pager-bar .pager-controls select { padding: 4px 8px; }
.ledger-modal { width: min(680px, 100%); }
.entry-type-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }

.alert-summary {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  background: var(--panel);
  margin-bottom: 14px;
}
.alert-summary button {
  min-width: 130px;
  padding: 12px 16px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
}
.alert-summary button.active { background: var(--accent-soft); color: var(--accent-dark); }
.alert-summary strong { font-size: 19px; font-variant-numeric: tabular-nums; }
.alert-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.alert-filters input, .alert-filters select {
  min-width: 150px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 8px;
  padding: 9px 10px;
}
.alert-table { width: 100%; max-width: 100%; overflow-x: auto; }
.alert-table table { min-width: 1080px; }
.alert-message, .alert-source, .alert-time { display: table-cell; }
.alert-message strong, .alert-message span, .alert-message small,
.alert-source strong, .alert-source span, .alert-source small,
.alert-time strong, .alert-time span, .alert-time small {
  display: block;
}
.alert-message { min-width: 260px; max-width: 420px; }
.alert-message span, .alert-source span, .alert-time span { margin-top: 4px; }
.alert-message small, .alert-source small, .alert-time small {
  margin-top: 4px;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}
.badge.severity-critical { background: var(--danger-bg); color: var(--danger); }
.badge.severity-warning { background: #fff0ca; color: #835600; }
.badge.severity-info { background: #e3edf8; color: #315d87; }
.badge.status-open { background: var(--danger-bg); color: var(--danger); }
.badge.status-resolved { background: var(--ok-bg); color: var(--ok); }
.badge.status-ignored { background: var(--paper-2); color: var(--ink-soft); }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  z-index: 30;
}
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 16px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .grid-2 { grid-template-columns: 1fr; }
  .redis-grid { grid-template-columns: 1fr; }
  .trend-section-head, .redis-raw-head { align-items: flex-start; flex-direction: column; }
  .trend-controls, .redis-raw-head .toolbar { width: 100%; }
  .redis-data-controls { justify-content: flex-start; }
  .trend-controls select, .redis-raw-head .search { flex: 1; min-width: 0; }
  .channel-metrics { grid-template-columns: 1fr; }
  .uid-chart svg { height: 220px; }
  .main { padding: 18px 14px 32px; }
  .topbar { align-items: flex-start; flex-wrap: wrap; }
  .topbar > div:first-child { min-width: 0; }
  .ledger-topbar { align-items: flex-start; }
  .ledger-filters > * { flex: 1 1 140px; min-width: 0; }
  .ledger-summary { display: block; }
  .ledger-summary section { flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); }
  .alert-summary button { flex: 1 1 50%; border-bottom: 1px solid var(--line); }
  .alert-filters > * { flex: 1 1 145px; min-width: 0; }
}
