/* ── CSS Variables / Themes ───────────────────────────────────────────────── */
:root {
  --primary:    #C4788A;
  --primary-lt: #EDD5DC;
  --bg:         #FBF5F7;
  --card:       #FFFFFF;
  --text:       #2D2D2D;
  --text-muted: #888;
  --radius:     16px;
  --shadow:     0 4px 16px rgba(0,0,0,.10);
  --green:      #8FAF85;
  --green-lt:   #D6E8D3;
  --red:        #C4788A;
  --red-lt:     #EDD5DC;
  --transition: 0.25s ease;
}

[data-theme="paars"]  { --primary: #9B59B6; --primary-lt: #D7BDE2; --bg: #F9F5FF; }
[data-theme="mint"]   { --primary: #1ABC9C; --primary-lt: #A8E6CF; --bg: #F0FBF8; }
[data-theme="geel"]   { --primary: #F39C12; --primary-lt: #FDEBD0; --bg: #FFFBF0; }
[data-theme="blauw"]  { --primary: #3498DB; --primary-lt: #AED6F1; --bg: #F0F8FF; }
[data-theme="oranje"] { --primary: #E67E22; --primary-lt: #FAD7A0; --bg: #FFF8F0; }
[data-theme="lely"]   { --primary: #C4788A; --primary-lt: #EDD5DC; --bg: #FBF5F7; --green: #8FAF85; --green-lt: #D6E8D3; }

/* ── Lucide Icons ─────────────────────────────────────────────────────────── */
.lucide {
  width: 1em;
  height: 1em;
  vertical-align: middle;
  stroke-width: 2;
  display: inline-block;
}

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  transition: background var(--transition);
}

button {
  cursor: pointer;
  border: none;
  font-family: inherit;
  font-size: 1rem;
  border-radius: var(--radius);
  transition: transform 0.1s ease, box-shadow 0.1s ease, opacity var(--transition);
}
button:active { transform: scale(0.96); }

input:not([type="checkbox"]), select, textarea {
  font-family: inherit;
  font-size: 1rem;
  border: 2px solid var(--primary-lt);
  border-radius: 12px;
  padding: 12px 14px;
  width: 100%;
  background: white;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  -webkit-appearance: none;
}
input:not([type="checkbox"]):focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

/* ── Login Screen ─────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  gap: 24px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #FBF5F7 0%, #EDD5DC 35%, #D6E8D3 65%, #FBF5F7 100%);
  background-size: 300% 300%;
  animation: login-bg-shift 9s ease infinite;
}

@keyframes login-bg-shift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* floating orbs */
#login-screen::before,
#login-screen::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  animation: login-float 6s ease-in-out infinite;
  filter: blur(40px);
  opacity: 0.5;
}

#login-screen::before {
  width: 340px;
  height: 340px;
  background: #C4788A;
  top: -100px;
  left: -100px;
  animation-duration: 8s;
}

#login-screen::after {
  width: 260px;
  height: 260px;
  background: #8FAF85;
  bottom: -80px;
  right: -80px;
  animation-duration: 6s;
  animation-delay: -3s;
}

@keyframes login-float {
  0%, 100% { transform: translateY(0) scale(1); }
  50%       { transform: translateY(-24px) scale(1.06); }
}

.login-card {
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 36px 28px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-logo {
  text-align: center;
}
.login-logo img { width: 96px; height: 96px; object-fit: contain; }

.login-title {
  text-align: center;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 6px;
}

.login-card label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 6px;
}

.login-field { display: flex; flex-direction: column; }

.btn-login {
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 16px;
  border-radius: 14px;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 40%, transparent);
  margin-top: 4px;
}
.btn-login:hover { opacity: 0.9; }

.login-error {
  background: var(--red-lt);
  color: var(--red);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  display: none;
}
.login-error.visible { display: block; }

/* ── App Layout ───────────────────────────────────────────────────────────── */
#app-screen { display: none; flex-direction: column; min-height: 100dvh; }
#app-screen.visible { display: flex; }

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  background: var(--primary);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px color-mix(in srgb, var(--primary) 40%, transparent);
}

.header-logo {
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-logo-img { width: 28px; height: 28px; object-fit: contain; filter: brightness(0) invert(1); }

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-user {
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(255,255,255,0.2);
  padding: 6px 12px;
  border-radius: 20px;
}

.btn-icon {
  background: rgba(255,255,255,0.2);
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.btn-icon:hover { background: rgba(255,255,255,0.3); }

/* ── Main Content ─────────────────────────────────────────────────────────── */
main {
  flex: 1;
  padding: 20px 16px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--primary);
}
.stat-card.full-width { grid-column: 1 / -1; }
.stat-card.full-width::before { background: linear-gradient(90deg, var(--green), var(--primary)); }

.stat-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--text);
  transition: color 0.4s ease;
}
.stat-card.full-width .stat-value { font-size: 2rem; color: var(--primary); }

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }

