/* Titanium Glass visual tokens and shared visualization surfaces. */
:root {
  color-scheme: light;
  --bg: #e8f1fc;
  --surface: #f6faff;
  --surface-2: #edf4fc;
  --surface-glass: #f8fbffd9;
  --line: #d2e1f0;
  --line-strong: #a9c1dd;
  --metal: #ffffff;
  --text: #12263c;
  --text-2: #344e68;
  --text-3: #48627b;
  --brand: #2057b1;
  --brand-fill: #2454a8;
  --brand-dark: #403f9a;
  --cyan: #08758e;
  --offset: #6940aa;
  --repay: #086c4b;
  --debt: #aa3449;
  --warn: #805000;
  --track: #adc5e3;
  --neutral: #536f8b;
  --brand-soft: #dce9fb;
  --brand-glow: #a8c8f2;
  --chart-grid: #7693b32d;
  --ambient-blue: #bddbff;
  --ambient-cyan: #c6f2f3;
  --ambient-violet: #ded9fb;
  --shadow: 0 10px 26px #172a4112, inset 0 1px 0 #fff;
  --shadow-lg: 0 20px 48px #172a4129, inset 0 1px 0 #fff;
  --radius: 20px;
  --radius-sm: 12px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101828;
  --surface: #172436;
  --surface-2: #1d2c42;
  --surface-glass: #172436de;
  --line: #334660;
  --line-strong: #4a6585;
  --metal: #506684;
  --text: #f0f6ff;
  --text-2: #c2d1e4;
  --text-3: #adbed3;
  --brand: #8cb8ff;
  --brand-fill: #2a55ac;
  --brand-dark: #4b3b99;
  --cyan: #72dcea;
  --offset: #c2a7ff;
  --repay: #68d9a8;
  --debt: #ff9ba6;
  --warn: #ffcd78;
  --track: #3b5779;
  --neutral: #a4b7d1;
  --brand-soft: #243d63;
  --brand-glow: #415e88;
  --chart-grid: #92add936;
  --ambient-blue: #19345a;
  --ambient-cyan: #113846;
  --ambient-violet: #2b234e;
  --shadow: 0 10px 30px #050a152f, inset 0 1px 0 #607c9d23;
  --shadow-lg: 0 20px 50px #050a1566, inset 0 1px 0 #607c9d40;
}

