/**
 * responsive.css
 * ------------------------------------------------------------------
 * Adaptação completa do FKTv Player para navegadores modernos,
 * tablets e celulares (iOS / Android / Desktop).
 * Garante layouts fluidos, áreas seguras (safe-area), suporte a toque
 * e redimensionamento inteligente de componentes.
 * ------------------------------------------------------------------
 */

/* ==========================================================================
   1. RESET FLUIDO & DYNAMIC VIEWPORT (100dvh)
   ========================================================================== */

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app-screen {
  width: 100%;
  height: 100%;
  height: 100dvh;
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
}

/* Rolagem com aceleração por hardware e momentum touch */
.catalog-categories-list,
.live-categories-list,
.live-channels-list,
.poster-grid,
.episodes-list,
.settings-content-panel,
.profiles-screen-wrap,
.detail-screen-wrap,
.series-detail-wrap,
.live-grid-main,
.modal-card {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Ocultar barras de rolagem nativas em abas horizontais no mobile */
.catalog-categories-list::-webkit-scrollbar,
.live-categories-list::-webkit-scrollbar,
.series-seasons-row::-webkit-scrollbar,
.settings-sidebar::-webkit-scrollbar {
  display: none;
  height: 0;
  width: 0;
}

.catalog-categories-list,
.live-categories-list,
.series-seasons-row,
.settings-sidebar {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* ==========================================================================
   2. BANNER DE DOWNLOAD DO APK (Android TV / Celular)
   ========================================================================== */

.apk-download-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(16, 20, 31, 0.85);
  border: 1.5px solid var(--fktv-glass-border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  border-radius: 16px;
  padding: 12px 20px;
  margin-top: 28px;
  color: #FFFFFF;
  text-decoration: none;
  max-width: 460px;
  width: 90%;
  transition: all 0.2s ease;
  cursor: pointer;
  z-index: 10;
}

.apk-download-banner:hover,
.apk-download-banner:focus {
  border-color: var(--fktv-blue-bright);
  box-shadow: 0 0 20px var(--fktv-focus-glow);
  transform: translateY(-2px);
}

.apk-download-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3E8FE0, #163F6E);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  flex-shrink: 0;
}

.apk-download-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.apk-download-info strong {
  font-size: 13.5px;
  color: #FFFFFF;
}

.apk-download-info span {
  font-size: 11.5px;
  color: var(--fktv-text-dim);
}

.apk-download-badge {
  background: rgba(62, 143, 224, 0.2);
  color: var(--fktv-blue-bright);
  border: 1px solid rgba(62, 143, 224, 0.35);
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
}

/* ==========================================================================
   3. DESKTOP & TELAS MÉDIAS (até 1200px)
   ========================================================================== */

@media (max-width: 1200px) {
  .dash-container {
    padding: 24px 36px;
  }
  .dash-cards-row {
    gap: 20px;
  }
  .dash-tile {
    width: 220px;
    height: 240px;
  }
  .live-categories-col {
    width: 230px;
    min-width: 230px;
  }
  .live-channels-col {
    width: 320px;
    min-width: 320px;
  }
  .live-preview-col {
    flex: 1;
    width: auto;
  }
  .live-mini-video-wrap {
    width: 100%;
    max-width: 460px;
    height: auto;
    aspect-ratio: 16/9;
  }
}

/* ==========================================================================
   4. TABLETS & CELULARES (até 900px)
   ========================================================================== */

@media (max-width: 900px) {
  /* --- Topbar de Conteúdo --- */
  .content-topbar {
    height: 52px;
    padding: 0 12px;
    gap: 8px;
  }
  .topbar-title {
    font-size: 15px;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-search-wrap {
    width: 150px;
    padding: 5px 10px;
  }
  .topbar-search-wrap:focus-within,
  .topbar-search-wrap.active {
    width: 190px;
  }
  .search-badge-red {
    display: none !important;
  }
  .content-topbar .dash-clock {
    display: none;
  }
  .btn-secondary {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 10px;
  }
  .btn-primary {
    padding: 7px 14px;
    font-size: 13px;
    border-radius: 10px;
  }

  /* --- Tela: Perfis --- */
  .profiles-screen-wrap {
    padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
    justify-content: flex-start;
    overflow-y: auto;
  }
  .profiles-brand-header {
    margin-bottom: 24px;
    gap: 10px;
  }
  .profiles-app-logo {
    width: 56px;
    height: 56px;
  }
  .profiles-title {
    font-size: 24px;
  }
  .profiles-grid {
    gap: 16px;
    max-width: 100%;
  }
  .profile-card {
    width: 120px;
    padding: 8px;
    gap: 8px;
  }
  .profile-avatar {
    width: 80px;
    height: 80px;
    font-size: 28px;
  }
  .profile-name {
    font-size: 13.5px;
    max-width: 100px;
  }

  /* --- Tela: Dashboard 2.0 --- */
  .dash-container {
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto;
    justify-content: flex-start;
    gap: 14px;
  }
  .dash-brand {
    gap: 10px;
  }
  .dash-logo {
    width: 38px;
    height: 38px;
  }
  .dash-app-title {
    font-size: 18px;
  }
  .dash-app-subtitle {
    font-size: 11px;
  }
  .dash-header-right {
    gap: 8px;
  }
  .dash-header-right .dash-clock {
    display: none;
  }
  .dash-profile-btn {
    padding: 6px 12px;
    gap: 6px;
  }
  .dash-profile-name {
    font-size: 12px;
  }
  .dash-center {
    margin: 8px 0;
    width: 100%;
  }
  .dash-cards-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 480px;
    margin: 0 auto 16px auto;
  }
  .dash-tile {
    width: 100%;
    height: auto;
    min-height: 140px;
    padding: 18px 10px;
    border-radius: 18px;
  }
  .dash-tile-circle {
    width: 54px;
    height: 54px;
    margin-bottom: 10px;
  }
  .dash-tile-circle svg {
    width: 28px;
    height: 28px;
  }
  .dash-tile-title {
    font-size: 15.5px;
    margin-bottom: 4px;
  }
  .dash-tile-subtitle {
    font-size: 11px;
  }
  .dash-reload-btn {
    padding: 10px 24px;
    font-size: 13.5px;
    border-radius: 20px;
  }
  .dash-footer {
    flex-direction: column;
    gap: 4px;
    text-align: center;
    font-size: 11px;
    padding: 12px 0;
    margin-top: auto;
    border-top-color: rgba(35, 42, 58, 0.2);
  }

  /* --- Tela: TV Ao Vivo (Live TV) no Mobile --- */
  .live-container {
    height: calc(100dvh - 52px);
  }
  .live-split-view {
    flex-direction: column;
    height: 100%;
    overflow: hidden;
  }
  /* Top: Mini Player + Canal Info */
  .live-preview-col {
    order: 1;
    flex: none;
    width: 100%;
    height: auto;
    border-left: none;
    border-bottom: 1px solid var(--fktv-border);
    background-color: var(--fktv-bg);
  }
  .live-top-panel {
    padding: 8px 12px;
    gap: 12px;
    flex-direction: row;
    align-items: center;
  }
  .live-mini-video-wrap {
    width: 130px;
    min-width: 130px;
    height: 73px;
    aspect-ratio: 16/9;
    border-radius: 8px;
  }
  .live-channel-details {
    padding: 0;
    gap: 3px;
    min-width: 0;
    flex: 1;
  }
  .live-channel-title {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .live-epg-title {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .live-tag-pill,
  .live-epg-time,
  .live-progress-track,
  .live-next-show {
    display: none;
  }
  .live-fullscreen-btn {
    padding: 5px 10px;
    font-size: 11.5px;
    border-radius: 8px;
    width: fit-content;
    margin-top: 2px;
  }
  .live-epg-schedule-panel {
    display: none;
  }
  /* Middle: Categorias em Chips Horizontais */
  .live-categories-col {
    order: 2;
    width: 100%;
    min-width: 100%;
    height: auto;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--fktv-border);
    background: rgba(10, 14, 22, 0.98);
  }
  .live-col-header {
    display: none;
  }
  .live-categories-list {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    padding: 6px 10px;
    gap: 6px;
    width: 100%;
  }
  .live-cat-item {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 6px 14px;
    margin: 0;
    border-radius: 20px;
    border-left: none;
    border: 1px solid var(--fktv-border);
    font-size: 12.5px;
  }
  .live-cat-item.active {
    background: var(--fktv-blue);
    border-color: var(--fktv-blue-bright);
    color: #FFFFFF;
    font-weight: 700;
  }
  /* Bottom: Lista de Canais */
  .live-channels-col {
    order: 3;
    width: 100%;
    min-width: 100%;
    flex: 1;
    height: auto;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-right: none;
  }
  .live-channels-list {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    padding: 4px 6px;
  }
  .channel-list-item {
    padding: 8px 10px;
    gap: 10px;
    min-height: 46px;
    border-radius: 8px;
    margin-bottom: 2px;
  }
  .channel-num {
    width: 22px;
    font-size: 11px;
  }
  .channel-icon {
    width: 32px;
    height: 32px;
  }
  .channel-name {
    font-size: 13.5px;
  }

  /* Modo Grade no Mobile */
  .live-grid-view {
    flex-direction: column;
    height: 100%;
  }
  .live-grid-view .live-categories-col {
    width: 100%;
    min-width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--fktv-border);
  }
  .live-grid-view .live-categories-list {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    padding: 6px 10px;
    gap: 6px;
    width: 100%;
  }
  .live-grid-main {
    padding: 8px;
    flex: 1;
    overflow-y: auto;
  }
  .live-grid-wrap {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
  }

  /* --- Catálogos: Filmes & Séries --- */
  .catalog-container {
    flex-direction: column;
    height: calc(100dvh - 52px);
  }
  .catalog-sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--fktv-border);
    background: rgba(10, 14, 22, 0.98);
  }
  .catalog-sidebar-header {
    display: none;
  }
  .catalog-categories-list {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    padding: 6px 10px;
    gap: 6px;
    width: 100%;
  }
  .catalog-cat-item {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 6px 14px;
    margin: 0;
    border-radius: 20px;
    border-left: none;
    border: 1px solid var(--fktv-border);
    font-size: 12.5px;
  }
  .catalog-cat-item.active {
    background: var(--fktv-blue);
    border-color: var(--fktv-blue-bright);
    color: #FFFFFF;
    font-weight: 700;
  }
  .catalog-main {
    padding: 10px 8px;
    flex: 1;
    overflow: hidden;
  }
  .poster-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    padding-bottom: 30px;
  }
  .poster-card {
    height: auto;
    border-radius: 10px;
  }
  .poster-thumb-wrap {
    height: 145px;
  }
  .poster-title {
    font-size: 11px;
    padding: 5px 3px;
    font-weight: 600;
  }
  .rating-badge {
    font-size: 10px;
    padding: 2px 4px;
    top: 4px;
    right: 4px;
  }
  .year-badge {
    font-size: 10px;
    padding: 2px 4px;
    bottom: 4px;
    left: 4px;
  }

  /* --- Detalhes do Filme --- */
  .detail-screen-wrap {
    overflow-y: auto;
    height: 100%;
    -webkit-overflow-scrolling: touch;
  }
  .detail-content-wrap {
    flex-direction: column;
    padding: 20px 16px 40px;
    gap: 16px;
    height: auto;
    min-height: 100%;
    align-items: center;
    background: rgba(5, 7, 12, 0.95);
  }
  .detail-poster-col {
    width: auto;
    align-items: center;
  }
  .detail-poster-img {
    width: 140px;
    height: 210px;
    border-radius: 12px;
  }
  .detail-info-col {
    align-items: center;
    max-width: 100%;
    gap: 12px;
  }
  .detail-title {
    font-size: 20px;
    text-align: center;
  }
  .detail-meta-row {
    justify-content: center;
    font-size: 12.5px;
    gap: 10px;
    flex-wrap: wrap;
  }
  .detail-plot {
    font-size: 13.5px;
    max-height: none;
    text-align: left;
  }
  .detail-credits {
    font-size: 12px;
    text-align: left;
    width: 100%;
  }
  .detail-actions-row {
    flex-direction: column;
    width: 100%;
    gap: 10px;
    margin-top: 10px;
  }
  .detail-actions-row button {
    width: 100%;
    padding: 12px;
    font-size: 14px;
  }

  /* --- Detalhes da Série --- */
  .series-detail-wrap {
    padding: 14px 12px 40px;
    overflow-y: auto;
  }
  .series-header-info {
    flex-direction: row;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
  }
  .series-thumb {
    width: 85px;
    height: 128px;
    border-radius: 8px;
    flex-shrink: 0;
  }
  .series-detail-wrap .detail-plot {
    font-size: 12.5px;
    line-height: 1.4;
    max-height: 110px;
    overflow-y: auto;
  }
  .series-seasons-row {
    gap: 8px;
    padding-bottom: 6px;
    overflow-x: auto;
  }
  .season-tab {
    padding: 6px 14px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .episode-row {
    padding: 8px 10px;
    gap: 10px;
    border-radius: 10px;
  }
  .ep-thumb {
    width: 70px;
    height: 42px;
    border-radius: 6px;
  }
  .ep-num-title {
    font-size: 13px;
  }
  .ep-duration {
    font-size: 11px;
  }
  .ep-plot {
    display: none;
  }
  .ep-play-btn {
    width: 36px;
    height: 36px;
    font-size: 14px;
  }

  /* --- Configurações --- */
  .settings-container {
    flex-direction: column;
    height: calc(100dvh - 52px);
  }
  .settings-sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    padding: 6px 8px;
    gap: 6px;
    border-right: none;
    border-bottom: 1px solid var(--fktv-border);
  }
  .settings-sidebar-header {
    display: none;
  }
  .settings-tab-btn {
    padding: 7px 12px;
    gap: 6px;
    white-space: nowrap;
    flex-shrink: 0;
    border-radius: 10px;
  }
  .tab-btn-desc {
    display: none;
  }
  .tab-btn-title {
    font-size: 12px;
  }
  .tab-btn-icon {
    width: 18px;
    height: 18px;
  }
  .settings-content-panel {
    padding: 14px 12px 40px;
    overflow-y: auto;
  }
  .settings-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
  }
  .setting-control {
    width: 100%;
  }
  .setting-control select,
  .setting-control button {
    width: 100%;
    font-size: 13.5px;
    padding: 9px 12px;
  }

  /* --- Player Fullscreen & OSD --- */
  .player-osd {
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  }
  .osd-topbar {
    gap: 10px;
  }
  .osd-back-btn {
    width: 38px;
    height: 38px;
    font-size: 16px;
    border-radius: 10px;
  }
  .osd-title {
    font-size: 15px;
  }
  .osd-subtitle {
    font-size: 12px;
  }
  .osd-top-actions .dash-clock {
    display: none;
  }
  .osd-controls-row {
    gap: 12px;
    flex-wrap: wrap;
  }
  .osd-ctrl-btn {
    width: 42px;
    height: 42px;
    font-size: 13px;
  }
  .osd-ctrl-btn-play {
    width: 54px;
    height: 54px;
    font-size: 18px;
  }
  #btn_osd_seek_back_min,
  #btn_osd_seek_fwd_min,
  #btn_osd_seek_fwd_5min,
  #btn_osd_picture_mode {
    display: none;
  }
  .next-episode-banner {
    bottom: 16px;
    right: 14px;
    left: 14px;
    width: auto;
    max-width: none;
    padding: 14px;
  }
}

