/* Sistema de diseño de StreamMate (docs/ui-redesign-plan.md, sección 4).
   Tokens, reset, cabecera, píldoras, menú, tarjetas glass, botones, formulario y medidor de
   audio. Se carga antes del css de cada página; las páginas solo agregan layout. */

:root {
  --bg-1: #35505a;
  --bg-2: #7c9ca6;
  --bg-3: #a9c3cb;
  --ink: #172026;
  --ink-2: #2b3a41;
  --ink-inv: #f4f8fa;
  --accent: #4285f4;
  --accent-2: #2a64c4;
  --teal: #1fb2a6;
  --teal-2: #0b7a72;
  --ok: #1b8a4c;
  --ok-ink: #0a4a28;
  --warn: #ffb300;
  --danger: #d93025;
  --danger-ink: #8f1d16;
  --glass: rgba(255, 255, 255, .62);
  --glass-strong: rgba(255, 255, 255, .78);
  --glass-dark: rgba(23, 32, 38, .62);
  --line: rgba(255, 255, 255, .45);
  --shadow: 0 8px 24px rgba(10, 30, 40, .18);
  --radius: 14px;
  --radius-sm: 8px;
  --blur: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Reset ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg-2);
}

/* Fondo fijo en un pseudo-elemento: background-attachment: fixed se ignora en móvil */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 400px at 100% 0%, rgba(31, 178, 166, .22), transparent 60%),
    linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
}

/* El atributo gana siempre: ninguna clase con display propio puede pisarlo */
[hidden] { display: none !important; }

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

a { color: #1b3a8a; }
a:hover { color: #0f2560; }

h1, h2, h3 { line-height: 1.25; }

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

/* ---------- Glass: el blur vive en un pseudo-elemento, nunca en el contenedor ---------- */

.app-bar, .card, .menu-panel {
  position: relative;
  isolation: isolate;
}
.app-bar::before, .card::before, .menu-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--glass);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
}
.app-bar::before, .menu-panel::before { background: var(--glass-dark); }

/* ---------- Cabecera ---------- */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding: 10px 24px;
  color: var(--ink-inv);
  border-bottom: 1px solid rgba(255, 255, 255, .18);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink-inv);
}
.brand-logo {
  display: block;
  height: 40px;
  width: auto;
}
/* Isotipo solo: se muestra en teléfonos, donde el logo completo no entra */
.brand-mark {
  display: none;
  height: 32px;
  width: auto;
}
.brand .role {
  font-weight: 500;
  font-size: 13px;
  color: rgba(244, 248, 250, .82);
  padding: 3px 9px;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
}

.app-bar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---------- Píldoras de estado ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
  color: var(--ink-inv);
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .22);
}
.pill::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .5);
}
.pill[data-state="open"]::before,
.pill[data-state="online"]::before { background: #3ddc84; box-shadow: 0 0 0 3px rgba(61, 220, 132, .25); }
.pill[data-state="connecting"]::before,
.pill[data-state="authenticating"]::before,
.pill[data-state="closed"]::before { background: var(--warn); box-shadow: 0 0 0 3px rgba(255, 179, 0, .25); }
.pill[data-state="ended"]::before,
.pill[data-state="replaced"]::before,
.pill[data-state="full"]::before,
.pill[data-state="offline"]::before { background: #ff6b60; box-shadow: 0 0 0 3px rgba(255, 107, 96, .25); }

/* ---------- Menú de sesión (details nativo) ---------- */

.menu { position: relative; }
.menu summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: #fff;
  background: linear-gradient(135deg, rgba(42, 100, 196, .9), rgba(11, 122, 114, .9));
  border: 1px solid rgba(255, 255, 255, .3);
  user-select: none;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid rgba(255, 255, 255, .9);
}
.menu[open] summary::after { transform: rotate(180deg); }
.menu summary:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 440px;
  max-width: calc(100vw - 32px);
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, .2);
  box-shadow: 0 14px 34px rgba(5, 20, 30, .35);
  color: var(--ink-inv);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.menu-panel::before { background: rgba(23, 32, 38, .86); }

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.link-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .08);
}
.link-row .lbl { font-size: 12px; color: rgba(244, 248, 250, .75); flex: none; width: 56px; }
.link-row a {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #dbe8ee;
}

/* ---------- Tarjetas ---------- */

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.card h2 { margin: 0 0 10px; font-size: 16px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }

.card select, .card input[type="text"], .card input[type="number"], .card input[type="search"], .card textarea {
  font-size: 12px;
  padding: 4px 7px;
  border-radius: 7px;
  border: 1px solid rgba(23, 32, 38, .22);
  background: rgba(255, 255, 255, .72);
  color: var(--ink);
}
.card textarea { width: 100%; }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.hint { font-size: 11px; color: var(--ink-2); }

/* ---------- Botones ---------- */

