/* Live Media Cloud — sistema visual "sala de control".
   Rojo tally para el aire, petróleo para lo interactivo, datos en monoespaciada
   con cifras tabulares. Pensado para operarse con el pulgar, en sol o de noche. */

:root {
  color-scheme: light dark;

  /* Neutros con sesgo cian (hacia el petróleo del acento) */
  --ground: #f2f5f5;
  --surface: #ffffff;
  --surface-2: #e9eeee;
  --line: #d3dcdc;
  --line-soft: #e4eaea;
  --ink: #16232a;
  --ink-2: #4a5c63;
  --ink-3: #7b8b91;

  /* Acento interactivo: petróleo */
  --accent: #0d6e75;
  --accent-press: #0a575d;
  --accent-ink: #ffffff;
  --accent-wash: #e2f0f1;

  /* Semánticos: estado de la señal, separados del acento */
  --tally: #e03127;
  --tally-ink: #ffffff;
  --live: #2f7d3a;
  --warn: #a86500;
  --warn-wash: #fdf3e0;
  --dead: #c02c22;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(22, 35, 42, .07), 0 6px 16px -10px rgba(22, 35, 42, .25);

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0e1416;
    --surface: #161f22;
    --surface-2: #1e2a2e;
    --line: #2a383d;
    --line-soft: #223034;
    --ink: #e7eeef;
    --ink-2: #a3b4b8;
    --ink-3: #74878c;
    --accent: #3fb3bd;
    --accent-press: #63c6ce;
    --accent-ink: #06282b;
    --accent-wash: #12363a;
    --tally: #f0483c;
    --live: #58c06a;
    --warn: #e0a02e;
    --warn-wash: #33280f;
    --dead: #f0483c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 20px -12px rgba(0, 0, 0, .7);
  }
}

