*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:        #0f1117;
  --bg-panel:       #1a1d27;
  --bg-input:       #0f1117;
  --border:         #2a2d3a;
  --text-primary:   #e8eaf0;
  --text-secondary: #8b92a8;
  --text-subtle:    #c5c9d6;
  --row-hover:      #1f2230;
  --row-border:     #1f2230;
  --no-clip:        #3a3d4d;
  --chart-grid:     #2a2d3a;
}

body.light {
  --bg-base:        #f4f6fa;
  --bg-panel:       #ffffff;
  --bg-input:       #ffffff;
  --border:         #e2e5ed;
  --text-primary:   #1a1d27;
  --text-secondary: #5a6070;
  --text-subtle:    #2d3345;
  --row-hover:      #f0f3f9;
  --row-border:     #eef0f5;
  --no-clip:        #b0b8cc;
  --chart-grid:     #e2e5ed;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

.hidden { display: none !important; }

/* ── Login ──────────────────────────────────────────────────────────────────── */
#view-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.login-title { font-size: 1.7rem; font-weight: 700; }
.card .subtitle { color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 2rem; }

form { display: flex; flex-direction: column; gap: 0.75rem; }

input[type="email"], input[type="password"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.95rem;
  padding: 0.7rem 1rem;
  outline: none;
  width: 100%;
}
input:focus { border-color: #4f8ef7; }

button {
  background: #4f8ef7;
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.75rem;
  transition: background 0.15s;
}
button:hover { background: #3a7ae0; }

.error { color: #f87171; font-size: 0.85rem; }

/* ── Logo dot ───────────────────────────────────────────────────────────────── */
.logo-dot {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #4f8ef7;
  display: inline-block;
  flex-shrink: 0;
}
.logo-dot.small { width: 10px; height: 10px; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 2rem;
  position: sticky;
  top: 0;
  z-index: 10;
  transition: background 0.2s;
}

.header-left { display: flex; align-items: center; gap: 0.6rem; }
.header-brand { font-size: 1rem; font-weight: 700; }
.header-client {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--border);
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
}

.header-right { display: flex; align-items: center; gap: 1rem; }
#header-user { font-size: 0.85rem; color: var(--text-secondary); }

#btn-theme {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0.35rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
#btn-theme:hover { background: var(--border); color: var(--text-primary); }

#btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.8rem;
  padding: 0.35rem 0.85rem;
}
#btn-logout:hover { background: var(--border); }

/* ── Dashboard layout ───────────────────────────────────────────────────────── */
.dashboard {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Filtros ─────────────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  flex-wrap: wrap;
  transition: background 0.2s;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.filter-group label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-group input[type="date"],
.filter-group select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-primary);
  font-size: 0.88rem;
  padding: 0.45rem 0.75rem;
  outline: none;
  min-width: 140px;
}
.filter-group select { cursor: pointer; }

.filters button {
  padding: 0.48rem 1.25rem;
  font-size: 0.88rem;
  align-self: flex-end;
}

/* ── Tarjetas de resumen ─────────────────────────────────────────────────────── */
.summary-cards {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.summary-card {
  flex: 1;
  min-width: 200px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent, #4f8ef7);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: background 0.2s;
}

.card-brand { font-size: 0.8rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.06em; }

.card-stat { display: flex; flex-direction: column; gap: 0.1rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--accent, #e8eaf0); }
.stat-label { font-size: 0.75rem; color: var(--text-secondary); }

.no-data { color: var(--text-secondary); font-size: 0.9rem; padding: 1rem 0; }

/* ── Panel Unificado ─────────────────────────────────────────────────────────── */
.sistema-chips { display: flex; gap: 0.75rem; padding-top: 0.35rem; }
.sistema-chip { display: flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; cursor: pointer; }
.sistema-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-tv { background: #3b82f6; }
.dot-audio { background: #f97316; }

.uni-rank-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 760px) { .uni-rank-cols { grid-template-columns: 1fr; } }

.uni-rank-list { list-style: none; margin-top: 0.75rem; }
.uni-rank-list > li { border-bottom: 1px solid var(--row-border); font-size: 0.88rem; }
.uni-rank-list > li:last-child { border-bottom: none; }
.uni-rank-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0; }
.uni-rank-row.uni-rank-expandible { cursor: pointer; }
.uni-rank-sw { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.uni-rank-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uni-rank-bar-wrap { width: 60px; height: 5px; background: var(--row-hover); border-radius: 100px; overflow: hidden; flex-shrink: 0; }
.uni-rank-bar { height: 100%; border-radius: 100px; }
.uni-rank-count { font-weight: 600; width: 32px; text-align: right; flex-shrink: 0; }
.uni-rank-versiones { color: var(--text-secondary); font-weight: 400; font-size: 0.8em; }
.uni-rank-chevron { display: inline-block; font-size: 0.75em; }
.uni-rank-detail {
  list-style: none; margin: 0 0 0.6rem 1.4rem; padding-left: 0.6rem;
  border-left: 2px solid var(--row-border); display: flex; flex-direction: column; gap: 0.3rem;
}
.uni-rank-detail li {
  font-size: 0.78rem; color: var(--text-secondary); padding: 0; border: none;
  white-space: normal; overflow: visible;
}

.uni-media-grid { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.75rem; }
.uni-media-card {
  display: flex; align-items: center; gap: 0.7rem;
  border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.7rem;
}
.uni-media-thumb {
  width: 40px; height: 40px; border-radius: 6px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: white; font-size: 1rem;
}
.uni-media-thumb-video {
  width: 40px; height: 40px; border-radius: 6px; flex-shrink: 0;
  object-fit: cover; background: var(--row-hover); pointer-events: none;
}
.uni-media-info { min-width: 0; flex: 1; }
.uni-media-title { font-size: 0.86rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uni-media-meta { font-size: 0.76rem; color: var(--text-secondary); }
.uni-media-play {
  border: 1px solid var(--border); border-radius: 50%; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center; color: var(--text-secondary);
  background: transparent; cursor: pointer; flex-shrink: 0;
}

/* ── Gráfico ─────────────────────────────────────────────────────────────────── */
.chart-section {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  transition: background 0.2s;
}

.chart-section h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-subtle);
  margin-bottom: 1rem;
}

.chart-wrap {
  height: 240px;
  position: relative;
}

/* ── Tabla ───────────────────────────────────────────────────────────────────── */
.table-section {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  transition: background 0.2s;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.table-header h2 { font-size: 0.95rem; font-weight: 600; color: var(--text-subtle); }
.table-header-right { display: flex; align-items: center; gap: 0.75rem; }
.table-count { font-size: 0.8rem; color: var(--text-secondary); }

.btn-export {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  transition: border-color 0.15s, color 0.15s;
}
.btn-export:hover { border-color: #3b82f6; color: #3b82f6; }

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--row-border);
  color: var(--text-subtle);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--row-hover); }

td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.conf { color: #4f8ef7; }

.brand-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--c, #4f8ef7) 15%, transparent);
  color: var(--c, #4f8ef7);
}

.table-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 2rem;
  font-size: 0.9rem;
}

td.no-clip { color: var(--no-clip); text-align: center; }

.btn-play {
  background: #1e3a5f;
  border: 1px solid #2563eb;
  border-radius: 6px;
  color: #60a5fa;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-play:hover { background: #2563eb; color: #fff; }

/* ── Modal player ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 780px;
  max-height: 88vh;
  overflow-y: auto;
  padding-bottom: 1.25rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-subtle);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  z-index: 1;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem 0.5rem;
}
.btn-close:hover { color: var(--text-primary); background: transparent; }

#modal-video {
  width: 100%;
  display: block;
  background: #000;
  max-height: 440px;
}

/* ── Paginación ──────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

.pagination button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.35rem 0.9rem;
}
.pagination button:hover:not(:disabled) { background: var(--border); color: var(--text-primary); }
.pagination button:disabled { opacity: 0.3; cursor: default; }
.page-info { color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* ── Admin nav ───────────────────────────────────────────────────────────────── */
.admin-nav {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0 1.5rem;
}
.admin-nav-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: -1px;
  padding: 0.75rem 1.25rem;
}
.admin-nav-tab:hover { color: var(--text-primary); }
.admin-nav-tab.active { border-bottom-color: var(--accent, #3b82f6); color: var(--text-primary); }

/* ── Admin panel ─────────────────────────────────────────────────────────────── */
.admin-section { padding: 1.5rem; }
.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.admin-section-header h2 { margin: 0; font-size: 1.1rem; }

.btn-primary {
  background: #3b82f6;
  border: none;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
}
.btn-primary:hover { background: #2563eb; }
.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.45rem 1rem;
}

/* Mismo estilo solido que btn-primary pero con color propio por accion, para
   que cada boton se identifique de un vistazo con lo que hace (pedido por
   Gabriela: Guardar = azul, Subir imagenes = verde, Actualizar reconocimiento
   visual = violeta). */
.btn-upload {
  background: #16a34a;
  border: none;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
}
.btn-upload:hover { background: #15803d; }
.btn-upload:disabled { background: #6b7280; cursor: default; }

.btn-rebuild {
  background: #7c3aed;
  border: none;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
}
.btn-rebuild:hover { background: #6d28d9; }
.btn-rebuild:disabled { background: #6b7280; cursor: default; }

.status-badge {
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.65rem;
}
.status-badge.active   { background: #dcfce7; color: #166534; }
.status-badge.inactive { background: #fee2e2; color: #991b1b; }
body.light .status-badge.active   { background: #dcfce7; color: #166534; }
body.light .status-badge.inactive { background: #fee2e2; color: #991b1b; }

.admin-actions { display: flex; gap: 0.5rem; }
.btn-edit      { background: transparent; border: 1px solid var(--border); border-radius: 4px; color: var(--text-secondary); cursor: pointer; font-size: 0.78rem; padding: 0.25rem 0.6rem; }
.btn-edit:hover { color: var(--text-primary); border-color: var(--text-secondary); }
.btn-deactivate { background: transparent; border: 1px solid #fca5a5; border-radius: 4px; color: #ef4444; cursor: pointer; font-size: 0.78rem; padding: 0.25rem 0.6rem; }
.btn-activate   { background: transparent; border: 1px solid #86efac; border-radius: 4px; color: #22c55e; cursor: pointer; font-size: 0.78rem; padding: 0.25rem 0.6rem; }
.btn-eliminar-usuario { background: #ef4444; border: 1px solid #ef4444; border-radius: 4px; color: #fff; cursor: pointer; font-size: 0.78rem; padding: 0.25rem 0.6rem; }
.btn-eliminar-usuario:hover { background: #dc2626; }

/* ── Usuarios y permisos ─────────────────────────────────────────────────────── */
.permisos-table th, .permisos-table td { text-align: center; padding: 0.5rem 0.75rem; }
.permisos-table th:first-child, .permisos-table td:first-child { text-align: left; }
.permisos-table input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.permisos-table input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.5; }
#btn-guardar-permisos { margin-top: 1rem; }
#permisos-matrix { padding: 1rem 1.25rem; }

/* ── Modal marca ─────────────────────────────────────────────────────────────── */
.admin-form { display: flex; flex-direction: column; gap: 1rem; padding: 1.25rem 0 0; }
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group-checkbox { gap: 0.2rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; font-weight: 500; color: var(--text-primary); text-transform: none; letter-spacing: normal; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.form-group label { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.form-group input { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary); font-size: 0.9rem; padding: 0.5rem 0.75rem; }
.form-group input:focus { border-color: var(--text-secondary); outline: none; }
.form-group select { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary); font-size: 0.9rem; padding: 0.5rem 0.75rem; }
.usuario-tenant-row { display: flex; gap: 0.5rem; }
.usuario-tenant-row select { flex: 1; }
.usuario-tenant-row button { white-space: nowrap; padding: 0.5rem 0.75rem; font-size: 0.85rem; }
.form-group select:focus { border-color: var(--text-secondary); outline: none; }
.form-group textarea { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary); font-size: 0.85rem; font-family: monospace; padding: 0.5rem 0.75rem; resize: vertical; }
.form-group textarea:focus { border-color: var(--text-secondary); outline: none; }
.form-hint { display: block; font-size: 0.78rem; color: var(--text-secondary); margin-top: 0.3rem; }
#marca-activacion h4 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); margin: 0.5rem 0; }
#marca-activacion hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 0.75rem; padding-top: 0.5rem; }
