/* Reset e Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: 'Roboto', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow-x: hidden;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    /* Compatibilidade cross-browser para altura */
    height: 100%;
}

/* Variáveis CSS - fallback para browsers mais antigos */
:root {
    --color-primary: #8B4513;
    --color-secondary: #DAA520;
    --color-tertiary: #FFD700;
    --color-quaternary: #FFFFFF;
}

/* === MOBILE ANDROID OTIMIZADO === */
.app-container {
    flex: 1;
    padding: 1rem 0.75rem;
    /* Espaço para status bar Android */
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: env(safe-area-inset-bottom);
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

/* Seletor de Idioma */
.language-switcher {
    position: fixed;
    top: max(0.5rem, env(safe-area-inset-top));
    right: 0.5rem;
    display: flex;
    gap: 0.4rem;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.97);
    padding: 0.4rem;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    /* Compatibilidade */
    -webkit-box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.language-switcher button {
    background: white;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    padding: 0.2rem;
    -webkit-transition: all 0.2s;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    /* Touch target mínimo 44x44 - Android guideline */
    min-width: 44px;
    min-height: 44px;
}

.language-switcher button svg {
    display: block;
    border-radius: 3px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    width: 30px;
    height: 22px;
}

.language-switcher button.active {
    border-color: var(--color-tertiary);
    background: rgba(255, 215, 0, 0.15);
    -webkit-transform: scale(1.05);
    transform: scale(1.05);
}

.language-switcher button:active {
    -webkit-transform: scale(0.95);
    transform: scale(0.95);
}

/* Grid de Botões - Mobile First */
.button-grid {
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    gap: 0.75rem;
    width: 100%;
    margin: 0 auto;
    -webkit-justify-content: center;
    justify-content: center;
}

.button-grid > * {
    -webkit-flex: 0 0 calc(50% - 0.375rem);
    -ms-flex: 0 0 calc(50% - 0.375rem);
    flex: 0 0 calc(50% - 0.375rem);
    max-width: calc(50% - 0.375rem);
}

/* Botões Mobile Home e Admin - Estilo Android Material */
.btn-mobile-home,
.btn-mobile-admin {
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 1.5rem 0.75rem;
    border-radius: 16px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    -webkit-box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    -webkit-transition: all 0.15s;
    transition: all 0.15s;
    min-height: 120px;
    background: var(--color-tertiary);
    color: var(--color-quaternary);
    text-align: center;
    width: 100%;
    /* Ripple effect Android */
    position: relative;
    overflow: hidden;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.btn-mobile-home i,
.btn-mobile-admin i {
    font-size: 1.75rem;
}

.btn-mobile-home:active,
.btn-mobile-admin:active {
    -webkit-transform: scale(0.94);
    transform: scale(0.94);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    -webkit-box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* Ripple effect para Android */
.btn-mobile-home::after,
.btn-mobile-admin::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: rgba(255,255,255,0.15);
    opacity: 0;
    -webkit-transition: opacity 0.2s;
    transition: opacity 0.2s;
    pointer-events: none;
}

.btn-mobile-home:active::after,
.btn-mobile-admin:active::after {
    opacity: 1;
}

/* Botão Voltar - Android style */
.btn-voltar {
    background: var(--color-tertiary);
    color: var(--color-quaternary);
    padding: 0.65rem 1.25rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    -webkit-box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    -webkit-transition: all 0.15s;
    transition: all 0.15s;
    display: -webkit-inline-flex;
    display: inline-flex;
    -webkit-align-items: center;
    align-items: center;
    margin-bottom: 1rem;
    min-height: 44px;
}

.btn-voltar:active {
    -webkit-transform: scale(0.95);
    transform: scale(0.95);
}

/* Botões Gerais */
.btn-mobile,
.btn-primary {
    width: 100%;
    padding: 0.9rem;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
    -webkit-box-shadow: 0 3px 8px rgba(0,0,0,0.15);
    -webkit-transition: all 0.15s;
    transition: all 0.15s;
    min-height: 48px;
    display: block;
    text-align: center;
}

.btn-primary {
    background: var(--color-tertiary);
    color: var(--color-quaternary);
}

.btn-mobile:active,
.btn-primary:active {
    -webkit-transform: scale(0.97);
    transform: scale(0.97);
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    -webkit-box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Botão Relatório */
.btn-relatorio {
    background: #dc2626;
    color: white;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    -webkit-box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    -webkit-transition: all 0.15s;
    transition: all 0.15s;
    min-height: 44px;
}

.btn-relatorio:active {
    background: #b91c1c;
    -webkit-transform: scale(0.96);
    transform: scale(0.96);
}

/* Botões de ação (tabelas) */
.btn-alterar,
.btn-excluir,
.btn-gravar,
.btn-novo {
    display: -webkit-inline-flex;
    display: inline-flex;
    -webkit-align-items: center;
    align-items: center;
    gap: 4px;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    margin: 2px;
    min-height: 36px;
    -webkit-transition: all 0.15s;
    transition: all 0.15s;
}

.btn-alterar {
    background: var(--color-tertiary);
    color: var(--color-quaternary);
}

.btn-excluir {
    background: #dc2626;
    color: white;
}

.btn-gravar {
    background: #16a34a;
    color: white;
}

.btn-novo {
    background: var(--color-tertiary);
    color: var(--color-quaternary);
    font-size: 0.9rem;
    padding: 0.6rem 1.2rem;
}

.btn-alterar:active,
.btn-excluir:active,
.btn-gravar:active,
.btn-novo:active {
    opacity: 0.8;
    -webkit-transform: scale(0.95);
    transform: scale(0.95);
}

/* === FORMULÁRIOS - Mobile Friendly === */
.form-input {
    width: 100%;
    padding: 0.8rem 0.75rem;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    /* 16px evita zoom automático no iOS e Android */
    font-size: 16px !important;
    background: white;
    color: #111;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    -webkit-transition: border-color 0.2s;
    transition: border-color 0.2s;
    min-height: 48px;
    /* Cross-browser */
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-tertiary);
    box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.2);
    -webkit-box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.2);
}

