/* ===== Design tokens ===== */
:root {
  --bg: #0f1524;
  --bg-elevated: #161d30;
  --sidebar-bg: #10162a;
  --card-bg: #ffffff;
  --card-bg-soft: #f6f7fb;
  --text-on-dark: #e7e9f3;
  --text-on-dark-muted: #8891ac;
  --text: #1c2130;
  --text-muted: #6b7285;
  --border: #e7e8f0;
  --accent: #6c5dd3;
  --accent-soft: #efeafc;
  --green: #1fae63;
  --green-soft: #e7f8ee;
  --red: #e0473f;
  --red-soft: #fdeceb;
  --orange: #f2994a;
  --orange-soft: #fdf1e4;
  --blue: #2f80ed;
  --blue-soft: #e8f1fd;
  --purple: #9b6bd6;
  --purple-soft: #f2eafb;
  --pink: #e6659a;
  --pink-soft: #fbe9f1;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 22, 42, 0.04), 0 8px 24px rgba(16, 22, 42, 0.06);
  --font-display: 'Sora', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --page-header-text: #ffffff;
}

[data-theme="light"] {
  --bg: #f2f3f8;
  --bg-elevated: #ffffff;
  --sidebar-bg: #171d30;
  --text-on-dark: #e7e9f3;
  --text-on-dark-muted: #8891ac;
  --page-header-text: #1c2130;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

@font-face {
  font-family: 'Sora';
  src: local('Sora');
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ===== Layout ===== */
.app {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  padding: 0 8px 24px;
}

.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  color: var(--text-on-dark-muted);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,0.05); }
.nav-link.active { color: #fff; background: var(--accent); }
.nav-link i[data-icon] { width: 18px; height: 18px; flex-shrink: 0; display: inline-flex; }
.nav-link i[data-icon]::before { content: ''; display: block; width: 18px; height: 18px; background: currentColor; -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.08); padding-top: 12px; margin-top: 12px; }
.current-user { color: var(--text-on-dark-muted); font-size: 12px; padding: 0 12px 8px; }
.current-user strong { color: #fff; }
.logout-link { color: var(--text-on-dark-muted); }
.logout-link:hover { color: #fff; }

.sidebar-overlay { display: none; }

.main { flex: 1; padding: 28px 32px 60px; min-width: 0; }

.main-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.main-header h1 {
  font-family: var(--font-display);
  color: var(--page-header-text);
  font-size: 22px;
  margin: 0;
  flex: 1;
}
.month-switcher {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-elevated);
  border-radius: 999px;
  padding: 8px 16px;
  color: var(--page-header-text);
  font-weight: 600;
  font-size: 14px;
}
.month-switcher button {
  background: none; border: none; color: var(--page-header-text); font-size: 18px; line-height: 1;
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.month-switcher button:hover { background: rgba(128,128,128,0.15); }

.theme-toggle {
  background: var(--bg-elevated);
  border: none;
  color: var(--page-header-text);
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.topbar { display: none; }
.desktop-only { display: flex; }

.view-root { display: flex; flex-direction: column; gap: 20px; }

/* ===== Cards & grid ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-family: var(--font-display);
  font-size: 15px;
  margin: 0 0 14px;
  color: var(--text);
}
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } }

/* Stat cards */
.stat-card { background: var(--card-bg); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-card .label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 8px; }
.stat-card .value { font-family: var(--font-display); font-size: 24px; font-weight: 700; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.value.pos { color: var(--green); }
.value.neg { color: var(--red); }
.value.neutral { color: var(--blue); }
.stat-card.status-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.status-icon { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }

/* Row list (Verdeling / Aanbevolen verdeling) */
.row-list { display: flex; flex-direction: column; gap: 14px; }
.row-item { display: flex; align-items: center; justify-content: space-between; font-size: 14px; }
.row-item .row-label { display: flex; align-items: center; gap: 10px; color: var(--text); }
.row-item .row-icon {
  width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0;
}
.row-item .row-amount { font-weight: 600; }
.row-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.row-total { display: flex; justify-content: space-between; font-weight: 700; font-size: 14.5px; }
.row-highlight { background: var(--green-soft); color: var(--green); border-radius: var(--radius-sm); padding: 10px 14px; display: flex; justify-content: space-between; font-weight: 700; }

.icon-blue { background: var(--blue-soft); color: var(--blue); }
.icon-green { background: var(--green-soft); color: var(--green); }
.icon-orange { background: var(--orange-soft); color: var(--orange); }
.icon-purple { background: var(--purple-soft); color: var(--purple); }
.icon-pink { background: var(--pink-soft); color: var(--pink); }
.icon-red { background: var(--red-soft); color: var(--red); }

/* Goal cards */
.goal-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; }
.goal-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.goal-card-head .row-icon { width: 34px; height: 34px; border-radius: 10px; font-size: 16px; }
.goal-card-title { font-weight: 700; font-size: 14px; }
.goal-card-sub { font-size: 12px; color: var(--text-muted); }
.progress-track { background: var(--card-bg-soft); border-radius: 999px; height: 7px; overflow: hidden; margin: 10px 0 6px; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s; }
.goal-card-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); }
.goal-card-actions { display: flex; gap: 8px; margin-top: 10px; }

/* Forms */
.form-group { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
input[type=text], input[type=number], input[type=password], input[type=email], select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--card-bg-soft);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-primary:hover { background: #5c4dc2; }
.btn-secondary { background: var(--card-bg-soft); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }

.extra-item-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.extra-item-row input[type=text] { flex: 2; }
.extra-item-row input[type=number] { flex: 1; }
.extra-item-row select { flex: 1; }
.icon-btn { background: none; border: none; color: var(--text-muted); font-size: 16px; width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon-btn:hover { background: var(--red-soft); color: var(--red); }

/* Table */
.simple-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.simple-table th { text-align: left; color: var(--text-muted); font-size: 12px; font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.simple-table td { padding: 12px 10px; border-bottom: 1px solid var(--border); }
.simple-table tr:last-child td { border-bottom: none; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }

.list-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row.dragging { opacity: 0.4; }
.list-row-main { display: flex; align-items: center; gap: 12px; }
.drag-handle { cursor: grab; color: var(--text-muted); font-size: 16px; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.reorder-btns { display: flex; flex-direction: column; gap: 1px; }
.reorder-btn { width: 20px; height: 16px; font-size: 9px; padding: 0; color: var(--text-muted); }
.reorder-btn:disabled { opacity: 0.25; cursor: default; }
.reorder-btn:hover:not(:disabled) { background: var(--card-bg-soft); color: var(--text); }
@media (max-width: 900px) {
  .drag-handle { display: none; } /* HTML5 drag-and-drop werkt niet betrouwbaar op touch; gebruik de pijltjes */
}
.list-row-title { font-weight: 600; font-size: 14px; }
.list-row-sub { font-size: 12px; color: var(--text-muted); }
.list-total { display: flex; justify-content: space-between; font-weight: 700; padding-top: 14px; margin-top: 6px; border-top: 2px solid var(--border); }

.tag { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: .02em; }
.tag-hoog { background: var(--red-soft); color: var(--red); }
.tag-gemiddeld { background: var(--orange-soft); color: var(--orange); }
.tag-laag { background: var(--blue-soft); color: var(--blue); }
.tag-blue { background: var(--blue-soft); color: var(--blue); }
.tag-green { background: var(--green-soft); color: var(--green); }
.tag-orange { background: var(--orange-soft); color: var(--orange); }
.tag-purple { background: var(--purple-soft); color: var(--purple); }
.tag-pink { background: var(--pink-soft); color: var(--pink); }
.tag-red { background: var(--red-soft); color: var(--red); }

.callout { background: var(--orange-soft); color: #8a5a1e; border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px; }
.callout ul { margin: 6px 0 0; padding-left: 18px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,13,25,0.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--card-bg); border-radius: var(--radius-lg); padding: 24px; width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin: 0 0 16px; font-family: var(--font-display); }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1c2130; color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 13.5px; z-index: 200; box-shadow: var(--shadow); }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

.loading-placeholder { color: var(--text-on-dark-muted); padding: 40px; text-align: center; }
.empty-state { color: var(--text-muted); font-size: 13.5px; text-align: center; padding: 24px 0; }
.empty-hint { color: var(--text-muted); font-size: 13.5px; text-align: left; margin: 10px 0 20px; }

/* ===== Login page ===== */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card { background: var(--bg-elevated); border-radius: var(--radius-lg); padding: 36px 32px; width: 100%; max-width: 360px; box-shadow: var(--shadow); position: relative; }
.lang-switch { position: absolute; top: 18px; right: 20px; display: flex; align-items: center; gap: 6px; font-size: 12px; }
.lang-switch a { color: var(--text-on-dark-muted); font-weight: 600; }
.lang-switch a.active { color: #fff; text-decoration: underline; }
.lang-switch span { color: var(--text-on-dark-muted); }
.login-logo { display: flex; align-items: center; gap: 10px; color: #fff; font-family: var(--font-display); font-weight: 700; margin-bottom: 22px; }
.login-card h1 { color: #fff; font-family: var(--font-display); font-size: 20px; margin: 0 0 6px; }
.login-sub { color: var(--text-on-dark-muted); font-size: 13.5px; margin: 0 0 20px; }
.login-form label { color: var(--text-on-dark-muted); font-size: 12.5px; font-weight: 600; display: block; margin-bottom: 6px; }
.login-form input { margin-bottom: 18px; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); color: #fff; }
.login-error { background: rgba(224,71,63,0.15); color: #ff8b84; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }

/* ===== Mobile ===== */
@media (max-width: 900px) {
  .desktop-only { display: none; }
  .topbar {
    display: flex; align-items: center; gap: 12px;
    background: var(--sidebar-bg); color: #fff; padding: 14px 16px;
    position: sticky; top: 0; z-index: 50;
  }
  .topbar-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-family: var(--font-display); font-size: 15px; flex: 1; }
  .hamburger, .topbar .theme-toggle { background: none; border: none; color: #fff; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
  .app { flex-direction: column; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 90;
    transform: translateX(-100%); transition: transform .25s ease;
    width: 78%; max-width: 280px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 80;
  }
  .sidebar-overlay.visible { display: block; }
  .main { padding: 16px 14px 80px; }
  .main-header h1 { display: none; }
  .main-header { margin-bottom: 14px; }
  .month-switcher { flex: 1; justify-content: center; }
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 12px; }
  .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .form-row { flex-direction: column; gap: 0; }
}