/* ==========================================================================
   5. CELULARES PEQUENOS (até 520px)
   ========================================================================== */

@media (max-width: 520px) {
  .topbar-title {
    display: none;
  }
  .topbar-search-wrap {
    flex: 1;
    min-width: 120px;
    max-width: none;
    width: auto;
  }
  .topbar-search-wrap:focus-within,
  .topbar-search-wrap.active {
    width: auto;
  }
  .app-modal {
    padding: 12px;
  }
  .modal-card {
    padding: 18px 14px;
    max-height: 88dvh;
    border-radius: 16px;
    width: 95%;
  }
  .modal-title {
    font-size: 18px;
  }
  .login-mode-tabs {
    gap: 6px;
  }
  .login-mode-tab {
    padding: 7px 8px;
    font-size: 11.5px;
  }
  /* Previne zoom automático do iOS Safari ao focar inputs */
  .form-input {
    font-size: 16px !important;
    padding: 10px 12px;
  }
  .poster-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 6px;
  }
  .poster-thumb-wrap {
    height: 130px;
  }
}

/* ==========================================================================
   6. ORIENTAÇÃO LANDSCAPE NO CELULAR (assistir em tela deitada)
   ========================================================================== */

@media (max-height: 500px) and (orientation: landscape) {
  .content-topbar {
    height: 44px;
  }
  .live-container,
  .catalog-container,
  .settings-container {
    height: calc(100dvh - 44px);
  }
  .dash-container {
    padding: 10px 20px;
    gap: 8px;
  }
  .dash-cards-row {
    margin: 4px auto 10px auto;
  }
  .dash-tile {
    min-height: 90px;
    padding: 8px 10px;
  }
  .dash-tile-circle {
    width: 40px;
    height: 40px;
    margin-bottom: 4px;
  }
  .dash-tile-circle svg {
    width: 20px;
    height: 20px;
  }
  .dash-tile-title {
    font-size: 13px;
  }
  .dash-tile-subtitle {
    display: none;
  }
  .player-osd {
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  }
  .osd-controls-row {
    gap: 16px;
  }
  .osd-ctrl-btn {
    width: 38px;
    height: 38px;
  }
  .osd-ctrl-btn-play {
    width: 48px;
    height: 48px;
  }
}

/* ==========================================================================
   7. DISPOSITIVOS TOUCH (Sem hover falso e sem saltos de foco)
   ========================================================================== */

@media (hover: none) and (pointer: coarse) {
  .focusable:focus:not(.focused) {
    transform: none;
    border-color: inherit;
    box-shadow: none;
  }
  .dash-tile:active,
  .poster-card:active,
  .channel-list-item:active,
  .btn-primary:active,
  .btn-secondary:active,
  .apk-download-banner:active {
    transform: scale(0.97);
  }
}
