/* ==========================================================================
   SISTEMA DE GESTÃO DE CONTRATOS - SISTEMA VISUAL (PURE CSS)
   ========================================================================== */

/* Importação da Fonte Inter do Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Variáveis do Tema (Sistema de Design) */
:root {
    --primary-color: #1e3a8a;       /* Azul Escuro Construtora */
    --primary-hover: #1e40af;
    --secondary-color: #0f172a;     /* Slate escuro */
    --bg-color: #f8fafc;            /* Fundo suave cinza/azul */
    --surface-color: #ffffff;       /* Fundo de cards/tabelas */
    --border-color: #e2e8f0;        /* Bordas finas */
    --text-main: #0f172a;           /* Texto primário */
    --text-muted: #64748b;          /* Texto secundário/mutado */
    
    /* Cores de Feedback */
    --success-color: #10b981;       /* Verde Sucesso */
    --danger-color: #ef4444;        /* Vermelho Erro */
    --warning-color: #f59e0b;       /* Amarelo Alerta */
    --info-color: #3b82f6;          /* Azul Info */
    
    /* Efeitos de Sombra e Transição */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

/* Reset Geral */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
    transition: var(--transition);
}

button, input, select, textarea {
    font-family: inherit;
    font-size: 16px; /* Impede zoom automático ao focar inputs no iOS Safari/Chrome */
    outline: none;
}

/* ==========================================================================
   TELA DE LOGIN
   ========================================================================== */
.login-container {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #1e3a8a 100%);
}

.login-card {
    background: var(--surface-color);
    padding: 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 440px;
    transition: var(--transition);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 14px;
}

/* ==========================================================================
   ALERTAS / FEEDBACKS
   ========================================================================== */
.alert {
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 4px solid transparent;
}

.alert-success {
    background-color: #ecfdf5;
    color: #065f46;
    border-left-color: var(--success-color);
}

.alert-error {
    background-color: #fef2f2;
    color: #991b1b;
    border-left-color: var(--danger-color);
}

/* Alertas flutuantes no painel principal para evitar quebra/movimento de layout */
.alert-flash {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    min-width: 300px;
    max-width: 450px;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-md);
    margin-bottom: 0;
    animation: slideInAlert 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideInAlert {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .alert-flash {
        left: 20px;
        right: 20px;
        min-width: auto;
    }
}

/* ==========================================================================
   FORMULÁRIOS
   ========================================================================== */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: #f8fafc;
    color: var(--text-main);
    transition: var(--transition);
}

.form-control:focus {
    border-color: var(--primary-color);
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    gap: 8px;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #ffffff;
}

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

.btn-danger {
    background-color: var(--danger-color);
    color: #ffffff;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-block {
    width: 100%;
}

/* ==========================================================================
   LAYOUT DO PAINEL (GRID & FLEX)
   ========================================================================== */
.app-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
}

/* Menu Lateral (Sidebar) */
.sidebar {
    background-color: var(--secondary-color);
    color: #f8fafc;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 40px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px;
}

.sidebar-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.sidebar-item > a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    color: #cbd5e1;
    font-weight: 500;
    font-size: 14px;
}

.sidebar-item > a:hover,
.sidebar-item.active > a {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.08);
}

.sidebar-item.active > a {
    background-color: var(--primary-color);
    color: #ffffff;
}

/* Estilo para Dropdown de Cadastros */
.sidebar-dropdown {
    display: flex;
    flex-direction: column;
}

.sidebar-dropdown-toggle {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    width: 100%;
}

.sidebar-dropdown-toggle .dropdown-arrow {
    margin-left: auto;
    transition: transform 0.25s ease;
}

.sidebar-dropdown.open .dropdown-arrow {
    transform: rotate(90deg);
}

.sidebar-dropdown.open > a {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.05);
}

.sidebar-submenu {
    list-style: none;
    padding: 0;
    margin: 4px 0 0 0;
    display: none;
    flex-direction: column;
    gap: 4px;
    background-color: rgba(0, 0, 0, 0.12);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.sidebar-dropdown.open .sidebar-submenu {
    display: flex;
}

.sidebar-submenu-item a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px 10px 32px;
    font-size: 13px;
    color: #cbd5e1;
    transition: var(--transition);
}

