/* Señal — broadcast test-card world, operate mode.
   Two grounds, one calibration palette, hairlines, high density. */

:root {
  --bar-y: #ffd400;
  --bar-c: #00c4c4;
  --bar-g: #00b140;
  --bar-m: #d6008a;
  --bar-r: #e10600;
  --bar-b: #2a4cff;
  --bar-w: #ededed;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --row: 30px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d0e;
  --panel: #0f1213;
  --line: #212729;
  --line-soft: #171c1e;
  --ink: #e9ebe6;
  --dim: #8d9691;
  --dim-2: #858e89;
  --sel: #ffffff10;
  --hover: #ffffff08;
  --accent: #ffd400;
  --screen: #050606;
  --grid: #ffffff0d;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f2ec;
  --panel: #fbfaf6;
  --line: #d6d2c6;
  --line-soft: #e6e2d8;
  --ink: #14171a;
  --dim: #5c6462;
  --dim-2: #5f6764;
  --sel: #14171a0e;
  --hover: #14171a06;
  --accent: #7a5f00;
  --screen: #101214;
  --grid: #00000012;
}

* { box-sizing: border-box; }

/* component display rules must never resurrect hidden elements */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr);
  background: var(--bg);
  color: var(--ink);
  font: 400 13px/1.45 var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--bar-y); color: #14171a; }
:root { caret-color: var(--accent); }

* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border: 3px solid var(--bg); border-radius: 0; }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

button, select, label, .row {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- topbar ---------- */

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { display: flex; align-items: center; gap: 9px; }

.brand-mark { display: flex; gap: 2px; }
.brand-mark i { width: 3px; height: 14px; display: block; }
.brand-mark i:nth-child(1) { background: var(--bar-y); }
.brand-mark i:nth-child(2) { background: var(--bar-c); }
.brand-mark i:nth-child(3) { background: var(--bar-g); }
.brand-mark i:nth-child(4) { background: var(--bar-m); }
.brand-mark i:nth-child(5) { background: var(--bar-r); }
.brand-mark i:nth-child(6) { background: var(--bar-b); }
.brand-mark i:nth-child(7) { background: var(--bar-w); }

.brand h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.search { position: relative; justify-self: center; width: min(100%, 760px); }

.search input {
  width: 100%;
  height: 34px;
  padding: 0 44px 0 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}

.search input::placeholder { color: var(--dim-2); }
.search input:focus { border-color: var(--accent); outline: none; }

kbd {
  font: 500 11px/1 var(--mono);
  padding: 3px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 2px;
  color: var(--dim);
  background: var(--panel);
}

.search kbd {
  position: absolute; right: 8px; top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.tools { display: flex; align-items: center; gap: 12px; }

.count {
  font: 500 11px/1 var(--mono);
  color: var(--dim);
  letter-spacing: 0.02em;
  min-width: 74px;
  text-align: right;
}

.icon {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
}
.icon:hover { color: var(--ink); border-color: var(--dim-2); }

/* ---------- split ---------- */

.split {
  display: grid;
  /* --monitor-w is set by the gutter drag; default keeps the original proportion */
  grid-template-columns: minmax(0, 1fr) 7px var(--monitor-w, clamp(340px, 37%, 560px));
  min-height: 0;
}

.catalog {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  /* columns and filters adapt to the catalog's own width (gutter drag), not the viewport */
  container: catalog / inline-size;
}

/* ---------- gutter (resizable split) ---------- */

.gutter {
  position: relative;
  cursor: col-resize;
  touch-action: none;
  background: var(--bg);
  border-left: 1px solid var(--line);
  outline: none;
}

.gutter::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 1px;
  width: 3px;
  height: 36px;
  transform: translateY(-50%);
  border-radius: 2px;
  background: var(--line);
  transition: background 0.15s ease-out;
}

.gutter:hover::after,
.gutter:focus-visible::after,
.gutter[data-dragging]::after { background: var(--accent); }

.gutter:focus-visible { border-left-color: var(--accent); }

body[data-resizing] { cursor: col-resize; user-select: none; }
/* keep the video from swallowing pointer events mid-drag */
body[data-resizing] .screen { pointer-events: none; }

/* ---------- filters ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel);
}

.field { display: grid; gap: 3px; flex: 0 1 220px; min-width: 120px; }

.field span {
  font: 500 11px/1 var(--mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim-2);
}

select {
  width: 100%;
  height: 28px;
  padding: 0 24px 0 8px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background-color: var(--bg);
  color: var(--ink);
  font: 12px/1 var(--sans);
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 13px) 12px, calc(100% - 8px) 12px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

select:hover { border-color: var(--dim-2); }
/* Windows renders the dropdown natively: give options explicit colors */
select option { background-color: var(--panel); color: var(--ink); }

.toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  margin-left: auto;
  font-size: 12px;
  color: var(--dim);
  cursor: pointer;
  user-select: none;
}

