/* =====================================================
   SISTEMA DE GESTÃO DE IMÓVEIS
   CSS - Versão Corrigida para Mobile v2
   ===================================================== */

:root {
    --cor-primaria: #1a4d2e;
    --cor-primaria-hover: #143d24;
    --cor-secundaria: #2d6a4f;
    --cor-terciaria: #40916c;
    --branco: #ffffff;
    --cinza-claro: #f8f9fa;
    --cinza-medio: #e9ecef;
    --cinza-texto: #6c757d;
    --cinza-escuro: #343a40;
    --vermelho: #dc3545;
    --amarelo: #ffc107;
    --azul: #0d6efd;
    --sombra: 0 2px 10px rgba(0, 0, 0, 0.05);
    --sombra-forte: 0 4px 20px rgba(0, 0, 0, 0.1);
    --transicao: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--cinza-claro);
    color: var(--cinza-escuro);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

/* =====================================================
   LOGIN PAGE
   ===================================================== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--cor-primaria) 0%, var(--cor-secundaria) 100%);
    padding: 20px;
}

.login-box {
    background: var(--branco);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    color: var(--cor-primaria);
    text-align: center;
    margin-bottom: 10px;
    font-size: 1.8rem;
}

.login-box .subtitle {
    color: var(--cinza-texto);
    text-align: center;
    margin-bottom: 30px;
    font-size: 0.9rem;
}

/* =====================================================
   LAYOUT PRINCIPAL
   ===================================================== */
.wrapper {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* =====================================================
   SIDEBAR - VERSÃO CORRIGIDA
   ===================================================== */
.sidebar {
    width: 260px;
    background: var(--cor-primaria);
    color: var(--branco);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    will-change: transform;
}

.sidebar-header {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.sidebar-logo {
    max-height: 45px;
    max-width: 180px;
    margin-bottom: 10px;
}

.sidebar-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.sidebar-header span {
    font-size: 0.8rem;
    opacity: 0.8;
}

/* MENU COM SCROLL */
.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px 0;
    -webkit-overflow-scrolling: touch;
}

.sidebar-menu::-webkit-scrollbar {
    width: 6px;
}

.sidebar-menu::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.sidebar-menu ul {
    list-style: none;
    padding-bottom: 20px;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    transition: var(--transicao);
    border-left: 3px solid transparent;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--branco);
    border-left-color: var(--branco);
}

.sidebar-menu a i {
    margin-right: 12px;
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.menu-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 12px 20px;
}

/* =====================================================
   SIDEBAR OVERLAY - VERSÃO CORRIGIDA
   ===================================================== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* =====================================================
   MAIN CONTENT
   ===================================================== */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 20px;
    min-height: 100vh;
    transition: var(--transicao);
    position: relative;
    z-index: 1; /* Baixo para não interferir com menu */
}

/* =====================================================
   MENU TOGGLE BUTTON - VERSÃO CORRIGIDA
   ===================================================== */
.menu-toggle {
    display: none;
    position: fixed !important;
    top: 12px !important;
    left: 12px !important;
    z-index: 99999 !important; /* MÁXIMO - acima de TUDO */
    background: var(--cor-primaria);
    color: var(--branco);
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.4rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    align-items: center;
    justify-content: center;
    transition: var(--transicao);
    /* Importante para touch */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    /* Garante que seja clicável */
    pointer-events: auto !important;
    /* Isolamento de contexto */
    isolation: isolate;
}

.menu-toggle:hover {
    background: var(--cor-primaria-hover);
    transform: scale(1.05);
}

.menu-toggle:active {
    transform: scale(0.95);
    background: var(--cor-primaria-hover);
}

.menu-toggle i {
    pointer-events: none;
}

/* =====================================================
   TOP HEADER
   ===================================================== */
.top-header {
    background: var(--branco);
    padding: 15px 25px;
    border-radius: 10px;
    margin-bottom: 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--sombra);
    flex-wrap: wrap;
    gap: 15px;
}

