/* =====================================================
   DENARIUS - PANTALLA TV VERTICAL 9:16 + ÚLTIMOS LLAMADOS
   Diseño Vertical Responsive (Móvil / Preview / TV FHD & 4K)
   Estética Romana Moderna (Piedra Travertino & Roble Claro)
   ===================================================== */

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

html,
body.tv-body,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  color: var(--roman-ink);
  background-color: var(--stone-canvas);
}

.mono-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* =====================================================
   LAYOUT VERTICAL ELÁSTICO: TABLA ELÁSTICA + BLOQUES AUTO
   ===================================================== */
main.tv-layout,
.tv-layout {
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: clamp(8px, 1.1vh, 18px);
  padding: clamp(8px, 1.2vh, 22px) clamp(10px, 1.8vw, 26px);
  overflow: hidden;
}

.tv-block {
  min-height: 0;
  background: var(--stone-slab);
  border: 1px solid var(--stone-border);
  border-left: 4px solid #C8A97E;
  border-radius: clamp(16px, 2vh, 24px);
  box-shadow: var(--roman-shadow);
  backdrop-filter: blur(10px);
  overflow: hidden;
}

/* =====================================================
   BLOQUE 1: HEADER + PIZARRA (SOLO BANDERITA + COMPRA + VENTA)
   ===================================================== */
.tv-rates-block {
  display: flex;
  flex-direction: column;
  padding: clamp(8px, 1.15vh, 18px) clamp(10px, 1.7vw, 24px);
  gap: clamp(5px, 0.8vh, 12px);
}

.tv-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(8px, 1.2vw, 16px);
  padding: clamp(7px, 1.05vh, 15px) clamp(10px, 1.5vw, 20px);
  background: var(--wood-surface);
  border: 1px solid var(--wood-border);
  border-radius: clamp(12px, 1.6vh, 18px);
  box-shadow: var(--roman-shadow-sm);
}

.tv-brand {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.2vw, 16px);
  min-width: 0;
}

.tv-logo-badge {
  width: clamp(34px, min(4vh, 7.5vw), 58px);
  height: clamp(34px, min(4vh, 7.5vw), 58px);
}

.tv-brand-titles {
  min-width: 0;
}

.tv-brand-titles h1 {
  margin: 0;
  font-family: var(--font-roman);
  font-size: clamp(1.02rem, min(2.05vh, 4vw), 2.15rem);
  font-weight: 800;
  letter-spacing: 0.13em;
  line-height: 1.05;
  color: var(--roman-ink);
  text-transform: uppercase;
  white-space: nowrap;
}

.tv-brand-titles p {
  margin: 2px 0 0;
  font-family: var(--font-sans);
  font-size: clamp(0.56rem, min(0.92vh, 2.2vw), 0.84rem);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--roman-ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tv-header-right {
  display: flex;
  align-items: center;
  gap: clamp(5px, 0.9vw, 12px);
  flex-shrink: 0;
}

.tv-voice-btn,
#voice-toggle-btn {
  width: clamp(30px, min(3.5vh, 7vw), 42px);
  height: clamp(30px, min(3.5vh, 7vw), 42px);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(255, 253, 250, 0.92);
  border: 1px solid var(--stone-border-strong);
  color: var(--roman-ink-soft);
  font-size: clamp(0.84rem, 1.4vh, 1.15rem);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.18s ease;
}

.tv-voice-btn.active,
#voice-toggle-btn.active {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.42);
  color: #065F46;
}

.tv-conn-pill {
  padding: 5px 10px;
  font-size: clamp(0.6rem, 0.92vh, 0.8rem);
  white-space: nowrap;
}

.tv-clock-box {
  text-align: right;
  padding-left: clamp(6px, 0.95vw, 14px);
  border-left: 1px solid var(--wood-border);
}

.tv-clock,
#tv-clock {
  font-family: var(--font-mono);
  font-size: clamp(0.96rem, min(1.95vh, 3.6vw), 1.95rem);
  font-weight: 800;
  line-height: 1;
  color: var(--roman-ink);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.tv-date,
#tv-date {
  margin-top: 2px;
  font-family: var(--font-sans);
  font-size: clamp(0.54rem, 0.86vh, 0.78rem);
  font-weight: 600;
  color: var(--roman-ink-soft);
  text-transform: capitalize;
  white-space: nowrap;
}

