/* Clearing — desk client.
   A tool that gets scanned and operated, not read. So: a persistent sidebar, wide
   dense tables, money right-aligned in tabular figures, and state carried in form
   (pill, stripe, bar) as well as in words. Cards are reserved for summaries. */

:root {
  --paper:      #f4f6f2;
  --surface:    #ffffff;
  --surface-2:  #eef2ec;
  --surface-3:  #e6ebe3;
  --ink:        #18211d;
  --ink-soft:   #48534c;
  --ink-mute:   #78837c;
  --rule:       #dde2d8;
  --rule-firm:  #c4ccbe;
  --accent:     #0e5a48;
  --accent-ink: #ffffff;
  --accent-soft:#e0ece7;
  --warn:       #97431f;
  --warn-soft:  #f7eae2;
  --ok:         #1f6b3a;
  --ok-soft:    #e2efe6;
  --radius:     8px;
  --sidebar:    236px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:      #0e1311;
    --surface:    #151b18;
    --surface-2:  #1c2320;
    --surface-3:  #232b27;
    --ink:        #e3e8e3;
    --ink-soft:   #aab4ae;
    --ink-mute:   #7f8a84;
    --rule:       #262e2a;
    --rule-firm:  #3a433d;
    --accent:     #4fbfa0;
    --accent-ink: #0e1311;
    --accent-soft:#152e28;
    --warn:       #dd8760;
    --warn-soft:  #2c1e17;
    --ok:         #6cc48a;
    --ok-soft:    #16281c;
  }
}

* { box-sizing: border-box; }

/* Must outrank any class that sets a display value. The browser's own rule for
   the hidden attribute is display:none at zero specificity, so a class such as
   .shell { display: grid } beats it and the element never hides. */
[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;
}

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-right: 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: left; 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;
}
.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); text-transform: capitalize; }
.position-block { margin: .9rem 0; }
.position-label {
  display: block; font-size: .68rem; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-mute);
}
.position-value {
  display: block; font-size: 1.35rem; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: var(--ok);
}
.position-value.negative { color: var(--warn); }
.position-dir { font-size: .74rem; color: var(--ink-mute); }
.sidebar-actions { display: flex; align-items: center; gap: .4rem; font-size: .76rem; color: var(--ink-mute); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-mute); flex: none; }
.dot.live { background: var(--ok); }
.conn-text { 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); }
.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); }

/* ── 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); }
.tile-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin-top: .15rem; }
.tile-value.warn { color: var(--warn); }
.tile-value.ok { color: var(--ok); }
.tile-note { font-size: .76rem; color: var(--ink-mute); }

/* ── 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; }
table.data th {
  text-align: left; 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;
}
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: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.strong { font-weight: 650; }
table.data td.actions { text-align: right; white-space: nowrap; }
.ref { font-family: var(--mono); font-size: .82rem; font-weight: 600; }
.who-cell { display: flex; flex-direction: column; line-height: 1.25; }
.who-cell small { color: var(--ink-mute); font-size: .76rem; }

/* A left stripe carries severity without spending the accent colour on it. */
tr.flagged td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
tr.settled td { color: var(--ink-mute); }

/* ── Progress ──────────────────────────────────────────────────────────── */
.progress { display: flex; align-items: center; gap: .5rem; min-width: 130px; }
.bar { flex: 1; height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar > i.part { background: var(--ok); }
.progress small { color: var(--ink-mute); font-variant-numeric: tabular-nums; min-width: 2.6em; text-align: right; }

/* ── 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);
}
.pill.open, .pill.low, .pill.verified, .pill.active { background: var(--ok-soft); color: var(--ok); }
.pill.elevated, .pill.pending, .pill.disputed { background: var(--warn-soft); color: var(--warn); }
.pill.high, .pill.rejected { background: var(--warn); color: #fff; }
.pill.settled, .pill.cancelled, .pill.expired, .pill.closed { background: var(--surface-3); color: var(--ink-mute); }

.countdown { font-family: var(--mono); font-weight: 650; font-variant-numeric: tabular-nums; }
.countdown.urgent { color: var(--warn); }

/* ── 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;
}
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(--warn); color: var(--warn); }
button.danger:hover { background: var(--warn-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; }
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; }
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; }
.money-input { font-family: var(--mono); font-size: 1.05rem; font-weight: 650; }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spread { display: flex; justify-content: space-between; gap: 1rem; padding: .3rem 0; font-size: .86rem; }
.spread + .spread { border-top: 1px solid var(--rule); }
.spread .num { font-variant-numeric: tabular-nums; font-weight: 600; }

.empty { text-align: center; color: var(--ink-mute); padding: 2.6rem 1rem; font-size: .88rem; }
.error { color: var(--warn); font-size: .84rem; margin: .5rem 0 0; }
.flags { margin: .5rem 0 0; padding-left: 1.1rem; font-size: .83rem; color: var(--warn); }

/* ── 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: 420px; }

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 .3rem; font-size: 1.05rem; }
dialog .row.end { margin-top: 1.1rem; }

.methods { display: flex; flex-direction: column; gap: .5rem; margin: .7rem 0; }
.method {
  border: 1px solid var(--rule); border-radius: 6px; padding: .6rem .7rem;
  display: flex; align-items: center; gap: .8rem; background: var(--surface-2);
}
.method .handle { flex: 1; min-width: 0; font-family: var(--mono); font-size: .85rem; word-break: break-all; }
.method img { width: 88px; height: 88px; flex: none; background: #fff; border-radius: 4px; padding: 3px; }

.proof-thumbs { display: flex; gap: .6rem; flex-wrap: wrap; margin: .7rem 0; }
.proof-thumbs img {
  width: 128px; height: 128px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--rule-firm); cursor: zoom-in; background: var(--surface-2);
}

.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; }
#enrol-body h3 { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-mute); margin: 1.3rem 0 .5rem; }
#enrol-body code { display: block; background: var(--surface-2); padding: .45rem .55rem; border-radius: 4px; font-size: .82rem; word-break: break-all; }

/* ── Toasts ────────────────────────────────────────────────────────────── */
.toasts {
  position: fixed; right: 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(--warn); 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-right: 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); }
  .position-block { margin: 0; }
  .position-value { font-size: 1rem; display: inline; }
  .page { padding: 1rem; }
  .toasts { left: 1rem; right: 1rem; align-items: stretch; }
  .field-row { grid-template-columns: 1fr; }
}

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