:root {
  --ink: #17212b;
  --muted: #637381;
  --line: #d6dee6;
  --paper: #f7f9fb;
  --surface: #ffffff;
  --nav: #102a43;
  --teal: #1f8a70;
  --blue: #2f6f9f;
  --amber: #d99b2b;
  --red: #c45f43;
  --green: #6f9f4f;
  --shadow: 0 14px 40px rgba(23, 33, 43, 0.08);
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(47, 111, 159, 0.10), transparent 36%),
    linear-gradient(315deg, rgba(31, 138, 112, 0.10), transparent 42%),
    var(--paper);
  font-family: Aptos, "Segoe UI", "Trebuchet MS", sans-serif;
  letter-spacing: 0;
}

button, input, select { font: inherit; }

.shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px 14px 92px;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 2px 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1, h2 {
  margin: 0;
  font-family: Bahnschrift, Aptos, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

h1 { font-size: clamp(2rem, 9vw, 4.5rem); line-height: 0.96; }
h2 { margin-bottom: 14px; font-size: 1.28rem; }

.status-pill {
  flex: 0 0 auto;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}
.hero-status { display: grid; justify-items: end; gap: 6px; }
.refresh-status-pill[data-state="succeeded"] { border-color: rgba(0, 163, 122, 0.35); color: var(--green); }
.refresh-status-pill[data-state="running"],
.refresh-status-pill[data-state="retrying"] { border-color: rgba(255, 176, 0, 0.45); color: #875f00; }
.refresh-status-pill[data-state="poisoned"] { border-color: rgba(196, 95, 67, 0.45); color: var(--red); }

.view { display: none; }
.view.active { display: block; }

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric, .panel, .chart-panel, .decision-form, .settings-form, .notice, .event-card, .split-row, .decision-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.90);
  box-shadow: var(--shadow);
}

