:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e3e7ee;
  --text: #1c2431;
  --muted: #667085;
  --primary: #0f6e56;
  --primary-soft: #e3f3ee;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --warn: #b54708;
  --warn-soft: #fef0c7;
  --info-soft: #eef4ff;
  --income: #1570ef;
  --expense: #c4320a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body.booting .app { visibility: hidden; }
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #111a2b; }
.gate-card { width: min(440px, 100%); }
.gate-card h1 { font-size: 22px; margin: 0 0 6px; }
.gate-brand { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.gate-brand img { width: 40px; height: 40px; border-radius: 10px; }
.recovery { font-family: ui-monospace, Menlo, monospace; background: #f8fafc; border-radius: 8px; padding: 12px 14px; line-height: 1.8; }
.qr { display: block; margin: 8px auto; width: 220px; height: 220px; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: #111a2b; color: #cbd5e1; padding: 20px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 20px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: #1a1636; display: block; object-fit: cover; }
.brand-name { color: #fff; font-weight: 700; font-size: 14px; white-space: nowrap; }
.brand-sub { font-size: 12px; color: #94a3b8; }
nav a { display: block; padding: 9px 12px; border-radius: 8px; color: #cbd5e1; margin-bottom: 2px; }
nav a:hover { background: rgba(255, 255, 255, 0.06); }
nav a.active { background: rgba(255, 255, 255, 0.12); color: #fff; font-weight: 600; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #64748b; padding: 16px 12px 6px; }
.sidebar-foot { margin-top: auto; font-size: 11px; color: #64748b; padding: 8px 12px; }

.view { padding: 28px 32px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 1100px) { .grid.cols-4, .grid.cols-5 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: 1fr; } }

.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi.income .value { color: var(--income); }
.kpi.expense .value { color: var(--expense); }
.kpi.net.pos .value { color: var(--primary); }
.kpi.net.neg .value { color: var(--danger); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.table-wrap { overflow-x: auto; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.paid, .badge.received { background: var(--primary-soft); color: var(--primary); }
.badge.unpaid, .badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.overdue { background: var(--danger-soft); color: var(--danger); }
.badge.cur { background: var(--info-soft); color: #1d4ed8; font-family: ui-monospace, Menlo, monospace; }
.badge.expense { background: #fff1ea; color: var(--expense); }
.badge.income { background: var(--info-soft); color: var(--income); }
.badge.live { background: var(--primary-soft); color: var(--primary); }
.badge.stale { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: #f2f4f7; color: var(--muted); }

button, .btn { font: inherit; border: 1px solid var(--border); background: #fff; color: var(--text); padding: 8px 12px; border-radius: 8px; cursor: pointer; }
button:hover, .btn:hover { background: #f8fafc; }
button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.primary:hover { background: #0c5b47; }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button.sm { padding: 4px 8px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: default; }
.icon-btn { border: none; background: transparent; font-size: 20px; line-height: 1; padding: 4px 8px; color: var(--muted); }

input, select, textarea { font: inherit; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 110, 86, 0.25); border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field { margin-bottom: 12px; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 14px; }
.form-grid .span2 { grid-column: span 2; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > * { width: auto; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 130px; }
.filters input, .filters select { padding: 7px 9px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: none; border-radius: 0; padding: 7px 12px; }
.seg button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.bar-row { display: grid; grid-template-columns: 1fr 120px; gap: 10px; align-items: center; padding: 6px 0; }
.bar-row .name { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.bar { height: 8px; background: #eef1f5; border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--expense); border-radius: 4px; }
.bar.income > i { background: var(--income); }
.bar-row .amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.chart { width: 100%; height: auto; max-height: 260px; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

.drop { border: 2px dashed #c9d1dc; border-radius: var(--radius); padding: 40px; text-align: center; background: #fff; color: var(--muted); transition: all 0.15s; cursor: pointer; }
.drop.over { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.drop strong { color: var(--text); }
.queue { margin-top: 16px; display: grid; gap: 10px; }
.queue-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.review { display: grid; grid-template-columns: minmax(0, 1fr) 460px; gap: 16px; margin-top: 16px; }
@media (max-width: 1100px) { .review { grid-template-columns: 1fr; } }
.review iframe { width: 100%; height: 720px; border: 1px solid var(--border); border-radius: 8px; background: #525659; }
.notes { background: var(--warn-soft); color: var(--warn); padding: 8px 12px; border-radius: 8px; font-size: 12px; margin-bottom: 12px; }
.notes.ok { background: var(--primary-soft); color: var(--primary); }
.aed-preview { background: var(--info-soft); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
.aed-preview b { font-size: 16px; }
details.raw { margin-top: 8px; }
details.raw pre { max-height: 240px; overflow: auto; background: #f8fafc; padding: 10px; border-radius: 8px; font-size: 11px; white-space: pre-wrap; }

dialog { border: none; border-radius: 12px; padding: 0; width: min(760px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
dialog::backdrop { background: rgba(17, 26, 43, 0.5); }
.modal-card { margin: 0; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: #fafbfc; border-radius: 0 0 12px 12px; }

.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 50; }
.toast { background: #111a2b; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; animation: fade 0.2s; max-width: 380px; }
.toast.error { background: var(--danger); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #cbd5e1; border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { background: none; border: none; color: var(--primary); padding: 0; cursor: pointer; font: inherit; }
.link:hover { text-decoration: underline; background: none; }
.sidebar-foot .link { color: #94a3b8; margin-top: 4px; }

/* Scanned-image preview (JPEG / PNG invoices) */
.preview-img { width: 100%; max-height: 720px; object-fit: contain; border: 1px solid var(--border); border-radius: 8px; background: #f8fafc; }

/* Tax-period readiness checks */
.check { padding: 10px 12px; border-radius: 8px; margin-bottom: 8px; font-weight: 600; }
.check.ok { background: var(--primary-soft); color: var(--primary); }
.check.warn { background: var(--warn-soft); color: var(--warn); }

/* Bank statement import */
.amt.credit { color: var(--income); font-weight: 600; }
.amt.debit { color: var(--expense); font-weight: 600; }
.badge.matched { background: var(--primary-soft); color: var(--primary); }
.badge.ignored { background: #eef1f5; color: var(--muted); }
.badge.new { background: var(--warn-soft); color: var(--warn); }
.badge.high { background: var(--primary-soft); color: var(--primary); }
.badge.medium { background: var(--info-soft); color: #1d4ed8; }
.badge.low { background: #eef1f5; color: var(--muted); }
.bank-row td { vertical-align: top; }
.bank-desc { max-width: 360px; }
.bank-desc .ref { font-size: 11px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
.bank-assign { display: grid; grid-template-columns: 210px minmax(160px, 1fr) minmax(150px, 1fr); gap: 6px; min-width: 540px; }
.bank-assign select, .bank-assign input { padding: 6px 8px; font-size: 13px; }
.bank-assign .span3 { grid-column: span 3; }
.bank-assign .remember { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.bank-assign .remember input[type=checkbox] { width: auto; }
.bank-assign .remember input[type=text] { flex: 1; font-family: ui-monospace, Menlo, monospace; font-size: 11px; text-transform: uppercase; }
.reason { font-size: 12px; color: var(--muted); margin-top: 4px; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.sample { font-size: 12px; }
.sample td, .sample th { padding: 5px 8px; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { border: none; border-radius: 8px 8px 0 0; background: transparent; padding: 8px 14px; color: var(--muted); }
.tabs button.active { color: var(--primary); font-weight: 600; box-shadow: inset 0 -2px 0 var(--primary); }
.tabs .count { background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: 0 7px; font-size: 11px; margin-left: 6px; }

[data-role=add-party] { white-space: nowrap; }
.add-party-panel .form-grid { margin-bottom: 8px; }

/* Sales invoices */
table.items { width: 100%; margin-top: 6px; }
table.items th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 4px 6px; }
table.items td { padding: 3px 4px; border-bottom: none; vertical-align: middle; }
table.items input { width: 100%; }
table.items .line-amt { font-variant-numeric: tabular-nums; }
.badge.draft, .badge.void { background: #eef0f4; color: var(--muted); }

/* Desktop app: room for the macOS traffic lights and a draggable header. */
#drag-strip { display: none; }
body.electron #drag-strip { display: block; position: fixed; top: 0; left: 0; right: 0; height: 40px; z-index: 5; -webkit-app-region: drag; }
body.electron .sidebar { padding-top: 44px; -webkit-app-region: drag; }
body.electron .sidebar nav, body.electron .sidebar button, body.electron .sidebar a { -webkit-app-region: no-drag; }
body.electron .view { padding-top: 40px; }
body.electron .page-head { -webkit-app-region: drag; }
body.electron .page-head button, body.electron .page-head a, body.electron .page-head input, body.electron .page-head .seg { -webkit-app-region: no-drag; }

/* Hosted (cloud) copy: nothing local to open. */
body.hosted #open-data, body.hosted [data-reveal], body.hosted #s-open-root, body.hosted #s-open-inv,
body.hosted #s-open-inc, body.hosted #s-open-bank, body.hosted #s-open-sales { display: none; }

/* Run costs: (i) buttons and help text */
.info-btn { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: 4px; padding: 0; border-radius: 50%; border: 1px solid var(--muted); background: transparent; color: var(--muted); font: italic 700 10px/1 Georgia, serif; vertical-align: middle; cursor: pointer; }
.info-btn:hover { color: var(--primary); border-color: var(--primary); }
.kpi .label .info-btn { margin-top: -2px; }
.help p, .help li { font-size: 14px; line-height: 1.5; }
.help ul { padding-left: 18px; }
.help p:first-child { margin-top: 0; }
