/* ============================================
   ASISTE · TV — 1080p, modo claro, sin scroll
   ============================================ */

:root {
  --tv-primary: #006D87;        /* Asistecom teal */
  --tv-primary-dark: #00576B;
  --tv-success: #059669;
  --tv-success-bg: #D1FAE5;
  --tv-danger: #DC2626;
  --tv-danger-bg: #FEE2E2;
  --tv-warning: #D97706;
  --tv-warning-bg: #FEF3C7;
  --tv-info: #0891B2;
  --tv-info-bg: #CFFAFE;
  --tv-bg: #F1F5F9;
  --tv-card: #FFFFFF;
  --tv-text: #0F172A;
  --tv-text-secondary: #475569;
  --tv-text-muted: #64748B;
  --tv-border: #CBD5E1;
  --tv-shadow: 0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.04);
  --tv-shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --tv-header-h: 64px;
  --tv-kpi-h: 96px;
  --tv-progress-h: 6px;
  --tv-footer-h: 44px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--tv-bg);
  color: var(--tv-text);
  -webkit-font-smoothing: antialiased;
}
body.tv-loading #tvLoadingScreen { display: flex; }

#tv-root {
  display: grid;
  grid-template-rows: var(--tv-header-h) var(--tv-kpi-h) 1fr var(--tv-progress-h) var(--tv-footer-h);
  height: 100vh;
}

/* Barra full-width de progreso del slide actual */
.tv-slide-progress {
  background: #E2E8F0;
  height: var(--tv-progress-h);
  width: 100%;
  overflow: hidden;
}
.tv-slide-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--tv-primary), #14B8A6, #FBBF24);
  width: 0%;
  transition: width 0.2s linear;
}

