:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef5f2;
  --ink: #17211f;
  --muted: #66716d;
  --line: #d9e0dd;
  --mint: #127a62;
  --mint-2: #0f5d4c;
  --blue: #2e5f9e;
  --rose: #b84a5a;
  --amber: #b96f14;
  --brand: #113f3a;
  --brand-soft: #e8f7f1;
  --brand-contrast: #f8fffc;
  --brand-muted: #cde8df;
  --nav-bg: #eef2f1;
  --field-bg: #ffffff;
  --row-bg: #ffffff;
  --settled-bg: #f2f5f4;
  --stat-bg: #fbfcfc;
  --topbar-bg: rgba(255, 255, 255, 0.96);
  --shadow: 0 8px 30px rgba(18, 35, 31, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="money"] {
  --bg: #f4f7f3;
  --surface: #ffffff;
  --surface-2: #eaf6df;
  --ink: #192019;
  --muted: #63705f;
  --line: #d5dfcf;
  --mint: #1f7a3b;
  --mint-2: #14562b;
  --blue: #315d82;
  --rose: #a33f4e;
  --amber: #bb7c16;
  --brand: #174927;
  --brand-soft: #f5ecd2;
  --brand-contrast: #fbfff7;
  --brand-muted: #d9edcf;
  --nav-bg: #e8efdf;
  --field-bg: #fffefa;
  --row-bg: #fffefa;
  --settled-bg: #edf3e9;
  --stat-bg: #fbfff7;
  --topbar-bg: rgba(255, 255, 250, 0.96);
  --shadow: 0 8px 30px rgba(32, 55, 21, 0.08);
}

:root[data-theme="savings"] {
  --bg: #f5f8fa;
  --surface: #ffffff;
  --surface-2: #e6f3ee;
  --ink: #172029;
  --muted: #5f6d75;
  --line: #d5e1e5;
  --mint: #0f766e;
  --mint-2: #0b5657;
  --blue: #2f6f9f;
  --rose: #a64b61;
  --amber: #b67522;
  --brand: #0f4f57;
  --brand-soft: #eaf5fb;
  --brand-contrast: #f8fdff;
  --brand-muted: #cce5e7;
  --nav-bg: #eaf1f4;
  --field-bg: #ffffff;
  --row-bg: #ffffff;
  --settled-bg: #eef5f6;
  --stat-bg: #f9fcfd;
  --topbar-bg: rgba(255, 255, 255, 0.96);
  --shadow: 0 8px 30px rgba(17, 43, 58, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--brand-soft) 55%, transparent), transparent 42%),
    var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  min-height: 100vh;
}

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

.auth-panel,
.tool-panel,
.summary-panel,
.list-panel,
.pref-card,
.statement-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-panel {
  width: min(880px, 100%);
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  overflow: hidden;
}

.single-auth {
  grid-template-columns: 1fr;
  width: min(560px, 100%);
}

.auth-brand {
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--brand) 90%, #000 10%), var(--brand));
  color: var(--brand-contrast);
  padding: 32px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 420px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 21px;
}

.brand-row img {
  width: 40px;
  height: 40px;
}

.auth-brand h1 {
  font-size: 44px;
  line-height: 1;
  margin: 48px 0 12px;
  letter-spacing: 0;
}

.auth-brand p,
.muted {
  color: var(--muted);
}

.auth-brand p {
  color: var(--brand-muted);
  line-height: 1.5;
}

.mascot-art {
  display: block;
  width: min(220px, 58vw);
  height: auto;
  margin: 6px 0 18px;
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.16);
}

:root:not([data-theme="cat"]) .mascot-art {
  display: none;
}

.auth-form {
  padding: 32px;
}

.auth-form h2,
.view-title h2 {
  margin: 0;
  font-size: 24px;
}

.form-grid {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

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

label {
  display: grid;
  gap: 7px;
  color: color-mix(in srgb, var(--ink) 82%, var(--muted));
  font-weight: 650;
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--line) 82%, var(--muted));
  border-radius: 6px;
  background: var(--field-bg);
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

textarea {
  min-height: 82px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(18, 122, 98, 0.15);
}

.primary,
.secondary,
.ghost,
.danger,
.icon-btn {
  min-height: 38px;
  border-radius: 6px;
  padding: 9px 13px;
  font-weight: 750;
}

.primary {
  background: var(--mint);
  color: #fff;
}

.primary:hover {
  background: var(--mint-2);
}

