/* UpScale design system. Colours, fonts, radii, spacing and shadows come from tokens.css. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font: 400 16px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--c-primary); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--c-primary) 55%, transparent); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Type scale */
.display { font: 700 32px/1.1 var(--font-display); letter-spacing: -0.02em; margin: 0; }
.title { font: 700 22px/1.2 var(--font-display); letter-spacing: -0.01em; margin: 0; }
.subtitle { font: 600 17px/1.3 var(--font-display); margin: 0; }
.body-soft { color: var(--c-text-soft); margin: 0; }
.caption { font-size: 13px; line-height: 1.4; color: var(--c-text-soft); margin: 0; }
.eyebrow { font: 700 12px/1 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--c-accent); margin: 0 0 var(--space-2); }
.mono { font-family: var(--font-mono); font-size: 13px; }

/* Shell */
.shell { min-height: 100vh; min-height: 100dvh; }
.rail, .detail { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--space-3);
  padding: calc(env(safe-area-inset-top) + 10px) var(--space-4) 10px;
  background: color-mix(in srgb, var(--c-bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--c-line);
}
.topbar .where { flex: 1; min-width: 0; }
.topbar .where strong { display: block; font: 700 17px/1.2 var(--font-display); }
.topbar .where span { font-size: 12px; color: var(--c-text-soft); }
.brandmark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--c-primary); color: var(--c-on-primary); flex: none;
}
.brandmark svg { width: 20px; height: 20px; }
.main { padding: var(--space-4) var(--space-4) calc(150px + env(safe-area-inset-bottom)); max-width: 680px; margin: 0 auto; }
.screen { display: grid; gap: var(--space-4); animation: rise .28s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--c-surface) 94%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--c-line);
}
.tab {
  display: grid; justify-items: center; gap: 2px; min-height: 52px; padding: 6px 2px;
  border: 0; background: none; border-radius: 12px; cursor: pointer;
  color: var(--c-text-soft); font-size: 11px; font-weight: 600; text-decoration: none;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--c-primary); background: color-mix(in srgb, var(--c-primary) 10%, transparent); }

/* Sticky action above the tab bar on phones */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: calc(70px + env(safe-area-inset-bottom)); z-index: 25;
  padding: 10px var(--space-4);
  background: linear-gradient(to top, var(--c-bg) 60%, transparent);
}
.actionbar .btn { width: 100%; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 48px; padding: 0 var(--space-5); border-radius: var(--r-control);
  border: 1px solid transparent; font-weight: 700; font-size: 16px; cursor: pointer; text-decoration: none;
  transition: transform .12s var(--ease), background-color .2s var(--ease), box-shadow .2s var(--ease), opacity .2s;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--c-primary); color: var(--c-on-primary); box-shadow: var(--shadow-1); }
.btn.primary:hover:not(:disabled) { box-shadow: var(--shadow-2); filter: brightness(1.05); }
.btn.secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-line); }
.btn.secondary:hover { border-color: var(--c-primary); }
.btn.ghost { background: transparent; color: var(--c-primary); padding: 0 var(--space-3); }
.btn.ghost:hover { background: color-mix(in srgb, var(--c-primary) 8%, transparent); }
.btn.small { min-height: 44px; font-size: 14px; padding: 0 var(--space-4); }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid var(--c-line); background: var(--c-surface); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }

/* Cards */
.card { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-card); padding: var(--space-5); box-shadow: var(--shadow-1); }
.card.tight { padding: var(--space-4); }
.inset { background: var(--c-surface-alt); border-radius: calc(var(--r-card) - 6px); padding: var(--space-4); display: flex; gap: var(--space-3); align-items: flex-start; }
.inset svg { width: 20px; height: 20px; flex: none; color: var(--c-primary); margin-top: 2px; }
.inset p { margin: 0; font-size: 14px; line-height: 1.45; }
.inset.notice { background: color-mix(in srgb, var(--c-primary) 10%, var(--c-surface)); border: 1px solid color-mix(in srgb, var(--c-primary) 25%, transparent); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin: var(--space-2) 0 calc(-1 * var(--space-2)); }
.section-head h2 { font: 700 15px/1.3 var(--font-display); margin: 0; }