/* El botón de tema manda sobre la preferencia del sistema, en ambos sentidos */
:root[data-theme="light"] {
  --ground: #f2f5f5; --surface: #ffffff; --surface-2: #e9eeee;
  --line: #d3dcdc; --line-soft: #e4eaea;
  --ink: #16232a; --ink-2: #4a5c63; --ink-3: #7b8b91;
  --accent: #0d6e75; --accent-press: #0a575d; --accent-ink: #ffffff; --accent-wash: #e2f0f1;
  --tally: #e03127; --live: #2f7d3a; --warn: #a86500; --warn-wash: #fdf3e0; --dead: #c02c22;
  --shadow: 0 1px 2px rgba(22, 35, 42, .07), 0 6px 16px -10px rgba(22, 35, 42, .25);
}
:root[data-theme="dark"] {
  --ground: #0e1416; --surface: #161f22; --surface-2: #1e2a2e;
  --line: #2a383d; --line-soft: #223034;
  --ink: #e7eeef; --ink-2: #a3b4b8; --ink-3: #74878c;
  --accent: #3fb3bd; --accent-press: #63c6ce; --accent-ink: #06282b; --accent-wash: #12363a;
  --tally: #f0483c; --live: #58c06a; --warn: #e0a02e; --warn-wash: #33280f; --dead: #f0483c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 20px -12px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; margin: 0; }

body {
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}

.shell { max-width: 620px; margin: 0 auto; padding: 14px 14px 56px; }

/* ---------- Barra superior ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 2px 14px;
}
.brand {
  display: flex; align-items: baseline; gap: 7px;
  font-size: .8125rem; letter-spacing: .14em; text-transform: uppercase;
  font-weight: 600; color: var(--ink-2);
}
.brand b { color: var(--ink); font-weight: 700; letter-spacing: .1em; }
.topbar .spacer { flex: 1; }
.linkish {
  color: var(--ink-2); text-decoration: none; font-size: .8125rem;
  border-bottom: 1px solid var(--line); padding-bottom: 1px;
}
.linkish:hover { color: var(--accent); border-color: var(--accent); }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-2); cursor: pointer;
  font-size: .95rem; line-height: 1;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Franja tally: el estado del aire ---------- */
.tally {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  padding: 16px 16px 14px; margin-bottom: 16px;
  transition: background-color .25s ease, border-color .25s ease;
}
.tally.on { background: var(--tally); border-color: var(--tally); }
.tally-head { display: flex; align-items: flex-start; gap: 12px; }
.tally-state {
  font-size: 1.75rem; font-weight: 800; letter-spacing: -.015em;
  text-transform: uppercase; line-height: 1.05; color: var(--ink-3);
}
.tally.on .tally-state { color: var(--tally-ink); }
.tally-meta {
  font-family: var(--mono); font-size: .75rem; font-variant-numeric: tabular-nums;
  color: var(--ink-3); margin-top: 5px;
}
.tally.on .tally-meta { color: rgba(255, 255, 255, .82); }
.tally-actions { margin-left: auto; display: flex; flex-direction: column; gap: 7px; }

.beacon {
  width: 11px; height: 11px; border-radius: 50%; flex: none;
  background: var(--ink-3); margin-top: 9px;
}
.tally.on .beacon { background: var(--tally-ink); }
@media (prefers-reduced-motion: no-preference) {
  .tally.on .beacon { animation: beat 1.6s ease-in-out infinite; }
}
@keyframes beat { 50% { opacity: .28; } }

/* ---------- Módulos ---------- */
.mod {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 12px; overflow: hidden;
}
.mod-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--line-soft);
  font-size: .6875rem; letter-spacing: .13em; text-transform: uppercase;
  font-weight: 700; color: var(--ink-2); background: var(--surface-2);
}
.mod-head .tag {
  margin-left: auto; font-family: var(--mono); font-size: .6875rem;
  letter-spacing: .02em; text-transform: none; color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.mod-body { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.mod-body.tight { gap: 8px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.label { font-size: .9375rem; }
.hint { font-size: .8125rem; color: var(--ink-2); }
.data {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: .8125rem; color: var(--ink); word-break: break-all;
}
.data.big { font-size: 1.0625rem; font-weight: 600; white-space: nowrap; }
/* El estado va pegado a su etiqueta, no compitiendo por ancho con el botón */
.label .chip { margin-left: 7px; vertical-align: 1px; }
.data.sel { user-select: all; }

/* ---------- Enlaces del bonding ---------- */
.link-row {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 14px 11px 11px; border-bottom: 1px solid var(--line-soft);
  position: relative;
}
.link-row:last-child { border-bottom: 0; }
.link-row::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--ink-3);
}
.link-row.is-live::before { background: var(--live); }
.link-row.is-warn::before { background: var(--warn); }
.link-row.is-dead::before { background: var(--dead); }
.link-row.is-off::before { background: var(--line); }
.link-name { font-weight: 600; font-size: .9375rem; }
.link-meta {
  font-family: var(--mono); font-size: .75rem; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.link-row .btn { margin-left: auto; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .6875rem; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--ink-2); background: var(--surface);
}
.chip.live { color: var(--live); border-color: color-mix(in srgb, var(--live) 40%, var(--line)); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.chip.dead { color: var(--dead); border-color: color-mix(in srgb, var(--dead) 40%, var(--line)); }

/* ---------- Controles ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; font-size: .875rem; font-weight: 600;
  padding: 9px 14px; border-radius: var(--radius-sm); cursor: pointer;
  min-height: 40px; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .42; cursor: default; }
.btn.solid { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.solid:hover:not(:disabled) { background: var(--accent-press); border-color: var(--accent-press); color: var(--accent-ink); }
.btn.stop { background: var(--dead); border-color: var(--dead); color: #fff; }
.btn.stop:hover:not(:disabled) { filter: brightness(1.08); color: #fff; }
.btn.sm { padding: 6px 11px; min-height: 34px; font-size: .8125rem; }
.btn.wide { width: 100%; justify-content: center; }
.tally.on .btn { border-color: rgba(255, 255, 255, .5); background: transparent; color: #fff; }
.tally.on .btn.stop { background: #fff; border-color: #fff; color: var(--tally); }
.tally.on .btn:disabled { opacity: .45; }

.btn-talk {
  width: 100%; min-height: 56px; font-size: 1rem; font-weight: 700;
  letter-spacing: .02em;
}
.btn-talk.on { background: var(--tally); border-color: var(--tally); color: #fff; }

:where(a, button, input, [tabindex]):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px;
}

input[type="range"] {
  width: 100%; accent-color: var(--accent); height: 26px; margin: 0;
}
input[type="email"], input[type="password"] {
  width: 100%; font: inherit; padding: 11px 12px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.divider { height: 1px; background: var(--line-soft); margin: 2px 0; }

/* Avisos: el cambio pendiente y el fallo del equipo se leen sin buscarlos */
.flag {
  font-size: .875rem; font-weight: 600; color: var(--warn);
  background: var(--warn-wash); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  border-radius: var(--radius-sm); padding: 8px 11px;
}
.flag.grave { color: var(--dead); background: color-mix(in srgb, var(--dead) 9%, transparent);
  border-color: color-mix(in srgb, var(--dead) 32%, transparent); }
.tally .flag { margin-top: 9px; }
.tally.on .flag { background: rgba(0, 0, 0, .22); border-color: rgba(255, 255, 255, .3); color: #fff; }

/* ---------- Avisos flotantes ---------- */
#toast {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: var(--ink); color: var(--ground); border-radius: var(--radius-sm);
  padding: 12px 22px; font-size: .9375rem; font-weight: 600; max-width: 92vw;
  box-shadow: 0 10px 30px -8px rgba(0, 0, 0, .5); z-index: 20;
  opacity: 0; pointer-events: none; transition: opacity .22s ease, transform .22s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--dead); color: #fff; }

/* ---------- Lista de equipos ---------- */
.device {
  display: flex; align-items: center; gap: 12px; text-decoration: none;
  color: inherit; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 15px 16px; margin-bottom: 10px;
}
.device:hover { border-color: var(--accent); }
.device .arrow { margin-left: auto; color: var(--ink-3); font-size: 1.1rem; }
.device:hover .arrow { color: var(--accent); }

.empty {
  text-align: center; color: var(--ink-2); padding: 44px 20px;
  border: 1px dashed var(--line); border-radius: var(--radius);
}

/* ---------- Acceso ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.gate-card {
  width: 100%; max-width: 370px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 30px 26px;
}
.gate-mark {
  font-size: .6875rem; letter-spacing: .2em; text-transform: uppercase;
  font-weight: 700; color: var(--accent); text-align: center;
}
.gate-title {
  font-size: 1.45rem; font-weight: 800; letter-spacing: -.02em;
  text-align: center; margin-top: 6px; text-wrap: balance;
}
.gate-sub { text-align: center; color: var(--ink-2); font-size: .875rem; margin-top: 5px; }
.field-label {
  display: block; font-size: .6875rem; letter-spacing: .12em; text-transform: uppercase;
  font-weight: 700; color: var(--ink-2); margin: 18px 0 6px;
}
.gate-error {
  margin-top: 18px; font-size: .875rem; font-weight: 600; text-align: center;
  color: var(--dead); background: color-mix(in srgb, var(--dead) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--dead) 30%, transparent);
  border-radius: var(--radius-sm); padding: 9px 12px;
}
