/* ============================================================
   ComuniAds — Smart TV Digital Signage — Versión moderna
   Requiere: Chrome 70+, Firefox 65+, Safari 12+, Edge 79+
   ============================================================ */

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

:root {
  --color-bg:           #0f172a;
  --color-bg-surface:   #1e293b;
  --color-border:       #2d3f5a;
  --color-accent:       #3b82f6;
  --color-accent-dim:   rgba(59,130,246,0.08);
  --color-text-primary:   #f1f5f9;
  --color-text-secondary: #94a3b8;
  --color-text-muted:     #64748b;
  --color-ica-buena:   #22c55e;
  --color-ica-regular: #eab308;
  --color-ica-danina:  #ef4444;
  --font-ui:    system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  --font-mono:  'Courier New', Courier, monospace;
  --font-serif: Georgia, 'Times New Roman', serif;
  --header-h:  100px;
  --main-h:    1570px;
  --t1-h:      125px;
  --t2-h:      125px;
  /* Canvas portrait */
  --canvas-w:  1080px;
  --canvas-h:  1920px;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden; background: #000;
  font-family: var(--font-ui); font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-rows: var(--header-h) var(--main-h) var(--t1-h) var(--t2-h);
  width:  var(--canvas-w);   /* 1080px */
  height: var(--canvas-h);   /* 1920px */
  overflow: hidden;
  position: relative;
  transform-origin: top left;
  background: var(--color-bg);
  color: var(--color-text-primary);
}

/* ── HEADER ── */
#header {
  display: flex; align-items: center;
  justify-content: space-between; padding: 0 24px;
  background: var(--color-bg-surface);
  border-bottom: 2px solid var(--color-accent);
  position: relative;
}

.header-logo { display: flex; align-items: center; gap: 14px; }

.logo-mark {
  width: 48px; height: 48px; border-radius: 10px;
  background: var(--color-accent); display: flex;
  align-items: center; justify-content: center;
}
.logo-mark svg { width: 28px; height: 28px; fill: #fff; }

.logo-name {
  font-size: 24px; font-weight: 700;
  letter-spacing: -0.03em; color: var(--color-text-primary);
}
.logo-name span { color: var(--color-accent); }
.logo-tagline {
  font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--color-text-muted); margin-top: 2px;
}

.header-community { display: flex; flex-direction: column; align-items: center; }
.community-label {
  font-size: 11px; letter-spacing: 0.15em;
  text-transform: uppercase; color: var(--color-text-muted);
}
.community-name { font-size: 20px; font-weight: 600; } /* reducido de 26px para portrait 1080px */

.header-clock { display: flex; flex-direction: column; align-items: flex-end; }
.clock-capsule {
  background: var(--color-bg); border: 1px solid var(--color-border);
  border-top: 2px solid var(--color-accent); border-radius: 8px;
  padding: 4px 18px; display: flex; align-items: baseline;
}
#clock-time {
  font-family: var(--font-mono); font-size: 44px;
  color: var(--color-text-primary); font-variant-numeric: tabular-nums; line-height: 1;
}
#clock-seconds {
  font-family: var(--font-mono); font-size: 26px;
  color: var(--color-accent); opacity: .85; line-height: 1;
}
#clock-date { font-size: 13px; color: var(--color-text-secondary); margin-top: 5px; text-align: right; }

/* ── MAIN ── */
#main-content {
  display: grid;
  overflow: hidden;
}

/* ── AVISOS RANDOM ── */
#avisos_random {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

/* Contenedor de slides */
#avisos-slides {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Cada slide */
.aviso-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.8s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.aviso-slide.active {
  opacity: 1;
  z-index: 1;
}

.aviso-slide.prev {
  opacity: 0;
  z-index: 0;
}

/* Imagen del slide */
.aviso-slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

/* Video del slide */
.aviso-slide video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Overlay superior (badge + contador) */
#avisos-overlay-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  padding: 20px 28px 60px;
  background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.avisos-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(59,130,246,0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(59,130,246,0.5);
  border-radius: 24px;
  padding: 8px 18px;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.04em;
}

