:root {
  --brand: #1f4fd8;
  --brand-ink: #1739a6;
  --brand-soft: #eaf0ff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --bg: #f5f7fb;
  --card: #ffffff;
  --ok: #059669;
  --ok-soft: #e7f8f1;
  --warn: #b45309;
  --warn-soft: #fff6e5;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --gold: #b7791f;
  --gold-soft: #fff7e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 16px rgba(15, 23, 42, 0.06);
  --sidebar: 248px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', Arial, sans-serif;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; } h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
p { margin: 0 0 .75em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; }

/* ------------------------------ Buttons ------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-2);
  background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn:focus-visible, .input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 1px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.danger { color: var(--bad); border-color: #f3c4c4; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef2f7; }
.btn.gold { background: linear-gradient(135deg, #f6c453, #e3a008); border-color: #d99a06; color: #3b2a00; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.lg { height: 44px; padding: 0 20px; font-size: 15px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ------------------------------- Forms ------------------------------- */
label { display: block; font-weight: 600; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px; }
.input, select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 8px;
  font: inherit; color: var(--ink); background: #fff;
}
textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; }
.input[readonly] { background: #f8fafc; }
.field { margin-bottom: 12px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.grid { display: grid; gap: 12px; }
.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; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 0 12px; height: 32px; font: inherit; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--brand); color: #fff; }

/* ------------------------------- Layout ------------------------------ */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex-shrink: 0; background: #0f1b3d; color: #cfd8f3; position: fixed; inset: 0 auto 0 0;
  display: flex; flex-direction: column; z-index: 40; transition: transform .2s;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; color: #fff; font-weight: 800; font-size: 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #4f7dff, #1f4fd8); display: grid; place-items: center; color: #fff; font-weight: 900; }
.biz-switch {
  margin: 0 12px 8px; padding: 8px 10px; border-radius: 8px; background: rgba(255,255,255,.06); color: #fff; cursor: pointer;
  display: flex; align-items: center; gap: 8px; border: 1px solid rgba(255,255,255,.08); width: calc(100% - 24px); font: inherit; text-align: left;
}
.biz-switch img, .biz-switch .ph { width: 28px; height: 28px; border-radius: 6px; object-fit: contain; background: #fff; flex-shrink: 0; }
.biz-switch .ph { display: grid; place-items: center; color: var(--brand); font-weight: 800; }
.biz-switch .nm { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.biz-switch .pl { font-size: 11px; color: #9fb0e0; }
.nav { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.nav .sec { font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #6f80b3; padding: 12px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; color: #cfd8f3; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.on { background: rgba(79,125,255,.22); color: #fff; }
.nav a .ico { width: 18px; text-align: center; opacity: .9; }
.nav a .lock { margin-left: auto; font-size: 10px; background: var(--gold-soft); color: var(--gold); border-radius: 4px; padding: 0 5px; font-weight: 700; }
.nav-cta { margin: 8px 12px 14px; }
.nav-cta .btn { width: 100%; }
.main { margin-left: var(--sidebar); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 20px; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar .burger { display: none; }
.topbar .title { font-weight: 700; font-size: 15px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.content { padding: 20px; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head .btn-row { margin-left: auto; }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; display: flow-root; line-height: 1.6; }
.banner.info { background: var(--brand-soft); color: #1e3a8a; }
.banner.warn { background: var(--warn-soft); color: #7c4a03; }
.banner.gold { background: var(--gold-soft); color: #6b4a0b; border: 1px solid #f5dfa6; }
.banner .btn { float: right; margin: -3px 0 -3px 12px; }

/* ------------------------------- Cards ------------------------------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-b { padding: 16px; }
.card-h { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card-h h2, .card-h h3 { margin: 0; }
.stack > * + * { margin-top: 16px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .lbl { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi .val { font-size: 22px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi .up { color: var(--ok); } .kpi .down { color: var(--bad); }
.cols { display: grid; gap: 16px; grid-template-columns: 2fr 1fr; }
.cols.even { grid-template-columns: 1fr 1fr; }
.cols > *, .grid > * { min-width: 0; }

/* ------------------------------- Tables ------------------------------ */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th, .t td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.t th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: #f8fafc; white-space: nowrap; }
.t td.num, .t th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t tr.click { cursor: pointer; }
.t tr.click:hover td { background: #f8fafc; }
.t tfoot td { font-weight: 700; background: #f8fafc; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 6px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.filters .input, .filters select { width: auto; min-width: 140px; }
.filters .search { flex: 1; min-width: 200px; }

/* ------------------------------- Badges ------------------------------ */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: #eef2f7; color: var(--ink-2); text-transform: capitalize; white-space: nowrap; }
.badge.paid, .badge.approved, .badge.accepted, .badge.converted, .badge.live, .badge.active, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.partial, .badge.pending, .badge.contacted, .badge.in_progress, .badge.open, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.unpaid, .badge.overdue, .badge.cancelled, .badge.rejected, .badge.declined, .badge.suspended, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.new, .badge.issued, .badge.info { background: var(--brand-soft); color: var(--brand); }
.badge.premium { background: var(--gold-soft); color: var(--gold); }

/* ------------------------------ Modal/toast ----------------------------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 100; display: grid; place-items: center; padding: 16px; animation: fade .12s; }
.modal { background: #fff; border-radius: 12px; width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(860px, 100%); }
.modal-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-h h3 { margin: 0; font-size: 16px; }
.modal-h .x { margin-left: auto; }
.modal-b { padding: 16px 18px; overflow-y: auto; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-weight: 500; animation: fade .15s; max-width: 90vw; }
.toast.bad { background: var(--bad); }
.toast.ok { background: #065f46; }

/* ----------------------------- Doc editor ----------------------------- */
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 6px 4px; letter-spacing: .03em; white-space: nowrap; }
.lines td { padding: 4px; vertical-align: top; }
.lines .input, .lines select { height: 34px; padding: 0 7px; }
.lines td.amt { text-align: right; padding-top: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lines .rm { color: var(--muted); border: 0; background: none; cursor: pointer; font-size: 18px; padding: 6px; }
.lines .rm:hover { color: var(--bad); }
.ac { position: relative; }
.ac-list { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line-2); border-radius: 8px; box-shadow: var(--shadow); max-height: 260px; overflow-y: auto; min-width: 260px; }
.ac-list div { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.ac-list div:hover, .ac-list div.on { background: var(--brand-soft); }
.ac-list .s { font-size: 12px; color: var(--muted); }
.totals { width: 100%; }
.totals td { padding: 4px 0; }
.totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.totals tr.grand td { font-size: 18px; font-weight: 800; border-top: 2px solid var(--ink); padding-top: 8px; }

/* --------------------------- Plan / pricing --------------------------- */
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.plan { padding: 22px; position: relative; display: flex; flex-direction: column; }
.plan.featured { border: 2px solid var(--brand); }
.plan .ribbon { position: absolute; top: -11px; right: 16px; background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 10px; border-radius: 999px; }
.plan .price { font-size: 30px; font-weight: 800; margin: 6px 0 2px; }
.plan .price small { font-size: 14px; color: var(--muted); font-weight: 600; }
.plan ul { list-style: none; padding: 0; margin: 14px 0; flex: 1; }
.plan li { padding: 4px 0 4px 24px; position: relative; }
.plan li::before { content: '✓'; position: absolute; left: 0; color: var(--ok); font-weight: 800; }
.plan li.no { color: #94a3b8; }
.plan li.no::before { content: '–'; color: #cbd5e1; }
.meter { height: 8px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.meter i.hot { background: var(--bad); }

/* ------------------------------- Charts ------------------------------- */
.chart { width: 100%; height: 220px; }
.chart text { font-size: 10.5px; fill: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* ------------------------------- Tabs -------------------------------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); }

/* ------------------------------- Guide -------------------------------- */
.guide { display: grid; grid-template-columns: 240px 1fr; gap: 20px; align-items: start; }
.guide nav { position: sticky; top: 72px; }
.guide nav a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--ink-2); font-weight: 500; }
.guide nav a:hover { background: #eef2f7; text-decoration: none; }
.guide article h2 { margin-top: 8px; scroll-margin-top: 72px; }
.guide article section { padding-bottom: 18px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.guide ol, .guide ul { padding-left: 20px; margin: 0 0 10px; }
.guide li { margin-bottom: 5px; }
.tip { background: var(--brand-soft); border-left: 3px solid var(--brand); padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f1f5f9; }
.checklist .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-2); display: grid; place-items: center; flex-shrink: 0; font-size: 12px; }
.checklist li.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.checklist li.done span { color: var(--muted); text-decoration: line-through; }

/* ---------------------------- Responsive ---------------------------- */
@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols, .cols.even { grid-template-columns: 1fr; }
  .guide { grid-template-columns: 1fr; }
  .guide nav { position: static; display: flex; flex-wrap: wrap; }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  body.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .main { margin-left: 0; }
  .topbar .burger { display: inline-flex; }
  .content { padding: 14px; }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .kpi .val { font-size: 18px; }
  .page-head .btn-row { margin-left: 0; }
  .hide-sm { display: none; }
}

/* ------------------------------- Print -------------------------------- */
@media print {
  @page { margin: 10mm; }
  body { background: #fff; }
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; left: 0; top: 0; width: 100%; }
  .no-print { display: none !important; }
}

/* ----------------------------- Feedback FAB ----------------------------- */
.fb-fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 50; border: 0; cursor: pointer;
  background: #0f1b3d; color: #fff; font: inherit; font-weight: 700; padding: 10px 16px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(15, 27, 61, .35);
}
.fb-fab:hover { background: var(--brand); }
@media print { .fb-fab { display: none; } }
@media (max-width: 560px) { .fb-fab { padding: 10px 12px; font-size: 13px; right: 12px; bottom: 12px; } }

.ai-box { background: #f8faff; border: 1px solid #d6e0ff; border-radius: 10px; padding: 12px; }
.ai-box textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: #fff; }
