/* ═══════════════════════════════════════
   APP MODE - Interfaz Tipo App Nativa
   Grupo Máxima PWA
   ═══════════════════════════════════════ */

/* Solo se aplica en modo standalone (app instalada) */
@media all and (display-mode: standalone) {

  /* ── RESET PARA MODO APP ────────────── */
  body.app-mode {
    padding-top: 0 !important;
    background: var(--dark);
    overflow: hidden;
  }

  /* Ocultar elementos web en modo app */
  body.app-mode #player-bar,
  body.app-mode #hero,
  body.app-mode #stations,
  body.app-mode #tv-online,
  body.app-mode #programming,
  body.app-mode #contact,
  body.app-mode footer,
  body.app-mode #scroll-top,
  body.app-mode #install-pwa-btn {
    display: none !important;
  }

  /* Mostrar contenedor app */
  body.app-mode #app-container {
    display: flex !important;
  }
}

/* ═══════════════════════════════════════
   CONTENEDOR APP
   ═══════════════════════════════════════ */

#app-container {
  display: none; /* Oculto por defecto (solo en standalone) */
  position: fixed;
  inset: 0;
  flex-direction: column;
  background: var(--dark);
  overflow: hidden;
  z-index: 10000;
}

/* ── APP HEADER ────────────────────────── */
.app-header {
  flex-shrink: 0;
  padding: 12px 20px;
  background: linear-gradient(180deg, var(--dark2) 0%, var(--dark) 100%);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 100;
}

.app-header-title {
  font-size: 1.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--mx-yellow), #fff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.05em;
}

.app-header-subtitle {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 2px;
}

.app-header-actions {
  display: flex;
  gap: 8px;
}

.app-header-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s;
}

.app-header-btn:active {
  transform: scale(0.95);
  background: rgba(255,255,255,0.1);
}

/* ── APP CONTENT ───────────────────────── */
.app-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* Ocultar scrollbar pero mantener funcionalidad */
.app-content::-webkit-scrollbar {
  width: 0px;
  display: none;
}

.app-content {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

/* ── APP VIEWS ─────────────────────────── */
.app-view {
  display: none;
  min-height: calc(100vh - 64px - 64px); /* viewport - header - bottom nav */
  padding: 16px;
  padding-bottom: 80px; /* Espacio para bottom nav */
}

.app-view.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── HOME VIEW ─────────────────────────── */
.app-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
  padding: 0 4px;
}

.app-station-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.app-station-card {
  background: var(--dark2);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}

.app-station-card::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  opacity: 0.08;
  transition: all 0.3s;
}

.app-station-card.mx::before { background: radial-gradient(circle, var(--mx-yellow), transparent); }
.app-station-card.em::before { background: radial-gradient(circle, var(--em-cyan), transparent); }
.app-station-card.vv::before { background: radial-gradient(circle, var(--vv-red), transparent); }
.app-station-card.tv::before { background: radial-gradient(circle, var(--tv-purple), transparent); }

.app-station-card:active {
  transform: scale(0.98);
}

.app-station-card.playing {
  border-color: rgba(245,197,24,0.3);
  background: linear-gradient(135deg, rgba(245,197,24,0.08), var(--dark2));
}

.app-station-logo {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  flex-shrink: 0;
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.app-station-logo.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  background: linear-gradient(135deg, var(--mx-yellow), var(--mx-blue));
}

.app-station-logo.placeholder.em {
  background: linear-gradient(135deg, var(--em-cyan), #0066CC);
}

.app-station-logo.placeholder.vv {
  background: linear-gradient(135deg, var(--vv-red), #8B0000);
}

.app-station-logo.placeholder.tv {
  background: linear-gradient(135deg, var(--tv-purple), #6B21A8);
}

.app-station-info {
  flex: 1;
  min-width: 0;
}

.app-station-name {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-station-freq {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.app-station-status {
  font-size: 0.65rem;
  color: var(--mx-yellow);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
}

.app-station-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mx-yellow);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.app-play-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--mx-yellow);
  border: none;
  color: #000;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(245,197,24,0.3);
  transition: all 0.3s;
}

.app-play-btn:active {
  transform: scale(0.95);
}

.app-play-btn.playing {
  background: #fff;
  color: #000;
}

/* ── TV CARDS (horizontal layout) ─────── */
.app-tv-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.app-station-card.tv-card {
  flex-direction: column;
  padding: 20px 16px;
  text-align: center;
  min-height: 140px;
  justify-content: center;
}

.app-station-card.tv-card .app-station-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
}

.app-station-card.tv-card .app-station-info {
  flex: 0;
  width: 100%;
}

.app-station-card.tv-card .app-station-name {
  white-space: normal;
  text-align: center;
  font-size: 0.9rem;
}

.app-station-card.tv-card .app-station-freq {
  justify-content: center;
  font-size: 0.7rem;
}

.app-station-card.tv-card .app-play-btn {
  position: absolute;
  bottom: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  font-size: 0.85rem;
}

/* Responsive: 1 columna en pantallas muy pequeñas */
@media (max-width: 340px) {
  .app-tv-grid {
    grid-template-columns: 1fr;
  }
}

/* ── PLAYER FULLSCREEN ─────────────────── */
#app-player-view {
  background: linear-gradient(180deg, var(--dark) 0%, var(--dark2) 50%, var(--dark3) 100%);
  padding: 0 !important;
  overflow: hidden !important; /* Sin scroll en player */
}