.metric { padding: 14px; min-height: 92px; }
.metric .label, .split-label, .event-label { color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.metric .value { margin-top: 8px; font-size: clamp(1.38rem, 6vw, 2.25rem); font-weight: 850; }
.metric .sub { margin-top: 6px; color: var(--muted); font-size: 0.78rem; }

.panel { margin-top: 12px; padding: 16px; }
.panel-title { color: var(--muted); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; }
.panel-value { margin-top: 8px; font-size: 1.9rem; font-weight: 850; }
.panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.goal-stat {
  min-height: 82px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}
.goal-label { color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.goal-stat strong { display: block; font-size: 1rem; font-weight: 850; line-height: 1.2; }

.notice-list { display: grid; gap: 10px; margin-top: 12px; }
.notice { padding: 12px; color: var(--muted); font-size: 0.9rem; box-shadow: none; }

.chart-panel { padding: 10px; overflow: hidden; }
.chart { min-height: 280px; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart svg:hover { cursor: crosshair; }
.chart-crosshair { stroke: #33404d; stroke-width: 1; stroke-dasharray: 4 3; }
.chart-tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  max-width: 300px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(23, 33, 43, 0.96);
  color: #f4f7fa;
  font: 12px Aptos, "Segoe UI", sans-serif;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
}
.chart-tooltip[hidden] { display: none; }
.chart-tooltip .tt-title { font-weight: 700; margin-bottom: 5px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 8px; line-height: 1.55; }
.chart-tooltip .tt-swatch { flex: 0 0 auto; width: 10px; height: 10px; border-radius: 2px; }
.chart-tooltip .tt-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-tooltip .tt-val { flex: 0 0 auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-controls { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.chart-toggle { display: inline-flex; gap: 0; margin: 0 0 8px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.chart-toggle button { border: none; background: var(--surface, #fff); color: var(--muted); font-size: 0.8rem; font-weight: 800; padding: 6px 14px; cursor: pointer; }
.chart-toggle button + button { border-left: 1px solid var(--line); }
.chart-toggle button.active { background: var(--teal); color: #fff; }
.chart-toggle button:disabled { opacity: 0.4; cursor: not-allowed; }

.event-list, .split-list, .decision-output { display: grid; gap: 10px; margin-top: 12px; }
.event-card, .split-row, .decision-card { padding: 12px; box-shadow: none; }
.event-card { border-left: 5px solid var(--blue); }
.event-card.goal-normal_job_supported { border-left-color: var(--teal); }
.event-card.goal-natural_buoyancy { border-left-color: var(--amber); }
.event-card.goal-simple_fire { border-left-color: var(--red); }
.event-main, .split-main { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.event-date, .split-value { font-weight: 850; }
.event-detail, .decision-detail { margin-top: 8px; color: var(--muted); font-size: 0.82rem; }

.split-row { display: grid; gap: 8px; }
.split-bar { height: 8px; overflow: hidden; border-radius: 999px; background: #e7edf2; }
.split-fill { height: 100%; border-radius: 999px; }
.split-sub { color: var(--muted); font-size: 0.78rem; }
.account-view-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.account-type-group { grid-column: 1 / -1; display: grid; gap: 8px; }
.account-type-title { display: flex; justify-content: space-between; gap: 12px; padding: 8px 2px 0; font-weight: 850; }
.account-type-accounts { display: grid; gap: 8px; }
.account-type-accounts .split-row { background: var(--surface, #fff); }

.decision-form, .settings-form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

@media (max-width: 560px) {
  .account-view-heading { display: grid; }
}

.settings-form { padding: 12px 0 0; box-shadow: none; border: 0; }
.decision-form label, .settings-form label { display: grid; gap: 6px; color: var(--muted); font-size: 0.82rem; font-weight: 800; }
.decision-form input, .decision-form select, .settings-form input {
  min-height: 46px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
}
.decision-form button, .settings-form button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--nav);
  color: white;
  font-weight: 850;
}

.settings-intro { margin: 0 0 14px; color: var(--muted); font-size: 0.9rem; }
.field-note { margin-top: 8px; color: var(--muted); font-size: 0.8rem; }
.slot-title { margin: 6px 0 -2px; color: var(--ink); font-size: 0.82rem; font-weight: 850; letter-spacing: 0.02em; text-transform: uppercase; }
.panel-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 8px; }
.panel-actions button { min-height: 44px; padding: 0 18px; border: 0; border-radius: 8px; background: var(--nav); color: white; font-weight: 800; cursor: pointer; }
.panel-actions button:disabled { opacity: 0.5; cursor: default; }
.link-danger { background: none; border: 0; color: #b3261e; font-weight: 750; cursor: pointer; }
.simplefin-steps { margin: 8px 0 4px; padding-left: 20px; color: var(--muted); font-size: 0.82rem; }
.simplefin-steps li { margin: 3px 0; }
.simplefin-token { grid-column: 1 / -1; }
.simplefin-token textarea { width: 100%; min-height: 52px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); padding: 10px 12px; font-family: inherit; resize: vertical; }
.sfin-acct-right { display: flex; align-items: center; gap: 10px; }
.sfin-bucket { min-height: 34px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); padding: 4px 6px; font-size: 0.8rem; }
.sfin-neg { color: #b3261e; }
.sfin-summary { display: grid; gap: 4px; margin: 8px 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.sfin-summary div { display: flex; justify-content: space-between; font-size: 0.85rem; }
.sfin-summary span { color: var(--muted); }
.flow-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 10px 0; }
.flow-card { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.flow-card .flow-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.flow-card .flow-net { font-size: 1.05rem; font-weight: 800; margin-top: 2px; }
.flow-card .flow-io { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.flow-pos { color: var(--teal); }
.flow-neg { color: #b3261e; }
.flow-row-right { display: flex; align-items: center; gap: 12px; font-size: 0.85rem; white-space: nowrap; }
.flow-row-right .flow-net { min-width: 78px; text-align: right; font-weight: 800; }
.sfin-error { color: #b3261e; font-size: 0.85rem; margin: 6px 0; line-height: 1.4; }
.sfin-error a { color: #b3261e; font-weight: 800; text-decoration: underline; white-space: nowrap; }
.rentcast-address { margin: 6px 0 4px; font-size: 0.9rem; color: var(--ink); }
.data-currency .field-note { margin-top: 12px; }

.live-data-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid #d4a72c;
  border-radius: 10px;
  background: #fff8dc;
  color: var(--ink);
  font-size: 0.86rem;
}
.live-data-panel[hidden] { display: none; }
.live-data-panel strong { display: block; margin-bottom: 3px; }
.live-data-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.live-data-actions button { white-space: nowrap; }
@media (max-width: 680px) {
  .live-data-panel { align-items: stretch; flex-direction: column; }
  .live-data-actions button { flex: 1; }
}

.warming-toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: min(92vw, 440px);
  padding: 14px 16px;
  background: var(--nav);
  color: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  z-index: 50;
}
.warming-toast[hidden] { display: none; }
.warming-copy { display: grid; flex: 1; gap: 3px; min-width: 0; }
.warming-copy strong { color: #fff; font-size: 0.93rem; }
.warming-copy > span:not(.warming-track) { color: rgba(255, 255, 255, 0.76); line-height: 1.35; }
.warming-spinner {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: warming-spin 0.8s linear infinite;
  flex: 0 0 auto;
}
.warming-track {
  height: 4px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}
.warming-progress {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  animation: warming-progress 1.7s ease-in-out infinite;
}
@keyframes warming-spin { to { transform: rotate(360deg); } }
@keyframes warming-progress {
  from { transform: translateX(-115%); }
  to { transform: translateX(340%); }
}
@media (prefers-reduced-motion: reduce) {
  .warming-spinner, .warming-progress { animation: none; }
}
.danger-button {
  width: 100%;
  min-height: 48px;
  margin-top: 16px;
  border: 1px solid var(--red);
  border-radius: 8px;
  background: rgba(196, 95, 67, 0.08);
  color: var(--red);
  font-weight: 850;
}

.delay-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.delay-box { padding: 10px; border-radius: 8px; background: #eef4f6; }
.delay-box strong { display: block; margin-top: 4px; }

.retire-controls { display: grid; gap: 14px; }
.slider-row { display: grid; gap: 8px; }
.slider-row label { color: var(--muted); font-size: 0.84rem; font-weight: 800; display: flex; justify-content: space-between; gap: 12px; }
.slider-row label strong { color: var(--ink); font-size: 0.98rem; }
.slider-row input[type="range"] {
  width: 100%;
  height: 30px;
  accent-color: var(--teal);
  cursor: pointer;
}

.layoff-toggle { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--ink); font-size: 0.9rem; }
.layoff-toggle input { width: 18px; height: 18px; accent-color: var(--teal); cursor: pointer; }
.layoff-fields { display: grid; gap: 10px; }
.layoff-fields label { display: grid; gap: 4px; color: var(--muted); font-size: 0.82rem; font-weight: 800; }
.layoff-fields input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 0.95rem; }
@media (min-width: 560px) { .layoff-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; } }

.bridge-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 0.9rem;
}
.bridge-banner strong { font-size: 1rem; }
.bridge-banner.ok { background: rgba(31, 138, 112, 0.10); border-color: rgba(31, 138, 112, 0.4); color: #17614c; }
.bridge-banner.warn { background: rgba(196, 95, 67, 0.10); border-color: rgba(196, 95, 67, 0.45); color: #8a3320; }
.bridge-banner.critical { background: rgba(192, 57, 43, 0.14); border-color: rgba(192, 57, 43, 0.55); color: #a11; }
.bridge-banner span { color: var(--muted); }

.sim-panel {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  border-left: 5px solid var(--blue);
}
.sim-panel.ok { border-left-color: var(--teal); }
.sim-panel.warn { border-left-color: var(--amber); }
.sim-panel.bad { border-left-color: var(--red); }
.sim-headline { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sim-pct { font-size: 2.4rem; font-weight: 850; line-height: 1; }
.sim-panel.ok .sim-pct { color: var(--teal); }
.sim-panel.warn .sim-pct { color: var(--amber); }
.sim-panel.bad .sim-pct { color: var(--red); }
.sim-label { color: var(--muted); font-weight: 700; font-size: 0.9rem; }
.sim-detail { margin-top: 8px; color: var(--ink); font-size: 0.9rem; }
.sim-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.sim-stat { padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.sim-stat-label { color: var(--muted); font-size: 0.76rem; font-weight: 700; }
.sim-stat strong { display: block; margin-top: 4px; font-size: 0.98rem; font-weight: 850; }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 1px;
  padding: 8px;
  background: rgba(16, 42, 67, 0.96);
  backdrop-filter: blur(12px);
}
.bottom-nav button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.72rem;
  font-weight: 850;
}
.bottom-nav button.active { background: rgba(255, 255, 255, 0.14); color: #ffffff; }

@media (min-width: 760px) {
  .shell { padding: 30px 28px 110px; }
  .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .decision-form { grid-template-columns: repeat(4, minmax(0, 1fr)) auto; align-items: end; }
  .settings-form { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; }
  .settings-form button { grid-column: 1 / -1; }
  .settings-form .slot-title { grid-column: 1 / -1; }
  .decision-form button, .settings-form button { padding: 0 22px; }
  .chart { min-height: 420px; }
  .event-list, .split-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