/* Form */
.field { display: grid; gap: 6px; }
.field label, .field .label { font-weight: 600; font-size: 14px; }
.field .hint { font-size: 12px; color: var(--c-text-soft); }
.input, .select {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--r-control);
  border: 1px solid var(--c-line); background: var(--c-surface-alt); color: var(--c-text);
  transition: border-color .2s, box-shadow .2s;
}
.input:focus, .select:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-primary) 20%, transparent); }
.money { position: relative; }
.money span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--c-text-soft); pointer-events: none; }
.money .input { padding-left: 28px; }
.suffix { position: relative; }
.suffix span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--c-text-soft); pointer-events: none; font-size: 14px; }
.grid2 { display: grid; gap: var(--space-4); grid-template-columns: 1fr 1fr; }
.grid2 > .full { grid-column: 1 / -1; }
.stack { display: grid; gap: var(--space-4); }

/* Choice cards and chips */
.choices { display: grid; gap: var(--space-3); }
.choice {
  display: flex; gap: var(--space-3); align-items: center; text-align: left; width: 100%;
  min-height: 64px; padding: var(--space-3) var(--space-4); border-radius: var(--r-control);
  border: 1.5px solid var(--c-line); background: var(--c-surface); cursor: pointer;
  transition: border-color .2s, background-color .2s;
}
.choice svg { width: 24px; height: 24px; color: var(--c-primary); flex: none; }
.choice strong { display: block; font-size: 15px; }
.choice small { color: var(--c-text-soft); font-size: 12px; }
.choice[aria-pressed="true"] { border-color: var(--c-primary); background: color-mix(in srgb, var(--c-primary) 7%, var(--c-surface)); }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--c-line);
  background: var(--c-surface); font-size: 14px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: background-color .2s, border-color .2s;
}
.chip[aria-pressed="true"] { background: var(--c-text); color: var(--c-bg); border-color: var(--c-text); }
.chip.static { cursor: default; min-height: 28px; padding: 0 10px; font-size: 12px; background: var(--c-surface-alt); border-color: transparent; }

/* Toggle */
.toggle { display: flex; align-items: center; gap: var(--space-3); justify-content: space-between; min-height: 48px; cursor: pointer; }
.toggle input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--c-line); position: relative; cursor: pointer; flex: none; transition: background-color .2s; margin: 0; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--c-surface); box-shadow: var(--shadow-1); transition: transform .2s var(--ease); }
.toggle input:checked { background: var(--c-primary); }
.toggle input:checked::after { transform: translateX(20px); }
.toggle input:disabled { opacity: .4; cursor: not-allowed; }
.toggle .t { font-weight: 600; font-size: 15px; }
.toggle .t small { display: block; font-weight: 400; font-size: 12px; color: var(--c-text-soft); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; min-height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.above { background: color-mix(in srgb, var(--c-success) 16%, transparent); color: var(--c-success); }
.badge.near { background: color-mix(in srgb, var(--c-accent) 18%, transparent); color: var(--c-text); }
.badge.below { background: color-mix(in srgb, var(--c-warning) 16%, transparent); color: var(--c-warning); }
.badge.neutral { background: var(--c-surface-alt); color: var(--c-text-soft); }
.badge.up { background: color-mix(in srgb, var(--c-success) 14%, transparent); color: var(--c-success); }

/* Score hero */
.score-hero { display: grid; grid-template-columns: auto 1fr; gap: var(--space-5); align-items: center; }
.ring { position: relative; width: 132px; height: 132px; }
.ring svg { width: 132px; height: 132px; transform: rotate(-90deg); }
.ring .track { stroke: var(--c-surface-alt); }
.ring .val { stroke: var(--c-primary); transition: stroke-dashoffset .8s var(--ease); }
.ring .num { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring .num strong { font: 800 40px/1 var(--font-display); letter-spacing: -0.03em; display: block; }
.ring .num span { font-size: 12px; color: var(--c-text-soft); }

/* Score rows */
.rows { display: grid; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 6px var(--space-3); align-items: center;
  width: 100%; text-align: left; padding: var(--space-4) 0; background: none; border: 0;
  border-bottom: 1px solid var(--c-line); cursor: pointer; border-radius: 0;
}
.row:last-child { border-bottom: 0; }
.row .name { font-weight: 700; font-size: 15px; }
.row .val { font-size: 13px; color: var(--c-text-soft); }
.row .bar { grid-column: 1 / -1; position: relative; height: 8px; border-radius: 999px; background: var(--c-surface-alt); overflow: visible; }
.row .bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--c-primary); transition: width .6s var(--ease); }
.row .bar b { position: absolute; top: -4px; width: 2px; height: 16px; background: var(--c-text); border-radius: 2px; }
.row:hover .name { color: var(--c-primary); }
.row.active { background: color-mix(in srgb, var(--c-primary) 6%, transparent); }
.legend { display: flex; gap: var(--space-4); font-size: 12px; color: var(--c-text-soft); align-items: center; }
.legend i { display: inline-block; width: 14px; height: 6px; border-radius: 4px; background: var(--c-primary); margin-right: 6px; vertical-align: middle; }
.legend b { display: inline-block; width: 2px; height: 12px; background: var(--c-text); margin-right: 6px; vertical-align: middle; }

