/* ==========================================
   📱 RESPONSIVE ENHANCEMENTS v1.1.0
   Melhorias de Adaptabilidade para TODOS os Dispositivos
   ========================================== */

/* ========== VARIÁVEIS RESPONSIVAS ADICIONAIS ========== */
:root {
    /* Breakpoints padronizados */
    --bp-xs: 320px;   /* Celular pequeno */
    --bp-sm: 480px;   /* Celular */
    --bp-md: 768px;   /* Tablet */
    --bp-lg: 1024px;  /* Tablet landscape / Desktop pequeno */
    --bp-xl: 1280px;  /* Desktop */
    --bp-2xl: 1536px; /* Desktop grande */

    /* Container responsivos */
    --container-xs: 100%;
    --container-sm: 540px;
    --container-md: 720px;
    --container-lg: 960px;
    --container-xl: 1140px;
    --container-2xl: 1320px;

    /* Espaçamentos adaptativos */
    --gap-xs: clamp(0.5rem, 2vw, 1rem);
    --gap-sm: clamp(0.75rem, 2.5vw, 1.25rem);
    --gap-md: clamp(1rem, 3vw, 1.5rem);
    --gap-lg: clamp(1.5rem, 4vw, 2rem);
    --gap-xl: clamp(2rem, 5vw, 3rem);

    /* Grid columns responsivas */
    --cols-mobile: 1;
    --cols-tablet: 2;
    --cols-desktop: 3;
    --cols-wide: 4;
}

/* ========== CONTAINER ADAPTATIVO MELHORADO ========== */
.container {
    width: 100%;
    max-width: var(--container-2xl);
    margin-inline: auto;
    padding-inline: clamp(1rem, 5vw, 2rem);
}

/* Containers específicos por tamanho */
@media (min-width: 320px) {
    .container { max-width: var(--container-xs); }
}

@media (min-width: 640px) {
    .container { max-width: var(--container-sm); }
}

@media (min-width: 768px) {
    .container { max-width: var(--container-md); }
}

@media (min-width: 1024px) {
    .container { max-width: var(--container-lg); }
}

@media (min-width: 1280px) {
    .container { max-width: var(--container-xl); }
}

@media (min-width: 1536px) {
    .container { max-width: var(--container-2xl); }
}

/* ========== GRID RESPONSIVO UNIVERSAL ========== */
.grid-responsive {
    display: grid;
    gap: var(--gap-md);
    grid-template-columns: repeat(var(--cols-mobile), 1fr);
}

@media (min-width: 640px) {
    .grid-responsive {
        grid-template-columns: repeat(var(--cols-tablet), 1fr);
    }
}

@media (min-width: 1024px) {
    .grid-responsive {
        grid-template-columns: repeat(var(--cols-desktop), 1fr);
    }
}

@media (min-width: 1536px) {
    .grid-responsive {
        grid-template-columns: repeat(var(--cols-wide), 1fr);
    }
}

/* ========== FLEX RESPONSIVO ========== */
.flex-responsive {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-md);
}

.flex-responsive > * {
    flex: 1 1 100%;
    min-width: 0; /* Previne overflow */
}

@media (min-width: 640px) {
    .flex-responsive > * {
        flex: 1 1 calc(50% - var(--gap-md));
    }
}

@media (min-width: 1024px) {
    .flex-responsive > * {
        flex: 1 1 calc(33.333% - var(--gap-md));
    }
}

/* ========== CARDS RESPONSIVOS ========== */
.card-responsive {
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: clamp(8px, 2vw, 16px);
    padding: clamp(1rem, 3vw, 1.5rem);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card-responsive:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

@media (min-width: 768px) {
    .card-responsive {
        flex-direction: row;
        align-items: center;
        gap: var(--gap-md);
    }
}

/* ========== TABELAS RESPONSIVAS ========== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scroll iOS */
    margin-block: var(--gap-md);
}

.table-responsive table {
    width: 100%;
    min-width: 600px; /* Previne quebra em mobile */
    border-collapse: collapse;
}

/* Mobile: Transformar tabela em cards */
@media (max-width: 640px) {
    .table-mobile-cards thead {
        position: absolute;
        left: -9999px; /* Hide visually */
    }

    .table-mobile-cards tr {
        display: block;
        margin-bottom: var(--gap-md);
        border: 1px solid #ddd;
        border-radius: 8px;
        padding: var(--gap-sm);
    }

    .table-mobile-cards td {
        display: flex;
        justify-content: space-between;
        padding: var(--gap-xs);
        border-bottom: 1px solid #eee;
    }

    .table-mobile-cards td:last-child {
        border-bottom: none;
    }

    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: bold;
        margin-right: var(--gap-sm);
    }
}

