/* ===================================================================
   AIM v1.5 — hoja base del rediseño. Mobile-first + RTL (propiedades
   lógicas). Tres identidades por data-theme en <html>: por defecto
   "warm" (Cálido); overrides para "cool" (Frío) y "dark" (Oscuro).
   En la Fase 2 cubre: reset, cabecera, selector de preferencias,
   pie, primitivas (card/btn) y la pantalla de bienvenida. Las
   pantallas de la app se irán añadiendo en la fase de vistas/CSS.
   =================================================================== */

/* Fuentes Lato locales (servidas desde /css/, offline). */
@font-face { font-family: lato; src: url('/css/Lato-Regular.ttf'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: lato; src: url('/css/Lato-Bold.ttf');    font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: lato; src: url('/css/Lato-Italic.ttf');  font-weight: 400; font-style: italic;  font-display: swap; }

/* ---- Temas ---------------------------------------------------------------- */
/* Colores que REPRESENTAN a cada tema en las muestras del selector de aspecto
   (views/base.erb). Viven aquí una sola vez y de aquí los toman tanto el tema
   como su muestra, para que el selector no pueda quedarse enseñando la paleta
   vieja. --sw-warm y --sw-cool son el --accent de su tema; --sw-dark es el
   --surface del oscuro, porque su acento (azul) no lo representa. */
:root { --sw-warm:#e8890b; --sw-cool:#0e9488; --sw-dark:#1b1f2e; }

/* OJO: install/errors/5xx/index.html —la página que sirve nginx cuando la app
   está caída— lleva una COPIA de seis de estos valores (--bg, --surface,
   --text, --muted, --border, --accent) y de --shadow. Es autocontenida por
   necesidad, así que si tocas la paleta Cálido, actualízala también. */
:root, [data-theme="warm"] {
  --font: lato, "Segoe UI", system-ui, sans-serif;
  --bg:#fbf7f0; --surface:#ffffff; --surface-2:#fdf6ea;
  --text:#2a2622; --muted:#8a8178; --border:#eadfce;
  --accent: var(--sw-warm); --accent-strong:#c9720a; --on-accent:#ffffff;
  --left:#2f6fb0; --left-bg:#e8f1fb; --right:#d5573b; --right-bg:#fdece7;
  --radius:12px; --shadow:0 2px 10px rgba(120,90,30,.10);
}
[data-theme="cool"] {
  --font:"Segoe UI", system-ui, Roboto, -apple-system, sans-serif;
  --bg:#f2f7f8; --surface:#ffffff; --surface-2:#eef5f6;
  --text:#1f2d33; --muted:#6b8088; --border:#dbe8ea;
  --accent: var(--sw-cool); --accent-strong:#0b7a70; --on-accent:#ffffff;
  --left:#2b7cc4; --left-bg:#e7f1fb; --right:#e07a5f; --right-bg:#fbeee8;
  --radius:16px; --shadow:0 4px 18px rgba(20,80,80,.10);
}
[data-theme="dark"] {
  --font:"Segoe UI", system-ui, Roboto, -apple-system, sans-serif;
  --bg:#12141d; --surface: var(--sw-dark); --surface-2:#232840;
  --text:#e9ebf5; --muted:#9aa0bd; --border:#2f3550;
  --accent:#7c8cff; --accent-strong:#9aa6ff; --on-accent:#0d1020;
  --left:#5aa0ff; --left-bg:#1a2540; --right:#ff8f78; --right-bg:#3a2130;
  --radius:14px; --shadow:0 6px 22px rgba(0,0,0,.35);
}

/* ---- Reset y base --------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font-family: var(--font); font-size: 16px; line-height: 1.5;
  background: var(--bg); color: var(--text);
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { opacity: .75; }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.2; }
img { max-width: 100%; }
button { font-family: inherit; }
/* Iconos SVG en línea (Feather): monocromo, heredan color; no encogen en flex */
.icon { flex: none; vertical-align: middle; }

/* ---- Cabecera ------------------------------------------------------------- */
.app-topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .7rem 1rem; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .6rem; min-width: 0;
  color: inherit; text-decoration: none; }
.brand:hover { opacity: 1; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-size: 1.1rem;
  background: var(--accent); color: var(--on-accent);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; font-size: 1.02rem; line-height: 1.1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-sub { color: var(--muted); font-size: .72rem; }
.app-actions { display: flex; align-items: center; gap: .4rem; flex: none; }

/* Botones de icono (cabecera) — objetivo táctil >= 44px */
.iconbtn {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  display: grid; place-items: center; position: relative; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 1.1rem; text-decoration: none;
}
.iconbtn:hover { opacity: 1; background: var(--border); }
/* #91: reiniciar/apagar son <button> en un <form> POST. El form se comporta
   como el icono que lleva dentro, y el boton hereda la familia de letra. */
.sys-action { display: flex; margin: 0; }
button.iconbtn { font-family: inherit; padding: 0; }
.iconbtn:active { transform: scale(.94); }
.iconbtn-tag { position: absolute; bottom: 2px; inset-inline-end: 3px;
  font-size: .6rem; font-weight: 700; color: var(--muted); }

/* ---- Selector de preferencias (details/summary, sin JS) ------------------- */
.pref { position: relative; }
.pref > summary { list-style: none; }
.pref > summary::-webkit-details-marker { display: none; }
.pref > summary::marker { content: ""; }
.panel {
  position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: 50;
  min-width: 220px; padding: .4rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 12px 34px rgba(0,0,0,.28);
}
.panel h3 { margin: .3rem .5rem .4rem; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.panel-scroll { max-height: 260px; overflow-y: auto; }
.panel form { margin: 0; }
.opt {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  width: 100%; padding: .7rem; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); font: inherit; font-size: .98rem;
  text-align: start; cursor: pointer;
}
.opt:hover { background: var(--surface-2); }
.opt.is-selected { background: var(--surface-2); font-weight: 700; }
.opt-label { display: flex; align-items: center; gap: .55rem; }
/* El borde es literal a propósito: rodea muestras de temas que NO son el
   activo, y var(--border) siempre resolvería al activo. */
.opt .swatch { width: 20px; height: 20px; border-radius: 6px; flex: none;
  border: 1px solid rgba(128,128,128,.35); }
.swatch--warm { background: var(--sw-warm); }
.swatch--cool { background: var(--sw-cool); }
.swatch--dark { background: var(--sw-dark); }
.opt .tick { color: var(--accent); font-weight: 700; }
.opt .tag { font-size: .62rem; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px; padding: .05rem .3rem; }

/* En movil el panel no cabe: anclado al boton (.pref), el borde final de este
   queda a ~167px del lado de la pantalla y el panel pide 220px hacia dentro, asi
   que se salia del viewport (por el lado de inicio en LTR, por el opuesto en
   RTL) y los nombres se leian a medias. Con .pref estatico, el ancestro
   posicionado pasa a ser .app-topbar (ya es sticky): el mismo
   `inset-inline-end: 0` lo alinea entonces con su padding, o sea al margen de
   pagina, y `top: calc(100% + 6px)` cae bajo la cabecera en vez de bajo el
   boton. max-width lo acota al ancho util. En escritorio no cambia nada. */
@media (max-width: 559px) {
  .pref { position: static; }
  .panel { max-width: 100%; }
}

/* Ventana baja (movil apaisado): los 260px fijos de la lista no saben cuanta
   pantalla hay y el panel se salia por abajo. Se ata al alto disponible =
   ventana - (cabecera 67 + separacion 6 + h3 y paddings del panel ~41 + aire).
   NO se reducen las cajas: ya estan en ~39px, por debajo del objetivo tactil de
   44px, y aun a 30px diez idiomas no cabrian en 360px de alto. La lista tiene
   que desplazarse; lo que faltaba era limitarla bien. */
@media (max-height: 380px) {
  .panel-scroll { max-height: calc(100vh - 8.5rem); }
}

/* ---- Contenido principal -------------------------------------------------- */
.app-main { flex: 1; width: 100%; max-width: 760px;
  margin-inline: auto; padding: 1.2rem 1rem 2rem; }

/* ---- Pie ------------------------------------------------------------------ */
.app-footer {
  display: flex; align-items: center; justify-content: center; gap: .55rem;
  flex-wrap: wrap;
  padding: 1rem; background: var(--surface); border-top: 1px solid var(--border);
  color: var(--muted); font-size: .78rem;
}
.footer-logo { height: 20px; width: auto; }
.app-version {
  font-variant-numeric: tabular-nums; letter-spacing: .01em; opacity: .85;
}
.app-version::before { content: '·'; margin-inline-end: .55rem; }

/* ---- Primitivas ----------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.2rem;
  margin-bottom: 1.1rem;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 54px; padding: .9rem 1.3rem; width: 100%;
  font: inherit; font-weight: 700; font-size: 1.05rem;
  border: 1.5px solid transparent; border-radius: 14px; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); opacity: 1; }

/* ---- Componentes de pantalla (formularios, títulos, avisos) --------------- */
.screen-title { font-size: 1.4rem; font-weight: 800; letter-spacing: -.01em;
  margin: .2rem 0 1.1rem; }

.field-label { display: block; font-weight: 700; margin-bottom: .5rem; }

/* Desplegable con flecha propia (aspecto uniforme entre navegadores) */
.select { position: relative; }
.select select {
  -webkit-appearance: none; appearance: none; width: 100%;
  font: inherit; font-size: 1.2rem;
  padding: 1.15rem 3rem 1.15rem 1.25rem; border-radius: 12px;
  border: 1.5px solid var(--border); background: var(--surface-2);
  color: var(--text); cursor: pointer;
}
.select::after { content: "▾"; position: absolute; inset-inline-end: 1.15rem;
  top: 50%; transform: translateY(-50%); font-size: 1.1rem;
  color: var(--muted); pointer-events: none; }

.link { display: inline-flex; align-items: center; gap: .35rem; margin-top: .85rem;
  color: var(--accent-strong); font-weight: 600; }

/* Aviso/alerta (errores de AJAX, mantenimiento…) */
.alert { margin-bottom: 1.1rem; padding: .9rem 1.1rem;
  border: 1.5px solid var(--accent); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); font-weight: 600; }
.alert[hidden] { display: none; }

/* Título dentro de una tarjeta */
.card-title { margin: 0 0 .9rem; font-size: .82rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; margin-top: .7rem; }

/* Rejilla de 3 columnas (parámetros): 1 col en móvil, 3 en pantalla ancha */
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 560px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }

