:root {
    /* Colors - Munhoz Tecnologia Theme */
    --bg-main: #0A0E17;
    --bg-sidebar: #0D1320;
    --bg-card: #111827;
    --bg-input: #1B2333;
    --border: #1E2D45;
    --text-primary: #FFFFFF;
    --text-secondary: #8899B4;
    --accent: #1A66FF;
    --accent-hover: #1550CC;
    --accent-soft: rgba(26, 102, 255, 0.12);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    /* Layout */
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    /* Transitions */
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

ul {
    list-style: none;
}

/* App Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: var(--transition);
}

.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    letter-spacing: -0.5px;
}

.logo-icon {
    color: var(--accent);
}

/* Scrollbar global */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.sidebar-nav {
    flex: 1;
    padding: 20px 12px;
    overflow-y: auto;
}

.nav-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 24px 12px 12px;
}

.nav-item {
    display: block;
    /* Mudar para block para o <a> ocupar tudo */
    padding: 0;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    margin-bottom: 4px;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
    width: 100%;
    height: 100%;
}

.nav-item:hover a {
    background-color: var(--bg-input);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
}

.nav-item.active a {
    background-color: var(--accent-soft);
    color: var(--accent);
    border-radius: var(--radius-sm);
}

.nav-item i {
    width: 18px;
    height: 18px;
}

.nav-item span {
    font-size: 0.9rem;
    font-weight: 500;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent), #0D3B99);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
}

.user-info {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-actions {
    display: flex;
    gap: 0.25rem;
}

.settings-btn, .logout-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.settings-btn:hover, .logout-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.logout-btn {
    color: #ef4444;
}

.logout-btn:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-bar {
    height: var(--topbar-height);
    background-color: var(--bg-main);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
}

.search-bar {
    position: relative;
    max-width: 400px;
    width: 100%;
}

.search-bar i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    width: 18px;
    height: 18px;
}

.search-bar input {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px 8px 40px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

.search-bar input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    position: relative;
}

.icon-btn:hover {
    background-color: var(--bg-input);
    color: var(--text-primary);
}

/* Efeito hover específico para botão de exclusão - fica vermelho */
.icon-btn[title="Excluir"]:hover {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.icon-btn .badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    background-color: var(--danger);
    border-radius: 50%;
    border: 2px solid var(--bg-main);
}

.content-area {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
    height: calc(100vh - var(--topbar-height));
}

/* Notification Container */
.notification-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 360px;
}

.notification {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    animation: fadeIn 0.3s ease-out forwards;
}

.notification-content {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.notification-content p {
    font-size: 0.875rem;
}

.notification-close {
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-secondary);
    line-height: 1;
    flex-shrink: 0;
}

.notification-close:hover {
    color: var(--text-primary);
}

.notification-info {
    border-left: 4px solid var(--accent);
}

.notification-success {
    border-left: 4px solid var(--success);
}

.notification-error {
    border-left: 4px solid var(--danger);
}

.notification-warning {
    border-left: 4px solid var(--warning);
}

/* Dashboard Elements */
.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
}

.loader {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-input);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Card and Components */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
    transition: var(--transition);
}

.card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.card-value {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.card-trend {
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

.trend-up {
    color: var(--success);
}

.trend-down {
    color: var(--danger);
}

/* Tables */
.table-container {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    background-color: rgba(255, 255, 255, 0.02);
    padding: 16px 24px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

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

tr:hover td {
    background-color: rgba(255, 255, 255, 0.01);
}

.badge-status {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-active {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.badge-churn {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.badge-inactive {
    background-color: rgba(161, 161, 170, 0.1);
    color: var(--text-secondary);
}

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

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.form-input {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

.form-input:focus {
    border-color: var(--accent);
}

.btn {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
}

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

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

.btn-secondary {
    background-color: var(--bg-input);
    color: var(--text-primary);
}

.btn-secondary:hover {
    border-color: var(--text-secondary);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

/* Modal System */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: overlayFadeIn 0.2s ease-out;
}

.modal-container {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 1100px;
    /* Modal maior para melhor visualização de dados */
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

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

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
}

#entity-form {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* Seção do formulário que ocupa uma coluna */
.form-section {
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
}

/* Seção que ocupa largura total (2 colunas) */
.form-section.full-width {
    grid-column: 1 / -1;
}

/* Grid de 3 colunas para campos menores */
.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

/* Custom Scrollbar para o Modal Body */
.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-shrink: 0;
}

/* Specific Form Helpers */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
}

select.form-input option,
select.form-input optgroup {
    background-color: var(--bg-input);
    color: var(--text-primary);
}

/* Estilo global para options de select no tema escuro */
.dark-theme select option,
.dark-theme select optgroup {
    background-color: var(--bg-input);
    color: var(--text-primary);
}

/* Animação de spin para loaders */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===============================================================================
   MODAL DE RELATÓRIO DE GRUPO ECONÔMICO
   =============================================================================== */

/* Modal de relatório - tamanho maior para acomodar cards */
.report-modal {
    max-width: 1000px;
    width: 90vw;
    max-height: 90vh;
}

/* Título do relatório no header */
.report-title {
    display: flex;
    align-items: center;
    gap: 16px;
}

.report-title h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-primary);
}

.report-title h2 i {
    color: var(--accent);
    width: 24px;
    height: 24px;
}

/* Body do modal com scroll */
.report-modal-body {
    max-height: calc(90vh - 140px);
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-main);
}

/* Grid de cards de empresas */
.companies-report-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(450px, 1fr));
    gap: 20px;
}