.tv-rates-head-row {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: clamp(58px, 14.5vw, 114px) minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  padding: 2px clamp(8px, 1.4vw, 18px) clamp(4px, 0.6vh, 8px);
  border-bottom: 1px solid var(--stone-border);
  font-family: var(--font-sans);
  font-size: clamp(0.62rem, min(1vh, 2.3vw), 0.9rem);
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--roman-muted);
}

.tv-rates-head-row .col-curr,
.tv-rates-head-row .col-buy,
.tv-rates-head-row .col-sell {
  text-align: center;
}

.tv-rates-list,
#tv-rates-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 0.68vh, 11px);
}

.tv-rate-row {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: clamp(58px, 14.5vw, 114px) minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  padding: 0 clamp(8px, 1.4vw, 18px);
  border-radius: clamp(11px, 1.5vh, 17px);
  background: var(--stone-tile);
  border: 1px solid var(--stone-border);
  box-shadow: 0 2px 6px rgba(38, 30, 22, 0.025);
  transition: transform 0.2s ease, background-color 0.25s ease, border-color 0.25s ease;
}

.tv-rate-row:nth-child(even) {
  background: var(--stone-tile-alt);
}

.tv-rate-row.flash-up {
  animation: tvFlashUp 1.4s ease-out;
}

.tv-rate-row.flash-down {
  animation: tvFlashDown 1.4s ease-out;
}

.tv-curr-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}

.tv-flag-wrap {
  width: clamp(38px, min(4.6vh, 9.5vw), 82px);
  height: clamp(26px, min(3.15vh, 6.5vw), 56px);
  border-radius: clamp(6px, 0.8vh, 11px);
  overflow: hidden;
  border: 1px solid rgba(28, 25, 23, 0.14);
  box-shadow: 0 3px 8px rgba(28, 25, 23, 0.14);
  flex-shrink: 0;
  background: #FFFFFF;
}

.tv-flag-wrap .flag-icon {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tv-price-cell {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: clamp(12px, 3.6vw, 42px);
  gap: clamp(4px, 0.8vw, 11px);
  min-width: 0;
  white-space: nowrap;
}

.tv-price-val {
  font-family: var(--font-mono);
  font-size: clamp(1.02rem, min(2.45vh, 4.6vw), 2.75rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--roman-ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tv-trend-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(17px, 2vh, 28px);
  height: clamp(17px, 2vh, 28px);
  border-radius: 7px;
  font-family: var(--font-sans);
  font-size: clamp(0.58rem, 0.92vh, 0.84rem);
  font-weight: 800;
  flex-shrink: 0;
}

.tv-trend-badge.trend-up {
  background: rgba(16, 185, 129, 0.16);
  color: var(--profit-green);
}

.tv-trend-badge.trend-down {
  background: rgba(239, 68, 68, 0.16);
  color: var(--loss-red);
}

/* =====================================================
   BLOQUE 2: AVISO DE SALA Y ÚLTIMOS LLAMADOS (ALTO AUTO SIN RECORTES)
   ===================================================== */
.tv-cajas-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(10px, 1.2vh, 18px) clamp(12px, 1.7vw, 22px);
  gap: clamp(8px, 1vh, 14px);
}

.tv-call-banner,
#active-call-banner {
  flex-shrink: 0;
  padding: clamp(7px, 0.95vh, 13px) clamp(12px, 1.6vw, 20px);
  background: var(--wood-surface);
  border: 1px solid var(--wood-border);
  border-radius: clamp(12px, 1.5vh, 16px);
  box-shadow: var(--roman-shadow-sm);
}

.tv-call-banner.is-idle {
  opacity: 0.98;
}

.call-banner-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2px;
}

.call-banner-eyebrow {
  font-family: var(--font-sans);
  font-size: clamp(0.62rem, 0.95vh, 0.84rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--roman-bronze-dark);
}

.call-banner-main {
  font-family: var(--font-sans);
  font-size: clamp(0.88rem, min(1.65vh, 3.4vw), 1.52rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--roman-ink);
}

.call-banner-meta {
  font-family: var(--font-sans);
  font-size: clamp(0.6rem, 0.9vh, 0.84rem);
  font-weight: 600;
  color: var(--roman-ink-soft);
}

.tv-recent-strip {
  flex: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(5px, 0.65vh, 9px);
}