.avisos-badge svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.avisos-counter {
  font-family: var(--font-mono);
  font-size: 22px;
  color: rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.4);
  padding: 6px 14px;
  border-radius: 20px;
  letter-spacing: 0.05em;
}

/* Overlay inferior (dots + barra de progreso) */
#avisos-overlay-bottom {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 10;
  padding: 60px 28px 24px;
  background: linear-gradient(0deg, rgba(0,0,0,0.65) 0%, transparent 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Dots de navegación */
#avisos-dots {
  display: flex;
  gap: 10px;
  align-items: center;
}

.aviso-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  border: 1px solid rgba(255,255,255,0.2);
  transition: all 0.3s ease;
  cursor: pointer;
}

.aviso-dot.active {
  background: #fff;
  width: 28px;
  border-radius: 5px;
  border-color: transparent;
}

/* Barra de progreso del slide actual */
.avisos-progress-bar {
  width: 100%;
  max-width: 400px;
  height: 3px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  overflow: hidden;
}

#avisos-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-accent), #60a5fa);
  border-radius: 2px;
  transition: width linear;
}

/* ── PANELS (ocultos temporalmente) ── */
#panel-left {
  background: var(--color-bg); border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
#panel-left::before {
  content: ''; position: absolute; inset: 0;
  background-image: radial-gradient(circle, var(--color-border) 1px, transparent 1px);
  background-size: 40px 40px; opacity: .3; pointer-events: none;
}
#panel-left::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, var(--color-bg) 100%);
  pointer-events: none;
}
.welcome-inner {
  position: relative; z-index: 1; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 24px;
}
.welcome-icon {
  width: 110px; height: 110px; border-radius: 50%;
  background: var(--color-accent-dim); border: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: center;
}
.welcome-icon svg { width: 56px; height: 56px; fill: var(--color-accent); opacity: .7; }
.welcome-label { font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--color-text-muted); }
.welcome-title { font-size: 52px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.welcome-sub { font-size: 16px; color: var(--color-text-secondary); max-width: 560px; line-height: 1.6; }

#panel-right {
  background: var(--color-bg-surface);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel-right-hdr { padding: 24px 28px 16px; border-bottom: 1px solid var(--color-border); }
.panel-right-hdr .lbl { font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--color-text-muted); margin-bottom: 4px; }
.panel-right-hdr .ttl { font-size: 22px; font-weight: 600; }
.panel-right-hdr .sub { font-size: 13px; color: var(--color-text-secondary); margin-top: 2px; }

#ica-container { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.ica-loading { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; color: var(--color-text-muted); }
.spinner { width: 28px; height: 28px; border: 2px solid var(--color-border); border-top-color: var(--color-accent); border-radius: 50%; animation: spin .8s linear infinite; }

.ica-card {
  flex: 1; display: flex; flex-direction: column;
  justify-content: center; padding: 20px 28px;
  border-bottom: 1px solid var(--color-border);
  position: relative; overflow: hidden;
}
.ica-card:last-child { border-bottom: none; }
.ica-card::before { content: ''; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: var(--ica-color, var(--color-accent)); }
.ica-card-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; }
.ica-comuna { font-size: 22px; font-weight: 700; }
.ica-region { font-size: 11px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 3px; }
.ica-num { font-family: var(--font-mono); font-size: 48px; color: var(--ica-color, var(--color-accent)); line-height: 1; }
.ica-num-lbl { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--color-text-muted); text-align: right; }
.ica-bar-track { height: 5px; background: var(--color-bg); border-radius: 3px; overflow: hidden; }
.ica-bar-fill { height: 100%; border-radius: 3px; background: var(--ica-color, var(--color-accent)); width: 0; transition: width 1s ease-out; }
.ica-estado { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; padding: 4px 10px; border-radius: 4px; border: 1px solid var(--ica-color, var(--color-border)); width: fit-content; }
.ica-estado-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ica-color, #fff); }
.ica-estado-txt { font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ica-color, var(--color-text-primary)); }

