:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface-2: #f0efe9; --line: #e3e1d8; --line-2: #d4d1c5;
  --text: #1c1b18; --muted: #6b6a63; --faint: #9a988f;
  --accent: #0f6e5f; --accent-2: #0c5a4e; --accent-soft: #e2f1ec; --on-accent: #fff;
  --dr: #0f6e5f; --cr: #b4442a; --warn: #a86a00; --warn-soft: #fbf1dc; --bad: #b4302a; --bad-soft: #fbe6e3;
  --good: #1d7a3e; --good-soft: #e1f3e6; --info-soft: #e7eefb; --info: #2c56a8;
  --radius: 12px; --shadow: 0 1px 2px rgba(20,20,10,.06), 0 4px 16px rgba(20,20,10,.06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412; --surface: #1d1d1a; --surface-2: #262622; --line: #2f2f2b; --line-2: #3c3c37;
    --text: #ecebe6; --muted: #a3a29a; --faint: #75746d;
    --accent: #3fb8a0; --accent-2: #5fcab4; --accent-soft: #19352f; --on-accent: #07231d;
    --dr: #4cc3a9; --cr: #ee8a70; --warn: #e3b24f; --warn-soft: #3a3020; --bad: #f08a80; --bad-soft: #3d2320;
    --good: #6fcf8f; --good-soft: #1d3325; --info-soft: #1f2a40; --info: #8fb0f0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141412; --surface: #1d1d1a; --surface-2: #262622; --line: #2f2f2b; --line-2: #3c3c37;
  --text: #ecebe6; --muted: #a3a29a; --faint: #75746d;
  --accent: #3fb8a0; --accent-2: #5fcab4; --accent-soft: #19352f; --on-accent: #07231d;
  --dr: #4cc3a9; --cr: #ee8a70; --warn: #e3b24f; --warn-soft: #3a3020; --bad: #f08a80; --bad-soft: #3d2320;
  --good: #6fcf8f; --good-soft: #1d3325; --info-soft: #1f2a40; --info: #8fb0f0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 620; }
h3 { font-size: 14px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.dr { color: var(--dr); } .cr { color: var(--cr); }
.small { font-size: 13px; } .tiny { font-size: 12px; }
.right { text-align: right; } .center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; } .row.wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.side { display: none; }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.brand { font-weight: 700; letter-spacing: -.02em; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; display: block; }
.login .brand .logo { width: 52px; height: 52px; border-radius: 13px; box-shadow: var(--shadow); }
.cmp-btn { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; cursor: pointer; max-width: 60vw; }
.cmp-btn .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.sync-dot.on { background: #22a86b; box-shadow: 0 0 0 3px color-mix(in srgb, #22a86b 25%, transparent); }
.sync-dot.off { background: #d08a1c; }
.main { padding: 16px 16px 110px; max-width: 1180px; width: 100%; margin: 0 auto; }
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; border-radius: 10px; }
.bottomnav a.active { color: var(--accent); }
.bottomnav svg, .side svg { width: 22px; height: 22px; }
.bottomnav .plus { background: var(--accent); color: var(--on-accent); width: 46px; height: 46px; border-radius: 16px; display: grid; place-items: center; margin-top: -4px; }
.bottomnav a.newbtn { color: var(--text); }

@media (min-width: 900px) {
  .app { grid-template-columns: 236px 1fr; }
  .side { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; padding: 14px 10px; border-right: 1px solid var(--line); background: var(--surface); }
  .side .brand { padding: 4px 8px 14px; }
  .side a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--text); font-weight: 500; }
  .side a:hover { background: var(--surface-2); }
  .side a.active { background: var(--accent-soft); color: var(--accent); }
  .side .sep { height: 1px; background: var(--line); margin: 8px 6px; }
  .side .newlink { background: var(--accent); color: var(--on-accent) !important; justify-content: center; margin: 0 4px 10px; }
  .topbar .brand { display: none; }
  .bottomnav { display: none; }
  .main { padding: 22px 28px 60px; }
}

