/*
 * Loan Desk.
 *
 * Inherits the Top Agent house system from recruit-ats: OKLCH tokens, blue primary,
 * amber accent, 8px radius, system stack. Loan Desk is a sibling of Recruit, so the
 * shared tokens keep their names and values and only the additions are new.
 *
 * The one deliberate departure: amber is not decoration here. Amber means a human is
 * required. It appears on the Needs You surface and nowhere else, so that on a phone in
 * a driveway the answer to "is anything waiting on me" is a colour, not a sentence.
 */

:root {
  --bg: oklch(1 0 0);
  --surface: oklch(0.968 0.004 250);
  --surface-2: oklch(0.945 0.006 250);
  --ink: oklch(0.24 0.012 250);
  --muted: oklch(0.46 0.014 250);
  --line: oklch(0.9 0.006 250);
  --primary: oklch(0.48 0.14 255);
  --primary-strong: oklch(0.41 0.13 255);
  --primary-soft: oklch(0.94 0.03 255);
  --accent: oklch(0.62 0.14 70);
  --accent-strong: oklch(0.47 0.12 66);
  --accent-soft: oklch(0.95 0.035 75);
  --danger: oklch(0.52 0.16 25);
  --danger-soft: oklch(0.95 0.025 25);
  --good: oklch(0.5 0.12 150);
  --good-soft: oklch(0.95 0.03 150);

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px oklch(0.2 0.01 250 / 0.06), 0 4px 12px oklch(0.2 0.01 250 / 0.07);
  --shadow-lg: 0 2px 4px oklch(0.2 0.01 250 / 0.06), 0 12px 32px oklch(0.2 0.01 250 / 0.12);

  --z-sticky: 10;
  --z-drawer-backdrop: 40;
  --z-drawer: 50;
  --z-toast: 60;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --fast: 150ms;
  --med: 220ms;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--ink); }
a { color: var(--primary-strong); }
h1, h2, h3 { margin: 0; letter-spacing: -0.012em; text-wrap: balance; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--ink); font-weight: 550;
  white-space: nowrap; /* a wrapped "Approve and send" reads as a broken layout */
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface); }
.btn:active:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn-primary:active:not(:disabled) { background: var(--primary-strong); }
.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
.btn-lg { height: 42px; padding: 0 20px; font-size: 15px; }
.btn-ghost { border-color: transparent; background: none; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface); color: var(--ink); }
.btn.is-busy { color: transparent; position: relative; }
.btn.is-busy::after {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  color: #fff; animation: spin 700ms linear infinite;
}
.btn:not(.btn-primary).is-busy::after { color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }

:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px;
}

/* ---------- fields ---------- */

.field { display: grid; gap: 5px; }
.field > label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  height: 34px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); width: 100%;
  transition: border-color var(--fast) var(--ease);
}
.field textarea { height: auto; padding: 9px 10px; resize: vertical; line-height: 1.5; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: oklch(0.82 0.008 250); }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

/* ---------- sign in ---------- */

