:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --bg-soft: #edf2f7;
    --panel: #ffffff;
    --panel-strong: #f8fafc;
    --ink: #111827;
    --muted: #64748b;
    --line: #d8dee8;
    --primary: #1d4ed8;
    --primary-dark: #1e40af;
    --primary-soft: #e8f0ff;
    --green: #059669;
    --green-soft: #dcfce7;
    --amber: #d97706;
    --amber-soft: #fef3c7;
    --red: #dc2626;
    --red-soft: #fee2e2;
    --violet: #7c3aed;
    --slate: #475569;
    --sidebar-bg: #111827;
    --sidebar-bg-soft: #182233;
    --sidebar-line: #263244;
    --sidebar-ink: #f8fafc;
    --sidebar-muted: #a8b3c7;
    --shadow: 0 20px 45px rgba(15, 23, 42, .08);
    --shadow-sm: 0 8px 22px rgba(15, 23, 42, .055);
    --radius: 9px;
}

[data-bs-theme="dark"] {
    color-scheme: dark;
    --bg: #0f141b;
    --bg-soft: #111827;
    --panel: #171e29;
    --panel-strong: #1d2634;
    --ink: #f4f7fb;
    --muted: #aab6c7;
    --line: #2c3748;
    --primary: #60a5fa;
    --primary-dark: #93c5fd;
    --primary-soft: rgba(96, 165, 250, .16);
    --green: #34d399;
    --green-soft: rgba(52, 211, 153, .14);
    --amber: #fbbf24;
    --amber-soft: rgba(251, 191, 36, .14);
    --red: #fb7185;
    --red-soft: rgba(251, 113, 133, .15);
    --violet: #a78bfa;
    --slate: #94a3b8;
    --sidebar-bg: #0b111a;
    --sidebar-bg-soft: #121b29;
    --sidebar-line: #263244;
    --sidebar-ink: #f8fafc;
    --sidebar-muted: #a8b3c7;
    --shadow: 0 22px 55px rgba(0, 0, 0, .34);
    --shadow-sm: 0 12px 30px rgba(0, 0, 0, .25);
}

* {
    letter-spacing: 0;
}

html {
    background: var(--bg);
    overflow-y: scroll;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

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

a:hover {
    color: var(--primary-dark);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    min-height: 2.35rem;
    border-radius: 9px;
    font-weight: 650;
    white-space: nowrap;
    transition: background-color .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn svg,
.nav-link svg,
.sidebar-folder-title svg,
.brand-mark svg {
    width: 1rem;
    height: 1rem;
    flex: 0 0 auto;
}

i[data-lucide] {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    flex: 0 0 auto;
    vertical-align: -.15em;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 10px 22px rgba(29, 78, 216, .18);
}

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

.btn-outline-secondary {
    border-color: var(--line);
    color: var(--ink);
    background: color-mix(in srgb, var(--panel) 88%, transparent);
}

.btn-outline-secondary:hover {
    border-color: var(--primary);
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.btn.icon-only {
    width: 2.35rem;
    padding-inline: 0;
}

.app-topbar {
    min-height: 64px;
    background: color-mix(in srgb, var(--panel) 96%, transparent);
    backdrop-filter: blur(12px);
    border-color: var(--line) !important;
    position: sticky;
    top: 0;
    z-index: 20;
}

.navbar-brand {
    color: var(--ink);
    font-weight: 800;
}

.brand-logo {
    display: block;
    width: 164px;
    max-width: 42vw;
    height: auto;
}

.nav-mobile-folder {
    margin-top: .6rem;
    padding: .45rem 1rem .15rem;
    color: var(--muted);
    font-size: .76rem;
    font-weight: 800;
    text-transform: uppercase;
}

.nav-mobile-sub .nav-link {
    padding-left: 1.75rem;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 9px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), #0f766e);
    box-shadow: 0 10px 20px rgba(15, 118, 110, .16);
}

.brand-mark-lg {
    width: 2.75rem;
    height: 2.75rem;
}

.brand-mark-lg svg {
    width: 1.35rem;
    height: 1.35rem;
}

.app-shell {
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr);
    gap: 1.15rem;
    min-height: calc(100vh - 64px);
    align-items: start;
    padding: 1rem 1.35rem 1.5rem 1rem;
}

.app-sidebar {
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-line) !important;
    border-radius: 18px;
    align-self: start;
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 92px);
    overflow-y: auto;
    padding: .8rem .7rem;
    box-shadow: 0 18px 42px rgba(2, 6, 23, .22);
}

.app-sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: .55rem;
    min-height: 2.34rem;
    color: var(--sidebar-muted);
    border: 1px solid transparent;
    border-radius: 8px;
    padding: .55rem .62rem;
    font-size: .92rem;
    font-weight: 650;
}

