/* ============================================================================
   GESTORCONECTA CONTROL - GLOBAL CSS
   Variaveis, reset, tipografia, utilitarios
   ============================================================================ */

/* -- Variaveis -- */
:root {
    /* Cores principais */
    --cor-primaria: #2563eb;
    --cor-primaria-hover: #1d4ed8;
    --cor-primaria-light: #dbeafe;
    --cor-primaria-dark: #1e40af;

    /* Cores semanticas */
    --cor-sucesso: #16a34a;
    --cor-sucesso-light: #dcfce7;
    --cor-erro: #dc2626;
    --cor-erro-light: #fee2e2;
    --cor-aviso: #d97706;
    --cor-aviso-light: #fef3c7;
    --cor-info: #0284c7;
    --cor-info-light: #e0f2fe;

    /* Neutros */
    --cor-texto: #1f2937;
    --cor-texto-secundario: #6b7280;
    --cor-texto-terciario: #9ca3af;
    --cor-borda: #e5e7eb;
    --cor-borda-hover: #d1d5db;
    --cor-fundo: #f9fafb;
    --cor-fundo-card: #ffffff;
    --cor-fundo-hover: #f3f4f6;

    /* Sidebar */
    --sidebar-largura: 260px;
    --sidebar-cor: #111827;
    --sidebar-texto: #d1d5db;
    --sidebar-hover: #1f2937;
    --sidebar-ativo: var(--cor-primaria);

    /* Header */
    --header-altura: 60px;

    /* Espacamentos */
    --espacamento-xs: 4px;
    --espacamento-sm: 8px;
    --espacamento-md: 16px;
    --espacamento-lg: 24px;
    --espacamento-xl: 32px;
    --espacamento-2xl: 48px;

    /* Bordas */
    --borda-raio-sm: 6px;
    --borda-raio-md: 8px;
    --borda-raio-lg: 12px;
    --borda-raio-full: 9999px;

    /* Sombras */
    --sombra-sm: 0 1px 2px rgba(0,0,0,0.05);
    --sombra-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --sombra-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --sombra-xl: 0 20px 25px -5px rgba(0,0,0,0.1);

    /* Transicoes */
    --transicao: 200ms ease;

    /* Fonte */
    --fonte: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --fonte-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* -- Reset -- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--fonte);
    color: var(--cor-texto);
    background: var(--cor-fundo);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--cor-primaria);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    display: block;
}

input, select, textarea, button {
    font-family: inherit;
    font-size: inherit;
}

/* -- Tipografia -- */
h1 { font-size: 1.875rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.5rem; font-weight: 600; line-height: 1.3; }
h3 { font-size: 1.25rem; font-weight: 600; line-height: 1.4; }
h4 { font-size: 1.125rem; font-weight: 500; line-height: 1.4; }

.texto-secundario { color: var(--cor-texto-secundario); }
.texto-sucesso { color: var(--cor-sucesso); }
.texto-erro { color: var(--cor-erro); }
.texto-aviso { color: var(--cor-aviso); }

/* -- Formularios -- */
.form-grupo {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: var(--espacamento-md);
}

.form-grupo label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--cor-texto);
}

.form-grupo label .obrigatorio {
    color: var(--cor-erro);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--cor-borda);
    border-radius: var(--borda-raio-md);
    background: var(--cor-fundo-card);
    color: var(--cor-texto);
    font-size: 0.9375rem;
    transition: border-color var(--transicao), box-shadow var(--transicao);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--cor-primaria);
    box-shadow: 0 0 0 3px var(--cor-primaria-light);
}

.form-input::placeholder {
    color: var(--cor-texto-terciario);
}

.form-input.erro {
    border-color: var(--cor-erro);
}

.form-erro {
    font-size: 0.8125rem;
    color: var(--cor-erro);
    min-height: 1.2em;
}

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

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--espacamento-md);
}

/* -- Botoes -- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--borda-raio-md);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transicao);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primario {
    background: var(--cor-primaria);
    color: #fff;
}

.btn-primario:hover:not(:disabled) {
    background: var(--cor-primaria-hover);
}

.btn-secundario {
    background: var(--cor-fundo-card);
    color: var(--cor-texto);
    border: 1px solid var(--cor-borda);
}

.btn-secundario:hover:not(:disabled) {
    background: var(--cor-fundo-hover);
    border-color: var(--cor-borda-hover);
}

.btn-sucesso {
    background: var(--cor-sucesso);
    color: #fff;
}

.btn-sucesso:hover:not(:disabled) {
    background: #15803d;
}

.btn-perigo {
    background: var(--cor-erro);
    color: #fff;
}

.btn-perigo:hover:not(:disabled) {
    background: #b91c1c;
}

.btn-info {
    background: var(--cor-info);
    color: #fff;
}

.btn-info:hover:not(:disabled) {
    background: #0369a1;
}

.btn-ghost {
    background: transparent;
    color: var(--cor-texto-secundario);
    padding: 8px 12px;
}

.btn-ghost:hover:not(:disabled) {
    background: var(--cor-fundo-hover);
    color: var(--cor-texto);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 12px 28px;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

.btn .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* -- Cards -- */
.card {
    background: var(--cor-fundo-card);
    border: 1px solid var(--cor-borda);
    border-radius: var(--borda-raio-lg);
    padding: var(--espacamento-lg);
    box-shadow: var(--sombra-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--espacamento-md);
}

.card-titulo {
    font-size: 1.125rem;
    font-weight: 600;
}

/* -- Tabelas -- */
.tabela-container {
    overflow-x: auto;
    border: 1px solid var(--cor-borda);
    border-radius: var(--borda-raio-lg);
}

