/* ============================================================
   MORTGAGE MATRIX — Control Center
   Dark "terminal" theme built on CLO$ED visual tokens.
   (Visual DNA only: type, money-green, gold hairlines, 0 radius.
    Product copy is professional fintech, not streetwear.)
   ============================================================ */

:root {
  /* ----- Surfaces (dark terminal) ----- */
  --bg-0:     #0A0A0A;          /* app base */
  --bg-1:     #121211;          /* panels */
  --bg-2:     #181816;          /* raised rows / inputs */
  --bg-3:     #201F1C;          /* hover / active row */
  --sidebar:  #0C0C0B;

  /* ----- Ink (warm cream) ----- */
  --ink:       #F5F0E8;
  --ink-soft:  rgba(245,240,232,0.62);
  --ink-faint: rgba(245,240,232,0.40);
  --ink-ghost: rgba(245,240,232,0.22);

  /* ----- Hairlines (warm — cream + gold, never gray) ----- */
  --line:        rgba(245,240,232,0.09);
  --line-2:      rgba(245,240,232,0.15);
  --gold:        #C9A96E;
  --gold-line:   rgba(201,169,110,0.30);
  --gold-strong: rgba(201,169,110,0.55);

  /* ----- Brand green ----- */
  --green:       #2D5A3D;       /* fills / primary button */
  --green-deep:  #234730;
  --green-lift:  #5FB079;       /* dots + status text on dark */
  --green-glow:  rgba(95,176,121,0.18);

  /* ----- Status language ----- */
  --st-pending:  #C9A96E;       /* draft / awaiting approval */
  --st-pending-bg: rgba(201,169,110,0.12);
  --st-sent:     #5FB079;       /* approved / sent */
  --st-sent-bg:  rgba(95,176,121,0.12);
  --st-reject:   #C0524F;       /* rejected (oxblood, lifted) */
  --st-reject-bg: rgba(192,82,79,0.12);
  --st-stale:    rgba(245,240,232,0.42); /* cold / stale */
  --st-stale-bg: rgba(245,240,232,0.06);
  --oxblood:     #8B0000;

  /* ----- Type ----- */
  --font-display: "Bebas Neue", "Oswald", Arial, sans-serif;
  --font-mono:    "DM Mono", ui-monospace, Menlo, Consolas, monospace;
  --font-body:    "Inter", "Helvetica Neue", Arial, sans-serif;

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  --rail: 232px;       /* sidebar width */
  --topbar-h: 60px;
}

/* ============ LIGHT THEME (tweak / toggle) ============ */
.theme-light {
  --bg-0:    #F5F0E8;
  --bg-1:    #FBF8F2;
  --bg-2:    #EFE9DE;
  --bg-3:    #E7DFD1;
  --sidebar: #EFE9DE;
  --ink:       #0A0A0A;
  --ink-soft:  rgba(10,10,10,0.60);
  --ink-faint: rgba(10,10,10,0.42);
  --ink-ghost: rgba(10,10,10,0.20);
  --line:    rgba(10,10,10,0.10);
  --line-2:  rgba(10,10,10,0.16);
  --gold-line: rgba(201,169,110,0.50);
  --gold-strong: rgba(201,169,110,0.75);
  --green-lift: #2D5A3D;
  --st-sent:   #2D5A3D;
  --st-stale:  rgba(10,10,10,0.40);
  --st-stale-bg: rgba(10,10,10,0.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--green); color: var(--ink); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); }
::-webkit-scrollbar-track { background: transparent; }
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ---------- Type helpers ---------- */
.display { font-family: var(--font-display); font-weight: 400; letter-spacing: 0.02em; line-height: 0.9; margin: 0; }
.mono { font-family: var(--font-mono); }
.eyebrow {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--ink-faint);
}
.label {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.16em;
  text-transform: uppercase;
}
.num { font-family: var(--font-display); letter-spacing: 0.01em; }
.logo { font-family: var(--font-display); letter-spacing: 0.05em; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-0);
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 0 18px; height: var(--topbar-h);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0; overflow: hidden;
}
.brand-mark {
  width: 26px; height: 26px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--green); color: var(--ink);
  font-family: var(--font-display); font-size: 20px; line-height: 1;
}
.brand-name { font-family: var(--font-display); font-size: 26px; letter-spacing: 0.04em; white-space: nowrap; }
.brand-name .dollar { color: var(--green-lift); }
.brand-kicker { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.26em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 2px; }
.brand-sub { font-family: var(--font-mono); font-size: 8px; letter-spacing: 0.24em; color: var(--ink-faint); text-transform: uppercase; }

