/* Qist Desk — admin shell.
   Same bones as Clearing's desk client: a persistent sidebar, wide dense
   tables, state carried in form (pill, stripe) as well as in words. Two
   additions: the whole layout is written with logical properties so it flips
   for Urdu, and Nastaliq is used for Urdu text. */

:root {
  --paper:      #f4f7f5;
  --surface:    #ffffff;
  --surface-2:  #eef3ef;
  --surface-3:  #e4ebe6;
  --ink:        #17201d;
  --ink-soft:   #46534e;
  --ink-mute:   #76837d;
  --rule:       #d9e1dc;
  --rule-firm:  #c0cbc4;
  --accent:     #0b6b4f;
  --accent-ink: #ffffff;
  --accent-soft:#dff0e8;
  --warn:       #a86d14;
  --warn-soft:  #fbf0d9;
  --bad:        #b23a3a;
  --bad-soft:   #f8e1e1;
  --ok:         #1f6b3a;
  --ok-soft:    #e2efe6;
  --radius:     8px;
  --sidebar:    236px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", monospace;
  --urdu: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", "Urdu Typesetting", "Nafees Nastaleeq", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:      #101816;
    --surface:    #182220;
    --surface-2:  #1e2927;
    --surface-3:  #25312e;
    --ink:        #e6ece9;
    --ink-soft:   #aab6b0;
    --ink-mute:   #7f8b86;
    --rule:       #2a3733;
    --rule-firm:  #3a4843;
    --accent:     #5fcfa4;
    --accent-ink: #101816;
    --accent-soft:#163b30;
    --warn:       #e3b05a;
    --warn-soft:  #3a2d14;
    --bad:        #e07a7a;
    --bad-soft:   #3d1e1e;
    --ok:         #6cc48a;
    --ok-soft:    #16281c;
  }
}

* { box-sizing: border-box; }

/* Must outrank any class that sets a display value. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.5 "Segoe UI Variable Text", "Segoe UI", -apple-system, system-ui, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Urdu: Nastaliq needs more line height; digits and codes stay in the Latin font. */
body.ur { font-family: var(--urdu), "Segoe UI", system-ui, sans-serif; font-size: 15px; line-height: 1.9; }
body.ur .ref, body.ur code, body.ur [dir="ltr"], body.ur .num { font-family: var(--mono); line-height: 1.5; }
body.ur input[dir="ltr"] { font-family: "Segoe UI", system-ui, sans-serif; }
.ur-text { font-family: var(--urdu); direction: rtl; unicode-bidi: isolate; }

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ── Shell ─────────────────────────────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-inline-end: 1px solid var(--rule);
  position: sticky;
  top: 0;
  height: 100vh;
}

.logo { display: flex; align-items: center; gap: .55rem; padding: 1.1rem 1.15rem; }
.logo-mark { color: var(--accent); font-size: 1.1rem; }
.logo-text { font-weight: 700; font-size: 1rem; letter-spacing: -.01em; }
.logo-lg { padding: 0 0 .3rem; }
.logo-lg .logo-mark { font-size: 1.4rem; }
.logo-lg .logo-text { font-size: 1.3rem; }

.nav { display: flex; flex-direction: column; padding: .3rem .6rem; gap: 1px; }
.nav button {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  width: 100%; text-align: start; cursor: pointer;
  padding: .5rem .6rem; border: 0; border-radius: 6px;
  background: none; color: var(--ink-soft); font-weight: 550;
}
.nav button:hover { background: var(--surface-2); color: var(--ink); }
.nav button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.count {
  min-width: 20px; padding: 0 6px; border-radius: 999px; text-align: center;
  background: var(--surface-3); color: var(--ink-mute);
  font-size: .72rem; font-weight: 700; font-variant-numeric: tabular-nums; font-family: var(--mono);
}
.nav button[aria-current="page"] .count { background: var(--accent); color: var(--accent-ink); }
.count.alert { background: var(--warn); color: #fff; }

.sidebar-foot { margin-top: auto; padding: .9rem 1.15rem 1.1rem; border-top: 1px solid var(--rule); }
.who-name { font-weight: 650; }
.who-role { font-size: .78rem; color: var(--ink-mute); }
.sidebar-actions { display: flex; align-items: center; gap: .6rem; margin-top: .8rem; font-size: .8rem; color: var(--ink-mute); }
.spacer { flex: 1; }
.linkish { background: none; border: 0; color: var(--ink-mute); cursor: pointer; padding: 0; text-decoration: underline; }
.linkish:hover { color: var(--ink); }

.page { padding: 1.5rem 1.8rem 4rem; max-width: 1500px; }

/* ── Page furniture ────────────────────────────────────────────────────── */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
  margin-bottom: 1.2rem; padding-bottom: .8rem; border-bottom: 1px solid var(--rule);
}
.page-head h1 { margin: 0; font-size: 1.3rem; font-weight: 650; letter-spacing: -.015em; }
.page-head .sub { margin: .2rem 0 0; }
.sub { color: var(--ink-mute); font-size: .86rem; margin: 0 0 1rem; }
.muted { color: var(--ink-mute); }
.hint { display: block; font-weight: 400; color: var(--ink-mute); font-size: .76rem; margin-top: .25rem; }
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin: 1.9rem 0 .7rem;
}
.section-head h2 { margin: 0; font-size: .78rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-mute); }
body.ur .section-head h2 { letter-spacing: 0; font-size: .9rem; }