.ica-legend { padding: 12px 28px; border-top: 1px solid var(--color-border); }
.ica-legend-lbl { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--color-text-muted); margin-bottom: 6px; }
.ica-legend-bar { display: flex; height: 5px; border-radius: 3px; overflow: hidden; }
.ica-legend-bar span:nth-child(1){flex:1;background:#22c55e}
.ica-legend-bar span:nth-child(2){flex:1;background:#84cc16}
.ica-legend-bar span:nth-child(3){flex:1;background:#eab308}
.ica-legend-bar span:nth-child(4){flex:1;background:#f97316}
.ica-legend-bar span:nth-child(5){flex:1;background:#ef4444}
.ica-legend-bar span:nth-child(6){flex:1;background:#7c3aed}
.ica-legend-lbls { display: flex; justify-content: space-between; margin-top: 4px; }
.ica-legend-lbls span { font-size: 10px; color: var(--color-text-muted); }

/* ── TICKERS ── */
.ticker-wrap {
  display: flex; align-items: stretch;
  overflow: hidden; position: relative; flex-shrink: 0;
}
#ticker1 { height: var(--t1-h); background: #0a0a0a; border-top: 3px solid #f59e0b; }
#ticker2 { height: var(--t2-h); background: #1a2e1a; border-top: 3px solid rgba(245,240,232,.3); }

/* ── TICKER LABEL — cápsula fija izquierda ── */
.ticker-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 110px;
  max-width: 110px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

#ticker1 .ticker-label {
  background: linear-gradient(180deg, #2a1800 0%, #1a1000 100%);
  border-right: 2px solid #f59e0b;
  box-shadow: 4px 0 20px rgba(245,158,11,0.15);
}

#ticker2 .ticker-label {
  background: linear-gradient(180deg, #1e3a1e 0%, #132213 100%);
  border-right: 2px solid rgba(245,240,232,0.3);
  box-shadow: 4px 0 20px rgba(245,240,232,0.05);
}

/* Indicador LIVE pulsante */
.ticker-label::before {
  content: '';
  position: absolute;
  top: 14px;
  right: 12px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  animation: pulse-live 2s ease-in-out infinite;
}

#ticker1 .ticker-label::before {
  background: #f59e0b;
  box-shadow: 0 0 0 0 rgba(245,158,11,0.6);
}

#ticker2 .ticker-label::before {
  background: #4ade80;
  box-shadow: 0 0 0 0 rgba(74,222,128,0.6);
  animation-name: pulse-live-green;
}

@keyframes pulse-live {
  0%   { box-shadow: 0 0 0 0 rgba(245,158,11,0.7); }
  70%  { box-shadow: 0 0 0 8px rgba(245,158,11,0); }
  100% { box-shadow: 0 0 0 0 rgba(245,158,11,0); }
}

@keyframes pulse-live-green {
  0%   { box-shadow: 0 0 0 0 rgba(74,222,128,0.7); }
  70%  { box-shadow: 0 0 0 8px rgba(74,222,128,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}

.ticker-lbl-icon {
  font-size: 36px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.05em;
}
#ticker1 .ticker-lbl-icon {
  color: #f59e0b;
  text-shadow: 0 0 20px rgba(245,158,11,0.6), 0 0 40px rgba(245,158,11,0.3);
}
#ticker2 .ticker-lbl-icon {
  color: #f5f0e8;
  font-size: 28px;
}

.ticker-lbl-text {
  font-size: 9px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  font-weight: 800;
}
#ticker1 .ticker-lbl-text { color: rgba(245,158,11,0.7); }
#ticker2 .ticker-lbl-text { color: rgba(245,240,232,0.5); }

.ticker-mask { position: absolute; top: 0; bottom: 0; width: 80px; z-index: 1; pointer-events: none; }
.ticker-mask.left  { left: 110px; }
.ticker-mask.right { right: 0; }
#ticker1 .ticker-mask.left  { background: linear-gradient(90deg,  #0a0a0a, transparent); }
#ticker1 .ticker-mask.right { background: linear-gradient(270deg, #0a0a0a, transparent); }
#ticker2 .ticker-mask.left  { background: linear-gradient(90deg,  #1a2e1a, transparent); }
#ticker2 .ticker-mask.right { background: linear-gradient(270deg, #1a2e1a, transparent); }

.ticker-viewport { flex: 1; overflow: hidden; display: flex; align-items: center; height: 100%; }
.ticker-track { display: flex; align-items: center; white-space: nowrap; will-change: transform; height: 100%; }

@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}
.ticker-track.running { animation: ticker-scroll var(--ticker-dur, 60s) linear infinite; }

/* ── TICKER 1 ITEMS — estilo financiero ── */
#ticker1 .ticker-item {
  font-family: var(--font-mono);
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 0 12px;
  height: 100%;
  position: relative;
}

#ticker1 .ticker-item::before { display: none; }

.ticker-icono {
  font-size: 28px;
  font-weight: 700;
  font-family: var(--font-mono);
  margin-right: 10px;
  color: #f59e0b;
  line-height: 1;
}

.ticker-prefix {
  font-size: 13px;
  letter-spacing: 0.22em;
  color: rgba(245,158,11,0.75);
  text-transform: uppercase;
  margin-right: 10px;
  align-self: flex-end;
  padding-bottom: 8px;
  font-weight: 600;
}

.ticker-valor {
  font-size: 58px;
  font-weight: 700;
  color: #f59e0b;
  letter-spacing: -0.03em;
  line-height: 1;
  text-shadow: 0 0 30px rgba(245,158,11,0.35);
}

/* Separador ticker 1 — línea vertical elegante */
#ticker1 .ticker-sep {
  display: inline-flex;
  align-items: center;
  height: 60%;
  width: 1px;
  background: rgba(245,158,11,0.2);
  margin: 0 28px;
  opacity: 1;
  font-size: 0;
  vertical-align: middle;
  align-self: center;
}

/* ── TICKER 2 ITEMS — estilo editorial + info ── */
#ticker2 .ticker-item {
  font-family: var(--font-serif);
  font-size: 28px;
  color: #f5f0e8;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  height: 100%;
}