.secondary {
  background: color-mix(in srgb, var(--blue) 12%, #fff);
  color: var(--blue);
}

.ghost {
  background: transparent;
  color: var(--blue);
}

.danger {
  background: color-mix(in srgb, var(--rose) 12%, #fff);
  color: var(--rose);
}

.icon-btn {
  width: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: var(--nav-bg);
  color: var(--ink);
}

.message {
  min-height: 22px;
  margin-top: 14px;
  color: var(--rose);
  font-weight: 650;
}

.invite-result {
  display: grid;
  gap: 14px;
}

.invite-result p {
  margin: 0;
}

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

.invite-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.theme-control {
  display: grid;
  grid-template-columns: auto minmax(128px, 1fr);
  align-items: center;
  gap: 8px;
  color: inherit;
  font-size: 12px;
  font-weight: 800;
}

.theme-control span {
  color: currentColor;
  opacity: 0.78;
}

.theme-control select {
  min-height: 34px;
  padding: 7px 28px 7px 10px;
  border-color: color-mix(in srgb, var(--line) 70%, var(--mint));
  background-color: var(--field-bg);
  font-size: 13px;
  font-weight: 750;
}

.link-button {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

.app-frame {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--nav-bg);
  padding: 4px;
  border-radius: 8px;
}

.nav button {
  background: transparent;
  color: color-mix(in srgb, var(--ink) 72%, var(--muted));
  border-radius: 6px;
  min-height: 34px;
  padding: 7px 12px;
  font-weight: 750;
}

.nav button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 6px rgba(30, 40, 38, 0.1);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-weight: 650;
}

.content {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.view-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.view-title p {
  margin: 6px 0 0;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.summary-panel,
.tool-panel,
.list-panel,
.statement-panel {
  padding: 18px;
}

.summary-amount {
  font-size: 34px;
  line-height: 1.1;
  font-weight: 850;
  margin: 8px 0;
}

.summary-name {
  display: inline-block;
  color: var(--mint-2);
  font-weight: 850;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--stat-bg);
}

.stat strong {
  display: block;
  font-size: 20px;
}

.expense-list,
.statement-list,
.pref-list {
  display: grid;
  gap: 10px;
}

.expense-row {
  display: grid;
  grid-template-columns: minmax(92px, 0.7fr) minmax(180px, 1.6fr) minmax(90px, 0.7fr) minmax(150px, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--row-bg);
}

.expense-row.settled {
  background: var(--settled-bg);
  color: #6d7774;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--surface-2);
  color: var(--mint-2);
  font-size: 12px;
  font-weight: 800;
}

.pill.blue {
  background: color-mix(in srgb, var(--blue) 12%, #fff);
  color: var(--blue);
}

.pill.rose {
  background: color-mix(in srgb, var(--rose) 12%, #fff);
  color: var(--rose);
}

.amount {
  font-weight: 850;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: color-mix(in srgb, var(--nav-bg) 80%, var(--surface));
  color: color-mix(in srgb, var(--ink) 82%, var(--muted));
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

tr:last-child td {
  border-bottom: 0;
}

.compact-input {
  min-width: 84px;
  padding: 8px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.compact-actions {
  justify-content: flex-end;
  margin-top: 0;
}

.upload-drop {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.statement-panel {
  margin-top: 18px;
}

.tool-panel + .tool-panel {
  margin-top: 14px;
}

.import-notice {
  margin-bottom: 14px;
  color: var(--mint-2);
  font-weight: 750;
}

.txn-description {
  min-width: 220px;
}

.reason {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.pref-card {
  padding: 16px;
}

.pref-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: start;
}

.pref-card .wide {
  grid-column: 1 / -1;
}

.empty {
  border: 1px dashed color-mix(in srgb, var(--line) 70%, var(--muted));
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 750;
}

.inline-check input {
  width: auto;
}

.toggle-check {
  min-height: 38px;
  padding: 0 6px;
}

.filter-note {
  margin: -8px 0 14px;
  font-size: 13px;
}

@media (max-width: 880px) {
  .auth-panel,
  .dashboard-grid,
  .invite-card,
  .two-col,
  .pref-grid,
  .upload-drop {
    grid-template-columns: 1fr;
  }

  .auth-brand {
    min-height: 260px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .nav {
    overflow-x: auto;
  }

  .content {
    padding: 16px;
  }

  .view-title {
    align-items: start;
    flex-direction: column;
  }

  .expense-row {
    grid-template-columns: 1fr;
  }
}