.sidebar-submenu-item a:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.04);
}

.sidebar-submenu-item.active a {
    background-color: var(--primary-color);
    color: #ffffff;
    font-weight: 600;
}

.sidebar-user {
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-user-name {
    font-size: 14px;
    font-weight: 600;
    color: #ffffff;
}

.sidebar-user-role {
    font-size: 12px;
    color: #94a3b8;
    text-transform: uppercase;
}

/* Área Principal (Main Content) */
.main-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-header {
    background-color: var(--surface-color);
    height: 70px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 32px;
    box-shadow: var(--shadow-sm);
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-main);
}

.header-breadcrumb {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 15px;
    flex: 1;
    min-width: 0;
}

.breadcrumb-prefix {
    color: var(--text-muted);
    font-size: 14px;
}

.breadcrumb-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-main);
}

.header-date {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
}

.main-content {
    flex-grow: 1;
    padding: 32px;
}

.page-title-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
}

/* ==========================================================================
   CARDS DE RESUMO (DASHBOARD)
   ========================================================================== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.kpi-grid-5 {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.kpi-grid-6 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

@media (max-width: 1400px) {
    .kpi-grid-5,
    .kpi-grid-6 {
        grid-template-columns: repeat(3, 1fr);
    }
}

.kpi-card {
    background-color: var(--surface-color);
    padding: 18px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 10px;
    min-height: 92px;
    transition: var(--transition);
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1.35;
}

.kpi-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.1;
}

.kpi-card.kpi-primary { border-top: 4px solid var(--primary-color); }
.kpi-card.kpi-success { border-top: 4px solid var(--success-color); }
.kpi-card.kpi-danger { border-top: 4px solid var(--danger-color); }
.kpi-card.kpi-warning { border-top: 4px solid var(--warning-color); }
.kpi-card.kpi-purple { border-top: 4px solid #7c3aed; }
.kpi-card.kpi-teal { border-top: 4px solid #0d9488; }

/* ==========================================================================
   GRID DE SEÇÕES DO DASHBOARD
   ========================================================================== */
.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 30px;
}

.panel-card {
    background-color: var(--surface-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: 24px;
}

.panel-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ==========================================================================
   TABELAS RESPONSIVAS
   ========================================================================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.table th {
    background-color: #f8fafc;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    text-align: left;
    padding: 14px 16px;
    border-bottom: 2px solid var(--border-color);
}

.table td {
    padding: 14px 16px;
    font-size: 14px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
}

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

.table tr:hover td {
    background-color: #f8fafc;
}

/* Badges de Status */
.badge {
    display: inline-flex;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 50px;
    text-transform: uppercase;
}

.badge-success {
    background-color: #ecfdf5;
    color: #047857;
}

.badge-danger {
    background-color: #fef2f2;
    color: #b91c1c;
}

.badge-warning {
    background-color: #fffbeb;
    color: #b45309;
}

.badge-info {
    background-color: #eff6ff;
    color: #1d4ed8;
}

/* ==========================================================================
   RODAPÉ (FOOTER)
   ========================================================================== */
.main-footer {
    background-color: var(--surface-color);
    padding: 20px 32px;
    border-top: 1px solid var(--border-color);
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    margin-top: auto;
}

/* ==========================================================================
   MODAIS E CADASTROS
   ========================================================================== */
.users-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 30px;
}

