:root,
[data-theme="light"] {
  color-scheme: light;
  --bg: #efe6d4;
  --card: #fffaf1;
  --ink: #1c2418;
  --muted: #6e6558;
  --line: #e3d5bf;
  --segment: #f0e6d2;
  --accent: #c6531a;
  --income: #1d7a4a;
  --income-soft: #e5f4ea;
  --expense: #c4372f;
  --expense-soft: #fde8e2;
  --shadow: 0 16px 40px rgba(78, 48, 16, 0.06);
  --radius: 22px;
  --glow: rgba(198, 83, 26, 0.16);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12100e;
  --card: #1d1a16;
  --ink: #f6efe4;
  --muted: #b4a898;
  --line: #342e27;
  --segment: #2a241e;
  --accent: #e58a55;
  --income: #7dcea0;
  --income-soft: #173226;
  --expense: #f0a397;
  --expense-soft: #3a221c;
  --shadow: none;
  --glow: rgba(229, 138, 85, 0.18);
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    color-scheme: dark;
    --bg: #12100e;
    --card: #1d1a16;
    --ink: #f6efe4;
    --muted: #b4a898;
    --line: #342e27;
    --segment: #2a241e;
    --accent: #e58a55;
    --income: #7dcea0;
    --income-soft: #173226;
    --expense: #f0a397;
    --expense-soft: #3a221c;
    --shadow: none;
    --glow: rgba(229, 138, 85, 0.18);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% -10%, var(--glow), transparent 60%),
    radial-gradient(700px 380px at 100% 0%, rgba(29, 122, 74, 0.08), transparent 55%),
    var(--bg);
  font-family: Outfit, sans-serif;
  transition: background 0.25s ease, color 0.25s ease;
}

button, input, select { font: inherit; color: inherit; }

h1, h2, p { margin: 0; }

.shell {
  display: block;
  min-height: 100vh;
}

.sidenav, .dock, .sheet { display: none; }

.page {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.topbar, .section-head, .panel-head, .toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.topbar { margin-bottom: 22px; }

.brand { display: flex; align-items: center; gap: 12px; }

.mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background:
    linear-gradient(160deg, var(--income) 0 48%, transparent 48% 52%, var(--expense) 52%);
}

.eyebrow {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1, .card-value, .thread-amount { font-family: Fraunces, Georgia, serif; font-optical-sizing: auto; }
h1 { font-size: 1.7rem; font-weight: 560; letter-spacing: -0.03em; }
h2 { font-size: 1.05rem; font-weight: 650; letter-spacing: -0.02em; }

.toolbar { flex-wrap: wrap; justify-content: flex-end; }

.segment {
  display: inline-flex;
  padding: 3px;
  background: var(--segment);
  border-radius: 12px;
  gap: 2px;
}

.segment button, .tabs button, .btn {
  border: 0;
  cursor: pointer;
  background: transparent;
}

.segment button {
  border-radius: 9px;
  padding: 7px 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.segment button.is-active {
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 22px;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tabs button {
  position: relative;
  flex: 0 0 auto;
  padding: 10px 8px 12px;
  margin-right: 10px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.tabs button.is-active { color: var(--ink); }

.tabs button.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--ink);
  animation: tab-in 0.25s ease;
}

.section-head { margin-bottom: 16px; }
.section-head p, .panel-head p, .card-label { color: var(--muted); font-size: 0.875rem; }

.summary, .charts, .workspace, .report-grid {
  display: grid;
  gap: 16px;
}

.summary { grid-template-columns: repeat(3, 1fr); margin-bottom: 16px; }
.charts { grid-template-columns: 1.45fr 0.9fr; }
.workspace, .report-grid { grid-template-columns: 0.82fr 1.18fr; margin-top: 0; }

.card, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: background 0.25s ease, border-color 0.25s ease;
}

.card { padding: 18px 20px; }
.panel { padding: 18px 20px; }
.charts + .panel { margin-top: 16px; }

.summary .card { animation: rise 0.45s ease backwards; }
.summary .card:nth-child(2) { animation-delay: 0.06s; }
.summary .card:nth-child(3) { animation-delay: 0.12s; }

.card-value {
  margin-top: 8px;
  font-size: 2rem;
  font-weight: 560;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.thread {
  margin-bottom: 16px;
  padding: 18px 18px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent) 10%, var(--card)), var(--card) 42%);
  box-shadow: var(--shadow);
}

