/* Cloudsoftera Invoice — UI tokens
   Ink sidebar, paper workspace; the brand gradient appears once (sidebar mark),
   money states carry the colour: amber = due, rose = overdue, green = settled. */
:root {
    --ink: #1e1b4b;
    --ink-2: #2e2a6b;
    --ink-text: #c7c9ff;
    --paper: #f5f6fa;
    --surface: #ffffff;
    --line: #e4e6ef;
    --text: #1d2133;
    --muted: #697086;
    --primary: #4f46e5;
    --primary-soft: #eef0ff;
    --due: #c2410c;
    --due-soft: #fff4e8;
    --overdue: #be123c;
    --overdue-soft: #fff0f3;
    --settled: #047857;
    --settled-soft: #e9f8f1;
    --brand-gradient: linear-gradient(135deg, #f59e0b 0%, #f97316 35%, #ec4899 65%, #4f46e5 100%);
    --radius: 10px;
    --bs-primary: #4f46e5;
    --bs-primary-rgb: 79, 70, 229;
    --bs-link-color: #4f46e5;
    --bs-link-hover-color: #3730a3;
    --bs-body-font-family: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
}

body { background: var(--paper); color: var(--text); font-family: var(--bs-body-font-family); font-size: .925rem; }
.num, .table td.num, .table th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }
a { text-decoration: none; }