/* ===== HEADER (compacto, blanco) ===== */
.tv-header {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  background: white;
  padding: 0 1.25rem;
  box-shadow: var(--tv-shadow);
  z-index: 5;
}
.tv-brand { display: flex; align-items: center; gap: 0.85rem; min-width: 0; }
.tv-logo { height: 36px; width: auto; flex-shrink: 0; }
.tv-brand-divider { width: 1px; height: 32px; background: var(--tv-border); flex-shrink: 0; }
.tv-brand-text { display: flex; flex-direction: column; gap: 0.05rem; min-width: 0; }
.tv-brand-name {
  font-size: 0.78rem;
  color: var(--tv-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
}
.tv-brand-sub {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--tv-text);
  letter-spacing: -0.01em;
}
.tv-header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: flex-end;
}
.tv-countdown-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.05rem;
}
.tv-countdown-label {
  font-size: 0.65rem;
  color: var(--tv-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.tv-countdown {
  font-size: 1.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--tv-primary);
  line-height: 1;
}
.tv-countdown.warning { color: var(--tv-warning); }
.tv-countdown.danger { color: var(--tv-danger); }
.tv-countdown.disabled,
.tv-countdown.text-mode {
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.tv-countdown.text-mode { color: var(--tv-warning); }
.tv-countdown.disabled { color: var(--tv-text-muted); }
.tv-date {
  font-size: 0.7rem;
  color: var(--tv-text-muted);
  text-transform: capitalize;
}
.tv-status-stack { display: flex; flex-direction: column; gap: 0.15rem; align-items: flex-end; }
.tv-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--tv-bg);
  border: 1px solid var(--tv-border);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--tv-text-secondary);
}
.tv-pill .tv-dot { width: 7px; height: 7px; border-radius: 50%; background: #10B981; }
.tv-pill .tv-dot.warning { background: #F59E0B; }
.tv-pill .tv-dot.critical { background: #DC2626; box-shadow: 0 0 0 3px rgba(220,38,38,0.2); animation: pulse 1.4s ease infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 3px rgba(220,38,38,0.2); } 50% { box-shadow: 0 0 0 6px rgba(220,38,38,0.05); } }

/* ===== KPI ROW FIJO ===== */
.tv-kpi-fixed {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.6rem;
  padding: 0.6rem 1.25rem;
  background: white;
  border-top: 1px solid var(--tv-border);
  border-bottom: 1px solid var(--tv-border);
}
.tv-kpi-block {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  background: var(--tv-bg);
  border-radius: 10px;
  border-left: 4px solid var(--tv-primary);
  min-width: 0;
}
.tv-kpi-block.primary { border-left-color: var(--tv-primary); }
.tv-kpi-block.info { border-left-color: var(--tv-info); }
.tv-kpi-block.success { border-left-color: var(--tv-success); }
.tv-kpi-block.danger { border-left-color: var(--tv-danger); }
.tv-kpi-block.warning { border-left-color: var(--tv-warning); }
.tv-kpi-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
  opacity: 0.85;
}
.tv-kpi-data { display: flex; flex-direction: column; min-width: 0; }
.tv-kpi-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--tv-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.tv-kpi-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--tv-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tv-kpi-sub {
  font-size: 0.7rem;
  color: var(--tv-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== STAGE ===== */
.tv-stage {
  position: relative;
  overflow: hidden;
  padding: 0.75rem 1.25rem;
}
.tv-slide {
  position: absolute;
  inset: 0.75rem 1.25rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.tv-slide.active { opacity: 1; pointer-events: auto; z-index: 2; }

/* ===== Big content card ===== */
.tv-card {
  background: var(--tv-card);
  border-radius: 12px;
  padding: 0.8rem 1.1rem;
  box-shadow: var(--tv-shadow);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.tv-card-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--tv-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.55rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--tv-bg);
  flex-shrink: 0;
}
.tv-card-body { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }

/* ===== Tablas ajustadas a alto disponible ===== */
.tv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  table-layout: auto;
}
.tv-table th {
  background: #F8FAFC;
  color: var(--tv-text-secondary);
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  padding: 0.4rem 0.55rem;
  border-bottom: 2px solid var(--tv-border);
  position: sticky;
  top: 0;
}
.tv-table td {
  padding: 0.42rem 0.55rem;
  border-bottom: 1px solid #E2E8F0;
  font-weight: 500;
  white-space: nowrap;
}
.tv-table .num { text-align: right; }
.tv-table .total td {
  font-weight: 800;
  font-size: 1rem;
  background: #F8FAFC;
  border-top: 2px solid var(--tv-text);
}
.tv-table .today { background: #DBEAFE; font-weight: 700; }
.tv-trend-up { color: var(--tv-success); font-weight: 700; }
.tv-trend-down { color: var(--tv-danger); font-weight: 700; }
.tv-trend-flat { color: var(--tv-text-muted); }

.tv-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.tv-badge-success { background: var(--tv-success-bg); color: #065F46; }
.tv-badge-danger { background: var(--tv-danger-bg); color: #991B1B; }
.tv-badge-warning { background: var(--tv-warning-bg); color: #92400E; }

/* ===== Two-col layout para Avance ===== */
.tv-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  flex: 1;
  min-height: 0;
}
.tv-grid-2 > .tv-card { min-height: 0; }
.tv-chart { position: relative; flex: 1; min-height: 0; }

/* ===== FOOTER (compacto) ===== */
.tv-footer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  background: #0F172A;
  color: #FFF;
  align-items: center;
  padding: 0 0.5rem;
  gap: 0.5rem;
  position: relative;
}
.tv-footer-left { display: flex; align-items: center; }
.tv-controls { display: flex; gap: 0.25rem; }
.tv-ctrl {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: white;
  min-width: 32px;
  height: 30px;
  padding: 0 0.4rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.tv-ctrl:hover { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.25); text-decoration: none; }
.tv-ctrl:active { background: rgba(255,255,255,0.25); }
.tv-ctrl.busy { opacity: 0.7; pointer-events: none; }

.tv-footer-center {
  display: flex;
  height: 100%;
  align-items: center;
  overflow: hidden;
  padding: 0 0.5rem;
}
.tv-ticker-wrap {
  position: relative;
  overflow: hidden;
  height: 100%;
  display: flex;
  align-items: center;
}
.tv-ticker {
  white-space: nowrap;
  font-size: 0.95rem;
  font-weight: 600;
  color: #FBBF24;
  animation: tickerScroll 70s linear infinite;
  font-variant-numeric: tabular-nums;
  padding-left: 100%;
}
.tv-ticker .tv-ticker-sep { color: #475569; margin: 0 1rem; font-weight: 400; }
.tv-ticker .tv-ticker-label { color: #94A3B8; margin-right: 0.3rem; font-weight: 500; font-size: 0.85rem; }
@keyframes tickerScroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}
.tv-footer-right { display: flex; align-items: center; gap: 0.6rem; }
.tv-slide-indicator { display: flex; gap: 0.3rem; align-items: center; }
.tv-slide-indicator .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #475569;
  transition: all 0.3s ease;
}
.tv-slide-indicator .dot.active {
  background: var(--tv-primary);
  width: 22px;
  border-radius: 3px;
}
.tv-pause-overlay {
  font-size: 0.75rem;
  font-weight: 700;
  color: #FBBF24;
  letter-spacing: 0.1em;
}

/* ===== Critical banner ===== */
.tv-critical-banner {
  position: fixed;
  top: var(--tv-header-h);
  left: 0;
  right: 0;
  background: linear-gradient(90deg, #DC2626, #B91C1C);
  color: white;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  z-index: 50;
  animation: slideDown 0.4s ease;
  box-shadow: 0 8px 24px rgba(220, 38, 38, 0.45);
}
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }
.tv-critical-icon { font-size: 1.7rem; }
.tv-critical-title { font-size: 1.1rem; font-weight: 800; }
.tv-critical-message { font-size: 0.92rem; margin-top: 0.05rem; opacity: 0.95; }

/* ===== Loading screen ===== */
.tv-loading-screen {
  display: none;
  position: absolute;
  inset: 0;
  background: var(--tv-bg);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  z-index: 20;
}
.tv-spinner-big {
  width: 50px;
  height: 50px;
  border: 4px solid var(--tv-border);
  border-top-color: var(--tv-primary);
  border-radius: 50%;
  animation: spinBig 0.9s linear infinite;
}
@keyframes spinBig { to { transform: rotate(360deg); } }
.tv-loading-text {
  font-size: 1rem;
  color: var(--tv-text-secondary);
  font-weight: 500;
}

/* ===== Avance bars ===== */
.tv-bar-row {
  display: grid;
  grid-template-columns: 110px 1fr 110px;
  align-items: center;
  gap: 0.6rem;
  padding: 0.25rem 0;
  font-size: 0.85rem;
}
.tv-bar-row .name { font-weight: 600; }
.tv-bar-row .bar-bg { background: #E2E8F0; height: 16px; border-radius: 4px; overflow: hidden; }
.tv-bar-row .bar-fill { background: var(--tv-success); height: 100%; transition: width 0.5s ease; }
.tv-bar-row .bar-fill.danger { background: var(--tv-danger); }
.tv-bar-row .bar-fill.warning { background: var(--tv-warning); }
.tv-bar-row .pct { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.78rem; }

.tv-empty {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  color: var(--tv-text-muted);
  font-size: 1rem;
}

/* ===== Ajustes de zoom segun resolucion ===== */
@media (min-width: 2400px) {
  :root { --tv-header-h: 80px; --tv-kpi-h: 120px; --tv-progress-h: 8px; --tv-footer-h: 56px; }
  body { font-size: 18px; }
  .tv-table { font-size: 1.15rem; }
  .tv-kpi-value { font-size: 1.8rem; }
  .tv-countdown { font-size: 2.1rem; }
  .tv-logo { height: 50px; }
}
@media (max-width: 1366px) {
  body { font-size: 14px; }
  .tv-kpi-value { font-size: 1.2rem; }
  .tv-countdown { font-size: 1.4rem; }
  .tv-logo { height: 30px; }
  .tv-table { font-size: 0.85rem; }
}
