/* ==============================================
   RESPONSIVIDADE GLOBAL - GymFlow
   ============================================== */

/* Mobile First - Base Styles */
@media (max-width: 767px) {
    /* Padding reduzido em mobile */
    main {
        padding: 1rem !important;
        padding-top: 80px !important;
    }
    
    /* Títulos menores em mobile */
    main h1 {
        font-size: 1.75rem !important; /* 28px */
        line-height: 1.2 !important;
    }
    
    h2 {
        font-size: 1.5rem !important; /* 24px */
    }
    
    h3 {
        font-size: 1.25rem !important; /* 20px */
    }
    
    /* Tabelas responsivas */
    .pro-table {
        font-size: 0.875rem !important; /* 14px */
    }
    
    .pro-table th,
    .pro-table td {
        padding: 0.75rem 1rem !important;
    }
    
    /* O padding pertence ao conteúdo de cada card; aplicá-lo globalmente
       quebrava tabelas com scroll e cards que já tinham espaçamento próprio. */
    .glass-card { border-radius: 1rem !important; }
    
    /* Botões full-width em mobile */
    .btn-primary,
    .btn-secondary {
        width: 100%;
        justify-content: center;
    }
    
    /* Modais mais compactos */
    .modal-content {
        max-height: 90vh;
        overflow-y: auto;
    }
    
    /* Grid sempre 1 coluna em mobile */
    .grid-responsive {
        grid-template-columns: 1fr !important;
    }
    
    /* Inputs maiores para touch */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="password"],
    input[type="time"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important; /* Previne zoom no iOS */
        padding: 0.875rem !important;
    }
    
    /* Badges menores */
    .badge {
        font-size: 0.6875rem !important; /* 11px */
        padding: 0.25rem 0.5rem !important;
    }
    
    /* Ocultar colunas não essenciais em tabelas */
    .hidden-mobile {
        display: none !important;
    }
    
    /* Sticky headers em mobile */
    .sticky-mobile {
        position: sticky;
        top: 0;
        z-index: 10;
        background: inherit;
    }
    
    /* Ajustar gap dos grids */
    .gap-6 {
        gap: 1rem !important;
    }
    
    .gap-4 {
        gap: 0.75rem !important;
    }
    
    /* Margem bottom menor */
    .mb-10 {
        margin-bottom: 1.5rem !important;
    }
}

/* Tablet - 768px a 1023px */
@media (min-width: 768px) and (max-width: 1023px) {
    main {
        padding: 1.5rem !important;
        padding-top: 5rem !important;
    }
    
    main h1 {
        font-size: 2rem !important; /* 32px */
        line-height: 1.15 !important;
    }
    
    /* 2 colunas em tablet */
    .grid-responsive {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
}

/* Desktop - 1024px+ */
@media (min-width: 1024px) {
    main {
        padding: 2.5rem !important;
    }

    main h1 { font-size: 2rem !important; line-height: 1.15 !important; }
    
    /* 3 colunas em desktop */
    .grid-responsive {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* Large Desktop - 1440px+ */
@media (min-width: 1440px) {
    main {
        padding: 3rem !important;
    }
    
    /* 4 colunas em telas grandes */
    .grid-responsive-xl {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
    /* Botões maiores para touch */
    button,
    .btn,
    a.btn {
        min-height: 44px; /* Tamanho mínimo recomendado */
    }
    
    /* Mais espaço entre elementos clicáveis */
    .clickable-row {
        padding: 1rem !important;
    }
}

/* Landscape em mobile */
@media (max-width: 767px) and (orientation: landscape) {
    main {
        padding-top: 60px !important;
    }
    
    /* Modais ocupam mais espaço horizontal */
    .modal-content {
        max-width: 90vw !important;
    }
}

/* Impressão */
@media print {
    .no-print,
    aside,
    nav,
    button,
    .btn {
        display: none !important;
    }
    
    main {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    
    .glass-card {
        border: 1px solid #ccc !important;
        background: white !important;
        box-shadow: none !important;
    }
}

/* Animações reduzidas para acessibilidade */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Alto contraste */
@media (prefers-contrast: high) {
    .glass-card {
        border-width: 2px !important;
    }
    
    button,
    .btn {
        border: 2px solid currentColor !important;
    }
}

/* Overflow horizontal em tabelas */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive::-webkit-scrollbar {
    height: 8px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

/* Safe area para iOS notch */
@supports (padding: max(0px)) {
  @media (max-width: 767px) {
    main {
        padding-left: max(1rem, env(safe-area-inset-left)) !important;
        padding-right: max(1rem, env(safe-area-inset-right)) !important;
        padding-bottom: max(1rem, env(safe-area-inset-bottom)) !important;
    }
  }
  @media (min-width: 768px) and (max-width: 1023px) {
    main {
        padding-left: max(1.5rem, env(safe-area-inset-left)) !important;
        padding-right: max(1.5rem, env(safe-area-inset-right)) !important;
        padding-bottom: max(1.5rem, env(safe-area-inset-bottom)) !important;
    }
  }
}

/* Impede que tabelas e grids largos aumentem a largura do layout flex. */
main.flex-1,
main[class*="lg:ml-"] { min-width: 0; max-width: 100%; }

main img, main video, main canvas, main svg { max-width: 100%; }

/* Área rolável padrão para tabelas legadas. */
.overflow-x-auto, .table-responsive {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

/* Modais antigos passam a respeitar o tema e o tamanho do ecrã. */
.fixed.inset-0 > [class*="max-w-"] {
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    overscroll-behavior: contain;
}

html:not(.dark) .fixed.inset-0 > .bg-\[\#0f172a\],
html:not(.dark) .fixed.inset-0 > .bg-slate-900,
html:not(.dark) .fixed.inset-0 > .bg-slate-950 {
    background: var(--card) !important;
    border-color: var(--border) !important;
}

@media (max-width: 640px) {
    .fixed.inset-0 { padding: 0.75rem !important; }
    .fixed.inset-0 > [class*="max-w-"] { max-height: calc(100dvh - 1.5rem); border-radius: 1rem !important; }
}