.recent-strip-label {
  font-family: var(--font-sans);
  font-size: clamp(0.6rem, 0.9vh, 0.82rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--roman-muted);
}

.recent-calls-pills,
#tv-recent-calls {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(36px, 4.2vh, 56px);
}

.recent-calls-pills.has-calls,
#tv-recent-calls.has-calls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(6px, 1vw, 14px);
}

.recent-call-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: clamp(7px, 0.85vh, 12px) 8px;
  border-radius: 13px;
  background: var(--stone-tile);
  border: 1.5px solid var(--stone-border);
  text-align: center;
  box-shadow: var(--roman-shadow-sm);
  min-width: 0;
}

.recent-call-pill.is-latest {
  background: linear-gradient(135deg, #FEF3C7, #FDE68A);
  border-color: #F59E0B;
}

.recent-call-desk {
  font-family: var(--font-sans);
  font-size: clamp(0.8rem, min(1.45vh, 3.1vw), 1.32rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--roman-ink);
  white-space: nowrap;
}

.recent-call-time {
  font-family: var(--font-mono);
  font-size: clamp(0.62rem, 0.92vh, 0.84rem);
  font-weight: 700;
  color: var(--roman-ink-soft);
}

.recent-empty {
  font-family: var(--font-sans);
  font-size: clamp(0.74rem, 1.1vh, 0.94rem);
  font-weight: 600;
  color: var(--roman-muted);
}

/* =====================================================
   BLOQUE 3: INFO SUCURSAL EDITABLE (ALTO AUTO SIN RECORTES)
   ===================================================== */
.tv-footer-block {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: clamp(6px, 0.8vh, 11px);
  padding: clamp(9px, 1.15vh, 16px) clamp(12px, 1.8vw, 22px);
  background: var(--wood-surface);
  border: 1px solid var(--wood-border);
  border-left: 4px solid #C8A97E;
}

.tv-ticker-card {
  display: flex;
  align-items: center;
  gap: clamp(9px, 1.4vw, 18px);
  min-width: 0;
}

.ticker-badge {
  flex-shrink: 0;
  padding: clamp(5px, 0.65vh, 8px) clamp(10px, 1.3vw, 15px);
  border-radius: 999px;
  background: linear-gradient(135deg, #29221C, #43372C);
  border: 1px solid #C8A97E;
  color: #E7CCA0;
  font-family: var(--font-sans);
  font-size: clamp(0.6rem, 0.95vh, 0.84rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.tv-ticker-text,
#tv-ticker-text {
  margin: 0;
  font-family: var(--font-sans);
  font-size: clamp(0.82rem, min(1.48vh, 3.1vw), 1.3rem);
  font-weight: 700;
  line-height: 1.3;
  color: var(--roman-ink);
  transition: opacity 0.3s ease, transform 0.3s ease;
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tv-ticker-text.is-fading,
#tv-ticker-text.is-fading {
  opacity: 0;
  transform: translateY(4px);
}

.tv-legal-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding-top: clamp(4px, 0.55vh, 7px);
  border-top: 1px solid var(--wood-border);
  font-family: var(--font-sans);
  font-size: clamp(0.56rem, 0.88vh, 0.78rem);
  font-weight: 600;
  color: var(--roman-ink-soft);
  white-space: nowrap;
}

/* =====================================================
   CARTEL EMERGENTE GIGANTE DE LLAMADO (#call-popup-overlay)
   ===================================================== */
.tv-call-popup-overlay,
#call-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: none;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 48px);
  background: rgba(28, 25, 23, 0.56);
  backdrop-filter: blur(10px);
}

.tv-call-popup-overlay.is-visible,
#call-popup-overlay.is-visible {
  display: flex;
  animation: popupBackdropIn 0.24s ease-out forwards;
}

.tv-call-popup-overlay.is-closing,
#call-popup-overlay.is-closing {
  animation: popupBackdropOut 0.24s ease-in forwards;
}

.call-popup-card,
#call-popup-card {
  position: relative;
  width: min(92vw, 760px);
  max-height: 92dvh;
  padding: clamp(24px, 4.2vh, 52px) clamp(20px, 4vw, 48px);
  border-radius: 28px;
  background: linear-gradient(165deg, #FFFDFA 0%, #F7F2EA 100%);
  border: 2px solid #F59E0B;
  box-shadow:
    0 32px 80px rgba(20, 16, 12, 0.42),
    0 0 0 8px rgba(245, 158, 11, 0.16);
  text-align: center;
  overflow: hidden;
  animation: popupCardIn 0.34s cubic-bezier(0.16, 1, 0.3, 1);
}