.nav { padding: 12px 10px; overflow-y: auto; flex: 1; min-height: 0; }
.nav-group-label { padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; color: var(--ink-soft);
  border: 1px solid transparent;
  position: relative; user-select: none;
  transition: background var(--ease) .15s, color var(--ease) .15s;
}
.nav-item:hover { background: var(--bg-2); color: var(--ink); }
.nav-item.active { background: var(--bg-2); color: var(--ink); border-color: var(--line); }
.nav-item.active::before {
  content: ""; position: absolute; left: -10px; top: 6px; bottom: 6px;
  width: 2px; background: var(--green-lift);
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; stroke-width: 1.5; }
.nav-item .nav-text { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.04em; flex: 1; }
.nav-badge {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.04em;
  min-width: 18px; height: 18px; padding: 0 5px;
  display: grid; place-items: center; border-radius: 999px;
  background: var(--bg-3); color: var(--ink-soft);
}
.nav-badge.hot { background: var(--green); color: var(--ink); }
.nav-badge.warn { background: var(--st-pending-bg); color: var(--st-pending); }

.sidebar-foot {
  border-top: 1px solid var(--line); padding: 12px 14px; flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 999px;
  background: var(--bg-3); border: 1px solid var(--gold-line);
  display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 11px; color: var(--ink); letter-spacing: 0.02em;
}

/* ---------- Main column ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--bg-0) 78%, transparent);
  backdrop-filter: blur(12px);
}
.topbar .page-title { font-family: var(--font-display); font-size: 26px; letter-spacing: 0.04em; white-space: nowrap; flex-shrink: 0; }
.topbar-spacer { flex: 1; }

.search {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-1); border: 1px solid var(--line);
  padding: 7px 12px; width: 280px; max-width: 30vw; min-width: 0; color: var(--ink-faint);
}
.search svg { flex-shrink: 0; }
.search input { min-width: 0; }
.search input {
  background: transparent; border: none; outline: none; flex: 1;
  color: var(--ink); font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.02em;
}
.search input::placeholder { color: var(--ink-faint); }
.search kbd {
  font-family: var(--font-mono); font-size: 10px; padding: 1px 5px;
  border: 1px solid var(--line-2); color: var(--ink-faint);
}

.approval-pill {
  display: flex; align-items: center; gap: 9px;
  background: var(--green); color: var(--ink);
  padding: 8px 14px; border: 1px solid var(--green);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  transition: background var(--ease) .2s, transform var(--ease) .2s;
}
.approval-pill:hover { background: var(--green-deep); transform: translateY(-1px); }
.approval-pill .count { font-family: var(--font-display); font-size: 17px; letter-spacing: 0; }
.approval-pill.zero { background: transparent; color: var(--ink-soft); border-color: var(--line-2); }

.icon-btn {
  width: 36px; height: 36px; flex-shrink: 0;
  display: grid; place-items: center;
  background: transparent; border: 1px solid var(--line); color: var(--ink-soft);
  transition: border-color var(--ease) .15s, color var(--ease) .15s, background var(--ease) .15s;
}
.icon-btn:hover { border-color: var(--gold-line); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; stroke-width: 1.5; }

.scroll-area { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; min-width: 0; }
.page { padding: 26px 28px 60px; max-width: 1440px; }
.page.narrow { max-width: 1080px; }

/* ---------- Section head ---------- */
.sec-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; padding-bottom: 12px; margin-bottom: 18px;
  border-bottom: 1px solid var(--gold-line);
}
.sec-head .display { font-size: 34px; }
.sec-head .sec-meta { text-align: right; }

