:root {
    --navy: #17243a;
    --navy-light: #243552;
    --blue: #315efb;
    --blue-dark: #244bd2;
    --background: #f5f7fb;
    --surface: #ffffff;
    --text: #202b3c;
    --muted: #778196;
    --border: #e3e8f0;
    --green: #17845b;
    --green-bg: #e4f7ee;
    --red: #c43d4b;
    --red-bg: #fff2f3;
    --orange: #b86a13;
    --orange-bg: #fff1d9;
    --purple: #6941c6;
    --purple-bg: #f4ebff;
    --radius: 14px;
    --shadow: 0 4px 18px rgba(20, 35, 60, 0.04);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
}

[hidden] { display: none !important; }

.app-layout { min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 250px;
    background: var(--navy);
    color: #fff;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; text-decoration: none; color: #fff; }
.brand-icon {
    width: 42px; height: 42px; background: var(--blue); border-radius: 12px;
    display: grid; place-items: center; font-weight: 800; font-size: 20px;
}
.navigation { display: grid; gap: 6px; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-radius: 8px; color: #c2ccdc; text-decoration: none;
    font-weight: 500; cursor: pointer; transition: all 0.2s;
}
.nav-link:hover, .nav-link.active { background: #2b3a53; color: #fff; }
.nav-link .badge-count {
    margin-left: auto; background: var(--blue); color: #fff; font-size: 11px;
    padding: 2px 7px; border-radius: 10px; font-weight: 700;
}
.sidebar-footer { margin-top: auto; font-size: 12px; color: #b8c3d5; display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; background: #46d59a; border-radius: 50%; }

.main-content { margin-left: 250px; padding: 32px; min-height: 100vh; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; }
.topbar-actions { display: flex; gap: 12px; align-items: center; }
.user-email-badge { color: var(--muted); font-size: 13px; }
h1 { margin: 0; font-size: 28px; font-weight: 700; }

.btn-primary, .btn-secondary, .btn-whatsapp, .btn-danger {
    padding: 9px 16px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600;
    display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-size: 13px;
    transition: opacity 0.2s;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { opacity: 0.92; }
.btn-secondary { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { background: #f8fafd; }
.btn-whatsapp { background: #25d366; color: #fff; font-weight: 700; }
.btn-whatsapp:hover { background: #20bd5a; color: #fff; }
.btn-danger { background: var(--red); color: #fff; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card {
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow);
}
.stat-value { font-size: 32px; font-weight: 800; display: block; margin-top: 6px; color: var(--text); }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; }

.content-card {
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 24px; margin-bottom: 24px; box-shadow: var(--shadow);
}
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.section-heading h2 { margin: 0; font-size: 20px; }

.filters-bar { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 240px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.filter-select { padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: #fff; }

.table-wrapper { overflow-x: auto; }
.properties-table { width: 100%; border-collapse: collapse; }
.properties-table th, .properties-table td { padding: 14px 12px; text-align: left; border-bottom: 1px solid #edf0f5; }
.properties-table th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.properties-table tr:hover { background: #fbfcfe; }

.property-cell { display: flex; align-items: center; gap: 12px; }
.property-thumb { width: 68px; height: 50px; object-fit: cover; border-radius: 8px; background: #e5e9f0; }

.status-badge { display: inline-block; padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.status-disponivel { background: var(--green-bg); color: var(--green); }
.status-reservado { background: var(--orange-bg); color: var(--orange); }
.status-vendido, .status-alugado { background: #e9efff; color: var(--blue); }

/* Badges de CRM */
.badge-lead-novo { background: #fee4e2; color: #b42318; }
.badge-lead-atendimento { background: #fef0c7; color: #b54708; }
.badge-lead-visita { background: #e0f2fe; color: #026aa2; }
.badge-lead-proposta { background: var(--purple-bg); color: var(--purple); }
.badge-lead-fechado { background: var(--green-bg); color: var(--green); }
.badge-lead-perdido { background: #f2f4f7; color: #667085; }

.action-buttons { display: flex; gap: 6px; align-items: center; }
.btn-sm { padding: 6px 10px; border-radius: 6px; font-size: 12px; border: none; cursor: pointer; text-decoration: none; font-weight: 600; }
.btn-edit { background: #f0f4ff; color: var(--blue); }
.btn-delete { background: var(--red-bg); color: var(--red); }
.btn-view { background: #f2f4f7; color: var(--text); }

/* Formulário de Imóveis e Corretores */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.span-2 { grid-column: span 2; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-weight: 600; font-size: 13px; color: var(--text); }
.form-group input, .form-group select, .form-group textarea {
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(49,94,251,0.12);
}
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* Galeria de Fotos no Form */
.galeria-container { display: flex; flex-direction: column; gap: 10px; }
.foto-input-row { display: flex; gap: 10px; align-items: center; }
.foto-input-row input { flex: 1; }
.foto-thumb-preview { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: #eee; flex-shrink: 0; }
.galeria-previews { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.galeria-thumb-card {
    position: relative; width: 100px; height: 75px; border-radius: 8px; overflow: hidden;
    border: 1px solid var(--border);
}
.galeria-thumb-card img { width: 100%; height: 100%; object-fit: cover; }
.galeria-thumb-card .thumb-num {
    position: absolute; bottom: 4px; left: 4px; background: rgba(0,0,0,0.7);
    color: #fff; font-size: 10px; padding: 2px 5px; border-radius: 4px;
}

/* Preview do Vídeo do YouTube */
.video-preview-wrapper {
    margin-top: 12px; aspect-ratio: 16/9; max-width: 480px; border-radius: 10px;
    overflow: hidden; background: #000;
}
.video-preview-wrapper iframe { width: 100%; height: 100%; border: 0; }

/* ==========================================================================
   CRM KANBAN BOARD & POPUP MODAL
   ========================================================================== */
.view-mode-toggle {
    display: inline-flex;
    background: #e2e8f0;
    padding: 3px;
    border-radius: 8px;
    gap: 2px;
}
.btn-toggle-view {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: var(--muted);
    transition: all 0.2s;
}
.btn-toggle-view.active {
    background: #fff;
    color: var(--text);
    box-shadow: 0 2px 4px rgba(0,0,0,0.06);
}

/* QUADRO KANBAN */
.crm-kanban-board {
    display: grid;
    grid-template-columns: repeat(6, minmax(290px, 1fr));
    gap: 16px;
    overflow-x: auto;
    padding: 4px 4px 24px;
    min-height: 540px;
    align-items: start;
}

.kanban-col {
    background: #f1f5f9;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    max-height: 80vh;
}

.kanban-col-header {
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid transparent;
}

.kanban-col-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.kanban-badge-counter {
    background: rgba(0,0,0,0.08);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Cores dos cabeçalhos das colunas */
.col-novo .kanban-col-header { border-bottom-color: #ef4444; }
.col-atendimento .kanban-col-header { border-bottom-color: #f59e0b; }
.col-visita .kanban-col-header { border-bottom-color: #0284c7; }
.col-proposta .kanban-col-header { border-bottom-color: #7c3aed; }
.col-fechado .kanban-col-header { border-bottom-color: #16a34a; }
.col-perdido .kanban-col-header { border-bottom-color: #94a3b8; }

.kanban-cards-container {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    min-height: 220px;
    transition: background 0.2s, border 0.2s;
    border-radius: 0 0 12px 12px;
}

.kanban-cards-container.drag-over {
    background: #e2e8f0;
    outline: 2px dashed var(--blue);
}

/* CARD KANBAN INDIVIDUAL (ARRASTÁVEL) */
.kanban-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px;
    cursor: grab;
    transition: transform 0.18s, box-shadow 0.18s, opacity 0.18s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    position: relative;
    user-select: none;
}

.kanban-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(0,0,0,0.08);
    border-color: #cbd5e1;
}

.kanban-card.is-dragging {
    opacity: 0.4;
    cursor: grabbing;
}

.kanban-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.kanban-lead-name {
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
}

.kanban-lead-time {
    font-size: 11px;
    color: var(--muted);
}

.kanban-lead-imovel {
    font-size: 12px;
    color: var(--blue);
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kanban-lead-msg {
    font-size: 12px;
    color: var(--muted);
    background: #f8fafc;
    padding: 6px 10px;
    border-radius: 6px;
    margin-bottom: 10px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.kanban-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #f1f5f9;
    padding-top: 8px;
}

.kanban-utm-pill {
    background: #f1f5f9;
    color: #475569;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

/* CRM Modo Lista */
.crm-card {
    background: #fff; border: 1px solid var(--border); border-radius: 10px;
    padding: 16px; margin-bottom: 12px; display: grid;
    grid-template-columns: 2fr 2fr 1.5fr 1.5fr auto; gap: 16px; align-items: center;
    transition: box-shadow 0.2s;
    cursor: pointer;
}
.crm-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.crm-cliente-nome { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.crm-contato-info { font-size: 13px; color: var(--muted); }
.crm-imovel-info { font-size: 13px; }
.crm-imovel-titulo { font-weight: 600; color: var(--blue); text-decoration: none; }
.crm-mensagem { font-size: 12px; color: var(--muted); background: #f8fafd; padding: 8px 12px; border-radius: 6px; margin-top: 6px; }

/* MODAL DE DETALHES DO LEAD & ANOTAÇÕES */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}

.modal-content-card {
    background: #ffffff;
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    border: 1px solid var(--border);
    animation: fadeInUp 0.25s ease-out;
}

.modal-header {
    padding: 22px 28px;
    border-bottom: 1px solid #edf0f5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    border-radius: 16px 16px 0 0;
}

.modal-header h2 {
    font-size: 20px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-body {
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.modal-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    background: #f8fafc;
    padding: 16px;
    border-radius: 10px;
    border: 1px solid #edf0f5;
}

.modal-field-label {
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 4px;
}

.modal-field-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.utms-panel {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 16px;
}

.utms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin-top: 8px;
}

.utm-tag {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
}
.utm-tag span {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--muted);
    display: block;
    font-weight: 700;
}

.anotacoes-box textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border 0.2s;
    background: #f8fafc;
}

.anotacoes-box textarea:focus {
    border-color: var(--blue);
    background: #fff;
}

.modal-footer {
    padding: 18px 28px;
    border-top: 1px solid #edf0f5;
    background: #f8fafc;
    border-radius: 0 0 16px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Login */
.login-overlay {
    position: fixed; inset: 0; background: rgba(23,36,58,0.92);
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.login-card {
    background: #fff; padding: 36px; border-radius: 16px; width: 100%; max-width: 420px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.login-card h2 { margin: 0 0 8px; font-size: 24px; text-align: center; }
.login-card p { margin: 0 0 20px; color: var(--muted); text-align: center; }

/* Abas de Perfil no Login */
.login-role-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 10px;
}
.login-role-tab {
    flex: 1;
    border: none;
    background: transparent;
    padding: 9px 12px;
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.login-role-tab.active {
    background: #fff;
    color: #0f172a;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.login-card label { display: flex; flex-direction: column; gap: 6px; text-align: left; margin-bottom: 14px; font-weight: 600; font-size: 13px; color: #1e293b; }
.login-card input {
    padding: 12px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    background: #fff;
    color: #0f172a;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: none;
}
.login-card input:focus {
    border-color: #c5a059;
    box-shadow: 0 0 0 3px rgba(197, 160, 89, 0.15);
    outline: none;
}
.login-card input::placeholder {
    color: #94a3b8;
    font-weight: 400;
}
.login-card button[type="submit"] { width: 100%; margin-top: 10px; padding: 12px; font-size: 14px; }
.erro { color: var(--red); font-size: 13px; margin-top: 10px; text-align: center; }

/* Badges de Nível de Acesso (RBAC) */
.user-role-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 9999px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.role-admin {
    background: rgba(200, 165, 90, 0.2);
    color: #f59e0b;
    border: 1px solid rgba(200, 165, 90, 0.4);
}
.role-corretor {
    background: #eff6ff;
    color: #3b82f6;
    border: 1px solid #bfdbfe;
}

/* Badge de Equipe / Squad de Corretores */
.badge-equipe {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #f8fafc;
    color: #1e293b;
    border: 1px solid #cbd5e1;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

/* Cards da Seção de Configurações do Site (Backend) */
.settings-section-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}
.settings-section-card h3 {
    font-size: 16px;
    margin: 0 0 18px;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f1f5f9;
}

@media (max-width: 900px) {
    .sidebar { position: static; width: 100%; }
    .main-content { margin-left: 0; padding: 20px; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .crm-card { grid-template-columns: 1fr; gap: 10px; }
}

@media (max-width: 600px) {
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
        margin-bottom: 20px;
    }
    .topbar-actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .topbar-actions .btn-secondary {
        flex: 1;
        justify-content: center;
        padding: 8px 12px;
        font-size: 12px;
    }
    .main-content {
        padding: 16px 12px;
    }
    .modal-card {
        padding: 20px 16px;
        max-width: 95vw;
    }
}