#call-popup-card::before,
#call-popup-card::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  background: linear-gradient(90deg, #9E7B4F 0%, #F59E0B 50%, #C8A97E 100%);
}

#call-popup-card::before {
  top: 0;
}

#call-popup-card::after {
  bottom: 0;
}

#call-popup-overlay.is-closing #call-popup-card {
  animation: popupCardOut 0.24s ease-in forwards;
}

.call-popup-eyebrow,
.call-popup-prefix,
#popup-call-eyebrow {
  font-family: var(--font-sans);
  font-size: clamp(0.86rem, min(1.65vh, 3.2vw), 1.32rem);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #B45309;
  margin-bottom: clamp(8px, 1.3vh, 14px);
}

.call-popup-prefix {
  color: var(--roman-muted);
  font-size: clamp(0.78rem, min(1.3vh, 2.8vw), 1.1rem);
  margin-bottom: clamp(4px, 0.8vh, 8px);
}

.call-popup-desk,
#popup-call-desk {
  margin: 0;
  font-family: var(--font-sans);
  font-size: clamp(2.6rem, min(9vh, 15vw), 7.2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  color: #1C1917;
  white-space: nowrap;
  animation: popupDeskPulse 1.2s ease-in-out infinite;
}

.call-popup-sub,
#popup-call-sub {
  margin-top: clamp(10px, 1.7vh, 22px);
  font-family: var(--font-sans);
  font-size: clamp(0.92rem, min(1.8vh, 3.4vw), 1.44rem);
  font-weight: 600;
  color: var(--roman-ink-soft);
}

.call-popup-queue,
#popup-queue-badge {
  display: none;
  margin-top: 14px;
  padding: 6px 14px;
  border-radius: 999px;
  background: #29221C;
  border: 1px solid #C8A97E;
  color: #E7CCA0;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 700;
}

.call-popup-progress-track {
  width: 100%;
  height: 7px;
  margin-top: clamp(18px, 2.8vh, 30px);
  border-radius: 999px;
  background: rgba(200, 169, 126, 0.25);
  overflow: hidden;
}

.call-popup-progress-fill,
#popup-progress-fill {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #F59E0B, #D97706);
  transform-origin: left center;
}

#popup-progress-fill.is-running {
  animation: callTimerBar var(--call-duration, 4500ms) linear forwards;
}

/* =====================================================
   ANIMACIONES Y SALVAGUARDAS RESPONSIVE
   ===================================================== */
@keyframes tvFlashUp {
  0% {
    background-color: rgba(16, 185, 129, 0.22);
    border-color: #10B981;
  }
  100% {
    background-color: var(--stone-tile);
    border-color: var(--stone-border);
  }
}

@keyframes tvFlashDown {
  0% {
    background-color: rgba(239, 68, 68, 0.20);
    border-color: #EF4444;
  }
  100% {
    background-color: var(--stone-tile);
    border-color: var(--stone-border);
  }
}

@keyframes callTimerBar {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

@keyframes popupBackdropIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes popupBackdropOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes popupCardIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes popupCardOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
}

@keyframes popupDeskPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
}

/* Pantallas con poca altura útil (ventanas preview horizontales bajas) */
@media (max-height: 680px) {
  html,
  body.tv-body,
  body {
    overflow-y: auto;
  }

  main.tv-layout,
  .tv-layout {
    height: auto;
    min-height: 100dvh;
    max-height: none;
  }

  .tv-rate-row {
    min-height: 44px;
  }
}

/* Pantallas muy angostas */
@media (max-width: 440px) {
  main.tv-layout,
  .tv-layout {
    padding: 8px;
    gap: 8px;
  }

  .tv-rates-block,
  .tv-cajas-block,
  .tv-footer-block {
    padding: 9px 10px;
  }

  #tv-conn-text {
    display: none;
  }

  .tv-conn-pill {
    padding: 6px;
  }

  .recent-calls-pills.has-calls,
  #tv-recent-calls.has-calls {
    gap: 6px;
  }
}
