/* BLM Portal — builds on site.css tokens. Layout concept: the framed "ledger" panel from the
   home page becomes the working surface (sign-in card, checklist, admin detail). */
:root {
  --pill-req-bg: #e9edf4;  --pill-req-fg: #3c4a69;
  --pill-up-bg: #fde7d6;   --pill-up-fg: #8a3d07;
  --pill-ok-bg: #dcefe3;   --pill-ok-fg: #17573a;
  --pill-err-bg: #f8e0dc;  --pill-err-fg: #8f2217;
  --drop-bg: #f8f9fc;
  --qr-bg: #ffffff; --qr-fg: #000000;
  --shadow: 0 18px 40px rgba(12, 26, 58, .16);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --pill-req-bg: #22345a; --pill-req-fg: #c9d3e6;
    --pill-up-bg: #4a2a12;  --pill-up-fg: #ffc79c;
    --pill-ok-bg: #133a29;  --pill-ok-fg: #8fe0b2;
    --pill-err-bg: #4a1d18; --pill-err-fg: #ffb0a5;
    --drop-bg: #0d1930;
    --shadow: 0 18px 40px rgba(0, 0, 0, .45);
  }
}
:root[data-theme="dark"] {
  --pill-req-bg: #22345a; --pill-req-fg: #c9d3e6;
  --pill-up-bg: #4a2a12;  --pill-up-fg: #ffc79c;
  --pill-ok-bg: #133a29;  --pill-ok-fg: #8fe0b2;
  --pill-err-bg: #4a1d18; --pill-err-fg: #ffb0a5;
  --drop-bg: #0d1930;
  --shadow: 0 18px 40px rgba(0, 0, 0, .45);
}

[hidden] { display: none !important; } /* panels use display:grid; keep the hidden attribute authoritative */
.portal-main { padding-block: clamp(32px, 5vw, 64px) clamp(48px, 6vw, 88px); }
.portal-main > .wrap { display: grid; gap: 28px; }

/* Preview notice (artifact / file previews have no Functions) */
.preview-note {
  display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 12px; align-items: start;
  padding: 14px 16px; border-radius: var(--radius); border: 1.5px dashed var(--orange); background: var(--surface);
  font-size: 0.9375rem;
}
.preview-note svg { width: 20px; height: 20px; color: var(--orange-ink); margin-top: 2px; }
.preview-note strong { font-family: var(--font-display); }

