:root {
  --bg: #f4f6f8; --card: #ffffff; --ink: #1c2530; --muted: #6b7684;
  --line: #e2e8ef; --accent: #1d6fd1; --accent-dark: #155aa8;
  --green: #178a4c; --red: #c0392b; --amber: #b7791f; --purple: #6c4fc4;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; }
.topbar { display: flex; justify-content: space-between; align-items: center;
  background: #16233a; color: #fff; padding: 12px 20px; position: sticky; top: 0; z-index: 50; }
.brand { font-size: 17px; font-weight: 700; }
.brand .tag { font-size: 11px; font-weight: 600; background: #2c3e5a; color: #bcd; padding: 2px 8px; border-radius: 20px; margin-left: 6px;}
.topbar-right { display: flex; gap: 10px; align-items: center; }
.pill { font-size: 11px; font-weight: 700; padding: 5px 12px; border-radius: 20px; letter-spacing: .4px; }
.pill.demo { background: #f5c518; color: #4a3800; }
.pill.test { background: #7aa2f7; color: #0b1e4b; }
.pill.live { background: #2ecc71; color: #063d1f; }
.chip { font-size: 12px; background: #2c3e5a; color: #cfe0ff; padding: 5px 12px; border-radius: 20px; }
.shell { display: flex; align-items: flex-start; min-height: calc(100vh - 52px); }
/* Left sidebar navigation */
.tabs { flex: 0 0 216px; display: flex; flex-direction: column; gap: 1px; background: #fff;
  border-right: 1px solid var(--line); padding: 14px 10px 24px; position: sticky; top: 52px;
  height: calc(100vh - 52px); overflow-y: auto; z-index: 40; }
.tabs .nav-group { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--muted); padding: 14px 12px 6px; }
.tabs .nav-group:first-child { padding-top: 2px; }
.tabs button { border: 0; background: none; text-align: left; padding: 9px 12px; font-size: 14px; font-weight: 600;
  color: #3d4856; cursor: pointer; border-radius: 8px; white-space: nowrap; display: flex; gap: 10px; align-items: center; }
.tabs button .ico { width: 18px; text-align: center; opacity: .85; }
.tabs button:hover { background: #f1f4f8; color: var(--ink); }
.tabs button.active { background: #e8f0fc; color: var(--accent); }
.view { flex: 1; min-width: 0; max-width: 1180px; margin: 0 auto; padding: 20px 24px; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 20px; margin-right: 10px; cursor: pointer; padding: 0 4px; }
@media (max-width: 860px) {
  .nav-toggle { display: inline-block; }
  .tabs { position: fixed; left: 0; top: 52px; bottom: 0; height: auto; width: 240px; transform: translateX(-105%);
    transition: transform .18s ease, visibility 0s linear .18s; box-shadow: 4px 0 18px rgba(0,0,0,.12); visibility: hidden; }
  .tabs.open { transform: none; visibility: visible; transition: transform .18s ease; }
}
@media (max-width: 600px) {
  .topbar { padding: 10px 12px; flex-wrap: nowrap; gap: 8px; }
  .brand { white-space: nowrap; font-size: 16px; }
  .topbar-right { gap: 6px; min-width: 0; }
  #trust-chip, #user-chip { display: none; }
  .pill { font-size: 10px; padding: 4px 8px; white-space: nowrap; }
  #company-switch { max-width: 120px; }
  .topbar .btn { white-space: nowrap; }
  .view { padding: 12px; }
  .panel { overflow-x: auto; }
}
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card h3 { margin: 0 0 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 700;}
.card .big { font-size: 22px; font-weight: 700; }
/* Clickable dashboard cards */
.card-link { font: inherit; color: inherit; text-align: left; cursor: pointer; position: relative;
  display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch;
  transition: border-color .12s, box-shadow .12s, transform .12s; }
.card-link:hover, .card-link:focus-visible { border-color: var(--accent); box-shadow: 0 2px 10px rgba(29,111,209,.12); outline: none; }
.card-link:active { transform: translateY(1px); }
.card-link .card-go { position: absolute; right: 14px; top: 14px; font-size: 12px; font-weight: 600; color: var(--accent); opacity: 0; transition: opacity .12s; }
.card-link:hover .card-go, .card-link:focus-visible .card-go { opacity: 1; }
tr.row-link { cursor: pointer; }
tr.row-link:hover td, tr.row-link:focus td { background: #f4f8fe; }
tr.row-link:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.card .big.pos { color: var(--green); } .card .big.neg { color: var(--red); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 16px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th { text-align: left; color: var(--muted); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .4px; padding: 8px 10px; border-bottom: 2px solid var(--line); }
table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:hover td { background: #f8fafc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px; }
.badge.draft { background: #eef1f5; color: #5b6774; }
.badge.sent { background: #dbeafe; color: #1d4fa1; }
.badge.paid, .badge.completed, .badge.matched { background: #dcf5e5; color: #14663a; }
.badge.overdue, .badge.failed { background: #fbe3e3; color: #a02c22; }
.badge.pending, .badge.unmatched { background: #fef3d8; color: #8a5d0b; }
.badge.stripe_demo { background: #fff3bf; color: #7a5b00; border: 1px dashed #d9b400; }
.badge.stripe { background: #e3ecff; color: #2743a0; }
.badge.manual { background: #eef1f5; color: #5b6774; }
.badge.trust { background: #e9defc; color: #4c2e9e; }
.badge.ignored, .badge.cancelled, .badge.void { background: #eef1f5; color: #98a2ad; }
.btn { border: 0; border-radius: 8px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; background: var(--accent); color: #fff; }
.btn:hover { background: var(--accent-dark); }
.btn.secondary { background: #eef1f5; color: var(--ink); }
.btn.secondary:hover { background: #dde4ea; }
.btn.danger { background: #fff; color: var(--red); border: 1px solid #f0c6c2; }
.btn.danger:hover { background: #fdf0ef; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
input, select, textarea { font-size: 13.5px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd7f5; border-color: var(--accent); }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 14px; }
.modal-back { position: fixed; inset: 0; background: rgba(15,25,40,.5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; }
.modal { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; }
.modal.wide { max-width: 760px; }
.modal h2 { margin: 0 0 14px; font-size: 17px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
#toast-root { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #16233a; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.toast.err { background: #a02c22; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.link { color: var(--accent); text-decoration: none; } .link:hover { text-decoration: underline; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 600; } .kv dd { margin: 0; }
.tree { font-size: 13.5px; } .tree ul { list-style: none; margin: 4px 0; padding-left: 22px; border-left: 1px dashed var(--line); }
.tree code { background: #eef1f5; padding: 1px 6px; border-radius: 5px; font-size: 12px; }
.progress { height: 8px; background: #eef1f5; border-radius: 6px; overflow: hidden; }
.progress > div { height: 100%; background: var(--green); }
@media (max-width: 720px) { .view { padding: 12px; } table.grid { font-size: 12.5px; } }

/* ── company letterhead (invoice view) ── */
.letterhead { display: flex; align-items: center; gap: 14px; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 2px solid var(--line); }
.lh-logo { max-height: 64px; max-width: 180px; object-fit: contain; }
.lh-name { font-size: 19px; font-weight: 700; }
.lh-contact { margin-top: 2px; line-height: 1.5; }

/* ── setup wizard + forms ── */
.wizard { max-width: 560px; margin: 40px auto; }
.form label { display: block; margin-bottom: 10px; font-size: 13px; font-weight: 600; }
.form .input, .form input[type="file"] { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
.form .row { display: flex; gap: 10px; }
.form .row label { flex: 1; }
.input, select.input { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; background: #fff; }
#company-switch { margin-right: 8px; max-width: 220px; }
@media print { .toolbar, .topbar, #tabs { display: none !important; } }

/* ── receipt inbox ── */
.thumb { max-width: 110px; max-height: 80px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }

/* Reconciliation suggestions */
.match-hint { margin-top: 3px; }
.badge.conf-strong { background: #dcf5e5; color: #14663a; }
.badge.conf-likely { background: #e3ecff; color: #2743a0; }
.badge.conf-possible { background: #eef1f5; color: #5b6774; }
#rc-lines td:first-child { white-space: nowrap; }
#rc-lines td:last-child { white-space: nowrap; }
#rc-lines .match-select { max-width: 280px; }
