/**
 * CyberTV Universal CSS Compatibility Layer v4.0
 * ===============================================
 * Compatibilidade universal para TODAS as Smart TVs 2012-2026
 * Safe Zone, Resolution Scaling, Spatial Navigation Focus, 10-foot UI
 */

/* ===== RESET E BOX-SIZING ===== */
*, *:before, *:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

/* ===== PREVENT SELECTION / CURSOR / CALLOUT ===== */
body {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

/* ===== HIDE CURSOR ON TV (no mouse) ===== */
.tv-samsung body, .tv-lg body, .tv-sony body, .tv-panasonic body,
.tv-stb body, .tv-hisense body, .tv-tcl body, .tv-sharp body,
.tv-firetv body, .tv-androidtv body, .tv-philips body {
  cursor: none;
}

/* ===== SCROLLBAR HIDDEN ===== */
::-webkit-scrollbar { width: 0; height: 0; background: transparent; }
* { scrollbar-width: none; -ms-overflow-style: none; }

/* ===== SAFE ZONE WRAPPER (5% padding all around) ===== */
.tv-safe-zone {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 27px 48px;
  overflow: hidden;
}

/* ===== RESOLUTION SCALING WRAPPER ===== */
.tv-scale-wrapper {
  position: relative;
  width: 1920px;
  height: 1080px;
  overflow: hidden;
  -webkit-transform-origin: 0 0;
  transform-origin: 0 0;
}

/* ===== FALLBACK: Flexbox com prefixos para browsers antigos ===== */
.flex-compat {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
}

.flex-col-compat {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  -webkit-flex-direction: column;
  flex-direction: column;
}

.flex-wrap-compat {
  -webkit-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
}

.flex-center-compat {
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
}

.flex-1-compat {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  -ms-flex: 1;
  flex: 1;
}

/* ===== CSS Grid Fallback ===== */
.no-cssgrid .tv-grid-4col {
  display: -webkit-box !important;
  display: -webkit-flex !important;
  display: flex !important;
  -webkit-flex-wrap: nowrap;
  flex-wrap: nowrap;
}
.no-cssgrid .tv-grid-4col > *:nth-child(1) { width: 18%; min-width: 18%; }
.no-cssgrid .tv-grid-4col > *:nth-child(2) { width: 25%; min-width: 25%; }
.no-cssgrid .tv-grid-4col > *:nth-child(3) { width: 35%; min-width: 35%; }
.no-cssgrid .tv-grid-4col > *:nth-child(4) { width: 22%; min-width: 22%; }

.no-cssgrid .tv-grid-movies {
  display: -webkit-box !important;
  display: -webkit-flex !important;
  display: flex !important;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
}
.no-cssgrid .tv-grid-movies > * {
  width: 25%;
  min-width: 25%;
}

/* ===== FOCO VISUAL UNIVERSAL - EXTREMAMENTE VISIVEL ===== */
/* Base styles for all focusable elements */
.tv-focusable, .focusable, [data-focusable] {
  outline: none !important;
  -webkit-transition: border-color 0.15s ease, box-shadow 0.15s ease, -webkit-transform 0.15s ease, background-color 0.15s ease;
  -moz-transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease, background-color 0.15s ease;
  -o-transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease, background-color 0.15s ease;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease, background-color 0.15s ease;
  border: 3px solid transparent;
}

/* FOCUSED STATE - Extremely visible for TV viewing at 3m distance */
.tv-focusable.focused,
.focusable.focused,
[data-focusable].focused,
.tv-focusable:focus,
.focusable:focus,
[data-focusable]:focus,
.spatial-focused {
  border-color: #2afa00 !important;
  outline: 3px solid #2afa00 !important;
  outline-offset: 2px;
  -webkit-box-shadow: 0 0 20px rgba(42, 250, 0, 0.6), 0 0 40px rgba(42, 250, 0, 0.3), inset 0 0 10px rgba(42, 250, 0, 0.1) !important;
  box-shadow: 0 0 20px rgba(42, 250, 0, 0.6), 0 0 40px rgba(42, 250, 0, 0.3), inset 0 0 10px rgba(42, 250, 0, 0.1) !important;
  -webkit-transform: scale(1.05);
  -moz-transform: scale(1.05);
  -ms-transform: scale(1.05);
  -o-transform: scale(1.05);
  transform: scale(1.05);
  z-index: 100;
  position: relative;
}

/* Active/pressed state for ENTER key */
.tv-focusable.pressed,
.focusable.pressed,
[data-focusable].pressed,
.spatial-active {
  -webkit-transform: scale(0.95) !important;
  -moz-transform: scale(0.95) !important;
  -ms-transform: scale(0.95) !important;
  transform: scale(0.95) !important;
  border-color: #fff !important;
  -webkit-box-shadow: 0 0 30px rgba(255, 255, 255, 0.8) !important;
  box-shadow: 0 0 30px rgba(255, 255, 255, 0.8) !important;
}

/* Focused items inside lists/grids - slightly different scale to avoid overlap */
.tv-scroll .tv-focusable.focused,
.tv-scroll .focusable.focused,
.tv-scroll [data-focusable].focused {
  -webkit-transform: scale(1.03);
  -moz-transform: scale(1.03);
  -ms-transform: scale(1.03);
  transform: scale(1.03);
}

/* White focus variant (for pages with colored/gradient backgrounds) */
.tv-focusable.focused-white,
.focusable.focused-white {
  border-color: #fff !important;
  outline-color: #fff !important;
  -webkit-box-shadow: 0 0 20px rgba(255, 255, 255, 0.6), 0 0 40px rgba(255, 255, 255, 0.3) !important;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.6), 0 0 40px rgba(255, 255, 255, 0.3) !important;
}