.page-title {
    color: var(--cor-primaria);
    font-size: 1.5rem;
    font-weight: 600;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.user-info span {
    color: var(--cinza-texto);
}

/* =====================================================
   CARDS
   ===================================================== */
.card {
    background: var(--branco);
    border-radius: 10px;
    box-shadow: var(--sombra);
    margin-bottom: 25px;
}

.card-header {
    padding: 20px;
    border-bottom: 1px solid var(--cinza-medio);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.card-header h2 {
    color: var(--cor-primaria);
    font-size: 1.2rem;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* =====================================================
   DASHBOARD CARDS
   ===================================================== */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.dash-card {
    background: var(--branco);
    border-radius: 10px;
    padding: 25px;
    box-shadow: var(--sombra);
    display: flex;
    align-items: center;
    gap: 20px;
}

.dash-card .icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.dash-card .icon.green {
    background: rgba(26, 77, 46, 0.1);
    color: var(--cor-primaria);
}

.dash-card .icon.orange {
    background: rgba(255, 193, 7, 0.15);
    color: #e6a800;
}

.dash-card .icon.red {
    background: rgba(220, 53, 69, 0.1);
    color: var(--vermelho);
}

.dash-card .icon.blue {
    background: rgba(13, 110, 253, 0.1);
    color: var(--azul);
}

.dash-card .info h3 {
    font-size: 1.8rem;
    color: var(--cinza-escuro);
    margin-bottom: 5px;
}

.dash-card .info p {
    color: var(--cinza-texto);
    font-size: 0.9rem;
}

/* FIX: Garantir que elementos do dashboard não bloqueiem o menu */
.dashboard-cards,
.dash-card,
.card,
.card-header,
.card-body,
.top-header,
.alert-box {
    position: relative;
    z-index: 1;
}

/* =====================================================
   ALERT BOXES
   ===================================================== */
.alert-box {
    border-radius: 10px;
    padding: 15px 20px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.alert-box.warning {
    background: rgba(255, 193, 7, 0.15);
    border-left: 4px solid var(--amarelo);
}

.alert-box.danger {
    background: rgba(220, 53, 69, 0.1);
    border-left: 4px solid var(--vermelho);
}

.alert-box i {
    font-size: 1.3rem;
}

.alert-box.warning i { color: #e6a800; }
.alert-box.danger i { color: var(--vermelho); }

/* =====================================================
   FORMS
   ===================================================== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--cinza-escuro);
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--cinza-medio);
    border-radius: 8px;
    font-size: 16px; /* Previne zoom no iOS */
    transition: var(--transicao);
    -webkit-appearance: none;
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--cor-secundaria);
    box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

select.form-control {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px 12px;
    padding-right: 40px;
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

/* =====================================================
   BUTTONS
   ===================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transicao);
    text-decoration: none;
    min-height: 48px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--cor-primaria);
    color: var(--branco);
}

.btn-primary:hover {
    background: var(--cor-primaria-hover);
}

.btn-secondary {
    background: var(--cinza-medio);
    color: var(--cinza-escuro);
}

.btn-secondary:hover {
    background: #dde0e3;
}

.btn-danger {
    background: var(--vermelho);
    color: var(--branco);
}

.btn-danger:hover {
    background: #bb2d3b;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.85rem;
    min-height: 40px;
}

.btn-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* =====================================================
   TABLES
   ===================================================== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th,
table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--cinza-medio);
}

table th {
    background: var(--cinza-claro);
    color: var(--cor-primaria);
    font-weight: 600;
    white-space: nowrap;
}

table tbody tr:hover {
    background: rgba(26, 77, 46, 0.03);
}

table td .actions {
    display: flex;
    gap: 8px;
}

/* =====================================================
   BADGES
   ===================================================== */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-success {
    background: rgba(26, 77, 46, 0.1);
    color: var(--cor-primaria);
}

.badge-warning {
    background: rgba(255, 193, 7, 0.2);
    color: #856404;
}

.badge-danger {
    background: rgba(220, 53, 69, 0.1);
    color: var(--vermelho);
}

.badge-secondary {
    background: var(--cinza-medio);
    color: var(--cinza-texto);
}

.badge-primary {
    background: rgba(13, 110, 253, 0.1);
    color: var(--azul);
}

.badge-info {
    background: rgba(13, 202, 240, 0.15);
    color: #0aa2c0;
}

/* =====================================================
   ALERTS
   ===================================================== */
.alert {
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.alert-success {
    background: rgba(26, 77, 46, 0.1);
    color: var(--cor-primaria);
    border: 1px solid rgba(26, 77, 46, 0.2);
}

.alert-danger {
    background: rgba(220, 53, 69, 0.1);
    color: var(--vermelho);
    border: 1px solid rgba(220, 53, 69, 0.2);
}

.alert-warning {
    background: rgba(255, 193, 7, 0.15);
    color: #856404;
    border: 1px solid rgba(255, 193, 7, 0.3);
}

/* =====================================================
   MODAL
   ===================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--branco);
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--cinza-medio);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: var(--cor-primaria);
    font-size: 1.2rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--cinza-texto);
    padding: 5px;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--cinza-medio);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* =====================================================
   FILE UPLOAD
   ===================================================== */
.file-upload {
    border: 2px dashed var(--cinza-medio);
    border-radius: 8px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: var(--transicao);
}

.file-upload:hover {
    border-color: var(--cor-secundaria);
}

.file-upload input {
    display: none;
}

.file-upload i {
    font-size: 2rem;
    color: var(--cinza-texto);
    margin-bottom: 10px;
}

.file-upload p {
    color: var(--cinza-texto);
}

.file-list {
    margin-top: 15px;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    background: var(--cinza-claro);
    border-radius: 6px;
    margin-bottom: 8px;
}

/* =====================================================
   SEARCH & FILTERS
   ===================================================== */
.filters-bar {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-box {
    flex: 1;
    min-width: 250px;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 10px 15px 10px 40px;
    border: 1px solid var(--cinza-medio);
    border-radius: 8px;
    font-size: 16px;
}

.search-box i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--cinza-texto);
}

.filter-select {
    min-width: 150px;
}

/* =====================================================
   PAGINATION
   ===================================================== */
.pagination {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.pagination a,
.pagination span {
    padding: 8px 14px;
    border: 1px solid var(--cinza-medio);
    border-radius: 6px;
    text-decoration: none;
    color: var(--cinza-escuro);
}

.pagination a:hover {
    background: var(--cinza-claro);
}

.pagination .active {
    background: var(--cor-primaria);
    color: var(--branco);
    border-color: var(--cor-primaria);
}

/* =====================================================
   EMPTY STATE
   ===================================================== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-state i {
    font-size: 4rem;
    color: var(--cinza-medio);
    margin-bottom: 20px;
}

.empty-state h3 {
    color: var(--cinza-texto);
    margin-bottom: 10px;
}

.empty-state p {
    color: var(--cinza-texto);
    margin-bottom: 20px;
}

/* =====================================================
   DETAILS VIEW
   ===================================================== */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.detail-item {
    padding: 15px;
    background: var(--cinza-claro);
    border-radius: 8px;
}

.detail-item label {
    display: block;
    font-size: 0.85rem;
    color: var(--cinza-texto);
    margin-bottom: 5px;
}

.detail-item span {
    font-size: 1rem;
    color: var(--cinza-escuro);
    font-weight: 500;
}

/* =====================================================
   BOTTOM NAVIGATION (Mobile) - VERSÃO CORRIGIDA
   ===================================================== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--branco);
    box-shadow: 0 -2px 15px rgba(0, 0, 0, 0.1);
    z-index: 998; /* Abaixo do menu toggle */
    padding: 8px 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

.bottom-nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
    max-width: 500px;
    margin: 0 auto;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 12px;
    color: var(--cinza-texto);
    text-decoration: none;
    font-size: 0.7rem;
    transition: var(--transicao);
    min-width: 60px;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item i {
    font-size: 1.2rem;
    margin-bottom: 4px;
}

.bottom-nav-item.active,
.bottom-nav-item:hover {
    color: var(--cor-primaria);
}

.bottom-nav-item span {
    font-weight: 500;
}

/* =====================================================
   UTILITIES
   ===================================================== */
.text-muted { color: var(--cinza-texto); }
.text-success { color: var(--cor-primaria); }
.text-danger { color: var(--vermelho); }
.mb-2 { margin-bottom: 16px; }
.mt-2 { margin-top: 16px; }

/* =====================================================
   RESPONSIVE - TABLET (até 992px)
   ===================================================== */
@media (max-width: 992px) {
    .sidebar {
        width: 240px;
    }
    
    .main-content {
        margin-left: 240px;
    }
}

/* =====================================================
   RESPONSIVE - MOBILE (até 768px)
   ===================================================== */
@media (max-width: 768px) {
    /* Sidebar escondido por padrão */
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }
    
    /* Sidebar visível quando ativo */
    .sidebar.active {
        transform: translateX(0);
    }
    
    /* Main content ocupa tudo */
    .main-content {
        margin-left: 0;
        padding: 15px;
        padding-top: 75px; /* Espaço para o botão */
        padding-bottom: 90px; /* Espaço para bottom nav */
    }
    
    /* Mostrar botão toggle */
    .menu-toggle {
        display: flex !important;
    }
    
    /* Mostrar bottom nav */
    .bottom-nav {
        display: block;
    }
    
    /* Header ajustes */
    .top-header {
        flex-direction: column;
        text-align: center;
        padding: 15px;
        margin-left: 0;
    }
    
    .page-title {
        font-size: 1.2rem;
    }
    
    /* Cards */
    .dashboard-cards {
        grid-template-columns: 1fr;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .card-header {
        flex-direction: column;
        text-align: center;
    }
    
    /* Filtros empilhados */
    .filters-bar {
        flex-direction: column;
    }
    
    .search-box {
        min-width: 100%;
    }
    
    /* Botões ocupam largura total */
    .btn-group {
        flex-direction: column;
    }
    
    .btn-group .btn {
        width: 100%;
    }
    
    /* Modal fullscreen */
    .modal {
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        height: 100%;
    }
    
    .modal-overlay {
        padding: 0;
    }
    
    /* Detail grid */
    .detail-grid {
        grid-template-columns: 1fr;
    }
    
    /* Tabelas - scroll horizontal */
    .table-responsive {
        margin: 0 -15px;
        padding: 0 15px;
    }
}

/* =====================================================
   MOBILE PEQUENO (até 480px)
   ===================================================== */
@media (max-width: 480px) {
    .main-content {
        padding: 10px;
        padding-top: 70px;
        padding-bottom: 85px;
    }
    
    .page-title {
        font-size: 1.1rem;
    }
    
    .card-body {
        padding: 15px;
    }
    
    .dash-card {
        padding: 20px;
    }
    
    .dash-card .icon {
        width: 50px;
        height: 50px;
        font-size: 1.3rem;
    }
    
    .dash-card .info h3 {
        font-size: 1.5rem;
    }
    
    .login-box {
        padding: 30px 20px;
    }
    
    .menu-toggle {
        width: 46px;
        height: 46px;
        font-size: 1.2rem;
        top: 10px;
        left: 10px;
    }
    
    /* Bottom nav mais compacto */
    .bottom-nav-item {
        padding: 6px 8px;
        min-width: 50px;
        font-size: 0.65rem;
    }
    
    .bottom-nav-item i {
        font-size: 1.1rem;
    }
}

/* =====================================================
   PRINT
   ===================================================== */
@media print {
    .sidebar,
    .menu-toggle,
    .bottom-nav,
    .sidebar-overlay,
    .btn,
    .actions {
        display: none !important;
    }
    
    .main-content {
        margin: 0;
        padding: 0;
    }
    
    .top-header {
        box-shadow: none;
        border-bottom: 1px solid #ccc;
    }
}
