/* ==========================================================
   FaturaPro - Professional polish layer (loaded after style.css)
   ========================================================== */
:root {
    --primary: #4f46e5;
    --primary-light: #6366f1;
    --primary-dark: #4338ca;
    --bg-main: #f4f6fb;
    --bg-sidebar: #0b1220;
    --border: #e5e9f2;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-md: 0 8px 24px -6px rgba(16, 24, 40, .10);
    --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, .18);
    --surface-2: #f8fafc;
    --row-hover: #f5f7ff;
}

html.dark {
    color-scheme: dark;
    --bg-main: #0a0f1c;
    --bg-sidebar: #070b14;
    --bg-card: #121a2b;
    --text-main: #e6ebf5;
    --text-muted: #8c9ab3;
    --white: #121a2b;
    --border: #212c43;
    --border-hover: #31405f;
    --glass-bg: rgba(14, 21, 36, .75);
    --primary: #7c83ff;
    --primary-light: #9aa0ff;
    --primary-dark: #5b62f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 2px 6px rgba(0, 0, 0, .35);
    --shadow-md: 0 10px 28px -6px rgba(0, 0, 0, .55);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .7);
    --surface-2: #0f1626;
    --row-hover: #18223a;
}

body {
    background:
        radial-gradient(900px 400px at 85% -10%, rgba(99, 102, 241, .08), transparent 60%),
        var(--bg-main);
    transition: background-color .3s ease, color .3s ease;
}

/* ---------- Sidebar ---------- */
.sidebar {
    background: linear-gradient(180deg, #0f172a 0%, var(--bg-sidebar) 100%);
    border-right: 1px solid rgba(255, 255, 255, .05);
}

.logo {
    padding: .35rem .5rem 1.1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.logo>span>span {
    color: var(--primary-light);
    -webkit-text-fill-color: var(--primary-light);
}

.nav-item {
    border-left: 3px solid transparent;
}

.nav-item:hover {
    transform: none;
    background: rgba(255, 255, 255, .06);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(99, 102, 241, .28), rgba(99, 102, 241, .06));
    border-left-color: var(--primary-light);
    color: #fff;
    box-shadow: none;
}

.nav-item.active i {
    color: var(--primary-light);
}

/* ---------- Header ---------- */
.header {
    height: 68px;
    background: var(--glass-bg);
    box-shadow: 0 1px 0 var(--border), 0 6px 20px -12px rgba(16, 24, 40, .12);
}

.header h2 {
    font-size: 1.25rem !important;
    color: var(--text-main);
}

.theme-toggle {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    transition: all .25s ease;
}

.theme-toggle:hover {
    color: var(--primary);
    border-color: var(--primary-light);
    transform: rotate(18deg);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, .12);
}

.theme-toggle i {
    width: 18px;
    height: 18px;
}

/* ---------- Cards & stats ---------- */
.card {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 1.4rem 1.35rem;
    box-shadow: var(--shadow);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.stat-card {
    border-top: 3px solid var(--primary-light);
    transition: transform .25s ease, box-shadow .25s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
}

.stat-card:nth-child(2) {
    border-top-color: var(--warning);
}

.stat-card:nth-child(3) {
    border-top-color: #0ea5e9;
}

.stat-card:nth-child(4) {
    border-top-color: var(--success);
}

.stat-label {
    font-size: .72rem;
    letter-spacing: .08em;
}

.stat-value {
    font-size: 1.7rem;
    letter-spacing: -.02em;
}

/* ---------- Buttons ---------- */
.btn {
    border-radius: 10px;
    padding: .65rem 1.25rem;
    font-weight: 600;
    letter-spacing: .005em;
}

.btn-sm {
    padding: .4rem .8rem;
    font-size: .8rem;
}

.btn-primary {
    background: linear-gradient(180deg, var(--primary-light), var(--primary));
    box-shadow: 0 1px 2px rgba(16, 24, 40, .15), 0 6px 14px -4px rgba(79, 70, 229, .45), inset 0 1px 0 rgba(255, 255, 255, .18);
}

.btn-primary:hover {
    background: linear-gradient(180deg, var(--primary-light), var(--primary-dark));
    transform: translateY(-1px);
}

.btn-outline {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.btn-outline:hover {
    background: var(--surface-2);
    border-color: var(--primary-light);
    color: var(--primary);
}

.btn:focus-visible,
.nav-item:focus-visible,
.theme-toggle:focus-visible {
    outline: 3px solid rgba(99, 102, 241, .45);
    outline-offset: 2px;
}

/* ---------- Tables ---------- */
.data-table th {
    background: var(--surface-2);
    padding: .75rem .75rem;
    font-size: .68rem;
    letter-spacing: .07em;
}

.data-table td {
    padding: .85rem .75rem;
    font-size: .84rem;
}

.data-table tbody tr {
    transition: background .15s ease;
}

.data-table tr:hover td {
    background: var(--row-hover);
}

.table-container {
    border: 1px solid var(--border);
    border-radius: 12px;
}

/* ---------- Badges ---------- */
.badge {
    padding: .28rem .7rem;
    font-size: .72rem;
    letter-spacing: .02em;
    border: 1px solid transparent;
}

.badge.paid,
.badge.pago {
    background: rgba(16, 185, 129, .12);
    color: #059669;
    border-color: rgba(16, 185, 129, .25);
}

.badge.pending,
.badge.pendente {
    background: rgba(245, 158, 11, .13);
    color: #b45309;
    border-color: rgba(245, 158, 11, .28);
}

.badge.overdue,
.badge.atrasado {
    background: rgba(239, 68, 68, .11);
    color: #dc2626;
    border-color: rgba(239, 68, 68, .25);
}

html.dark .badge.paid,
html.dark .badge.pago {
    color: #34d399;
}

html.dark .badge.pending,
html.dark .badge.pendente {
    color: #fbbf24;
}

html.dark .badge.overdue,
html.dark .badge.atrasado {
    color: #f87171;
}

/* ---------- Forms ---------- */
.form-input,
.item-cell-input {
    background: var(--bg-card);
    color: var(--text-main);
    border-color: var(--border-hover);
    border-radius: 10px;
}

.item-cell-input {
    border-radius: 8px;
}

.form-input:focus,
.item-cell-input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, .16);
    background: var(--bg-card);
}