#ticker2 .ticker-item::before { display: none; }

/* Badge coloreado para el estado ICA */
.ticker-estado {
  display: inline-flex;
  align-items: center;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: var(--font-ui);
}
.ticker-estado.buena   { background: rgba(34,197,94,0.2);  color: #4ade80; border: 1px solid rgba(74,222,128,0.4); }
.ticker-estado.regular { background: rgba(234,179,8,0.2);  color: #fbbf24; border: 1px solid rgba(251,191,36,0.4); }
.ticker-estado.danina  { background: rgba(239,68,68,0.2);  color: #f87171; border: 1px solid rgba(248,113,113,0.4); }

/* Icono para cada item de farmacia */
.ticker-farma-icon {
  font-size: 24px;
  color: #f5f0e8;
  opacity: 0.85;
  flex-shrink: 0;
}

/* Badge contenedor del nombre — Tailwind maneja el layout */
.ticker-farma-badge {
  line-height: 1;
}

/* Nombre farmacia en bold */
.ticker-farma-nombre {
  font-size: 28px;
  font-weight: 700;
  color: #ffffff;
  font-family: var(--font-serif);
  letter-spacing: -0.01em;
  line-height: 1;
}

/* Pill de comuna — Tailwind maneja color/layout; CSS custom solo fuente */
.ticker-farma-comuna {
  font-family: var(--font-ui);
  font-size: 14px;
}

/* Dirección farmacia — legible, crema cálido, sin itálica */
.ticker-farma-info {
  font-size: 20px;
  font-family: var(--font-serif);
  color: #e8e0d0;
  font-style: normal;
  font-weight: 400;
  opacity: 1;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* Icono de ubicación ◎ previo a la dirección */
.ticker-farma-dir-icon {
  font-size: 16px;
  color: rgba(245,240,232,0.5);
  font-family: var(--font-ui);
  flex-shrink: 0;
  line-height: 1;
}

/* Separador ticker 2 — entre ítems del mismo grupo */
#ticker2 .ticker-sep {
  display: inline-block;
  width: 4px;
  height: 4px;
  background: rgba(245,240,232,0.3);
  border-radius: 50%;
  margin: 0 32px;
  align-self: center;
  flex-shrink: 0;
  font-size: 0;
  vertical-align: middle;
}

/* ── TICKER 2 — Títulos de grupo ── */
.t2-group-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px 0 14px;
  height: 100%;
  flex-shrink: 0;
}

.t2-group-title-icon {
  font-size: 20px;
  color: #f59e0b;
  line-height: 1;
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(245,158,11,0.5));
}

.t2-group-title-text {
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #f59e0b;
  text-shadow: 0 0 20px rgba(245,158,11,0.35);
  white-space: nowrap;
}

/* ── TICKER 2 — Separador de grupo (entre bloques farmacia e ICA) ── */
.t2-group-sep {
  display: inline-block;
  width: 3px;
  height: 52%;
  background: linear-gradient(180deg,
    transparent 0%,
    rgba(245,158,11,0.6) 30%,
    rgba(245,158,11,0.6) 70%,
    transparent 100%
  );
  border-radius: 2px;
  margin: 0 48px;
  align-self: center;
  flex-shrink: 0;
  vertical-align: middle;
}

/* ── TICKER 2 — Punto medio entre campos de farmacia ── */
.ticker-farma-dot {
  font-size: 22px;
  color: rgba(245,240,232,0.35);
  margin: 0 6px;
  line-height: 1;
  flex-shrink: 0;
  font-family: var(--font-ui);
}

/* ICA valor prominente */
.ticker-ica-valor {
  font-family: var(--font-mono);
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #f5f0e8;
}

/* ICA comuna */
.ticker-ica-comuna {
  font-weight: 600;
  font-size: 28px;
  color: rgba(245,240,232,0.85);
}

/* Línea de scanner decorativa en ticker1 */
#ticker1::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(245,158,11,0.4) 20%,
    rgba(245,158,11,0.8) 50%,
    rgba(245,158,11,0.4) 80%,
    transparent 100%
  );
  animation: scan-line 4s ease-in-out infinite;
  z-index: 0;
}