/* Card individual de empresa */
.company-report-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: var(--transition);
}

.company-report-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Header do card */
.company-report-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--accent-soft) 100%);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.company-title h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.company-fantasia {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.cnpj-badge {
    background: var(--accent-soft);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    font-family: monospace;
    white-space: nowrap;
}

/* Body do card */
.company-report-body {
    padding: 16px 20px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

/* Seções do relatório */
.report-section {
    padding: 12px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.report-section h5 {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.report-section h5 i {
    width: 14px;
    height: 14px;
}

.report-section p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    line-height: 1.4;
}

/* Seção de preferências ocupa toda a largura */
.report-section.preferences {
    grid-column: 1 / -1;
}

/* Seção de dados do vínculo */
.report-section.vinculo {
    grid-column: 1 / -1;
    background: var(--accent-soft);
    border: 1px solid rgba(26, 102, 255, 0.2);

    color: var(--accent);
}

.report-section.vinculo p strong {
    color: var(--text-primary);
    font-weight: 500;
}

/* Seção de contatos vinculados */
.report-section.contatos {
    grid-column: 1 / -1;
    background: rgba(16, 185, 129, 0.05);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.report-section.contatos h5 {
    color: var(--success);
}

.contatos-lista {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.contato-item {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--success);
}

.contato-nome {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.contato-detalhes {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.contato-cargo {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 4px;
}

.contato-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

.contato-badge.principal {
    background: rgba(26, 102, 255, 0.2);
    color: var(--accent);
}

.contato-badge.cobranca {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.contato-contato {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 6px;
    display: flex;
    gap: 12px;
}

/* Seção de empresas vinculadas */
.report-section.empresas-vinculadas {
    grid-column: 1 / -1;
    background: rgba(139, 92, 246, 0.05);
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.report-section.empresas-vinculadas h5 {
    color: #a78bfa;
}

.empresas-lista {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.empresa-vinculada-item {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
    border-left: 3px solid #a78bfa;
}

.empresa-vinc-nome {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.empresa-vinc-detalhes {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
    align-items: center;
}

.empresa-vinc-cnpj {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: monospace;
}

.empresa-vinc-tipo {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
    text-transform: uppercase;
}

.empresa-vinc-tipo.filial {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.empresa-vinc-tipo.matriz {
    background: rgba(26, 102, 255, 0.2);
    color: var(--accent);
}

.empresa-vinc-tipo.holding {
    background: rgba(139, 92, 246, 0.2);
    color: #a78bfa;
}

.empresa-vinc-tipo.conglomerado {
    background: rgba(236, 72, 153, 0.2);
    color: #ec4899;
}

.empresa-vinc-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.report-section.preferences p {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

/* Badges de preferência */
.pref-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
}

.pref-badge.active {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.pref-badge.inactive {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.pref-badge i {
    width: 14px;
    height: 14px;
}

/* Responsividade para telas menores */
@media (max-width: 768px) {
    .companies-report-grid {
        grid-template-columns: 1fr;
    }
    
    .company-report-body {
        grid-template-columns: 1fr;
    }
    
    .report-modal {
        width: 95vw;
        max-height: 95vh;
    }
    
    .report-modal-body {
        max-height: calc(95vh - 140px);
        padding: 16px;
    }
    
    .company-report-header {
        flex-direction: column;
        gap: 8px;
    }
}

/* Animação de pulse para indicadores de carregamento */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Badge styles */
.badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: white !important;
}

.badge-warning {
    background: #f59e0b;
    border: 1px solid #f59e0b;
}

.badge-success {
    background: #10b981;
    border: 1px solid #10b981;
}

.badge-error {
    background: #ef4444;
    border: 1px solid #ef4444;
}

/* Responsividade para página de sincronização */
@media (max-width: 768px) {
    .card-content > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    
    .page-header h1 {
        font-size: 1.4rem;
    }
    
    .page-header h1 i {
        width: 24px;
        height: 24px;
    }
}