:root {
  --page-plane: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --divider: #e1e0d9;

  --accent: #2a78d6;
  --accent-track: #cde2fb;
  --good: #0ca30c;
  --critical: #d03b3b;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page-plane: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --divider: #2c2c2a;

    --accent: #3987e5;
    --accent-track: rgba(57, 135, 229, 0.22);
    --good: #0ca30c;
    --critical: #e66767;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page-plane);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

h1, h2 {
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 1rem;
}

h2 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin: 2rem 0 0.75rem;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

/* ---- Top bar / nav ---- */

.topbar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
}

.nav a {
  color: var(--text-secondary);
  font-size: 0.92rem;
  padding: 0.25rem 0;
}

.nav a.active,
.nav a:hover {
  color: var(--accent);
}

@media (min-width: 640px) {
  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

/* ---- Flash messages ---- */

.flash-stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.flash {
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
  border: 1px solid var(--border);
}

.flash-success {
  color: var(--good);
  border-color: var(--good);
}

.flash-error {
  color: var(--critical);
  border-color: var(--critical);
}

/* ---- Stat tiles ---- */

.stat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 480px) {
  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

.stat-value {
  font-size: 1.7rem;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
}

.stat-delta-good {
  color: var(--good);
}

.stat-delta-critical {
  color: var(--critical);
}

/* ---- Goals / meters ---- */

.goal-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.goal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.goal-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.goal-name {
  font-weight: 600;
}

.goal-pct {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.meter {
  height: 8px;
  border-radius: 999px;
  background: var(--accent-track);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.meter-fill-complete {
  background: var(--good);
}

.goal-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.goal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.inline-form {
  display: flex;
  gap: 0.4rem;
}

.inline-form input {
  width: 100px;
}

/* ---- Forms ---- */

.card-form,
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.auth-card {
  max-width: 360px;
  margin: 2rem auto;
  text-align: center;
}

.subtitle {
  color: var(--text-secondary);
  margin-top: -0.5rem;
  font-size: 0.92rem;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.85rem;
}

label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: left;
}

input,
select {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page-plane);
  color: var(--text-primary);
  width: 100%;
}

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

/* ---- Buttons ---- */

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-block {
  width: 100%;
  margin-top: 0.25rem;
}

.btn-small {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

.btn-danger {
  color: var(--critical);
  border-color: var(--critical);
  background: transparent;
}

/* ---- Tables ---- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  padding: 0.55rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--divider);
  white-space: nowrap;
}

th {
  color: var(--text-secondary);
  font-weight: 600;
  background: var(--surface);
}

td.num {
  font-variant-numeric: tabular-nums;
}

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

.type-income {
  color: var(--good);
}

.type-expense {
  color: var(--critical);
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* ---- OTP entry ---- */

.otp-status {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

#code {
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: 0.4em;
  font-variant-numeric: tabular-nums;
}
