/* ===== RESPONSIVIDADE MOBILE FIRST ===== */

/* Suprimir seletor vazio gerado pelo Tailwind runtime */
element:empty {
    display: none;
}

/* Contenção de overflow global */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    max-width: 100vw;
    overflow-x: hidden;
    /* text-size-adjust removido - propriedade não suportada universalmente e causa avisos no console */
}

body {
    max-width: 100vw;
    overflow-x: hidden;
    min-height: 100vh;
    /* Safe area insets para dispositivos com notch */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Containers principais */
.container {
    max-width: 100%;
    overflow-x: hidden;
}

/* Tipografia responsiva com clamp */
h1 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
}

h2 {
    font-size: clamp(1.25rem, 3vw, 2rem);
}

h3 {
    font-size: clamp(1.125rem, 2.5vw, 1.5rem);
}

p, span, label {
    font-size: clamp(0.875rem, 2vw, 1rem);
}

button {
    font-size: clamp(0.875rem, 2vw, 1rem);
    min-height: 44px; /* Mínimo recomendado para touch targets */
}

/* Garantir que imagens e iframes sejam responsivos */
img, iframe, video {
    max-width: 100%;
    height: auto;
}

/* Text wrap para evitar cortes */
h1, h2, h3, h4, h5, h6 {
    text-wrap: balance;
    overflow-wrap: anywhere;
}

p, span, label {
    overflow-wrap: break-word;
}

/* Estilos customizados para o wizard */

.etapa {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Alpine.js x-cloak para ocultar elementos não inicializados */
[x-cloak] {
    display: none !important;
}

/* Melhorias de acessibilidade */
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Estilos para preview de fotos */
#fotos-preview img {
    transition: transform 0.2s;
}

#fotos-preview img:hover {
    transform: scale(1.05);
}

/* Responsividade para mobile */
@media (max-width: 640px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    input, select, textarea {
        font-size: 16px; /* Evita zoom no iOS */
    }
    
    /* Botão modo escuro menor no mobile */
    #dark-mode-toggle {
        padding: 0.5rem;
    }
    
    #moon-icon, #sun-icon {
        width: 1.25rem;
        height: 1.25rem;
    }
}

/* Garantir que cards e inputs sejam responsivos */
@media (max-width: 768px) {
    /* Estilos responsivos para cards - aplicados via classes Tailwind */
    .card-responsive {
        padding: 1rem;
    }
    
    /* Grid responsivo - aplicado via classes Tailwind */
    .grid-responsive {
        grid-template-columns: 1fr;
    }
}

/* Estilos de impressão */
@media print {
    header, footer, button, .no-print {
        display: none;
    }
    
    #protocolo {
        font-size: 2rem;
    }
}

/* Melhorias para modo escuro - Contraste de textos e placeholders */
.dark input::placeholder,
.dark textarea::placeholder {
    color: rgb(156, 163, 175); /* gray-400 */
    opacity: 0.8;
}

.dark input[type="text"]:not(:placeholder-shown),
.dark input[type="email"]:not(:placeholder-shown),
.dark input[type="tel"]:not(:placeholder-shown),
.dark textarea:not(:placeholder-shown) {
    color: rgb(243, 244, 246); /* gray-100 */
}

/* Garantir contraste em labels no modo escuro */
.dark label {
    color: rgb(229, 231, 235); /* gray-200 */
}

/* Melhorar contraste em textos de ajuda */
.dark .text-gray-500,
.dark .text-gray-400 {
    color: rgb(209, 213, 219); /* gray-300 */
}

/* Melhorar contraste em textos secundários */
.dark span:not(.text-white):not(.text-blue-600):not(.text-green-600):not(.text-red-600) {
    color: rgb(229, 231, 235); /* gray-200 */
}

/* Garantir que radios e checkboxes tenham bom contraste */
.dark input[type="radio"] + span,
.dark input[type="checkbox"] + span {
    color: rgb(229, 231, 235); /* gray-200 */
}

/* Garantir contraste em seleções */
.dark select option {
    background-color: rgb(31, 41, 55); /* gray-800 */
    color: rgb(243, 244, 246); /* gray-100 */
}

/* Melhorar contraste em textos dentro de cards e containers */
.dark p:not(.text-white):not(.text-blue-600):not(.text-green-600):not(.text-red-600) {
    color: rgb(229, 231, 235); /* gray-200 */
}

/* Garantir que strong tags tenham bom contraste */
.dark strong {
    color: rgb(243, 244, 246); /* gray-100 */
}

/* Melhorar contraste em listas */
.dark ul li,
.dark ol li {
    color: rgb(229, 231, 235); /* gray-200 */
}

/* Área de Drag & Drop */
#drop-zone {
    position: relative;
}

#drop-zone.dragging {
    border-color: #3b82f6 !important;
    background-color: rgba(59, 130, 246, 0.05);
}