.badge-profile {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}
.badge-admin { background-color: #dbeafe; color: #1e40af; }
.badge-gestor { background-color: #f1f5f9; color: #475569; }
.badge-corretor { background-color: #fef3c7; color: #92400e; }

/* ==========================================================================
   RESPONSIVIDADE (MEDIA QUERIES)
   ========================================================================== */

/* Telas médias (ex: Laptops pequenos, iPads paisagem) */
@media (max-width: 992px) {
    .app-layout {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        display: none; /* Escondido por padrão no mobile */
        position: fixed;
        left: 0;
        top: 0;
        width: 260px;
        z-index: 1000;
    }
    
    .sidebar.show {
        display: flex;
    }
    
    .menu-toggle {
        display: block;
    }
    
    .kpi-grid,
    .kpi-grid-5,
    .kpi-grid-6 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .users-layout {
        grid-template-columns: 1fr;
    }
}

/* Telas pequenas (ex: Mobile - largura mínima 360px) */
@media (max-width: 576px) {
    .kpi-grid,
    .kpi-grid-5,
    .kpi-grid-6 {
        grid-template-columns: 1fr;
    }
    
    .main-header {
        padding: 0 16px;
    }
    
    .breadcrumb-prefix {
        display: none;
    }
    
    .header-date {
        display: none;
    }
    
    .main-content {
        padding: 16px;
    }
    
    .page-title-section {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .login-card {
        padding: 24px;
    }
}

/* ==========================================================================
   MODAIS (OVERLAY & WINDOWS)
   ========================================================================== */
.modal {
    display: none; 
    position: fixed; 
    z-index: 9999; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    transition: var(--transition);
}

.modal-content {
    background-color: var(--surface-color);
    margin: 10% auto; 
    padding: 30px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 450px;
    border: 1px solid var(--border-color);
    animation: modalFadeIn 0.3s ease;
}

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

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

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
}

.modal-close {
    font-size: 24px;
    font-weight: bold;
    color: var(--text-muted);
    cursor: pointer;
    background: none;
    border: none;
    line-height: 1;
}

.modal-close:hover {
    color: var(--danger-color);
}

.btn-inline-add {
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    background-color: #f1f5f9;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-inline-add:hover {
    background-color: #e2e8f0;
    border-color: var(--text-muted);
}

/* =============================================
   EDITOR DE TEXTO RICO (Rich Text Editor)
   ============================================= */
.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 8px 10px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background-color: #cbd5e1;
    margin: 0 4px;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: #475569;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.15s ease;
}

.toolbar-btn:hover {
    background-color: #e2e8f0;
    border-color: #cbd5e1;
    color: #1e293b;
}

.toolbar-btn:active,
.toolbar-btn.active {
    background-color: #c7d2fe;
    border-color: #818cf8;
    color: #3730a3;
}

.toolbar-select {
    height: 32px;
    padding: 0 8px;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    background: #ffffff;
    color: #475569;
    font-size: 12px;
    cursor: pointer;
    outline: none;
    transition: all 0.15s ease;
}

.toolbar-select:hover {
    border-color: #94a3b8;
}

.toolbar-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.toolbar-color-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    position: relative;
    transition: all 0.15s ease;
}

.toolbar-color-wrapper:hover {
    background-color: #e2e8f0;
    border-color: #cbd5e1;
}

.toolbar-color-input {
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 6px;
    border: none;
    padding: 0;
    cursor: pointer;
    border-radius: 2px;
}

.toolbar-color-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.toolbar-color-input::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

#editor-area {
    min-height: 420px;
    max-height: 600px;
    overflow-y: auto;
    padding: 24px 30px;
    border: 1px solid var(--border-color);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    background-color: #ffffff;
    font-family: 'Arial', sans-serif;
    font-size: 14px;
    line-height: 1.7;
    color: #334155;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#editor-area:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#editor-area:empty::before {
    content: 'Escreva o contrato utilizando os placeholders do menu lateral...';
    color: #94a3b8;
    pointer-events: none;
}

#editor-area h1, #editor-area h2, #editor-area h3, #editor-area h4 {
    color: #1e293b;
    margin-bottom: 8px;
}

#editor-area blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 16px;
    margin: 10px 0;
    color: #64748b;
    font-style: italic;
}

#editor-area hr {
    border: none;
    border-top: 2px solid #e2e8f0;
    margin: 16px 0;
}

/* Placeholder Tags Clicáveis */
.placeholder-tag {
    display: block;
    background: #f1f5f9;
    padding: 6px 8px;
    border-radius: 4px;
    margin: 2px 0;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    user-select: none;
}

.placeholder-tag:hover {
    background: #e0e7ff;
    border-color: #c7d2fe;
    transform: translateX(3px);
}

.placeholder-tag:active {
    background: #c7d2fe;
    transform: translateX(3px) scale(0.98);
}

/* Estilo para as tags de variáveis dentro da área de edição do editor */
.template-placeholder-tag {
    background-color: #fef08a; /* amarelo bem claro */
    color: #854d0e; /* marrom/dourado escuro */
    border: 1px dashed #eab308;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    font-family: monospace;
    margin: 0 2px;
    display: inline-block;
    user-select: all;
}