/* ---------- Panels ---------- */
.panel { background: var(--bg-1); border: 1px solid var(--line); }
.panel-pad { padding: 18px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  padding: 10px 16px; border: 1px solid var(--line-2); background: transparent; color: var(--ink);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  transition: all var(--ease) .18s; white-space: nowrap;
}
.btn:hover { border-color: var(--gold-line); }
.btn.primary { background: var(--green); border-color: var(--green); color: var(--ink); }
.btn.primary:hover { background: var(--green-deep); transform: translateY(-1px); }
.btn.danger { color: var(--st-reject); border-color: rgba(192,82,79,0.4); }
.btn.danger:hover { background: var(--st-reject-bg); border-color: var(--st-reject); }
.btn.ghost-gold { color: var(--gold); border-color: var(--gold-line); }
.btn.ghost-gold:hover { background: rgba(201,169,110,0.1); }
.btn.sm { padding: 7px 11px; font-size: 10px; letter-spacing: 0.1em; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn .k {
  font-family: var(--font-mono); font-size: 9px; padding: 1px 4px;
  border: 1px solid currentColor; opacity: 0.7; border-radius: 2px;
}

.arrow-tail { display: inline-block; width: 16px; height: 1px; background: currentColor; position: relative; transition: width var(--ease) .2s; }
.arrow-tail::after { content:""; position:absolute; right:0; top:-3px; width:7px; height:7px; border-top:1px solid currentColor; border-right:1px solid currentColor; transform: rotate(45deg) translate(-1px,1px); }
.btn:hover .arrow-tail { width: 26px; }

/* ---------- Status pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase;
  padding: 4px 8px; border: 1px solid var(--line-2); color: var(--ink-soft); white-space: nowrap;
}
.pill .dot { width: 5px; height: 5px; border-radius: 999px; background: currentColor; }
.pill.pending { color: var(--st-pending); border-color: rgba(201,169,110,0.4); background: var(--st-pending-bg); }
.pill.sent    { color: var(--st-sent); border-color: rgba(95,176,121,0.4); background: var(--st-sent-bg); }
.pill.reject  { color: var(--st-reject); border-color: rgba(192,82,79,0.4); background: var(--st-reject-bg); }
.pill.stale   { color: var(--st-stale); border-color: var(--line-2); background: var(--st-stale-bg); }
.pill.plain   { color: var(--ink-soft); }
.pill.gold    { color: var(--gold); border-color: var(--gold-line); }

/* channel chip */
.chan {
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.18em; text-transform: uppercase;
  padding: 3px 7px; border: 1px solid var(--line-2); color: var(--ink-faint);
}
.chan.sms { color: var(--green-lift); border-color: rgba(95,176,121,0.35); }
.chan.email { color: var(--gold); border-color: var(--gold-line); }

/* ---------- Live dot ---------- */
.live-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--green-lift); position: relative; }
.live-dot::after {
  content:""; position: absolute; inset: -4px; border-radius: 999px;
  border: 1px solid var(--green-lift); animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse { 0%{ transform: scale(0.6); opacity: 0.9;} 100%{ transform: scale(1.6); opacity: 0;} }
.unread-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--green-lift); flex-shrink: 0; }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.stat {
  background: var(--bg-1); padding: 18px; display: flex; flex-direction: column; gap: 8px;
  transition: background var(--ease) .15s; cursor: pointer; position: relative;
}
.stat:hover { background: var(--bg-2); }
.stat .stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat .stat-val { font-family: var(--font-display); font-size: 50px; line-height: 0.85; }
.stat .stat-foot { display: flex; align-items: center; gap: 7px; }
.stat.accent .stat-val { color: var(--green-lift); }

/* ---------- Forms ---------- */
.field {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line-2); color: var(--ink);
  padding: 11px 13px; font-family: var(--font-body); font-size: 14px; outline: none;
  transition: border-color var(--ease) .15s;
}
.field:focus { border-color: var(--gold-line); }
.field::placeholder { color: var(--ink-faint); }
textarea.field { resize: vertical; line-height: 1.55; }
.field.mono { font-family: var(--font-mono); font-size: 13px; letter-spacing: 0.02em; }

/* ---------- Toggle switch ---------- */
.switch { width: 38px; height: 21px; border-radius: 999px; background: var(--bg-3); border: 1px solid var(--line-2); position: relative; transition: all var(--ease) .2s; flex-shrink: 0; }
.switch::after { content:""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 999px; background: var(--ink-faint); transition: all var(--ease) .2s; }
.switch.on { background: var(--green); border-color: var(--green); }
.switch.on::after { left: 19px; background: var(--ink); }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--bg-2); border: 1px solid var(--gold-line);
  border-left: 2px solid var(--green-lift);
  padding: 13px 16px; min-width: 290px; max-width: 360px;
  display: flex; gap: 12px; align-items: flex-start;
  animation: toastIn .4s var(--ease);
}
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.out { animation: toastOut .35s var(--ease) forwards; }
@keyframes toastOut { to { transform: translateX(20px); opacity: 0; } }

/* ---------- Empty states ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; padding: 70px 20px; }
.empty .empty-mark { width: 56px; height: 56px; display: grid; place-items: center; border: 1px solid var(--gold-line); color: var(--green-lift); }

/* ---------- kbd hints ---------- */
.kbd {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.06em;
  min-width: 18px; padding: 2px 6px; text-align: center;
  border: 1px solid var(--line-2); color: var(--ink-soft); background: var(--bg-2);
}

/* meta row */
.meta-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.meta-row .m { display: flex; align-items: center; gap: 6px; }
.dotsep { width: 3px; height: 3px; border-radius: 999px; background: var(--ink-ghost); }

.hide-scroll { scrollbar-width: none; }
.hide-scroll::-webkit-scrollbar { display: none; }

/* reveal-in for streamed items */
@keyframes slideIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
.slide-in { animation: slideIn .45s var(--ease) both; }

/* approvals triage motion */
@keyframes flyRight { to { transform: translateX(60%) rotate(4deg); opacity: 0; } }
@keyframes flyLeft  { to { transform: translateX(-60%) rotate(-4deg); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin .9s linear infinite; }
.panel.peek { transition: all .3s var(--ease); }

/* ---------- Email message rendering (sanitized HTML on a white canvas) ---------- */
.email-body {
  background: #ffffff; color: #1a1a1a;
  border: 1px solid var(--line-2);
  padding: 14px 16px; max-height: 460px; overflow: auto;
  font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 1.5;
}
.email-body img { max-width: 100%; height: auto; }
.email-body table { max-width: 100%; }
.email-body a { color: #0a58ca; word-break: break-word; }
.email-body p { margin: 0 0 8px; }
.email-body * { max-width: 100%; }
