/*
 * Design system do NfseSaaS — portado de um mockup aprovado (visual
 * moderno: sidebar escura fixa, topbar com blur, cards com sombra
 * suave, badges em pill, botões com leve elevação no hover).
 *
 * Decisão importante: em vez de introduzir um conjunto de classes
 * paralelo ao Bootstrap, as classes do Bootstrap já usadas em TODAS as
 * views (.card, .btn, .btn-primary, .badge, .form-control, .form-select,
 * table) foram RESTILIZADAS aqui pra ficar com a cara do mockup. Isso
 * significa que nenhuma view precisou ser reescrita — o efeito visual
 * se propaga globalmente só por herdar este arquivo + o novo _Layout.
 *
 * O "shell" (sidebar/topbar/app/content) é próprio (não é AdminLTE) —
 * removemos o AdminLTE de propósito: além de mais simples, ele foi a
 * causa do bug de "tudo preto" anterior (seguia o dark mode do SO).
 */

:root {
    --bg: #f6f8fc;
    --surface: #ffffff;
    --surface-2: #f9fbff;
    --text: #142033;
    --muted: #6b778c;
    --line: #e7ebf2;
    --primary: #2563eb;
    --primary-2: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #16a34a;
    --success-soft: #ecfdf3;
    --warning: #d97706;
    --danger: #dc2626;
    --shadow: 0 10px 30px rgba(20, 32, 51, .06);
    --radius: 16px;
    --sidebar-width: 260px;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
    color: inherit;
}

/* =============== Shell (sidebar + topbar + conteúdo) =============== */

.app {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: #0f172a;
    color: #cbd5e1;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    z-index: 40;
    overflow-y: auto;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    padding: 0 10px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    margin-bottom: 18px;
}

.sidebar .brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #2563eb, #60a5fa);
    box-shadow: 0 8px 18px rgba(37, 99, 235, .28);
    font-weight: 700;
    flex: 0 0 auto;
}

.sidebar .brand strong {
    display: block;
    font-size: 15px;
}

.sidebar .brand span {
    display: block;
    font-size: 11px;
    color: #94a3b8;
    margin-top: 3px;
}

.sidebar .nav-label {
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: 10px;
    font-weight: 700;
    color: #64748b;
    margin: 12px 10px 8px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 10px;
    color: #aeb8c7;
    font-size: 14px;
    transition: .2s ease;
}

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff;
}

.sidebar-nav a.active {
    background: linear-gradient(90deg, rgba(37, 99, 235, .28), rgba(37, 99, 235, .10));
    color: #fff;
    box-shadow: inset 3px 0 0 #60a5fa;
}

.sidebar-nav .nav-icon {
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    font-size: 15px;
    opacity: .95;
}

.sidebar-footer {
    margin-top: auto;
    padding: 14px 10px 4px;
    border-top: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-footer .support {
    background: rgba(255, 255, 255, .05);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 12px;
    padding: 12px;
}

.sidebar-footer .support strong {
    color: #fff;
    font-size: 13px;
}

.sidebar-footer .support p {
    font-size: 11px;
    line-height: 1.5;
    color: #94a3b8;
    margin: 5px 0 0;
}

.main {
    min-width: 0;
}

.topbar {
    height: 72px;
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar .top-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-btn {
    display: none;
    border: 0;
    background: transparent;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    color: var(--text);
    font-size: 1.1rem;
}

.menu-btn:hover {
    background: #f1f5f9;
}

.breadcrumb {
    font-size: 13px;
    color: var(--muted);
}

.breadcrumb strong {
    color: var(--text);
    font-weight: 600;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 12px;
    cursor: pointer;
}

.user-menu:hover {
    background: #f8fafc;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    color: #1d4ed8;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
    flex: 0 0 auto;
}

.user-meta {
    line-height: 1.25;
}

.user-meta strong {
    display: block;
    font-size: 13px;
}

.user-meta span {
    font-size: 11px;
    color: var(--muted);
}

.content {
    padding: 28px;
    max-width: 1600px;
    margin: 0 auto;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.page-head h1 {
    margin: 0;
    font-size: 26px;
    letter-spacing: -.03em;
    font-weight: 700;
}

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .35);
    z-index: 35;
}

@media (max-width: 992px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        width: 260px;
        transition: .25s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .mobile-overlay.show {
        display: block;
    }

    .menu-btn {
        display: grid;
        place-items: center;
    }

    .topbar {
        padding: 0 16px;
    }

    .content {
        padding: 20px 16px;
    }

    .user-meta {
        display: none;
    }
}

@media (max-width: 560px) {
    .breadcrumb {
        display: none;
    }
}

/* =============== KPI (stat) cards =============== */

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

@media (max-width: 1100px) {
    .stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 560px) {
    .stats {
        grid-template-columns: 1fr;
    }
}

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.stat-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.stat-label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
}