.auth {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: var(--surface);
}
.auth-card {
  width: min(400px, 100%); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 28px; box-shadow: var(--shadow);
  display: grid; gap: 16px;
}
.auth-card h1 { font-size: 20px; }
.auth-card p { margin: 0; color: var(--muted); }
.auth-error {
  padding: 9px 12px; border-radius: var(--radius);
  background: var(--danger-soft); color: oklch(0.4 0.14 25); font-weight: 550;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px; height: 56px;
  border-bottom: 1px solid var(--line); background: var(--bg);
  position: sticky; top: 0; z-index: var(--z-sticky);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--primary);
  display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700;
}
.tabs { display: flex; gap: 2px; background: var(--surface); border-radius: var(--radius); padding: 3px; }
.tab {
  border: 0; background: none; color: var(--muted);
  padding: 5px 13px; border-radius: 6px; font-weight: 550; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px;
  transition: color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { background: var(--bg); color: var(--ink); box-shadow: 0 1px 2px oklch(0.2 0.01 250 / 0.08); }
.tab-count {
  min-width: 19px; height: 19px; padding: 0 6px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 700; display: inline-grid; place-items: center;
}
.tab-count.is-live { background: var(--accent); color: #fff; }
.topbar .spacer { flex: 1; }
.user-chip { color: var(--muted); font-size: 13px; white-space: nowrap; }
.linklike { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 0; white-space: nowrap; }
.linklike:hover { color: var(--ink); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }

.view-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.view-head h2 { font-size: 17px; }
.view-head .sub { color: var(--muted); }

/* ---------- needs you ---------- */

.approvals { display: grid; gap: 14px; max-width: 780px; }

.approval {
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--bg); box-shadow: var(--shadow);
  overflow: hidden;
}
.approval-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px; background: var(--accent-soft);
  border-bottom: 1px solid oklch(0.88 0.03 75);
}
.approval-head .what { flex: 1; min-width: 0; }
.approval-head h3 { font-size: 15px; color: oklch(0.32 0.09 62); }
.approval-head .who { color: oklch(0.42 0.06 62); margin-top: 2px; }
.approval-age { color: oklch(0.45 0.05 62); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.approval-why {
  padding: 12px 16px; color: var(--muted);
  border-bottom: 1px solid var(--line); white-space: pre-wrap;
}

.artifact { padding: 14px 16px; display: grid; gap: 10px; }
.artifact-meta {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  font-size: 12px; color: var(--muted);
}
.chan {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-weight: 600; font-size: 11px; letter-spacing: 0.01em;
}
.artifact-subject { font-weight: 650; }
.artifact-body {
  white-space: pre-wrap; line-height: 1.55;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  max-width: 68ch;
}
.artifact textarea {
  width: 100%; min-height: 190px; padding: 12px 14px;
  border: 1px solid var(--primary); border-radius: var(--radius);
  background: var(--bg); line-height: 1.55; resize: vertical;
}

.warn {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--accent-soft); color: oklch(0.36 0.09 62);
  border: 1px solid oklch(0.85 0.05 75);
}
.warn.is-info { background: var(--primary-soft); color: var(--primary-strong); border-color: oklch(0.86 0.05 255); }

.approval-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface);
}
.approval-actions .spacer { flex: 1; }

/* ---------- empty states ---------- */

.empty {
  display: grid; gap: 8px; justify-items: center; text-align: center;
  padding: 56px 24px; border: 1px dashed var(--line); border-radius: var(--radius-lg);
  color: var(--muted); background: var(--surface);
}
.empty h3 { font-size: 16px; color: var(--ink); }
.empty p { margin: 0; max-width: 46ch; }
.empty .tick {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--good-soft); color: var(--good);
  display: grid; place-items: center; margin-bottom: 4px;
}

/* ---------- board ---------- */

/*
 * Nine stages against a pipeline of about ten files means most columns are empty on any
 * given day. A uniform grid spends its width on nothing and pushes the files that are
 * actually in trouble off the right edge. So the board is flex, and an empty stage
 * shrinks to a labelled rail: still visible, still a drop target conceptually, but not
 * taking room from the column with a contingency expiring this week.
 */