.app-sidebar .nav-link:hover {
    background: var(--sidebar-bg-soft);
    color: var(--sidebar-ink);
}

.app-sidebar .nav-link.active {
    background: rgba(96, 165, 250, .16);
    border-color: rgba(147, 197, 253, .22);
    color: #ffffff;
}

.sidebar-folder {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: .22rem;
}

.sidebar-folder.active {
    border-color: rgba(147, 197, 253, .16);
    background: rgba(15, 23, 42, .32);
}

.sidebar-folder-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .55rem;
    width: 100%;
    min-height: 2.22rem;
    padding: .46rem .58rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--sidebar-ink);
    font-size: .72rem;
    font-weight: 800;
    text-transform: uppercase;
    text-align: left;
}

.sidebar-folder-title:hover {
    background: var(--sidebar-bg-soft);
}

.sidebar-folder-title i[data-lucide] {
    color: #93c5fd;
}

.sidebar-folder-name {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
}

.sidebar-folder-chevron {
    transition: transform .16s ease;
}

.sidebar-folder:not(.is-open) .sidebar-folder-chevron {
    transform: rotate(-90deg);
}

.sidebar-folder-links {
    display: none;
    gap: .16rem;
}

.sidebar-folder.is-open .sidebar-folder-links {
    display: grid;
}

.sidebar-folder-links .nav-link {
    min-height: 2.14rem;
    padding: .48rem .55rem .48rem 1.55rem;
    font-size: .88rem;
}

.app-content {
    width: 100%;
    max-width: 1500px;
    min-width: 0;
    padding: .2rem 0 2rem;
}

.auth-content {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
    background:
        linear-gradient(135deg, rgba(29, 78, 216, .08), transparent 36%),
        linear-gradient(315deg, rgba(5, 150, 105, .08), transparent 36%),
        var(--bg-soft);
}

.auth-panel {
    width: min(100%, 440px);
}

.auth-panel-wide {
    width: min(100%, 760px);
}

.auth-card,
.panel,
.metric-card,
.empty-state {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.auth-card {
    padding: 2rem;
}

.auth-logo {
    display: block;
    width: min(270px, 100%);
    height: auto;
}

.auth-card h1,
.page-header h1,
.empty-state h1,
.empty-state h2 {
    color: var(--ink);
    font-weight: 800;
}

.auth-switch {
    display: flex;
    justify-content: center;
    gap: .5rem;
    margin-top: 1.25rem;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.1rem;
}

.page-header h1 {
    margin: 0;
    font-size: 1.72rem;
    line-height: 1.15;
}

.page-subtitle {
    margin: .35rem 0 0;
    color: var(--muted);
}

.page-subtitle strong {
    color: var(--ink);
}

.eyebrow {
    margin: 0 0 .3rem;
    color: var(--muted);
    font-size: .76rem;
    font-weight: 800;
    text-transform: uppercase;
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .55rem;
}

.period-filter {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .55rem;
}

.period-filter .form-select,
.period-filter .form-control {
    width: auto;
    min-width: 148px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.quick-action {
    display: grid;
    align-content: center;
    gap: .35rem;
    min-height: 98px;
    padding: 1rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
    transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}

.quick-action:hover {
    background: var(--primary-soft);
    color: var(--ink);
    border-color: color-mix(in srgb, var(--primary) 28%, transparent);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.quick-action svg {
    width: 1.4rem;
    height: 1.4rem;
    color: var(--primary);
}

.quick-action strong {
    font-size: 1rem;
}

.quick-action span {
    color: var(--muted);
    font-size: .86rem;
}

.metric-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: .9rem;
    min-height: 98px;
    padding: 1rem;
    overflow: hidden;
}

.metric-card::after {
    content: "";
    position: absolute;
    inset: auto 0 0 0;
    height: 3px;
    background: color-mix(in srgb, var(--primary) 55%, transparent);
}

.metric-card.compact {
    min-height: 82px;
    box-shadow: none;
}

.secondary-metrics .metric-card::after {
    opacity: .45;
}

.metric-card p {
    color: var(--muted);
    margin: 0 0 .25rem;
    font-weight: 650;
}

.metric-card strong {
    display: block;
    color: var(--ink);
    font-size: 1.38rem;
    line-height: 1.2;
}

.metric-card small {
    display: block;
    margin-top: .35rem;
    color: var(--muted);
    font-weight: 650;
}

.metric-card-stacked {
    align-items: flex-start;
    min-height: 116px;
}

.metric-card-stacked strong {
    margin-top: .15rem;
    font-size: 1.5rem;
}

.metric-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 10px;
    color: #fff;
    flex: 0 0 auto;
}

.metric-icon svg {
    width: 1.18rem;
    height: 1.18rem;
}

.bg-blue { background: var(--primary); }
.bg-green { background: var(--green); }
.bg-amber { background: var(--amber); }
.bg-red { background: var(--red); }
.bg-violet { background: var(--violet); }
.bg-slate { background: var(--slate); }

.content-grid,
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.detail-grid-equal {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
    padding: 1rem;
}

.form-panel {
    padding: 1.15rem;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .95rem;
}

.panel-header h2,
.invoice-document h3 {
    margin: 0;
    color: var(--ink);
    font-size: 1rem;
    font-weight: 800;
}

.chart-box {
    height: 286px;
    min-height: 220px;
}

.chart-box.tall {
    height: 340px;
}

.filter-bar,
.filter-grid {
    display: grid;
    gap: .75rem;
    margin-bottom: 1rem;
}

.filter-bar {
    grid-template-columns: minmax(0, 1fr) auto auto;
}

.filter-grid {
    grid-template-columns: minmax(220px, 2fr) minmax(160px, 1.2fr) repeat(4, minmax(130px, 1fr)) auto;
}

.filter-search {
    position: relative;
}

.filter-search svg {
    position: absolute;
    left: .85rem;
    top: 50%;
    width: 1rem;
    height: 1rem;
    transform: translateY(-50%);
    color: var(--muted);
}

.filter-search .form-control {
    padding-left: 2.35rem;
}

.form-control,
.form-select {
    border-color: var(--line);
    border-radius: 9px;
    background-color: var(--panel);
    color: var(--ink);
}

.form-control:focus,
.form-select:focus {
    border-color: color-mix(in srgb, var(--primary) 58%, var(--line));
    box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--primary) 14%, transparent);
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--ink);
    --bs-table-border-color: var(--line);
    margin-bottom: 0;
}

