:root {
  color-scheme: dark;
  --page: #111412;
  --surface: #181c19;
  --surface-raised: #202521;
  --border: #303631;
  --border-strong: #454d46;
  --text: #f3f5f2;
  --muted: #9ba49c;
  --subtle: #6f7870;
  --green: #72d49b;
  --green-dark: #183626;
  --amber: #e9bd67;
  --red: #ef857f;
  --blue: #81b4dd;
  --radius: 6px;
  --content: 1500px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--text);
}

button, input { font: inherit; }
button { color: inherit; }

.app-header {
  min-height: 78px;
  padding: 16px clamp(18px, 3vw, 44px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand-block, .header-actions, .connection, .panel-heading, .active-primary,
.active-meta, footer { display: flex; align-items: center; }

.brand-block { gap: 12px; }
.brand-block h1 { margin: 0; font-size: 19px; line-height: 1.2; letter-spacing: 0; }
.brand-block p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.brand-mark {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 3px;
  padding: 8px;
  background: var(--surface-raised);
}

.brand-mark span { width: 4px; background: var(--green); border-radius: 1px; }
.brand-mark span:nth-child(1) { height: 8px; }
.brand-mark span:nth-child(2) { height: 16px; }
.brand-mark span:nth-child(3) { height: 12px; background: var(--amber); }

.header-actions { gap: 12px; }
.connection { gap: 8px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.connection.is-online .status-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(114, 212, 155, .12); }
.connection.is-offline .status-dot { background: var(--red); }

.command-button {
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-raised);
  cursor: pointer;
}
.command-button:hover { border-color: var(--green); }
.command-button:disabled { opacity: .55; cursor: wait; }

.tabs {
  padding: 0 clamp(18px, 3vw, 44px);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 28px;
  overflow-x: auto;
}

.tab {
  height: 49px;
  padding: 0;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 650;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--green); border-bottom-color: var(--green); }

main { width: min(100%, var(--content)); margin: 0 auto; padding: 22px clamp(18px, 3vw, 44px) 48px; }

.control-bar {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.period-control {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(78px, 1fr));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
}
.period-control button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-right: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.period-control button:last-child { border-right: 0; }
.period-control button.is-active { color: #08130d; background: var(--green); font-weight: 750; }

.search-control { width: min(330px, 42vw); position: relative; }
.search-control span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.search-control input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}
.search-control input:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(114, 212, 155, .1); }
.search-control input::placeholder { color: var(--subtle); }

