/* ─── Design tokens ─────────────────────────────────────────── */
:root {
  --bg:        #0F1117;
  --surface:   #181B24;
  --surface2:  #1F2330;
  --border:    #2A2F3F;
  --text:      #E8EAF0;
  --muted:     #6B7280;
  --brass:     #C8922A;
  --brass-dim: #8A6420;
  --green:     #2ECC71;
  --yellow:    #F39C12;
  --red:       #E74C3C;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --radius:    6px;
  --transition: 150ms ease;
}

/* ─── Reset & base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--brass); text-decoration: none; }
a:hover { color: #E0A030; }

/* ─── Layout ────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 48px 1fr;
  min-height: 100vh;
}

.app-topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-logo {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass);
}

.app-logo span { color: var(--muted); }

.app-nav {
  grid-row: 2;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  border-left: 2px solid transparent;
}

.nav-link:hover { color: var(--text); background: var(--surface2); }
.nav-link.active { color: var(--brass); border-left-color: var(--brass); background: rgba(200,146,42,0.08); }
.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; }

.nav-section {
  padding: 18px 18px 6px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.app-main {
  grid-row: 2;
  overflow-y: auto;
  padding: 28px 32px;
}

/* ─── Page titles ───────────────────────────────────────────── */
.page-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.page-subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 24px;
}

/* ─── Panels & cards ────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.panel-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 16px;
}

/* ─── Signature element: metric tape ───────────────────────── */
/* Reads like a cash register receipt — key numbers in a row */
.metric-tape {
  display: flex;
  gap: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}

.metric-tape-item {
  flex: 1;
  padding: 14px 16px;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.metric-tape-item:last-child { border-right: none; }

.metric-tape-item.highlight { background: rgba(200,146,42,0.07); }

.metric-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

.metric-value.good  { color: var(--green); }
.metric-value.warn  { color: var(--yellow); }
.metric-value.bad   { color: var(--red); }
.metric-value.brass { color: var(--brass); }

.metric-sub {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ─── Flags ─────────────────────────────────────────────────── */
.flag-list { display: flex; flex-direction: column; gap: 6px; }

.flag {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.82rem;
  line-height: 1.4;
}

.flag-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.flag.green .flag-dot { background: var(--green); }
.flag.yellow .flag-dot { background: var(--yellow); }
.flag.red .flag-dot { background: var(--red); }
.flag.green { color: var(--text); }
.flag.yellow { color: var(--yellow); }
.flag.red { color: var(--red); }

/* ─── Pipeline table ────────────────────────────────────────── */
.pipeline-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.pipeline-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.pipeline-table th:hover { color: var(--text); }
.pipeline-table th.sorted { color: var(--brass); }

.pipeline-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.pipeline-table tr:hover td { background: var(--surface2); cursor: pointer; }

.pipeline-table .mono { font-family: var(--font-mono); font-size: 0.82rem; }

/* ─── Status badge ──────────────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.status-sourced    { background: rgba(107,114,128,0.2); color: var(--muted); }
.status-reviewing  { background: rgba(200,146,42,0.15); color: var(--brass); }
.status-broker-qs  { background: rgba(52,152,219,0.15); color: #5DADE2; }
.status-loi        { background: rgba(155,89,182,0.15); color: #A569BD; }
.status-diligence  { background: rgba(241,196,15,0.15); color: #F4D03F; }
.status-passed     { background: rgba(231,76,60,0.12);  color: var(--red); }
.status-closed     { background: rgba(46,204,113,0.15); color: var(--green); }

/* ─── Forms & inputs ────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

.field { display: flex; flex-direction: column; gap: 5px; }

.field label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 8px 10px;
  transition: border-color var(--transition);
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brass);
}

.field input[type="number"] { font-family: var(--font-mono); }
.field textarea { resize: vertical; min-height: 80px; }

.field-hint {
  font-size: 0.72rem;
  color: var(--muted);
}

/* ─── Sliders ───────────────────────────────────────────────── */
.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.slider-label {
  font-size: 0.78rem;
  color: var(--muted);
  width: 140px;
  flex-shrink: 0;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--brass);
  cursor: pointer;
}

.slider-value {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--brass);
  width: 72px;
  text-align: right;
  flex-shrink: 0;
}

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: var(--brass);
  color: #0F1117;
  border-color: var(--brass);
}

.btn-primary:hover { background: #E0A030; border-color: #E0A030; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover { border-color: var(--muted); background: var(--surface2); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: rgba(231,76,60,0.3);
}

.btn-danger:hover { background: rgba(231,76,60,0.1); }

.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── Projection table ──────────────────────────────────────── */
.proj-table-wrap { overflow-x: auto; }

.proj-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-family: var(--font-mono);
}

