/* =====================================================================
   Silence Detector – design system
   Colours, fonts and theme come from /theme.css (Settings → Appearance).
   The values below are only fallbacks in case it fails to load.
   ===================================================================== */
:root {
  --bg: #0b0f14; --surface: #121820; --surface-2: #1a222c; --border: #26303c;
  --text: #e6edf3; --muted: #8b98a8; --idle: #8b98a8; --meter-bg: #26303c; --shadow: none;
  --primary: #3b82f6; --primary-hover: #60a5fa; --on-primary: #fff; --primary-bg: rgba(59,130,246,.14);
  --ok: #22c55e; --silent: #ef4444; --on-silent: #fff; --offline: #f97316;
  --ok-bg: rgba(34,197,94,.16); --silent-bg: rgba(239,68,68,.16); --offline-bg: rgba(249,115,22,.16); --idle-bg: rgba(139,152,168,.16);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;

  /* layout + shape tokens */
  --page-w: 1320px;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%238b98a8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --gutter: 24px;
  --radius: 12px;
  --radius-sm: 8px;
  --control-h: 38px;
  --control-h-sm: 32px;
  --row-hover: color-mix(in srgb, var(--text) 4%, transparent);
  --focus: 0 0 0 3px color-mix(in srgb, var(--primary) 35%, transparent);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; }
