/* =========================================================
   SpressX Invoice Studio — design system
   Brand: Cream #f0e8d9 · Sage #7e8967 · Forest #2e3934
   ========================================================= */
:root {
  --cream: #f0e8d9;
  --cream-2: #e8dfcc;
  --cream-3: #ddd2bb;
  --paper: #fbf8f2;
  --sage: #7e8967;
  --sage-2: #6c7657;
  --sage-soft: #e3e3d2;
  --forest: #2e3934;
  --forest-2: #242e2a;
  --forest-3: #3a4741;
  --ink: #2e3934;
  --ink-2: #56625c;
  --ink-3: #87908a;
  --line: rgba(46, 57, 52, 0.12);
  --line-2: rgba(46, 57, 52, 0.2);
  --danger: #a5523f;
  --danger-soft: #f3dfd6;
  --warn: #b08a3e;
  --warn-soft: #f4ead2;
  --ok: #5f7a4f;
  --ok-soft: #e2e8d6;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(46,57,52,.05), 0 8px 24px -12px rgba(46,57,52,.18);
  --shadow-lg: 0 30px 60px -20px rgba(46,57,52,.35);
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Manrope', system-ui, -apple-system, Segoe UI, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--cream);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1, h2 { font-family: var(--serif); }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { fill: currentColor; }
.muted { color: var(--ink-2); margin: 0; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--forest);
  color: var(--cream);
  padding: 24px 18px;
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh; align-self: start;
  background-image:
    radial-gradient(600px 300px at -20% 110%, rgba(126,137,103,.35), transparent 60%),
    radial-gradient(300px 200px at 120% -10%, rgba(240,232,217,.08), transparent 60%);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--cream); display: grid; place-items: center;
}
.brand-mark svg { width: 26px; height: 26px; }
.brand-mark path { stroke: var(--forest); stroke-width: 6; stroke-linecap: round; fill: none; }
.brand-mark circle { fill: var(--sage); }
.brand-name { font-family: var(--serif); font-size: 20px; font-weight: 700; line-height: 1; }
.brand-name span { color: var(--sage); font-style: italic; }
.brand-sub { font-size: 11px; letter-spacing: .18em; text-transform: uppercase; opacity: .6; margin-top: 4px; }

.client-chip {
  display: flex; gap: 12px; align-items: center;
  background: rgba(240,232,217,.06);
  border: 1px solid rgba(240,232,217,.1);
  border-radius: 14px; padding: 12px;
}
.client-logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--sage); color: var(--cream);
  display: grid; place-items: center;
  font-family: var(--serif); font-weight: 700; font-size: 18px;
}
.client-name { font-weight: 700; font-size: 14px; }
.client-plan { font-size: 11.5px; opacity: .6; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 11px;
  text-decoration: none; font-weight: 600; font-size: 14px;
  color: rgba(240,232,217,.72);
  transition: background .15s, color .15s;
}
.nav a svg { width: 19px; height: 19px; opacity: .85; }
.nav a:hover { background: rgba(240,232,217,.06); color: var(--cream); }
.nav a.active { background: var(--cream); color: var(--forest); }
.nav a.active svg { color: var(--sage); opacity: 1; }

.ai-status {
  margin-top: auto; display: flex; gap: 12px; align-items: center;
  padding: 14px; border-radius: 14px;
  background: linear-gradient(135deg, rgba(126,137,103,.35), rgba(126,137,103,.1));
  border: 1px solid rgba(126,137,103,.4);
}
.ai-status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); flex: none; }
.ai-status.on .dot { background: #b8c99a; box-shadow: 0 0 0 4px rgba(184,201,154,.2); animation: pulse 2s infinite; }
.ai-status.off .dot { background: #d38c74; }
.ai-status-title { font-weight: 700; font-size: 13px; }
.ai-status-sub { font-size: 11.5px; opacity: .7; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(184,201,154,0); } }

.main { min-width: 0; padding: 28px 36px 60px; }
.topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 26px; }
.topbar h1 { font-size: 30px; line-height: 1.15; }
.topbar-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.menu-btn { display: none; }

