/**
 * GECE - Responsive CSS & Full Responsive / Cross-platform
 * Otimizado para Pixel Perfect 2025:
 * - iPhone (iOS) - Safari (Safe areas, Touch > 44px, Previned Zoom)
 * - Android (Phones/Tablets)
 * - macOS Retina - Safari/Chrome
 * - Windows/Linux - Custom Scrollbars, Max-width Container
 */

/* ============================================
   GLOBAL & NATIVE BEHAVIOR IMPROVEMENTS
   ============================================ */
/* --- Global Design Systems 2026 --- */
:root {
    --primary-gold: #c5a059;
    --primary-dark: #0f172a;
    --accent-slate: #334155;
    --bg-body: #f8fafc;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.2);
    
    /* Spacing (8-point grid) */
    --sp-xs: 4px;
    --sp-sm: 8px;
    --sp-md: 16px;
    --sp-lg: 24px;
    --sp-xl: 32px;
    --sp-2xl: 48px;
    
    /* Dynamic Typography */
    --fs-h1: clamp(2.2rem, 8vw, 3.8rem);
    --fs-h2: clamp(1.8rem, 6vw, 2.5rem);
    --fs-body: clamp(0.95rem, 2vw, 1.1rem);
    
    /* Transitions & Shadows */
    --ease-premium: cubic-bezier(0.165, 0.84, 0.44, 1);
    --shadow-soft: 0 10px 40px -10px rgba(0, 0, 0, 0.05);
    --shadow-premium: 0 30px 60px -12px rgba(15, 23, 42, 0.12);
}

* { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

:root {
    /* Touch targets Native */
    --touch-target-size: 44px;
    --touch-target-padding: 12px;

    /* Typographic Fluid System (Desktop to Mobile smoothly) */
    --font-size-base: clamp(1rem, 0.95vw + 0.8rem, 1.125rem); /* ~16px to ~18px */
    --font-size-h1: clamp(1.8rem, 3vw + 1rem, 2.5rem);
    --font-size-h2: clamp(1.5rem, 2vw + 1rem, 2rem);
    --font-size-h3: clamp(1.2rem, 1.5vw + 1rem, 1.5rem);

    /* Grid & Container Limits (Ultrawide protection) */
    --max-container-width: 1400px; /* Mais largo para o hub */
}

*,
*::before,
*::after {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    scroll-behavior: smooth;
    font-size: 16px; /* Base nativa sólida para os rems calc() */
}

body {
    -webkit-user-select: text;
    user-select: text;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale; /* Retina Ready (MacBook/iMac) */
    text-rendering: optimizeLegibility;
    font-size: var(--font-size-base);
    line-height: 1.6;
}

/* ============================================
   DESKTOP/MAC REFINEMENTS
   ============================================ */

/* Limitador de Conteúdo p/ Monitores Grandes e Ultrawide */
.container,
.container-fluid {
    max-width: var(--max-container-width) !important;
    margin-left: auto;
    margin-right: auto;
}

/* Tipografia Fluida (H1 a H6) */
h1, .h1 { font-size: var(--font-size-h1) !important; font-weight: 800; letter-spacing: -0.02em; }
h2, .h2 { font-size: var(--font-size-h2) !important; font-weight: 700; letter-spacing: -0.01em; }
h3, .h3 { font-size: var(--font-size-h3) !important; font-weight: 600; }

/* Custom Webkit Scrollbars (Windows/Linux Modern View) */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ============================================
   MOBILE UNIVERSAL & TOUCH-FRIENDLY
   ============================================ */

/* Botões, Links e Elementos acionáveis com Touch Target Seguro de 44x44 (Motorola/Samsung/Apple) */
button,
a.btn,
input[type="button"],
input[type="submit"],
input[type="reset"],
a[role="button"],
.social-link {
    min-height: var(--touch-target-size);
    min-width: var(--touch-target-size);
    padding: var(--touch-target-padding) 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Inputs form: "font-size: 16px" mandatório p/ evitar zoom automático no iOS/Safari */
input,
textarea,
select,
.form-control,
.form-select {
    font-size: 16px !important; 
    border-radius: 8px;
    padding: 12px;
    min-height: var(--touch-target-size);
}

input:focus,
textarea:focus,
select:focus,
.form-control:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary-gold, #c5a059);
    box-shadow: 0 0 0 3px rgba(197, 160, 89, 0.15);
}

/* Imagens Fluidas - Prevenção de overflow */
img,
video,
iframe {
    max-width: 100%;
    height: auto;
    display: block;
}

picture {
    display: block;
}

/* ============================================
   iOS SAFE AREAS (Notch / Dynamic Island)
   ============================================ */

@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .container,
    .container-fluid {
        padding-left: max(16px, env(safe-area-inset-left)) !important;
        padding-right: max(16px, env(safe-area-inset-right)) !important;
    }
}