/* ---------- cards & lists ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card h2 { margin-bottom: 10px; }
.grid { display: grid; gap: 12px; }
.grid.kpis { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .grid.kpis { grid-template-columns: repeat(4, 1fr); } .grid.two { grid-template-columns: 1fr 1fr; } }
.kpi .label { font-size: 12.5px; color: var(--muted); }
.kpi .value { font-size: 21px; font-weight: 650; letter-spacing: -.01em; margin-top: 2px; }
.kpi .sub { font-size: 12px; color: var(--faint); margin-top: 2px; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li, .list > a { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--line); color: var(--text); }
.list > :first-child { border-top: 0; }
.list > a:hover, .list > li.click:hover { background: var(--surface-2); cursor: pointer; }
.list .t { font-weight: 550; } .list .s { font-size: 12.5px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.banner { border-radius: 10px; padding: 10px 12px; font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; }
.banner.warn { background: var(--warn-soft); color: var(--warn); } .banner.info { background: var(--info-soft); color: var(--info); }
.banner.bad { background: var(--bad-soft); color: var(--bad); } .banner.good { background: var(--good-soft); color: var(--good); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 10px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 3px; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); position: sticky; top: 0; }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tr.click:hover td { background: var(--surface-2); cursor: pointer; }
table.t .num { text-align: right; }
table.t tfoot td { font-weight: 650; border-top: 2px solid var(--line-2); border-bottom: 0; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-2); background: var(--surface);
  border-radius: 10px; padding: 9px 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 11px; outline: none; min-height: 40px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.num { text-align: right; }
textarea.input { min-height: 70px; resize: vertical; }
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
@media (min-width: 800px) { .form-grid.three { grid-template-columns: repeat(3, 1fr); } .form-grid.four { grid-template-columns: repeat(4, 1fr); } }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .input { width: auto; min-width: 0; }
.search { position: relative; flex: 1; min-width: 180px; }
.search .input { padding-left: 34px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--faint); }

/* combobox */
.combo { position: relative; }
.combo .menu { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 50; background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 10px; box-shadow: var(--shadow); max-height: 320px; overflow-y: auto; }
.combo .opt { padding: 9px 12px; cursor: pointer; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.combo .opt:first-child { border-top: 0; }
.combo .opt.hi, .combo .opt:hover { background: var(--accent-soft); }
.combo .opt .x { font-size: 12px; color: var(--muted); white-space: nowrap; }
.combo .hint { font-size: 12px; color: var(--muted); margin-top: 4px; min-height: 16px; }

/* invoice lines */
.lines { display: flex; flex-direction: column; gap: 10px; }
.line { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--surface); display: grid; gap: 8px;
  grid-template-columns: 1fr 1fr 1fr; }
.line .item { grid-column: 1 / -1; }
.line .amt { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
@media (min-width: 900px) {
  .line { grid-template-columns: minmax(220px, 3fr) 1fr 1.2fr .8fr .8fr 1.2fr 34px; align-items: end; }
  .line .item { grid-column: auto; }
  .line .amt { grid-column: auto; justify-content: flex-end; padding-bottom: 9px; }
  .line .amt .lbl { display: none; }
}
.totals { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font-size: 14px; }
.totals .big { font-size: 20px; font-weight: 700; }
.sticky-actions { position: sticky; bottom: 74px; z-index: 10; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow); margin-top: 16px; }
@media (min-width: 900px) { .sticky-actions { bottom: 12px; } }

/* sheet / modal */
.overlay { position: fixed; inset: 0; background: rgba(10,10,5,.4); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: var(--shadow); }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 16px; } }
.sheet .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px;
  border-radius: 10px; z-index: 200; font-weight: 550; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; height: 16px; }
@keyframes sk { to { background-position: -200% 0; } }

/* bars */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 8px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; height: 100%; justify-content: flex-end; }
.bars .col { width: 100%; max-width: 30px; background: var(--accent); border-radius: 5px 5px 2px 2px; min-height: 2px; }
.bars .col.p { background: var(--line-2); }
.bars .m { font-size: 10.5px; color: var(--muted); }
.bars .pair { display: flex; gap: 2px; align-items: flex-end; width: 100%; justify-content: center; height: 100%; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 26px 22px; }

/* ---------- print ---------- */
.invoice { background: #fff; color: #111; max-width: 820px; margin: 0 auto; font-size: 12px; border: 1px solid #333; }
.invoice table { width: 100%; border-collapse: collapse; }
.invoice td, .invoice th { border: 1px solid #333; padding: 4px 6px; vertical-align: top; }
.invoice th { background: #f2f2f2; font-weight: 700; font-size: 11px; }
.invoice .title { text-align: center; font-weight: 800; font-size: 15px; padding: 6px; border-bottom: 1px solid #333; letter-spacing: .05em; }
.invoice .cmp { font-size: 16px; font-weight: 800; }
.invoice .nb td, .invoice .nb th { border: 0; }
.invoice .r { text-align: right; } .invoice .c { text-align: center; } .invoice .b { font-weight: 700; }
.invoice .qr { width: 120px; height: 120px; }
.print-bar { display: flex; gap: 8px; justify-content: center; margin: 0 0 14px; flex-wrap: wrap; }
@media print {
  body { background: #fff; }
  .side, .topbar, .bottomnav, .print-bar, .no-print { display: none !important; }
  .app { display: block; } .main { padding: 0; max-width: none; }
  .invoice { border: 1px solid #333; max-width: none; }
  @page { size: A4; margin: 10mm; }
}

.cmplogo { height: 44px; width: auto; max-width: 110px; object-fit: contain; border-radius: 8px; background: #fff; padding: 3px; border: 1px solid var(--line); }
.invoice .brandlogo { max-height: 70px; max-width: 150px; float: left; margin: 2px 10px 4px 0; }
.invoice .c .brandlogo { float: none; display: block; margin: 0 auto 6px; max-height: 72px; }