/* Campo con color de canal (oído izquierdo / derecho) */
.field.is-left .field-label { color: var(--left); }
.field.is-left .select select { border-color: var(--left); }
.field.is-right .field-label { color: var(--right); }
.field.is-right .select select { border-color: var(--right); }

/* Casillas de frecuencia (chips). Estado activo/deshabilitado desde aim.js.
   Móvil: 1 columna (chip a todo el ancho). Desktop: 3 columnas -> 3+3. */
.freqs { display: grid; grid-template-columns: 1fr; gap: .6rem; }
@media (min-width: 560px) { .freqs { grid-template-columns: repeat(3, 1fr); } }
.freq-chip { display: flex; align-items: center; justify-content: center; gap: .55rem;
  padding: .7rem 1rem; border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-weight: 600; user-select: none; }
.freq-chip input { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
.freq-chip.is-on { border-color: var(--accent); background: var(--surface); font-weight: 800; }
.freq-chip.is-disabled { opacity: .45; cursor: not-allowed; }
.freq-chip.is-disabled input { cursor: not-allowed; }

/* ---- Pantalla de sesión ---------------------------------------------------- */
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

/* Miga de pan (rastro de navegación) */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem;
  margin-bottom: .5rem; font-size: .85rem; }
.crumbs a { color: var(--muted); font-weight: 600; }
.crumbs a:hover { color: var(--accent-strong); opacity: 1; }
.crumbs .sep { color: var(--border); }
.crumbs .current { color: var(--text); font-weight: 700; }