.table thead th {
    color: var(--muted);
    font-size: .75rem;
    font-weight: 800;
    text-transform: uppercase;
    border-bottom-color: var(--line);
    background: color-mix(in srgb, var(--panel-strong) 74%, transparent);
}

.table td,
.table th {
    vertical-align: middle;
    padding-block: .72rem;
}

.table tbody tr:hover {
    background: color-mix(in srgb, var(--panel-strong) 70%, transparent);
}

.table a {
    font-weight: 750;
}

.table a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.empty-cell {
    color: var(--muted);
    text-align: center;
    padding: 2rem 1rem !important;
}

.empty-state {
    display: grid;
    place-items: center;
    text-align: center;
    gap: .75rem;
    padding: 3rem 1rem;
}

.small-empty {
    padding: 1.5rem;
}

.detail-list {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr);
    gap: .75rem 1rem;
    margin: 0;
}

.detail-list dt {
    color: var(--muted);
}

.detail-list dd {
    margin: 0;
}

.summary-list {
    display: grid;
    gap: .65rem;
}

.summary-list > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: .65rem;
    border-bottom: 1px solid var(--line);
}

.summary-list > div:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.summary-list span {
    color: var(--muted);
}

.invoice-form {
    max-width: 1280px;
}

.invoice-items-table {
    min-width: 980px;
}

.invoice-items-table .number-col {
    width: 140px;
}

.invoice-items-table .action-col {
    width: 54px;
}

.invoice-items-table tfoot th {
    border-bottom: 0;
}

.invoice-document {
    padding: 1.5rem;
}

.invoice-doc-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--line);
    padding-bottom: 1rem;
}

.invoice-doc-header h2 {
    margin: .6rem 0 .25rem;
    font-size: 1.5rem;
}

.invoice-doc-header p {
    margin: 0;
    color: var(--muted);
}

.invoice-totals-main {
    text-align: right;
}

.invoice-totals-main span {
    color: var(--muted);
    display: block;
}

.invoice-totals-main strong {
    color: var(--ink);
    font-size: 1.6rem;
}

.invoice-notes {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--panel-strong);
    border: 1px solid var(--line);
    border-radius: 10px;
    white-space: pre-wrap;
}

.settings-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 1.25rem;
    align-items: start;
}

.settings-main,
.settings-side {
    display: grid;
    gap: 1rem;
}

.settings-side {
    position: sticky;
    top: 84px;
}

.settings-actions {
    display: flex;
    justify-content: flex-end;
    gap: .65rem;
}

.color-input-row {
    display: grid;
    grid-template-columns: 3.2rem minmax(0, 1fr);
    gap: .65rem;
    align-items: center;
}

