:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #151b23;
  --panel-2: #1b232e;
  --chrome: #0d1117;
  --accent-text: #0d1117;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e6edf3;
  --muted: #8b949e;
  --input-bg: #1b232e;
  --meter-bg: #262f3b;
  --hover-bg: #21262d;
  --teal: #2dd4bf;
  --red: #f87171;
  --blue: #38bdf8;
  --violet: #a78bfa;
  --orange: #fb923c;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --chrome: #ffffff;
  --accent-text: #083344;
  --line: rgba(15, 23, 42, 0.12);
  --text: #0f172a;
  --muted: #64748b;
  --input-bg: #ffffff;
  --meter-bg: #e2e8f0;
  --hover-bg: #f1f5f9;
  --teal: #0f766e;
  --red: #dc2626;
  --blue: #0284c7;
  --violet: #7c3aed;
  --orange: #ea580c;
}

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }

button, input, select {
  font: inherit;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  width: 232px;
  height: 100vh;
  background: var(--chrome);
  border-right: 1px solid var(--line);
}

.sidebar nav {
  display: grid;
  gap: 4px;
  padding: 18px 14px 14px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
}

.nav-item.active {
  background: rgba(45, 212, 191, 0.12);
  color: var(--teal);
}

.side-card {
  margin: auto 16px 16px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.creator-credit {
  padding: 0 16px 18px;
  color: var(--muted);
  font-size: 12px;
}

.side-card span,
.side-card small,
.heading p,
.muted,
.fine-print {
  color: var(--muted);
}

.side-card strong {
  display: block;
  margin: 8px 0;
  color: var(--teal);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.meter {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--meter-bg);
}

.meter i {
  display: block;
  height: 100%;
  background: var(--teal);
}

.workspace {
  flex: 1;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 62px;
  padding: 0 26px;
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.logout-form {
  margin: 0;
}

.logout-form button {
  min-height: 30px;
  padding: 0 10px;
  color: var(--text);
  background: var(--panel-2);
  font-size: 12px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.theme-toggle input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.theme-toggle i {
  position: relative;
  width: 42px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
}

.theme-toggle i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .18s ease, background .18s ease;
}

.theme-toggle input:checked + i {
  background: rgba(45, 212, 191, .18);
}

.theme-toggle input:checked + i::after {
  transform: translateX(20px);
  background: var(--teal);
}

main {
  display: grid;
  gap: 20px;
  padding: 26px;
}

.heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.heading.spread {
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.heading h2,
.heading p,
.panel h3,
.panel h4 {
  margin: 0;
}

.heading h2 {
  font-size: 20px;
}

.heading p {
  font-size: 13px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.kpi-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kpi {
  display: grid;
  gap: 8px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.kpi span {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .04em;
}

.kpi strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 22px;
}

.kpi small {
  color: var(--muted);
  font-size: 12px;
}

.kpi.teal strong, .income { color: var(--teal); }
.kpi.red strong, .expense { color: var(--red); }
.kpi.blue strong { color: var(--blue); }
.kpi.violet strong { color: var(--violet); }
.kpi.orange strong { color: var(--orange); }

.split {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  align-items: start;
}

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

.panel,
.toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.panel {
  display: grid;
  height: 100%;
  gap: 12px;
  align-content: start;
}

.stack {
  display: grid;
  gap: 12px;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(12, minmax(28px, 1fr));
  gap: 10px;
  min-height: 230px;
  align-items: end;
  padding-top: 8px;
}

.bar-group {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 210px;
  gap: 8px;
  text-align: center;
}

.bars {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 4px;
  padding: 0 2px;
  border-bottom: 1px solid var(--line);
}

.bar {
  display: block;
  width: 12px;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
}

.bar.teal { background: var(--teal); }
.bar.red { background: var(--red); }
.bar.blue { background: var(--blue); }
.bar.violet { background: var(--violet); }

.bar-group small {
  color: var(--muted);
  font-size: 12px;
}

.category-list,
.mini-list {
  display: grid;
  gap: 8px;
}

.category-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding-bottom: 10px;
  font-size: 13px;
}

.category-row i {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  border-radius: 999px;
  background: var(--teal);
}

.check-list {
  display: grid;
  gap: 10px;
}

.check-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
}

.check-list input {
  min-height: auto;
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.mock-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.entry-form,
.filters,
.statement-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.transaction-editor {
  gap: 14px;
}

.form-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.form-title p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.entry-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  align-items: end;
}

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

.entry-form label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.entry-form .span-2 {
  grid-column: span 2;
}

.form-actions {
  display: flex;
  gap: 8px;
}

input,
select {
  min-height: 40px;
  padding: 0 12px;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--teal);
}

.input-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 40px;
  overflow: hidden;
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.input-with-unit:focus-within {
  border-color: var(--teal);
}

.input-with-unit input {
  min-height: 38px;
  border: 0;
  border-radius: 0;
}

.input-with-unit b {
  padding: 0 12px;
  color: var(--muted);
  font-size: 12px;
}

button,
.ghost-button,
.year-nav a,
.statement-filter a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--teal);
  color: var(--accent-text);
  cursor: pointer;
  font-weight: 700;
}

