/* ---------------------------------------------------------------- tokens */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e3e5ea;
  --text: #15171c;
  --muted: #646a76;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-weak: #eceeff;
  --ok: #16a34a;
  --ok-weak: #dcfce7;
  --warn: #d97706;
  --warn-weak: #fef3c7;
  --bad: #dc2626;
  --bad-weak: #fee2e2;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgb(16 18 27 / 0.05), 0 1px 1px rgb(16 18 27 / 0.03);
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --surface: #161920;
    --surface-2: #1e222b;
    --border: #282d38;
    --text: #e8eaf0;
    --muted: #8d94a3;
    --accent: #8b8ff9;
    --accent-text: #0e1015;
    --accent-weak: #22244a;
    --ok: #22c55e;
    --ok-weak: #11301f;
    --warn: #f59e0b;
    --warn-weak: #36270b;
    --bad: #f05252;
    --bad-weak: #3a1618;
    --shadow: none;
    color-scheme: dark;
  }
}

/* ---------------------------------------------------------------- basis */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; margin-bottom: 14px; }
h3 { font-size: 15px; font-weight: 650; margin: 22px 0 12px; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.icon { flex-shrink: 0; }

/* ---------------------------------------------------------------- layout */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 18px;
  color: var(--text); text-decoration: none; font-weight: 700;
}
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark {
  display: grid; place-items: center; flex-shrink: 0;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--accent-text);
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav button {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 9px 10px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--muted); font: inherit; font-weight: 500;
  text-decoration: none; cursor: pointer; text-align: left;
}
.nav a span, .nav button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a:hover, .nav button:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-weak); color: var(--accent); }
.nav-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }
.logout { margin: 0; }

.content { width: 100%; max-width: 1180px; padding: 34px clamp(16px, 4vw, 44px) 56px; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin-bottom: 22px;
}
.page-head p { margin: 4px 0 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 12px; }
.section-head h2 { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------------------------------------------------------------- kaarten */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card, .card + .stack, .stack + .card { margin-top: 14px; }
.widget-grid > .card, .stat-grid > .card, .stack > .card { margin-top: 0; }
.card.narrow { max-width: 520px; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 40px 20px; color: var(--muted); text-align: center; }
.empty p { margin: 0; }

/* ---------------------------------------------------------------- knoppen & formulieren */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 15px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger:hover { background: var(--bad-weak); color: var(--bad); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .nav a:focus-visible, .widget:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

input, select {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus, select:focus { border-color: var(--accent); outline: none; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 550; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 9px; color: var(--text); font-size: 14px; }
.hint { font-weight: 400; font-size: 12.5px; }

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: end; }
.form-grid .span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; }
.inline-form { display: flex; gap: 10px; }
.inline-form input { flex: 1; }

.add-card summary {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; cursor: pointer; list-style: none;
}
.add-card summary::-webkit-details-marker { display: none; }
.add-card[open] summary { margin-bottom: 16px; }
.add-card + .stack { margin-top: 14px; }

.actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.actions form { margin: 0; }

/* ---------------------------------------------------------------- meldingen */
.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.flash {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); font-size: 14px;
}
.flash.ok { background: var(--ok-weak); border-color: transparent; }
.flash.bad { background: var(--bad-weak); border-color: transparent; }
.flash-close { border: 0; background: none; color: inherit; font-size: 20px; line-height: 1; cursor: pointer; opacity: 0.6; }
.auth .flash { margin-bottom: 14px; }

/* ---------------------------------------------------------------- status */
.dot { display: inline-block; flex-shrink: 0; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.up { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-weak); }
.dot.down { background: var(--bad); box-shadow: 0 0 0 4px var(--bad-weak); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-weak); }
.dot.pending, .dot.paused { background: var(--muted); opacity: 0.6; }
.status-up { color: var(--ok); }
.status-down { color: var(--bad); }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600;
}
.badge.accent { background: var(--accent-weak); color: var(--accent); }
.badge.ok { background: var(--ok-weak); color: var(--ok); }
.badge.bad { background: var(--bad-weak); color: var(--bad); }
.inline-icon { display: inline-flex; align-items: center; gap: 7px; }
.inline-icon .icon { color: var(--muted); }

.section-head.first { margin: 0 0 14px; }
.device-list { list-style: none; margin: 0; padding: 0; }
.device-list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.device-list li:first-child { border-top: 0; padding-top: 0; }
.device-list form { margin: 0; }
.device-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.device-title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.table.events td { white-space: normal; vertical-align: top; }
.table.events .badge { white-space: nowrap; }