/* Flecha "siguiente" de los botones: se voltea en RTL (árabe/hebreo) */
.nav-arrow { display: inline-block; }
[dir="rtl"] .nav-arrow { transform: scaleX(-1); }

/* Resumen de /session (v1.5.1): tabla "al inicio" vs "ahora". Cabe en móvil
   (3 columnas estrechas); si aun así no cupiera, desplaza dentro de su caja y
   nunca empuja el ancho de la página. */
.summary-head { margin: -.4rem 0 .9rem; font-weight: 700; font-size: 1.05rem; }
.summary-head .sep { color: var(--border); margin: 0 .35rem; }
.table-wrap { overflow-x: auto; }
.summary-table { width: 100%; border-collapse: collapse; }
.summary-table th, .summary-table td { padding: .55rem .5rem; text-align: start;
  vertical-align: middle; }
.summary-table thead th { color: var(--muted); font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
.summary-table tbody th { font-size: .8rem; font-weight: 700; }
.summary-table tbody td { font-weight: 700; font-size: 1rem; }
.summary-table tbody tr + tr th, .summary-table tbody tr + tr td {
  border-top: 1px solid var(--border); }
.summary-table .none { color: var(--muted); font-weight: 400; font-size: .85rem; }
/* Valor que ha cambiado durante la sesión: se marca con un punto de acento
   delante (no solo con color, para que se distinga sin percibir el matiz). */
.summary-table .is-changed { color: var(--accent-strong); }
.summary-table .is-changed::before { content: "•"; margin-inline-end: .3rem; }

.pill { display: inline-block; padding: .28rem .7rem; border-radius: 999px;
  font-size: .82rem; font-weight: 700; background: var(--surface-2);
  border: 1px solid var(--border); margin-block-start: .15rem; margin-inline-end: .25rem; }

/* Panel de volumen: móvil en columna; ancho -> canal | candado | canal */
.vol-wrap { display: grid; grid-template-columns: 1fr; gap: .9rem; }
@media (min-width: 560px) { .vol-wrap { grid-template-columns: 1fr auto 1fr; align-items: center; } }
.channel { border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 1rem; text-align: center; background: var(--surface); }
.channel.left  { border-color: var(--left);  background: var(--left-bg); }
.channel.right { border-color: var(--right); background: var(--right-bg); }
.chlabel { font-weight: 700; font-size: .82rem; text-transform: uppercase;
  letter-spacing: .06em; margin-bottom: .5rem; }
.channel.left .chlabel  { color: var(--left); }
.channel.right .chlabel { color: var(--right); }
.stepper { display: flex; align-items: center; justify-content: center; gap: .9rem; }
.step { width: 60px; height: 60px; border-radius: 50%; flex: none; padding: 0;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 1.9rem; font-weight: 700; line-height: 1; cursor: pointer;
  display: grid; place-items: center; }
.step:active { transform: scale(.92); }
.step:disabled { opacity: .4; cursor: not-allowed; }
.bignum { font-size: 2.6rem; font-weight: 800; min-width: 2.4ch; line-height: 1; }
.lock { display: grid; place-items: center; }
/* El color es OBLIGATORIO: un <button> no hereda `color`, así que sin esto el
   icono (currentColor) cae al color de sistema —negro— y en el tema Oscuro se
   pierde contra el fondo. Mismo `--text` que los +/- de al lado. */
.lockbtn { width: 56px; height: 56px; border-radius: 14px; padding: 0; cursor: pointer;
  border: 1.5px solid var(--border); background: var(--surface-2); color: var(--text);
  display: grid; place-items: center; }
/* Muestra candado cerrado (vinculado) o abierto (independiente) segun data-locked */
.lockbtn .ic-unlocked { display: none; }
.lockbtn[data-locked="false"] .ic-locked { display: none; }
.lockbtn[data-locked="false"] .ic-unlocked { display: block; }

/* Lista de canciones: cabecera (título + tiempo) + barra de progreso por pista */
#songs-list { list-style: none; margin: 1rem 0 0; padding: 0;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: .5rem; }
#songs-list li { min-width: 0; padding: .6rem .7rem; border-radius: 10px; }
#songs-list .playing { background: var(--surface-2); }
.song-head { display: flex; align-items: baseline; gap: .8rem; }
/* Título: ocupa el espacio disponible y trunca con … si es muy largo (móvil).
   El nombre completo queda en el atributo title (tooltip). */
.song-title { flex: 1; min-width: 0; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#songs-list .playing .song-title { font-weight: 800; color: var(--accent-strong); }
.song-duration-screen { flex: none; color: var(--muted); font-size: .9rem;
  font-variant-numeric: tabular-nums; }
.song-bar { height: 5px; margin-top: .45rem; border-radius: 999px;
  background: var(--border); overflow: hidden; }
.song-bar-fill { display: block; height: 100%; width: 0; border-radius: 999px;
  background: var(--accent); transition: width .5s linear; }

/* Botones de sesión */
.session-actions { display: grid; gap: .7rem; }
/* Pausar: "ghost" = transparente con borde, a juego con el Abortar de al lado.
   El `color` es obligatorio (un <button> no hereda color): sin él caía al negro
   de sistema sobre fondo de sistema, y en el tema Oscuro desentonaba. */
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); opacity: 1; }
.btn-danger { background: transparent; color: var(--right); border-color: var(--right); }
/* Al pasar por encima se tiñe con el fondo suave del canal derecho, no con el
   rojo plano: `--right` sobre `--right-bg` es la pareja que ya usa el panel de
   volumen y mantiene el contraste en los tres temas. El relleno plano dejaba el
   texto blanco sobre un rojo claro (Frío y Oscuro) casi ilegible. */