/* Estilo select */
select.form-input {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-container,
.config-form,
.config-container {
    background: rgba(255, 255, 255, 0.08);
    padding: 1.25rem;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.15);
}

/* === LOGO === */
.logo-container {
    width: 160px;
    height: 160px;
    margin: 2.5rem auto 1.75rem;
}

.logo-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 14px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.25);
    -webkit-box-shadow: 0 6px 16px rgba(0,0,0,0.25);
}

/* === RODAPÉ === */
footer {
    padding: 1rem;
    text-align: center;
    color: white;
    margin-top: auto;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    /* Garante visibilidade em todos os browsers */
    position: relative;
    z-index: 1;
}

.footer-logo {
    width: 50px;
    height: 35px;
    object-fit: cover;
    border-radius: 4px;
}

/* === TABELAS - Mobile Scroll === */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: white;
    border-radius: 12px;
    box-shadow: 0 3px 8px rgba(0,0,0,0.1);
    -webkit-box-shadow: 0 3px 8px rgba(0,0,0,0.1);
    /* Força scroll horizontal em todos os browsers */
    display: block;
    width: 100%;
}

table {
    min-width: 100%;
    font-size: 0.85rem;
    border-collapse: collapse;
    width: 100%;
}

th, td {
    padding: 0.6rem 0.5rem;
    text-align: left;
    white-space: nowrap;
}

th {
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.78rem;
    letter-spacing: 0.03em;
}

tbody tr {
    border-bottom: 1px solid #f0f0f0;
    -webkit-transition: background-color 0.15s;
    transition: background-color 0.15s;
}

tbody tr:active {
    background-color: rgba(0,0,0,0.04);
}

/* === GALERIA DE FOTOS === */
.foto-grid {
    display: -ms-grid;
    display: grid;
    -ms-grid-columns: 1fr 0.75rem 1fr;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

@media (min-width: 480px) {
    .foto-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.foto-item {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
    -webkit-box-shadow: 0 3px 8px rgba(0,0,0,0.15);
    -webkit-transition: -webkit-transform 0.2s;
    transition: transform 0.2s;
    aspect-ratio: 2/3;
    background: #f0f0f0;
}

.foto-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.foto-item button {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    background: rgba(239, 68, 68, 0.92);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    -webkit-transition: all 0.15s;
    transition: all 0.15s;
}

.foto-item button:active {
    background: rgba(220, 38, 38, 1);
    -webkit-transform: scale(1.1);
    transform: scale(1.1);
}

/* === COLOR PICKER === */
.color-picker-container {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: 0.75rem;
}

.color-preview {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    border: 2px solid #e5e7eb;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    -webkit-box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}

input[type="color"] {
    height: 48px;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid #e5e7eb;
    padding: 2px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
    border-radius: 6px;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 6px;
}

/* === TEXTAREA === */
textarea.form-input {
    resize: vertical;
    min-height: 100px;
    line-height: 1.5;
}

/* === MODAL === */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
    /* iOS/Android fix */
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
}

.modal-content {
    max-width: 400px;
    width: 100%;
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    -webkit-box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    -webkit-animation: modalFadeIn 0.25s ease;
    animation: modalFadeIn 0.25s ease;
    margin: auto;
}

@-webkit-keyframes modalFadeIn {
    from {
        opacity: 0;
        -webkit-transform: scale(0.88) translateY(20px);
        transform: scale(0.88) translateY(20px);
    }
    to {
        opacity: 1;
        -webkit-transform: scale(1) translateY(0);
        transform: scale(1) translateY(0);
    }
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.88) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* === HIDDEN === */
.hidden {
    display: none !important;
}

/* === ANIMAÇÕES === */
@-webkit-keyframes fadeIn {
    from {
        opacity: 0;
        -webkit-transform: translateY(8px);
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        -webkit-transform: translateY(0);
        transform: translateY(0);
    }
}

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

.app-container > div:not(.hidden) {
    -webkit-animation: fadeIn 0.25s ease-in-out;
    animation: fadeIn 0.25s ease-in-out;
}

/* === SCROLLBAR === */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-tertiary);
    border-radius: 4px;
}

