:root {
  color-scheme: light dark;
  --canvas: #eff3f8;
  --surface: #fff;
  --ink: #14243a;
  --muted: #52647b;
  --line: #dbe4ee;
  --quiet: #f3f6fa;
  --accent: #245ab8;
  --accent-ink: #fff;
  --accent-soft: #e9f0ff;
  --good: #176b50;
  --good-soft: #e4f5ec;
  --warn: #8a500a;
  --warn-soft: #fff2da;
  --bad: #a12739;
  --bad-soft: #ffedf0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --canvas: #101823; --surface: #172231; --ink: #eaf0fb; --muted: #aebbd0;
    --line: #2e4056; --quiet: #202f42; --accent: #92b9ff; --accent-ink: #10203a;
    --accent-soft: #213858; --good: #88e2b9; --good-soft: #17362f;
    --warn: #ffd183; --warn-soft: #3e3121; --bad: #ffadb9; --bad-soft: #492833;
  }
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #101823; --surface: #172231; --ink: #eaf0fb; --muted: #aebbd0;
  --line: #2e4056; --quiet: #202f42; --accent: #92b9ff; --accent-ink: #10203a;
  --accent-soft: #213858; --good: #88e2b9; --good-soft: #17362f;
  --warn: #ffd183; --warn-soft: #3e3121; --bad: #ffadb9; --bad-soft: #492833;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--tg-theme-text-color, var(--ink));
  background: var(--tg-theme-secondary-bg-color, var(--canvas));
  font: 15px/1.45 Inter, system-ui, -apple-system, sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: progress; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, p, figure, dl, dd { margin: 0; }