/* ---------- primitives ---------- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 22px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h3 { font-size: 15px; font-weight: 700; }
.card-head .spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 11px;
  border: 1px solid var(--line-2); background: var(--paper);
  font-weight: 700; font-size: 13.5px; cursor: pointer;
  transition: transform .08s, background .15s, border-color .15s, box-shadow .15s;
  white-space: nowrap; text-decoration: none;
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { border-color: var(--forest); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--forest); color: var(--cream); border-color: var(--forest); }
.btn-primary:hover { background: var(--forest-3); }
.btn-sage { background: var(--sage); color: #fff; border-color: var(--sage); }
.btn-sage:hover { background: var(--sage-2); border-color: var(--sage-2); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--cream-2); border-color: transparent; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 9px; }
.btn-danger:hover { color: var(--danger); border-color: var(--danger); }
.btn-ai {
  background: linear-gradient(135deg, var(--forest) 0%, #46564a 55%, var(--sage) 130%);
  color: var(--cream); border: none;
  box-shadow: inset 0 0 0 1px rgba(240,232,217,.12);
}
.btn-ai:hover { filter: brightness(1.08); }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 10px; border: 1px solid transparent; background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--cream-2); }
.icon-btn svg { width: 18px; height: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 12px;
  background: #fff; border: 1px solid var(--line-2); border-radius: 10px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 80px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--sage); box-shadow: 0 0 0 3px rgba(126,137,103,.2); }
.grid { display: grid; gap: 14px; }
.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)); }
.span2 { grid-column: span 2; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-paid { background: var(--ok-soft); color: var(--ok); }
.badge-pending { background: var(--warn-soft); color: var(--warn); }
.badge-overdue { background: var(--danger-soft); color: var(--danger); }
.badge-draft { background: var(--cream-2); color: var(--ink-2); }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--cream-2); color: var(--ink-2); }

.ai-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10.5px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: var(--sage-2); background: var(--sage-soft);
  padding: 4px 9px; border-radius: 999px;
}
.ai-pill svg { width: 12px; height: 12px; }

/* ---------- dashboard ---------- */
.hero {
  position: relative; overflow: hidden;
  background: var(--forest); color: var(--cream);
  border-radius: 22px; padding: 30px 32px;
  display: grid; grid-template-columns: 1.3fr 1fr; gap: 28px; align-items: center;
  margin-bottom: 22px;
}
.hero::after {
  content: ''; position: absolute; right: -120px; top: -120px; width: 420px; height: 420px;
  border-radius: 50%; border: 1px solid rgba(240,232,217,.1);
  box-shadow: 0 0 0 60px rgba(240,232,217,.025), 0 0 0 120px rgba(240,232,217,.02);
  pointer-events: none;
}
.hero h2 { font-size: 34px; line-height: 1.1; font-weight: 600; }
.hero h2 em { color: #b8c99a; font-style: italic; }
.hero p { opacity: .72; margin: 10px 0 20px; max-width: 46ch; }
.hero .btn { border: none; }
.hero .btn-cream { background: var(--cream); color: var(--forest); }
.hero .btn-outline { background: transparent; color: var(--cream); box-shadow: inset 0 0 0 1px rgba(240,232,217,.3); }
.hero-stat { position: relative; z-index: 1; background: rgba(240,232,217,.06); border: 1px solid rgba(240,232,217,.12); border-radius: 18px; padding: 20px; }
.hero-stat .lbl { font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; opacity: .6; }
.hero-stat .val { font-family: var(--serif); font-size: 40px; font-weight: 600; margin: 6px 0 2px; }
.hero-stat .sub { font-size: 12.5px; opacity: .7; }
.spark { width: 100%; height: 56px; margin-top: 12px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 22px; }
.stat { padding: 18px 20px; }
.stat .lbl { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.stat .val { font-family: var(--serif); font-size: 26px; font-weight: 600; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--ink-3); }

.dash-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; }
.insight-list { display: flex; flex-direction: column; gap: 10px; }
.insight {
  display: grid; grid-template-columns: 34px 1fr; gap: 12px; padding: 13px;
  border-radius: 12px; background: #fff; border: 1px solid var(--line);
}
.insight .ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 16px; }
.insight.win .ico { background: var(--ok-soft); }
.insight.risk .ico { background: var(--danger-soft); }
.insight.idea .ico { background: var(--warn-soft); }
.insight h4 { font-size: 13.5px; font-weight: 700; }
.insight p { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.ai-headline { font-family: var(--serif); font-size: 18px; line-height: 1.35; margin-bottom: 14px; }
.next-action { margin-top: 12px; padding: 14px; border-radius: 12px; background: var(--forest); color: var(--cream); font-size: 13px; }
.next-action b { color: #b8c99a; display: block; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; margin-bottom: 4px; }
.empty { text-align: center; padding: 36px 16px; color: var(--ink-2); }
.empty .big { font-family: var(--serif); font-size: 20px; color: var(--ink); margin-bottom: 6px; }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 90px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 9px; border-radius: 99px; background: var(--cream-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--sage), var(--forest)); }
.bar-row .amt { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-3); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.tbl td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover { background: rgba(240,232,217,.5); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .strong { font-weight: 700; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 16px; border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 1; min-width: 200px; }
.search svg { position: absolute; left: 12px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--ink-3); }
.search .input { padding-left: 36px; }
.seg { display: inline-flex; background: var(--cream-2); padding: 3px; border-radius: 11px; }
.seg button { border: none; background: transparent; padding: 7px 12px; border-radius: 8px; font-weight: 700; font-size: 12.5px; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

/* ---------- editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.95fr); gap: 22px; align-items: start; }
.editor-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.preview-col { position: sticky; top: 20px; }
.preview-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.preview-head .lbl { font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); font-weight: 700; }
.preview-frame { border-radius: 18px; padding: 14px; background: var(--cream-2); border: 1px solid var(--line); max-height: calc(100vh - 80px); overflow: auto; }
.preview-scale { transform-origin: top left; }

.magic {
  background: linear-gradient(160deg, var(--forest) 0%, #34423b 60%, #4a5a48 100%);
  color: var(--cream); border-radius: 20px; padding: 20px; position: relative; overflow: hidden;
}
.magic::before {
  content: ''; position: absolute; inset: auto -60px -80px auto; width: 240px; height: 240px; border-radius: 50%;
  background: radial-gradient(circle, rgba(184,201,154,.35), transparent 70%);
}
.magic-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; position: relative; }
.magic-head h3 { font-family: var(--serif); font-size: 19px; font-weight: 600; }
.magic p.sub { opacity: .7; margin: 0 0 14px; font-size: 13px; position: relative; }
.magic textarea {
  width: 100%; min-height: 86px; resize: vertical; border-radius: 12px; padding: 12px 14px;
  background: rgba(240,232,217,.07); border: 1px solid rgba(240,232,217,.18); color: var(--cream); outline: none;
  position: relative;
}
.magic textarea::placeholder { color: rgba(240,232,217,.45); }
.magic textarea:focus { border-color: #b8c99a; }
.magic-actions { display: flex; gap: 8px; margin-top: 10px; position: relative; flex-wrap: wrap; }
.magic .btn-cream { background: var(--cream); color: var(--forest); border: none; }
.magic .btn-mic { background: rgba(240,232,217,.1); color: var(--cream); border: 1px solid rgba(240,232,217,.2); }
.magic .btn-mic.rec { background: #a5523f; border-color: #a5523f; animation: recpulse 1.2s infinite; }
@keyframes recpulse { 50% { box-shadow: 0 0 0 6px rgba(165,82,63,.25); } }
.magic .chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; position: relative; }
.magic .chip { font-size: 12px; padding: 5px 10px; border-radius: 999px; background: rgba(240,232,217,.08); border: 1px solid rgba(240,232,217,.14); cursor: pointer; color: rgba(240,232,217,.85); }
.magic .chip:hover { background: rgba(240,232,217,.16); }
.magic-result { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: rgba(184,201,154,.15); font-size: 13px; position: relative; }

.items { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px;
  display: grid; grid-template-columns: minmax(0, 2.2fr) 70px 110px 100px 36px; gap: 10px; align-items: end;
}
.item .full { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.item .line-total { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--ink-2); border-top: 1px dashed var(--line-2); padding-top: 10px; }
.item .line-total b { color: var(--ink); font-size: 14px; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; }

.upsell { border: 1px dashed var(--sage); background: rgba(126,137,103,.06); border-radius: 14px; padding: 14px; }
.upsell-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.upsell-item { display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.upsell-item .info { flex: 1; min-width: 0; }
.upsell-item .t { font-weight: 700; font-size: 13.5px; }
.upsell-item .r { font-size: 12.5px; color: var(--ink-2); }
.upsell-pitch { font-family: var(--serif); font-style: italic; font-size: 14px; color: var(--forest); margin-top: 10px; }

.totals-box { display: flex; flex-direction: column; gap: 8px; }
.totals-box .row { display: flex; justify-content: space-between; font-size: 13.5px; }
.totals-box .row.grand { font-family: var(--serif); font-size: 22px; font-weight: 600; padding-top: 10px; border-top: 1px solid var(--line); }

.audit-score { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.ring { width: 58px; height: 58px; flex: none; }
.audit-issue { display: flex; gap: 10px; padding: 9px 11px; border-radius: 10px; font-size: 13px; margin-bottom: 6px; }
.audit-issue.error { background: var(--danger-soft); color: #7a3a2b; }
.audit-issue.warning { background: var(--warn-soft); color: #7b5e22; }
.audit-issue.tip { background: var(--ok-soft); color: #44593a; }

.msg-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.msg-box { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; white-space: pre-wrap; font-size: 13.5px; min-height: 80px; }

/* ---------- invoice document ---------- */
.doc {
  width: 794px; min-height: 1123px; background: #fffdf9; color: var(--forest);
  font-family: var(--sans); font-size: 12.5px; position: relative; overflow: hidden;
  box-shadow: var(--shadow-lg); border-radius: 6px;
  display: flex; flex-direction: column;
}
.doc-band { background: var(--forest); color: var(--cream); padding: 40px 48px 34px; position: relative; overflow: hidden; }
.doc-band::after {
  content: ''; position: absolute; right: -80px; top: -110px; width: 320px; height: 320px; border-radius: 50%;
  border: 1px solid rgba(240,232,217,.12); box-shadow: 0 0 0 40px rgba(240,232,217,.03), 0 0 0 80px rgba(240,232,217,.02);
}
.doc-top { display: flex; justify-content: space-between; align-items: flex-start; position: relative; z-index: 1; }
.doc-logo { display: flex; align-items: center; gap: 12px; }
.doc-logo .mk { width: 46px; height: 46px; border-radius: 12px; background: var(--cream); color: var(--forest); display: grid; place-items: center; font-family: var(--serif); font-size: 24px; font-weight: 700; }
.doc-logo .nm { font-family: var(--serif); font-size: 24px; font-weight: 700; line-height: 1; }
.doc-logo .tg { font-size: 10px; letter-spacing: .22em; text-transform: uppercase; opacity: .6; margin-top: 5px; }
.doc-title { text-align: right; }
.doc-title .w { font-family: var(--serif); font-size: 38px; font-weight: 600; font-style: italic; line-height: 1; color: var(--cream); }
.doc-title .n { font-family: var(--mono); font-size: 12px; opacity: .75; margin-top: 8px; }
.doc-meta { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 30px; position: relative; z-index: 1; }
.doc-meta .k { font-size: 9.5px; letter-spacing: .18em; text-transform: uppercase; opacity: .55; }
.doc-meta .v { font-weight: 700; font-size: 13px; margin-top: 3px; }
.doc-body { padding: 30px 48px; flex: 1; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-bottom: 26px; }
.doc-parties .k { font-size: 9.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--sage); font-weight: 800; margin-bottom: 6px; }
.doc-parties .nm { font-family: var(--serif); font-size: 17px; font-weight: 600; margin-bottom: 2px; }
.doc-parties .ln { color: var(--ink-2); line-height: 1.55; }
.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th { text-align: left; font-size: 9.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); font-weight: 800; padding: 10px 8px; border-bottom: 1.5px solid var(--forest); }
.doc-table td { padding: 12px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.doc-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-table .pn { font-weight: 700; font-size: 13px; }
.doc-table .ps { color: var(--ink-3); font-size: 11px; margin-top: 2px; }
.doc-table .imei { font-family: var(--mono); font-size: 10.5px; color: var(--sage-2); margin-top: 3px; }
.doc-sum { display: grid; grid-template-columns: 1fr 280px; gap: 30px; margin-top: 22px; }
.doc-words { font-size: 11.5px; color: var(--ink-2); }
.doc-words b { display: block; font-size: 9.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--sage); margin-bottom: 4px; }
.doc-tot .r { display: flex; justify-content: space-between; padding: 6px 0; }
.doc-tot .r span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.doc-tot .g { margin-top: 8px; padding: 14px 16px; background: var(--forest); color: var(--cream); border-radius: 10px; display: flex; justify-content: space-between; align-items: center; }
.doc-tot .g span:first-child { font-size: 10px; letter-spacing: .18em; text-transform: uppercase; opacity: .7; }
.doc-tot .g span:last-child { font-family: var(--serif); font-size: 22px; font-weight: 600; }
.doc-note { margin-top: 26px; padding: 16px 18px; border-left: 3px solid var(--sage); background: #f6f1e7; border-radius: 0 10px 10px 0; font-family: var(--serif); font-style: italic; font-size: 13.5px; line-height: 1.5; }
.doc-extra { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-top: 22px; font-size: 11px; color: var(--ink-2); }
.doc-extra b { display: block; font-size: 9.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--sage); margin-bottom: 4px; }
.doc-stamp { position: absolute; right: 48px; top: 228px; transform: rotate(-10deg); border: 2.5px solid var(--sage); color: var(--sage); padding: 5px 14px; border-radius: 8px; font-weight: 800; letter-spacing: .2em; font-size: 15px; opacity: .85; }
.doc-stamp.pending { border-color: var(--warn); color: var(--warn); }
.doc-foot { padding: 18px 48px; background: var(--cream); display: flex; justify-content: space-between; align-items: center; font-size: 10.5px; color: var(--ink-2); }
.doc-foot .pw { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--forest); }
.doc-foot .pw i { font-style: italic; color: var(--sage); font-family: var(--serif); }