/* Checklist and list rows */
.check-row { display: grid; grid-template-columns: auto 1fr; gap: var(--space-3); padding: var(--space-4) 0; border-bottom: 1px solid var(--c-line); }
.check-row:last-child { border-bottom: 0; }
.check {
  width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--c-line); background: var(--c-surface);
  display: grid; place-items: center; cursor: pointer; padding: 0; margin-top: 2px; transition: background-color .2s, border-color .2s;
}
.check svg { width: 18px; height: 18px; opacity: 0; transition: opacity .2s; }
.check[aria-pressed="true"] { background: var(--c-primary); border-color: var(--c-primary); color: var(--c-on-primary); }
.check[aria-pressed="true"] svg { opacity: 1; }
.check-row h3 { margin: 0 0 4px; font: 700 16px/1.3 var(--font-display); }
.check-row.done h3 { text-decoration: line-through; color: var(--c-text-soft); }
.check-row .meta { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-2); }
.steps { margin: var(--space-3) 0 0; padding-left: 20px; display: grid; gap: 6px; font-size: 14px; color: var(--c-text-soft); }
.more { min-height: 44px; margin-left: -12px; }
.progress { height: 8px; border-radius: 999px; background: var(--c-surface-alt); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--c-success); border-radius: 999px; transition: width .4s var(--ease); }

.list-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: var(--space-3); align-items: center;
  width: 100%; text-align: left; padding: var(--space-4); border-radius: var(--r-control);
  border: 1px solid var(--c-line); background: var(--c-surface); cursor: pointer; transition: border-color .2s, box-shadow .2s;
}
.list-row:hover { border-color: var(--c-primary); box-shadow: var(--shadow-1); }
.list-row .ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--c-primary) 12%, transparent); color: var(--c-primary); }
.list-row .ico.program { background: color-mix(in srgb, var(--c-accent) 18%, transparent); color: var(--c-text); }
.list-row .ico svg { width: 22px; height: 22px; }
.list-row strong { display: block; font-size: 15px; line-height: 1.3; }
.list-row small { color: var(--c-text-soft); font-size: 13px; }
.list-row .chev { width: 18px; height: 18px; color: var(--c-text-soft); }
.list { display: grid; gap: var(--space-3); }

/* Lender cards */
.lender { display: grid; gap: var(--space-3); }
.lender header { display: flex; gap: var(--space-3); align-items: flex-start; justify-content: space-between; }
.lender h3 { margin: 0; font: 700 17px/1.25 var(--font-display); }
.lender dl { margin: 0; display: grid; gap: 6px; font-size: 14px; }
.lender dt { font-size: 12px; color: var(--c-text-soft); font-weight: 600; }
.lender dd { margin: 0 0 4px; }
.lender .grid2 { grid-template-columns: auto auto; justify-content: start; }
.lender .btn { white-space: nowrap; }
.sent { border-color: color-mix(in srgb, var(--c-success) 45%, transparent); }
.sent .head { display: flex; gap: var(--space-2); align-items: center; color: var(--c-success); font-weight: 700; }
.sent .head svg { width: 20px; height: 20px; }