.form-label {
    color: var(--text-muted);
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.form-section-title {
    font-size: 1rem;
}

/* ---------- Modal / toast ---------- */
.modal {
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    background: var(--surface-2);
    border-radius: 18px 18px 0 0;
}

.toast {
    background: var(--bg-card);
    border-radius: 12px;
}

/* ---------- Surfaces that were hard-coded white ---------- */
.doc-type-switcher-bar,
.doc-type-btn,
.items-builder-table,
.totals-summary-box {
    background: var(--bg-card);
}

.rubric-card,
.items-builder-table thead tr {
    background: var(--surface-2);
}

.items-builder-table tbody tr:hover {
    background: var(--row-hover);
}

.btn-icon:hover {
    background: var(--surface-2);
}

/* ---------- Scrollbars ---------- */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-hover) transparent;
}

/* ---------- Document frame (new FR / FT / VD) ---------- */
.doc-frame-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 1.5rem;
    background: rgba(8, 13, 25, .62);
    backdrop-filter: blur(5px);
    overflow-y: auto;
    animation: frameFade .2s ease;
}

.doc-frame {
    width: 100%;
    max-width: 1280px;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: frameIn .3s cubic-bezier(.16, 1, .3, 1);
}

.doc-frame-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .9rem 1.5rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.doc-frame-header h3 {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: 1.1rem;
    margin: 0;
}

.doc-frame-header h3 i {
    color: var(--primary);
}

.doc-frame-body {
    padding: 1.5rem;
}

@keyframes frameFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes frameIn { from { opacity: 0; transform: translateY(24px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* ==========================================================
   Visualizador de Fatura Oficial (Modelo e-Fatura fatura2.pdf)
   ========================================================== */
.official-preview-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
    width: 100%;
}

.official-preview-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 820px;
    background: #1e293b;
    color: #f8fafc;
    padding: 0.65rem 1.15rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    flex-wrap: wrap;
    gap: 0.75rem;
}

.official-preview-toolbar .toolbar-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    font-weight: 600;
}

.official-preview-toolbar .toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.official-invoice-sheet {
    background: #ffffff !important;
    color: #000000 !important;
    border: 1.5px solid #000000 !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    width: 100%;
    max-width: 820px;
    padding: 26px 32px;
    box-sizing: border-box;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    line-height: 1.35;
    position: relative;
    user-select: text;
}

.official-invoice-sheet * {
    color: #000000;
    box-sizing: border-box;
}

.official-items-table {
    width: 100%;
    border-collapse: collapse !important;
    border: 1px solid #000000 !important;
    margin: 4px 0 16px 0;
}

.official-items-table th,
.official-items-table td {
    border: 1px solid #000000 !important;
    padding: 5px 6px;
    font-size: 10px;
}

.official-items-table th {
    background-color: #ffffff !important;
    font-weight: bold;
    text-transform: none;
}

.official-totals-table {
    width: 100%;
    border-collapse: collapse !important;
    border: 1px solid #000000 !important;
}

.official-totals-table td {
    border: 1px solid #000000 !important;
    padding: 4px 8px;
    font-size: 10.5px;
}

@media print {
    body * {
        visibility: hidden !important;
    }
    .official-invoice-sheet,
    .official-invoice-sheet * {
        visibility: visible !important;
    }
    .official-invoice-sheet {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 10mm 15mm !important;
        border: 1.5px solid #000000 !important;
        box-shadow: none !important;
        background: #ffffff !important;
        color: #000000 !important;
    }
    .modal-overlay,
    .doc-frame-overlay {
        background: transparent !important;
        backdrop-filter: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    .modal {
        box-shadow: none !important;
        border: none !important;
        background: transparent !important;
        margin: 0 !important;
        padding: 0 !important;
        max-width: 100% !important;
    }
    .modal-header,
    .official-preview-toolbar,
    .btn,
    .btn-icon,
    .header,
    .sidebar {
        display: none !important;
    }
    @page {
        size: A4 portrait;
        margin: 8mm;
    }
}