/* ---------- misc ---------- */
.toast-wrap { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--forest); color: var(--cream); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); font-weight: 600; font-size: 13.5px; animation: tin .25s ease; max-width: 360px; }
.toast.err { background: var(--danger); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }
.modal-backdrop { position: fixed; inset: 0; background: rgba(36,46,42,.55); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 90; padding: 16px; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--paper); border-radius: 20px; width: min(560px, 100%); max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-family: var(--serif); font-size: 19px; }
.modal-body { padding: 20px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.shimmer { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--cream-2), var(--cream), var(--cream-2)); background-size: 200% 100%; animation: sh 1.2s infinite; margin: 8px 0; }
@keyframes sh { to { background-position: -200% 0; } }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.cat-card { padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.cat-card .top { display: flex; justify-content: space-between; align-items: center; }
.cat-card .nm { font-weight: 800; font-size: 15px; }
.cat-card .vr { color: var(--ink-2); font-size: 12.5px; }
.cat-card .pr { font-family: var(--serif); font-size: 22px; font-weight: 600; margin-top: 6px; }
.cat-card .acts { display: flex; gap: 6px; margin-top: 8px; }
.phone-glyph { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--cream-2); color: var(--forest); }
.phone-glyph svg { width: 20px; height: 20px; }
#printRoot { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .preview-col { position: static; }
}
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .dash-grid, .hero { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 80; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .menu-btn { display: grid; }
  .main { padding: 18px 16px 50px; }
  .topbar { flex-wrap: wrap; }
  .topbar h1 { font-size: 24px; }
  .topbar-actions { width: 100%; justify-content: flex-start; }
  .g3, .g4 { grid-template-columns: 1fr 1fr; }
  .item { grid-template-columns: 1fr 1fr; }
  .item > :first-child { grid-column: 1 / -1; }
  .item .full { grid-template-columns: 1fr; }
  .hero { padding: 22px; }
  .hero h2 { font-size: 26px; }
}
@media (max-width: 520px) {
  .g2, .g3, .g4, .stats { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .bar-row { grid-template-columns: 90px 1fr 70px; }
}

/* ---------- print: only the invoice ---------- */
@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; }
  .app, .toast-wrap, .modal-backdrop { display: none !important; }
  #printRoot { display: block; }
  #printRoot .doc { box-shadow: none; border-radius: 0; width: 210mm; min-height: 296mm; overflow: visible; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* =========================================================
   v2: profit, P&L, customers & dues, Ask AI
   ========================================================= */