.live { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(34 197 94 / 0.5); } 70% { box-shadow: 0 0 0 8px rgb(34 197 94 / 0); } 100% { box-shadow: 0 0 0 0 rgb(34 197 94 / 0); } }

/* ---------------------------------------------------------------- dashboard */
.widget-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.widget {
  display: flex; flex-direction: column; gap: 12px;
  color: var(--text); text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}
.widget:hover { border-color: var(--accent); transform: translateY(-1px); }
.widget-head { display: flex; align-items: center; gap: 10px; }
.widget-label { flex: 1; font-weight: 600; }
.widget-icon {
  display: grid; place-items: center; flex-shrink: 0;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent-weak); color: var(--accent);
}
.widget-value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.widget-value small { font-size: 14px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.widget-items { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.widget-items li { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.widget.state-bad .widget-items li { color: var(--bad); }

/* ---------------------------------------------------------------- monitors */
.monitor { display: flex; flex-direction: column; gap: 14px; }
.monitor.is-paused { opacity: 0.65; }
.monitor-main { display: flex; align-items: center; gap: 14px; }
.monitor-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.monitor-title a, .monitor-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; text-decoration: none; }
.monitor-title a:hover { color: var(--accent); }
.monitor-stats { display: flex; gap: 26px; margin: 0; }
.monitor-stats dt, .stat-label { font-size: 12px; color: var(--muted); font-weight: 550; }
.monitor-stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.bars { display: flex; gap: 3px; height: 30px; }
.bar { flex: 1; min-width: 2px; border-radius: 3px; background: var(--surface-2); }
.bar.up { background: var(--ok); }
.bar.down { background: var(--bad); }
.monitor-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------------------------------------------------------------- systeem */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.stat-grid + .card { margin-top: 14px; }
.stat { display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; }
.stat-value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 16px; color: var(--muted); font-weight: 600; margin-left: 2px; }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: inherit; background: var(--ok); transition: width 0.6s ease, background 0.3s; }
.meter span[data-level="warn"] { background: var(--warn); }
.meter span[data-level="bad"] { background: var(--bad); }
.spark { width: 100%; height: 34px; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.6; vector-effect: non-scaling-stroke; stroke-linejoin: round; }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px 24px; margin: 0; }
.kv dt { font-size: 12px; color: var(--muted); font-weight: 550; }
.kv dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- taken */
.task-list { list-style: none; margin: 0; padding: 6px; }
.task { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--radius-sm); }
.task:hover { background: var(--surface-2); }
.task form { margin: 0; }
.task-title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.task-time { white-space: nowrap; }
.check-btn {
  display: grid; place-items: center;
  width: 22px; height: 22px; padding: 0;
  border: 2px solid var(--border); border-radius: 7px;
  background: none; color: transparent; cursor: pointer;
}
.check-btn:hover { border-color: var(--accent); color: var(--accent); }
.task.done .check-btn { background: var(--ok); border-color: var(--ok); color: #fff; }
.task.done .task-title { color: var(--muted); text-decoration: line-through; }

/* ---------------------------------------------------------------- apps */
.uploader { display: flex; flex-direction: column; gap: 14px; }
.uploader + .app-grid, .uploader + .empty { margin-top: 14px; }
.uploader-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.uploader-head h2 { margin: 0; }
.uploader p { margin: 0; }
.uploader-name { max-width: 420px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 28px 16px; text-align: center;
  border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--bg); transition: border-color 0.15s, background 0.15s;
}
.dropzone.is-over { border-color: var(--accent); background: var(--accent-weak); }
.dropzone-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.uploader.is-busy .dropzone { opacity: 0.5; pointer-events: none; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 0.2s; }
.upload-status:empty { display: none; }

