:root {
  --bg: #f3f5f8; --card: #fff; --ink: #1c2530; --muted: #6a7686; --line: #d9dfe7; --brand: #0b6fa4; --brand-ink: #fff;
  --ok: #1e7e45; --warn: #b26a00; --bad: #b3261e; --row: #eef3f8; --radius: 8px; --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); font-size: 15px; color: var(--ink); background: var(--bg); }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 18px; margin: 0; } h3 { font-size: 14px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
a { color: var(--brand); }
.muted { color: var(--muted); } .mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, Consolas, monospace; font-size: 13.5px; }
.r { text-align: right; } .c { text-align: center; } .neg { color: var(--bad); }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.sidebar { background: #12263a; color: #dbe6f1; display: flex; flex-direction: column; padding: 14px 10px; gap: 6px; }
.brand { font-size: 24px; font-weight: 700; padding: 6px 10px 14px; color: #fff; } .brand small { display: block; font-size: 12px; font-weight: 400; color: #9fb3c8; }
.nav-link { display: block; color: #dbe6f1; text-decoration: none; padding: 10px 12px; border-radius: 6px; }
.nav-link:hover { background: #1c3650; } .nav-link.active { background: var(--brand); color: #fff; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 6px; }
.side-foot .who { color: #9fb3c8; font-size: 13px; }
.sync-badge { display: block; padding: 7px 10px; border-radius: 6px; font-size: 13px; text-decoration: none; background: #1c3650; color: #dbe6f1; }
.sync-badge.ok { background: #1d4d36; } .sync-badge.warn { background: #5a4310; } .sync-badge.bad { background: #6b1f1a; } .sync-badge.info { background: #1c3a5c; }
.main { overflow: auto; padding: 22px 26px 40px; }
.page { max-width: 1180px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }

/* ---- controls ---- */
input, select, textarea { font: inherit; color: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%; }
textarea { resize: vertical; } input.narrow { width: 90px; } input.wide { flex: 1; } input[type=checkbox] { width: auto; margin: 0 4px 0 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input.bad { border-color: var(--bad); background: #fdf1f0; }
.btn { font: inherit; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; }
.btn:hover:not(:disabled) { background: #f0f4f8; } .btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); } .btn.primary:hover:not(:disabled) { background: #095d8b; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; } .btn.danger-outline { color: var(--bad); border-color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.icon-btn { border: 0; background: transparent; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 4px; } .icon-btn:hover { background: #e7ecf2; color: var(--bad); }
.field { display: block; margin-bottom: 12px; } .field-label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; } .hint { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }
.row { display: flex; gap: 8px; align-items: center; } .row-2 { display: grid; grid-template-columns: 1fr 160px; gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 4px; margin-right: 14px; cursor: pointer; } .checks { margin-bottom: 12px; }
.form-error { color: var(--bad); margin: 8px 0; font-size: 14px; } .form-error ul { margin: 0; padding-left: 18px; }
.form.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #e6eef6; border-radius: 14px; padding: 3px 10px; margin: 0 6px 6px 0; font-size: 13.5px; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: #e6eaf0; color: #3c4858; margin-right: 4px; } .pill.warn { background: #fdecc8; color: #7a4a00; } .pill.bad { background: #f9d9d6; color: var(--bad); }

/* ---- tables ---- */
.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; } .filters .search { max-width: 360px; } .filters select { width: auto; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--line); background: #fafbfd; white-space: nowrap; }
table.grid td { padding: 8px 12px; border-bottom: 1px solid #edf0f4; vertical-align: middle; }
table.grid th.r { text-align: right; } table.grid th.c { text-align: center; }
tr.clickable { cursor: pointer; } tr.clickable:hover, tr.clickable:focus { background: var(--row); outline: none; }
td.actions { text-align: right; white-space: nowrap; } td.actions .btn { margin-left: 4px; }
td.empty { text-align: center; color: var(--muted); padding: 28px; } .more { text-align: center; margin-top: 12px; }

/* ---- invoice editor ---- */
.ed-top { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; } .ed-bottom { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; }
.lines-card { padding: 0; } .lines-card .table-wrap { border: 0; }
table.lines td { padding: 4px 6px; } table.lines input { padding: 6px 8px; } table.lines input.num { text-align: right; width: 90px; } table.lines input.code { width: 130px; }
td.lineno { width: 30px; text-align: center; font-size: 12.5px; } td.total { white-space: nowrap; min-width: 100px; font-variant-numeric: tabular-nums; }
.totals .trow { display: flex; justify-content: space-between; padding: 6px 0; font-size: 15px; } .totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; font-weight: 700; } .big { font-size: 26px; }
.readonly { padding: 8px 0; font-weight: 600; }
.action-bar { position: sticky; bottom: 0; display: flex; justify-content: space-between; gap: 10px; background: var(--bg); padding: 12px 0 4px; border-top: 1px solid var(--line); margin-top: 8px; flex-wrap: wrap; }
.action-left, .action-right { display: flex; gap: 8px; flex-wrap: wrap; }
.banner { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; } .banner.warn { background: #fdf3da; color: #6b4300; } .banner.bad { background: #fbe4e1; color: #7c1b14; } .banner-actions { margin-top: 8px; display: flex; gap: 8px; }
details summary { cursor: pointer; color: var(--brand); margin-bottom: 8px; }
.pick-list { display: flex; flex-direction: column; gap: 8px; } .pick { text-align: left; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; } .pick:hover { background: var(--row); }

/* ---- overlays ---- */
.overlay { position: fixed; inset: 0; background: rgba(15, 25, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px; z-index: 50; overflow: auto; }
.modal { background: #fff; border-radius: 10px; width: min(520px, 100%); box-shadow: 0 12px 40px rgba(0,0,0,.3); } .modal.wide { width: min(760px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); } .modal-body { padding: 16px 18px; } .modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.ac { position: absolute; z-index: 60; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-height: 320px; overflow: auto; }
.ac-item { padding: 8px 12px; cursor: pointer; } .ac-item.active, .ac-item:hover { background: var(--row); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: #223; color: #fff; padding: 10px 14px; border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.25); max-width: 380px; } .toast.ok { background: var(--ok); } .toast.error { background: var(--bad); } .toast.warn { background: var(--warn); }

/* ---- login / settings ---- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(420px, 100%); box-shadow: 0 10px 30px rgba(0,0,0,.08); } .login-card h1 { margin-bottom: 18px; } .login-card .btn { width: 100%; margin-top: 6px; }
.kv { display: grid; grid-template-columns: 260px 1fr; gap: 6px 14px; font-size: 14px; } .kv .k { color: var(--muted); } .kv .v { word-break: break-all; }
.problem { border: 1px solid #f0c4c0; background: #fdf3f2; border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; }
.person { display: block; padding: 3px 0; } .barcodes { margin-bottom: 8px; }

/* ---- narrow screens (phones): one column, bigger touch targets ---- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px; }
  .brand { padding: 4px 8px; font-size: 18px; } .brand small { display: none; } .sidebar nav { display: flex; flex-wrap: wrap; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; } .side-foot .who { display: none; }
  .main { padding: 14px 12px 40px; overflow: visible; }
  .ed-top, .ed-bottom, .form.two, .row-2 { grid-template-columns: 1fr; }
  input, select, textarea, .btn { min-height: 44px; } table.lines input.num { width: 70px; } table.lines input.code { width: 100px; }
  .kv { grid-template-columns: 1fr; }
}
@media print { .sidebar, .action-bar, .toasts { display: none !important; } .shell { display: block; height: auto; } }