/* ============================================
   HIGH DPI/RETINA DISPLAYS (Apple Devices)
   ============================================ */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Borders crisp em alta definição */
    border,
    .border,
    .card,
    .sidebar-card,
    .cookie-banner {
        border-width: 0.5px !important;
    }

    /* Sombras refinadas (não estouram na Retina) */
    .shadow {
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05) !important;
    }
}

/* ============================================
   BREAKPOINTS (Mobile-First structure override)
   ============================================ */

/* Telas muito pequenas (Mobile em pé) */
@media (max-width: 575.98px) {
    /* Força botões a empilharem, mantendo o min-height seguro */
    button,
    .btn,
    .btn-outline-gold,
    .btn-assistir {
        width: 100%;
        margin-bottom: 12px;
    }

    button:last-child,
    .btn:last-child {
        margin-bottom: 0;
    }

    .card, .sidebar-card, .main-card {
        border-radius: 12px;
        margin-bottom: 16px;
        padding: 16px !important;
    }

    /* Modals em mobile devem aproveitar 100% da tela preservando o safe area */
    .modal-dialog {
        margin: 12px;
    }
    .modal-content {
        border-radius: 16px;
    }
}

/* Landscape Mode (Vários Celulares deitados) - Reduzir Alturas para economizar tela */
@media (max-height: 500px) and (orientation: landscape) {
    .header-top {
        padding: 10px 0 !important;
    }
    
    body {
        /* Compensa falta de height vertical */
        line-height: 1.4;
    }
}

/* ============================================
   DARK MODE SUPORTE NATIVO
   ============================================ */

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }

    body {
        background-color: #0f172a; /* Azul tech refinado ao invés do cinza puro */
        color: #f1f5f9;
        -webkit-font-smoothing: antialiased;
    }

    input,
    textarea,
    select {
        background-color: #1e293b;
        color: #f1f5f9;
        border-color: #334155;
    }

    .card,
    .sidebar-card,
    .main-card,
    .modal-content {
        background-color: #1e293b;
        border-color: #334155;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    }
    
    .table-custom thead th {
        background: #1e293b;
        color: #94a3b8;
        border-bottom-color: #334155;
    }
    .table-custom td {
        background: #1e293b;
        color: #f1f5f9;
        border-color: #334155;
    }
}

/* ============================================
   REDUCED MOTION (Acessibilidade OS)
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================
   TABELAS RESPONSIVAS -> CARDS (Universal Engine)
   ============================================ */

/* Design Base da Tabela Desktop */
.table-custom {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 10px;
}

.table-custom th {
    padding: 15px;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    border-bottom: 2px solid #e2e8f0;
}

.table-custom td {
    background: white;
    padding: 15px;
    vertical-align: middle;
    border-top: 1px solid #f1f5f9;
    border-bottom: 1px solid #f1f5f9;
}

/* 
  Padrão Excel Absoluto (Desktop):
  Célula 1: NR. (Centro)
  Célula 2: DATA (Centro)
  Célula 3: AULA (Esquerda - Leitura de Título)
  Célula 4: LINK/ACESSO (Centro)
  Célula 5: STATUS (Centro)
*/
.table-custom th:nth-child(1), .table-custom td:nth-child(1) { text-align: center; width: 6%; }
.table-custom th:nth-child(2), .table-custom td:nth-child(2) { text-align: center; width: 10%; }
.table-custom th:nth-child(3), .table-custom td:nth-child(3) { text-align: left; }
.table-custom th:nth-child(4), .table-custom td:nth-child(4) { text-align: center; width: 15%; }
.table-custom th:nth-child(5), .table-custom td:nth-child(5) { text-align: center; width: 15%; }

.table-custom tr td:first-child {
    border-top-left-radius: 12px;
    border-bottom-left-radius: 12px;
    border-left: 1px solid #f1f5f9;
}

.table-custom tr td:last-child {
    border-top-right-radius: 12px;
    border-bottom-right-radius: 12px;
    border-right: 1px solid #f1f5f9;
}

