:root {
  --ink: #1d1c19;
  --ink-2: #2a2925;
  --green: #8bb22d;
  --green-dark: #4f6b12;
  --lime: #d9e087;
  --bg: #f4f5f1;
  --card: #ffffff;
  --line: #e3e4dd;
  --muted: #5f5e57;
  --red: #b42318;
  --amber: #b54708;
  --blue: #175cd3;
  --radius: 14px;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--green-dark); text-decoration: none; font-weight: 600; }
a:hover { color: var(--ink); }
h1 { font-size: 26px; margin: 0; font-weight: 800; letter-spacing: -0.4px; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 800; }
h3 { font-size: 15px; margin: 18px 0 8px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; background: var(--ink); }
.main { background: var(--bg); }
.sidebar { background: var(--ink); color: #d6d6cf; padding: 18px 0 30px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 0 20px 18px; border-bottom: 1px solid #34332e; margin-bottom: 8px; }
.sidebar .brand img { width: 150px; display: block; }
.sidebar .brand small { display: block; color: var(--lime); letter-spacing: 2px; font-size: 10px; margin-top: 8px; text-transform: uppercase; }
.nav-group { padding: 14px 22px 6px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.4px; color: #9a998f; font-weight: 700; }
.sidebar a.nav { display: flex; align-items: center; gap: 11px; color: #e4e4dd; padding: 9px 22px; font-size: 13.5px; font-weight: 600; min-height: 40px; }
.sidebar a.nav:hover { background: #2a2925; color: #fff; }
.sidebar a.nav.active { background: #34332e; color: #fff; }
.sidebar a.nav svg { flex: none; opacity: .9; }
.main { min-width: 0; }
.topbar { background: #fff; border-bottom: 1px solid var(--line); padding: 10px 26px; display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 20; }
.topbar .spacer { flex: 1; }
.entity-switch { display: flex; align-items: center; gap: 8px; }
.entity-switch select { font-weight: 600; min-width: 240px; }
.entity-badge { background: var(--lime); color: var(--ink); font-weight: 700; font-size: 11px; padding: 3px 8px; border-radius: 20px; }
.user-chip { color: var(--muted); font-size: 13px; }
.menu-btn { display: none; }
.content { padding: 24px 26px 60px; max-width: 1400px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- controls ---------- */
button, .btn { font: inherit; border: 1px solid #d5d6ce; background: #fff; color: var(--ink); padding: 0 16px; min-height: 40px; border-radius: 10px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap; }
button:hover, .btn:hover { border-color: #c9c9bf; text-decoration: none; }
button.primary, .btn.primary { background: var(--green); border-color: var(--green); color: var(--ink); font-weight: 800; }
button.primary:hover, .btn.primary:hover { background: #9cc43a; color: var(--ink); }
button.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
button.danger { color: var(--red); }
button.link { border: 0; background: none; padding: 0 4px; min-height: 0; color: var(--green-dark); font-weight: 700; }
button.small, .btn.small { padding: 0 12px; min-height: 34px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; border: 1px solid #d5d6ce; border-radius: 8px; padding: 9px 11px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(139, 178, 45, .35); border-color: var(--green); }
textarea { resize: vertical; min-height: 38px; }
label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.grid { display: grid; gap: 12px 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: 13.5px; }
.check input { width: auto; }

/* ---------- cards & tables ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card .card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 150px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 11px 12px; border-bottom: 1px solid var(--line); background: #f7f8f4; white-space: nowrap; }
table.data td { padding: 12px 12px; border-bottom: 1px solid #efefe9; vertical-align: top; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: #f8f9f1; }
table.data tfoot td { font-weight: 700; background: #fafaf6; border-top: 2px solid var(--line); }
table.data tr.section td { background: #f3f4ea; font-weight: 700; }
table.data tr.subtotal td { font-weight: 700; border-top: 1px solid #d9d9cf; }
table.data tr.grand td { font-weight: 800; background: var(--ink); color: #fff; }
.num { text-align: right !important; white-space: nowrap; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.neg { color: var(--red); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 700; text-transform: capitalize; background: #eee; color: #444; }
.badge.draft { background: #ececec; color: #555; }
.badge.open, .badge.sent { background: #e1ebfc; color: #174ea6; }
.badge.partial { background: #fdedd3; color: #8a3b06; }
.badge.paid, .badge.accepted, .badge.invoiced, .badge.posted { background: #e6f0cf; color: #3d5410; }
.badge.overdue, .badge.void, .badge.declined { background: #fde3df; color: #a3200f; }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.kpi.lime { background: var(--lime); border-color: var(--lime); }
.kpi.lime .label, .kpi.lime .foot { color: #3d3c36; }
.kpi.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.kpi.dark .label { color: #c9c9bf; }
.kpi .label { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }
.kpi .value { font-size: 26px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .foot { font-size: 12px; margin-top: 4px; color: var(--muted); }
.kpi.dark .foot { color: var(--lime); }
.chart { width: 100%; height: 240px; }
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }

/* ---------- document editor ---------- */
table.lines-edit { width: 100%; border-collapse: collapse; }
table.lines-edit th { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.lines-edit td { padding: 6px 4px; vertical-align: top; border-bottom: 1px solid #f0f0ea; }
table.lines-edit input, table.lines-edit select, table.lines-edit textarea { padding: 6px 7px; font-size: 13px; }
table.lines-edit .amount { padding-top: 12px; font-weight: 600; text-align: right; white-space: nowrap; }
.totals-box { margin-left: auto; width: 340px; max-width: 100%; }
.totals-box div { display: flex; justify-content: space-between; padding: 5px 0; }
.totals-box .grand { border-top: 2px solid var(--ink); font-weight: 800; font-size: 16px; margin-top: 4px; padding-top: 8px; }
.dmc-box { background: #f4f6ea; border-radius: 12px; padding: 16px 16px 4px; margin: 4px 0 16px; }
.dmc-box .title { font-size: 11px; font-weight: 700; color: var(--green-dark); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }

.doc-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.doc-summary .item .label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.doc-summary .item .value { font-weight: 700; margin-top: 3px; }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 20, 16, .5); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 640px; max-width: 100%; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal.wide { width: 920px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toasts { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 200; max-width: 420px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }
.toast.error { background: #a3200f; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--ink); padding: 20px; }
.auth .box { background: #fff; border-radius: 14px; width: 400px; max-width: 100%; overflow: hidden; }
.auth .box .head { background: var(--ink); padding: 28px; text-align: center; border-bottom: 4px solid var(--green); }
.auth .box .head img { width: 220px; }
.auth .box form { padding: 24px 28px 28px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 11px 14px; color: var(--muted); font-weight: 700; border-bottom: 3px solid transparent; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--green); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.report-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.report-list a { display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; color: var(--ink); }
.report-list a:hover { border-color: var(--green); text-decoration: none; }
.report-list a strong { display: block; margin-bottom: 4px; }
.report-list a span { color: var(--muted); font-size: 13px; }
.notice { background: #fff8e6; border: 1px solid #f6d58a; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; color: #6b4c00; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
  .report-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; width: 240px; z-index: 50; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .entity-switch select { min-width: 0; }
  .g2, .g3, .g4, .g6, .doc-summary, .report-list, .kpis { grid-template-columns: 1fr; }
  table.data td, table.data th { white-space: nowrap; }
  .shell { background: var(--bg); }
  .span2, .span3 { grid-column: auto; }
}
@media print {
  .sidebar, .topbar, .actions, .filters, .no-print { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; }
  .card { border: 0; padding: 0; }
  body { background: #fff; }
}