/* === FOCO ACESSÍVEL === */
*:focus-visible {
    outline: 3px solid var(--color-tertiary);
    outline-offset: 2px;
}

/* === RESPONSIVO - BREAKPOINTS ANDROID === */

/* Telas muito pequenas - 320px */
@media (max-width: 360px) {
    .app-container {
        padding: 0.75rem 0.5rem;
    }

    .btn-mobile-home,
    .btn-mobile-admin {
        min-height: 100px;
        padding: 1.1rem 0.5rem;
        font-size: 0.8rem;
    }

    .btn-mobile-home i,
    .btn-mobile-admin i {
        font-size: 1.5rem;
    }

    .logo-container {
        width: 130px;
        height: 130px;
        margin: 2rem auto 1.25rem;
    }
}

/* Telas médias - 360px a 480px (Android comum) */
@media (min-width: 361px) and (max-width: 479px) {
    .btn-mobile-home,
    .btn-mobile-admin {
        min-height: 115px;
    }
}

/* Tablets */
@media (min-width: 600px) {
    .app-container {
        padding: 1.5rem 1rem;
    }
    
    .button-grid > * {
        -webkit-flex: 0 0 calc(33.333% - 0.5rem);
        flex: 0 0 calc(33.333% - 0.5rem);
        max-width: calc(33.333% - 0.5rem);
    }

    .btn-mobile-home,
    .btn-mobile-admin {
        min-height: 130px;
    }

    .logo-container {
        width: 180px;
        height: 180px;
    }

    .foto-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* == COMPATIBILIDADE FIREFOX == */
@-moz-document url-prefix() {
    .form-input {
        padding: 0.75rem;
    }
    
    input[type="color"] {
        padding: 4px;
    }
}

/* === PRINT === */
@media print {
    .btn-mobile, .btn-voltar, button, footer, .language-switcher {
        display: none !important;
    }
    
    body {
        background: white !important;
    }
    
    .app-container {
        padding: 0 !important;
    }
}

/* === LOADING === */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* === TRANSIÇÕES SUAVES === */
button,
a,
input[type="file"],
.foto-item,
select {
    cursor: pointer;
}

/* Suporte a prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    * {
        -webkit-animation-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        -webkit-transition-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* === TEMA ESCURO SUPORTE === */
@media (prefers-color-scheme: dark) {
    /* Mantemos o tema customizado via variáveis CSS */
    .form-input,
    .form-container,
    .modal-content {
        /* Não sobrescreve o tema do app */
    }
}

/* === SPECIFIC FIREFOX EDGE FIXES === */
/* Firefox: Fix flexbox gap */
.button-grid {
    /* Fallback margin para Firefox antigo */
}

/* Edge Legacy: Fix */
@supports (-ms-ime-align: auto) {
    .btn-mobile-home,
    .btn-mobile-admin {
        min-height: 120px;
    }
}

/* === TOAST/NOTIFICAÇÃO ANDROID STYLE === */
.toast-notification {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    -webkit-transform: translateX(-50%);
    transform: translateX(-50%);
    background: rgba(30,30,30,0.92);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 100px;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 9999;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    -webkit-box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    max-width: 90vw;
    text-align: center;
    -webkit-animation: toastIn 0.3s ease;
    animation: toastIn 0.3s ease;
}

@-webkit-keyframes toastIn {
    from {
        opacity: 0;
        -webkit-transform: translateX(-50%) translateY(20px);
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        -webkit-transform: translateX(-50%) translateY(0);
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* === FORM LABELS === */
label.block {
    font-size: 0.9rem;
    margin-bottom: 0.3rem;
    font-weight: 600;
}

/* === SPACE-Y PADRÃO === */
.space-y-4 > * + * {
    margin-top: 1rem;
}

.space-y-6 > * + * {
    margin-top: 1.5rem;
}

/* === GRID 2 COLUNAS NO FORMULÁRIO === */
.grid.grid-cols-2 {
    display: -ms-grid;
    display: grid;
    -ms-grid-columns: 1fr 1rem 1fr;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* === CHECKBOX E RADIO ANDROID STYLE === */
input[type="radio"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--color-tertiary);
    -webkit-appearance: auto;
    appearance: auto;
}

input[type="file"].form-input {
    padding: 0.6rem;
    font-size: 0.9rem;
    min-height: 44px;
}

/* Borda com tema */
.border-2 {
    border-width: 2px;
    border-style: solid;
}

.rounded-lg {
    border-radius: 10px;
}
