:root {
  color-scheme: dark;
  --bg: #0f1110;
  --ink: #f6efe6;
  --muted: #b9a999;
  --accent: #2fb8ad;
  --accent-strong: #1f8078;
  --surface: #161a18;
  --surface-tint: rgba(22, 26, 24, 0.7);
  --border: rgba(246, 239, 230, 0.12);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --panel-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --bg-spot-1: #1c2c2a;
  --bg-spot-2: #2a1f1b;
  --bg-spot-3: #1e2c25;
  --accent-border: rgba(47, 184, 173, 0.35);
  --accent-shadow: 0 10px 20px rgba(47, 184, 173, 0.2);
  --accent-glow: 0 16px 28px rgba(47, 184, 173, 0.25);
  --nav-active-bg: rgba(47, 184, 173, 0.2);
  --nav-active-border: rgba(47, 184, 173, 0.45);
  --hero-accent: linear-gradient(135deg, rgba(47, 184, 173, 0.18), transparent);
  --txn-bg: linear-gradient(135deg, rgba(26, 30, 28, 0.95), rgba(26, 30, 28, 0.75));
  --txn-hover: linear-gradient(135deg, rgba(30, 34, 32, 0.95), rgba(20, 44, 40, 0.6));
  --txn-uncat: linear-gradient(135deg, rgba(42, 30, 28, 0.95), rgba(60, 36, 30, 0.6));
  --pill-bg: #1c201e;
  --rule-bg: #1c201e;
  --kids-bg: rgba(28, 32, 30, 0.7);
  --table-hover: rgba(47, 184, 173, 0.12);
  --table-uncat: rgba(80, 45, 35, 0.45);
  --ghost-border: rgba(47, 184, 173, 0.5);
  --modal-backdrop: rgba(0, 0, 0, 0.5);
}

body.theme-light {
  color-scheme: light;
  --bg: #f7f4ef;
  --ink: #1f1a16;
  --muted: #6b5f55;
  --accent: #0f766e;
  --accent-strong: #0a4d47;
  --surface: #ffffff;
  --surface-tint: rgba(255, 255, 255, 0.55);
  --border: rgba(31, 26, 22, 0.12);
  --shadow: 0 20px 60px rgba(15, 118, 110, 0.12);
  --panel-shadow: 0 10px 30px rgba(31, 26, 22, 0.08);
  --bg-spot-1: #fff2d9;
  --bg-spot-2: #f4c7b6;
  --bg-spot-3: #d1e6dc;
  --accent-border: rgba(15, 118, 110, 0.2);
  --accent-shadow: 0 10px 20px rgba(15, 118, 110, 0.25);
  --accent-glow: 0 16px 28px rgba(15, 118, 110, 0.15);
  --nav-active-bg: rgba(15, 118, 110, 0.12);
  --nav-active-border: rgba(15, 118, 110, 0.25);
  --hero-accent: linear-gradient(135deg, rgba(15, 118, 110, 0.12), transparent);
  --txn-bg: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.7));
  --txn-hover: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(209, 230, 220, 0.55));
  --txn-uncat: linear-gradient(135deg, rgba(255, 247, 240, 0.95), rgba(244, 199, 182, 0.35));
  --pill-bg: #fffaf2;
  --rule-bg: #fffaf2;
  --kids-bg: rgba(255, 250, 242, 0.7);
  --table-hover: rgba(15, 118, 110, 0.06);
  --table-uncat: rgba(244, 199, 182, 0.25);
  --ghost-border: rgba(15, 118, 110, 0.4);
  --modal-backdrop: rgba(15, 118, 110, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;

  height: 100%;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, var(--bg-spot-1) 0%, transparent 45%),
    radial-gradient(circle at 80% 0%, var(--bg-spot-2) 0%, transparent 45%),
    radial-gradient(circle at 20% 90%, var(--bg-spot-3) 0%, transparent 45%),
    var(--bg);
  min-height: 100vh;
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 28px 18px;
  border-right: 1px solid var(--border);
  background: var(--surface-tint);
  backdrop-filter: blur(20px);
  display: grid;
  gap: 20px;
  align-content: start;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.brand-logo {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.brand {
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
}

.logo-button {
  border: none;
  border-radius: 0 !important;
  background: transparent;
  box-shadow: none;
  width: 44px;
  height: 44px;
}

.logo-button.ghost {
  border: none;
  border-radius: 0 !important;
  background: transparent;
  box-shadow: none;
}

.logo-button:hover {
  transform: none;
}


.logo-button img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.nav {
  display: grid;
  gap: 8px;
}

.theme-toggle {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-weight: 600;
  color: var(--muted);
}

.theme-toggle input {
  accent-color: var(--accent);
}

.nav-link {
  text-align: left;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  padding: 10px 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.2s ease, color 0.2s ease;
}

.nav-link.active {
  background: var(--nav-active-bg);
  color: var(--accent-strong);
  border-color: var(--nav-active-border);
}

.page {
  padding: 32px 24px 48px;
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.mobile-topbar .brand {
  margin-top: 10px;
  margin-left: 10px;
}

.hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 24px;
  align-items: center;
  margin-bottom: 28px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 12px;
}

h1 {
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: clamp(2.1rem, 4vw, 3.2rem);
  margin: 0 0 10px;
}

.subtitle {
  font-size: 1.05rem;
  color: var(--muted);
  max-width: 440px;
}

.hero-card {
  background: var(--hero-accent), var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  display: grid;
  gap: 14px;
  box-shadow: var(--shadow);
}

.label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
  margin: 0 0 6px;
}