.btn-danger:hover { background: var(--right-bg); opacity: 1; }
/* Botón de pausa: muestra icono de pausa (reproduciendo) o de play (pausado) */
#pause .ic-resume { display: none; }
#pause[data-state="paused"] .ic-pause { display: none; }
#pause[data-state="paused"] .ic-resume { display: inline-flex; }
.session-note { text-align: center; padding: 1.1rem; border-radius: var(--radius);
  background: var(--surface-2); font-weight: 800; }

/* ---- Pantalla de bienvenida (portal cautivo) ------------------------------ */
.welcome { text-align: center; margin-top: 1.5rem; }
.welcome-kicker { color: var(--muted); font-size: .8rem; text-transform: uppercase;
  letter-spacing: .08em; margin: 0 0 .4rem; }
.welcome-name { font-size: 2rem; font-weight: 800; margin: 0 0 .2rem; }
.welcome-title { font-size: 1.1rem; color: var(--muted); margin: 0 0 1.4rem; }
/* Aviso de sesión en marcha en el portal (v1.5.1) */
.welcome-live { display: inline-flex; align-items: center; gap: .4rem;
  margin: -.6rem 0 1.1rem; padding: .35rem .8rem; border-radius: 999px;
  font-size: .85rem; font-weight: 700; color: var(--accent-strong);
  background: var(--surface-2); border: 1px solid var(--border); }
.welcome-live svg { flex: none; }
.welcome .btn { margin-bottom: 1.2rem; }
.welcome-fallback { color: var(--muted); font-size: .85rem; line-height: 1.6; }
.welcome-fallback .mono { font-family: ui-monospace, "Courier New", monospace;
  color: var(--text); font-weight: 700; }

/* ---- Avisos / páginas terminales (apagado, reinicio, errores) ------------- */
.notice { margin-top: 1.5rem; text-align: center; }
.notice p { margin: .6rem 0; line-height: 1.6; }
.notice .btn { margin-top: 1.1rem; }