/* ---------- Sign-in ---------- */
.auth {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 460px); grid-template-areas: "intro card" "more card";
  gap: 22px clamp(28px, 6vw, 80px); align-items: start;
}
.auth__copy { grid-area: intro; display: grid; gap: 18px; min-width: 0; padding-top: 8px; }
.auth__more { grid-area: more; display: grid; gap: 18px; min-width: 0; }
.auth > .ledger { grid-area: card; }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; grid-template-areas: "intro" "card" "more"; } }
.auth__copy h1 { font-size: clamp(2rem, 1.5rem + 2vw, 2.75rem); max-width: 16ch; }
.assure { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 14px; max-width: 46ch; }
.assure li { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; color: var(--muted); }
.assure svg { width: 24px; height: 24px; color: var(--orange-ink); }
.assure strong { display: block; color: var(--fg); font-family: var(--font-display); font-weight: 600; font-size: 1rem; }
.auth .ledger { padding: 24px; display: grid; gap: 18px; }
.ledger__step { font-size: var(--fs-sm); color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.auth-panel { display: grid; gap: 16px; }
.auth-panel p { color: var(--muted); }
.auth-panel p strong { color: var(--fg); overflow-wrap: anywhere; }
.code-input {
  font-family: var(--font-display) !important; font-size: 1.6rem !important; font-weight: 600;
  letter-spacing: .32em; font-variant-numeric: tabular-nums; text-align: center; padding-inline: 8px !important;
}
.code-input::placeholder { letter-spacing: .32em; color: var(--line); }
.link-row { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.9375rem; }
.linkish { background: none; border: 0; padding: 4px 0; font: inherit; font-weight: 600; color: var(--fg); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.linkish:hover { text-decoration-thickness: 2px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--danger { background: transparent; color: var(--err); border-color: currentColor; }
.btn--danger.is-armed { background: var(--err); color: var(--bg); border-color: var(--err); }

.enroll-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; counter-reset: es; }
.enroll-steps > li { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; counter-increment: es; }
.enroll-steps > li::before {
  content: counter(es); width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%;
  background: var(--navy); color: #fff; font: 700 0.875rem var(--font-display);
}
:root[data-theme="dark"] .enroll-steps > li::before { background: var(--orange); color: var(--btn-fg-on-orange); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .enroll-steps > li::before { background: var(--orange); color: var(--btn-fg-on-orange); } }
.enroll-steps > li > div { display: grid; gap: 10px; min-width: 0; }
.qr { width: 200px; max-width: 100%; aspect-ratio: 1; padding: 10px; background: var(--qr-bg); border: 1px solid var(--line); border-radius: var(--radius); }
.qr svg { display: block; width: 100%; height: 100%; }
.secret { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 0.9375rem; letter-spacing: .06em; overflow-wrap: anywhere; user-select: all; padding: 8px 10px; background: var(--surface-2); border-radius: var(--radius); }
.recovery { list-style: none; margin: 0; padding: 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; background: var(--surface-2); border-radius: var(--radius); }
.recovery li { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 1rem; font-variant-numeric: tabular-nums; user-select: all; }

/* ---------- Dashboard head ---------- */
.dash-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 16px 24px; }
.dash-head__title { display: grid; gap: 8px; min-width: 0; }
.dash-head__title h1 { font-size: clamp(1.9rem, 1.4rem + 2vw, 2.6rem); }
.dash-head__tools { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.dash-head__tools .field { min-width: 150px; }
.who { font-size: var(--fs-sm); color: var(--muted); overflow-wrap: anywhere; }

.dash { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 320px); gap: 28px; align-items: start; }
@media (max-width: 960px) { .dash { grid-template-columns: 1fr; } }
.dash__main { display: grid; gap: 28px; min-width: 0; }
.dash__side { display: grid; gap: 20px; min-width: 0; }
@media (min-width: 961px) { .dash__side { position: sticky; top: 96px; } }

.panel { display: grid; gap: 16px; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); min-width: 0; }
.panel__head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 16px; }
.panel__head h2 { font-size: var(--fs-lg); }
.panel__head p { color: var(--muted); font-size: 0.9375rem; }
.empty { color: var(--muted); padding: 18px; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface); }

/* Status pills (state is shown by word + colour) */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font: 600 0.8125rem var(--font-display); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill--requested { background: var(--pill-req-bg); color: var(--pill-req-fg); }
.pill--uploaded { background: var(--pill-up-bg); color: var(--pill-up-fg); }
.pill--accepted { background: var(--pill-ok-bg); color: var(--pill-ok-fg); }
.pill--error { background: var(--pill-err-bg); color: var(--pill-err-fg); }