.stat-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--primary-soft);
    color: var(--primary);
    display: grid;
    place-items: center;
    font-size: 1rem;
}

.stat strong {
    font-size: 24px;
    letter-spacing: -.03em;
    display: block;
}

.stat small {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    font-size: 11px;
}

/* =============== Cards (Bootstrap .card restilizado) =============== */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
    padding: 18px 20px;
    font-weight: 600;
}

.card-footer {
    background: var(--surface);
    border-top: 1px solid var(--line);
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}

/* =============== Botões (Bootstrap .btn restilizado) =============== */

.btn {
    border-radius: 10px;
    font-weight: 600;
    font-size: 13px;
    transition: .18s ease;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 6px 16px rgba(37, 99, 235, .18);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--primary-2);
    border-color: var(--primary-2);
    transform: translateY(-1px);
}

.btn-outline-secondary,
.btn-outline-primary,
.btn-outline-danger,
.btn-outline-warning,
.btn-secondary {
    background: #fff;
    border-color: var(--line);
    color: #344054;
}

.btn-outline-secondary:hover,
.btn-outline-primary:hover,
.btn-secondary:hover {
    background: #f8fafc;
    border-color: #d6dce6;
}

.btn-outline-danger:hover {
    background: #fff7f7;
    color: var(--danger);
    border-color: #fecaca;
}

.btn-sm {
    border-radius: 8px;
}

.dt-buttons .btn {
    border-radius: 8px;
    font-size: 0.78rem;
}

/* =============== Badges (status pill) =============== */

.badge {
    font-weight: 700;
    font-size: 11px;
    padding: 5px 9px;
    border-radius: 999px;
    letter-spacing: .01em;
}

/* =============== Tabelas / DataTables =============== */

table.dataTable thead th,
.table thead th {
    background: #f8fafc;
    color: #667085;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 700;
    border-bottom: 1px solid var(--line) !important;
    white-space: nowrap;
}

table.dataTable tbody td,
.table tbody td {
    font-size: 13px;
    vertical-align: middle;
    border-bottom-color: #eef1f6;
}

table.dataTable tbody tr:hover,
.table tbody tr:hover {
    background: #fbfdff;
}

/* =============== Formulários =============== */

.form-label {
    font-weight: 600;
    font-size: 12.5px;
    color: #344054;
}

.form-control,
.form-select {
    border-radius: 10px;
    border-color: var(--line);
    font-size: 13px;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, .15);
}

/* =============== Autenticação (login/registro/convite) =============== */