.entry-form button,
.filters button {
  color: #fff;
}

.ghost-button,
.year-nav a,
.statement-filter a {
  background: var(--panel-2);
  color: var(--text);
}

.auth-body {
  min-height: 100vh;
  background: var(--bg);
}

.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-title {
  display: grid;
  gap: 8px;
  margin-bottom: 22px;
}

.auth-title span,
.auth-title p {
  margin: 0;
  color: var(--muted);
}

.auth-title span {
  color: var(--teal);
  font-weight: 800;
}

.auth-title h1 {
  margin: 0;
  font-size: 28px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

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

.auth-form label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.auth-form button {
  margin-top: 4px;
  color: #fff;
}

.message-stack {
  display: grid;
  gap: 8px;
}

.notice {
  padding: 12px 14px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.notice.error {
  color: var(--red);
  background: rgba(248, 113, 113, .1);
}

.table-panel {
  padding: 0;
  overflow: hidden;
}

.paginated-panel {
  transition: opacity .12s ease;
}

.paginated-panel.is-loading {
  opacity: .62;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.table-header strong {
  color: var(--text);
  font-size: 14px;
}

.table-header span {
  color: var(--muted);
  font-size: 12px;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

td {
  color: var(--muted);
  font-size: 13px;
}

td strong {
  display: block;
  color: var(--text);
  font-weight: 600;
}

td small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.mono,
.amount {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.amount {
  text-align: right;
  font-weight: 700;
}

.pill {
  display: inline-flex;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.pill.income {
  background: rgba(45, 212, 191, .14);
}

.pill.expense {
  background: rgba(248, 113, 113, .14);
}

.pill.neutral {
  background: rgba(148, 163, 184, .16);
  color: var(--muted);
}

.delete {
  min-height: 30px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
}

.delete:hover {
  color: var(--red);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-actions form {
  margin: 0;
}

.settlement-form {
  display: grid;
  grid-template-columns: 124px 100px minmax(96px, 1fr) auto;
  gap: 6px;
  align-items: center;
  min-width: 440px;
}

.settlement-form input {
  min-height: 32px;
  padding: 0 8px;
  font-size: 12px;
}

.settlement-form button {
  min-height: 32px;
  padding: 0 10px;
  color: #fff;
  font-size: 12px;
}

.settled-label {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(45, 212, 191, .14);
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
}

.edit-link {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.page-link.active {
  background: var(--teal);
  color: var(--accent-text);
}

.page-link.disabled {
  pointer-events: none;
  opacity: .45;
}

.page-link.edge {
  min-width: 52px;
}

.empty {
  padding: 42px;
  text-align: center;
  color: var(--muted);
}

.year-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.year-nav strong,
.statement-filter strong {
  min-width: 56px;
  text-align: center;
}

.month-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.month-button {
  padding: 8px 11px;
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
}

.month-button.active {
  background: var(--teal);
  color: var(--accent-text);
  font-weight: 800;
}

.line-item,
.mini-tx {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}

.line-item span,
.mini-tx small {
  color: var(--muted);
  font-size: 13px;
}

.line-item + h4 {
  margin-top: 14px;
  padding-top: 4px;
}

.mini-tx strong {
  display: block;
  font-size: 13px;
}

.mini-tx span,
.line-item strong,
.statement td:last-child {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.panel-title {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.statement .section td,
.statement .total td {
  color: var(--text);
  font-weight: 800;
}

.statement .indent {
  padding-left: 34px;
}

.fine-print {
  margin: 6px 0 0;
  font-size: 12px;
}

@media (max-width: 980px) {
  .shell {
    display: block;
  }

  .sidebar {
    position: static;
    width: auto;
    height: auto;
  }

  .sidebar nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav-item {
    justify-content: center;
  }

  .side-card {
    display: none;
  }

  .creator-credit {
    display: none;
  }

  .kpi-grid,
  .kpi-grid.three,
  .kpi-grid.four,
  .split,
  .split.equal {
    grid-template-columns: 1fr;
  }

  .bar-chart {
    overflow-x: auto;
    grid-template-columns: repeat(12, 42px);
  }
}

@media (max-width: 640px) {
  main,
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .heading.spread {
    flex-direction: column;
  }

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

  table {
    min-width: 860px;
  }

  .entry-form {
    grid-template-columns: 1fr;
  }

  .entry-form .span-2 {
    grid-column: span 1;
  }

}
