:root {
  color-scheme: dark;
  --bg: #1c1d1f;
  --bg-deep: #050607;
  --panel: #23252b;
  --panel-muted: #262a31;
  --panel-soft: #202228;
  --border: #343741;
  --border-soft: rgba(63, 63, 70, 0.56);
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-soft: #71717a;
  --brand: #22c55e;
  --mint: #2dd4bf;
  --income: #22c55e;
  --expense: #ef4444;
  --asset: #38bdf8;
  --goal: #a78bfa;
  --warning: #f59e0b;
  --radius: 8px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-rows: minmax(0, 68fr) minmax(0, 32fr);
  height: 100vh;
  min-height: 0;
  gap: 12px;
  padding: 16px;
  background: var(--bg);
}

.timeline-section,
.command-deck {
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.timeline-section {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
}

.top-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 42vw);
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px 13px;
  border-bottom: 1px solid var(--border-soft);
}

.hero-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.brand-kicker,
.panel-kicker {
  margin: 0 0 6px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.08;
}

h2 {
  font-size: 1.06rem;
  line-height: 1.1;
}

.timeline-subtitle {
  max-width: 560px;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: rgba(38, 42, 49, 0.72);
}

.summary-cell {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 10px 12px;
  border-left: 1px solid rgba(63, 63, 70, 0.48);
}

.summary-cell:first-child {
  border-left: 0;
}

.summary-cell span {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.summary-cell strong {
  overflow: hidden;
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.12;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-cell[data-summary="income"] strong {
  color: #86efac;
}

.summary-cell[data-summary="expense"] strong {
  color: #fca5a5;
}

.setup-warning {
  padding: 9px 22px;
  border-bottom: 1px solid rgba(245, 158, 11, 0.22);
  background: rgba(245, 158, 11, 0.08);
  color: #f8d391;
  font-size: 0.86rem;
}

.timeline-canvas {
  position: relative;
  min-height: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.016) 1px, transparent 1px),
    var(--panel);
  background-size: 100% 118px, 148px 100%;
}

.timeline-chart {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.timeline-empty {
  position: absolute;
  left: 50%;
  bottom: 22%;
  width: min(520px, calc(100% - 40px));
  transform: translateX(-50%);
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.45;
  text-align: center;
  pointer-events: none;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  min-width: 160px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(5, 6, 7, 0.94);
  color: var(--text);
  box-shadow: var(--shadow);
  pointer-events: none;
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 4px;
}

.chart-tooltip span {
  display: block;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.command-deck {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
}

.deck-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-width: 0;
  min-height: 0;
  padding: 13px 14px 14px;
  background: var(--panel);
  border-right: 1px solid var(--border-soft);
}

.deck-panel:last-child {
  border-right: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
}

.panel-kicker {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.panel-kicker::before {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--mint);
  content: "";
}

.deck-panel[data-panel="asset"] .panel-kicker::before {
  background: var(--asset);
}

.deck-panel[data-panel="income"] .panel-kicker::before {
  background: var(--income);
}

.deck-panel[data-panel="expense"] .panel-kicker::before {
  background: var(--expense);
}

.panel-summary {
  display: grid;
  gap: 4px;
  padding: 1px 0 12px;
}

.panel-summary h2 {
  color: var(--text);
  font-size: clamp(1.15rem, 1.6vw, 1.45rem);
  font-weight: 850;
  line-height: 1.08;
}

.panel-summary p {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.76rem;
  line-height: 1.35;
}

.add-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(45, 212, 191, 0.34);
  border-radius: var(--radius);
  background: rgba(45, 212, 191, 0.08);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
}

.add-button span[aria-hidden="true"] {
  color: var(--mint);
  font-size: 1rem;
  line-height: 1;
}

.add-button:hover,
.add-button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible {
  outline: none;
  border-color: var(--mint);
  background: rgba(45, 212, 191, 0.15);
}