.error-banner {
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid rgba(239, 133, 127, .45);
  border-radius: var(--radius);
  background: rgba(239, 133, 127, .08);
  color: #ffc0bb;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.view { display: none; }
.view.is-active { display: block; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
}
.metric {
  min-width: 0;
  min-height: 110px;
  padding: 19px 20px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.metric:last-child { border-right: 0; }
.metric-label { display: block; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.metric-value { display: block; margin-top: 11px; font-size: clamp(22px, 2.5vw, 32px); line-height: 1; font-weight: 720; overflow-wrap: anywhere; }
.metric-note { display: block; margin-top: 8px; color: var(--subtle); font-size: 11px; }
.metric:first-child .metric-value { color: var(--green); }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, .8fr); gap: 18px; margin-bottom: 18px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-heading { justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.panel-heading h2 { margin: 3px 0 0; font-size: 16px; line-height: 1.25; letter-spacing: 0; }
.panel-heading strong { color: var(--green); font-size: 14px; }
.eyebrow { margin: 0; color: var(--subtle); font-size: 10px; font-weight: 750; text-transform: uppercase; }
.count-label { color: var(--muted); font-size: 12px; white-space: nowrap; }

.trend {
  height: 278px;
  padding: 22px 20px 16px;
  display: flex;
  align-items: stretch;
  gap: clamp(3px, .65vw, 10px);
  overflow: hidden;
}
.trend-column { flex: 1 1 0; min-width: 0; display: grid; grid-template-rows: 1fr 25px; gap: 8px; }
.trend-track { height: 100%; display: flex; align-items: end; background: #141714; border-bottom: 1px solid var(--border); }
.trend-bar { width: 100%; min-height: 2px; background: var(--green); border-top: 2px solid #a4ebbf; }
.trend-column:nth-child(3n) .trend-bar { background: var(--blue); border-color: #add6f5; }
.trend-label { color: var(--subtle); font-size: 9px; text-align: center; white-space: nowrap; overflow: hidden; }

.leader-list { padding: 7px 20px 14px; }
.leader-row { padding: 13px 0 10px; border-bottom: 1px solid var(--border); }
.leader-row:last-child { border-bottom: 0; }
.leader-copy { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 12px; }
.leader-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-copy strong { flex: 0 0 auto; }
.leader-track { height: 4px; background: #2b302c; }
.leader-fill { height: 100%; background: var(--amber); }

.active-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.active-session { min-width: 0; padding: 18px 20px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.active-session:nth-child(3n) { border-right: 0; }
.active-primary { justify-content: space-between; gap: 10px; }
.active-channel { min-width: 0; }
.active-channel strong, .active-channel span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.active-channel strong { font-size: 14px; }
.active-channel span { margin-top: 5px; color: var(--muted); font-size: 12px; }
.live-pill { flex: 0 0 auto; padding: 4px 7px; border-radius: 3px; background: var(--green-dark); color: var(--green); font-size: 9px; font-weight: 800; }
.active-meta { margin-top: 16px; justify-content: space-between; gap: 10px; color: var(--subtle); font-size: 11px; }

.empty-state { min-height: 150px; padding: 36px 20px; display: grid; place-items: center; color: var(--muted); text-align: center; font-size: 13px; }

.table-panel { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th { height: 42px; padding: 0 16px; text-align: left; border-bottom: 1px solid var(--border); background: #151815; }
th button { padding: 0; border: 0; background: transparent; color: var(--subtle); cursor: pointer; font-size: 10px; font-weight: 750; text-transform: uppercase; }
th button:hover, th button.is-sorted { color: var(--green); }
td { height: 58px; padding: 9px 16px; border-bottom: 1px solid var(--border); color: #d7dcd8; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, .018); }
.cell-primary { display: block; color: var(--text); font-weight: 650; }
.cell-secondary { display: block; margin-top: 4px; color: var(--subtle); font-size: 10px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.duration-cell { font-weight: 700; }
.active-text { color: var(--green); }
.rank-bar { display: flex; align-items: center; gap: 12px; min-width: 180px; }
.rank-track { width: 90px; height: 4px; background: #2b302c; }
.rank-fill { height: 100%; background: var(--blue); }
.format-tag { display: inline-block; min-width: 44px; padding: 3px 5px; border: 1px solid var(--border-strong); border-radius: 3px; color: var(--muted); text-align: center; font-size: 9px; font-weight: 750; }

footer {
  justify-content: space-between;
  gap: 20px;
  min-height: 52px;
  padding: 0 clamp(18px, 3vw, 44px);
  border-top: 1px solid var(--border);
  color: var(--subtle);
  font-size: 10px;
}

@media (max-width: 980px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .metric:nth-child(3) { border-right: 0; }
  .metric:nth-child(-n+3) { border-bottom: 1px solid var(--border); }
  .metric:nth-child(5) { border-right: 0; }
  .overview-grid { grid-template-columns: 1fr; }
  .active-list { grid-template-columns: repeat(2, 1fr); }
  .active-session:nth-child(3n) { border-right: 1px solid var(--border); }
  .active-session:nth-child(2n) { border-right: 0; }
}

@media (max-width: 680px) {
  .app-header { align-items: flex-start; }
  .connection { display: none; }
  .tabs { gap: 24px; }
  main { padding-top: 16px; }
  .control-bar { align-items: stretch; flex-direction: column; }
  .period-control { width: 100%; grid-template-columns: repeat(4, 1fr); }
  .period-control button { padding: 0 5px; font-size: 10px; }
  .search-control { width: 100%; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .metric { min-height: 96px; padding: 16px; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(3) { border-right: 1px solid var(--border); }
  .metric:nth-child(4) { border-right: 0; border-bottom: 1px solid var(--border); }
  .metric:nth-child(5) { grid-column: 1 / -1; border-bottom: 0; }
  .trend { height: 230px; padding-inline: 12px; }
  .trend-label { writing-mode: vertical-rl; text-orientation: mixed; height: 30px; }
  .active-list { grid-template-columns: 1fr; }
  .active-session { border-right: 0 !important; }
  .panel-heading { padding: 16px; }
}