#app-player-view.active {
  display: flex !important;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.app-player-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.app-player-artwork {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 1;
  margin: 0 auto 32px;
  border-radius: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.app-player-artwork img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app-player-artwork.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--mx-yellow), var(--mx-blue));
  font-size: 6rem;
}

.app-player-artwork::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 60%, rgba(0,0,0,0.4));
}

.app-player-info {
  text-align: center;
  margin-bottom: 32px;
  width: 100%;
}

.app-player-title {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 8px;
  line-height: 1.3;
}

.app-player-subtitle {
  font-size: 0.9rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.app-player-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(229,34,34,0.15);
  border: 1px solid rgba(229,34,34,0.3);
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #ff6060;
  margin-top: 8px;
}

.app-player-live .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.5s ease-in-out infinite;
}

.app-player-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  width: 100%;
}

.app-player-control {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--mx-yellow);
  border: none;
  color: #000;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(245,197,24,0.4);
  transition: all 0.3s;
}

.app-player-control:active {
  transform: scale(0.95);
}

/* ── NOTICIAS VIEW ─────────────────────── */
.app-news-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-news-card {
  background: var(--dark2);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s;
}

.app-news-card:active {
  transform: scale(0.98);
}

.app-news-image {
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: var(--dark3);
}

.app-news-content {
  padding: 14px;
}

.app-news-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.app-news-cat {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mx-yellow);
  background: rgba(245,197,24,0.1);
  border: 1px solid rgba(245,197,24,0.2);
  padding: 2px 8px;
  border-radius: 4px;
}

.app-news-date {
  font-size: 0.7rem;
  color: var(--muted);
}

.app-news-title {
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 6px;
}

.app-news-summary {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── BOTTOM NAVIGATION ─────────────────── */
.app-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--dark2);
  border-top: 1px solid rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 8px 16px;
  z-index: 200;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.3);
}

.app-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 6px;
  border-radius: 12px;
  transition: all 0.3s;
  color: var(--muted);
}

.app-nav-item:active {
  transform: scale(0.95);
}

.app-nav-item.active {
  color: var(--mx-yellow);
}

.app-nav-icon {
  font-size: 1.2rem;
  transition: all 0.3s;
}

.app-nav-item.active .app-nav-icon {
  transform: translateY(-2px);
}

.app-nav-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* ── MINI PLAYER ───────────────────────── */
.app-mini-player {
  position: fixed;
  bottom: 64px;
  left: 0;
  right: 0;
  height: 64px;
  background: linear-gradient(135deg, var(--dark2), var(--dark3));
  border-top: 1px solid rgba(255,255,255,0.1);
  display: none;
  align-items: center;
  padding: 8px 16px;
  gap: 12px;
  cursor: pointer;
  z-index: 150;
  box-shadow: 0 -2px 16px rgba(0,0,0,0.2);
}

.app-mini-player.active {
  display: flex;
}

.app-mini-player-art {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.app-mini-player-info {
  flex: 1;
  min-width: 0;
}

.app-mini-player-title {
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-mini-player-subtitle {
  font-size: 0.7rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.app-mini-player-controls {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.app-mini-player-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--mx-yellow);
  border: none;
  color: #000;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ── EMPTY STATE ───────────────────────── */
.app-empty {
  text-align: center;
  padding: 60px 32px;
  color: var(--muted);
}

.app-empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.3;
}

.app-empty-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.app-empty-text {
  font-size: 0.85rem;
  line-height: 1.6;
}

/* ── SAFE AREAS (notch/island) ───────── */
@supports (padding: env(safe-area-inset-top)) {
  .app-header {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .app-bottom-nav {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    height: calc(64px + env(safe-area-inset-bottom));
  }

  .app-content {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
}

/* ── RESPONSIVE ────────────────────────── */
@media (max-width: 360px) {
  .app-station-card {
    padding: 12px;
  }

  .app-station-logo {
    width: 48px;
    height: 48px;
  }

  .app-play-btn {
    width: 40px;
    height: 40px;
  }
}

@media (min-height: 700px) {
  .app-player-artwork {
    max-width: 360px;
  }
}

/* ── TV PLAYER ─────────────────────────── */
.app-tv-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 16px;
  gap: 12px;
}

.app-tv-frame {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9; /* Formato horizontal */
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 0 2px rgba(255,255,255,0.05),
    0 10px 30px rgba(0,0,0,0.5);
  position: relative;
  flex-shrink: 0;
}

.app-tv-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #000;
}

.app-tv-info {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-top: 0;
}

.app-tv-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  background: rgba(229,34,34,0.15);
  border: 1px solid rgba(229,34,34,0.3);
  border-radius: 100px;
  font-size: 0.65rem;
  font-weight: 700;
  color: #ff6060;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.app-tv-badge .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.5s ease-in-out infinite;
}

.app-tv-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
  margin: 0;
  line-height: 1.2;
}

/* Responsive TV Player */
@media (max-width: 400px) {
  .app-tv-player {
    padding: 12px;
    gap: 10px;
  }

  .app-tv-frame {
    border-radius: 12px;
  }

  .app-tv-title {
    font-size: 1.1rem;
  }
}

@media (min-width: 600px) {
  .app-tv-frame {
    max-width: 90%;
  }
}

@media (min-height: 700px) {
  .app-tv-frame {
    max-width: 85%;
  }
}