/* ── Stat tiles ────────────────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin-bottom: .4rem; }
.tile { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: .85rem 1rem; }
.tile-label { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-mute); }
body.ur .tile-label { letter-spacing: 0; font-size: .85rem; }
.tile-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin-top: .15rem; font-family: var(--mono); }
.tile-value.warn { color: var(--warn); }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  overflow-x: auto;
}
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
body.ur table.data { font-size: 1rem; }
table.data th {
  text-align: start; font-size: .68rem; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--ink-mute); white-space: nowrap;
  padding: .6rem .8rem; border-bottom: 1px solid var(--rule-firm); background: var(--surface-2);
  position: sticky; top: 0; z-index: 1;
}
body.ur table.data th { letter-spacing: 0; font-size: .85rem; }
table.data td { padding: .62rem .8rem; border-bottom: 1px solid var(--rule); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.strong { font-weight: 650; }
table.data td.actions { text-align: end; white-space: nowrap; }
table.data td.actions button + button { margin-inline-start: .3rem; }
.ref { font-family: var(--mono); font-size: .82rem; font-weight: 600; }
.who-cell { display: flex; flex-direction: column; line-height: 1.25; }
body.ur .who-cell { line-height: 1.7; }
.who-cell small { color: var(--ink-mute); font-size: .76rem; }
tr.settled td { color: var(--ink-mute); }

/* ── Pills ─────────────────────────────────────────────────────────────── */
.pill {
  display: inline-block; padding: .1rem .45rem; border-radius: 4px;
  font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  background: var(--surface-3); color: var(--ink-mute); white-space: nowrap;
}
body.ur .pill { letter-spacing: 0; font-size: .8rem; text-transform: none; }
.pill.active { background: var(--ok-soft); color: var(--ok); }
.pill.pending_enrolment { background: var(--warn-soft); color: var(--warn); }
.pill.suspended, .pill.closed { background: var(--surface-3); color: var(--ink-mute); }
.pill.role { background: var(--accent-soft); color: var(--accent); text-transform: none; letter-spacing: 0; font-size: .74rem; margin: .1rem 0; }
body.ur .pill.role { font-size: .85rem; }

/* ── Controls ──────────────────────────────────────────────────────────── */
button.primary, button.ghost, button.danger, button.small {
  padding: .42rem .85rem; border-radius: 6px; border: 1px solid transparent;
  cursor: pointer; font-weight: 600; font-size: .84rem; white-space: nowrap;
}
body.ur button.primary, body.ur button.ghost, body.ur button.danger { font-size: .95rem; }
button.primary { background: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: var(--surface); border-color: var(--rule-firm); color: var(--ink); }
button.ghost:hover { background: var(--surface-2); }
button.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
button.danger:hover { background: var(--bad-soft); }
button.small { padding: .28rem .6rem; font-size: .78rem; }
button[disabled] { opacity: .45; cursor: not-allowed; }
button.wide { width: 100%; }

label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-soft); margin-bottom: .8rem; }
body.ur label { font-size: .95rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .28rem; padding: .48rem .6rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule-firm); border-radius: 6px;
}
textarea { resize: vertical; font-family: var(--mono); font-size: .82rem; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .9rem; }
.page-head select { width: auto; margin: 0; display: inline-block; }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; margin: .8rem 0 0; }

.empty { text-align: center; color: var(--ink-mute); padding: 2.6rem 1rem; font-size: .88rem; }
.error { color: var(--bad); font-size: .84rem; margin: .5rem 0 0; }
code { font-family: var(--mono); font-size: .82rem; background: var(--surface-2); padding: .1rem .35rem; border-radius: 4px; }

