:root { --bg:#f5f6f8; --panel:#fff; --ink:#111827; --muted:#6b7280; --line:#e5e7eb; --brand:#2563eb; --brand-ink:#fff; --danger:#dc2626; --ok:#16a34a; --warn:#d97706; --r:8px; }
* { box-sizing:border-box; }
html, body { margin:0; background:var(--bg); color:var(--ink); font:14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color:var(--brand); }
h1, h2, h3 { margin:0 0 12px; line-height:1.2; } h1 { font-size:22px; } h2 { font-size:17px; } h3 { font-size:14px; }
.muted { color:var(--muted); } .small { font-size:12px; }
.hidden { display:none !important; }

/* buttons & inputs */
.btn { display:inline-flex; align-items:center; gap:6px; border:1px solid var(--line); background:#fff; color:var(--ink); padding:7px 12px; border-radius:6px; font:inherit; font-weight:500; cursor:pointer; text-decoration:none; white-space:nowrap; }
.btn:hover { background:#f9fafb; }
.btn.primary { background:var(--brand); border-color:var(--brand); color:#fff; } .btn.primary:hover { filter:brightness(1.07); }
.btn.danger { color:var(--danger); } .btn.danger.solid { background:var(--danger); color:#fff; border-color:var(--danger); }
.btn.ghost { border-color:transparent; background:none; }
.btn.sm { padding:4px 8px; font-size:12.5px; }
.btn.icon { padding:4px 7px; }
input, select, textarea { font:inherit; color:inherit; border:1px solid #d1d5db; border-radius:6px; padding:7px 9px; background:#fff; width:100%; }
textarea { resize:vertical; min-height:60px; }
input:focus, select:focus, textarea:focus { outline:2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color:var(--brand); }
input[type=checkbox] { width:auto; } input[type=color] { padding:2px; height:34px; width:56px; }
.fld { display:block; margin-bottom:10px; } .fld > span { display:block; font-size:12px; font-weight:600; color:#374151; margin-bottom:3px; }
.chk { display:flex; align-items:center; gap:8px; margin-bottom:10px; }
.grid2 { display:grid; grid-template-columns:1fr 1fr; gap:0 12px; } .grid3 { display:grid; grid-template-columns:repeat(3,1fr); gap:0 12px; }
.row { display:flex; gap:8px; align-items:center; flex-wrap:wrap; } .row-end { display:flex; gap:8px; justify-content:flex-end; margin-top:12px; flex-wrap:wrap; }
.spacer { flex:1; }

/* auth */
.auth { min-height:100vh; display:grid; place-items:center; padding:20px; }
.auth-card { background:#fff; border:1px solid var(--line); border-radius:12px; padding:32px; width:100%; max-width:380px; box-shadow:0 10px 30px rgba(0,0,0,.05); }
.auth-card .brand { display:flex; gap:10px; align-items:center; font-weight:700; font-size:18px; margin-bottom:18px; }
.auth-card .brand img { width:32px; }
.err { color:var(--danger); min-height:20px; margin:6px 0; font-size:13px; }

/* shell */
.shell { display:grid; grid-template-columns:220px 1fr; min-height:100vh; }
.side { background:#0f172a; color:#cbd5e1; padding:18px 12px; display:flex; flex-direction:column; gap:2px; position:sticky; top:0; height:100vh; }
.side .brand { display:flex; gap:10px; align-items:center; color:#fff; font-weight:700; padding:0 8px 18px; }
.side .brand img { width:28px; }
.side a { color:#cbd5e1; text-decoration:none; padding:8px 10px; border-radius:6px; display:flex; gap:10px; align-items:center; }
.side a:hover { background:#1e293b; color:#fff; } .side a.on { background:#1e293b; color:#fff; font-weight:600; }
.side .bottom { margin-top:auto; font-size:12px; padding:8px 10px; } .side .bottom button { color:#94a3b8; background:none; border:0; padding:0; cursor:pointer; font:inherit; text-decoration:underline; }
.main { padding:24px 28px; min-width:0; }
.top { display:flex; align-items:center; gap:10px; margin-bottom:18px; flex-wrap:wrap; } .top h1 { margin:0; }

/* cards / tables */
.cards { display:grid; grid-template-columns:repeat(auto-fit,minmax(170px,1fr)); gap:12px; margin-bottom:18px; }
.card { background:#fff; border:1px solid var(--line); border-radius:var(--r); padding:14px 16px; }
.card .k { font-size:12px; color:var(--muted); } .card .v { font-size:20px; font-weight:700; margin-top:2px; }
.panel { background:#fff; border:1px solid var(--line); border-radius:var(--r); padding:16px; margin-bottom:14px; }
.panel > h3 { display:flex; align-items:center; gap:8px; }
.tabs { display:flex; gap:4px; border-bottom:1px solid var(--line); margin-bottom:12px; overflow-x:auto; }
.tabs button { background:none; border:0; padding:8px 12px; font:inherit; color:var(--muted); cursor:pointer; border-bottom:2px solid transparent; white-space:nowrap; }
.tabs button.on { color:var(--ink); border-color:var(--brand); font-weight:600; }
.tbl { width:100%; border-collapse:collapse; background:#fff; border:1px solid var(--line); border-radius:var(--r); overflow:hidden; }
.tbl th { text-align:left; font-size:12px; color:var(--muted); font-weight:600; padding:9px 12px; background:#f9fafb; border-bottom:1px solid var(--line); }
.tbl td { padding:10px 12px; border-bottom:1px solid var(--line); }
.tbl tr:last-child td { border-bottom:0; }
.tbl tr.click { cursor:pointer; } .tbl tr.click:hover td { background:#f9fafb; }
.tbl .n { text-align:right; white-space:nowrap; }
.empty { text-align:center; padding:40px; color:var(--muted); background:#fff; border:1px dashed #d1d5db; border-radius:var(--r); }
.badge { display:inline-block; padding:2px 8px; border-radius:999px; font-size:12px; font-weight:600; background:#f3f4f6; color:#374151; }
.s-paid, .s-approved, .s-converted { background:#dcfce7; color:#166534; } .s-overdue, .s-declined { background:#fee2e2; color:#991b1b; }
.s-partial { background:#fef3c7; color:#92400e; } .s-sent { background:#dbeafe; color:#1e40af; } .s-pending { background:#ede9fe; color:#5b21b6; }
.eye { color:var(--muted); font-size:12px; }

/* editor */
.editor { display:grid; grid-template-columns:minmax(380px,520px) 1fr; gap:20px; align-items:start; }
.editor .form { min-width:0; }
.preview { position:sticky; top:16px; min-width:0; }
.preview .paper { max-height:calc(100vh - 110px); overflow:auto; }
.paper { background:#fff; box-shadow:0 2px 14px rgba(0,0,0,.08); border-radius:4px; }
.line-it { border:1px solid var(--line); border-radius:6px; padding:10px; margin-bottom:8px; background:#fcfcfd; }
.line-it .lt { display:grid; grid-template-columns:1fr auto; gap:8px; }
.line-it .nums { display:grid; grid-template-columns:1fr .7fr .7fr .7fr; gap:8px; margin-top:6px; }
.line-it .nums .fld { margin:0; } .line-it .amt { text-align:right; font-weight:600; margin-top:6px; }
.thumbs { display:flex; gap:8px; flex-wrap:wrap; }
.thumbs .th { width:110px; } .thumbs img { width:110px; height:80px; object-fit:cover; border-radius:4px; border:1px solid var(--line); display:block; }
.sig-prev { height:60px; max-width:220px; object-fit:contain; border:1px dashed #d1d5db; border-radius:4px; background:#fff; display:block; margin-bottom:6px; }
.logo-prev { max-height:60px; max-width:200px; display:block; margin-bottom:6px; }
.saving { font-size:12px; color:var(--muted); }
.toggle-prev { display:none; }
.acts { display:flex; gap:6px; flex-wrap:wrap; }
.hist { font-size:12.5px; } .hist li { margin-bottom:3px; }
.swatches { display:flex; gap:6px; align-items:center; flex-wrap:wrap; } .swatches button { width:24px; height:24px; border-radius:50%; border:2px solid #fff; box-shadow:0 0 0 1px #d1d5db; cursor:pointer; }
.tpl-pick { display:grid; grid-template-columns:repeat(4,1fr); gap:8px; margin-bottom:10px; }
.tpl-pick button { border:1px solid var(--line); background:#fff; border-radius:6px; padding:8px 4px; cursor:pointer; font:inherit; font-size:12px; }
.tpl-pick button.on { border-color:var(--brand); box-shadow:0 0 0 2px color-mix(in srgb, var(--brand) 25%, transparent); font-weight:600; }
.bar-chart { display:flex; align-items:flex-end; gap:6px; height:160px; padding:8px 0; }
.bar-chart .b { flex:1; display:flex; flex-direction:column; align-items:center; gap:4px; height:100%; justify-content:flex-end; font-size:11px; color:var(--muted); }
.bar-chart .b .bars { display:flex; gap:2px; align-items:flex-end; height:100%; width:100%; justify-content:center; }
.bar-chart .b i { display:block; width:40%; max-width:18px; border-radius:3px 3px 0 0; background:#cbd5e1; min-height:1px; }
.bar-chart .b i.c { background:var(--brand); }
.legend { display:flex; gap:14px; font-size:12px; color:var(--muted); } .legend span::before { content:""; display:inline-block; width:10px; height:10px; border-radius:2px; margin-right:5px; background:#cbd5e1; vertical-align:-1px; } .legend span.c::before { background:var(--brand); }

/* modal & toast */
.overlay { position:fixed; inset:0; background:rgba(15,23,42,.45); display:grid; place-items:center; padding:16px; z-index:50; }
.modal { background:#fff; border-radius:12px; padding:22px; width:100%; max-width:520px; max-height:calc(100vh - 32px); overflow:auto; box-shadow:0 20px 50px rgba(0,0,0,.2); }
.sigpad { width:100%; height:160px; border:1px dashed #9ca3af; border-radius:6px; background:#fff; display:block; }
.toast { position:fixed; bottom:20px; left:50%; transform:translateX(-50%); background:#111827; color:#fff; padding:10px 16px; border-radius:8px; z-index:60; font-size:13px; }

/* client view */
body.viewer { background:#eef0f3; }
.view-bar { position:sticky; top:0; z-index:5; background:#fff; border-bottom:1px solid var(--line); padding:10px 20px; display:flex; align-items:center; gap:12px; flex-wrap:wrap; }
.vb-info { flex:1; min-width:200px; } .vb-biz { font-weight:700; }
.vb-act { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.view-wrap { max-width:860px; margin:24px auto; padding:0 12px; }

@media (max-width:1100px) {
  .editor { grid-template-columns:1fr; }
  .preview { position:static; } .preview .paper { max-height:none; }
  .toggle-prev { display:inline-flex; }
  .editor.form-mode .preview { display:none; } .editor.prev-mode .form { display:none; }
}
@media (max-width:760px) {
  .shell { grid-template-columns:1fr; grid-template-rows:auto 1fr; }
  .side > * { flex-shrink:0; }
  .side { position:sticky; height:auto; flex-direction:row; overflow-x:auto; padding:8px; gap:2px; z-index:10; }
  .side .brand { padding:0 8px 0 4px; } .side .brand span { display:none; }
  .side a { padding:6px 9px; font-size:13px; } .side .bottom { margin:0 0 0 auto; display:flex; align-items:center; }
  .side .bottom .who { display:none; }
  .main { padding:14px; }
  .grid3 { grid-template-columns:1fr 1fr; }
  .hide-sm { display:none; }
  .line-it .nums { grid-template-columns:1fr 1fr; }
  .cards { grid-template-columns:1fr 1fr; gap:8px; } .card { padding:10px 12px; } .card .v { font-size:17px; }
  .tbl { display:block; overflow-x:auto; white-space:nowrap; }
  .tabs { flex:1 1 100% !important; } #q { max-width:none !important; }
  .top h1 { font-size:19px; } .grid2 { grid-template-columns:1fr; }
}
@media print {
  body, body.viewer { background:#fff; }
  .no-print, .side, .top, .form, .view-bar { display:none !important; }
  .view-wrap { margin:0; max-width:none; padding:0; }
  .paper { box-shadow:none; }
  @page { margin:14mm; }
}