.thread-head, .thread-now { display: flex; justify-content: space-between; gap: 16px; }
.thread-now { display: block; text-align: right; min-width: 180px; }
.thread-lead, .thread-hint, .thread-story { color: var(--muted); font-size: 0.9rem; }
.thread-lead { margin-top: 6px; max-width: 42ch; }
.thread-amount {
  margin-top: 4px;
  font-size: 2.4rem;
  font-weight: 560;
  letter-spacing: -0.04em;
  line-height: 1;
}
.thread-amount.is-negative { color: var(--expense); }
.thread-hint { margin-top: 8px; }
.thread-week, .thread-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.thread-week { margin-top: 16px; color: var(--muted); font-size: 0.72rem; font-weight: 700; text-align: center; }
.thread-strip { margin-top: 6px; }
.thread-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
.thread-compare .thread-amount { font-size: 1.7rem; }
.knot, .knot-blank {
  min-height: 72px;
  border: 0;
  border-radius: 14px;
  background: var(--segment);
  padding: 6px 2px;
}
.knot-blank { background: transparent; }
.knot { cursor: pointer; color: inherit; }
.knot.is-future { opacity: 0.72; }
.knot.is-today { box-shadow: inset 0 0 0 1px var(--line); }
.knot.is-picked { outline: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--card)); }
.knot-plot {
  display: grid;
  grid-template-rows: 22px 22px;
  align-items: end;
  width: min(100%, 22px);
  margin: 0 auto;
}
.knot-in, .knot-out { width: 100%; display: block; min-height: 0; justify-self: center; }
.knot-in { align-self: end; background: var(--income); border-radius: 6px 6px 2px 2px; }
.knot-out { align-self: start; background: var(--expense); border-radius: 2px 2px 6px 6px; }
.knot-num { display: block; margin-top: 4px; color: var(--ink); font-size: 0.75rem; font-weight: 700; }
.thread-story {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--ink);
}

.card-value.income, .amount.income { color: var(--income); }
.card-value.expense, .amount.expense { color: var(--expense); }
.card-value.is-negative { color: var(--expense); }
.card-value.is-positive { color: var(--income); }

.delta { margin-top: 8px; font-size: 0.8rem; font-weight: 600; }
.delta.good { color: var(--income); }
.delta.bad { color: var(--expense); }
.delta.neutral { color: var(--muted); }

.chart-wrap { position: relative; height: 300px; }
.chart-wrap canvas { width: 100% !important; height: 300px !important; }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}
.empty[hidden] { display: none; }
.empty.static { position: static; padding: 24px 0; }

.stage {
  position: relative;
  overflow: hidden;
}

.view { display: none; }

.view.is-active,
.view.is-leaving { display: block; }

.view.is-leaving {
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  pointer-events: none;
}

.view.is-active { animation: enter-forward 0.42s cubic-bezier(0.22, 1, 0.36, 1); }
.view.is-leaving { animation: leave-forward 0.42s cubic-bezier(0.22, 1, 0.36, 1) forwards; }
.view[data-dir="back"].is-active { animation-name: enter-back; }
.view[data-dir="back"].is-leaving { animation-name: leave-back; }

.view[data-view-panel="categories"] .chart-panel {
  max-width: 560px;
  margin-inline: auto;
}