/* ========== IMAGENS RESPONSIVAS ========== */
img, picture, video, canvas, svg {
    max-width: 100%;
    height: auto;
    display: block;
}

.img-responsive {
    width: 100%;
    height: auto;
    object-fit: cover;
    aspect-ratio: 16 / 9; /* Mantém proporção */
}

/* Aspect ratios comuns */
.aspect-square { aspect-ratio: 1 / 1; }
.aspect-video { aspect-ratio: 16 / 9; }
.aspect-portrait { aspect-ratio: 3 / 4; }
.aspect-widescreen { aspect-ratio: 21 / 9; }

/* ========== TIPOGRAFIA RESPONSIVA APRIMORADA ========== */
.text-responsive-xs { font-size: clamp(0.75rem, 1.5vw, 0.875rem); }
.text-responsive-sm { font-size: clamp(0.875rem, 2vw, 1rem); }
.text-responsive-base { font-size: clamp(1rem, 2.5vw, 1.125rem); }
.text-responsive-md { font-size: clamp(1.125rem, 3vw, 1.25rem); }
.text-responsive-lg { font-size: clamp(1.25rem, 3.5vw, 1.5rem); }
.text-responsive-xl { font-size: clamp(1.5rem, 4vw, 2rem); }
.text-responsive-2xl { font-size: clamp(2rem, 5vw, 3rem); }
.text-responsive-3xl { font-size: clamp(2.5rem, 6vw, 4rem); }

