:root {
  color-scheme: dark;
  --bg: #050b14;
  --surface: #0b1524;
  --surface-2: #101e30;
  --line: #20334a;
  --text: #f3f7fb;
  --muted: #8fa4bb;
  --green: #28d7a1;
  --green-soft: rgba(40, 215, 161, .13);
  --orange: #ff9c54;
  --red: #ff647c;
  --blue: #53a5ff;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 85% -5%, rgba(38, 118, 190, .22), transparent 30rem),
    linear-gradient(180deg, #07111f 0%, var(--bg) 72%);
  color: var(--text);
}

button, select { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

.shell {
  width: min(100%, 880px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(26px, env(safe-area-inset-bottom));
}

.topbar {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--green);
  color: #04150f;
  font-weight: 900;
  letter-spacing: -.06em;
}

.brand-copy h1 { margin: 0; font-size: 1.22rem; line-height: 1.2; }
.brand-copy p { margin: 3px 0 0; color: var(--muted); font-size: .88rem; }

.icon-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(16, 30, 48, .72);
  color: var(--text);
  cursor: pointer;
}

.icon-button svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button:active { transform: scale(.96); }

.filters {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(11, 21, 36, .88);
  backdrop-filter: blur(12px);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-self: end;
  min-height: 48px;
  padding: 4px;
  border-radius: 13px;
  background: #07101d;
}

.segment, .periods button {
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.segment.active { background: var(--surface-2); color: var(--text); box-shadow: 0 0 0 1px var(--line); }

.field { display: grid; gap: 7px; }
.field span, .metric-label, .eyebrow { color: var(--muted); font-size: .74rem; font-weight: 800; letter-spacing: .08em; }

select {
  width: 100%;
  min-height: 48px;
  padding: 0 38px 0 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--text);
  outline: 0;
}

select:focus, button:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.metric {
  min-height: 132px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(150deg, rgba(16,30,48,.96), rgba(9,18,31,.96));
}

.metric strong { display: block; margin: 16px 0 9px; font-size: clamp(1.45rem, 4vw, 2rem); letter-spacing: -.04em; }
.metric strong em { color: var(--muted); font-size: .78rem; font-style: normal; letter-spacing: 0; }
.metric small { color: var(--muted); font-size: .8rem; }
.metric small.good { color: var(--green); }
.status-dot { display: inline-block; width: 10px; height: 10px; margin-right: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px var(--green-soft); }

.chart-card {
  margin-top: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(150deg, rgba(12,24,40,.98), rgba(7,16,28,.98));
  box-shadow: 0 24px 60px rgba(0, 0, 0, .24);
}

.chart-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.chart-heading h2 { margin: 5px 0 0; font-size: 1.2rem; }
.live-indicator { color: var(--muted); font-size: .76rem; white-space: nowrap; }
.live-indicator i { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--green); }

.periods {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 18px 0 14px;
  padding: 4px;
  border-radius: 13px;
  background: #07101d;
}

.periods button { min-height: 36px; }
.periods button.active { background: var(--green); color: #04150f; }

.legend { display: flex; gap: 18px; margin-bottom: 10px; color: var(--muted); font-size: .78rem; }
.line-key { display: inline-block; width: 18px; height: 3px; margin: 0 6px 2px 0; border-radius: 4px; }
.line-key.rx { background: var(--green); }
.line-key.tx { background: var(--orange); }

.chart-wrap { position: relative; width: 100%; height: 260px; }
#signalChart { width: 100%; height: 100%; touch-action: none; }
.tooltip { position: absolute; z-index: 3; min-width: 130px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #07101df2; color: var(--text); font-size: .76rem; line-height: 1.55; pointer-events: none; box-shadow: 0 10px 30px rgba(0,0,0,.35); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.stat { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 12px; background: rgba(16,30,48,.68); color: var(--muted); font-size: .78rem; }
.stat strong { color: var(--text); font-weight: 700; }

.interface-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 12px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(11,21,36,.88);
}

.interface-card h3 { margin: 6px 0 4px; font-size: 1rem; }
.interface-card p { margin: 0; color: var(--muted); font-size: .8rem; }
.pill { padding: 7px 10px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: .72rem; font-weight: 800; }
.data-note { margin: 15px 0 0; color: #647b94; text-align: center; font-size: .72rem; }

@media (max-width: 680px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .segmented { grid-column: 1 / -1; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .metric-status { grid-column: 1 / -1; min-height: 104px; }
  .metric-status strong { margin: 10px 0 6px; }
}

@media (max-width: 430px) {
  .shell { padding-inline: 12px; }
  .filters { grid-template-columns: 1fr; }
  .segmented { grid-column: auto; }
  .summary-grid { gap: 9px; }
  .metric { min-height: 120px; padding: 14px; }
  .metric strong { font-size: 1.34rem; }
  .chart-card { padding: 15px 12px; }
  .chart-wrap { height: 230px; }
  .stats { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: no-preference) {
  .icon-button, .segment, .periods button { transition: transform .16s ease, background .16s ease, color .16s ease; }
}