.proj-table th {
  text-align: right;
  padding: 6px 10px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.proj-table th:first-child { text-align: left; }

.proj-table td {
  padding: 7px 10px;
  text-align: right;
  border-bottom: 1px solid rgba(42,47,63,0.5);
}

.proj-table td:first-child { text-align: left; color: var(--muted); }
.proj-table tr:hover td { background: var(--surface2); }

.proj-table .renewal-row td { color: var(--muted); font-style: italic; }
.proj-table .loan-risk td { background: rgba(231,76,60,0.05); }
.proj-table .loan-risk td:first-child::after { content: ' ⚠'; color: var(--red); font-style: normal; }

/* ─── Grid sensitivity ──────────────────────────────────────── */
.irr-grid {
  display: grid;
  gap: 2px;
}

.irr-cell {
  padding: 8px 6px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  border-radius: 3px;
  background: var(--surface2);
}

.irr-cell.header { background: transparent; color: var(--muted); font-size: 0.7rem; }
.irr-cell.row-header { text-align: left; background: transparent; color: var(--muted); }
.irr-cell.low    { background: rgba(231,76,60,0.18);  color: var(--red); }
.irr-cell.mid    { background: rgba(243,156,18,0.15); color: var(--yellow); }
.irr-cell.high   { background: rgba(46,204,113,0.15); color: var(--green); }

/* ─── Stress table ──────────────────────────────────────────── */
.stress-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
.stress-table th, .stress-table td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--border); }
.stress-table th { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stress-table td:first-child { text-align: left; color: var(--text); font-style: normal; }
.stress-table .base-row td { color: var(--brass); }
.stress-table .mono { font-family: var(--font-mono); }

/* ─── Notes & checklist ─────────────────────────────────────── */
.note-list { display: flex; flex-direction: column; gap: 10px; }

.note-item {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 0.85rem;
}

.note-meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.checklist { display: flex; flex-direction: column; gap: 6px; }

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.84rem;
  cursor: pointer;
}

.checklist-item input[type="checkbox"] { accent-color: var(--brass); margin-top: 3px; flex-shrink: 0; }
.checklist-item.done { color: var(--muted); text-decoration: line-through; }

/* ─── Compare view ──────────────────────────────────────────── */
.compare-grid {
  display: grid;
  grid-template-columns: 140px repeat(var(--compare-cols, 2), 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.compare-cell {
  background: var(--surface);
  padding: 10px 14px;
  font-size: 0.83rem;
}

.compare-cell.header {
  background: var(--surface2);
  font-weight: 600;
  font-size: 0.82rem;
}

.compare-cell.row-label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface2);
}

.compare-cell .mono { font-family: var(--font-mono); }

/* ─── Tabs ──────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 10px 18px;
  font-size: 0.84rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition), border-color var(--transition);
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--brass); border-bottom-color: var(--brass); }

/* ─── Toast / notifications ─────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 0.84rem;
  max-width: 320px;
  animation: slide-in 200ms ease;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }

@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ─── Loading states ────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--brass);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ─── Empty states ──────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.empty-state h3 { font-size: 1rem; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 0.85rem; margin-bottom: 20px; }

/* ─── Intake steps ──────────────────────────────────────────── */
.intake-step { display: none; }
.intake-step.active { display: block; }

.step-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.step-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.step-dot.active { background: var(--brass); color: #0F1117; border-color: var(--brass); }
.step-dot.done   { background: var(--surface2); color: var(--green); border-color: var(--green); }

.step-line { flex: 1; height: 1px; background: var(--border); }

/* ─── Toggle ────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.toggle {
  position: relative;
  width: 36px; height: 20px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  transition: background var(--transition);
}

.toggle input:checked ~ .toggle-track { background: var(--brass-dim); border-color: var(--brass); }

.toggle-thumb {
  position: absolute;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--muted);
  top: 2px; left: 2px;
  transition: all var(--transition);
}

.toggle input:checked ~ .toggle-thumb { left: 18px; background: var(--brass); }

/* ─── Utility ───────────────────────────────────────────────── */
.text-muted { color: var(--muted); }
.text-brass { color: var(--brass); }
.text-mono  { font-family: var(--font-mono); }
.text-right { text-align: right; }

.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--surface2);
  color: var(--muted);
}

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 48px auto 1fr; }
  .app-nav { grid-row: auto; flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 0; }
  .nav-link { padding: 12px 14px; border-left: none; border-bottom: 2px solid transparent; }
  .nav-link.active { border-bottom-color: var(--brass); border-left-color: transparent; background: transparent; }
  .nav-section { display: none; }
  .app-main { padding: 18px 16px; }
  .metric-tape { flex-wrap: wrap; }
  .metric-tape-item { min-width: 120px; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
}