.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.app-grid > .card { margin-top: 0; }
.app-card { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.app-main { display: flex; align-items: center; gap: 13px; color: var(--text); text-decoration: none; min-width: 0; }
a.app-main[href]:hover strong { color: var(--accent); }
.app-icon {
  display: grid; place-items: center; flex-shrink: 0;
  width: 48px; height: 48px; border-radius: 12px; object-fit: cover;
  background: var(--surface-2);
}
.app-icon.letter { background: var(--accent-weak); color: var(--accent); font-size: 21px; font-weight: 700; }
.app-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.app-text strong, .app-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-open { color: var(--muted); }
.app-meta { display: flex; flex-direction: column; gap: 3px; }
.app-meta span { display: inline-flex; align-items: center; gap: 6px; overflow-wrap: anywhere; }
.app-card .actions { justify-content: flex-start; margin: 0 -6px -4px; border-top: 1px solid var(--border); padding-top: 8px; }
.app-card.is-broken .app-icon { opacity: 0.5; }

/* ---------------------------------------------------------------- 2FA */
.code-input { font-family: var(--mono); font-size: 20px; letter-spacing: 0.25em; text-align: center; height: 48px; }
.inline-form .code-input { max-width: 200px; }
.recovery { margin-top: 18px; }
.recovery summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.recovery[open] summary { margin-bottom: 12px; }
.cancel-login { margin: 14px 0 0; text-align: center; }
.setup-steps ol { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 22px; }
.setup-steps li { display: flex; flex-direction: column; gap: 8px; }
.setup-steps li::marker { font-weight: 700; color: var(--accent); }
.qr { align-self: flex-start; line-height: 0; border-radius: 12px; overflow: hidden; }
.qr svg { display: block; width: 210px; height: 210px; }
.secret { align-self: flex-start; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); font-size: 14px; letter-spacing: 0.04em; overflow-wrap: anywhere; }
.recovery-codes { list-style: none; margin: 16px 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.recovery-codes li { padding: 10px; border-radius: 8px; background: var(--surface-2); text-align: center; font-size: 16px; letter-spacing: 0.05em; }
.codes-actions { justify-content: flex-start; gap: 8px; }
.twofa-manage { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }
.twofa-manage details { flex: 1 1 260px; }
.twofa-manage summary { list-style: none; display: inline-flex; }
.twofa-manage summary::-webkit-details-marker { display: none; }
.twofa-manage details[open] summary { margin-bottom: 10px; }
.btn.danger:not(.ghost) { color: var(--bad); }
.nudge { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; color: var(--text); text-decoration: none; border-color: var(--accent); }
.nudge > span:nth-child(2) { flex: 1; display: flex; flex-direction: column; }
.nudge:hover { background: var(--accent-weak); }

/* ---------------------------------------------------------------- app-database */
.back-link { display: inline-block; margin-bottom: 6px; color: var(--muted); text-decoration: none; }
.back-link:hover { color: var(--accent); }
textarea {
  width: 100%; padding: 10px 12px; resize: vertical;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font: inherit;
}
textarea:focus { border-color: var(--accent); outline: none; }
textarea.mono { font-family: var(--mono); font-size: 13.5px; }
.db-tables { display: flex; flex-direction: column; }
.db-table { border-top: 1px solid var(--border); padding: 10px 0; }
.db-table:first-child { border-top: 0; padding-top: 0; }
.db-table summary { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.db-columns { margin: 10px 0 6px; padding: 0 0 0 18px; display: flex; flex-direction: column; gap: 2px; }
.db-peek { margin: 4px 0 0; }
.db-result { margin-top: 16px; }
.db-grid td { max-width: 320px; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 13px; }
.db-io { display: flex; flex-direction: column; gap: 14px; }
.db-import { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin: 0; }
.db-import label { flex: 1 1 260px; }
.db-import input[type="file"] { height: auto; padding: 8px; }
.db-import .upload-status { flex-basis: 100%; margin: 0; }
.db-actions { justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
.code-block {
  margin: 0; padding: 14px 16px; overflow-x: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: 13px/1.55 var(--mono);
}

/* ---------------------------------------------------------------- beheer */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 12px 10px; }
.table td { padding: 10px 12px; border-top: 1px solid var(--border); white-space: nowrap; }
.module-list { list-style: none; margin: 0; padding: 0; }
.module-list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.module-list li > div { flex: 1; min-width: 0; }

/* ---------------------------------------------------------------- inloggen */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; padding: 30px; }
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-card .form-stack { margin-top: 18px; }
.auth-brand { padding: 0 0 22px; }

.error-page { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 50px 0; text-align: center; }
.error-code { font-size: 64px; font-weight: 800; color: var(--accent); line-height: 1; }

/* ---------------------------------------------------------------- telefoon */
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; z-index: 20;
    height: auto; flex-direction: row; gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border);
    overflow-x: auto; scrollbar-width: none;
  }
  .brand, .logout { display: none; }
  .nav { display: contents; }
  .nav a { flex: 1 0 44px; flex-direction: column; gap: 3px; padding: 7px 2px; font-size: 10px; text-align: center; }
  .nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .content { padding: 22px 16px 104px; }
  h1 { font-size: 23px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .monitor-main { flex-wrap: wrap; }
  .monitor-stats { width: 100%; gap: 18px; padding-left: 24px; }
  .monitor-foot { flex-direction: column; align-items: stretch; }
  .monitor-foot .actions { justify-content: flex-start; }
  .bars { gap: 2px; }
  .inline-form .btn span { display: none; }
  .table th, .table td { padding-left: 6px; padding-right: 6px; }
  .device-list .btn span { display: none; }
}