/* Checklist rows */
.reqs { list-style: none; margin: 0; padding: 0; display: grid; border-top: 1px solid var(--line); }
.req { display: grid; gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.req__top { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px; align-items: start; }
.req__label { font-family: var(--font-display); font-weight: 600; font-size: 1.0625rem; overflow-wrap: anywhere; }
.req__note { font-size: 0.9375rem; color: var(--muted); grid-column: 1; }
.req__files { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.req--accepted .req__label { color: var(--muted); }

/* Drop zone */
.drop {
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; align-items: center;
  padding: 14px 16px; border: 2px dashed var(--line); border-radius: var(--radius); background: var(--drop-bg); cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.drop:hover, .drop.is-over { border-color: var(--orange); }
.drop:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.drop input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.drop__icon { grid-row: span 2; width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--radius); background: var(--orange); color: var(--btn-fg-on-orange); }
.drop__icon svg { width: 22px; height: 22px; }
.drop__title { font-weight: 700; font-family: var(--font-display); font-size: 0.9875rem; }
.drop__hint { font-size: 0.8125rem; color: var(--muted); }
.drop--compact { padding: 10px 12px; }
.drop--compact .drop__icon { width: 34px; height: 34px; }
.drop--big { padding: 26px 20px; }

/* File rows */
.files { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.file {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 4px 12px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
}
.file__icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--radius); background: var(--surface-2); color: var(--fg); font: 700 0.625rem var(--font-display); letter-spacing: .04em; text-transform: uppercase; }
.file__name { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.file__meta { font-size: 0.8125rem; color: var(--muted); grid-column: 2; font-variant-numeric: tabular-nums; }
.file__actions { grid-column: 3; grid-row: 1 / span 2; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
@media (max-width: 520px) {
  .file { grid-template-columns: 34px minmax(0, 1fr); }
  .file__actions { grid-column: 1 / -1; grid-row: auto; justify-content: flex-start; }
}
.file--progress { background: var(--surface); }
.bar { grid-column: 2 / -1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--orange); transition: width .2s linear; }
.file--error .file__meta { color: var(--err); font-weight: 600; }

/* Side ledger */
.tally { list-style: none; margin: 0; padding: 0; }
.tally li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.tally li:last-child { border-bottom: 0; }
.tally b { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--orange); }

/* Toasts + dialog */
.toasts { position: fixed; z-index: 80; left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: grid; justify-items: end; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; max-width: 420px; padding: 12px 16px; border-radius: var(--radius); background: var(--navy); color: #fff; box-shadow: var(--shadow); font-weight: 600; font-size: 0.9375rem; border-left: 4px solid var(--orange); }
.toast--error { border-left-color: #ff9a8b; }
dialog.timeout { border: 3px solid var(--orange); border-radius: var(--radius); padding: 24px; max-width: min(440px, calc(100vw - 32px)); background: var(--bg); color: var(--fg); box-shadow: var(--shadow); }
dialog.timeout::backdrop { background: rgba(10, 20, 40, .55); }
dialog.timeout h2 { font-size: var(--fs-lg); margin-bottom: 8px; }
dialog.timeout p { color: var(--muted); margin-bottom: 18px; }
.count { font-family: var(--font-display); font-variant-numeric: tabular-nums; color: var(--fg); }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); overflow-x: auto; }
.tab { background: none; border: 0; padding: 12px 14px; margin-bottom: -2px; font: 600 1rem var(--font-display); color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--orange); }
.admin { display: grid; grid-template-columns: minmax(0, 330px) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 960px) { .admin { grid-template-columns: 1fr; } }
.clients { display: grid; gap: 12px; min-width: 0; }
.client-list { list-style: none; margin: 0; padding: 0; display: grid; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; max-height: 70vh; overflow-y: auto; }
.client-list button {
  width: 100%; text-align: left; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 12px 14px;
  background: var(--bg); color: var(--fg); border: 0; border-bottom: 1px solid var(--line); font: inherit; cursor: pointer;
}
.client-list li:last-child button { border-bottom: 0; }
.client-list button:hover { background: var(--surface); }
.client-list button[aria-current="true"] { background: var(--surface-2); box-shadow: inset 4px 0 0 var(--orange); }
.client-list .nm { font-weight: 700; overflow-wrap: anywhere; }
.client-list .em { font-size: 0.8125rem; color: var(--muted); overflow-wrap: anywhere; }
.client-list .badge { grid-row: span 2; align-self: center; }
.badge { min-width: 26px; padding: 2px 8px; border-radius: 999px; background: var(--orange); color: var(--btn-fg-on-orange); font: 700 0.8125rem var(--font-display); text-align: center; font-variant-numeric: tabular-nums; }
.detail { display: grid; gap: 22px; min-width: 0; }
.detail__head { display: grid; gap: 10px; }
.detail__head h2 { font-size: var(--fs-xl); overflow-wrap: anywhere; }
.facts-row { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); font-size: 0.9375rem; }
.facts-row span { overflow-wrap: anywhere; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid .full { grid-column: 1 / -1; }
.field textarea { width: 100%; min-height: 80px; padding: 10px 14px; border-radius: var(--radius); border: 1.5px solid var(--muted); background: var(--bg); color: var(--fg); font: inherit; }
.check-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; }
@media (max-width: 560px) { .check-list { grid-template-columns: 1fr; } }
.check-list label { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; align-items: start; cursor: pointer; font-size: 0.9375rem; }
.check-list input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--orange); }
.req-admin { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.req-admin select { min-height: 40px; padding: 6px 10px; border-radius: var(--radius); border: 1.5px solid var(--muted); background: var(--bg); color: var(--fg); font: inherit; }
@media (max-width: 520px) { .req-admin { grid-template-columns: minmax(0, 1fr) auto; } .req-admin > :first-child { grid-column: 1 / -1; } }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.audit { width: 100%; border-collapse: collapse; font-size: 0.875rem; min-width: 760px; }
table.audit th, table.audit td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.audit th { position: sticky; top: 0; background: var(--surface); font-family: var(--font-display); font-size: 0.8125rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
table.audit td.t { white-space: nowrap; font-variant-numeric: tabular-nums; }
table.audit td.act { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.8125rem; white-space: nowrap; }
table.audit tr.is-fail td.act { color: var(--err); font-weight: 700; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.toolbar .field { min-width: 160px; flex: 1 1 160px; }
.inline-form { display: grid; gap: 14px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.subhead { font-family: var(--font-display); font-weight: 700; font-size: 1.0625rem; }
.retention { font-size: 0.8125rem; color: var(--muted); border-left: 3px solid var(--orange); padding: 2px 0 2px 12px; }
.auth .form-status:empty { display: none; }

/* ---------- Invoices (Square) ---------- */
.invs { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.inv {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px 16px; align-items: center;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
}
.inv--overdue { border-left: 4px solid var(--err); }
.inv__main { display: grid; gap: 2px; min-width: 0; }
.inv__title { font-family: var(--font-display); font-weight: 600; overflow-wrap: anywhere; }
.inv__meta { font-size: 0.875rem; color: var(--muted); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.inv--overdue .inv__due { color: var(--err); font-weight: 700; }
.inv__amt { display: grid; justify-items: end; gap: 4px; }
.inv__money { font-family: var(--font-display); font-weight: 700; font-size: 1.125rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.inv--overdue .inv__money { color: var(--err); }
.inv__bal { font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.inv__act { display: flex; justify-content: flex-end; }
.inv__note { font-size: 0.8125rem; color: var(--muted); max-width: 18ch; text-align: right; }
.invs--paid .inv { grid-template-columns: minmax(0, 1fr) auto; background: var(--surface); }
.inv-total { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; padding: 12px 14px; border: 3px solid var(--orange); border-radius: var(--radius); }
.inv-total span { color: var(--muted); font-weight: 600; }
.inv-total b { font-family: var(--font-display); font-size: 1.375rem; font-variant-numeric: tabular-nums; }
#inv-body, #dsq-body { display: grid; gap: 14px; min-width: 0; }
#dsq-body code, .notice code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.875em; overflow-wrap: anywhere; }
@media (max-width: 560px) {
  .inv { grid-template-columns: minmax(0, 1fr) auto; }
  .inv__act { grid-column: 1 / -1; justify-content: stretch; }
  .inv__act .btn { width: 100%; }
  .inv__note { max-width: none; text-align: left; }
}