.color-input-row .form-control-color {
    width: 3.2rem;
    min-height: 2.35rem;
    padding: .2rem;
}

.pdf-mini-preview {
    min-height: 178px;
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: #111827;
    box-shadow: var(--shadow-sm);
}

.pdf-mini-top {
    width: 42%;
    height: .4rem;
    margin-bottom: 1.15rem;
    background: var(--preview-accent);
    border-radius: 999px;
}

.pdf-mini-title {
    color: var(--preview-accent);
    font-size: .78rem;
    font-weight: 800;
    margin-bottom: .65rem;
}

.pdf-mini-line {
    width: 100%;
    height: .42rem;
    margin-bottom: .45rem;
    background: #e5e7eb;
    border-radius: 999px;
}

.pdf-mini-line.short {
    width: 62%;
}

.pdf-mini-table {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: .25rem;
    margin: 1rem 0 .75rem;
}

.pdf-mini-table span {
    height: 1.8rem;
    background: color-mix(in srgb, var(--preview-accent) 18%, #f3f4f6);
    border: 1px solid color-mix(in srgb, var(--preview-accent) 30%, #d1d5db);
    border-radius: 4px;
}

.pdf-mini-total {
    text-align: right;
    color: #111827;
    font-size: .76rem;
    font-weight: 800;
}

.settings-summary .summary-list strong {
    overflow-wrap: anywhere;
}

.logo-upload-box {
    display: grid;
    gap: .85rem;
    height: auto;
}

.logo-preview {
    display: grid;
    place-items: center;
    min-height: 186px;
    margin-bottom: 0;
    padding: 1rem;
    background: color-mix(in srgb, var(--panel-strong) 72%, var(--panel));
    border: 1px dashed var(--line);
    border-radius: 14px;
}

.logo-preview img {
    max-width: 100%;
    max-height: 142px;
    object-fit: contain;
}

.default-logo-preview {
    display: grid;
    gap: .25rem;
    text-align: center;
    color: var(--primary);
}

.default-logo-preview strong {
    font-size: 1.35rem;
    font-style: italic;
}

.default-logo-preview span {
    color: var(--muted);
    font-size: .85rem;
}

.file-upload-control {
    display: grid;
    grid-template-columns: 1fr;
    gap: .5rem;
    align-items: stretch;
    overflow: visible;
}

.file-upload-control input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.file-upload-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    width: 100%;
    min-height: 2.65rem;
    margin: 0;
    padding: .5rem .85rem;
    border-radius: 10px;
    color: #fff;
    background: var(--primary);
    font-weight: 750;
    cursor: pointer;
    transition: background-color .16s ease;
}

.file-upload-button:hover {
    background: var(--primary-dark);
}

.file-upload-name {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 2.35rem;
    padding: .5rem .75rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.email-status-panel,
.email-attachments {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem;
    background: var(--panel-strong);
    border: 1px solid var(--line);
    border-radius: 10px;
}

.email-status-panel strong {
    display: block;
    margin: .1rem 0;
    color: var(--ink);
}

.email-attachments {
    align-items: flex-start;
    flex-direction: column;
}

.email-attachments-title {
    color: var(--ink);
    font-weight: 800;
}

.modal-content {
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.modal-header,
.modal-footer {
    border-color: var(--line);
}

[data-bs-theme="dark"] .dropdown-menu {
    --bs-dropdown-bg: var(--panel);
    --bs-dropdown-border-color: var(--line);
    --bs-dropdown-link-color: var(--ink);
    --bs-dropdown-link-hover-color: var(--ink);
    --bs-dropdown-link-hover-bg: var(--panel-strong);
}

.flash-stack {
    margin-bottom: 1rem;
}

.alert {
    border-radius: 10px;
}

.badge {
    border-radius: 7px;
    font-weight: 700;
}

[data-bs-theme="dark"] .text-secondary {
    color: var(--muted) !important;
}

[data-bs-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

@media (max-width: 1100px) {
    .settings-layout {
        grid-template-columns: 1fr;
    }

    .settings-side {
        position: static;
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .quick-actions-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
        padding: 0;
    }

    .app-sidebar {
        display: none;
    }

    .app-content {
        padding: 1rem;
    }

    .content-grid,
    .detail-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .page-header,
    .invoice-doc-header {
        align-items: stretch;
        flex-direction: column;
    }

    .header-actions,
    .page-header .btn,
    .invoice-doc-header .btn {
        width: 100%;
    }

    .metric-grid,
    .quick-actions-grid,
    .filter-bar,
    .filter-grid {
        grid-template-columns: 1fr;
    }

    .detail-list {
        grid-template-columns: 1fr;
    }

    .auth-card {
        padding: 1.35rem;
    }
}