/* ---------- buttons ---------- */
.btn { border-radius: 8px; font-weight: 600; }
.btn-primary { --bs-btn-bg: var(--primary); --bs-btn-border-color: var(--primary); --bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca; --bs-btn-active-bg: #3730a3; --bs-btn-disabled-bg: var(--primary); --bs-btn-disabled-border-color: var(--primary); }
.btn-outline-primary { --bs-btn-color: var(--primary); --bs-btn-border-color: #c7c9f5; --bs-btn-hover-bg: var(--primary); --bs-btn-hover-border-color: var(--primary); }
.btn:focus-visible, .form-control:focus, .form-select:focus { box-shadow: 0 0 0 3px rgba(79, 70, 229, .25); border-color: var(--primary); }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex-shrink: 0; background: var(--ink); color: var(--ink-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { display: flex; align-items: center; gap: .65rem; padding: 1.1rem 1.15rem 1rem; color: #fff; font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em; }
.sidebar .brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand-gradient); display: grid; place-items: center; color: #fff; font-size: .95rem; }
.sidebar .brand small { display: block; font-weight: 500; font-size: .72rem; color: var(--ink-text); letter-spacing: 0; }
.sidebar nav { flex: 1; overflow-y: auto; padding: .25rem .6rem; }
.sidebar .nav-group { font-size: .72rem; color: #8b8fd6; padding: .9rem .6rem .3rem; }
.sidebar .nav-link { color: var(--ink-text); display: flex; align-items: center; gap: .7rem; padding: .48rem .65rem; border-radius: 8px; font-weight: 600; }
.sidebar .nav-link i { font-size: 1.05rem; opacity: .85; }
.sidebar .nav-link:hover { background: var(--ink-2); color: #fff; }
.sidebar .nav-link.active { background: #fff; color: var(--ink); }
.sidebar .nav-link.active i { color: var(--primary); opacity: 1; }
.sidebar .user { border-top: 1px solid #34307a; padding: .8rem 1rem; font-size: .82rem; }
.sidebar .user .name { color: #fff; font-weight: 700; }
.sidebar .user a { color: var(--ink-text); }
.sidebar .user a:hover { color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 1.6rem 2rem 3rem; max-width: 1320px; width: 100%; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.55rem; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.page-head p { color: var(--muted); margin: .2rem 0 0; }

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-pad { padding: 1.15rem 1.25rem; }
.panel-title { font-weight: 700; font-size: .98rem; margin: 0 0 .75rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; padding: .85rem 1rem; border-bottom: 1px solid var(--line); }
.filters .form-control, .filters .form-select { max-width: 220px; }

.table { --bs-table-bg: transparent; margin: 0; }
.table > thead th { font-size: .78rem; color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--line); background: #fafbfd; padding: .6rem .75rem; white-space: nowrap; }
.table > tbody td { padding: .62rem .75rem; vertical-align: middle; border-color: #eef0f5; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: #f7f7fe; }
tr.clickable { cursor: pointer; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty .bi { font-size: 2rem; display: block; margin-bottom: .4rem; color: #b8bbd0; }

/* ---------- status pills ---------- */
.pill { display: inline-flex; align-items: center; gap: .3rem; font-size: .75rem; font-weight: 700; padding: .18rem .55rem; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-draft { background: #eef0f5; color: #586079; }
.pill-issued, .pill-sent { background: var(--due-soft); color: var(--due); }
.pill-partially_paid { background: #fff7d6; color: #a16207; }
.pill-paid, .pill-accepted, .pill-converted { background: var(--settled-soft); color: var(--settled); }
.pill-overdue, .pill-rejected, .pill-expired { background: var(--overdue-soft); color: var(--overdue); }
.pill-cancelled { background: #f1f1f4; color: #8b8f9c; text-decoration: line-through; }
.pill-active { background: var(--primary-soft); color: var(--primary); }

/* ---------- dashboard ---------- */
.ledger { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.ledger > div { padding: 1.1rem 1.25rem; border-right: 1px solid var(--line); }
.ledger > div:last-child { border-right: 0; }
.ledger .label { color: var(--muted); font-size: .82rem; font-weight: 600; }
.ledger .value { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: .15rem; }
.ledger .lead-cell { background: var(--ink); color: #fff; }
.ledger .lead-cell .label { color: var(--ink-text); }
.ledger .lead-cell .value { font-size: 1.9rem; }
.ledger .sub { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.ledger .lead-cell .sub { color: var(--ink-text); }
.v-due { color: var(--due); }
.v-overdue { color: var(--overdue); }
.v-settled { color: var(--settled); }
.quick-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.bar-list .row-item { display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem; padding: .45rem 0; border-bottom: 1px dashed var(--line); }
.bar-list .row-item:last-child { border-bottom: 0; }
.bar-list .bar { grid-column: 1 / -1; height: 5px; background: #eef0f5; border-radius: 4px; overflow: hidden; }
.bar-list .bar span { display: block; height: 100%; background: var(--primary); border-radius: 4px; }

/* ---------- document editor: laid out like the invoice itself ---------- */
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 0 #e7e8f0, 0 12px 32px -18px rgba(30, 27, 75, .25); }
.sheet-head { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; padding: 1.5rem 1.75rem 1.25rem; border-bottom: 3px solid var(--ink); }
.sheet-head > * { min-width: 0; }
.sheet-title { font-size: 1.35rem; font-weight: 800; color: var(--primary); letter-spacing: -.01em; }
.sheet-body { padding: 1.25rem 1.75rem 1.75rem; }
.party-card { border: 1px dashed #cfd2e6; border-radius: 8px; padding: .7rem .85rem; font-size: .86rem; background: #fbfbff; min-height: 86px; }
.party-card .nm { font-weight: 800; font-size: .98rem; }
.supply-hint { font-size: .8rem; color: var(--muted); }
.lines { width: 100%; border-collapse: separate; border-spacing: 0; }
.lines th { font-size: .76rem; font-weight: 700; color: #fff; background: var(--ink); padding: .5rem .45rem; }
.lines th:first-child { border-top-left-radius: 8px; }
.lines th:last-child { border-top-right-radius: 8px; }
.lines td { padding: .4rem .3rem; border-bottom: 1px solid #eef0f5; vertical-align: top; }
.lines .form-control, .lines .form-select { font-size: .86rem; padding: .32rem .45rem; }
.lines textarea.form-control { resize: vertical; min-height: 36px; }
.lines .amt { padding-top: .6rem; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lines .rm { color: #a3a7bb; border: 0; background: none; padding: .4rem; }
.lines .rm:hover { color: var(--overdue); }
.totals-stack { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-variant-numeric: tabular-nums; }
.totals-stack .t-row { display: flex; justify-content: space-between; padding: .42rem .85rem; font-size: .9rem; }
.totals-stack .t-row span:first-child { color: var(--muted); }
.totals-stack .t-grand { background: var(--primary); color: #fff; font-weight: 800; font-size: 1.15rem; padding: .7rem .85rem; }
.totals-stack .t-grand span:first-child { color: #e0e1ff; }
.words { font-size: .82rem; color: var(--muted); margin-top: .5rem; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(245, 246, 250, .92); backdrop-filter: blur(6px); border-top: 1px solid var(--line); padding: .75rem 0; margin-top: 1rem; display: flex; gap: .5rem; justify-content: flex-end; z-index: 5; }

/* ---------- document view ---------- */
.doc-frame { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.facts dt { font-size: .8rem; color: var(--muted); font-weight: 600; }
.facts dd { overflow-wrap: anywhere; font-weight: 700; margin-bottom: .55rem; font-variant-numeric: tabular-nums; }
.balance-box { border-radius: 8px; padding: .9rem 1rem; background: var(--due-soft); color: var(--due); }
.balance-box.settled { background: var(--settled-soft); color: var(--settled); }
.balance-box.overdue { background: var(--overdue-soft); color: var(--overdue); }
.balance-box .big { font-size: 1.55rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: var(--ink); color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art::after { content: ""; position: absolute; right: -120px; bottom: -120px; width: 360px; height: 360px; border-radius: 50%; background: var(--brand-gradient); opacity: .9; filter: blur(2px); }
.login-art .ticket { position: relative; z-index: 1; background: #fff; color: var(--text); border-radius: 12px; width: 330px; padding: 1.1rem 1.2rem; box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .6); font-variant-numeric: tabular-nums; transform: rotate(-2deg); }
.login-art .ticket .r { display: flex; justify-content: space-between; font-size: .85rem; padding: .2rem 0; }
.login-art .ticket .tot { border-top: 2px solid var(--ink); margin-top: .4rem; padding-top: .45rem; font-weight: 800; font-size: 1.05rem; }
.login-form { display: grid; place-items: center; padding: 2rem; }
.login-form form { width: 100%; max-width: 360px; }

.toast-zone { position: fixed; right: 1rem; bottom: 1rem; z-index: 2000; display: flex; flex-direction: column; gap: .5rem; }
.toast-msg { background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 8px; font-weight: 600; box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .4); max-width: 380px; }
.toast-msg.error { background: var(--overdue); }

.form-label { font-weight: 600; font-size: .84rem; margin-bottom: .25rem; }
.form-text { font-size: .78rem; }
.section-gap { margin-top: 1.25rem; }

@media (max-width: 991.98px) {
    .sidebar { position: fixed; left: 0; top: 0; z-index: 1050; transform: translateX(-100%); transition: transform .2s ease; }
    .sidebar.open { transform: none; }
    .topbar { display: flex; align-items: center; gap: .75rem; padding: .7rem 1rem; background: var(--ink); color: #fff; font-weight: 800; position: sticky; top: 0; z-index: 1000; }
    .topbar button { background: none; border: 0; color: #fff; font-size: 1.4rem; }
    .content { padding: 1rem 1rem 3rem; }
    .ledger { grid-template-columns: 1fr 1fr; }
    .ledger > div { border-bottom: 1px solid var(--line); }
    .sheet-head { grid-template-columns: 1fr; }
    .sheet-body, .sheet-head { padding-left: 1rem; padding-right: 1rem; }
    .login-wrap { grid-template-columns: 1fr; }
    .login-art { display: none; }
    .lines thead { display: none; }
    .lines tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .3rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
    .lines td { border: 0; padding: 0; }
    .lines td.c-desc { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print { .sidebar, .topbar, .sticky-actions, .no-print { display: none !important; } }