.entry-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.entry-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  min-height: 52px;
  padding: 9px 10px;
  border: 1px solid rgba(63, 63, 70, 0.48);
  border-radius: var(--radius);
  background: rgba(38, 42, 49, 0.54);
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.entry-row:hover,
.entry-row:focus-within {
  border-color: rgba(45, 212, 191, 0.34);
  background: rgba(42, 46, 54, 0.82);
}

.entry-main {
  min-width: 0;
}

.entry-name {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 760;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-meta {
  display: block;
  margin-top: 4px;
  color: var(--text-soft);
  font-size: 0.72rem;
  line-height: 1.2;
}

.entry-amount {
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

.entry-actions {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
}

.entry-actions summary {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text-soft);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  list-style: none;
}

.entry-actions summary::-webkit-details-marker {
  display: none;
}

.entry-actions summary:hover,
.entry-actions summary:focus-visible,
.entry-actions[open] summary {
  outline: none;
  border-color: rgba(45, 212, 191, 0.3);
  background: rgba(45, 212, 191, 0.08);
  color: var(--text);
}

.entry-action-menu {
  position: absolute;
  top: 50%;
  right: 34px;
  z-index: 5;
  display: inline-flex;
  gap: 4px;
  min-width: 82px;
  padding: 4px;
  border: 1px solid rgba(63, 63, 70, 0.82);
  border-radius: 8px;
  background: rgba(5, 6, 7, 0.94);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.32);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%) translateX(4px);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.entry-actions[open] .entry-action-menu {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-50%) translateX(0);
}

.entry-row:has(.entry-actions[open]) .entry-amount {
  opacity: 0.18;
}

.mini-button {
  min-height: 24px;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

.mini-button:hover,
.mini-button:focus-visible {
  outline: none;
  color: var(--text);
  background: rgba(45, 212, 191, 0.12);
}

.mini-button.danger:hover,
.mini-button.danger:focus-visible {
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
}

.entry-row-empty {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  min-height: 62px;
  padding: 11px 12px;
  color: var(--text-muted);
  border-style: dashed;
  background: rgba(38, 42, 49, 0.28);
}

.entry-row-empty:hover {
  border-color: rgba(63, 63, 70, 0.48);
  background: rgba(38, 42, 49, 0.28);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 6, 7, 0.72);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(420px, 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-muted);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.entry-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.entry-form label {
  display: grid;
  gap: 7px;
}

.entry-form label > span,
.check-row span {
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.entry-form input,
.entry-form select {
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #1c1d1f;
  color: var(--text);
}

.entry-form input:focus,
.entry-form select:focus {
  outline: 2px solid rgba(45, 212, 191, 0.35);
  border-color: var(--mint);
}

.check-row {
  display: flex !important;
  grid-template-columns: none;
  align-items: center;
  gap: 10px !important;
}

.check-row input {
  width: 18px;
  height: 18px;
  min-height: auto;
  accent-color: var(--brand);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius);
}

.primary-button {
  border: 1px solid rgba(34, 197, 94, 0.55);
  background: rgba(34, 197, 94, 0.12);
  color: var(--text);
  font-weight: 800;
}

.ghost-button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
}

.ghost-button:hover,
.ghost-button:focus-visible {
  outline: none;
  color: var(--text);
  border-color: var(--text-muted);
}

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

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-rows: minmax(480px, 64vh) auto;
    height: auto;
    min-height: 100vh;
    padding: 10px;
  }

  .top-bar {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .summary-strip {
    width: 100%;
  }

  .summary-cell {
    padding: 9px 10px;
  }

  .timeline-empty {
    bottom: 18%;
    font-size: 0.86rem;
  }

  h1 {
    font-size: 1.45rem;
  }

  .timeline-subtitle {
    font-size: 0.82rem;
  }

  .command-deck {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .deck-panel {
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
  }

  .deck-panel:last-child {
    border-bottom: 0;
  }

  .entry-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  .entry-actions {
    grid-column: auto;
  }
}