.btn {
  appearance: none;
  cursor: pointer;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 9px;
  border: 1px solid transparent;
  color: var(--ink);
  background: var(--glass-strong);
  transition: filter .15s, box-shadow .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { filter: brightness(.95); }
.btn:disabled { opacity: .6; cursor: default; filter: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-2), var(--teal-2));
  box-shadow: 0 4px 12px rgba(31, 100, 180, .28);
}
.btn-ghost {
  background: rgba(255, 255, 255, .55);
  border-color: rgba(255, 255, 255, .7);
}
.menu-panel .btn-ghost {
  background: rgba(255, 255, 255, .12);
  color: var(--ink-inv);
  border-color: rgba(255, 255, 255, .25);
}
.btn-danger {
  background: rgba(217, 48, 37, .18);
  color: #ffb4ad;
  border-color: rgba(255, 120, 110, .4);
}
.card .btn-danger { color: var(--danger-ink); border-color: rgba(217, 48, 37, .4); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn[aria-pressed="true"] {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-2), var(--teal-2));
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .55), 0 4px 12px rgba(31, 100, 180, .28);
}

/* ---------- Pares clave/valor, barras, chips ---------- */

.kv {
  font-size: 13px;
  margin: 4px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: baseline;
}
.kv > b { min-width: 110px; font-weight: 600; }

.bar-track {
  height: 6px;
  border-radius: 3px;
  background: rgba(23, 32, 38, .14);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--teal));
  transition: width .2s;
}

.chip {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .65);
  border: 1px solid rgba(23, 32, 38, .15);
  margin: 4px 4px 0 0;
}

/* ---------- Formulario ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}
.field input {
  width: 100%;
  font-weight: 400;
  font-size: 15px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(23, 32, 38, .2);
  background: rgba(255, 255, 255, .85);
  color: var(--ink);
}
.field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Video ---------- */

/* El borde, el radio y el recorte van acá; el <video> no lleva nada que desplace sus cajas */
.video-wrap {
  position: relative;
  contain: paint;
  overflow: hidden;
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .35);
  background: linear-gradient(135deg, #0d1a20, #1c3038 60%, #23424b);
}
.video-wrap > video {
  display: block;
  width: 100%;
}
.video-wrap > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* ---------- Medidor de audio (.vu, sección 5.6) ---------- */

.vu {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 20px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .5);
  border: 1px solid rgba(255, 255, 255, .18);
  pointer-events: none;
}
.vu > i {
  display: block;
  width: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .3);
}
.vu > i:nth-child(1) { height: 25%; }
.vu > i:nth-child(2) { height: 45%; }
.vu > i:nth-child(3) { height: 65%; }
.vu > i:nth-child(4) { height: 85%; }
.vu > i:nth-child(5) { height: 100%; }
.vu > i:nth-child(n+6) { height: 100%; }
.vu[data-state="live"] > i.on { background: linear-gradient(180deg, #3ddc84, var(--teal)); }
.vu[data-state="live"] > i.peak { background: var(--warn); }
.vu[data-state="suspended"] > i { background: rgba(255, 179, 0, .5); }
.vu[data-state="empty"] { opacity: .55; }
.vu-lg { left: 14px; bottom: 14px; height: 28px; gap: 4px; }
.vu-lg > i { width: 5px; }

/* ---------- Etiqueta de detección del sender ---------- */

.det-badge {
  display: inline-block;
  max-width: 100%;
  white-space: normal;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: rgba(255, 255, 255, .5);
  color: var(--ink-2);
  transition: background .2s;
}
.det-badge[data-state="hit"] {
  background: linear-gradient(135deg, #ffd60a, #ffb300);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(255, 179, 0, .3);
}
.det-badge[data-state="miss"] { background: rgba(255, 255, 255, .5); color: var(--ink-2); }
.det-badge[data-state="off"] { background: rgba(23, 32, 38, .1); color: var(--ink-2); }

/* ---------- Responsive y preferencias ---------- */

@media (max-width: 600px) {
  :root { --blur: 0px; }
  .app-bar { padding: 8px 12px; gap: 8px; }
  /* Solo el isotipo: el logo completo y el rol no entran */
  .brand-logo, .brand .role { display: none; }
  .brand-mark { display: block; }
  .pill { font-size: 11px; padding: 4px 8px; gap: 6px; }
  .pill::before { width: 7px; height: 7px; }
  .menu summary { font-size: 12px; padding: 5px 10px; }
  .menu-panel { width: calc(100vw - 24px); }
  .link-row .lbl { width: 48px; }
}

@media (prefers-reduced-transparency: reduce) {
  :root { --glass: rgba(255, 255, 255, .9); --glass-strong: rgba(255, 255, 255, .95); --glass-dark: rgba(23, 32, 38, .9); }
  .app-bar::before, .card::before, .menu-panel::before { backdrop-filter: none; -webkit-backdrop-filter: none; }
}

@supports not (backdrop-filter: blur(1px)) {
  :root { --glass: rgba(255, 255, 255, .9); --glass-strong: rgba(255, 255, 255, .95); --glass-dark: rgba(23, 32, 38, .9); }
}