.tabela {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.tabela th {
    background: var(--cor-fundo);
    font-weight: 600;
    text-align: left;
    padding: 10px 10px;
    border-bottom: 1px solid var(--cor-borda);
    white-space: nowrap;
    color: var(--cor-texto-secundario);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tabela td {
    padding: 10px 10px;
    border-bottom: 1px solid var(--cor-borda);
    vertical-align: middle;
}

.tabela tbody tr:hover {
    background: var(--cor-fundo-hover);
}

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

/* -- Badges -- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--borda-raio-full);
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-sucesso { background: var(--cor-sucesso-light); color: var(--cor-sucesso); }
.badge-erro { background: var(--cor-erro-light); color: var(--cor-erro); }
.badge-aviso { background: var(--cor-aviso-light); color: var(--cor-aviso); }
.badge-info { background: var(--cor-info-light); color: var(--cor-info); }
.badge-neutro { background: var(--cor-fundo); color: var(--cor-texto-secundario); }

/* -- Toast / Notificacoes -- */
.toast-container {
    position: fixed;
    top: var(--espacamento-lg);
    right: var(--espacamento-lg);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: var(--espacamento-sm);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--espacamento-sm);
    padding: 12px 16px;
    border-radius: var(--borda-raio-md);
    background: var(--cor-fundo-card);
    border: 1px solid var(--cor-borda);
    box-shadow: var(--sombra-lg);
    min-width: 300px;
    max-width: 450px;
    animation: toastIn 0.3s ease;
    font-size: 0.875rem;
}

.toast-sucesso { border-left: 4px solid var(--cor-sucesso); }
.toast-erro { border-left: 4px solid var(--cor-erro); }
.toast-aviso { border-left: 4px solid var(--cor-aviso); }
.toast-info { border-left: 4px solid var(--cor-info); }

.toast-fechar {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--cor-texto-terciario);
    font-size: 1.25rem;
    line-height: 1;
    padding: 0 4px;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

.toast-saindo {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
    to { opacity: 0; transform: translateX(100%); }
}

/* -- Modal -- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--espacamento-lg);
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--cor-fundo-card);
    border-radius: var(--borda-raio-lg);
    box-shadow: var(--sombra-xl);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 0.2s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--espacamento-lg);
    border-bottom: 1px solid var(--cor-borda);
}

.modal-titulo {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-fechar {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--cor-texto-terciario);
    line-height: 1;
    padding: 4px;
}

.modal-fechar:hover {
    color: var(--cor-texto);
}

.modal-body {
    padding: var(--espacamento-lg);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--espacamento-sm);
    padding: var(--espacamento-md) var(--espacamento-lg);
    border-top: 1px solid var(--cor-borda);
}

.modal-lg {
    max-width: 720px;
}

.modal-xl {
    max-width: 1100px;
}

/* NFS-e — Modal de revisão split-view */
.nfse-review-container {
    display: flex;
    gap: 1.5rem;
    min-height: 400px;
}

.nfse-review-form {
    flex: 1;
    overflow-y: auto;
    max-height: 70vh;
}

.nfse-review-preview {
    flex: 1;
    overflow-y: auto;
    max-height: 70vh;
    border: 1px solid var(--cor-borda);
    border-radius: var(--borda-raio);
    padding: 1.5rem;
    background: #fff;
    font-size: 0.85rem;
    color: #333;
}

.nfse-preview-header {
    text-align: center;
    border-bottom: 2px solid #333;
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}

.nfse-preview-header h4 {
    margin: 0;
    font-size: 1rem;
}

.nfse-preview-section {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px dashed #ccc;
}

.nfse-preview-section strong {
    display: block;
    font-size: 0.75rem;
    color: #666;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.nfse-preview-descricao {
    white-space: pre-wrap;
    background: #f9f9f9;
    padding: 0.75rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    min-height: 80px;
    border: 1px solid #eee;
}

.nfse-chars-counter {
    font-size: 0.8rem;
    text-align: right;
    margin-top: 4px;
    color: var(--cor-texto-secundario);
}

.nfse-chars-counter.alerta {
    color: var(--cor-erro);
    font-weight: 600;
}

@media (max-width: 768px) {
    .nfse-review-container {
        flex-direction: column;
    }
    .modal-xl {
        max-width: 95vw;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* -- Utilitarios -- */
.escondido { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-sm { gap: var(--espacamento-sm); }
.gap-md { gap: var(--espacamento-md); }
.gap-lg { gap: var(--espacamento-lg); }
.mt-sm { margin-top: var(--espacamento-sm); }
.mt-md { margin-top: var(--espacamento-md); }
.mt-lg { margin-top: var(--espacamento-lg); }
.mb-md { margin-bottom: var(--espacamento-md); }
.mb-lg { margin-bottom: var(--espacamento-lg); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.w-full { width: 100%; }

/* -- Loading overlay -- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--cor-fundo);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: opacity 0.3s ease;
}

.loading-overlay.saindo {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--cor-borda);
    border-top-color: var(--cor-primaria);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* -- Vazio / Empty state -- */
.estado-vazio {
    text-align: center;
    padding: var(--espacamento-2xl) var(--espacamento-lg);
    color: var(--cor-texto-secundario);
}

.estado-vazio-icone {
    font-size: 3rem;
    margin-bottom: var(--espacamento-md);
    opacity: 0.4;
}

.estado-vazio h3 {
    color: var(--cor-texto);
    margin-bottom: var(--espacamento-sm);
}

/* -- Responsivo -- */
@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .modal {
        max-width: 100%;
        margin: var(--espacamento-sm);
    }

    .toast {
        min-width: auto;
        max-width: calc(100vw - 48px);
    }
}
