/* Luxe Accounts — back-office ledger UI */
:root {
  --paper: #F6F7F4;
  --surface: #FFFFFF;
  --ink: #1B2733;
  --ink-soft: #55616D;
  --rule: #D9DDE1;
  --rule-soft: #ECEEF0;
  --teal: #0E6B70;
  --teal-strong: #0A5357;
  --teal-wash: #E3F0EF;
  --night: #12303A;
  --night-ink: #C9D8DB;
  --neg: #A8452B;
  --neg-wash: #F8E9E4;
  --pos: #2C7A4B;
  --pos-wash: #E4F2E9;
  --amber: #8A5A00;
  --amber-wash: #FBF0D9;
  --focus: #F2B33D;
  --sand: #E7C27A;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
/* Pakistan books get a different sidebar tone so nobody posts into the wrong branch by mistake */
body[data-branch="pk"] { --night: #1C3326; --night-ink: #CFDCCF; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.5 var(--font);
  font-feature-settings: "tnum" 1, "lnum" 1;
}
a { color: var(--teal); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--teal-strong); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 .75em; }
small { font-size: .85em; }
.muted { color: var(--ink-soft); }
.small { font-size: .875rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Shell ---------- */
.has-nav .main { margin-left: 248px; }
.main { padding: 28px 36px 64px; max-width: 1280px; }
.no-nav .main { margin: 0 auto; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 248px;
  background: var(--night); color: var(--night-ink);
  overflow-y: auto; padding: 18px 0 24px;
  display: flex; flex-direction: column;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 0 20px 18px; color: #fff; text-decoration: none; }
.brand-mark { color: #E7C27A; display: grid; }
.brand-text { display: grid; line-height: 1.15; }
.brand-text strong { font-size: 1.05rem; }
.brand-text small { color: var(--night-ink); opacity: .8; max-width: 170px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-group { display: grid; padding: 8px 12px; }

/* Branch books: which set of books is open */
.books { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 0 14px 10px; padding: 4px; background: rgba(0,0,0,.22); border-radius: var(--radius-m); }
.books.single { grid-template-columns: 1fr; }
.book { display: grid; gap: 0; text-align: left; background: transparent; border: 0; border-radius: var(--radius-s); padding: 7px 10px; color: var(--night-ink); font: inherit; cursor: pointer; line-height: 1.15; }
.book strong { font-size: 1.15rem; letter-spacing: .02em; color: #fff; opacity: .55; }
.book span { font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book:hover strong { opacity: .85; }
.book.on { background: var(--sand); color: var(--night); cursor: default; }
.book.on strong { color: var(--night); opacity: 1; }
.topbar-cur { margin-left: auto; font-weight: 700; color: var(--sand); }
.nav-group-title { font-size: .8rem; color: #8FA9AE; padding: 6px 10px 4px; }
.nav-group a {
  color: var(--night-ink); text-decoration: none; padding: 6px 10px; border-radius: var(--radius-s);
  font-weight: 500;
}
.nav-group a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-group a.active { background: var(--teal); color: #fff; }
.nav-user { margin-top: auto; padding: 16px 22px 0; border-top: 1px solid rgba(255,255,255,.08); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.nav-user span { display: grid; color: #fff; line-height: 1.2; }
.nav-user small { color: #8FA9AE; }
.link-btn { background: none; border: 0; color: #E7C27A; font: inherit; cursor: pointer; padding: 4px; }

.topbar, .nav-toggle { display: none; }

/* ---------- Page head ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.subtitle { margin: 4px 0 0; color: var(--ink-soft); }
.back { display: inline-block; margin-bottom: 4px; font-size: .9rem; text-decoration: none; }
.back::before { content: "‹ "; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--teal); color: #fff; border: 1px solid var(--teal);
  padding: 8px 14px; border-radius: var(--radius-s); font: 600 .95rem/1.2 var(--font);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--teal-strong); border-color: var(--teal-strong); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: var(--surface); color: var(--teal); border-color: var(--rule); }
.btn-ghost:hover { background: var(--teal-wash); color: var(--teal-strong); border-color: var(--teal); }
.btn-danger { background: var(--neg); border-color: var(--neg); }
.btn-danger:hover { background: #8C3720; border-color: #8C3720; }
.btn-danger-ghost { background: transparent; color: var(--neg); border-color: transparent; padding-left: 0; }
.btn-danger-ghost:hover { background: transparent; color: #8C3720; text-decoration: underline; border-color: transparent; }
.btn-wide { width: 100%; padding: 11px; }
.chip { background: transparent; border: 1px solid var(--rule); border-radius: 999px; padding: 4px 10px; font: 500 .85rem var(--font); color: var(--ink-soft); cursor: pointer; }
.chip:hover { border-color: var(--teal); color: var(--teal); }
.icon-btn { background: none; border: 0; font-size: 1.3rem; line-height: 1; color: var(--ink-soft); cursor: pointer; padding: 4px 8px; border-radius: var(--radius-s); }
.icon-btn:hover { color: var(--neg); background: var(--neg-wash); }

/* ---------- Notices ---------- */
.notice { padding: 10px 14px; border-radius: var(--radius-s); margin: 0 0 16px; border-left: 4px solid; }
.notice-success { background: var(--pos-wash); border-color: var(--pos); }
.notice-error { background: var(--neg-wash); border-color: var(--neg); }
.notice-info { background: var(--teal-wash); border-color: var(--teal); }

/* ---------- Ledger strip: the signature element ---------- */
.ledger-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m);
  margin-bottom: 24px;
}
.figure { padding: 16px 20px; display: grid; gap: 2px; align-content: start; border-left: 1px solid var(--rule-soft); }
.figure:first-child { border-left: 0; }
.figure-label { color: var(--ink-soft); font-size: .9rem; }
.figure-value { font-size: 1.6rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.15; }
.figure-value small { font-size: .55em; font-weight: 600; color: var(--ink-soft); letter-spacing: .02em; vertical-align: .35em; }
.figure-value.neg { color: var(--neg); }
.figure a { font-size: .875rem; margin-top: 4px; }
.figure-lead { background: var(--night); color: #fff; border-radius: calc(var(--radius-m) - 1px) 0 0 calc(var(--radius-m) - 1px); }
.figure-lead:last-child:not(:first-child) { border-radius: 0 calc(var(--radius-m) - 1px) calc(var(--radius-m) - 1px) 0; }
.figure-lead .figure-label { color: var(--night-ink); }
.figure-lead .figure-value { font-size: 2.1rem; }
.figure-lead .figure-value small { color: #E7C27A; }
.figure-text { font-size: .95rem; color: var(--ink-soft); }

/* ---------- Panels & layout ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 18px 20px; margin-bottom: 20px; }
.panel h2 { margin-bottom: 12px; }
.panel.flush { padding: 18px 0 0; overflow-x: auto; }
.panel.flush h2 { padding: 0 20px; }
.panel.flush > p { padding: 0 20px 18px; margin: 0; }
.panel.flush .tbl { border: 0; border-top: 1px solid var(--rule); border-radius: 0; }
.panel .tbl { border: 0; }
.panel .more { display: inline-block; margin-top: 10px; font-size: .9rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 20px; }
.grid-2 > .panel { margin-bottom: 20px; }

/* ---------- Tables ---------- */
.tbl { position: relative; width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); }
.tbl th, .tbl td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--rule-soft); }
.tbl thead th { font-weight: 600; font-size: .875rem; color: var(--ink-soft); border-bottom: 1px solid var(--rule); background: #FAFBFA; white-space: nowrap; }
.tbl tbody tr:hover td { background: #FAFCFB; }
.tbl tfoot td { font-weight: 600; border-bottom: 0; border-top: 1px solid var(--rule); }
.tbl .num, .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl td.num { font-size: 1rem; }
.tbl .neg, .neg { color: var(--neg); }
.tbl .strong { font-weight: 600; }
.tbl tr.inactive td { color: #98A1A9; }
.tbl tr.inactive a { color: #7E9A9C; }
.tbl tr.subtotal td { font-weight: 600; border-top: 1px solid var(--rule); }
.tbl tr.total td { font-weight: 700; border-top: 1px solid var(--ink); }
.tbl tr.grand td { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--ink); border-bottom: 3px double var(--ink); }
.tbl tr.section th { padding-top: 18px; font-size: 1rem; font-weight: 700; color: var(--ink); background: none; border-bottom: 1px solid var(--rule); }
.tbl tr.opening td { color: var(--ink-soft); font-style: italic; }
.tbl tr.note td { color: var(--ink-soft); font-size: .9rem; }
.tbl tr.warn-row td { background: var(--amber-wash); }
.tbl td.indent { padding-left: 28px; }
.tbl td.late { color: var(--neg); font-weight: 600; }
.tbl .row-act { text-align: right; }
.tbl td:first-child a { white-space: nowrap; }
.tbl-plain { border: 0; }
.tbl-plain td { padding: 7px 0; }
.tbl-plain td.num { padding-left: 12px; }
.w-code { width: 90px; }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; margin-bottom: 18px; }
.filters label { display: grid; gap: 3px; font-size: .875rem; color: var(--ink-soft); font-weight: 500; }
.filters label.grow { flex: 1 1 220px; }
.filters label.check { display: flex; align-items: center; gap: 6px; padding-bottom: 8px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 4px; }

/* ---------- Forms ---------- */
input, select, textarea {
  font: 400 15px/1.4 var(--font); color: var(--ink);
  border: 1px solid #C3C9CF; border-radius: var(--radius-s); background: #fff;
  padding: 7px 9px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal); outline: 2px solid var(--teal-wash); outline-offset: 0; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
textarea { resize: vertical; }
input[type=checkbox] { width: auto; accent-color: var(--teal); }
.form-card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 22px 24px; max-width: 980px; }
.form-card.narrow { max-width: 440px; }
.form-card h2 { margin: 20px 0 12px; padding-top: 16px; border-top: 1px solid var(--rule-soft); }
.form-card h2:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; margin-bottom: 18px; }
.form-grid label, .stack label { display: grid; gap: 4px; font-weight: 600; font-size: .9rem; }
.form-grid label small { font-weight: 400; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid label.check, .check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.stack { display: grid; gap: 14px; }
.with-link { display: flex; gap: 12px; align-items: center; }
.with-link a { white-space: nowrap; font-weight: 500; font-size: .9rem; }
.form-actions { display: flex; gap: 10px; align-items: center; padding-top: 16px; border-top: 1px solid var(--rule-soft); margin-top: 8px; }

/* Line items */
.lines { margin: 6px 0 10px; border-radius: var(--radius-s); }
.lines td { padding: 6px 6px; border-bottom: 0; }
.lines th { padding: 8px 6px; }
.lines tbody tr:hover td { background: none; }
.lines .w-desc { min-width: 220px; }
.lines .w-acc { min-width: 180px; }
.lines .w-qty { width: 70px; }
.lines .w-rate { width: 120px; }
.lines .w-vat { width: 140px; }
.lines .w-amt { width: 120px; }
.lines .w-inv { width: 140px; }
.inline-edit { margin-top: 12px; }
.inline-edit summary { cursor: pointer; color: var(--teal); font-weight: 600; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin-top: 10px; }
.inline-form label { display: grid; gap: 4px; font-weight: 600; font-size: .9rem; min-width: 160px; }
.small-value { font-size: 1.1rem !important; padding-top: 8px; }
.detail.flat { border: 0; padding: 0; background: none; margin: 0 0 8px; max-width: none; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .88em; background: #EEF1EF; padding: 2px 6px; border-radius: 4px; word-break: break-all; }
code.key { display: inline-block; margin-top: 6px; }
.mono-area { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9rem; }
.form-card .form-actions form { display: inline; }
.form-card + .form-card, .form-card + .panel, .panel + .form-card { margin-top: 20px; }
.filters.inline { padding: 0 20px; margin-bottom: 12px; }
.payload summary { cursor: pointer; color: var(--ink-soft); font-size: .82rem; margin-top: 4px; }
.payload pre { white-space: pre-wrap; word-break: break-all; font-size: .78rem; background: #F4F6F5; padding: 8px; border-radius: 4px; max-height: 240px; overflow: auto; }
.cost-links { margin: 12px 0 0; color: var(--ink-soft); font-size: .92rem; }
.lines td.js-amt { padding-top: 13px; font-weight: 600; }
.doc-bottom { display: grid; grid-template-columns: 1fr 320px; gap: 24px; margin: 18px 0; align-items: start; }
.doc-bottom label { display: grid; gap: 4px; font-weight: 600; font-size: .9rem; }
.totals { width: 100%; border-collapse: collapse; }
.totals td { padding: 6px 0; }
.totals td.num { font-size: 1.05rem; }
.totals tr.grand td { border-top: 2px solid var(--ink); font-weight: 700; font-size: 1.25rem; padding-top: 10px; }

/* Document view */
.doc-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 18px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 18px 20px; }
.doc-head > div { display: grid; gap: 2px; }
.doc-party { font-size: 1.35rem; font-weight: 700; text-decoration: none; color: var(--ink); }
.doc-meta, .detail { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0; }
.doc-meta dt, .detail dt { color: var(--ink-soft); }
.doc-meta dd, .detail dd { margin: 0; font-weight: 500; }
.detail { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 18px 20px; max-width: 720px; margin-bottom: 20px; }
.doc-notes { background: var(--surface); border-left: 3px solid var(--rule); padding: 10px 14px; margin: 16px 0; }
.num-strong { font-weight: 700; font-size: 1.15rem; }

.void-box { margin: 24px 0 8px; max-width: 520px; }
.void-box summary { list-style: none; display: inline-flex; }
.void-box summary::-webkit-details-marker { display: none; }
.void-box form { margin-top: 10px; background: var(--neg-wash); padding: 14px 16px; border-radius: var(--radius-m); display: grid; gap: 10px; }
.void-box label { display: grid; gap: 4px; font-weight: 600; }

/* Badges */
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.badge-paid, .badge-posted { background: var(--pos-wash); color: var(--pos); }
.badge-partial { background: var(--amber-wash); color: var(--amber); }
.badge-unpaid { background: var(--teal-wash); color: var(--teal-strong); }
.badge-overdue { background: var(--neg-wash); color: var(--neg); }
.badge-void { background: #EEF0F2; color: #6B757E; text-decoration: line-through; }

/* Reports */
.report { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 22px 24px; margin-bottom: 20px; overflow-x: auto; }
.report .tbl { border: 0; }
.report-head { display: grid; gap: 2px; margin-bottom: 16px; }
.report-head strong { font-size: 1.15rem; }
.report-head span { color: var(--ink-soft); }
.statement-head { grid-template-columns: 1fr 1fr; gap: 24px; }
.statement-head > div { display: grid; gap: 2px; }
.statement-head > div:last-child { text-align: right; }
.statement { max-width: 760px; }
.aging-docs { font-size: .875rem; margin-top: 2px; }
.aging-docs summary { color: var(--ink-soft); cursor: pointer; }
.aging-docs ul { margin: 6px 0 0; padding-left: 18px; }

.code { display: inline-block; font-size: .8rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; background: var(--teal-wash); color: var(--teal-strong); }
.code-zr { background: #EEF0F2; color: #4F5962; }
.code-ex, .code-os { background: var(--amber-wash); color: var(--amber); }
.register td { font-size: .95rem; }
.register td:nth-child(-n+2), .register td:nth-child(-n+2) a { white-space: nowrap; }
.report > p { margin: 12px 0 0; }
.help { background: var(--teal-wash); border-radius: var(--radius-m); padding: 10px 14px; margin-bottom: 18px; }
.help summary { cursor: pointer; font-weight: 600; color: var(--teal-strong); }
.help p { margin: 8px 0 0; }

.empty { background: var(--surface); border: 1px dashed #C3C9CF; border-radius: var(--radius-m); padding: 36px; text-align: center; }
.empty p { color: var(--ink-soft); }

/* Login / install */
.login-wrap { min-height: 90vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 30px; display: grid; gap: 16px; }
.login-brand { display: flex; align-items: center; gap: 12px; color: var(--teal); }
.login-brand div { display: grid; line-height: 1.2; color: var(--ink); }
.login-brand strong { font-size: 1.3rem; }
.login-brand span { color: var(--ink-soft); font-size: .9rem; }
.install { max-width: 760px; margin: 0 auto; padding: 24px 0; display: grid; gap: 14px; }
.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.checks .ok { color: var(--pos); }
.checks .bad { color: var(--neg); font-weight: 600; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .has-nav .main { margin-left: 0; }
  .main { padding: 72px 16px 48px; }
  .topbar { display: flex; align-items: center; gap: 12px; position: fixed; inset: 0 0 auto 0; height: 56px; background: var(--night); color: #fff; padding: 0 16px; z-index: 20; }
  .topbar-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .nav-burger { display: grid; gap: 4px; cursor: pointer; padding: 8px; }
  .nav-burger span { width: 20px; height: 2px; background: #fff; display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; z-index: 30; top: 56px; }
  .nav-toggle:checked ~ .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .nav-toggle { display: block; position: absolute; opacity: 0; pointer-events: none; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .doc-bottom { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .figure { border-left: 0; border-top: 1px solid var(--rule-soft); }
  .figure:first-child { border-top: 0; }
  .figure-lead, .figure-lead:last-child:not(:first-child) { border-radius: calc(var(--radius-m) - 1px) calc(var(--radius-m) - 1px) 0 0; }
  .tbl { display: block; overflow-x: auto; }
  .tbl:not(.tbl-plain) th, .tbl:not(.tbl-plain) td { white-space: nowrap; }
  .tbl-plain { display: table; }
  .lines td { min-width: 90px; }
  .lines td:first-child { min-width: 200px; }
  .statement-head { grid-template-columns: 1fr; }
  .statement-head > div:last-child { text-align: left; }
  .form-card { padding: 16px; }
  .with-link { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Print ---------- */
@media print {
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar, .page-actions, .filters, .void-box, .back, .notice, .help, .form-actions, .aging-docs { display: none !important; }
  .has-nav .main { margin: 0; padding: 0; max-width: none; }
  .ledger-strip, .panel, .report, .tbl, .detail, .doc-head { border-color: #999; break-inside: avoid; }
  .figure-lead { background: #fff; color: #000; }
  .figure-lead .figure-label, .figure-lead .figure-value small { color: #444; }
  a { color: inherit; text-decoration: none; }
}
