:root {
    --accent: #2563eb;
    --accent-dark: #1e40af;
    --ink: #1c2430;
    --muted: #64748b;
    --line: #e4e7ec;
    --bg: #f5f7fb;
    --sidebar-bg: #0e1626;
    --sidebar-ink: #cbd5e1;
}

html, body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    margin: 0;
}

h1, h2, h3 { font-weight: 700; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.btn-primary {
    --bs-btn-bg: var(--accent);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-bg: var(--accent-dark);
    --bs-btn-hover-border-color: var(--accent-dark);
    --bs-btn-active-bg: var(--accent-dark);
    --bs-btn-disabled-bg: var(--accent);
    --bs-btn-disabled-border-color: var(--accent);
}
.text-accent { color: var(--accent) !important; }

/* ---- App shell layout ------------------------------------------------ */
.page { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px; flex: 0 0 240px;
    background: var(--sidebar-bg);
    background-image: linear-gradient(180deg, #101b30, #0b1220);
}
main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.top-row.px-4 {
    height: 56px; background: #fff; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 20;
}
.content { padding-top: 1.4rem; padding-bottom: 3rem; }
.company-icon { color: var(--muted); }
.company-switcher { min-width: 180px; }
.user-chip { color: var(--muted); font-size: .9rem; }
.top-link { color: var(--muted); font-size: 1.15rem; }
.top-link:hover { color: var(--accent); text-decoration: none; }

/* ---- Sidebar nav ----------------------------------------------------- */
.sidebar .navbar { background: transparent; height: 56px; }
.sidebar .navbar-brand { color: #fff; font-weight: 700; font-size: 1.15rem; }
.nav-scrollable { padding: .5rem 0; }
.sidebar .nav-link {
    color: var(--sidebar-ink); border-radius: 8px; margin: 2px 8px;
    padding: .5rem .75rem; font-size: .94rem; font-weight: 500;
}
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar .nav-link.active { background: var(--accent); color: #fff; }
.nav-section {
    color: #5b6b85; font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .06em; padding: 1rem 1.25rem .25rem;
}
.navbar-toggler { display: none; }

@media (max-width: 820px) {
    .page { flex-direction: column; }
    .sidebar { width: 100%; flex-basis: auto; }
}

/* ---- Cards / tables -------------------------------------------------- */
.card { border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.stat-card { padding: 1.1rem 1.25rem; }
.stat-card .stat-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .stat-value { font-size: 1.7rem; font-weight: 700; }
.table thead th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; border-bottom: 2px solid var(--line); }
.table td { vertical-align: middle; }

.badge-status { font-weight: 600; padding: .35em .6em; border-radius: 6px; font-size: .74rem; }
.st-Draft { background: #eef0f4; color: #475467; }
.st-Sent { background: #e0edff; color: #1e40af; }
.st-PartiallyPaid { background: #fff3d6; color: #92600b; }
.st-Paid { background: #dcfce7; color: #166534; }
.st-Overdue { background: #fee2e2; color: #b42318; }
.st-Void { background: #f1f1f4; color: #98a2b3; text-decoration: line-through; }

/* ---- Login ----------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0e1626, #1e293b); padding: 1rem; }
.login-card { background: #fff; border-radius: 16px; padding: 2.2rem; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-brand { font-size: 1.5rem; font-weight: 700; }

/* ---- Invoice document (shared base; each template overrides heavily) - */
.inv-doc {
    --inv-accent: var(--accent);
    background: #fff; color: #1c2430; max-width: 820px; margin: 0 auto;
    padding: 44px 48px; font-size: 14px; line-height: 1.5; position: relative;
    box-shadow: 0 1px 3px rgba(16,24,40,.08); border-radius: 8px;
}
.inv-doc table { width: 100%; border-collapse: collapse; }
.inv-doc .inv-logo { max-height: 70px; max-width: 240px; margin-bottom: 8px; display: block; }
.inv-doc .header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.inv-doc .party-meta { text-align: right; white-space: nowrap; }
.inv-doc .inv-title { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.inv-doc .inv-number { font-weight: 600; font-size: 15px; margin-top: 4px; }
.inv-doc .inv-dates { font-size: 13px; }
.inv-doc .inv-company-name { font-size: 20px; font-weight: 700; }
.inv-doc .muted { color: #64748b; }
.inv-doc .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; }
.inv-doc .parties { display: flex; justify-content: space-between; gap: 24px; margin: 28px 0 10px; }
.inv-doc .terms-col { text-align: right; }
.inv-doc .bill-name { font-weight: 700; font-size: 15px; }
.inv-doc .items th { text-align: left; padding: 9px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #64748b; }
.inv-doc .items td { padding: 10px 8px; border-bottom: 1px solid #eef0f4; }
.inv-doc .items .num { text-align: right; white-space: nowrap; }
.inv-doc .totals { width: 300px; margin-left: auto; margin-top: 14px; }
.inv-doc .totals td { padding: 4px 8px; }
.inv-doc .totals .grand td { font-weight: 800; font-size: 17px; border-top: 2px solid #1c2430; padding-top: 8px; }
.inv-doc .totals .due td { font-weight: 700; color: #b42318; }
.inv-doc .inv-notes { margin-top: 26px; padding-top: 16px; border-top: 1px solid #eef0f4; color: #475467; }

/* ============ TEMPLATE 1 — CLASSIC: formal, serif title, double rule ==== */
.tmpl-classic .header { padding-bottom: 20px; border-bottom: 3px double var(--inv-accent); }
.tmpl-classic .inv-title { color: var(--inv-accent); font-family: Georgia, 'Times New Roman', serif; font-weight: 700; }
.tmpl-classic .inv-company-name { font-family: Georgia, 'Times New Roman', serif; }
.tmpl-classic .items thead tr { border-bottom: 2px solid var(--inv-accent); }
.tmpl-classic .items tbody td { border-bottom: 1px solid #e4e7ec; }
.tmpl-classic .totals .grand td { border-top-color: var(--inv-accent); }

/* ============ TEMPLATE 2 — MODERN: full-width accent band, zebra ======= */
.tmpl-modern { padding-top: 0; overflow: hidden; }
.tmpl-modern .band { background: var(--inv-accent); margin: 0 -48px 30px; padding: 36px 48px; }
.tmpl-modern .band .header { align-items: center; }
.tmpl-modern .band .inv-title,
.tmpl-modern .band .inv-company-name { color: #fff; }
.tmpl-modern .band .muted,
.tmpl-modern .band .lbl,
.tmpl-modern .band .inv-number,
.tmpl-modern .band .inv-dates { color: rgba(255,255,255,.85); }
.tmpl-modern .items thead tr { background: color-mix(in srgb, var(--inv-accent) 12%, #fff); }
.tmpl-modern .items th { color: var(--inv-accent); }
.tmpl-modern .items td { border-bottom: none; }
.tmpl-modern .items tbody tr:nth-child(even) td { background: #f7f9fc; }
.tmpl-modern .totals { background: color-mix(in srgb, var(--inv-accent) 8%, #fff); border-radius: 10px; padding: 10px 16px; }
.tmpl-modern .totals .grand td { color: var(--inv-accent); border-top-color: color-mix(in srgb, var(--inv-accent) 45%, #fff); }

/* ============ TEMPLATE 3 — MINIMAL: airy, monochrome, wide tracking ==== */
.tmpl-minimal { padding: 60px 56px; color: #111; }
.tmpl-minimal .header { border-bottom: 1px solid #ececec; padding-bottom: 22px; }
.tmpl-minimal .inv-logo { max-height: 52px; }
.tmpl-minimal .inv-title { font-weight: 500; letter-spacing: .35em; text-transform: uppercase; font-size: 15px; color: #111; }
.tmpl-minimal .inv-company-name { font-size: 16px; font-weight: 600; letter-spacing: .02em; }
.tmpl-minimal .inv-number { font-weight: 400; color: #111; }
.tmpl-minimal .parties { margin: 34px 0 18px; }
.tmpl-minimal .items th { color: #9aa2ae; border-bottom: 1px solid #ececec; font-weight: 500; }
.tmpl-minimal .items td { border-bottom: 1px solid #f4f4f6; padding: 12px 8px; }
.tmpl-minimal .totals { margin-top: 22px; }
.tmpl-minimal .totals .grand td { color: #111; border-top: 2px solid var(--inv-accent); }

/* ============ TEMPLATE 4 — BOLD: accent left stripe, hero, filled bar == */
.tmpl-bold { border-left: 14px solid var(--inv-accent); }
.tmpl-bold .hero { background: var(--inv-accent); margin: -44px -48px 30px; padding: 40px 48px; }
.tmpl-bold .hero .header { align-items: flex-end; }
.tmpl-bold .hero .inv-title { color: #fff; font-size: 52px; letter-spacing: -.03em; }
.tmpl-bold .hero .inv-company-name { color: #fff; font-size: 22px; }
.tmpl-bold .hero .muted,
.tmpl-bold .hero .lbl,
.tmpl-bold .hero .inv-number,
.tmpl-bold .hero .inv-dates { color: rgba(255,255,255,.9); }
.tmpl-bold .bill-name { font-size: 17px; }
.tmpl-bold .items thead tr { background: #1c2430; }
.tmpl-bold .items th { color: #fff; }
.tmpl-bold .items td { border-bottom: 2px solid #eef0f4; }
.tmpl-bold .totals .grand td { background: var(--inv-accent); color: #fff; padding: 11px 12px; font-size: 19px; border-top: none; }

/* ---- Template picker thumbnails (Settings) -------------------------- */
.tmpl-card { border: 2px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; background: #fff; transition: border-color .12s, box-shadow .12s; }
.tmpl-card:hover { border-color: #cbd5e1; }
.tmpl-card.sel { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.tmpl-thumb { height: 188px; overflow: hidden; position: relative; background: #fff; pointer-events: none; border-bottom: 1px solid var(--line); }
.tmpl-thumb .inv-doc { width: 820px; transform: scale(.285); transform-origin: top left; box-shadow: none; border-radius: 0; margin: 0; }
.tmpl-cap { padding: 8px 12px; font-weight: 600; font-size: .9rem; display: flex; align-items: center; justify-content: space-between; }
.tmpl-card.sel .tmpl-cap { color: var(--accent); }

/* ---- Public page + print -------------------------------------------- */
.public-wrap { background: var(--bg); min-height: 100vh; padding: 28px 16px; }
.public-actions { max-width: 820px; margin: 0 auto 16px; display: flex; justify-content: flex-end; gap: 8px; }

@media print {
    .no-print { display: none !important; }
    body, .public-wrap { background: #fff !important; padding: 0 !important; }
    .inv-doc { box-shadow: none; border-radius: 0; max-width: none; }
    .inv-doc, .inv-doc * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
