:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --danger: #d03b3b;
  --card-shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 1px 8px rgba(11, 11, 11, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --danger: #e66767;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 8px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--series-1);
}

.muted {
  color: var(--text-muted);
}

/* Top navigation */
.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--text-primary);
}

.nav-links {
  display: flex;
  gap: 16px;
  align-items: center;
  flex: 1;
}

.nav-links a {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.nav-cta {
  background: var(--series-1);
  color: #fff !important;
  padding: 6px 12px;
  border-radius: 6px;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

/* Cards */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  box-shadow: var(--card-shadow);
}

.auth-card {
  max-width: 420px;
  margin: 48px auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  box-shadow: var(--card-shadow);
}

.form-card {
  max-width: 560px;
  margin: 0 auto;
}

/* Forms */
.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 16px;
}

.form-row {
  display: flex;
  gap: 14px;
}

.form-row label {
  flex: 1;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

input, select, button {
  font: inherit;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="file"],
select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--page-plane);
  color: var(--text-primary);
}

.mode-toggle {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  gap: 16px;
}

.mode-toggle legend {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.radio {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--series-1);
  color: #fff;
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border);
}

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

.link-button {
  background: none;
  border: none;
  color: var(--series-1);
  cursor: pointer;
  padding: 0;
  font-size: 0.9rem;
}

.link-button.danger {
  color: var(--danger);
}

.alert {
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-top: 12px;
}

.alert-error {
  background: rgba(208, 59, 59, 0.12);
  color: var(--danger);
  border: 1px solid rgba(208, 59, 59, 0.3);
}

/* Dashboard */
.stat-row {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-tile {
  flex: 1;
  min-width: 180px;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 4px;
}

.charts-row {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.chart-card {
  flex: 1;
  min-width: 320px;
}

.chart-card h2 {
  font-size: 1rem;
  margin: 0 0 12px;
}

.filters {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

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

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

/* Table */
.table-wrap {
  overflow-x: auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.expenses-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.expenses-table th,
.expenses-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}

.expenses-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.expenses-table td:nth-child(3) {
  white-space: normal;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--page-plane);
  border: 1px solid var(--border);
}

.row-actions {
  display: flex;
  gap: 10px;
}

.receipt-preview {
  max-width: 240px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

@media (max-width: 640px) {
  .expenses-table th,
  .expenses-table td {
    white-space: normal;
  }
}