/* ========== BUTTONS TOUCH-FRIENDLY ========== */
.btn-responsive {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 48px; /* Touch target mínimo */
    min-width: 48px;
    padding-inline: clamp(1rem, 3vw, 2rem);
    padding-block: clamp(0.75rem, 2vw, 1rem);
    font-size: clamp(0.875rem, 2vw, 1rem);
    border-radius: clamp(6px, 1.5vw, 12px);
    transition: all 0.2s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* Feedback visual em touch */
.btn-responsive:active {
    transform: scale(0.98);
}

@media (hover: hover) {
    .btn-responsive:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
}

/* ========== NAVEGAÇÃO RESPONSIVA ========== */
.nav-responsive {
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
}

@media (min-width: 768px) {
    .nav-responsive {
        flex-direction: row;
        align-items: center;
        gap: var(--gap-md);
    }
}

/* ========== MODALS/DIALOGS RESPONSIVOS ========== */
.modal-responsive {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: flex-end; /* Mobile: bottom sheet */
    justify-content: center;
    padding: 0;
    z-index: 9999;
}

.modal-content-responsive {
    background: white;
    border-radius: 20px 20px 0 0; /* Mobile: bottom sheet */
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: var(--gap-lg);
}

@media (min-width: 768px) {
    .modal-responsive {
        align-items: center; /* Desktop: centered */
        padding: var(--gap-xl);
    }

    .modal-content-responsive {
        border-radius: 20px; /* Desktop: all corners */
        width: auto;
        min-width: 500px;
        max-width: 90vw;
    }
}

/* ========== FORMULÁRIOS RESPONSIVOS ========== */
.form-responsive {
    display: flex;
    flex-direction: column;
    gap: var(--gap-md);
}

.form-group-responsive {
    display: flex;
    flex-direction: column;
    gap: var(--gap-xs);
}

.form-row-responsive {
    display: flex;
    flex-direction: column;
    gap: var(--gap-md);
}

@media (min-width: 768px) {
    .form-row-responsive {
        flex-direction: row;
    }

    .form-row-responsive > * {
        flex: 1;
    }
}

.input-responsive {
    width: 100%;
    min-height: 48px; /* Touch target */
    padding-inline: clamp(0.75rem, 2vw, 1rem);
    padding-block: clamp(0.5rem, 1.5vw, 0.75rem);
    font-size: clamp(0.875rem, 2vw, 1rem);
    border: 2px solid #ddd;
    border-radius: clamp(6px, 1.5vw, 12px);
    transition: border-color 0.2s;
}

.input-responsive:focus {
    outline: none;
    border-color: #9b59b6;
    box-shadow: 0 0 0 3px rgba(155, 89, 182, 0.1);
}

/* ========== SCROLL SNAP (CARROSSÉIS MOBILE) ========== */
.scroll-snap-container {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    gap: var(--gap-md);
    scrollbar-width: none; /* Firefox */
}

.scroll-snap-container::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.scroll-snap-item {
    scroll-snap-align: start;
    flex: 0 0 85%; /* Mobile */
}

@media (min-width: 640px) {
    .scroll-snap-item {
        flex: 0 0 45%;
    }
}

@media (min-width: 1024px) {
    .scroll-snap-item {
        flex: 0 0 30%;
    }
}

/* ========== VISIBILITY UTILITIES ========== */
/* Esconder em mobile */
.hide-xs { display: none !important; }

@media (min-width: 640px) {
    .hide-xs { display: initial !important; }
}

/* Esconder em tablet */
@media (min-width: 640px) and (max-width: 1023px) {
    .hide-md { display: none !important; }
}

/* Esconder em desktop */
@media (min-width: 1024px) {
    .hide-lg { display: none !important; }
}

/* Mostrar apenas em mobile */
.show-xs { display: initial !important; }

@media (min-width: 640px) {
    .show-xs { display: none !important; }
}

/* ========== SAFE AREAS (iOS NOTCH) ========== */
@supports (padding: max(0px)) {
    .safe-top {
        padding-top: max(1rem, env(safe-area-inset-top));
    }

    .safe-bottom {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }

    .safe-left {
        padding-left: max(1rem, env(safe-area-inset-left));
    }

    .safe-right {
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .safe-all {
        padding:
            max(1rem, env(safe-area-inset-top))
            max(1rem, env(safe-area-inset-right))
            max(1rem, env(safe-area-inset-bottom))
            max(1rem, env(safe-area-inset-left));
    }
}

/* ========== ORIENTATION ADAPTATIONS ========== */
@media (orientation: landscape) and (max-height: 600px) {
    /* Landscape mobile: reduzir paddings verticais */
    .container {
        padding-block: var(--gap-sm);
    }

    .modal-content-responsive {
        max-height: 85vh;
    }

    .btn-responsive {
        padding-block: 0.5rem;
    }
}

/* ========== HIGH CONTRAST MODE ========== */
@media (prefers-contrast: high) {
    .card-responsive {
        border: 2px solid currentColor;
    }

    .input-responsive {
        border-width: 3px;
    }

    .btn-responsive {
        border: 2px solid currentColor;
    }
}

/* ========== REDUCED MOTION ========== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ========== PRINT STYLES ========== */
@media print {
    .hide-print {
        display: none !important;
    }

    .container {
        max-width: 100%;
        box-shadow: none;
    }

    .card-responsive {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* ========== LOADING STATES RESPONSIVOS ========== */
.skeleton-responsive {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
    border-radius: clamp(4px, 1vw, 8px);
    min-height: 20px;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ========== ZOOM RESPONSIVO (Acessibilidade) ========== */
@media (min-resolution: 2dppx) {
    /* Telas Retina: ajustar renderização */
    body {
        -webkit-font-smoothing: subpixel-antialiased;
    }
}

/* ========== UTILITIES DE ESPAÇAMENTO ========== */
.p-responsive-xs { padding: var(--gap-xs); }
.p-responsive-sm { padding: var(--gap-sm); }
.p-responsive-md { padding: var(--gap-md); }
.p-responsive-lg { padding: var(--gap-lg); }
.p-responsive-xl { padding: var(--gap-xl); }

.m-responsive-xs { margin: var(--gap-xs); }
.m-responsive-sm { margin: var(--gap-sm); }
.m-responsive-md { margin: var(--gap-md); }
.m-responsive-lg { margin: var(--gap-lg); }
.m-responsive-xl { margin: var(--gap-xl); }

/* ========== OVERFLOW HANDLING ========== */
.overflow-responsive {
    overflow: hidden;
}

@media (max-width: 640px) {
    .overflow-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========== FULL BLEED (Edge-to-edge) ========== */
.full-bleed {
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
}

/* ========== STATUS INDICATOR ========== */
.status-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 8px 12px;
    background: rgba(0,0,0,0.8);
    color: white;
    border-radius: 8px;
    font-size: 12px;
    z-index: 99999;
    pointer-events: none;
}

@media (min-width: 640px) {
    .status-indicator::after {
        content: ' - Tablet';
    }
}

@media (min-width: 1024px) {
    .status-indicator::after {
        content: ' - Desktop';
    }
}

@media (max-width: 639px) {
    .status-indicator::after {
        content: ' - Mobile';
    }
}

/* ========== ACCESSIBILITY ========== */
/* Melhor foco para teclado */
*:focus-visible {
    outline: 3px solid #9b59b6;
    outline-offset: 2px;
}

/* Skip links */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #9b59b6;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* ==========================================
   FIM DAS MELHORIAS RESPONSIVAS
   ========================================== */