@keyframes scan-line {
  0%   { opacity: 0; transform: scaleX(0.3); }
  50%  { opacity: 1; transform: scaleX(1); }
  100% { opacity: 0; transform: scaleX(0.3); }
}

/* ── STATUS ── */
#conn-status {
  position: fixed; top: 8px; right: 12px;
  font-size: 10px; letter-spacing: .08em;
  color: var(--color-text-muted); display: flex;
  align-items: center; gap: 5px; z-index: 100; opacity: .6;
}
#conn-status .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--color-ica-buena); }
#conn-status.mock .dot { background: var(--color-ica-regular); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile-first override
   Aplica cuando body.is-mobile (clase puesta por JS en fitViewport)
   y como fallback cuando el viewport es <= 767px.
   El selector doble garantiza que funcione aunque JS tarde en cargar.
   ══════════════════════════════════════════════════════════════ */

/*
 * Los estilos mobile se aplican con dos mecanismos complementarios:
 *
 * 1. body.is-mobile  — clase que pone JS en fitViewport() al detectar
 *    viewport corto < 768px. Más preciso: reacciona a resize y rotate.
 *
 * 2. @media (max-width: 767px) — fallback puro CSS por si JS tarda en
 *    ejecutarse o el dispositivo tiene viewport angosto en CSS pixels.
 *
 * Ambos bloques contienen los mismos estilos para garantizar que
 * el layout responsivo aplique en cualquier condición.
 */

/* ── Mobile base — vía clase JS ── */
body.is-mobile html,
body.is-mobile body,
body.is-mobile {
  overflow-x: hidden;
  overflow-y: auto;
  height: auto;
  min-height: 100%;
  background: #000;
}

body.is-mobile #app {
  width: 100% !important;
  height: auto !important;
  transform: none !important;
  margin: 0 !important;
  display: flex;
  flex-direction: column;
  min-height: 100svh;
}

body.is-mobile #header {
  height: auto;
  min-height: 64px;
  padding: 10px 16px;
  flex-wrap: wrap;
  gap: 8px;
}

body.is-mobile .logo-name { font-size: 18px; }
body.is-mobile .logo-tagline { display: none; }
body.is-mobile .logo-mark { width: 36px; height: 36px; }
body.is-mobile .logo-mark svg { width: 20px; height: 20px; }
body.is-mobile .community-name { font-size: 14px; }
body.is-mobile .community-label { font-size: 10px; }
body.is-mobile .clock-capsule { padding: 2px 10px; }
body.is-mobile #clock-time { font-size: 26px; }
body.is-mobile #clock-seconds { font-size: 16px; }
body.is-mobile #clock-date { font-size: 11px; }

