:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2230;
  --border: #2a3140;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --yellow: #e2c93b;
  --orange: #f0883e;
  --idle: #6e7681;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 9px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}

h1 { font-size: 17px; margin: 0; letter-spacing: 0.3px; }
.sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* Decoders | Encoders page switcher under the title. */
.tabs {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}
.tabs a {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-decoration: none;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.tabs a:hover { border-color: var(--accent); color: var(--text); }
.tabs a.active { background: var(--accent); border-color: transparent; color: #fff; }

.cname { font-size: 14px; font-weight: 600; color: var(--text); margin-top: 2px; }

.conn { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.conn .meta { color: var(--muted); opacity: 0.7; margin-right: 4px; }

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--idle); box-shadow: 0 0 0 0 rgba(0,0,0,0);
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.filters:empty { display: none; }
.filter-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-right: 2px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip .cnt {
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
  font-weight: 700;
}
/* Included: filled with the status color (same palette as the card pills). */
.chip.include { color: #fff; border-color: transparent; }
.chip.include.playing, .chip.include.play { background: var(--ok); }
.chip.include.idle, .chip.include.offline { background: var(--idle); }
.chip.include.paused, .chip.include.buffering { background: var(--warn); color: #1a1a1a; }
.chip.include.error, .chip.include.stopped { background: var(--bad); }
.chip.include.unknown { background: var(--idle); }
.chip.include.streaming, .chip.include.start, .chip.include.starting { background: var(--ok); }
.chip.include.stop, .chip.include.stopping, .chip.include.offline { background: var(--idle); }
/* Excluded: red outline, struck through. */
.chip.exclude {
  border-color: var(--bad);
  color: var(--bad);
  text-decoration: line-through;
  opacity: 0.85;
}
.chip.exclude:hover { color: var(--bad); }

.clearbtn {
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.clearbtn:hover { color: var(--bad); border-color: var(--bad); }

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
  padding: 16px;
  align-content: start;
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 80px 0;
  font-size: 15px;
}

/* Dense venue card: header (name / serial / version), then the event's full
   cue list with a Position marker dropped in at the live playhead. */
.vcard {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.vcard.idle { opacity: 0.72; }

.vhead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.vtitle { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.vname { font-size: 15px; font-weight: 600; }
.vupdated { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.vupdated.stale { color: var(--bad); }
.vupdated.warnnote { color: var(--warn); }
.vmeta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}
.vmeta .vstats { color: var(--text); opacity: 0.85; }
.badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
  background: var(--idle);
  color: #fff;
}
.badge.playing, .badge.play { background: var(--ok); }
.badge.idle { background: var(--idle); }
.badge.paused, .badge.buffering { background: var(--warn); color: #1a1a1a; }
.badge.error, .badge.stopped { background: var(--bad); }
/* Encoder operational states. "stop" is an encoder's normal resting state
   (not streaming), so it reads neutral grey rather than red. */
.badge.streaming, .badge.start, .badge.starting { background: var(--ok); }
.badge.stop, .badge.stopping, .badge.offline { background: var(--idle); }

/* The list owns the columns; the header, cue rows, and the Position marker each
   span them as a `subgrid`, so all rows share one set of tracks and line up down
   the whole card. The numeric columns are `auto` — they size to their widest
   content instead of a fixed width. Zero-width edge tracks plus the column gap
   inset the content 12px on each side while letting row backgrounds/borders run
   full-bleed (the rows span every track, including the edges). */
.cuelist {
  padding: 2px 0 4px;
  display: grid;
  grid-template-columns: 0 minmax(0, 1fr) auto auto 0;
  column-gap: 12px;
}
/* While playing, the list grows a column for the extrapolated time of day
   (past cues -> when breached, future cues -> when they'll fire). */
.cuelist.withtod {
  grid-template-columns: 0 minmax(0, 1fr) auto auto auto 0;
}
.cuehead, .cuerow, .posrow {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  align-items: baseline;
  padding: 4px 0;
  font-size: 13px;
  line-height: 1.3;
}
.cuehead {
  border-bottom: 1px solid var(--border);
  padding-top: 6px;
  padding-bottom: 6px;
  margin-bottom: 2px;
}
.cuehead span {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  color: var(--muted);
  /* Let multi-word headers (e.g. "Projected Time") wrap instead of overflowing. */
  white-space: normal;
}
.cuehead .cuestart, .cuehead .cuetimer, .cuehead .cuetod { text-align: right; }
.cuename {
  grid-column: 2;
  color: var(--muted);
  /* Wrap long cue/venue names onto multiple lines rather than clipping them. */
  overflow-wrap: anywhere;
}
.cuehead .cuename { color: var(--text); }
.cuerow.current .cuename { color: var(--text); font-weight: 600; }
.cuestart {
  grid-column: 3;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}
.cuetimer {
  grid-column: 4;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
  text-align: right;
}
.cuetimer.past { color: var(--muted); }
.cuetimer.future { color: var(--accent); }   /* >2m  — blue */
.cuetimer.t120 { color: var(--yellow); }      /* <=2m — yellow */
.cuetimer.t60 { color: var(--orange); }       /* <=1m — orange */
.cuetimer.t15 { color: var(--bad); }          /* <=15s — red */
.cuetimer.na { color: var(--muted); font-weight: 400; }

/* Extrapolated time of day column (only present while playing). */
.cuetod {
  grid-column: 5;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
/* Time of day escalates in color with proximity, mirroring the countdown. */
.cuetod.past { color: var(--muted); }
.cuetod.future { color: var(--accent); }   /* >2m  — blue */
.cuetod.t120 { color: var(--yellow); }      /* <=2m — yellow */
.cuetod.t60 { color: var(--orange); }       /* <=1m — orange */
.cuetod.t15 { color: var(--bad); }          /* <=15s — red */
.cuetod.na { color: var(--muted); }

/* Position marker — the live playhead between the cues. Its border and label
   take the row's status color (--status-color, set per status below). */
.posrow {
  --status-color: var(--accent);
  align-items: center;
  margin: 3px 0;
  padding-top: 7px;
  padding-bottom: 7px;
  background: var(--panel-2);
  /* 2px so the colored line always lands on a paintable device pixel — a 1px
     line falls on a fractional row at Retina/zoom scaling and rounds away to
     invisible for some cards (those happened to look uncolored). */
  border-top: 2px solid var(--status-color);
  border-bottom: 2px solid var(--status-color);
}
.posrow.playing, .posrow.play { --status-color: var(--ok); }
.posrow.idle, .posrow.offline { --status-color: var(--idle); }
.posrow.paused, .posrow.buffering { --status-color: var(--warn); }
.posrow.error, .posrow.stopped { --status-color: var(--bad); }
/* Grid items stretch by default; keep the pill sized to its text so it isn't
   widened to fill the column (which read as right padding). */
.posrow .badge { grid-column: 2; align-self: center; justify-self: start; }
/* Live position sits in the Position column, aligned with the cue start times
   and styled like them, just in the status color. */
.posval {
  grid-column: 3;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--status-color);
}
/* "Now" time of day at the marker — same status color as the live position. */
.posrow .cuetod { color: var(--status-color); }

/* Encoder card body — a list of label/value stat rows (no playhead/cues). */
.statlist { padding: 4px 0 6px; }
.statrow {
  display: grid;
  grid-template-columns: minmax(0, auto) 1fr;
  align-items: baseline;
  column-gap: 12px;
  padding: 4px 12px;
  font-size: 13px;
  line-height: 1.3;
}
.statlabel {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.statval {
  text-align: right;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.statval.is-empty { color: var(--muted); }

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  background: var(--panel);
}
.foot-left { display: flex; align-items: center; }
footer .sep { opacity: 0.5; margin: 0 6px; }
#poll-select, #sort-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  padding: 2px 6px;
  cursor: pointer;
}
#poll-select:hover, #sort-select:hover { border-color: var(--accent); }

.sortby {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.sortby #sort-select { text-transform: none; letter-spacing: normal; font-size: 12px; }

.banner {
  grid-column: 1 / -1;
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid var(--bad);
  color: var(--text);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 14px;
}
.banner.config { background: rgba(210, 153, 34, 0.12); border-color: var(--warn); }