body {
  background:
    radial-gradient(ellipse at 88% 0%, var(--ambient-violet), transparent 50%),
    radial-gradient(ellipse at 4% 24%, var(--ambient-blue), transparent 55%),
    radial-gradient(ellipse at 78% 48%, var(--ambient-cyan), transparent 52%), var(--bg);
  background-attachment: fixed;
  caret-color: var(--brand);
  scrollbar-color: var(--line-strong) var(--bg);
}
::selection { background: var(--brand-soft); color: var(--text); }
:where(a, input, select, textarea, button):focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.wrap { max-width: 1180px; }
.card, .item, .role-btn, .modal, .sheet {
  background: linear-gradient(142deg, var(--surface), var(--surface-glass));
  border-color: var(--line);
  box-shadow: var(--shadow);
}
.modal, .sheet { background: linear-gradient(142deg, var(--surface), var(--surface-2)); }
.card { padding: clamp(14px, 2.5vw, 24px); }
.item { box-shadow: none; }
.input, .select, .textarea { min-width: 0; background: var(--surface-2); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: 1; }
.btn, .icon-btn, .theme-picker, .text-action, .link-btn { min-height: 44px; }
.icon-btn { min-width: 44px; }
.btn:not(.ghost,.soft,.danger,.success), .nav-record .ico { background: linear-gradient(120deg, var(--brand-fill), var(--brand-dark)); }
.btn:not(:disabled):active, .role-btn:active { transform: translateY(1px); }
.app-header, .bottom-nav {
  background: var(--surface-glass);
  backdrop-filter: blur(14px) saturate(1.16);
  border-color: var(--line-strong);
  box-shadow: 0 6px 24px #14294b15;
}
.app-header .bar { gap: 8px; min-height: 66px; }
.app-header .title { flex: 1; min-width: 0; }
.app-mark { width: 30px; height: 30px; flex: none; }
.theme-picker {
  max-width: 110px;
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  background: var(--surface);
  font-size: .79rem;
}
.bottom-nav .inner { display: flex; max-width: 610px; padding: 0 10px; }
.bottom-nav .nav-item { flex: 1; min-width: 0; }
.nav-record .ico { color: #fff; padding: 3px 13px; border-radius: 9px; }
.nav-item .dot { background: var(--warn); color: var(--surface); }
.nav-record { color: var(--brand); font-weight: 720; }
.nav-record:active .ico { transform: scale(.95); }
.nav-item .ico, .role-btn .icon, .icon-btn svg { display: grid; place-items: center; }
.nav-item svg, .role-btn svg, .icon-btn svg {
  width: 21px; height: 21px; fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round;
}
.nav-item.active .ico { background: var(--brand-soft); border-radius: 10px; padding: 3px 14px; }
.app-main { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 24px); }
.welcome { position: relative; background: none; }
.welcome-theme { position: absolute; top: max(16px, env(safe-area-inset-top)); right: max(18px, calc((100% - 1100px)/2)); }
.welcome-mark { width: 92px; height: 92px; filter: drop-shadow(0 16px 18px #233d7d35); margin-bottom: 16px; }
.brand { margin-bottom: 28px; }
.brand h1 { font-size: 3rem; }
.role-actions { max-width: 420px; }
.role-btn { border-color: var(--line-strong); min-height: 84px; }
.role-btn .icon { background: var(--brand-soft); color: var(--brand); }
.role-btn.alt .icon { color: var(--offset); }

.balance-glass {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(12px, 3vw, 44px);
  overflow: hidden;
  padding: clamp(18px, 4vw, 40px);
  border: 1px solid #5d79ae;
  border-radius: calc(var(--radius) + 8px);
  background:
    radial-gradient(ellipse at 92% 2%, #62b9db55, transparent 55%),
    linear-gradient(118deg, #0c203c 5%, #20477d 64%, #3c3c78);
  color: #f2f7ff;
  box-shadow: 0 17px 36px #14213c35, inset 0 1px 0 #c3e1ff75;
}
.balance-glass::before {
  content: ""; position: absolute; z-index: -1; inset: 0;
  background: linear-gradient(152deg, #cce8ff20 0%, transparent 35%, transparent 69%, #8a98ff19 100%);
  pointer-events: none;
}
.balance-copy { min-width: 0; }
.balance-heading { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; }
.balance-heading h1 { margin: 0; font-size: clamp(1.12rem, 2.4vw, 1.55rem); font-weight: 690; overflow-wrap: anywhere; }
.balance-status { border: 1px solid #c0d9fb66; background: #bad9ff1f; border-radius: 999px; padding: 2px 9px; font-size: .73rem; color: #e1efff; }
.balance-label { margin: 20px 0 2px; color: #d4e5fa; font-size: .85rem; }
.balance-amount { margin: 0; font-size: clamp(1.8rem, 5.7vw, 4.35rem); font-weight: 735; line-height: 1.15; letter-spacing: -.04em; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.balance-amount span { font-size: .58em; color: #b8dcf7; margin-right: .16em; font-weight: 630; }
.balance-track { height: 6px; margin-top: 18px; background: #dcecff35; border-radius: 8px; overflow: hidden; max-width: 450px; }
.balance-track i { display: block; height: 100%; background: linear-gradient(90deg,#4cc6a6,#91e9c5); border-radius: inherit; }
.balance-foot { display: flex; flex-wrap: wrap; gap: 4px 18px; color: #d4e5fa; font-size: .76rem; margin-top: 12px; }
.balance-foot b { color: #f6fbff; white-space: nowrap; }
.repay-ring { position: relative; width: clamp(86px, 17vw, 168px); aspect-ratio: 1; }
.repay-ring .glass-plot.plot-ring { width: 100%; height: 100%; aspect-ratio: 1; }
.balance-glass .repay-ring { --surface: #234478; --repay: #7ce2bb; --track: #6e8bb6; }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.ring-center strong { font-size: clamp(1.05rem, 3vw, 2.05rem); line-height: 1.1; font-variant-numeric: tabular-nums; }
.ring-center small { font-size: .65em; }
.ring-center > span { font-size: .69rem; margin-top: 3px; }
.ledger-ribbon { display: flex; flex-wrap: wrap; align-items: center; gap: 0 20px; padding: 8px 5px; margin-bottom: 8px; color: var(--text-2); font-size: .79rem; }
.ledger-ribbon strong { font-variant-numeric: tabular-nums; color: var(--text); }
.text-action { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--text-2); padding: 0; }
.text-action:hover { color: var(--brand); }
.join-notice { margin-bottom: 14px; }

.page-title { margin: 2px 0 13px; font-size: clamp(1.38rem, 2.5vw, 1.85rem); font-weight: 720; }
.viz-grid { display: grid; gap: 12px; }
.viz-grid > * { min-width: 0; }
.viz-grid > .card { margin-bottom: 0; }
.viz-grid + * { margin-top: 14px; }
.viz-card h2 { margin: 0; font-size: 1rem; font-weight: 710; }
.viz-caption { font-size: .76rem; color: var(--text-3); margin: 3px 0 13px; }
.glass-plot { position: relative; min-width: 0; height: clamp(154px, 28vw, 246px); }
.glass-plot canvas { display: block; max-width: 100%; }
.glass-plot.plot-ring { width: min(100%, 145px); height: auto; aspect-ratio: 1; }
.glass-plot.plot-short { height: 126px; }
.glass-plot.plot-tall { height: 220px; }
.balance-point { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 11px 0; color: var(--text-2); font-size: .85rem; }
.balance-point strong { color: var(--text); font-variant-numeric: tabular-nums; }
.viz-empty { font-size: .86rem; color: var(--text-3); padding: 12px 0 2px; }
.mix-layout { display: grid; grid-template-columns: minmax(75px, 140px) minmax(0, 1fr); align-items: center; gap: 8px 16px; }
.viz-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .8rem; }
.viz-legend li { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: baseline; }
.viz-legend strong { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.swatch { display: inline-block; width: 8px; height: 8px; background: var(--neutral); border-radius: 2px; flex: none; }
.swatch.debt { background: var(--debt); }
.swatch.repay { background: var(--repay); }
.swatch.offset { background: var(--offset); }
.swatch.warn { background: var(--warn); }
.swatch.brand { background: var(--brand); }
.swatch.cyan { background: var(--cyan); }
.series-key { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 8px; color: var(--text-2); font-size: .76rem; }
.series-key span { display: inline-flex; align-items: center; gap: 5px; }
.viz-strip { display: flex; height: 8px; overflow: hidden; border-radius: 999px; background: var(--track); }
.viz-strip span + span { box-shadow: -1px 0 0 var(--surface); }
.viz-strip + .viz-legend { margin-top: 12px; }
.detail-summary { display: grid; gap: 10px; margin-bottom: 14px; }
.detail-summary strong { font-variant-numeric: tabular-nums; }
.detail-summary .viz-legend { max-width: 410px; }
.cal-day { min-height: 56px; border-radius: 10px; }
.cal-day .amt { flex-shrink: 0; }
.cal-day.out { background: transparent; }
.cal-day.sel { background: var(--brand-fill); }
.approval-metrics { margin-bottom: 14px; }
.approval-metrics .plot-tall { height: 176px; }
@media (max-width: 739px) {
  .approval-metrics .plot-ring { width: min(100%, 84px); }
  .approval-metrics .mix-layout { grid-template-columns: 84px minmax(0, 1fr); }
}
.flow-progress { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; list-style: none; padding: 0; margin: 0; }
.flow-progress li { border-top: 3px solid var(--line-strong); padding: 8px 0 0; color: var(--text-3); font-size: .8rem; }
.flow-progress li.done { border-color: var(--repay); }
.flow-progress li[aria-current="step"] { border-color: var(--brand); color: var(--text); font-weight: 700; }
.settings-summary { margin-bottom: 14px; }
.settings-summary .repay-ring { width: 84px; }
.settings-summary .repay-ring .plot-ring { width: 100%; height: 100%; }
.settings-summary .ring-center strong { font-size: 1.1rem; }

@media (min-width: 740px) {
  .wrap { padding-inline: 24px; }
  .viz-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
  .dashboard-viz, .calendar-viz, .transactions-viz { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
  .wide-viz { grid-column: 1 / -1; }
  .dashboard-viz .mix-layout { min-height: min(22vw, 218px); }
}
@media (max-width: 420px) {
  .app-mark { width: 25px; height: 25px; }
  .theme-picker { max-width: 89px; padding-inline: 4px; }
  .balance-heading { gap: 4px 8px; }
  .ledger-ribbon { gap: 0 12px; }
  .mix-layout { grid-template-columns: minmax(70px,105px) minmax(0,1fr); gap: 8px; }
}
@media (prefers-reduced-motion: no-preference) {
  .balance-glass { animation: glass-arrive .34s ease-out both; }
  #view > .page-title { animation: glass-arrive .19s ease-out both; }
  @keyframes glass-arrive { from { opacity: .72; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
}
@media (prefers-reduced-motion: reduce) {
  .role-btn, .btn, .skeleton { transition: none; animation: none; }
}

.settings-repayment { margin-top: 16px; }
.transactions-viz { margin-bottom: 14px; }