body.is-mobile #main-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: auto;
  overflow: visible;
  min-height: 0;
}

body.is-mobile #avisos_random {
  flex: 1;
  min-height: min(70vw, 55svh);
  aspect-ratio: 9 / 13;
  max-height: 70svh;
  position: relative;
  width: 100%;
  overflow: hidden;
}

body.is-mobile #avisos-slides {
  position: absolute;
  inset: 0;
}

body.is-mobile .aviso-slide img,
body.is-mobile .aviso-slide video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

body.is-mobile #avisos-overlay-top { padding: 12px 16px 40px; }
body.is-mobile .avisos-badge { font-size: 13px; padding: 5px 12px; border-radius: 16px; }
body.is-mobile .avisos-badge svg { width: 14px; height: 14px; }
body.is-mobile .avisos-counter { font-size: 13px; padding: 4px 10px; }
body.is-mobile #avisos-overlay-bottom { padding: 30px 16px 12px; gap: 8px; }
body.is-mobile .aviso-dot { width: 7px; height: 7px; }
body.is-mobile .aviso-dot.active { width: 20px; }
body.is-mobile .avisos-progress-bar { max-width: 100%; height: 2px; }

body.is-mobile #panel-left { width: 100%; min-height: 120px; }
body.is-mobile #panel-right { width: 100%; border-left: none; border-top: 1px solid var(--color-border); }

body.is-mobile #ticker1,
body.is-mobile #ticker2 { height: 64px !important; flex-shrink: 0; }

body.is-mobile .ticker-label {
  min-width: 56px !important;
  max-width: 56px !important;
  gap: 2px;
}

body.is-mobile .ticker-lbl-icon { font-size: 20px !important; }
body.is-mobile .ticker-lbl-text { font-size: 7px !important; letter-spacing: 0.15em !important; }
body.is-mobile .ticker-label::before { top: 8px; right: 6px; width: 5px; height: 5px; }
body.is-mobile .ticker-mask { display: none !important; }
body.is-mobile .ticker-icono { font-size: 18px !important; margin-right: 6px !important; }
body.is-mobile .ticker-prefix { font-size: 9px !important; padding-bottom: 4px !important; margin-right: 6px !important; }
body.is-mobile .ticker-valor { font-size: 26px !important; }

body.is-mobile #ticker2 .ticker-item {
  font-size: 16px !important;
  gap: 6px !important;
  padding: 0 8px !important;
}

body.is-mobile .ticker-farma-icon { font-size: 16px !important; }
body.is-mobile .ticker-farma-nombre { font-size: 17px !important; }
body.is-mobile .ticker-farma-info { font-size: 13px !important; }
body.is-mobile .ticker-farma-comuna { font-size: 10px !important; }
body.is-mobile .ticker-farma-dot { font-size: 14px !important; margin: 0 3px !important; }
body.is-mobile .ticker-ica-valor { font-size: 22px !important; }
body.is-mobile .ticker-ica-comuna { font-size: 17px !important; }
body.is-mobile .ticker-estado { font-size: 12px !important; padding: 2px 8px !important; }
body.is-mobile .t2-group-title { padding: 0 12px 0 8px !important; gap: 5px !important; }
body.is-mobile .t2-group-title-icon { font-size: 13px !important; }
body.is-mobile .t2-group-title-text { font-size: 11px !important; letter-spacing: 0.1em !important; }
body.is-mobile .t2-group-sep { height: 40% !important; margin: 0 24px !important; }