.primary,
.ghost {
  border: none;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary {
  background: var(--accent);
  color: #fffaf2;
  box-shadow: var(--accent-shadow);
}

.primary:hover {
  transform: translateY(-1px);
}

.ghost {
  background: transparent;
  color: var(--accent-strong);
  border: 1px solid var(--ghost-border);
}

.grid {
  display: grid;
  gap: 22px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

body[data-page="transactions"] .grid {
  display: block;
  flex: 1;
  min-height: 0;
}

.page-section {
  display: none;
  animation: float-in 0.5s ease-out;
}

.page-section.active {
  display: block;
}

body[data-page="transactions"] .page-section[data-page="transactions"].active {
  flex: 1;
  display: flex;
  flex-direction: column;
}

body[data-page="transactions"] .footer {
  display: none;
}

.page-section[data-page="transactions"] .panel {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.page-section[data-page="transactions"] .panel-header {
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

.page-section[data-page="transactions"] .controls {
  width: 100%;
  justify-content: space-between;
}

.page-section[data-page="transactions"] .scroll {
  max-width: 100%;

  flex: 1;
  width: 100%;
  min-height: 0;
}

.panel {
  background: var(--surface-tint);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--panel-shadow);
}

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

.panel-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

label {
  font-size: 0.8rem;
  color: var(--muted);
  display: grid;
  gap: 6px;
}

input,
select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.95rem;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  background: var(--surface);
  color: var(--ink);
}

textarea {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  resize: vertical;
  background: var(--surface);
  color: var(--ink);
}

.scroll {
  max-height: 700px;
  overflow: auto;
}

.txn-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.txn-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 14px;
  border-radius: 18px;
  border: 1px solid var(--accent-border);
  background: var(--txn-bg);
  box-shadow: 0 10px 20px rgba(31, 26, 22, 0.08);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.txn-item:hover {
  background: var(--txn-hover);
  transform: translateY(-2px);
  box-shadow: var(--accent-glow);
}

.txn-item.uncategorized {
  background: var(--txn-uncat);
  border-color: rgba(244, 199, 182, 0.6);
}

.txn-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.txn-title {
  font-weight: 600;
  font-size: 0.98rem;
  overflow-wrap: anywhere;
}

.txn-meta {
  color: var(--muted);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.txn-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table {
  width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  table-layout: fixed;
}

colgroup col:nth-child(1) {
  width: 90px;
}

colgroup col:nth-child(4) {
  width: 90px;
}


thead {
  text-align: left;
  font-size: 0.75rem;
  color: var(--muted);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s ease;
}

tbody tr:hover {
  background: var(--table-hover);
}

tbody tr.uncategorized {
  background: var(--table-uncat);
}

td,
th {
  padding: 10px 6px;
}

.pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  background: var(--pill-bg);
  border-radius: 999px;
  padding: 8px 14px;
  border: 1px solid var(--accent-border);
  font-size: 0.85rem;
}

.rule-form {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-bottom: 14px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

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

.rule-item {
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--rule-bg);
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.rule-item small {
  color: var(--muted);
}

.footer {
  margin-top: 24px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--modal-backdrop);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal {
  width: min(560px, 100%);
  background: var(--surface);
  border-radius: 24px;
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  animation: float-in 0.3s ease-out;
  max-height: calc(100vh - 40px);
  overflow: auto;
  overflow-x: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-body {
  display: grid;
  gap: 12px;
  width: 100%;
  overflow-x: hidden;
}

.modal-body label {
  width: 100%;
}

.modal-body input:not([type="checkbox"]):not([type="radio"]),
.modal-body select,
.modal-body textarea {
  width: 100%;
}

.modal-meta {
  font-size: 0.85rem;
  color: var(--muted);
  display: grid;
  gap: 4px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.kids-panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  background: var(--kids-bg);
  display: grid;
  gap: 10px;
}

.receipt-panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  background: var(--surface-tint);
  display: grid;
  gap: 10px;
}

.receipt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}

.receipt-list {
  display: grid;
  gap: 8px;
}

.receipt-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.receipt-item a {
  color: var(--accent-strong);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.receipt-item small {
  color: var(--muted);
}

.receipt-actions {
  display: grid;
  gap: 8px;
}

.receipt-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.kids-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}

.kids-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.kid-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.hidden {
  display: none;
}

@keyframes float-in {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 720px) {
  body {
    overflow-x: hidden;
  }

  .page {
    width: 100%;
    max-width: 100%;
  }

  .panel {
    max-width: 100%;
  }

  .modal {
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    padding: 16px;
    grid-template-rows: auto 1fr auto;
    gap: 12px;
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .modal-backdrop {
    padding: 0;
  }

  .modal-header,
  .modal-actions {
    flex: none;
  }

  .modal-body {
    min-height: 0;
    overflow: auto;
    padding-right: 4px;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 20;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .page {
    padding: 0;
    max-width: none;
  }

  .mobile-topbar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 0 12px 8px 0;
    background: var(--surface-tint);
    backdrop-filter: blur(12px);
    z-index: 15;
    min-height: 52px;
  }

  body[data-page="transactions"]
    .page-section[data-page="transactions"].active {
    height: 100%;
  }

  body[data-page="transactions"] .page-section[data-page="transactions"] .panel {
    height: 100%;
    flex: 1;
    border-radius: 0;
  }

  body[data-page="transactions"]
    .page-section[data-page="transactions"]
    .panel-header {
    padding-top: 54px;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }

  table {
    font-size: 0.85rem;
  }

  td:nth-child(3),
  th:nth-child(3) {
    display: none;
  }
}