/* Empty state and quiet line */
.empty { text-align: center; padding: var(--space-6) var(--space-4); color: var(--c-text-soft); }
.quiet { font-size: 13px; color: var(--c-text-soft); display: flex; gap: var(--space-2); align-items: center; }
.quiet svg { width: 16px; height: 16px; flex: none; }

/* Sheet */
.backdrop { position: fixed; inset: 0; z-index: 50; background: color-mix(in srgb, var(--c-text) 45%, transparent); animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; max-height: 88vh; overflow: auto;
  background: var(--c-surface); border-radius: var(--r-sheet) var(--r-sheet) 0 0; box-shadow: var(--shadow-2);
  padding: var(--space-3) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom));
  animation: up .28s var(--ease);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 999px; background: var(--c-line); margin: 0 auto var(--space-4); }
.sheet .sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); margin-bottom: var(--space-4); }
.sheet .stack { gap: var(--space-3); }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px var(--space-3); font-size: 14px; }
.kv span:nth-child(odd) { color: var(--c-text-soft); }
.kv span:nth-child(even) { font-weight: 700; text-align: right; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(140px + env(safe-area-inset-bottom)); z-index: 70;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--c-text); color: var(--c-bg); padding: 12px 18px; border-radius: 14px; font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow-2); transition: opacity .25s, transform .25s var(--ease); max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Persona card */
.persona { display: flex; gap: var(--space-3); align-items: center; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 14px; background: color-mix(in srgb, var(--c-accent) 30%, var(--c-surface)); color: var(--c-text); flex: none; }
.persona strong { display: block; font-size: 14px; }
.persona small { font-size: 12px; color: var(--c-text-soft); }

/* Desktop: rail, content, detail panel */
@media (min-width: 1024px) {
  .shell { display: grid; grid-template-columns: 252px minmax(0, 1fr) 360px; }
  .topbar, .tabbar { display: none; }
  .actionbar { position: static; padding: var(--space-2) 0 0; background: none; display: flex; justify-content: flex-end; }
  .actionbar .btn { width: auto; min-width: 260px; }
  .rail {
    display: flex; flex-direction: column; gap: var(--space-5); position: sticky; top: 0; height: 100vh;
    padding: var(--space-5) var(--space-4); border-right: 1px solid var(--c-line); background: var(--c-surface);
  }
  .rail .brand { display: flex; align-items: center; gap: var(--space-3); font: 800 20px/1 var(--font-display); letter-spacing: -0.02em; padding: 0 var(--space-2); }
  .rail nav { display: grid; gap: 4px; }
  .rail nav a {
    display: flex; align-items: center; gap: var(--space-3); min-height: 44px; padding: 0 var(--space-3);
    border-radius: 12px; color: var(--c-text-soft); text-decoration: none; font-weight: 600; font-size: 15px;
  }
  .rail nav a svg { width: 20px; height: 20px; }
  .rail nav a .n { margin-left: auto; font-size: 12px; color: var(--c-text-soft); }
  .rail nav a:hover { background: var(--c-surface-alt); color: var(--c-text); }
  .rail nav a[aria-current="page"] { background: color-mix(in srgb, var(--c-primary) 12%, transparent); color: var(--c-primary); }
  .rail .foot { margin-top: auto; display: grid; gap: var(--space-3); }
  .main { padding: var(--space-6) var(--space-6) var(--space-7); max-width: 860px; width: 100%; }
  .detail { display: block; position: sticky; top: 0; height: 100vh; overflow: auto; padding: var(--space-6) var(--space-5); border-left: 1px solid var(--c-line); background: color-mix(in srgb, var(--c-surface) 60%, var(--c-bg)); }
  .detail .stack { gap: var(--space-4); }
  .desk-cols { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); align-items: start; }
  .list.cols { grid-template-columns: 1fr 1fr; }
  .display { font-size: 38px; }
  .toast { bottom: var(--space-6); }
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 520px; transform: translate(-50%, -50%); border-radius: var(--r-sheet); animation: fade .2s; }
  .sheet .grab { display: none; }
}

@media (max-width: 380px) {
  .grid2 { grid-template-columns: 1fr; }
  .score-hero { grid-template-columns: 1fr; justify-items: center; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