/* ── Fallback @media para cuando JS no ha puesto la clase aún ── */
@media (max-width: 767px) {
  html, body {
    overflow-x: hidden;
    overflow-y: auto;
    height: auto;
    min-height: 100%;
    background: #000;
  }

  #app {
    width: 100% !important;
    height: auto !important;
    transform: none !important;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
    min-height: 100svh;
  }

  #header {
    height: auto;
    min-height: 64px;
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .logo-name { font-size: 18px; }
  .logo-tagline { display: none; }
  .logo-mark { width: 36px; height: 36px; }
  .logo-mark svg { width: 20px; height: 20px; }
  .community-name { font-size: 14px; }
  .community-label { font-size: 10px; }
  .clock-capsule { padding: 2px 10px; }
  #clock-time { font-size: 26px; }
  #clock-seconds { font-size: 16px; }
  #clock-date { font-size: 11px; }

  #main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: auto;
    overflow: visible;
    min-height: 0;
  }

  #avisos_random {
    flex: 1;
    min-height: min(70vw, 55svh);
    aspect-ratio: 9 / 13;
    max-height: 70svh;
    position: relative;
    width: 100%;
    overflow: hidden;
  }

  #avisos-slides {
    position: absolute;
    inset: 0;
  }

  .aviso-slide img,
  .aviso-slide video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    display: block;
  }

  #avisos-overlay-top { padding: 12px 16px 40px; }
  .avisos-badge { font-size: 13px; padding: 5px 12px; border-radius: 16px; }
  .avisos-badge svg { width: 14px; height: 14px; }
  .avisos-counter { font-size: 13px; padding: 4px 10px; }
  #avisos-overlay-bottom { padding: 30px 16px 12px; gap: 8px; }
  .aviso-dot { width: 7px; height: 7px; }
  .aviso-dot.active { width: 20px; }
  .avisos-progress-bar { max-width: 100%; height: 2px; }

  #panel-left { width: 100%; min-height: 120px; }
  #panel-right { width: 100%; border-left: none; border-top: 1px solid var(--color-border); }

  #ticker1, #ticker2 { height: 64px !important; flex-shrink: 0; }

  .ticker-label { min-width: 56px !important; max-width: 56px !important; gap: 2px; }
  .ticker-lbl-icon { font-size: 20px !important; }
  .ticker-lbl-text { font-size: 7px !important; letter-spacing: 0.15em !important; }
  .ticker-label::before { top: 8px; right: 6px; width: 5px; height: 5px; }
  .ticker-mask { display: none !important; }
  .ticker-icono { font-size: 18px !important; margin-right: 6px !important; }
  .ticker-prefix { font-size: 9px !important; padding-bottom: 4px !important; margin-right: 6px !important; }
  .ticker-valor { font-size: 26px !important; }

  #ticker2 .ticker-item { font-size: 16px !important; gap: 6px !important; padding: 0 8px !important; }
  .ticker-farma-icon { font-size: 16px !important; }
  .ticker-farma-nombre { font-size: 17px !important; }
  .ticker-farma-info { font-size: 13px !important; }
  .ticker-farma-comuna { font-size: 10px !important; }
  .ticker-farma-dot { font-size: 14px !important; margin: 0 3px !important; }
  .ticker-ica-valor { font-size: 22px !important; }
  .ticker-ica-comuna { font-size: 17px !important; }
  .ticker-estado { font-size: 12px !important; padding: 2px 8px !important; }
  .t2-group-title { padding: 0 12px 0 8px !important; gap: 5px !important; }
  .t2-group-title-icon { font-size: 13px !important; }
  .t2-group-title-text { font-size: 11px !important; letter-spacing: 0.1em !important; }
  .t2-group-sep { height: 40% !important; margin: 0 24px !important; }
}

/* ── LANDSCAPE en mobile (ancho > alto, ambos < 900px) ──
   En landscape el viewport es ancho pero poco alto.
   Reorganizamos para aprovechar el ancho.

   IMPORTANTE: los selectores duplican body.is-mobile para igualar o superar
   la especificidad de las reglas de la clase .is-mobile definidas más arriba.
   Sin esto, body.is-mobile #avisos_random (especificidad 0,2,1) gana sobre
   el media query (0,1,1) y mantiene aspect-ratio: 9/13 + max-height: 70svh,
   colapsando el contenedor de imágenes en landscape. */
