:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232c;
  --border: rgba(230, 237, 243, 0.12);
  --text: #e6edf3;
  --muted: #8b949e;
  --brand: #0fdc78;
  --up: #f87454;
  --down: #2ea88a;
  --warn: #efaa17;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "SF Pro Text", "PingFang SC", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 16px; font-weight: 600; margin: 0; }

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted); transition: background .2s;
}
.dot.live { background: var(--brand); }
.dot.down { background: var(--up); }

.topbar-meta { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.pill {
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  border: 1px solid var(--border);
  cursor: pointer;
  background: transparent;
  color: inherit;
  font-family: inherit;
}
.pill-ok { color: var(--brand); border-color: rgba(15, 220, 120, .4); }
.pill-warn { color: var(--warn); border-color: rgba(239, 170, 23, .4); }
.pill:hover { border-color: var(--muted); }

.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 24px 60px;
  display: grid;
  gap: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px;
}
.panel-head h2 { font-size: 15px; font-weight: 600; margin: 0; }
.panel-actions { display: flex; gap: 8px; align-items: center; }
.sub-title { font-size: 13px; font-weight: 500; color: var(--muted); margin: 18px 0 10px; }

.mini-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 9px;
  font: inherit;
  font-size: 13px;
}

.form-grid { display: flex; gap: 12px; flex-wrap: wrap; }
.form-grid.params { margin-top: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 128px; }
.form-grid label.grow { flex: 3; min-width: 220px; }
.form-grid label > span { font-size: 12px; color: var(--muted); }

input, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  width: 100%;
}
input::placeholder { color: var(--muted); opacity: .7; }
input:focus, select:focus { outline: none; border-color: var(--brand); }

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 13px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary {
  background: var(--brand); border-color: var(--brand); color: #062b18; font-weight: 600;
}
.btn-ghost { background: transparent; }
.btn-danger { color: var(--up); }

.results { margin-top: 12px; display: grid; gap: 6px; max-height: 260px; overflow-y: auto; }
.result-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px;
}
.result-row .name { font-weight: 500; }
.result-row .meta { font-size: 12px; color: var(--muted); }

.watchlist { display: grid; gap: 10px; }
.card-row {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1.5fr 1fr 1.1fr 1.1fr auto;
  gap: 14px;
  align-items: center;
}
.card-row.disabled { opacity: .5; }
.card-row.selected { border-color: var(--brand); }

.symbol-block .name { font-weight: 600; font-size: 15px; }
.symbol-block .src { font-size: 12px; color: var(--muted); margin-top: 2px; }

.price-block .p { font: 600 18px/1.3 "SF Mono", ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
.metric .k { font-size: 12px; color: var(--muted); }
.metric .v { font: 500 13px/1.4 "SF Mono", ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }

.chg-up { color: var(--up); }
.chg-down { color: var(--down); }
.chg-flat { color: var(--muted); }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 500; border: 1px solid var(--border);
}
.badge-armed { color: var(--brand); border-color: rgba(15,220,120,.35); }
.badge-trip { color: var(--up); border-color: rgba(248,116,84,.35); }
.badge-lv2 { color: var(--warn); border-color: rgba(239,170,23,.4); }
.badge-lv3 { color: var(--up); border-color: rgba(248,116,84,.5); font-weight: 600; }

.spark { display: block; width: 100%; height: 34px; }
.spark path.line { fill: none; stroke-width: 1.5; }

.row-actions { display: flex; gap: 6px; }

.chart-wrap { width: 100%; height: 320px; position: relative; }
.chart-canvas { width: 100%; height: 100%; }

.timeline { display: grid; gap: 6px; }
.tl-row {
  display: grid; grid-template-columns: 90px 1fr auto;
  gap: 12px; align-items: center;
  padding: 8px 10px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 12px;
}
.tl-time { color: var(--muted); font-family: "SF Mono", ui-monospace, Menlo, monospace; }
.tl-mark { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.tl-val { font-family: "SF Mono", ui-monospace, Menlo, monospace; }

.alerts { display: grid; gap: 8px; }
.alert-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px;
}
.alert-row .time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.alert-detail { font-size: 12px; color: var(--muted); margin-top: 3px; }
.tag-ok { color: var(--brand); font-size: 12px; }
.tag-fail { color: var(--up); font-size: 12px; }
.alert-row.recovered { opacity: .72; }

.empty { color: var(--muted); text-align: center; padding: 24px 0; font-size: 13px; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card, 12px);
  padding: 20px 22px;
  width: min(460px, 92vw);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { font-size: 15px; font-weight: 600; margin: 0; }

.channel-list { display: grid; gap: 8px; margin-bottom: 14px; }
.channel-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px;
}
.channel-row .ch-name { font-weight: 500; }
.channel-row .ch-state { font-size: 12px; color: var(--muted); margin-top: 2px; }
.switch {
  position: relative; width: 38px; height: 21px; flex-shrink: 0;
  background: var(--surface-muted, #262626); border: 1px solid var(--border);
  border-radius: 999px; cursor: pointer; transition: background .15s;
}
.switch.on { background: var(--brand); border-color: var(--brand); }
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--text); transition: transform .15s;
}
.switch.on::after { transform: translateX(17px); background: #062b18; }
.switch:disabled { opacity: .4; cursor: not-allowed; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 8px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 980px) {
  .card-row { grid-template-columns: 1fr 1fr; }
  .chart-wrap { height: 260px; }
}