.auth-page {
    background: linear-gradient(160deg, #eef1fb 0%, var(--bg) 55%);
}

.auth-card {
    border-radius: 20px;
}

/* =============== Toast de feedback (substitui alert() nativo) =============== */

.toast-container-nfse {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast-nfse {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #111827;
    color: #fff;
    padding: 12px 34px 12px 14px;
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .2);
    font-size: 13px;
    max-width: 360px;
    overflow: hidden;
    opacity: 0;
    transform: translateX(24px);
    transition: opacity .2s ease, transform .2s ease;
    pointer-events: auto;
}

.toast-nfse.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-nfse.hide {
    opacity: 0;
    transform: translateX(24px);
}

.toast-nfse.toast-erro {
    background: #7f1d1d;
}

.toast-nfse-icone {
    font-size: 16px;
    flex-shrink: 0;
}

.toast-nfse-texto {
    flex: 1;
}

.toast-nfse-fechar {
    position: absolute;
    top: 6px;
    right: 6px;
    background: transparent;
    border: 0;
    color: rgba(255, 255, 255, .7);
    font-size: 12px;
    line-height: 1;
    padding: 5px;
    cursor: pointer;
    border-radius: 6px;
}

.toast-nfse-fechar:hover {
    background: rgba(255, 255, 255, .12);
    color: #fff;
}

.toast-nfse-barra {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: rgba(255, 255, 255, .35);
    transform: scaleX(1);
    transform-origin: left;
    animation-name: toast-nfse-progresso;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}

@keyframes toast-nfse-progresso {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

/* =============== Rodapé de auditoria injetado na impressão =============== */

.rodape-exportacao {
    margin-top: 1.5rem;
    padding-top: 0.6rem;
    border-top: 1px solid #ccc;
    font-size: 0.75rem;
    color: #666;
}

/* =============== Tema escuro =============== */
/*
 * Ativado via atributo data-theme="dark" no <html> (ver _Layout.cshtml
 * e o botão no topbar). Reaproveita as MESMAS variáveis de :root — a
 * maior parte dos componentes (card, btn, badge, form-control) já lê
 * essas variáveis, então só redefini-las aqui já propaga pra quase tudo.
 * O resto (cores fixas em hex que não passavam por variável — tabelas,
 * topbar com blur, dropdown) é sobrescrito explicitamente abaixo.
 */
html[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1a2436;
    --surface-2: #16202f;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --line: #2b3852;
    --primary-soft: rgba(37, 99, 235, .18);
    --success-soft: rgba(22, 163, 74, .18);
}

html[data-theme="dark"] .topbar {
    background: rgba(15, 23, 42, .85);
    border-bottom-color: var(--line);
}

html[data-theme="dark"] .user-menu:hover,
html[data-theme="dark"] .menu-btn:hover {
    background: rgba(255, 255, 255, .06);
}

html[data-theme="dark"] table.dataTable thead th,
html[data-theme="dark"] .table thead th {
    background: var(--surface-2);
    color: var(--muted);
}

html[data-theme="dark"] table.dataTable tbody td,
html[data-theme="dark"] .table tbody td {
    background-color: var(--surface);
    border-bottom-color: var(--line);
    color: var(--text);
}

html[data-theme="dark"] table.dataTable tbody tr:hover,
html[data-theme="dark"] .table tbody tr:hover {
    background: var(--surface-2);
}

html[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: var(--surface-2);
    color: var(--text);
}

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
    background-color: var(--surface-2);
    border-color: var(--line);
    color: var(--text);
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    background-color: var(--surface-2);
    color: var(--text);
}

html[data-theme="dark"] .modal-content {
    background-color: var(--surface);
    color: var(--text);
}

/*
 * Todo modal centralizado verticalmente, sem precisar da classe
 * modal-dialog-centered em cada view (mesma regra que ela aplicaria,
 * replicada aqui uma vez só — cobre os 16 modais existentes e qualquer
 * um novo automaticamente).
 */
.modal-dialog {
    display: flex;
    align-items: center;
    min-height: calc(100% - var(--bs-modal-margin-y, .5rem) * 2);
}

/* Corpo do modal nunca cresce além da tela — header/footer continuam
   visíveis, só o conteúdo do meio rola (ex.: detalhe de Nfse com
   muitos eventos). Não afeta modal pequeno: max-height só limita, não
   força altura mínima. */
.modal-body {
    max-height: calc(100vh - 210px);
    overflow-y: auto;
}

.modal-content {
    border: none;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .18);
}

.modal-backdrop.show {
    backdrop-filter: blur(3px);
}

html[data-theme="dark"] .dropdown-menu {
    background-color: var(--surface);
    border-color: var(--line);
}

html[data-theme="dark"] .dropdown-item {
    color: var(--text);
}

html[data-theme="dark"] .dropdown-item:hover {
    background-color: var(--surface-2);
    color: var(--text);
}

html[data-theme="dark"] .btn-outline-secondary,
html[data-theme="dark"] .btn-secondary {
    background: var(--surface-2);
    border-color: var(--line);
    color: var(--text);
}

html[data-theme="dark"] .card-footer,
html[data-theme="dark"] .card-header {
    background: var(--surface);
    border-color: var(--line);
}

/* Botão de alternar tema — sol/lua conforme o tema ativo (ver JS) */
.btn-tema {
    border: 0;
    background: transparent;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    color: var(--text);
    font-size: 1.1rem;
    display: grid;
    place-items: center;
}

.btn-tema:hover {
    background: #f1f5f9;
}

html[data-theme="dark"] .btn-tema:hover {
    background: rgba(255, 255, 255, .06);
}

/* Tela Sobre — visualizador do CHANGELOG.md (era <style> inline em Sobre/Index.cshtml) */
.changelog-viewer {
    max-height: 65vh;
    overflow-y: auto;
    white-space: pre-wrap;
    font-size: 0.875rem;
}

/* Tela Logs — visualizador dos logs de erro (era <style> inline em Logs/Index.cshtml) */
.log-viewer {
    max-height: 70vh;
    overflow-y: auto;
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 1rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.log-viewer .linha-erro { color: #f47174; }
.log-viewer .linha-aviso { color: #dcdcaa; }