.dark #drop-zone.dragging {
    background-color: rgba(59, 130, 246, 0.1);
}

/* Miniaturas de fotos - garantir aspecto quadrado */
#fotos-preview > div {
    aspect-ratio: 1 / 1;
}

#fotos-preview img {
    object-fit: cover;
    width: 100%;
    height: 100%;
}

/* Animação ao adicionar foto */
@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

#fotos-preview > div {
    animation: fadeInScale 0.3s ease-out;
}

/* Melhorar hover nos cards de foto */
#fotos-preview > div:hover {
    transform: translateY(-2px);
}

/* Garantir que a área de drop seja visível */
#drop-zone:hover {
    border-color: #60a5fa !important;
}

.dark #drop-zone:hover {
    border-color: #3b82f6 !important;
}

/* ===== ZOOM E ROTAÇÃO ===== */

/* Permitir zoom em galerias de imagens */
.image-gallery {
    touch-action: pan-y pinch-zoom;
    overflow: hidden;
}

/* Containers de conteúdo devem conter zoom */
main, .container {
    position: relative;
    isolation: isolate;
}

/* ===== MAPA RESPONSIVO ===== */

/* Container do mapa */
#mapa-localizacao {
    width: 100%;
    height: 400px;
    position: relative;
    z-index: 1;
    touch-action: pan-y pinch-zoom;
}

@media (max-width: 640px) {
    #mapa-localizacao {
        height: 300px;
    }
}

/* Leaflet - ajustar z-index das camadas */
.leaflet-pane {
    z-index: 4;
}

.leaflet-tile-pane {
    z-index: 2;
}

.leaflet-overlay-pane {
    z-index: 4;
}

.leaflet-shadow-pane {
    z-index: 5;
}

.leaflet-marker-pane {
    z-index: 6;
}

.leaflet-tooltip-pane {
    z-index: 7;
}

.leaflet-popup-pane {
    z-index: 7;
}

.leaflet-map-pane canvas {
    z-index: 1;
}

.leaflet-map-pane svg {
    z-index: 2;
}

/* Controles do mapa devem ficar acima */
.leaflet-control-zoom,
.leaflet-control-attribution {
    z-index: 10 !important;
}

/* Garantir que modais e overlays fiquem acima do mapa */
.loading-overlay,
[x-show="isSubmitting"] {
    z-index: 9999 !important;
}

/* ===== ORIENTAÇÃO E LARGURAS ESPECÍFICAS ===== */

/* Extra small devices (320px) */
@media (max-width: 320px) {
    body {
        font-size: 14px;
    }
    
    .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    button {
        padding: 0.5rem 0.75rem;
    }
}

/* Small devices (360px - 414px) */
@media (min-width: 360px) and (max-width: 414px) {
    .grid-cols-2 {
        gap: 0.75rem;
    }
}

/* Landscape mode adjustments */
@media (orientation: landscape) and (max-height: 500px) {
    header {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
    
    header img {
        height: 3rem;
    }
    
    #mapa-localizacao {
        height: 250px;
    }
}

/* ===== HIT AREAS (ACESSIBILIDADE) ===== */

/* Garantir mínimo de 40px para touch targets */
a, button, input[type="radio"], input[type="checkbox"], select {
    min-height: 40px;
    min-width: 40px;
}

/* Exceção para inputs de texto que já são maiores */
input[type="text"],
input[type="email"],
input[type="tel"],
textarea {
    min-height: 44px;
}

/* Estados de foco visíveis */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid #3b82f6;
    outline-offset: 2px;
}

/* ===== CHECKBOXES RESPONSIVOS ===== */

/* Ajustar tamanho de checkboxes e radios para melhor usabilidade mobile */
input[type="checkbox"],
input[type="radio"] {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

/* Garantir espaçamento adequado entre checkbox/radio e label */
input[type="checkbox"] + span,
input[type="radio"] + span {
    margin-left: 0.5rem;
}

/* ===== MODAL DE TERMOS - FULL SCREEN ===== */

/* FORÇA BRUTA: Modal sempre no topo absoluto */
.fixed.inset-0[style*="z-index: 99999"] {
    z-index: 99999 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
}

/* Prevenir scroll do body quando modal estiver aberto */
body.modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100vh !important;
}

/* Footer deve ficar atrás do modal */
footer {
    z-index: 10 !important;
    position: relative !important;
}

/* Header deve ficar atrás do modal */
header {
    z-index: 20 !important;
    position: relative !important;
}

/* Botão dark mode deve ficar atrás do modal */
.fixed.top-4.right-4.z-50 {
    z-index: 50 !important;
}

/* No mobile, garantir que o modal ocupe toda a tela */
@media (max-width: 640px) {
    .fixed.inset-0[style*="z-index: 99999"] > div {
        max-height: 100vh !important;
        height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }
}