.status-badge {
    padding: 6px 14px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.status-ok { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.status-wait { background: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }

/* Telas Tablets/Laptops Pequenos */
@media (max-width: 1199px) {
    .header-logo {
        max-width: 180px;
        margin-top: 0;
    }
}

/* 991.98px: O Gateway de quebra (Tablet/iPad Portrait/Mobile) */
@media (max-width: 991.98px) {
    /* Esconde o Header da Tabela */
    .table-custom thead {
        display: none;
    }

    /* O Corpo da Tabela Vira Bloco */
    .table-custom,
    .table-custom tbody,
    .table-custom tr,
    .table-custom td {
        display: block;
        width: 100%;
    }

    /* Cada Linha Vira um Card */
    .table-custom tr {
        margin-bottom: 20px;
        border-radius: 16px;
        border: 1px solid #e2e8f0;
        overflow: hidden;
        background: white;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
    }

    /* Padrão Stacked V2 (Aprovado em Brainstorm) - Rótulo no topo e Valor embaixo */
    .table-custom td {
        text-align: left !important; /* Força reset do Padrão Excel */
        padding: 16px 20px;
        border: none;
        border-bottom: 1px solid #f1f5f9;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        font-size: 1rem;
        gap: 6px;
        color: #334155;
    }

    /* O Último item (Geralmente Ações/Botões) ocupa Centro total e sem borda */
    .table-custom td:last-child {
        border-bottom: none;
        background: #f8fafc;
        min-height: var(--touch-target-size);
        align-items: stretch;
        padding: 20px;
    }

    /* Pseudo-Elemento injeta o Rótulo ANTES do valor da célula */
    .table-custom td::before {
        content: attr(data-label);
        display: block;
        font-weight: 800;
        color: #94a3b8;
        font-size: 0.70rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-right: 0;
    }
}

/* ============================================
   FÓRUM & ADMIN UI REFINEMENTS (Universal Mobile)
   ============================================ */

/* Ocultar botões no Header Mobile se existir FAB (Floating Action Button) */
@media (max-width: 991.98px) {
    .btn-new {
        display: none !important;
    }
    
    .fab-mobile {
        display: flex !important;
        width: 56px;
        height: 56px;
        bottom: 20px;
        right: 16px;
        box-shadow: 0 4px 12px rgba(197, 160, 89, 0.4);
    }

    .topic-card {
        padding: 16px !important;
        border-radius: 16px !important;
        margin-bottom: 16px !important;
    }

    .topic-avatar {
        width: 50px !important;
        height: 50px !important;
        font-size: 1.4rem !important;
        margin-right: 12px !important;
    }

    .header-top {
        padding: 40px 0 60px !important;
        text-align: center;
    }

    .header-top::after {
        height: 50px;
    }

    .hero-title {
        margin-bottom: 20px;
    }

    .hero-subtitle {
        font-size: 1rem !important;
        margin: 0 auto 30px;
    }

    .header-logo {
        max-width: 150px !important;
        margin: 20px auto 0 !important;
    }

    .btn-premium-gold {
        width: 100%;
        justify-content: center;
    }

    /* Modal otimizado em mobile */
    .modal-dialog {
        margin: 10px !important;
    }

    .modal-fullscreen-lg-down {
        max-width: 100% !important;
        margin: 0 !important;
        width: 100% !important;
    }
}

/* ============================================
   ADMIN PANEL & SIDEBAR
   ============================================ */
.sidebar {
    width: 260px;
    height: 100vh;
    position: fixed;
    background: var(--dark-bg, #0f172a);
    color: white;
    padding-top: 20px;
    z-index: 1050;
    transition: transform 0.3s ease;
}

.sidebar a {
    color: #94a3b8;
    padding: 15px 25px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    font-weight: 600;
    transition: 0.2s;
    border-left: 4px solid transparent;
}

.sidebar a:hover,
.sidebar a.active {
    color: white;
    background: rgba(255, 255, 255, 0.05);
    border-left-color: var(--primary-gold, #c5a059);
}

.main {
    margin-left: 260px;
    padding: 30px;
    transition: margin-left 0.3s ease;
}

.card-stat {
    background: white;
    padding: 25px;
    border-radius: 16px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    border: 1px solid #f1f5f9;
}

.btn-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1100;
    background: var(--primary-gold, #c5a059);
    border: none;
    color: white;
    border-radius: 8px;
    padding: 8px 12px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
}
.overlay.active { display: block; }

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }
    .sidebar.active {
        transform: translateX(0);
    }
    .main {
        margin-left: 0;
        padding: 20px;
        padding-top: 70px;
    }
    .btn-toggle {
        display: block;
    }
}

/* ============================================
   PRINT SAFRAN (Legal/Fórum content out)
   ============================================ */

@media print {
    body {
        background-color: white !important;
        color: black !important;
    }

    .no-print, button, .btn, .header-top, .site-footer {
        display: none !important;
    }
}