.toggle input { accent-color: var(--accent); width: 13px; height: 13px; }
.toggle:hover { color: var(--ink); }

/* ---------- list ---------- */

.listhead {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) 200px;
  gap: 0;
  padding: 6px 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  font: 500 11px/1 var(--mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim-2);
  background: var(--panel);
}

.list {
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  min-height: 0;
  contain: strict;
}

.spacer { width: 1px; }

.rows { position: absolute; inset: 0 0 auto 0; }

.row {
  position: absolute;
  left: 0; right: 0;
  height: var(--row);
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) 200px;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--line-soft);
  cursor: default;
  contain: layout style;
}

.row:hover { background: var(--hover); }

.row[aria-selected="true"] { background: var(--sel); }
.row[aria-selected="true"] .idx { color: var(--accent); }

.idx {
  font: 500 11px/1 var(--mono);
  color: var(--dim-2);
  letter-spacing: 0.02em;
}

.name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.pip {
  width: 5px; height: 5px;
  flex: 0 0 5px;
  background: var(--dim-2);
  opacity: 0.45;
}

.pip[data-h="live"] { background: var(--bar-g); opacity: 1; }
.pip[data-h="dead"] { background: var(--bar-r); opacity: 1; }

.name span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grp {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--dim);
  font-size: 12px;
  padding-left: 16px;
}

.listfoot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 7px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-size: 11px;
  color: var(--dim);
}

.hint { display: flex; align-items: center; gap: 5px; color: var(--dim-2); }
.hint kbd { font-size: 11px; padding: 2px 4px; }

/* narrow catalog (dragged gutter or small window): drop the group column */
@container catalog (max-width: 640px) {
  .listhead, .row { grid-template-columns: 58px minmax(0, 1fr); }
  .listhead span:nth-child(3), .grp { display: none; }
}

@container catalog (max-width: 460px) {
  .hint { display: none; }
  .toggle { margin-left: 0; }
}

/* ---------- monitor ---------- */

/* Column: screen → signal strip → channel info. The screen grows with the
   monitor width but stops before it would push the channel info off-screen. */
.monitor {
  --np-reserve: 128px; /* signal strip + title row + one meta row */
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
  container: monitor / inline-size;
}

.screen {
  position: relative;
  flex: none;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100dvh - 56px - var(--np-reserve));
  background: var(--screen);
  overflow: hidden;
}

.screen video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--screen);
  opacity: 0;
  transition: opacity 0.25s ease-out;
}

.screen[data-state="live"] video { opacity: 1; }

/* carta de ajuste */
.testcard {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transition: opacity 0.25s ease-out;
}

.screen[data-state="live"] .testcard { opacity: 0; pointer-events: none; }

.graticule {
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M40 0H0V40' fill='none' stroke='%23ffffff' stroke-opacity='0.09' stroke-width='1'/%3E%3C/svg%3E");
  mask-image: radial-gradient(circle at center, #000 30%, transparent 78%);
}

.tc-bars {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 9px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  opacity: 0.9;
}

.tc-bars i:nth-child(1) { background: var(--bar-y); }
.tc-bars i:nth-child(2) { background: var(--bar-c); }
.tc-bars i:nth-child(3) { background: var(--bar-g); }
.tc-bars i:nth-child(4) { background: var(--bar-m); }
.tc-bars i:nth-child(5) { background: var(--bar-r); }
.tc-bars i:nth-child(6) { background: var(--bar-b); }
.tc-bars i:nth-child(7) { background: var(--bar-w); }

.tc-copy { position: relative; text-align: center; padding: 0 24px; max-width: 42ch; }

.tc-label {
  margin: 0 0 10px;
  font: 500 11px/1 var(--mono);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #8d9691;
}

.tc-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 500;
  color: #e9ebe6;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.tc-hint { margin: 0; font-size: 12px; color: #8d9691; }

.screen[data-state="tuning"] .tc-label { color: var(--bar-y); }
.screen[data-state="error"] .tc-label { color: var(--bar-r); }

/* franja de señal */
.signal {
  flex: none;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  height: 4px;
  background: var(--line);
}

.signal i { background: var(--bar-w); opacity: 0.1; }
.signal i:nth-child(1) { background: var(--bar-y); }
.signal i:nth-child(2) { background: var(--bar-c); }
.signal i:nth-child(3) { background: var(--bar-g); }
.signal i:nth-child(4) { background: var(--bar-m); }
.signal i:nth-child(5) { background: var(--bar-r); }
.signal i:nth-child(6) { background: var(--bar-b); }
.signal i:nth-child(7) { background: var(--bar-w); }

.signal[data-state="live"] i { opacity: 1; }

.signal[data-state="tuning"] i { animation: sweep 1.05s infinite linear; }
.signal[data-state="tuning"] i:nth-child(2) { animation-delay: 0.15s; }
.signal[data-state="tuning"] i:nth-child(3) { animation-delay: 0.3s; }
.signal[data-state="tuning"] i:nth-child(4) { animation-delay: 0.45s; }
.signal[data-state="tuning"] i:nth-child(5) { animation-delay: 0.6s; }
.signal[data-state="tuning"] i:nth-child(6) { animation-delay: 0.75s; }
.signal[data-state="tuning"] i:nth-child(7) { animation-delay: 0.9s; }

.signal[data-state="error"] i { opacity: 0.08; }
.signal[data-state="error"] i:nth-child(5) { opacity: 1; }

@keyframes sweep {
  0%, 100% { opacity: 0.08; }
  45%, 55% { opacity: 1; }
}

/* ---------- now playing ---------- */

/* takes whatever height the screen leaves; errors and recents scroll inside */
.nowplaying {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 16px 16px;
}

.np-head { display: flex; align-items: center; gap: 12px; min-width: 0; }

.np-title {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.35;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ghost {
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  color: var(--dim);
  font: 11px/1 var(--sans);
  cursor: pointer;
  white-space: nowrap;
}

.ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--dim-2); }
.ghost:disabled { opacity: 0.4; cursor: default; }

