:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1d2433; --muted: #6b7385; --line: #dfe2e8;
  --accent: #1f5fae; --accent-ink: #fff; --ok: #1e7a46; --warn: #a15c00; --bad: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171d; --panel: #1c2028; --ink: #e6e8ec; --muted: #9aa1ad; --line: #2c323d;
          --accent: #5b9bea; --accent-ink: #0d1117; --ok: #4cc283; --warn: #e5a54a; --bad: #f2786d; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
header { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header .wrap { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; padding: 8px 16px; }
header .brand { font-weight: 700; margin-right: 12px; letter-spacing: .2px; }
header nav a { padding: 6px 10px; border-radius: 6px; color: var(--ink); }
header nav a.on, header nav a:hover { background: var(--bg); }
.wrap { max-width: 1180px; margin: 0 auto; }
main.wrap { padding: 16px; }
h1 { font-size: 20px; margin: 4px 0 14px; }
h2 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.chk { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
textarea { min-height: 54px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 12px; border-radius: 6px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); }
table.list th, table.list td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); }
table.list tr:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; border: 1px solid currentColor; }
.badge.paid { color: var(--ok); } .badge.unpaid { color: var(--warn); } .badge.cancelled { color: var(--bad); text-decoration: line-through; }
.t-credit { color: var(--bad); } .t-debit { color: var(--warn); } .t-proforma { color: var(--muted); }
.flash { padding: 9px 12px; border-radius: 8px; margin-bottom: 10px; border: 1px solid; }
.flash.ok { color: var(--ok); } .flash.error { color: var(--bad); }
.muted { color: var(--muted); }
.lines td { padding: 4px; } .lines input { width: 100%; }
.lines .c-name { min-width: 220px; } .lines .c-s { width: 80px; } .lines .c-m { width: 110px; }
.totals { margin-left: auto; min-width: 280px; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { font-weight: 700; font-size: 16px; border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sumbar { display: flex; gap: 22px; justify-content: flex-end; padding: 10px 4px; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { main.wrap { padding: 10px; } .totals { min-width: 100%; } }

/* v2 */
.hdr-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.co-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher select { max-width: 230px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line); }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 4px); background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  min-width: 200px; padding: 6px; display: flex; flex-direction: column; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 10; }
.menu-pop a, .menu-pop button { padding: 7px 10px; border-radius: 6px; color: var(--ink); text-align: left; background: none; border: 0; font: inherit; cursor: pointer; width: 100%; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--bg); }
.auth { max-width: 460px; margin: 6vh auto; }
.auth.wide { max-width: 760px; }
.auth h1 { text-align: center; }
.inline-btn { display: flex; gap: 6px; } .inline-btn input { flex: 1; }
.eik-status { font-size: 12px; min-height: 16px; }
.eik-status.ok { color: var(--ok); } .eik-status.bad { color: var(--bad); }
.share { display: flex; gap: 6px; } .share input { flex: 1; font-family: ui-monospace, monospace; font-size: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; }
.pill { font-size: 11px; padding: 1px 6px; border-radius: 99px; background: var(--bg); color: var(--muted); }
.mono { font-family: ui-monospace, monospace; font-size: 12px; }
code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }
