/* ── Tokens ──────────────────────────────────────────────────────────────── */
:root {
  --bg:          #ffffff;
  --bg-subtle:   #f4f6fb;
  --bg-card:     #ffffff;
  --border:      #e3e7f0;
  --border-strong: #c4ccdd;
  --text:        #1a1f2b;
  --text-muted:  #5a6472;
  --text-faint:  #6b7482;
  --brand:       #05164c;
  --accent:      #0044f5;
  --accent-inv:  #ffffff;
  --danger:      #cc0000;
  --success:     #007a00;
  --shadow:      0 1px 3px rgba(5, 22, 76, 0.09), 0 1px 2px rgba(5, 22, 76, 0.05);
  --mono:        "JetBrains Mono", "Fira Mono", "Courier New", monospace;
  --sans:        "Inter", system-ui, -apple-system, sans-serif;
  --radius:      6px;
  --nav-h:       60px;
  --max-w:       1080px;
  --transition:  0.15s ease;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0a0d12;
    --bg-subtle:   #131822;
    --bg-card:     #1b2230;
    --border:      #313a4d;
    --border-strong: #4a5569;
    --text:        #e7ebf3;
    --text-muted:  #a3acc0;
    --text-faint:  #7c869c;
    --brand:       #eef1fb;
    --accent:      #3b7bff;
    --accent-inv:  #ffffff;
    --danger:      #ff6b6b;
    --success:     #22c55e;
    --shadow:      0 1px 3px rgba(0, 0, 0, 0.6), 0 4px 14px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  --bg:          #0a0d12;
  --bg-subtle:   #131822;
  --bg-card:     #1b2230;
  --border:      #313a4d;
  --border-strong: #4a5569;
  --text:        #e7ebf3;
  --text-muted:  #a3acc0;
  --text-faint:  #7c869c;
  --brand:       #eef1fb;
  --accent:      #3b7bff;
  --accent-inv:  #ffffff;
  --danger:      #ff6b6b;
  --success:     #22c55e;
  --shadow:      0 1px 3px rgba(0, 0, 0, 0.6), 0 4px 14px rgba(0, 0, 0, 0.4);
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
}

main { flex: 1; }

/* ── Typography ──────────────────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--brand);
}
h1 { font-size: 2.15rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }

p { color: var(--text); }
p + p { margin-top: 0.9rem; }

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { opacity: 0.7; }

code, kbd, pre, .mono {
  font-family: var(--mono);
  font-size: 0.875em;
}

code {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.15em 0.4em;
}

pre {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  overflow-x: auto;
  line-height: 1.5;
}

/* ── Nav ─────────────────────────────────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  isolation: isolate;
  height: var(--nav-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1.5rem;
  transition: background var(--transition);
}

.nav-brand {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--brand);
  margin-right: auto;
}
.nav-brand span { opacity: 0.4; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
}

.nav-links a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius);
  transition: background var(--transition), color var(--transition);
}
.nav-links a:hover { background: var(--bg-subtle); color: var(--text); opacity: 1; }
.nav-links a.active { color: var(--text); background: var(--bg-subtle); }

.nav-actions { display: flex; align-items: center; gap: 0.25rem; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius);
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  cursor: pointer; transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--bg-subtle); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: inline; }
}
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }

.nav-toggle { display: none; }

/* ── Tabs (Settings sub-navigation) ─────────────────────────────────────── */
.tab-bar {
  display: flex; gap: 0.25rem; margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-bar a {
  font-size: 0.875rem; font-weight: 500; color: var(--text-muted);
  text-decoration: none; white-space: nowrap;
  padding: 0.6rem 0.85rem; margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.tab-bar a:hover { color: var(--text); }
.tab-bar a.active { color: var(--accent); border-bottom-color: var(--accent); }

@media (max-width: 700px) {
  html { font-size: 15px; }
  .nav { padding: 0 1rem; gap: 0.75rem; }
  .page { padding: 1.75rem 1rem 3rem; }
  .page-narrow { padding: 2.5rem 1rem 3rem; }
  h1 { font-size: 1.7rem; }
  h2 { font-size: 1.2rem; }
  .card { padding: 1.15rem; border-radius: 10px; }
  .card-header { margin-bottom: 1rem; padding-bottom: 0.75rem; flex-wrap: wrap; gap: 0.5rem; }
  .btn { padding: 0.65rem 1rem; }
  .btn-lg { padding: 0.8rem 1.4rem; font-size: 1rem; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  .nav-toggle { display: inline-flex; }
  .nav-links {
    display: none;
    position: absolute;
    top: var(--nav-h);
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 0.5rem 1rem 0.75rem;
  }
  .nav-links.open { display: flex; }
  .nav-links a { padding: 0.6rem 0.75rem; }
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.page {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
}

.page-narrow {
  max-width: 420px;
  margin: 0 auto;
  padding: 4rem 1.5rem 5rem;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 1rem; }
.card-grid > .card { margin-top: 0; }

.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }

label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

input[type="text"],
input[type="email"],
input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.9375rem;
  transition: border-color var(--transition);
  outline: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus {
  border-color: var(--text);
}

input[type="checkbox"] { accent-color: var(--text); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.7rem 1.4rem;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity var(--transition), background var(--transition);
  border: 1px solid transparent;
  line-height: 1.4;
}
.btn:disabled { cursor: default; opacity: 0.4; }
.btn:disabled:hover { background: inherit; opacity: 0.4; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-inv);
  border-color: var(--accent);
}
.btn-primary:hover { opacity: 0.88; color: var(--accent-inv); }

.btn-ghost {
  background: transparent;
  color: var(--brand);
  border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--bg-subtle); opacity: 1; }
.btn-ghost.active { background: var(--accent); color: var(--accent-inv); border-color: var(--accent); }
.btn-ghost.active:hover { background: var(--accent); opacity: 1; }

.btn-lg { padding: 0.9rem 2rem; font-size: 1.05rem; border-radius: var(--radius); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; opacity: 1; }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8125rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  border: 1px solid;
  margin-bottom: 1.25rem;
}
.alert-error  { border-color: var(--danger);  color: var(--danger);  background: color-mix(in srgb, var(--danger) 8%, var(--bg)); }
.alert-success{ border-color: var(--success); color: var(--success); background: color-mix(in srgb, var(--success) 8%, var(--bg)); }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

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

th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-subtle); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15em 0.5em;
  border-radius: 2px;
  border: 1px solid;
}
.badge-admin { border-color: var(--text); color: var(--text); }
.badge-user  { border-color: var(--border-strong); color: var(--text-muted); }

/* ── Divider ─────────────────────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ── Section header ──────────────────────────────────────────────────────── */
.section-label {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.85rem;
}

/* ── Login page hero ─────────────────────────────────────────────────────── */
.login-hero {
  text-align: center;
  margin-bottom: 2.5rem;
}

.login-hero .wordmark {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.login-hero p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.4rem;
}

/* ── Content prose ───────────────────────────────────────────────────────── */
.prose h2 { margin: 2rem 0 0.6rem; }
.prose h3 { margin: 1.5rem 0 0.4rem; }
.prose p  { margin-bottom: 0.9rem; color: var(--text-muted); }
.prose ul { padding-left: 1.4rem; color: var(--text-muted); }
.prose ul li { margin-bottom: 0.3rem; }
.prose pre { margin: 1rem 0; }

/* ── Inline form row ─────────────────────────────────────────────────────── */
.inline-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
.inline-form .form-group { margin-bottom: 0; flex: 1; min-width: 120px; }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.text-muted  { color: var(--text-muted); }
.text-faint  { color: var(--text-faint); }
.text-mono   { font-family: var(--mono); }
.text-sm     { font-size: 0.875rem; }
.text-xs     { font-size: 0.75rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.5rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* ── Extra form controls (not in the original template) ─────────────────── */
input[type="number"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.9375rem;
  transition: border-color var(--transition);
  outline: none;
}
input[type="number"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
select:focus,
textarea:focus { border-color: var(--text); }

textarea { font-family: var(--mono); font-size: 0.8125rem; resize: vertical; min-height: 140px; }

input[type="checkbox"] { width: auto; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; }

/* ── KPI-tegels ──────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow);
}
.kpi-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.kpi-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px; flex: none;
}
.kpi-icon svg { width: 16px; height: 16px; }
.kpi-icon-import, .kpi-icon-usage-elec { background: rgba(0, 68, 245, 0.12); color: var(--accent); }
.kpi-icon-export { background: rgba(0, 122, 0, 0.12); color: var(--success); }
.kpi-icon-gas { background: rgba(204, 102, 0, 0.12); color: #cc6600; }
.kpi-label {
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-muted);
}
.kpi-value { font-size: 1.35rem; font-weight: 700; color: var(--brand); letter-spacing: -0.02em; white-space: nowrap; }
.kpi-sub { font-size: 0.8rem; color: var(--text-faint); margin-top: 0.25rem; }

/* ── File drop ───────────────────────────────────────────────────────────── */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: 12px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  transition: border-color var(--transition), background var(--transition);
  cursor: pointer;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--bg-subtle); }
.dropzone input[type="file"] { display: none; }

/* ── Toggle switch (P1 aan/uit) ─────────────────────────────────────────── */
.toggle-row { display: flex; align-items: center; gap: 0.75rem; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border-strong); border-radius: 999px; transition: var(--transition);
}
.switch .slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: var(--transition);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ── Chart container ─────────────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 320px; }
