:root {
  --green: #22c55e;
  --green-dark: #16a34a;
  --green-dim: rgba(34,197,94,0.12);
  --blue: #4d8bf5;
  --blue-dim: rgba(77,139,245,0.12);
  --red: #ef4444;
  --bg: #13151e;
  --bg2: #1a1e2c;
  --card: #1e2233;
  --card2: #242840;
  --text: #d4ddf0;
  --text-muted: #6b7a99;
  --border: #2a3148;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 4px 20px rgba(0,0,0,0.5);
  --tab-height: 56px;
  --topbar-height: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  color-scheme: dark;
}

.screen { min-height: 100dvh; }
.hidden { display: none !important; }

/* ── Auth screens ── */
.auth-card {
  max-width: 400px;
  margin: 0 auto;
  padding: 48px 28px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  justify-content: center;
}

.logo { font-size: 56px; margin-bottom: 12px; }

.auth-card h1 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 2px;
  text-align: center;
}

.auth-card h1 span {
  display: block;
  color: var(--blue);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.subtitle {
  color: var(--text-muted);
  margin-bottom: 32px;
  text-align: center;
  font-size: 0.95rem;
}

form { width: 100%; display: flex; flex-direction: column; gap: 8px; }

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 8px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"] {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--bg2);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  appearance: none;
  -webkit-appearance: none;
}

input:focus { border-color: var(--green); }
input::placeholder { color: var(--text-muted); }

.btn-primary {
  margin-top: 16px;
  padding: 14px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  letter-spacing: 0.03em;
}

.btn-primary:active { background: #3a76e0; transform: scale(0.98); }

.error-msg {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #f87171;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-top: 4px;
}

/* ── Top bar ── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--bg2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.topbar-title { font-size: 1rem; font-weight: 800; letter-spacing: 0.01em; color: var(--blue); }

.btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 600;
  transition: border-color 0.2s, color 0.2s;
}

.btn-logout:active { border-color: var(--text-muted); color: var(--text); }

/* ── Tab nav ── */
.tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--tab-height);
  background: var(--bg2);
  display: flex;
  border-top: 1px solid var(--border);
  z-index: 100;
}

.tab {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  padding: 0;
  letter-spacing: 0.02em;
}

.tab.active {
  color: var(--blue);
  background: var(--blue-dim);
}

/* ── Tab content ── */
.tab-content {
  padding-top: calc(var(--topbar-height) + 12px);
  padding-bottom: calc(var(--tab-height) + 16px);
  padding-left: 12px;
  padding-right: 12px;
  max-width: 600px;
  margin: 0 auto;
}

/* ── Savings banner ── */
.savings-banner {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 12px;
}

.savings-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 4px; }
.savings-amount { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.03em; color: var(--green); }

/* ── Day cards ── */
.day-cards { display: flex; flex-direction: column; gap: 8px; }

.day-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.day-card.today { border-color: rgba(77,139,245,0.4); }
.day-card.future { background: var(--bg2); opacity: 0.7; }

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

.day-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}

.day-date {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.day-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--blue-dim);
  color: var(--blue);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.day-badge.future-badge { background: var(--bg2); color: var(--text-muted); border: 1px solid var(--border); }

.day-toggles {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

.toggle-row:active { transform: scale(0.97); }

.toggle-row.checked {
  background: var(--green-dim);
  border-color: rgba(34,197,94,0.3);
}

/* ripple burst on check */
.toggle-row .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(34,197,94,0.25);
  transform: scale(0);
  animation: ripple-burst 0.5s ease-out forwards;
  pointer-events: none;
}

@keyframes ripple-burst {
  to { transform: scale(4); opacity: 0; }
}

/* icon bounce on check */
@keyframes icon-bounce {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.4) rotate(-8deg); }
  65%  { transform: scale(0.9) rotate(4deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.toggle-row.just-checked .toggle-icon {
  animation: icon-bounce 0.45s cubic-bezier(.36,.07,.19,.97);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: color 0.18s;
}

.toggle-row.checked .toggle-label { color: var(--text); }

.toggle-icon { font-size: 1.25rem; display: inline-block; }

.toggle-switch {
  width: 44px;
  height: 26px;
  background: var(--border);
  border-radius: 13px;
  position: relative;
  transition: background 0.25s cubic-bezier(.4,0,.2,1), box-shadow 0.25s;
  flex-shrink: 0;
}

.toggle-row.checked .toggle-switch {
  background: var(--green);
  box-shadow: 0 0 10px rgba(34,197,94,0.35);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.25s cubic-bezier(.4,0,.2,1), width 0.12s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* squash effect while sliding */
.toggle-row:active .toggle-switch::after { width: 24px; }

.toggle-row.checked .toggle-switch::after { transform: translateX(18px); }

/* ── Section cards ── */
.section-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}

.section-card h2 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ── Weight form ── */
.weight-row {
  display: flex;
  gap: 12px;
}

.field-group { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.field-group label { margin-top: 0; }

.weight-summary {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.weight-chip {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  flex: 1;
  min-width: 100px;
  text-align: center;
}

.weight-chip-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.weight-chip-value { font-size: 1.3rem; font-weight: 800; color: var(--green); margin-top: 2px; }

.chart-wrap {
  position: relative;
  height: 220px;
}

/* ── Weight list ── */
.weight-list { display: flex; flex-direction: column; gap: 8px; }

.weight-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 13px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.weight-item-date { font-size: 0.85rem; color: var(--text-muted); }
.weight-item-value { font-weight: 700; font-size: 0.95rem; color: var(--text); }

.btn-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: color 0.15s;
}

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

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.stat-tile {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-icon { font-size: 1.6rem; margin-bottom: 6px; }
.stat-value { font-size: 1.5rem; font-weight: 800; color: var(--text); }
.stat-label { font-size: 0.68rem; color: var(--text-muted); margin: 4px 0; line-height: 1.3; letter-spacing: 0.02em; }
.stat-money { font-size: 0.85rem; font-weight: 700; color: var(--blue); }

.savings-total-card { text-align: center; }
.savings-total-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 700; margin-bottom: 6px; letter-spacing: 0.08em; text-transform: uppercase; }
.savings-total-value { font-size: 2.8rem; font-weight: 800; color: var(--green); margin-bottom: 16px; letter-spacing: -0.02em; }

.savings-breakdown {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 13px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.breakdown-name { color: var(--text-muted); }
.breakdown-amount { font-weight: 700; color: var(--blue); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 24px 0;
}

/* ── Responsive ── */
@media (min-width: 500px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .day-toggles { flex-direction: row; }
  .toggle-row { flex: 1; flex-direction: column; align-items: center; gap: 8px; padding: 14px 8px; }
  .toggle-label { flex-direction: column; gap: 4px; font-size: 0.8rem; text-align: center; }
}