.stat-icon {
  position: absolute;
  top: 14px;
  right: 14px;
  color: var(--primary-lt);
}
.stat-icon .lucide { width: 24px; height: 24px; }

/* ── Action Buttons ───────────────────────────────────────────────────────── */
.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-income, .btn-expense {
  padding: 20px 16px;
  font-size: 1.1rem;
  font-weight: 800;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 80px;
  box-shadow: var(--shadow);
}

.btn-income {
  background: var(--green);
  color: white;
  box-shadow: 0 4px 16px rgba(143,175,133,0.35);
}
.btn-income:hover { background: #7A9E70; }

.btn-expense {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 16px rgba(196,120,138,0.35);
}
.btn-expense:hover { background: #AD6578; }

.btn-big-icon { display: flex; align-items: center; justify-content: center; }
.btn-big-icon .lucide { width: 28px; height: 28px; }

/* ── Transaction List ─────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
}

.btn-export {
  background: var(--primary-lt);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-export:hover { background: var(--primary); color: white; }

.tx-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tx-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 1rem;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.tx-empty-icon { display: block; margin-bottom: 12px; color: var(--primary-lt); }
.tx-empty-icon .lucide { width: 48px; height: 48px; }

.tx-item {
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform var(--transition), box-shadow var(--transition);
  animation: slideIn 0.3s ease;
  border-left: 4px solid transparent;
}
.tx-item.income { border-left-color: var(--green); }
.tx-item.expense { border-left-color: var(--red); }
.tx-item:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tx-cat-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 12px;
}

.tx-info { flex: 1; min-width: 0; }

.tx-desc {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tx-badge {
  background: var(--primary-lt);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.72rem;
}
.tx-badge.split { background: #EAF4FB; color: #3498DB; }

.tx-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.tx-amount {
  font-size: 1.1rem;
  font-weight: 900;
}
.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--red); }

.btn-delete {
  background: none;
  color: #CCC;
  font-size: 1rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.btn-delete:hover { color: var(--red); background: var(--red-lt); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--card);
  border-radius: 28px 28px 0 0;
  padding: 28px 24px 36px;
  width: 100%;
  max-width: 500px;
  max-height: 90dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
}
.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: #DDD;
  border-radius: 4px;
  margin: 0 auto -6px;
}

.modal-title {
  font-size: 1.4rem;
  font-weight: 900;
  text-align: center;
}
.modal-title.income { color: var(--green); }
.modal-title.expense { color: var(--red); }

.form-field { display: flex; flex-direction: column; gap: 6px; }

.form-label {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.split-toggle {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg);
  padding: 14px 16px;
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
}
.split-toggle input[type="checkbox"] {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  cursor: pointer;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.split-toggle-text {
  font-weight: 600;
  font-size: 0.95rem;
  flex: 1;
}
.split-toggle-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

.modal-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 4px;
}

.btn-cancel {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 700;
  padding: 16px;
}

.btn-submit-income {
  background: var(--green);
  color: white;
  font-weight: 800;
  padding: 16px;
  font-size: 1rem;
  box-shadow: 0 4px 12px rgba(143,175,133,0.35);
}
.btn-submit-expense {
  background: var(--primary);
  color: white;
  font-weight: 800;
  padding: 16px;
  font-size: 1rem;
  box-shadow: 0 4px 12px rgba(196,120,138,0.35);
}

/* ── Theme Picker Modal ───────────────────────────────────────────────────── */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 4px;
}

.theme-btn {
  border-radius: 14px;
  padding: 18px 12px;
  font-weight: 700;
  font-size: 0.85rem;
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 3px 10px rgba(0,0,0,.15);
  position: relative;
  overflow: hidden;
}
.theme-btn.active::after {
  content: '✓';
  position: absolute;
  top: 6px; right: 8px;
  font-size: 0.9rem;
  font-weight: 900;
}

.theme-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255,255,255,0.4);
  border: 2px solid rgba(255,255,255,0.7);
  display: block;
}
.theme-roze   { background: #C4788A; }
.theme-paars  { background: #9B59B6; }
.theme-mint   { background: #1ABC9C; }
.theme-geel   { background: #F39C12; }
.theme-blauw  { background: #3498DB; }
.theme-oranje { background: #E67E22; }

/* ── Footer ───────────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 20px;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.pop { animation: pop 0.35s ease; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (min-width: 480px) {
  main { padding: 24px 20px; }
  .modal { border-radius: 28px; margin-bottom: 20px; }
  .modal-overlay { align-items: center; }
}

@media (min-width: 640px) {
  .stat-card.full-width .stat-value { font-size: 2.4rem; }
  .btn-income, .btn-expense { font-size: 1.2rem; }
}

/* ── Utility ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
