/* Cartelería — base styles */

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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #2563eb;
  --body-bg: #f1f5f9;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 8px;
}

body { font-family: system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Admin layout ── */

.admin-body {
  display: flex;
  min-height: 100vh;
  background: var(--body-bg);
}

.sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
}

.sidebar-brand {
  padding: 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-icon { font-size: 20px; }
.brand-name { color: #fff; font-weight: 700; font-size: 16px; }

.sidebar-nav { list-style: none; padding: 12px 0; flex: 1; }
.sidebar-nav li { padding: 0; }

.nav-link {
  display: block;
  padding: 10px 20px;
  color: var(--sidebar-text);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }

.sidebar-footer { padding: 12px 0; border-top: 1px solid rgba(255,255,255,.08); }

.main-content { margin-left: 220px; flex: 1; padding: 28px 32px; min-height: 100vh; }

/* ── Flash ── */

.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 14px; }
.flash-notice { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.flash-alert  { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }

/* ── Page header ── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title { font-size: 22px; font-weight: 700; }

/* ── Stat cards ── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card { background: var(--card-bg); border-radius: var(--radius); padding: 20px; border: 1px solid var(--border); }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 32px; font-weight: 700; margin-top: 4px; }
.stat-online  { color: var(--success); }
.stat-offline { color: var(--danger); }
.stat-total   { color: var(--text); }

/* ── Dashboard panels ── */

.dashboard-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
  margin-bottom: 32px;
}

@media (max-width: 800px) {
  .dashboard-columns { grid-template-columns: 1fr; }
}

.dashboard-column { display: flex; flex-direction: column; gap: 24px; }

.dashboard-panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

.panel-header { padding: 12px 18px; color: #fff; font-weight: 700; font-size: 14px; }
.panel-header-blue   { background: var(--primary); }
.panel-header-green  { background: var(--success); }
.panel-header-red    { background: var(--danger); }
.panel-header-orange { background: var(--warning); }

.panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.panel-row:last-child { border-bottom: none; }
.panel-row.total { font-weight: 700; background: #f8fafc; }
.panel-row-label { display: flex; align-items: center; gap: 8px; }
.panel-row-value { font-weight: 700; }

.panel-row-link { color: var(--text); cursor: pointer; transition: background .15s; }
.panel-row-link:hover { background: #f8fafc; text-decoration: none; }

.panel-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.panel-dot-online  { background: var(--success); }
.panel-dot-offline { background: var(--danger); }

/* ── Download progress ── */

.progress-wrap { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }

.progress-bar {
  width: 100%;
  height: 8px;
  border-radius: 99px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill { height: 100%; border-radius: 99px; transition: width .3s; }
.progress-fill-synced  { background: var(--success); }
.progress-fill-syncing { background: var(--primary); }
.progress-fill-error   { background: var(--danger); }
.progress-fill-pending { background: var(--text-muted); }

.progress-label { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.progress-label-none { font-style: italic; }

/* ── Filter tabs ── */

.filter-tabs { display: flex; gap: 8px; margin-bottom: 16px; }

.filter-tab {
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--card-bg);
  border: 1px solid var(--border);
}

.filter-tab:hover { text-decoration: none; background: #f8fafc; }
.filter-tab.active { color: #fff; background: var(--primary); border-color: var(--primary); }

/* ── Cards ── */

.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title { font-weight: 600; font-size: 15px; }
.card-body { padding: 20px; }

/* ── Tables ── */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

/* ── Badges ── */

.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.badge-online  { background: #dcfce7; color: #15803d; }
.badge-offline { background: #fee2e2; color: #b91c1c; }
.badge-pending { background: #fef9c3; color: #a16207; }
.badge-image   { background: #dbeafe; color: #1d4ed8; }
.badge-video   { background: #ede9fe; color: #6d28d9; }

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background .15s;
}

.btn:hover { text-decoration: none; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-icon { padding: 8px; gap: 0; }
.btn-icon.btn-sm { padding: 6px; }
.btn-icon svg { width: 16px; height: 16px; display: block; }

/* ── Forms ── */

.form-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; max-width: 600px; }
.form-group { margin-bottom: 18px; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }

input[type="text"],
input[type="email"],
input[type="number"],
input[type="datetime-local"],
input[type="file"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

input[readonly] { background: #f8fafc; color: var(--text-muted); cursor: default; }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.field-error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.form-actions { display: flex; gap: 12px; margin-top: 24px; }

/* ── Detail grid ── */

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; }
.detail-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.detail-value { font-size: 14px; margin-top: 2px; }

.token-box {
  font-family: monospace;
  font-size: 13px;
  background: #f1f5f9;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  word-break: break-all;
}

/* ── Playlist items ── */

.playlist-items { list-style: none; }

.playlist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.playlist-item:last-child { border-bottom: none; }
.playlist-item-pos { width: 24px; text-align: center; font-weight: 700; color: var(--text-muted); font-size: 12px; }
.playlist-item-title { flex: 1; font-weight: 500; }
.playlist-item-dur { color: var(--text-muted); font-size: 13px; min-width: 80px; }
.playlist-item-actions { display: flex; gap: 6px; }

/* ── Media preview ── */

.media-preview { max-width: 100%; max-height: 300px; border-radius: var(--radius); border: 1px solid var(--border); display: block; margin-bottom: 16px; }

/* ── Player ── */

.player-body { background: #000; margin: 0; padding: 0; overflow: hidden; width: 100vw; height: 100vh; }

#player { width: 100%; height: 100%; position: relative; background: #000; }

.media-item {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  display: none;
}

.media-item.active { display: block; }

.player-collage {
  width: 100%;
  height: 100%;
  display: grid;
  background: #000;
}

/* A screen configured as "vertical" hangs in portrait. If the device rotated its own display the
   viewport is already portrait and everything below fills it as-is; if it didn't (common on the
   mini PCs and TV boxes that only output landscape) the whole stage is turned 90° here, so the
   collage grid and each media item are laid out against a 9:16 canvas and read upright on the
   physical panel. Only "vertical" rotates — a horizontal screen is left alone so that opening a
   player URL on a phone to check it stays readable. */
@media (orientation: landscape) {
  .player-body[data-orientation="vertical"] #player,
  .player-body[data-orientation="vertical"] .player-fallback {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vh;
    height: 100vw;
    transform-origin: 0 0;
    transform: translateX(100vw) rotate(90deg);
  }
}

/* Sin fondo propio a proposito: es lo que deja que el relleno de una zona con contain sea
   transparente y se vea la capa de fondo del template por debajo (o el negro de .player-collage
   donde no hay ninguna). */
.collage-cell { position: relative; overflow: hidden; min-width: 0; min-height: 0; }

/* Una pieza de la linea de tiempo de la zona. Todas ocupan la zona entera, una encima de la otra,
   y se ve solo la que le toca (la marca player_controller). */
.collage-slot { position: absolute; inset: 0; display: none; }
.collage-slot.active { display: block; }

/* El encuadre por defecto es entrar entera: una pieza de carteleria se diseña para su zona y
   recortarla le come texto de los bordes — un diagrama de linea perdia estaciones arriba y abajo.
   Donde la proporcion no coincide quedan bandas transparentes en vez de contenido perdido. Es
   ademas lo que hacen el reproductor secuencial y los streams. */
.collage-media { width: 100%; height: 100%; object-fit: contain; display: block; }

/* La otra mitad del encuadre: llenar la zona recortando lo que sobra. La clase la pone el item
   segun su ajuste (entera / llenar / automatico, este ultimo decidido por cuanto habria que
   recortar), y la capa de fondo cae siempre aca: un fondo existe para tapar la pantalla entera,
   asi que si entra entero deja de cubrir y asoma el negro de .player-collage por los bordes. */
.collage-cell-fill .collage-media { object-fit: cover; }

.stream-video { width: 100%; height: 100%; object-fit: contain; display: block; }

/* — zocalo de texto en bucle —————————————————————————————————————————————
   container-type: size hace que .ticker sea el contenedor de consulta de lo que tiene adentro,
   que es lo que permite medir el cuerpo de letra en cqh (% del alto de la zona) en vez de en px.
   Una zona ocupa una fraccion de la grilla, asi que su alto real depende de la resolucion de la
   pantalla: un tamano fijo en px que queda bien en 1080p se ve a la mitad en un panel 4K. */
.ticker {
  container-type: size;
  position: absolute; inset: 0;
  display: flex; align-items: center;
  overflow: hidden;
  background: #111;
  color: #fff;
}
.ticker-track {
  display: flex; flex-wrap: nowrap; align-items: center;
  /* La cinta se corre hacia la izquierda el ancho de una copia, asi que tiene que poder
     desbordar el contenedor a lo ancho sin que flex la comprima. */
  flex: none; will-change: transform;
}
.ticker-copy {
  flex: none;
  white-space: nowrap;
  font-family: system-ui, sans-serif;
  font-weight: 600;
  line-height: 1;
  /* El espacio entre repeticiones va como padding de la propia copia: asi entra en el ancho que
     mide el controlador y la vuelta del bucle sigue cayendo justo. */
  padding-inline-end: 4ch;
  font-size: 28px;                      /* si el navegador no soporta container queries */
  font-size: var(--ticker-font-size);
}

/* El mismo zocalo ocupando la pantalla entera, cuando el texto es un elemento mas de una
   playlist secuencial en vez de una zona de un collage. */
.text-item { position: relative; width: 100%; height: 100%; }

.stream-fallback {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: #111;
  color: #ccc;
  font-size: 1.1rem;
}

.stream-error .stream-fallback { display: flex; }

.collage-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
}

.player-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  color: #555;
  font-size: 18px;
  background: #111;
}

/* Entrada de los kioscos (/player): el código de vinculación se lee desde unos metros. */
.device-pairing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  height: 100vh;
  padding: 24px;
  box-sizing: border-box;
  background: #111;
  color: #ddd;
  font-family: system-ui, sans-serif;
  text-align: center;
}

.device-pairing-logo { height: 56px; width: auto; }
.device-pairing-panel { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.device-pairing-panel[hidden] { display: none; }
.device-pairing-lead { margin: 0; font-size: clamp(18px, 2.4vw, 32px); }

.device-pairing-code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: clamp(64px, 12vw, 180px);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  line-height: 1;
}

.device-pairing-hint { margin: 0; font-size: clamp(14px, 1.6vw, 22px); color: #aaa; }
.device-pairing-status { margin: 0; font-size: clamp(13px, 1.3vw, 18px); color: #888; }
.device-pairing-host { margin: 0; font-size: 13px; color: #666; }

/* ── Devise ── */

.devise-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--body-bg);
}

.devise-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  width: 360px;
}

.devise-title { font-size: 20px; font-weight: 700; margin-bottom: 24px; text-align: center; }

.devise-card p { font-size: 13px; text-align: center; margin-top: 12px; }