/* ── Panels / dialogs ──────────────────────────────────────────────────── */
.centred { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.panel {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--radius); padding: 1.6rem;
}
#enrol-body { max-width: 440px; }
#enrol-body h1 { font-size: 1.3rem; margin: 0 0 .3rem; }
#enrol-body h3 { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-mute); margin: 1.3rem 0 .5rem; }
body.ur #enrol-body h3 { text-transform: none; letter-spacing: 0; font-size: .95rem; }
#enrol-body code { display: block; background: var(--surface-2); padding: .45rem .55rem; border-radius: 4px; font-size: .82rem; word-break: break-all; margin-top: .4rem; }
#enrol-body summary { cursor: pointer; font-size: .85rem; }

dialog {
  border: 1px solid var(--rule-firm); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  max-width: min(94vw, 620px); width: 100%; padding: 1.3rem;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.4);
}
dialog::backdrop { background: rgba(10, 16, 13, .55); }
dialog h3 { margin: 0 0 .6rem; font-size: 1.05rem; }
dialog .row.end { margin-top: 1.1rem; }
dialog .section-head { margin: 1.2rem 0 .5rem; }

.qr-wrap { background: #fff; border-radius: var(--radius); padding: .7rem; display: grid; place-items: center; }
.qr-wrap svg { width: 100%; max-width: 220px; height: auto; display: block; }

.callout {
  border: 1px solid var(--warn); border-inline-start-width: 3px; border-radius: 6px;
  background: var(--warn-soft); padding: .7rem .85rem; margin: 1.4rem 0 0;
  font-size: .86rem; max-width: 70ch;
}

/* ── Toasts ────────────────────────────────────────────────────────────── */
.toasts {
  position: fixed; inset-inline-end: 1.2rem; bottom: 1.2rem; z-index: 60;
  display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; pointer-events: none;
}
.toast {
  max-width: 380px; padding: .6rem .9rem; border-radius: 6px;
  background: var(--ink); color: var(--paper); font-size: .85rem;
  box-shadow: 0 10px 30px -12px rgba(0,0,0,.55);
}
.toast.good { background: var(--ok); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }

/* ── Narrow screens keep working, they are just not the target ─────────── */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: column; border-inline-end: 0; border-bottom: 1px solid var(--rule); }
  .nav { flex-direction: row; overflow-x: auto; padding: 0 .6rem .5rem; }
  .nav button { justify-content: center; }
  .sidebar-foot { display: flex; align-items: center; gap: 1.2rem; padding: .7rem 1.15rem; border-top: 1px solid var(--rule); }
  .sidebar-actions { margin: 0; }
  .page { padding: 1rem; }
  .page-head { flex-direction: column; align-items: stretch; }
  .toasts { inset-inline: 1rem; align-items: stretch; }
  .field-row { grid-template-columns: 1fr; }
}

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

