:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --ink: #1c1915;
  --muted: #6f675c;
  --line: #e3d9c8;
  --card: #fffdf8;
  --field: #fff;
  --income: #1f7a4d;
  --expense: #c45c26;
  --balance: #1e3a4c;
  --button: #1e3a4c;
  --button-text: #fff;
  --chart-grid: #eadfce;
  --chart-label: #5c564e;
  --shadow: 0 10px 28px rgba(48, 36, 18, 0.06);
  --radius: 14px;
}

html[data-theme="night"] {
  color-scheme: dark;
  --bg: #10141a;
  --ink: #ece7df;
  --muted: #a79f94;
  --line: #2c343f;
  --card: #1a212b;
  --field: #121820;
  --income: #3dbe7a;
  --expense: #e08a52;
  --balance: #d5e4ef;
  --button: #d5e4ef;
  --button-text: #121820;
  --chart-grid: #313a46;
  --chart-label: #c9c1b6;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font: 15px/1.45 "Segoe UI", "PT Sans", sans-serif;
}

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

h1,
h2,
p {
  margin: 0;
}

.top,
main {
  width: min(1120px, calc(100% - 32px));
  margin-inline: auto;
}

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 0 18px;
}

.top-actions {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.currency-switch {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.currency-switch button {
  min-width: 42px;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.currency-switch button[aria-pressed="true"] {
  background: var(--button);
  color: var(--button-text);
}

.rate-note {
  padding: 0 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.original {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--expense);
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

h2 {
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 22px;
  font-weight: 600;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: fit-content;
  max-width: 100%;
  margin-bottom: 12px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.tabs button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.tabs button[aria-selected="true"] {
  background: var(--button);
  color: var(--button-text);
}

.tab-badge {
  min-width: 8px;
  height: 8px;
  border-radius: 99px;
  background: currentColor;
  box-shadow: 0 0 0 0 currentColor;
  animation: pulse 1.4s ease infinite;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
  animation: tab-in 0.32s ease;
}

.signal {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13px;
}

.signal[hidden] {
  display: none;
}

.signal[data-level="warn"] {
  color: #8a5a12;
  background: rgba(196, 140, 40, 0.14);
  border-color: rgba(196, 140, 40, 0.35);
}

.signal[data-level="danger"] {
  color: #9b2c2c;
  background: rgba(176, 48, 40, 0.12);
  border-color: rgba(176, 48, 40, 0.32);
}

html[data-theme="night"] .signal[data-level="warn"] {
  color: #f0c27a;
}

html[data-theme="night"] .signal[data-level="danger"] {
  color: #ffb4a8;
}

.signal-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.4s ease infinite;
}

.signal-inline {
  margin: 0;
}

.workspace-entry .form {
  max-width: 460px;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.82); }
}

@media (prefers-reduced-motion: reduce) {
  .tab-panel.is-active,
  .signal-dot,
  .tab-badge {
    animation: none;
  }
}

.cards,
.charts,
.workspace {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.cards > *,
.charts > *,
.workspace > * {
  min-width: 0;
}

.cards {
  grid-template-columns: repeat(3, 1fr);
}

.charts,
.workspace {
  grid-template-columns: 1.2fr 0.8fr;
}

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

.card {
  padding: 14px 16px 12px;
  border-top: 3px solid var(--balance);
}

.card-income { border-top-color: var(--income); }
.card-expense { border-top-color: var(--expense); }

.card-label,
.field span,
.type-switch legend,
.list-head .field span {
  color: var(--muted);
  font-size: 13px;
}

.card-value {
  margin-top: 8px;
  font-size: clamp(20px, 1.7vw, 28px);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.card-income .card-value { color: var(--income); }
.card-expense .card-value { color: var(--expense); }
.card-balance .card-value { color: var(--balance); }

.card-note {
  min-height: 1.2em;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.panel {
  padding: 18px;
}

.panel-head,
.list-head,
.form-actions,
.filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head,
.list-head {
  align-items: flex-end;
  margin-bottom: 14px;
}

.legend-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 99px;
}

.swatch-income { background: var(--income); margin-left: 8px; }
.swatch-expense { background: var(--expense); margin-left: 8px; }

.chart-frame {
  position: relative;
  height: 280px;
}

.chart-frame canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-frame.is-empty canvas {
  visibility: hidden;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

.chart-frame.is-empty .chart-empty {
  display: flex;
}

.category-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 8px;
  align-items: center;
}

.chart-frame-donut,
.chart-frame-pie {
  height: 180px;
}

.split-chart {
  display: grid;
  grid-template-columns: 1fr 168px;
  gap: 12px;
  align-items: center;
}

.pie-title {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.legend li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
}

.legend b {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 99px;
}

.form {
  display: grid;
  gap: 12px;
  align-content: start;
}

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

.type-switch legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
}

.type-option {
  position: relative;
}

.type-option input {
  position: absolute;
  opacity: 0;
}

.type-option span {
  display: block;
  padding: 10px 12px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  cursor: pointer;
}

.type-option input:checked + span {
  color: #fff;
  border-color: transparent;
}

.type-option input[value="income"]:checked + span { background: var(--income); }
.type-option input[value="expense"]:checked + span { background: var(--expense); }

.type-option input:focus-visible + span {
  outline: 2px solid var(--balance);
  outline-offset: 2px;
}

.field {
  display: grid;
  gap: 6px;
}

.period {
  min-width: 180px;
}

input,
select {
  width: 100%;
  padding: 10px 12px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--balance);
  outline-offset: 1px;
}

.form-error {
  margin: 0;
  color: #9b2c2c;
  font-size: 14px;
}

.form-actions {
  justify-content: flex-start;
}

button {
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--button);
  color: var(--button-text);
  cursor: pointer;
}

button.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 12px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.switch {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 99px;
  background: var(--line);
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}

.theme-toggle[aria-pressed="true"] .switch {
  background: var(--income);
}

.theme-toggle[aria-pressed="true"] .switch::after {
  transform: translateX(16px);
}

button:hover {
  filter: brightness(1.08);
}

#cancel-edit,
.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.filters {
  align-items: end;
}

.filters .field {
  min-width: 140px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tbody tr:hover td {
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.num,
td.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 13px;
}

.tag-income {
  color: var(--income);
  background: rgba(31, 122, 77, 0.12);
}

.tag-expense {
  color: var(--expense);
  background: rgba(196, 92, 38, 0.12);
}

.amount-income { color: var(--income); }
.amount-expense { color: var(--expense); }

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  white-space: nowrap;
}

.row-actions button {
  padding: 6px 10px;
  font-size: 13px;
}

.empty-list {
  margin: 8px 0 0;
  color: var(--muted);
}

.list.is-empty .table-wrap {
  display: none;
}

@media (max-width: 860px) {
  .cards,
  .charts,
  .workspace,
  .category-layout {
    grid-template-columns: 1fr;
  }

  .top,
  .top-actions,
  .list-head,
  .filters {
    flex-direction: column;
    align-items: stretch;
  }

  .tabs {
    width: 100%;
  }

  h1 {
    font-size: 32px;
  }

  .chart-frame-donut,
  .chart-frame-pie {
    height: 220px;
  }

  .split-chart {
    grid-template-columns: 1fr;
  }
}