.board {
  display: flex; gap: 12px; align-items: flex-start;
  overflow-x: auto; padding-bottom: 10px;
}
.col { display: grid; gap: 8px; align-content: start; flex: 0 1 244px; min-width: 244px; }
.col.is-empty { flex: 0 1 132px; min-width: 132px; }
.col.is-empty .col-body { background: none; border: 1px dashed var(--line); }
.col-head {
  display: flex; align-items: baseline; gap: 7px;
  padding: 0 2px 2px; position: sticky; top: 0;
}
.col-head .name { font-weight: 650; font-size: 13px; }
.col-head .n { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.col-body {
  display: grid; gap: 8px; align-content: start;
  min-height: 60px; padding: 6px; border-radius: var(--radius);
  background: var(--surface);
}
.col-empty { color: var(--muted); font-size: 12px; padding: 10px 6px; }

.file-card {
  display: grid; gap: 6px; text-align: left; width: 100%;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); box-shadow: 0 1px 1px oklch(0.2 0.01 250 / 0.04);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.file-card:hover { border-color: oklch(0.8 0.01 250); box-shadow: var(--shadow); }
.file-card:active { transform: translateY(1px); }
.file-card .name { font-weight: 650; }
.file-card .addr { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 1px; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.pill.is-need { background: var(--accent); color: #fff; }
.pill.is-warn { background: var(--accent-soft); color: oklch(0.4 0.1 62); }
.pill.is-danger { background: var(--danger-soft); color: oklch(0.4 0.14 25); }
.pill.is-good { background: var(--good-soft); color: oklch(0.36 0.1 150); }
.pill.is-paused { background: var(--surface-2); color: var(--muted); }

/* ---------- at risk strip ---------- */

.at-risk { margin-bottom: 18px; }
.at-risk:empty { display: none; }
.risk-row { display: flex; gap: 8px; flex-wrap: wrap; }
.risk {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); text-align: left;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.risk:hover { background: var(--surface); border-color: oklch(0.8 0.01 250); }
.risk .who { font-weight: 650; }
.risk .what { color: var(--muted); font-size: 13px; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--bg); }
table { border-collapse: collapse; width: 100%; min-width: 620px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface); }
td.num { font-variant-numeric: tabular-nums; }
.t-muted { color: var(--muted); }

/* ---------- drawer ---------- */

dialog.drawer {
  margin: 0 0 0 auto; height: 100%; max-height: 100%;
  width: min(620px, 100%); max-width: 100%;
  border: 0; border-left: 1px solid var(--line);
  padding: 0; background: var(--bg); color: var(--ink);
  box-shadow: var(--shadow-lg);
}
dialog.drawer::backdrop { background: oklch(0.2 0.01 250 / 0.35); }
dialog.drawer[open] { animation: slide-in var(--med) var(--ease); }
dialog.drawer[open]::backdrop { animation: fade-in var(--med) var(--ease); }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }

.drawer-inner { display: grid; grid-template-rows: auto auto 1fr; height: 100%; }
.drawer-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { font-size: 17px; }
.drawer-head .meta { color: var(--muted); margin-top: 3px; }
.drawer-tabs { display: flex; gap: 2px; padding: 8px 18px 0; border-bottom: 1px solid var(--line); }
.drawer-tab {
  border: 0; background: none; color: var(--muted); font-weight: 550;
  padding: 7px 11px; border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.drawer-tab:hover { color: var(--ink); }
.drawer-tab[aria-selected="true"] { color: var(--primary-strong); border-bottom-color: var(--primary); }
.drawer-body { overflow-y: auto; padding: 16px 18px 28px; display: grid; gap: 18px; align-content: start; }

.section { display: grid; gap: 9px; }
.section > h3 { font-size: 13px; color: var(--muted); font-weight: 600; }

.doc-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg);
}
.doc-row .label { flex: 1; min-width: 0; }
.doc-row .label small { display: block; color: var(--muted); font-size: 12px; }
.doc-row select { height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; background: var(--bg); }
.doc-row.is-in { background: var(--good-soft); border-color: oklch(0.86 0.04 150); }

.kv { display: grid; grid-template-columns: 148px 1fr; gap: 7px 14px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }

.timeline { display: grid; gap: 0; }
.tl-item { display: grid; grid-template-columns: 92px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.tl-item:last-child { border-bottom: 0; }
.tl-when { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.tl-what { min-width: 0; }
.tl-what .head { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.tl-what .body { color: var(--muted); white-space: pre-wrap; margin-top: 3px; max-width: 62ch; }

.linkbar { display: flex; gap: 8px; flex-wrap: wrap; }
.linkbar a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); font-weight: 550; background: var(--bg);
  transition: background var(--fast) var(--ease);
}
.linkbar a:hover { background: var(--surface); }

/* ---------- live feed ---------- */

.live-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--good); margin-left: 3px; vertical-align: middle;
  box-shadow: 0 0 0 0 color-mix(in oklab, var(--good) 60%, transparent);
  animation: live-pulse 2s var(--ease) infinite;
}
.live-dot.is-stale { background: var(--muted); animation: none; }
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--good) 55%, transparent); }
  70% { box-shadow: 0 0 0 6px color-mix(in oklab, var(--good) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--good) 0%, transparent); }
}