/* ── Catalog (Phase 1) ───────────────────────────────────────────────── */
.nav button.sub { padding-inline-start: 1.4rem; font-size: .9rem; }
.pill.published { background: var(--ok-soft); color: var(--ok); }
.pill.hidden { background: var(--surface-3); color: var(--ink-mute); }
.thumb-cell { width: 56px; padding-block: .3rem; }
.thumb { width: 48px; height: 48px; object-fit: contain; border-radius: 6px; background: #fff; border: 1px solid var(--rule); display: block; }
.thumb.empty { background: var(--surface-2); }
.page-head select, .page-head input[type=search] {
  padding: .4rem .55rem; border: 1px solid var(--rule-firm); border-radius: 6px; background: var(--surface); max-width: 220px;
}
.run-line { margin: -.4rem 0 .6rem; font-size: .82rem; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin: .4rem 0 .8rem; }
.chip {
  border: 1px solid var(--rule-firm); border-radius: 999px; background: var(--surface); color: var(--ink-soft);
  padding: .25rem .75rem; cursor: pointer; font-weight: 550;
}
.chip b { font-family: var(--mono); font-weight: 600; margin-inline-start: .3rem; font-variant-numeric: tabular-nums; }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.chip:hover { border-color: var(--accent); }
button.small.primary { padding: .3rem .7rem; }
.dialog-wide { width: min(92vw, 860px); }
dialog:has(.dialog-wide) { max-width: min(94vw, 900px); max-height: 92vh; overflow: auto; }
.strip { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .4rem; margin: .4rem 0 .8rem; }
.strip img { height: 120px; width: auto; border-radius: 6px; background: #fff; border: 1px solid var(--rule); flex: 0 0 auto; }
dialog h4 { margin: 1rem 0 .35rem; font-size: .9rem; color: var(--ink-soft); }
ul.plain { margin: 0; padding-inline-start: 1.2rem; }
ul.plain li { margin: .15rem 0; }
.spec-group h4 { margin: .8rem 0 .2rem; }
table.data.compact td, table.data.compact th { padding: .3rem .55rem; font-size: .84rem; }
table.data.compact td:first-child { width: 38%; }

/* ── Price sheet, quote, stock (Phase 1) ─────────────────────────────── */
.pill.price { background: var(--accent-soft); color: var(--accent); text-transform: none; letter-spacing: 0; font-size: .76rem; }
.pill.price b { font-family: var(--mono); font-weight: 700; }
.pill.in_stock { background: var(--ok-soft); color: var(--ok); }
.pill.delivered { background: var(--accent-soft); color: var(--accent); }
.pill.repossessed { background: var(--warn-soft); color: var(--warn); }
.pill.sold_cash { background: var(--surface-3); color: var(--ink-mute); }
.money { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.money.neg { color: var(--bad); }
.margin-line { display: flex; gap: 1.2rem; flex-wrap: wrap; margin: -.3rem 0 .8rem; font-size: .84rem; color: var(--ink-soft); }
.margin-line b { font-family: var(--mono); }
.quote { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface-2); padding: .9rem 1rem; margin: 1rem 0; }
.quote .field-row { grid-template-columns: 1fr 1fr 1fr; align-items: end; }
.quote .totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin: .4rem 0 .8rem; }
.quote .totals div { background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: .5rem .7rem; }
.quote .totals small { display: block; font-size: .72rem; color: var(--ink-mute); }
.quote .totals b { font-family: var(--mono); font-size: 1.05rem; font-weight: 600; }
.quote .table-wrap { max-height: 300px; overflow: auto; }
.csv-result { display: grid; gap: .8rem; margin-top: .8rem; }
.csv-result h4 { margin: 0 0 .3rem; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.line-row { border: 1px solid var(--rule); border-radius: 6px; padding: .6rem .75rem .1rem; margin-bottom: .6rem; background: var(--surface-2); }
.line-row .picked { font-weight: 600; margin-bottom: .5rem; }
.line-row .picked small { display: block; font-weight: 400; color: var(--ink-mute); }
.line-row .field-row { grid-template-columns: 1fr 1fr; }
.search-list { max-height: 180px; overflow: auto; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); margin: -.5rem 0 .8rem; }
.search-list button { display: block; width: 100%; text-align: start; border: 0; border-bottom: 1px solid var(--rule); background: none; padding: .4rem .6rem; cursor: pointer; }
.search-list button:hover { background: var(--surface-2); }
.search-list button small { color: var(--ink-mute); margin-inline-start: .4rem; }
.unit-list { max-height: 260px; overflow: auto; border: 1px solid var(--rule); border-radius: 6px; padding: .3rem .6rem; margin-bottom: .8rem; }
.unit-list label { display: flex; align-items: center; gap: .5rem; margin: .25rem 0; font-weight: 500; }
.unit-list input[type=checkbox] { width: auto; margin: 0; }
@media (max-width: 900px) { .quote .field-row, .line-row .field-row { grid-template-columns: 1fr; } }

/* ── Books (Phase 1) ─────────────────────────────────────────────────── */
tr.clickable { cursor: pointer; }
tr.tb-group td { background: var(--surface-2); color: var(--ink-mute); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; padding-block: .35rem; }
body.ur tr.tb-group td { letter-spacing: 0; text-transform: none; font-size: .9rem; }
tr.tb-total td { font-weight: 700; border-top: 2px solid var(--rule-firm); background: var(--surface-2); }
table.data tbody tr.tb-group:hover td, table.data tbody tr.tb-total:hover td { background: var(--surface-2); }
td.indent { padding-inline-start: 2.2rem; }
.status-line { margin: -.4rem 0 .9rem; font-size: .84rem; font-weight: 600; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; margin: 0; font-weight: 500; }
label.inline input[type=checkbox] { width: auto; margin: 0; }
.section-head .row input[type=date], .section-head .row select { margin: 0; width: auto; padding: .3rem .5rem; font-size: .82rem; }

/* Phase 2: the outbox and plan requests */
.pill.queued { background: var(--warn-soft); color: var(--warn); }
.pill.sent { background: var(--ok-soft); color: var(--ok); }
.pill.failed { background: var(--danger-soft, #fde2e2); color: var(--danger, #b23a3a); }
.pill.open { background: var(--warn-soft); color: var(--warn); }
.pill.answered { background: var(--ok-soft); color: var(--ok); }
.pill.tmpl { background: var(--accent-soft); color: var(--accent); text-transform: none; letter-spacing: 0; font-size: .74rem; }
td.body-cell { max-width: 34ch; white-space: normal; }
.customer-pick { max-height: 12rem; overflow: auto; border: 1px solid var(--rule); border-radius: var(--radius); margin: .3rem 0 .6rem; }
.customer-pick button { display: block; width: 100%; text-align: start; background: none; border: 0; border-bottom: 1px solid var(--rule); padding: .45rem .6rem; cursor: pointer; font: inherit; color: inherit; }
.customer-pick button[aria-selected="true"] { background: var(--accent-soft); }

/* ── Phase 3: applications, verification, contracts ───────────────────── */
.pill.app-quote, .pill.contract-closed { background: var(--surface-3); color: var(--ink-soft); }
.pill.app-submitted, .pill.app-verification, .pill.app-review, .pill.contract-awaiting_delivery { background: var(--warn-soft); color: var(--warn); }
.pill.app-approved, .pill.app-contracted { background: var(--accent-soft); color: var(--accent); }
.pill.app-delivered, .pill.contract-active { background: var(--ok-soft); color: var(--ok); }
.pill.app-declined, .pill.contract-written_off, .pill.contract-repossessed { background: var(--bad-soft); color: var(--bad); }
.pill.app-cancelled, .pill.contract-rescheduled { background: var(--surface-3); color: var(--ink-mute); }
.pill.ok, .pill.call-confirmed, .pill.visit-verified, .pill.inst-paid { background: var(--ok-soft); color: var(--ok); }
.pill.warn, .pill.call-no_answer, .pill.visit-not_home, .pill.inst-due { background: var(--warn-soft); color: var(--warn); }
.pill.flag, .pill.call-not_confirmed, .pill.call-wrong_number, .pill.call-refused, .pill.visit-address_wrong, .pill.visit-refused { background: var(--bad-soft); color: var(--bad); }
.pill[class*="app-"], .pill[class*="contract-"], .pill.flag, .pill[class*="call-"], .pill[class*="visit-"], .pill[class*="inst-"] { text-transform: none; letter-spacing: 0; }
button.ghost.danger { color: var(--bad); border-color: var(--bad-soft); }
tr.flagged td { background: color-mix(in srgb, var(--bad-soft) 45%, transparent); }
.status-line { margin: -.4rem 0 1rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.facts { display: grid; grid-template-columns: minmax(8rem, max-content) 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.facts dt { color: var(--ink-mute); font-size: .82rem; }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
body.ur .facts dt { font-size: .95rem; }
.kyc-grid { display: flex; flex-wrap: wrap; gap: .6rem; margin: .4rem 0 .8rem; }
.kyc-grid.small .kyc-tile { width: 64px; }
.kyc-grid.small .kyc-tile img { height: 48px; }
.kyc-tile { margin: 0; width: 120px; display: grid; gap: .25rem; }
.kyc-tile img { width: 100%; height: 84px; object-fit: cover; border-radius: 6px; border: 1px solid var(--rule); background: var(--surface-2); cursor: zoom-in; }
.kyc-tile img.broken { cursor: default; }
.kyc-tile.empty { height: 84px; border: 1px dashed var(--rule-firm); border-radius: 6px; place-items: center; text-align: center; font-size: .78rem; padding: .3rem; }
.kyc-tile figcaption { font-size: .74rem; color: var(--ink-mute); }
body.ur .kyc-tile figcaption { font-size: .85rem; }
.kyc-full { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto 1rem; border-radius: 6px; }
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: .8rem 1rem; margin: 0 0 .8rem; }
.card-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.card p { margin: .3rem 0; }
.problems, .checklist { margin: .3rem 0 1rem; padding-inline-start: 1.2rem; }
.problems li, .checklist li { margin: .2rem 0; }
.checklist { list-style: none; padding-inline-start: 0; }
.timeline { list-style: none; padding: 0; margin: 0 0 1.5rem; border-inline-start: 2px solid var(--rule); }
.timeline li { padding: .3rem .8rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.score { font-family: var(--mono); }
.clauses { display: grid; gap: .6rem; margin-bottom: 1.5rem; }
.clause { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: .7rem 1rem; }
.clause p { margin: 0; }
.clause .ur-text { font-family: var(--urdu); line-height: 2; }
@media (max-width: 760px) { .clause { grid-template-columns: 1fr; } .facts { grid-template-columns: 1fr; } }
label.check { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
label.check input { width: auto; }
.error .problems { color: inherit; }

/* ── Receipts, cash days, aging (Phase 4) ─────────────────────────────── */
.pill.rcpt-reversal, .pill.rcpt-reversed { background: var(--bad-soft); color: var(--bad); }
.pill.rcpt-pending { background: var(--warn-soft); color: var(--warn); }
.pill.aging-current { background: var(--ok-soft); color: var(--ok); }
.pill.aging-d1_30 { background: var(--warn-soft); color: var(--warn); }
.pill.aging-d31_60, .pill.aging-d61_90, .pill.aging-over_90 { background: var(--bad-soft); color: var(--bad); }
.warn-text { color: var(--warn); }
.small-print { font-size: .78rem; margin-top: .2rem; }
body.ur .small-print { font-size: .9rem; }
tr.total-row td { border-top: 2px solid var(--rule-firm); font-weight: 600; }
.stamps { display: inline-flex; flex-wrap: wrap; gap: .25rem; }
.stamp-no { font-family: var(--mono); font-size: .72rem; border: 1px dashed var(--rule-firm); border-radius: 4px; padding: 0 .3rem; color: var(--ink-soft); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .2rem 1rem; }
.pick-list { display: grid; gap: .3rem; margin: .2rem 0 .6rem; max-height: 220px; overflow: auto; }
.pick-list .pick { text-align: start; background: var(--surface-2); border: 1px solid var(--rule); border-radius: 6px; padding: .45rem .6rem; color: var(--ink); cursor: pointer; }
.pick-list .pick:hover, .pick-list .pick:focus-visible { border-color: var(--accent); }
.callout.stale-cash { margin: 0 0 1rem; }

/* The receipt slip: narrow like a thermal roll, bilingual, black on white
   when printed whatever the screen's theme. */
.slip { width: min(100%, 360px); margin: 0 auto; background: #fff; color: #111; padding: 1rem 1.1rem; border: 1px dashed #b9c2bd; border-radius: 6px; font-size: .86rem; line-height: 1.45; }
.slip .muted { color: #555; }
.slip-head { text-align: center; border-bottom: 1px dashed #b9c2bd; padding-bottom: .5rem; margin-bottom: .5rem; }
.slip-shop { font-weight: 700; font-size: 1.05rem; }
.slip-title { text-align: center; font-weight: 700; font-size: 1rem; margin: .3rem 0 0; }
.slip-no { text-align: center; font-family: var(--mono); font-size: 1rem; font-weight: 700; }
.slip-when { text-align: center; color: #555; font-size: .78rem; margin-bottom: .4rem; }
.slip-void { text-align: center; border: 2px solid #b23a3a; color: #b23a3a; font-weight: 700; border-radius: 4px; padding: .15rem; margin: .3rem 0; }
.slip-lines { display: grid; grid-template-columns: max-content 1fr; gap: .15rem .6rem; margin: .4rem 0; }
.slip-lines dt { color: #555; font-size: .76rem; }
.slip-lines dd { margin: 0; text-align: end; overflow-wrap: anywhere; }
.slip-amount { font-family: var(--mono); font-size: 1.15rem; font-weight: 700; }
.slip-sub { font-size: .76rem; color: #555; border-top: 1px dashed #b9c2bd; padding-top: .4rem; }
.slip-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .78rem; }
.slip-table td { padding: .1rem 0; }
.slip-table td.num { text-align: end; }
.slip-note { font-style: italic; margin: .3rem 0; }
.slip-foot { border-top: 1px dashed #b9c2bd; padding-top: .4rem; margin: .4rem 0 0; font-size: .72rem; text-align: center; color: #333; }
.slip .ur-text { font-family: var(--urdu); line-height: 1.9; }
dialog.slip-dialog { width: min(94vw, 420px); }

@media print {
  @page { margin: 6mm; }
  body { background: #fff !important; }
  body > *:not(dialog) { display: none !important; }
  dialog[open] { position: static; display: block; border: 0; padding: 0; margin: 0; box-shadow: none; max-height: none; max-width: none; width: auto; overflow: visible; background: #fff; }
  dialog::backdrop { display: none; }
  .no-print { display: none !important; }
  .slip { border: 0; width: 72mm; padding: 0; }
}