h1 { font-size: clamp(1.7rem, 4.5vw, 2.3rem); line-height: 1.08; letter-spacing: -.044em; }
h2 { font-size: 1.12rem; line-height: 1.25; letter-spacing: -.02em; }
.shell {
  max-width: 1120px;
  margin: auto;
  padding: max(30px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
}
.page-header, .identity, .tools, .panel-head, .filters { display: flex; align-items: center; }
.page-header { justify-content: space-between; gap: 18px; margin-bottom: 24px; }
.identity { gap: 13px; }
.mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: none;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 15px;
}
.mark svg { width: 29px; }
.domain { margin: 0 0 3px; color: var(--muted); font-size: .81rem; font-weight: 650; }
.tools { flex-wrap: wrap; gap: 8px; }
.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--tg-theme-bg-color, var(--surface));
  color: var(--tg-theme-text-color, var(--ink));
  font-size: .88rem;
  font-weight: 650;
  text-decoration: none;
}
.button svg { width: 18px; height: 18px; flex: none; }
.button.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.button:disabled { color: var(--muted); }
#dashboard { display: grid; gap: 14px; }
.panel {
  min-width: 0;
  padding: 19px 20px;
  background: var(--tg-theme-bg-color, var(--surface));
  border: 1px solid var(--line);
  border-radius: 16px;
}
.panel-head { align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.gate { max-width: 540px; }
.gate p { margin-top: 8px; color: var(--muted); }
.gate button { margin-top: 14px; }
.freshness { margin-top: 4px; color: var(--muted); font-size: .77rem; line-height: 1.3; }
.freshness[data-tone="warn"] { color: var(--warn); }
.freshness[data-tone="bad"] { color: var(--bad); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 52%;
  padding: 5px 9px;
  border-radius: 20px;
  background: var(--quiet);
  color: var(--muted);
  font-size: .76rem;
  font-weight: 650;
}
.chip span { width: 6px; height: 6px; flex: none; border-radius: 50%; background: currentColor; }
.chip[data-tone="good"] { background: var(--good-soft); color: var(--good); }
.chip[data-tone="warn"], .notice { background: var(--warn-soft); color: var(--warn); }
.chip[data-tone="bad"] { background: var(--bad-soft); color: var(--bad); }
.notice { border-radius: 10px; padding: 10px 13px; font-size: .88rem; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
.metric { min-width: 0; padding: 11px 13px; border-radius: 12px; background: var(--quiet); }
.metric dt { color: var(--muted); font-size: .79rem; font-weight: 650; }
.metric dd { margin-top: 3px; font-size: clamp(1.05rem, 3.2vw, 1.65rem); line-height: 1.18; letter-spacing: -.034em; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .metric-note { min-height: 1em; margin-top: 7px; color: var(--muted); font-size: .73rem; font-weight: 500; letter-spacing: normal; }
.meter { display: block; height: 4px; margin-top: 9px; border-radius: 4px; background: var(--line); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--accent); }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 14px; }
.filters { justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.segments {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 1px;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 3px;
  border: 0;
  border-radius: 10px;
  background: var(--quiet);
}
.segments label { position: relative; display: flex; cursor: pointer; }
.segments input, .sr-only, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.segments span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 4px 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 650;
}
.segments input:checked + span { color: var(--tg-theme-text-color, var(--ink)); background: var(--tg-theme-bg-color, var(--surface)); border-color: var(--line); }
.segments input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.chart-scope { color: var(--muted); font-size: .79rem; text-align: right; }
.chart-body { position: relative; display: grid; grid-template-columns: 3.5rem minmax(0, 1fr); height: 134px; margin-top: 17px; }
.chart-scale { display: flex; flex-direction: column; justify-content: space-between; padding-right: 8px; color: var(--muted); font-size: .71rem; font-variant-numeric: tabular-nums; }
#plot { display: block; width: 100%; height: 100%; overflow: visible; cursor: crosshair; }
.chart-grid { fill: none; stroke: var(--line); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-points { stroke-width: 4; }
.chart-guide { fill: none; stroke: var(--muted); stroke-dasharray: 3 3; }
.chart-marker { stroke-width: 6; }
.chart-tooltip {
  position: absolute;
  z-index: 1;
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tg-theme-bg-color, var(--surface));
  box-shadow: 0 2px 8px #0002;
  color: var(--muted);
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.chart-tooltip strong { display: block; color: var(--tg-theme-text-color, var(--ink)); font-size: .94rem; }
.chart-times { display: flex; justify-content: space-between; gap: 7px; margin: 7px 0 0 3.5rem; color: var(--muted); font-size: .71rem; }
.empty { padding: 15px 0 5px; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.chart-empty { display: grid; min-height: 157px; place-items: center; margin-top: 14px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; text-align: center; }
.count { padding: 3px 8px; border-radius: 8px; background: var(--quiet); color: var(--tg-theme-text-color, var(--ink)); font-weight: 700; font-variant-numeric: tabular-nums; }
.alerts { margin: 0; padding: 0; list-style: none; }
.alerts li { padding: 10px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.alerts li:last-child { padding-bottom: 0; }
.alert-name { font-weight: 650; }
.alert-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; color: var(--muted); font-size: .75rem; }
.severity { padding: 2px 6px; border-radius: 5px; color: var(--muted); background: var(--quiet); font-weight: 650; }
.severity[data-tone="bad"] { color: var(--bad); background: var(--bad-soft); }
.severity[data-tone="warn"] { color: var(--warn); background: var(--warn-soft); }
.alert-summary { margin-top: 5px; color: var(--muted); font-size: .85rem; white-space: pre-line; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 5px; text-align: right; }
th:first-child { padding-left: 0; text-align: left; }
th:last-child, td:last-child { padding-right: 0; }
thead th { padding-top: 0; color: var(--muted); font-size: .76rem; font-weight: 650; }
tbody tr { border-top: 1px solid var(--line); }
tbody th { font-size: .87rem; font-weight: 600; }
tbody td { font-size: .96rem; font-weight: 650; }
.footnote { margin-top: 5px; color: var(--muted); font-size: .77rem; }
footer { text-align: right; }
.text-button { min-height: 44px; padding: 6px 4px; border: 0; background: none; color: var(--muted); font-size: .82rem; }
.skip:focus { position: absolute; z-index: 1; margin: 8px; padding: 8px; background: var(--tg-theme-bg-color, var(--surface)); }
@media (max-width: 760px) {
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 540px) {
  .shell { padding: max(16px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .page-header { align-items: flex-start; flex-direction: column; margin-bottom: 13px; gap: 13px; }
  #dashboard, .detail-grid { gap: 9px; }
  .panel { padding: 14px; border-radius: 13px; }
  .panel-head { margin-bottom: 12px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .metric { padding: 8px 10px; }
  .metric dd { font-size: 1.2rem; }
  .segments span { min-height: 40px; }
}