.live-feed { display: grid; gap: 0; max-width: 780px; }
.ev {
  display: grid; grid-template-columns: 18px 1fr auto; gap: 12px; align-items: baseline;
  padding: 11px 4px; border-bottom: 1px solid var(--line);
}
.ev:first-child { animation: ev-in 320ms var(--ease); }
@keyframes ev-in {
  from { opacity: 0; transform: translateY(-6px); background: var(--primary-soft); }
  to { opacity: 1; transform: none; background: transparent; }
}
.ev .dot {
  width: 9px; height: 9px; border-radius: 50%; margin-top: 6px;
  background: var(--muted); grid-row: 1;
}
.ev .dot.desk { background: var(--primary); }
.ev .dot.human { background: var(--accent); }
.ev .dot.inbound { background: var(--good); }
.ev .dot.problem { background: var(--danger); }
.ev .body { min-width: 0; }
.ev .verb { font-weight: 600; }
.ev .detail { color: var(--muted); }
.ev .who {
  display: block; font-size: 12px; color: var(--muted); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ev .when { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.live-empty { color: var(--muted); padding: 40px 4px; }

/* ---------- toast ---------- */

.toast-stack {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: var(--z-toast); display: grid; gap: 8px; width: min(460px, calc(100vw - 32px));
}
.toast {
  padding: 11px 14px; border-radius: var(--radius);
  background: oklch(0.24 0.012 250); color: #fff; box-shadow: var(--shadow-lg);
  animation: toast-in var(--med) var(--ease);
}
.toast.is-bad { background: oklch(0.42 0.15 25); }
.toast.is-good { background: oklch(0.36 0.1 150); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- skeleton ---------- */

.skel { display: grid; gap: 12px; max-width: 780px; }
.skel-card { height: 128px; border-radius: var(--radius-lg); background: var(--surface); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------- stat strip ---------- */

.stats { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { display: grid; gap: 1px; }
.stat .n { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat .l { color: var(--muted); font-size: 12px; }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  main { padding: 14px; }
  .topbar { padding: 0 12px; gap: 10px; height: 52px; overflow-x: auto; }
  .brand span:not(.brand-mark) { display: none; }
  .user-chip { display: none; }
  .board { grid-auto-flow: row; grid-auto-columns: auto; }
  .col-head { position: static; }
  .approval-actions .btn { flex: 1; min-width: 128px; }
}

/*
 * Phone. This is the surface Charles actually uses, standing in a driveway, so the
 * primary action gets the full width and its own row rather than competing with Decline
 * for space. Approve should never be the same size as the thing that throws work away.
 */
@media (max-width: 560px) {
  .approval-actions {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  }
  .approval-actions .btn { min-width: 0; height: 42px; }
  .approval-actions .btn-primary { grid-column: 1 / -1; }
  .approval-actions .spacer { display: none; }
  .topbar { gap: 8px; }
  .tabs { flex: none; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 7px; }
  .tl-item { grid-template-columns: 1fr; gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important; animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

/* ---------- playbook ---------- */
.playbook-card { margin-bottom: 8px; cursor: pointer; }
.playbook-doc {
  max-width: 720px; margin-top: 12px; padding: 18px 20px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
  line-height: 1.55; font-size: 14px;
}
.playbook-doc h2 { font-size: 19px; margin: 0 0 4px; }
.playbook-doc h3 { font-size: 15px; margin: 18px 0 6px; }
.playbook-doc h4 { font-size: 13.5px; margin: 14px 0 4px; }
.playbook-doc p { margin: 6px 0; }
.playbook-doc ul { margin: 6px 0; padding-left: 20px; }
.playbook-doc li { margin: 3px 0; }
.playbook-doc li.nested { margin-left: 16px; list-style-type: circle; }
.playbook-doc hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.know-list { margin: 4px 0 0; padding-left: 18px; }
.know-list li { margin: 4px 0; font-size: 13px; line-height: 1.45; }