/* ===== 10-FOOT UI: Minimum Font Size Enforcement ===== */
/* Enforce minimum 24px font for TV readability at 3m distance */
.tv-10foot body,
.tv-10foot * {
  font-size-adjust: none;
}

.tv-10foot p, .tv-10foot span, .tv-10foot div, .tv-10foot a, .tv-10foot li,
.tv-10foot td, .tv-10foot th, .tv-10foot label, .tv-10foot input, .tv-10foot button,
.tv-10foot select, .tv-10foot textarea, .tv-10foot option {
  min-height: 1em;
}

/* ===== Resolucao adaptativa ===== */
.res-sd body, .res-sd .container { font-size: 14px !important; }
.res-hd body, .res-hd .container { font-size: 16px !important; }
.res-fhd body, .res-fhd .container { font-size: 18px !important; }
.res-4k body, .res-4k .container { font-size: 24px !important; }

/* ===== Overflow seguro para TVs antigas ===== */
.tv-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* ===== Legacy SmartHub / Maple fixes ===== */
.tv-legacy * {
  -webkit-transform: translateZ(0);
}
.tv-legacy .tv-scroll {
  overflow: auto;
}
/* Legacy TVs don't support transform scale well */
.tv-legacy .tv-focusable.focused,
.tv-legacy .focusable.focused,
.tv-legacy [data-focusable].focused {
  -webkit-transform: none !important;
  transform: none !important;
  border-width: 5px !important;
  border-color: #2afa00 !important;
}

/* ===== Animacoes com prefixos ===== */
@-webkit-keyframes tvFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes tvFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@-webkit-keyframes tvPulse {
  0% { -webkit-box-shadow: 0 0 15px rgba(255,215,0,0.4); box-shadow: 0 0 15px rgba(255,215,0,0.4); }
  50% { -webkit-box-shadow: 0 0 30px rgba(255,215,0,0.8); box-shadow: 0 0 30px rgba(255,215,0,0.8); }
  100% { -webkit-box-shadow: 0 0 15px rgba(255,215,0,0.4); box-shadow: 0 0 15px rgba(255,215,0,0.4); }
}
@keyframes tvPulse {
  0% { box-shadow: 0 0 15px rgba(255,215,0,0.4); }
  50% { box-shadow: 0 0 30px rgba(255,215,0,0.8); }
  100% { box-shadow: 0 0 15px rgba(255,215,0,0.4); }
}

@-webkit-keyframes tvSpin {
  0% { -webkit-transform: rotate(0deg); transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); }
}
@keyframes tvSpin {
  0% { -webkit-transform: rotate(0deg); transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); }
}

.tv-fade-in {
  -webkit-animation: tvFadeIn 0.3s ease-out;
  animation: tvFadeIn 0.3s ease-out;
}

.tv-pulse-focus {
  -webkit-animation: tvPulse 1.5s ease-in-out infinite;
  animation: tvPulse 1.5s ease-in-out infinite;
}

.tv-spinner {
  -webkit-animation: tvSpin 1s linear infinite;
  animation: tvSpin 1s linear infinite;
}

/* ===== Spatial Navigation Debug Indicator ===== */
.spatial-nav-indicator {
  position: fixed;
  top: 11px;
  right: 19px;
  background: rgba(0,0,0,0.7);
  color: #2afa00;
  padding: 5px 19px;
  border-radius: 10px;
  font-size: 15px;
  z-index: 99999;
  pointer-events: none;
  opacity: 0;
  -webkit-transition: opacity 0.3s;
  transition: opacity 0.3s;
}
.spatial-nav-indicator.visible {
  opacity: 1;
}
