:root {
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --panel: #ffffff;
  --brand: #0d9488;
  --brand-deep: #0f766e;
  --brand-soft: #ccfbf1;
  --green: #16a34a;
  --green-deep: #15803d;
  --amber: #d97706;
  --red: #dc2626;
  --blue: #2563eb;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(13,148,136,0.08), transparent 28%),
    var(--bg);
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--brand-deep); }

.app-shell { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: rgba(255,255,255,0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--brand), #115e59);
  color: white;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 800;
}
.brand small { display: block; color: var(--muted); font-weight: 500; font-size: 0.75rem; }
.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.main {
  width: min(1180px, calc(100% - 2rem));
  margin: 1.25rem auto 2.5rem;
  flex: 1;
}

.view { display: none; animation: fade 0.18s ease; }
.view.active { display: block; }
.wizard-step { display: none; }
.wizard-step.active { display: block; }
.detail-pane { display: none; }
.detail-pane.active { display: block; }
@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1.35rem;
}
.panel + .panel { margin-top: 1rem; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.panel-head h2, .panel-head h3 { margin: 0; letter-spacing: -0.02em; }
.panel-head p { margin: 0.35rem 0 0; color: var(--muted); }

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.05rem;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: 0.12s ease;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-deep)); color: white; }
.btn-green { background: linear-gradient(135deg, #22c55e, var(--green-deep)); color: white; }
.btn-secondary { background: white; border: 1px solid var(--line); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-danger { background: #fef2f2; color: var(--red); border: 1px solid #fecaca; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.88rem; }
.btn-lg { padding: 0.85rem 1.3rem; font-size: 1rem; }
.btn:hover:not(:disabled) { filter: brightness(1.03); transform: translateY(-1px); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }

.field { display: flex; flex-direction: column; gap: 0.35rem; position: relative; }
.field label {
  font-size: 0.86rem;
  font-weight: 650;
  color: var(--ink-soft);
}
.field input, .field select, .field textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  background: #fff;
  outline: none;
  transition: 0.12s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(13,148,136,0.15);
}
.field textarea { min-height: 96px; resize: vertical; }
.hint { color: var(--muted); font-size: 0.8rem; }
.error-text { color: var(--red); font-size: 0.85rem; }

.bubble {
  position: absolute;
  z-index: 5;
  left: calc(100% + 10px);
  top: 1.6rem;
  width: min(280px, 40vw);
  background: #0f172a;
  color: #f8fafc;
  border-radius: 14px;
  padding: 0.85rem 0.95rem;
  font-size: 0.86rem;
  box-shadow: 0 16px 40px rgba(15,23,42,0.25);
  display: none;
}
.bubble::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 16px;
  width: 12px;
  height: 12px;
  background: #0f172a;
  transform: rotate(45deg);
}
.field:focus-within .bubble, .field.show-tip .bubble { display: block; }
.bubble strong { display: block; margin-bottom: 0.25rem; color: #5eead4; }

.strength {
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}
.strength > i {
  display: block;
  height: 100%;
  width: 0%;
  transition: 0.15s ease;
  background: #ef4444;
}
.strength.ok > i { background: #f59e0b; }
.strength.good > i { background: #22c55e; }
.strength.strong > i { background: #0d9488; }

.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
  margin-bottom: 1rem;
}
.stat {
  background: linear-gradient(180deg, #fff, #f8fafc);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.95rem;
}
.stat .label { color: var(--muted); font-size: 0.8rem; }
.stat .value { font-size: 1.35rem; font-weight: 750; letter-spacing: -0.03em; margin-top: 0.2rem; }

.table-wrap { overflow: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
table.data th, table.data td {
  text-align: left;
  padding: 0.75rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data th { color: var(--muted); font-weight: 650; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
table.data tr:hover td { background: #f8fafc; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
  background: #e2e8f0;
  color: #334155;
  white-space: nowrap;
}
.badge.draft { background: #e2e8f0; }
.badge.application { background: #dbeafe; color: #1d4ed8; }
.badge.committee_review, .badge.committee_decision { background: #fef3c7; color: #b45309; }
.badge.approved, .badge.funding { background: #ccfbf1; color: #0f766e; }
.badge.pending_signatures { background: #ffedd5; color: #c2410c; }
.badge.disbursement { background: #e0e7ff; color: #3730a3; }

/* Pipeline status stepper */
.pipeline {
  display: flex;
  align-items: flex-start;
  gap: 0;
  overflow-x: auto;
  padding: 1rem 0.25rem 1.5rem;
}
.pipeline-step {
  flex: 1;
  min-width: 110px;
  text-align: center;
  position: relative;
  cursor: pointer;
  padding: 0 0.25rem;
}
.pipeline-step:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 14px;
  left: calc(50% + 16px);
  width: calc(100% - 32px);
  height: 3px;
  background: #e2e8f0;
  z-index: 0;
}
.pipeline-step.complete:not(:last-child)::after {
  background: #22c55e;
}
.pipeline-step.current:not(:last-child)::after {
  background: linear-gradient(90deg, #22c55e, #fbbf24);
}
.pipeline-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin: 0 auto 0.45rem;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 800;
  position: relative;
  z-index: 1;
  border: 3px solid #cbd5e1;
  background: #f1f5f9;
  color: #64748b;
}
.pipeline-step.complete .pipeline-dot {
  background: #16a34a;
  border-color: #15803d;
  color: white;
}
.pipeline-step.current .pipeline-dot {
  background: #fbbf24;
  border-color: #d97706;
  color: #1c1917;
  box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.35);
}
.pipeline-step.locked .pipeline-dot {
  background: #0f766e;
  border-color: #115e59;
  color: white;
}
.pipeline-step.pending .pipeline-dot {
  background: #e2e8f0;
  border-color: #cbd5e1;
}
.pipeline-step.active-detail {
  outline: 2px solid rgba(13, 148, 136, 0.35);
  border-radius: 12px;
  background: rgba(204, 251, 241, 0.25);
}
.pipeline-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1.25;
}
.pipeline-meta {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.2rem;
}
.pipeline-step.current .pipeline-title { color: #b45309; }
.badge.active { background: #dcfce7; color: #15803d; }
.badge.declined, .badge.defaulted, .badge.charged_off { background: #fee2e2; color: #b91c1c; }
.badge.paid_off { background: #ede9fe; color: #6d28d9; }

.steps {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.step-pill {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: #e2e8f0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}
.step-pill.on { background: var(--brand-soft); color: var(--brand-deep); }
.step-pill.done { background: #dcfce7; color: #15803d; }

.tabs {
  display: flex;
  gap: 0.35rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.tab {
  border: none;
  background: transparent;
  padding: 0.7rem 0.95rem;
  color: var(--muted);
  font-weight: 650;
  border-bottom: 2px solid transparent;
  border-radius: 0;
}
.tab.active { color: var(--brand-deep); border-bottom-color: var(--brand); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(520px, 100%);
  background: white;
  border-radius: 18px;
  padding: 1.4rem;
  box-shadow: 0 30px 80px rgba(15,23,42,0.28);
}
.modal.wide { width: min(920px, 100%); max-height: 90vh; overflow: auto; }
.modal h3 { margin: 0 0 0.5rem; }
.modal p { color: var(--ink-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.1rem; }

.hero-lite {
  background: linear-gradient(135deg, #0f766e, #115e59 45%, #0f172a);
  color: white;
  border-radius: 20px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.hero-lite h1 { margin: 0 0 0.35rem; font-size: clamp(1.5rem, 2.5vw, 2rem); letter-spacing: -0.03em; }
.hero-lite p { margin: 0; opacity: 0.9; }

.auth-wrap {
  min-height: calc(100vh - 70px);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.auth-card {
  width: min(560px, 100%);
}
.center { text-align: center; }
.muted { color: var(--muted); }
.success-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #dcfce7;
  color: #15803d;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  margin: 0 auto 0.8rem;
}

.progress-bar {
  height: 10px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--brand), #22c55e);
}

.report {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.5rem;
}
.report h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.report .meta { color: var(--muted); margin-bottom: 1rem; font-size: 0.9rem; }
.report h2 { font-size: 1.05rem; margin: 1.2rem 0 0.45rem; border-bottom: 1px solid var(--line); padding-bottom: 0.35rem; }
.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1.25rem;
}
.kv { font-size: 0.92rem; }
.kv span { display: block; color: var(--muted); font-size: 0.78rem; }
.callout {
  background: #f8fafc;
  border-left: 4px solid var(--brand);
  padding: 0.85rem 1rem;
  border-radius: 0 12px 12px 0;
  margin: 0.75rem 0;
}

.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}
.split-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.alert {
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
  margin: 0.5rem 0;
}
.alert.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert.info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
.alert.ok { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }

.money { font-variant-numeric: tabular-nums; font-weight: 650; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.88rem; }

@media (max-width: 960px) {
  .grid-2, .grid-3, .stat-cards, .report-grid { grid-template-columns: 1fr; }
  .bubble {
    position: static;
    width: 100%;
    margin-top: 0.35rem;
    display: none;
  }
  .field:focus-within .bubble { display: block; }
  .bubble::before { display: none; }
}