.field { display: grid; gap: 6px; color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.field[hidden], .banner[hidden] { display: none; }
.field.compact select { min-width: 150px; }

select, input[type="number"], input[type="date"], input[type="text"], input[type="search"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  padding: 11px 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select:focus, input:focus {
  outline: 2px solid transparent;
  border-color: var(--ink);
}

form { display: grid; gap: 12px; }

.banner {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--income-soft);
  color: var(--ink);
  font-weight: 600;
}

.banner button {
  margin-left: 8px;
}

.filters, .inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.filters > * { flex: 1 1 140px; }

.stack-form {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.budget-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 6px;
}

.budget-line input { width: 140px; }

.type-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.type-switch input { position: absolute; opacity: 0; }
.type-switch span {
  display: block;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
  font-weight: 650;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.type-switch input[value="income"]:checked + span { background: var(--income); border-color: var(--income); color: #fff; }
.type-switch input[value="expense"]:checked + span { background: var(--expense); border-color: var(--expense); color: #fff; }
.type-switch input[value="transfer"]:checked + span { background: var(--ink); border-color: var(--ink); color: var(--card); }

.form-error { color: var(--expense); font-size: 0.875rem; font-weight: 600; }
.form-actions { display: flex; gap: 8px; }

.btn {
  border-radius: 10px;
  padding: 11px 14px;
  font-weight: 650;
  transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--ink); color: var(--card); }
.btn-ghost { color: var(--muted); padding-inline: 8px; }
.btn-text {
  border: 0;
  background: transparent;
  padding: 0;
  margin-left: 12px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn-text.danger { color: var(--expense); }

.tx-list { list-style: none; margin: 0; padding: 0; }
.tx-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  animation: rise 0.4s ease backwards;
}
.tx-row:last-child { border-bottom: 0; }
.tx-row:nth-child(2) { animation-delay: 0.04s; }
.tx-row:nth-child(3) { animation-delay: 0.08s; }
.tx-row:nth-child(4) { animation-delay: 0.12s; }
.tx-row:nth-child(5) { animation-delay: 0.16s; }

.tx-cat { display: block; font-weight: 650; }
.tx-note, .tx-date { color: var(--muted); font-size: 0.82rem; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }

.badge {
  display: inline-block;
  margin-top: 4px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
}
.badge.income { background: var(--income-soft); color: var(--income); }
.badge.expense { background: var(--expense-soft); color: var(--expense); }

.meters { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.meter-label { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; font-size: 0.9rem; }
.meter-track {
  height: 8px;
  border-radius: 999px;
  background: var(--segment);
  overflow: hidden;
}
.meter-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--expense);
  transform-origin: left center;
  animation: grow 0.6s ease;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes enter-forward {
  from { opacity: 0; transform: translateX(32px); }
  to { opacity: 1; transform: none; }
}

@keyframes leave-forward {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateX(-32px); }
}

@keyframes enter-back {
  from { opacity: 0; transform: translateX(-32px); }
  to { opacity: 1; transform: none; }
}

@keyframes leave-back {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateX(32px); }
}

@keyframes grow {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes tab-in {
  from { transform: scaleX(0.4); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

.sidenav {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 18px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 72%, transparent);
}

.side-links { display: grid; gap: 4px; margin-top: 28px; }

.side-links .nav-btn, .sheet-card .nav-btn {
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 10px 12px;
  font-weight: 650;
  cursor: pointer;
}

.side-links .nav-btn.is-active, .sheet-card .nav-btn.is-active {
  background: var(--ink);
  color: var(--card);
}

.dock {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(10px);
}

.dock button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
  font-size: 0.72rem;
  min-height: 44px;
  border-radius: 12px;
  cursor: pointer;
}

.dock button.is-active { color: var(--ink); background: var(--segment); }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  align-items: end;
  padding: 16px;
  background: rgba(20, 16, 12, 0.45);
}

.sheet[hidden] { display: none; }

.sheet-card {
  display: grid;
  gap: 6px;
  padding: 16px;
  border-radius: 20px 20px 16px 16px;
  background: var(--card);
  border: 1px solid var(--line);
}

@media (max-width: 700px) {
  .sidenav, .tabs { display: none; }
  .dock { display: grid; }
  .page {
    width: min(100% - 20px, 1120px);
    padding: 16px 0 calc(96px + env(safe-area-inset-bottom));
  }
  .topbar, .section-head, .summary, .charts, .workspace, .report-grid, .tx-row, .thread-head {
    display: grid;
    grid-template-columns: 1fr;
  }
  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    justify-content: stretch;
    width: 100%;
  }
  .toolbar .segment { grid-column: 1 / -1; }
  .toolbar .field, .toolbar .segment { width: 100%; }
  .field.compact select { min-width: 0; }
  .thread { padding: 14px; }
  .thread-lead { display: none; }
  .thread-amount { font-size: 1.8rem; }
  .knot, .knot-blank { min-height: 52px; padding: 4px 1px; }
  .thread-compare .thread-amount { font-size: 1.35rem; }
  .segment button { flex: 1; min-height: 40px; }
  .thread-now { text-align: left; }
  .thread-amount { font-size: 2rem; }
  .card-value { font-size: 1.7rem; }
  .tx-row { align-items: start; }
  select, input[type="number"], input[type="date"], input[type="text"], input[type="search"], .btn {
    min-height: 44px;
  }
  .budget-line, .budget-line input { width: 100%; }
  .budget-line { align-items: stretch; flex-direction: column; }
}

@media (min-width: 701px) and (max-width: 1099px) {
  .sidenav, .dock { display: none; }
  .tabs { display: flex; }
  .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .workspace, .report-grid { grid-template-columns: 1fr 1fr; }
  .page { width: min(100% - 40px, 1120px); }
}

@media (min-width: 1100px) {
  .shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); }
  .sidenav { display: block; }
  .tabs, .dock, .brand-inline { display: none; }
  .page { width: min(1080px, calc(100% - 48px)); }
}