p { margin: 0; }
code { font-family: var(--mono); font-size: 0.85em; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.wrap { overflow-wrap: anywhere; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 14px;
  margin: 0;
  font: inherit;
  font-size: 0.933rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-sm { height: var(--control-h-sm); padding: 0 10px; font-size: 0.867rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--silent); }
.btn-danger:hover { background: var(--silent-bg); border-color: color-mix(in srgb, var(--silent) 40%, var(--border)); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; font-size: 0.933rem; font-weight: 500; cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ---------- form controls ---------- */
input, select, textarea {
  display: block;
  width: 100%;
  height: var(--control-h);
  margin: 0;
  padding: 0 12px;
  font: inherit;
  font-size: 0.933rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { height: auto; min-height: 72px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
select {
  appearance: none;
  padding-right: 34px;
  cursor: pointer;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 12px center;
}
select.btn { width: auto; padding-right: 30px; background: var(--surface) var(--chevron) no-repeat right 10px center; text-align: left; }
select.btn:hover { background-color: var(--surface-2); }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--primary); cursor: pointer; flex: none; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0 0 16px; }
.field-label { font-size: 0.867rem; font-weight: 600; color: var(--text); }
.help { font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.field-grid { display: grid; gap: 16px; align-items: start; margin-bottom: 16px; }
.field-grid > .field { margin: 0; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-url { grid-template-columns: minmax(0, 1fr) 200px; }
.checks { display: flex; flex-wrap: wrap; gap: 10px 24px; margin-bottom: 16px; }
label.check { display: inline-flex; align-items: center; gap: 8px; font-size: 0.933rem; font-weight: 500; cursor: pointer; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 200px; width: auto; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.sub-title { font-size: 0.733rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 12px; }

.alert { margin-top: 16px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 0.933rem; }
.alert.error, .alert-error { background: var(--silent-bg); color: var(--silent); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }

/* ---------- app shell ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner,
.banner-inner,
.container { max-width: var(--page-w); margin: 0 auto; padding-left: var(--gutter); padding-right: var(--gutter); }
.topbar-inner { display: flex; align-items: center; gap: 28px; height: 60px; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-link { color: inherit; text-decoration: none; border-radius: var(--radius-sm); flex: none; }
.brand-link:hover .brand-name { color: var(--primary); }
.brand-link:focus-visible { outline: none; box-shadow: var(--focus); }
.brand-name { font-size: 1rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color 0.15s; }
.brand-logo { height: 28px; width: auto; max-width: 160px; object-fit: contain; flex: none; }

.tabs { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 7px 12px;
  font-size: 0.933rem;
  font-weight: 550;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--primary); background: var(--primary-bg); }
.user-menu { display: flex; align-items: center; gap: 8px; flex: none; }
.user-email { font-size: 0.867rem; color: var(--muted); }

.banner { background: var(--offline-bg); border-bottom: 1px solid color-mix(in srgb, var(--offline) 30%, var(--border)); color: var(--offline); }
.banner-inner { padding-top: 10px; padding-bottom: 10px; font-size: 0.867rem; }

.container { padding-top: 32px; padding-bottom: 64px; }

/* ---------- page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
.page-desc { margin-top: 4px; font-size: 0.933rem; color: var(--muted); }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.handle-demo { font-weight: 700; letter-spacing: -2px; margin-right: 3px; }

/* ---------- panels & tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel-toolbar select { width: auto; min-width: 160px; }
.panel-toolbar input { flex: 1; min-width: 220px; width: auto; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.933rem; }
.table th {
  height: 40px;
  padding: 0 16px;
  text-align: left;
  font-size: 0.733rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--row-hover); }
.col-time { width: 200px; white-space: nowrap; }
.col-stream { width: 200px; }
.col-type { width: 130px; }
.col-actions { width: 110px; }
.ev { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; font-size: 0.733rem; font-weight: 650; text-transform: capitalize; white-space: nowrap; border-radius: 6px; background: var(--idle-bg); color: var(--idle); }
.ev-silence, .ev-email_error { background: var(--silent-bg); color: var(--silent); }
.ev-recovered, .ev-online, .ev-email { background: var(--ok-bg); color: var(--ok); }
.ev-offline, .ev-muted { background: var(--offline-bg); color: var(--offline); }
.ev-config, .ev-auth { background: var(--primary-bg); color: var(--primary); }

.empty { text-align: center; padding: 56px 24px; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); }
.empty h3 { color: var(--text); font-size: 1.067rem; margin-bottom: 6px; }

/* ---------- segmented control ---------- */
.segmented { display: inline-flex; height: var(--control-h); padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.seg { padding: 0 12px; margin: 0; font: inherit; font-size: 0.867rem; font-weight: 600; color: var(--muted); background: none; border: 0; border-radius: 6px; cursor: pointer; }
.seg:hover { color: var(--text); }
.seg[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }

/* ---------- status, badges, meter ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  font-size: 0.8rem;
  font-weight: 650;
  white-space: nowrap;
  border-radius: 999px;
  background: var(--idle-bg);
  color: var(--idle);
  flex: none;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.offline { background: var(--offline-bg); color: var(--offline); }
.pill.silent { background: var(--silent); color: var(--on-silent); }

/* Animated status dots: a ripple ring that grows out of the dot and fades */
@keyframes dot-ping {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--dot) 75%, transparent); }
  80%, 100% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--dot) 0%, transparent); }
}
@keyframes dot-blink { 50% { opacity: 0.3; } }
.pill.ok { --dot: var(--ok); }
.pill.offline { --dot: var(--offline); }
.pill.silent { --dot: var(--on-silent); }
.pill.ok::before { animation: dot-ping 2.4s ease-out infinite; }
.pill.offline::before { animation: dot-ping 1.6s ease-out infinite; }
.pill.silent::before { animation: dot-ping 0.9s ease-out infinite; }
.pill.connecting::before { animation: dot-blink 1s ease-in-out infinite; }

.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 6px; font-size: 0.7rem; font-weight: 650; letter-spacing: 0.04em; white-space: nowrap; border-radius: 5px; background: var(--idle-bg); color: var(--muted); }
.muted-badge { background: var(--offline-bg); color: var(--offline); letter-spacing: 0; }