@media (max-height: 500px) and (orientation: landscape) {
  #app,
  body.is-mobile #app {
    flex-direction: column !important;
    flex-wrap: nowrap;
    min-height: 100svh;
  }

  #header,
  body.is-mobile #header {
    width: 100%;
    flex: 0 0 auto;
    min-height: 48px;
    padding: 6px 16px;
  }

  #clock-time,
  body.is-mobile #clock-time { font-size: 20px; }
  #clock-seconds,
  body.is-mobile #clock-seconds { font-size: 13px; }
  #clock-date,
  body.is-mobile #clock-date { display: none; } /* sin espacio en landscape pequeño */

  #main-content,
  body.is-mobile #main-content {
    flex: 1;
    display: flex !important;
    flex-direction: column !important;
    height: 0; /* fuerza que flex: 1 funcione dentro de un flex container */
    min-height: 0;
    overflow: hidden;
  }

  /*
   * Causa raíz del bug: body.is-mobile #avisos_random aplica
   * aspect-ratio: 9/13 y max-height: 70svh, que en landscape colapsan
   * el contenedor (aspect-ratio portrait + viewport ancho = contenedor
   * muy estrecho; max-height pequeña en landscape bajo).
   *
   * Solución: en landscape quitamos aspect-ratio, max-height y min-height
   * con !important para ganar sobre la regla .is-mobile. El contenedor
   * ocupa todo el espacio disponible con flex: 1.
   */
  #avisos_random,
  body.is-mobile #avisos_random {
    flex: 1 !important;
    min-height: 0 !important;
    max-height: none !important;
    aspect-ratio: unset !important;
    width: 100% !important;
    position: relative !important;
    overflow: hidden !important;
  }

  /* #avisos-slides ya usa position absolute + inset: 0 en el CSS base
     y en body.is-mobile — no necesita override adicional aquí */

  .aviso-slide img,
  .aviso-slide video,
  body.is-mobile .aviso-slide img,
  body.is-mobile .aviso-slide video {
    object-position: center center !important;
  }

  /* Tickers en landscape: más compactos */
  #ticker1, #ticker2,
  body.is-mobile #ticker1,
  body.is-mobile #ticker2 { height: 28px !important; flex-shrink: 0 !important; }
  .ticker-label,
  body.is-mobile .ticker-label { min-width: 44px !important; max-width: 44px !important; }
  .ticker-lbl-icon,
  body.is-mobile .ticker-lbl-icon { font-size: 14px !important; }
  .ticker-lbl-text,
  body.is-mobile .ticker-lbl-text { display: none !important; }
  .ticker-valor,
  body.is-mobile .ticker-valor { font-size: 18px !important; }
  #ticker2 .ticker-item,
  body.is-mobile #ticker2 .ticker-item { font-size: 12px !important; }
  .ticker-farma-nombre,
  body.is-mobile .ticker-farma-nombre { font-size: 12px !important; }
  .ticker-farma-dot,
  body.is-mobile .ticker-farma-dot { font-size: 10px !important; margin: 0 2px !important; }
  .ticker-ica-valor,
  body.is-mobile .ticker-ica-valor { font-size: 14px !important; }
  .ticker-ica-comuna,
  body.is-mobile .ticker-ica-comuna { font-size: 12px !important; }
  .ticker-estado,
  body.is-mobile .ticker-estado { font-size: 9px !important; }
  .t2-group-title,
  body.is-mobile .t2-group-title { padding: 0 8px 0 6px !important; gap: 3px !important; }
  .t2-group-title-icon,
  body.is-mobile .t2-group-title-icon { font-size: 10px !important; }
  .t2-group-title-text,
  body.is-mobile .t2-group-title-text { font-size: 9px !important; letter-spacing: 0.06em !important; }
  .t2-group-sep,
  body.is-mobile .t2-group-sep { height: 35% !important; margin: 0 16px !important; }
}

/* ── Tablet portrait (768px–1023px) ──
   El canvas escalado ya funciona bien aquí (fitViewport escala).
   Sólo ajuste para tablets que entren en modo responsivo por borde. */
@media (min-width: 768px) and (max-width: 1023px) {
  /* En tablet: el canvas escalado puede quedar pequeño.
     Opcional: reducir tamaños de label del ticker para que
     quepan mejor visualmente tras el scale. */
  .community-name { font-size: 16px; }
}