.pos { color: var(--ok); font-weight: 700; }
.neg { color: var(--danger); font-weight: 700; }
.int { font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; font-weight: 800; color: var(--sage-2); background: var(--sage-soft); padding: 1px 6px; border-radius: 5px; margin-left: 4px; vertical-align: 1px; }
.cost-input { background: #f7f5ee; border-style: dashed; }
.item .full { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.margin-chip { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 6px; }
.margin-chip.pos { background: var(--ok-soft); color: var(--ok); }
.margin-chip.neg { background: var(--danger-soft); color: var(--danger); }
.margin-chip.none { background: var(--cream-2); color: var(--ink-3); font-weight: 600; }
.profit-box { margin-top: 6px; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--ok-soft); color: var(--ok); font-size: 13px; }
.profit-box.neg { background: var(--danger-soft); color: var(--danger); }
.cost-row { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--ink-2); }
.cost-row .margin-chip { margin: 0; }
.margin-preview { font-size: 13px; color: var(--ink-2); padding: 10px 12px; background: var(--cream); border-radius: 10px; }
.margin-preview:empty { display: none; }
.stat-link { text-decoration: none; transition: border-color .15s, transform .15s; }
.stat-link:hover { border-color: var(--sage); transform: translateY(-1px); }

/* P&L */
.pl { display: flex; flex-direction: column; }
.pl-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 2px; border-bottom: 1px dashed var(--line); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.pl-row em { font-style: normal; color: var(--ink-3); font-size: 12px; }
.pl-row.sub { color: var(--ink-2); padding-left: 14px; }
.pl-row.total { font-weight: 800; border-bottom: 1px solid var(--line-2); background: linear-gradient(90deg, rgba(126,137,103,.08), transparent); }
.pl-net { margin-top: 12px; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-radius: 12px; background: var(--forest); color: var(--cream); font-weight: 700; }
.pl-net span:last-child { font-family: var(--serif); font-size: 24px; font-weight: 600; }
.pl-net .tag { background: rgba(240,232,217,.14); color: #cfdcb6; }
.pl-net.loss { background: #7a3a2b; }
.pl-foot { font-size: 11.5px; margin-top: 10px; }
#plSeg button { padding: 6px 10px; font-size: 12px; }
.bar-row-3 { grid-template-columns: 170px 1fr 90px; }
.bar-row-3 .name small { display: block; font-weight: 500; color: var(--ink-3); font-size: 11.5px; }

/* receivables */
.aging { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.aging-cell { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.aging-cell .al { font-size: 11.5px; color: var(--ink-2); font-weight: 600; }
.aging-cell .av { font-family: var(--serif); font-size: 19px; font-weight: 600; margin: 2px 0 8px; }
.aging-cell .ab { height: 6px; border-radius: 9px; background: var(--cream-2); overflow: hidden; }
.aging-cell .ab i { display: block; height: 100%; border-radius: 9px; }
.aging-cell .an { font-size: 11.5px; color: var(--ink-3); margin-top: 6px; }
.aging-cell.a0 .ab i { background: var(--sage); }
.aging-cell.a1 .ab i { background: var(--warn); }
.aging-cell.a2 .ab i { background: #c0704f; }
.aging-cell.a3 .ab i { background: var(--danger); }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.cbadge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.cbadge.loyal { background: var(--forest); color: var(--cream); }
.cbadge.instant { background: var(--ok-soft); color: var(--ok); }
.cbadge.ontime { background: var(--sage-soft); color: var(--sage-2); }
.cbadge.slow { background: var(--warn-soft); color: var(--warn); }
.cbadge.risk { background: var(--danger-soft); color: var(--danger); }
.cbadge.new { background: var(--cream-2); color: var(--ink-2); }
.fu { margin-top: 14px; }
.fu-h { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; font-weight: 800; color: var(--ink-3); margin-bottom: 8px; }
.fu-row { display: grid; grid-template-columns: 26px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 13px; }
.fu-n { width: 24px; height: 24px; border-radius: 50%; background: var(--forest); color: var(--cream); display: grid; place-items: center; font-weight: 800; font-size: 12px; }

/* Ask AI */
.toast-wrap { bottom: 88px; }
.chat-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 70;
  display: inline-flex; align-items: center; gap: 10px; height: 52px; padding: 0 20px 0 16px; border-radius: 999px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--forest) 0%, #46564a 60%, var(--sage) 140%); color: var(--cream); font-weight: 800; font-size: 14px;
  box-shadow: 0 14px 30px -10px rgba(46,57,52,.6), inset 0 0 0 1px rgba(240,232,217,.12);
  transition: transform .2s, opacity .2s;
}
.chat-fab svg { width: 20px; height: 20px; color: #cfdcb6; }
.chat-fab:hover { transform: translateY(-2px); }
.chat-fab.hide { opacity: 0; pointer-events: none; transform: translateY(10px); }
.chat-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 85;
  background: var(--paper); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; transform: translateX(105%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
}
.chat-drawer.open { transform: none; }
.chat-head { display: flex; align-items: center; gap: 6px; padding: 18px 16px 16px 20px; background: var(--forest); color: var(--cream); }
.chat-head > div { flex: 1; }
.chat-head .icon-btn { color: var(--cream); }
.chat-head .icon-btn:hover { background: rgba(240,232,217,.1); }
.chat-title { font-family: var(--serif); font-size: 20px; font-weight: 700; }
.chat-title i { color: #b8c99a; }
.chat-sub { font-size: 12px; opacity: .65; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.cm { max-width: 88%; padding: 11px 14px; border-radius: 16px; font-size: 13.5px; line-height: 1.55; }
.cm.user { align-self: flex-end; background: var(--forest); color: var(--cream); border-bottom-right-radius: 5px; }
.cm.assistant { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.cm p { margin: 0 0 6px; } .cm p:last-child { margin: 0; }
.cm ul { margin: 4px 0 6px; padding-left: 18px; } .cm li { margin: 2px 0; }
.cm b { color: var(--forest); }
.cm code { font-family: var(--mono); font-size: 12px; background: var(--cream); padding: 1px 4px; border-radius: 4px; }
.cm.typing { display: flex; gap: 5px; padding: 14px 16px; }
.cm.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--sage); animation: blink 1.2s infinite; }
.cm.typing span:nth-child(2) { animation-delay: .15s; } .cm.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.chat-empty { margin: auto 0; text-align: center; padding: 10px 20px; }
.chat-empty .big { font-family: var(--serif); font-size: 20px; margin: 12px 0 4px; }
.ce-mark { width: 52px; height: 52px; margin: 0 auto; border-radius: 16px; display: grid; place-items: center; background: var(--sage-soft); color: var(--sage-2); }
.ce-mark svg { width: 26px; height: 26px; }
.chat-sugg { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 18px 12px; }
.chat-sugg .chip { font-size: 12px; padding: 6px 11px; border-radius: 999px; background: #fff; border: 1px solid var(--line-2); cursor: pointer; font-weight: 600; color: var(--ink-2); }
.chat-sugg .chip:hover { border-color: var(--sage); color: var(--forest); }
.chat-form { display: flex; gap: 8px; padding: 14px 18px 18px; border-top: 1px solid var(--line); }
.chat-form .btn { width: 44px; padding: 0; }

@media (max-width: 1100px) { .aging { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .item .full { grid-template-columns: 1fr 1fr; }
  .bar-row-3 { grid-template-columns: 110px 1fr 80px; }
  .chat-fab span { display: none; }
  .chat-fab { width: 52px; padding: 0; justify-content: center; }
  .card-head .seg { overflow-x: auto; max-width: 100%; }
}
@media print { .chat-fab, .chat-drawer { display: none !important; } }

.dash-grid { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.dash-grid > * { min-width: 0; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: minmax(0, 1fr); } }
.tbl td.mono, .tbl .badge { white-space: nowrap; }