.meter { position: relative; height: 6px; background: var(--meter-bg); border-radius: 3px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--ok); border-radius: 3px; transition: width 0.35s ease; }
.meter-fill.below { background: var(--silent); }
.meter-threshold { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); opacity: 0.45; }
.level-row { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.level { font-family: var(--mono); font-size: 0.867rem; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-label { font-size: 0.733rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat-value { font-size: 0.933rem; font-weight: 600; font-variant-numeric: tabular-nums; }
[data-status="silent"] .stat-state .stat-value { color: var(--silent); }
[data-status="offline"] .stat-state .stat-value { color: var(--offline); }

/* ---------- overview summary ---------- */
.ov-summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 32px; }
.ov-stat { display: flex; flex-direction: column; gap: 6px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.ov-label { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.ov-num { font-size: 1.867rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; }
.ov-stat.total .dot { background: var(--primary); }
.ov-stat.ok .dot { background: var(--ok); }
.ov-stat.silent .dot { background: var(--silent); }
.ov-stat.offline .dot { background: var(--offline); }
.ov-stat.silent.alerting { border-color: var(--silent); background: color-mix(in srgb, var(--silent) 8%, var(--surface)); }
.ov-stat.silent.alerting .ov-num { color: var(--silent); }
.ov-stat.offline.alerting { border-color: color-mix(in srgb, var(--offline) 60%, var(--border)); }
.ov-stat.offline.alerting .ov-num { color: var(--offline); }
.ov-stat.silent.alerting .dot { --dot: var(--silent); animation: dot-ping 0.9s ease-out infinite; }
.ov-stat.offline.alerting .dot { --dot: var(--offline); animation: dot-ping 1.6s ease-out infinite; }
@media (prefers-reduced-motion: reduce) {
  .pill::before, .ov-stat .dot { animation: none !important; }
}

/* ---------- stream groups (categories) ---------- */
.stream-group + .stream-group { margin-top: 32px; }
.group-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.group-title { font-size: 1.067rem; font-weight: 650; }
.group-count { font-size: 0.867rem; color: var(--muted); }
.group-count.has-problems { color: var(--silent); font-weight: 600; }

/* ---------- streams: card view ---------- */
.stream-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); }
.stream-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color 0.2s, background-color 0.2s;
}
.stream-card[data-status="silent"] { border-color: var(--silent); background: color-mix(in srgb, var(--silent) 7%, var(--surface)); }
.stream-card[data-status="offline"] { border-color: color-mix(in srgb, var(--offline) 45%, var(--border)); }
.stream-card[data-status="disabled"] { opacity: 0.6; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card-title { min-width: 0; }
.stream-name { font-size: 1rem; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; margin-bottom: 6px; }
.stream-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.stream-url { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stream-error { font-size: 0.8rem; color: var(--offline); background: var(--offline-bg); padding: 8px 10px; border-radius: var(--radius-sm); overflow-wrap: anywhere; }
.card-top-right { display: flex; align-items: center; gap: 4px; flex: none; margin: -4px -8px 0 0; }

/* ---------- streams + overview: list (table) view ---------- */
.list-head { display: none; }
.list-view .stream-grid { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-view .list-head,
.list-view .stream-card {
  display: grid;
  grid-template-columns: 104px minmax(0, 2fr) minmax(0, 1.3fr) minmax(0, 1fr) minmax(150px, 0.9fr) 40px;
  column-gap: 20px;
  padding-left: 16px;
  padding-right: 16px;
}
.list-view .list-head {
  align-items: center;
  height: 40px;
  font-size: 0.733rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  white-space: nowrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}
.list-view .stream-card {
  grid-template-areas:
    "pill name level state mon actions"
    "pill url  level state mon actions"
    "err  err  err   err   err err";
  align-items: center;
  row-gap: 2px;
  padding-top: 12px;
  padding-bottom: 12px;
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}
.list-view .stream-card:hover { background: var(--row-hover); }
.list-view .stream-card[data-status="silent"] { background: color-mix(in srgb, var(--silent) 8%, var(--surface)); box-shadow: inset 3px 0 0 var(--silent); }
.list-view .stream-card[data-status="offline"] { box-shadow: inset 3px 0 0 var(--offline); }
.list-view .card-top,
.list-view .card-top-right,
.list-view .stats { display: contents; }
.list-view .menu-btn { grid-area: actions; grid-row: 1 / 3; justify-self: end; }
.list-view .pill { grid-area: pill; justify-self: start; }
.list-view .card-title { grid-area: name; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.list-view .stream-name { font-size: 0.933rem; margin: 0; }
.list-view .stream-url { grid-area: url; }
.list-view .level-row { grid-area: level; grid-row: 1 / 3; }
.list-view .stat-state { grid-area: state; grid-row: 1 / 3; }
.list-view .stat-uptime { grid-area: mon; grid-row: 1 / 3; }
.list-view .stat-uptime .stat-label { display: none; }
.list-view .stat-state .stat-label { font-size: 0.8rem; font-weight: 500; text-transform: none; letter-spacing: 0; }
.list-view .stat-state.is-healthy .stat-label { display: none; } /* the column heading already says it */
.list-view .stream-error { grid-area: err; margin-top: 8px; }

/* Overview: read-only list, no actions column */
.ov-list .list-head,
.ov-list .stream-card { grid-template-columns: 104px minmax(0, 2fr) minmax(0, 1.6fr) minmax(0, 1fr) minmax(150px, 0.8fr); }
.ov-list .stream-card { grid-template-areas: "pill name level state mon" "err err err err err"; padding-top: 14px; padding-bottom: 14px; }
.ov-list .level-row { grid-area: level; }
.ov-list .stat-state { grid-area: state; }
.ov-list .stat-uptime { grid-area: mon; }

/* ---------- arrange mode ---------- */
.arrange-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; }
.arrange-head { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.arrange-title { flex: 1; min-width: 0; font-weight: 650; overflow-wrap: anywhere; }
.arrange-uncat .arrange-title { color: var(--muted); padding-left: 4px; }
.arrange-head-actions { display: flex; gap: 6px; }
.arrange-list { display: flex; flex-direction: column; gap: 6px; min-height: 56px; padding: 10px; }
.arrange-list:empty::after { content: "Drag streams here"; padding: 12px; text-align: center; font-size: 0.867rem; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius-sm); }
.arrange-item { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 12px 6px 6px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.arrange-name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.handle { display: inline-grid; place-items: center; width: 28px; height: 28px; font-weight: 700; letter-spacing: -2px; color: var(--muted); border-radius: 6px; cursor: grab; user-select: none; touch-action: none; }
.handle:hover { background: var(--surface-2); color: var(--text); }
.handle:active { cursor: grabbing; }
.drag-ghost { opacity: 0.4; }

/* ---------- settings ---------- */
.settings-section { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 32px; padding: 28px 0; border-top: 1px solid var(--border); }
.settings-section:first-child { padding-top: 0; border-top: 0; }
.settings-intro h2 { font-size: 1.067rem; margin-bottom: 6px; }
.settings-intro p { font-size: 0.867rem; color: var(--muted); }
.settings-intro .btn { margin-top: 14px; }
.settings-body { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.settings-body > :last-child { margin-bottom: 0; }
.form-footer { display: flex; justify-content: flex-end; padding-top: 24px; border-top: 1px solid var(--border); }

.color-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.color-label { font-size: 0.867rem; font-weight: 600; margin-bottom: 6px; }
.color-inputs { display: flex; gap: 8px; align-items: center; }
input.color-square { width: var(--control-h); height: var(--control-h); flex: none; padding: 3px; background: var(--bg); cursor: pointer; }
input.color-square::-webkit-color-swatch-wrapper { padding: 0; }
input.color-square::-webkit-color-swatch { border: none; border-radius: 5px; }
input.color-square::-moz-color-swatch { border: none; border-radius: 5px; }
input.hex-input { flex: 1; min-width: 0; font-family: var(--mono); text-transform: lowercase; }
input.hex-input.invalid { border-color: var(--silent); box-shadow: 0 0 0 3px var(--silent-bg); }

.logo-upload { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.logo-preview { display: grid; place-items: center; width: 160px; height: 80px; flex: none; padding: 10px; font-size: 0.8rem; color: var(--muted); text-align: center; background: var(--bg); border: 1px dashed var(--border); border-radius: var(--radius-sm); }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-actions { flex: 1; min-width: 220px; }
.logo-actions .help { margin-top: 8px; }

/* ---------- dialog ---------- */
dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}
dialog::backdrop { background: rgba(5, 8, 12, 0.6); backdrop-filter: blur(2px); }
.dialog-form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dialog-head { padding: 20px 24px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: 1.133rem; }
.dialog-body { padding: 20px 24px; overflow-y: auto; }
.dialog-body .sub-title { margin-top: 8px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface-2); }
.dialog-foot .dialog-delete { margin-right: auto; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  font-size: 0.933rem;
  font-weight: 600;
  color: var(--bg);
  background: var(--text);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.toast.error { background: var(--silent); color: var(--on-silent); }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; padding: 36px 32px 32px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.brand-lg { justify-content: center; flex-direction: column; gap: 14px; margin-bottom: 24px; text-align: center; }
.brand-lg .brand-logo { height: 48px; max-width: 220px; }
.brand-lg .brand-name { font-size: 1.4rem; white-space: normal; }
.login-intro { color: var(--muted); font-size: 0.933rem; text-align: center; margin-bottom: 20px; }
.code-input { height: 52px; font-family: var(--mono); font-size: 1.6rem; letter-spacing: 0.4em; text-align: center; }
.row-between { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 1180px) {
  /* list rows become two-line rows; actions underneath */
  .list-view .list-head { display: none; }
  .list-view .stream-grid { border-radius: var(--radius); }
  .list-view .stream-card:first-child { border-top: 0; }
  .list-view .stream-card {
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr) auto auto;
    grid-template-areas:
      "name  name  name  pill actions"
      "url   url   url   url  url"
      "level state mon   mon  mon"
      "err   err   err   err  err";
    row-gap: 10px;
    padding-top: 14px;
    padding-bottom: 14px;
  }
  .list-view .pill { justify-self: end; }
  .list-view .level-row, .list-view .stat-state, .list-view .stat-uptime, .list-view .menu-btn { grid-row: auto; }
  .list-view .stat-uptime .stat-label,
  .list-view .stat-state.is-healthy .stat-label { display: block; }
  .list-view .stat-state .stat-label { font-size: 0.733rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
  .ov-list .stream-card {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "name  name  pill"
      "level state mon"
      "err   err   err";
  }
}

@media (max-width: 960px) {
  .settings-section { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .color-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
  .user-email { display: none; }
}

@media (max-width: 900px) {
  .topbar-inner { flex-wrap: wrap; height: auto; gap: 8px 12px; padding-top: 10px; padding-bottom: 6px; }
  .brand-link { flex: 1; min-width: 0; }
  .tabs { order: 3; flex: 1 0 100%; }
  .tab { padding: 7px 8px; font-size: 0.867rem; }
}

@media (max-width: 760px) {
  :root { --gutter: 16px; }
  .container { padding-top: 24px; }
  .page-head { align-items: flex-start; }
  .page-head h1 { font-size: 1.4rem; }
  .cols-2, .cols-3, .cols-url { grid-template-columns: minmax(0, 1fr); }
  .settings-body { padding: 18px; }
}

@media (max-width: 640px) {
  .tabs { justify-content: space-between; }
  .ov-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 24px; }
  .ov-stat.total { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
  .ov-stat { padding: 12px; gap: 4px; }
  .ov-num { font-size: 1.4rem; }
  .ov-label { font-size: 0.733rem; gap: 6px; }
  .list-view .stream-card { display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
  .list-view .card-top, .list-view .card-top-right { display: flex; }
  .list-view .card-title { display: block; }
  .list-view .stream-name { margin-bottom: 6px; }
  .list-view .stats { display: grid; }
  .list-view .stats > .stat { grid-area: auto; }
  .page-actions { width: 100%; }
  .page-actions .btn-primary { margin-left: auto; }
  .color-fields { grid-template-columns: minmax(0, 1fr); }
  .dialog-head, .dialog-body { padding-left: 18px; padding-right: 18px; }
  .dialog-foot { padding: 12px 18px; }
}
.list-head > span { overflow: hidden; text-overflow: ellipsis; }

/* ---------- ⋯ action menu ---------- */
.btn-icon { width: var(--control-h-sm); height: var(--control-h-sm); padding: 0; font-size: 1.25rem; line-height: 1; color: var(--muted); background: transparent; border-color: transparent; }
.btn-icon:hover, .btn-icon[aria-expanded="true"] { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.menu {
  position: fixed;
  z-index: 60;
  min-width: 210px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  height: 34px;
  padding: 0 10px;
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item.danger { color: var(--silent); }
.menu-item.danger:hover, .menu-item.danger:focus-visible { background: var(--silent-bg); }
.menu-sep { height: 1px; margin: 6px 0; background: var(--border); }
.menu-label { padding: 6px 10px 4px; font-size: 0.733rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.menu-btn svg { display: block; transition: transform 0.3s ease; }
.menu-btn:hover svg, .menu-btn[aria-expanded="true"] svg { transform: rotate(45deg); }
@media (prefers-reduced-motion: reduce) { .menu-btn svg { transition: none; } }
.seg-icon { display: inline-grid; place-items: center; width: 36px; padding: 0; }
.seg-icon svg { display: block; }

/* ---------- stream uptime ---------- */
.stat-sub { font-size: 0.8rem; color: var(--muted); }
.stat-sub.sub-alert { color: var(--silent); font-weight: 600; }
.stat-value.up-warn { color: var(--offline); }
.stat-value.up-bad { color: var(--silent); }

/* ---------- tables that stack on small screens ---------- */
@media (max-width: 900px) {
  .stack-md thead { display: none; }
  .stack-md tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "time type" "stream stream" "details details";
    gap: 2px 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
  }
  .stack-md tbody tr:last-child { border-bottom: 0; }
  .stack-md td { display: block; padding: 0; border: 0; }
  .stack-md td:nth-child(1) { grid-area: time; font-size: 0.8rem; color: var(--muted); }
  .stack-md td:nth-child(2) { grid-area: stream; font-weight: 600; }
  .stack-md td:nth-child(3) { grid-area: type; justify-self: end; }
  .stack-md td:nth-child(4) { grid-area: details; }
  .stack-md td[colspan] { grid-column: 1 / -1; text-align: center; }
}
@media (max-width: 640px) {
  .stack-sm thead { display: none; }
  .stack-sm tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "email action" "added added" "last last";
    gap: 2px 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
  }
  .stack-sm tbody tr:last-child { border-bottom: 0; }
  .stack-sm td { display: block; padding: 0; border: 0; }
  .stack-sm td:nth-child(1) { grid-area: email; font-weight: 600; overflow-wrap: anywhere; }
  .stack-sm td:nth-child(2) { grid-area: added; }
  .stack-sm td:nth-child(3) { grid-area: last; }
  .stack-sm td:nth-child(4) { grid-area: action; align-self: center; }
  .stack-sm td[data-label] { font-size: 0.8rem; color: var(--muted); }
  .stack-sm td[data-label]::before { content: attr(data-label) ": "; }
  .panel-toolbar select { flex: 1 1 calc(50% - 4px); min-width: 0; }
  #events-refresh { flex: 1 1 100%; }
}
