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

:root {
  --bg: #0f0f13;
  --bg2: #18181f;
  --bg3: #222230;
  --border: #2e2e3e;
  --text: #e8e8f0;
  --text2: #9898b0;
  --accent: #7c6af7;
  --accent-h: #9080ff;
  --green: #3ecf6e;
  --red: #f0544f;
  --yellow: #f5a623;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

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

/* ── AUTH ── */
.auth-box {
  max-width: 380px;
  margin: 0 auto;
  padding: 48px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand { text-align: center; margin-bottom: 8px; }
.brand-icon { width: 64px; height: 64px; margin-bottom: 8px; }
.brand h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.5px; color: var(--accent); }
.brand-sub { color: var(--text2); font-size: 0.9rem; margin-top: 4px; }

/* ── INPUTS ── */
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  background: var(--bg3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
input:focus, select:focus { border-color: var(--accent); }
select option { background: var(--bg2); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 18px;
  transition: opacity 0.1s, background 0.1s;
  touch-action: manipulation;
  user-select: none;
  white-space: nowrap;
}
.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover:not(:disabled) { color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: 0.9; }
.btn-icon { background: var(--bg3); color: var(--text); font-size: 1.6rem; padding: 8px 14px; border-radius: var(--radius-sm); min-width: 48px; }
.btn-sm { font-size: 0.85rem; padding: 6px 12px; }
.btn-full { width: 100%; }

.auth-buttons { display: flex; gap: 10px; }
.auth-buttons .btn { flex: 1; }

/* ── MESSAGES ── */
.msg { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 0.9rem; }
.msg-error { background: rgba(240,84,79,0.15); color: var(--red); border: 1px solid rgba(240,84,79,0.3); }
.msg-success { background: rgba(62,207,110,0.12); color: var(--green); border: 1px solid rgba(62,207,110,0.3); }

/* ── TOPBAR ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-user { font-weight: 700; color: var(--accent); font-size: 1rem; }

/* ── CONTENT ── */
.content { padding: 16px; max-width: 600px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* ── CARDS ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-title { font-size: 0.95rem; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }

/* ── DATE NAV ── */
.date-nav { flex-direction: row; align-items: center; justify-content: space-between; padding: 12px 14px; }
.date-center { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.date-label { font-size: 1.1rem; font-weight: 700; color: var(--text); }

/* ── TOTALS ── */
.totals-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.total-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.total-card-full { grid-column: span 2; }
.total-label { font-size: 0.8rem; color: var(--text2); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.total-amount { font-size: 1.4rem; font-weight: 800; color: var(--accent); margin-top: 4px; }

/* ── FORM ROWS ── */
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── CALENDAR ── */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.cal-header {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text2);
  padding: 4px 0;
  font-weight: 600;
}
.cal-day {
  background: var(--bg3);
  border-radius: 6px;
  padding: 4px 2px;
  text-align: center;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1.5px solid transparent;
  transition: border-color 0.1s;
  touch-action: manipulation;
}
.cal-day:active { opacity: 0.7; }
.cal-day.empty { background: transparent; cursor: default; }
.cal-day.has-expenses { background: rgba(124,106,247,0.15); }
.cal-day.selected { border-color: var(--accent); }
.cal-day.today-day { border-color: var(--yellow); }
.cal-day-num { font-size: 0.8rem; font-weight: 700; color: var(--text); line-height: 1; }
.cal-day-amt { font-size: 0.6rem; color: var(--accent); font-weight: 600; }
.cal-day.empty .cal-day-num { color: transparent; }

/* ── EXPENSE LIST ── */
.expense-list { display: flex; flex-direction: column; gap: 8px; }
.expense-item {
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.expense-info { flex: 1; min-width: 0; }
.expense-title { font-weight: 700; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-meta { font-size: 0.8rem; color: var(--text2); margin-top: 2px; }
.expense-note { font-size: 0.78rem; color: var(--text2); font-style: italic; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-amount { font-size: 1.05rem; font-weight: 800; color: var(--green); white-space: nowrap; }
.expense-actions { display: flex; gap: 6px; align-items: center; }
.btn-edit { background: var(--bg2); color: var(--text2); font-size: 0.8rem; padding: 6px 10px; }
.btn-delete { background: rgba(240,84,79,0.12); color: var(--red); font-size: 0.8rem; padding: 6px 10px; }

.empty-state { text-align: center; color: var(--text2); font-size: 0.9rem; padding: 24px 0; }

/* ── CATEGORY BREAKDOWN ── */
.cat-breakdown { display: flex; flex-direction: column; gap: 8px; }
.cat-item { display: flex; align-items: center; gap: 10px; }
.cat-name { flex: 1; font-size: 0.9rem; }
.cat-bar-wrap { flex: 2; background: var(--bg3); border-radius: 4px; height: 8px; overflow: hidden; }
.cat-bar { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; }
.cat-amount { font-size: 0.85rem; font-weight: 700; color: var(--accent); min-width: 60px; text-align: right; }

/* ── ACTIVITY LOG ── */
.activity-log { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.log-item { font-size: 0.82rem; color: var(--text2); padding: 6px 10px; background: var(--bg3); border-radius: 6px; }
.log-item span { color: var(--text); font-weight: 600; }

/* ── DATA BUTTONS ── */
.data-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.danger-zone { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.danger-label { font-size: 0.8rem; font-weight: 700; color: var(--red); text-transform: uppercase; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 200;
  max-width: calc(100vw - 40px);
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  transition: opacity 0.3s;
}
.toast.toast-success { border-color: var(--green); color: var(--green); }
.toast.toast-error { border-color: var(--red); color: var(--red); }

/* ── FOOTER ── */
.footer { text-align: center; color: var(--text2); font-size: 0.8rem; padding: 20px 0; }

/* ── LOADING ── */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