/* one compact row: label above value, three columns */
.meta {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.3fr);
  gap: 16px;
  padding: 8px 0;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
}

.meta > div { display: grid; gap: 2px; min-width: 0; }

.meta dt {
  font: 500 11px/1.6 var(--mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim-2);
}

.meta dd {
  margin: 0;
  font: 12px/1.6 var(--mono);
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* narrow player: the screen is short, so there is room to list meta vertically.
   Must come after the .meta base rules to win. */
@container monitor (max-width: 520px) {
  .meta { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .meta > div { grid-template-columns: 78px minmax(0, 1fr); gap: 12px; }
}

.err {
  margin: 0;
  padding: 9px 11px;
  border: 1px solid color-mix(in srgb, var(--bar-r) 45%, transparent);
  background: color-mix(in srgb, var(--bar-r) 10%, transparent);
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink);
  overflow-wrap: anywhere;
  white-space: pre-line;
}

/* ---------- recientes ---------- */

.recents { display: grid; gap: 8px; }

.recents h2 {
  margin: 0;
  font: 500 11px/1 var(--mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim-2);
}

.recent-list { display: grid; border-top: 1px solid var(--line-soft); }

.recent {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-soft);
  background: none;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.recent .idx { font-size: 11px; }

.recent:hover { color: var(--accent); }
.recent .r-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .r-grp { font: 11px/1 var(--mono); color: var(--dim-2); }

/* ---------- acceso ---------- */

.who { font: 500 11px/1 var(--mono); color: var(--dim); }

.gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--bg);
  overscroll-behavior: contain;
}

.gate-card {
  display: grid;
  gap: 10px;
  width: min(100%, 360px);
  padding: 24px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.gate-card .brand { margin-bottom: 8px; }
.gate-card h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }

.gate-card label {
  font: 500 11px/1 var(--mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim-2);
}

.gate-card input {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1 var(--mono);
}

.gate-card input::placeholder { color: var(--dim-2); font-family: var(--sans); }
.gate-card input:focus { border-color: var(--accent); outline: none; }

.gate-msg {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--bar-r) 45%, transparent);
  background: color-mix(in srgb, var(--bar-r) 10%, transparent);
  font-size: 12px;
  line-height: 1.5;
}

.gate-card button {
  height: 36px;
  margin-top: 4px;
  border: 0;
  border-radius: 3px;
  background: var(--accent);
  color: var(--panel);
  font: 600 13px/1 var(--sans);
  cursor: pointer;
  touch-action: manipulation;
}

.gate-card button:hover:not(:disabled) { filter: brightness(1.08); }
.gate-card button:disabled { opacity: 0.6; cursor: progress; }
.gate-card button:focus-visible { outline-offset: 2px; }

/* ---------- responsive ---------- */

/* side by side down to 760px (fits a window snapped to half a 1920 screen);
   below that, stack: player on top, list gets the rest */
@media (max-width: 760px) {
  .split { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .gutter { display: none; }
  .catalog { border-top: 1px solid var(--line); grid-row: 2; }
  .monitor { grid-row: 1; }
  .screen { max-height: 36dvh; }
  .nowplaying { flex: none; overflow: visible; padding-bottom: 12px; }
  .recents { display: none; }
}

@media (max-width: 640px) {
  .topbar { gap: 12px; padding: 0 12px; }
  .count, .who { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .screen video, .testcard { transition: none; }
}
