/* ==========================================================================
   app.css — één stylesheet, geen preprocessor, geen build-stap.
   ==========================================================================
   Ontwerprichting: de gebruiker komt van Kontentino en is die look gewend.
   Witte kaarten op een zeer lichte achtergrond, een smalle icoon-rail links
   met labels onder de iconen, blauw als primaire kleur, veel witruimte,
   subtiele randen in plaats van zware schaduwen, 10px hoeken.

   Alle kleuren komen uit CSS-variabelen op :root, met een volledige
   dark-mode via prefers-color-scheme. Wil je de huisstijl aanpassen, dan
   hoef je alleen de variabelen hieronder te wijzigen.
   ========================================================================== */

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e3e8ef;
  --text: #17202f;
  --text-dim: #6b7788;
  --primary: #2563eb;
  /* Wordt bij het opstarten overschreven met de merkkleur uit app_branding,
     als inline stijl op :root (zie js/lib/branding.js). Daardoor werkt de hele
     stylesheet mee zonder dat er iets aangepast hoeft te worden. */
  --accent: #2563eb;
  /* Tekstkleur die op --primary leesbaar is. branding.js rekent die uit, zodat
     een lichte merkkleur zwarte letters op de knop krijgt in plaats van witte. */
  --primary-ink: #ffffff;
  --accent-ink: #ffffff;
  /* Afgeleid van --primary in plaats van een vaste hex: kiest iemand groen als
     merkkleur, dan wordt de zachte variant ook groen — en in de donkere modus
     automatisch een donkere tint, omdat --surface meebeweegt. */
  --primary-soft: color-mix(in srgb, var(--primary) 13%, var(--surface));
  --accent-soft: color-mix(in srgb, var(--accent) 13%, var(--surface));
  --danger: #dc2626;
  --ok: #15a34a;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);

  /* Afgeleide waardes; niet bedoeld om los aan te passen. */
  --danger-soft: #fdeaea;
  --ok-soft: #e6f6ec;
  --warn-soft: #fdf1e0;
  --neutral-soft: #eef1f5;
  --sidebar-w: 88px;
  --topbar-h: 60px;
  --focus: 0 0 0 3px color-mix(in srgb, var(--primary) 28%, transparent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1218;
    --surface: #161b23;
    --surface-2: #1b212b;
    --border: #272f3b;
    --text: #e6eaf1;
    --text-dim: #8d99aa;
    /* Geen eigen --primary in het donker: de merkkleur uit app_branding is in
       beide thema's dezelfde kleur. Zonder huisstijl valt dit terug op de
       standaard uit :root, die op donker ook prima leest.
       --primary-soft en --accent-soft komen uit color-mix met --surface en
       worden hier dus automatisch een donkere tint. */
    --primary: #4d8ef7;
    --accent: #4d8ef7;
    --danger: #f26d6d;
    --ok: #4ac07c;
    --warn: #e0a244;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);

    --danger-soft: #2e1a1c;
    --ok-soft: #15271d;
    --warn-soft: #2c2213;
    --neutral-soft: #1f2631;
  }
}

/* ── Basis ───────────────────────────────────────────────────────────────── */

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: 6px;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 12px 8px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  margin-bottom: 10px;
  color: var(--primary);
  flex: 0 0 auto;
}

.sidebar-item {
  display: flex;
  flex-direction: column;   /* label ONDER het icoon, zoals in Kontentino */
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px 4px 8px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  position: relative;
  cursor: pointer;
  border: 0;
  background: none;
  width: 100%;
  transition: background-color .12s ease, color .12s ease;
}
.sidebar-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar-item svg { width: 21px; height: 21px; flex: 0 0 auto; }
.sidebar-item .sidebar-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}
.sidebar-item.active::before {
  /* Smal streepje links, het Kontentino-accent voor de actieve sectie. */
  content: "";
  position: absolute;
  left: -8px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}

.sidebar-count {
  position: absolute;
  top: 4px;
  right: 10px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.content {
  flex: 1 1 auto;
  min-width: 0;
  padding: 24px 24px 64px;
  max-width: 1400px;
  width: 100%;
}

/* ── Kaarten ─────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.card-body { padding: 18px; }

.card-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* Een kaart die alleen een tabel bevat wil geen dubbele padding. */
.card-body.is-flush { padding: 0; }

/* ── Knoppen ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .12s ease, border-color .12s ease, opacity .12s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  /* Niet hard #fff: bij een lichte merkkleur zet branding.js dit op zwart,
     anders is het label onleesbaar. */
  color: var(--primary-ink);
}
.btn-primary:hover {
  background: color-mix(in srgb, var(--primary) 88%, #000);
  border-color: color-mix(in srgb, var(--primary) 88%, #000);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger {
  background: transparent;
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger-soft); }

.btn-sm {
  height: 29px;
  padding: 0 10px;
  font-size: 13px;
  gap: 5px;
}
.btn-sm svg { width: 14px; height: 14px; }

.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn-loading::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin .7s linear infinite;
  /* currentColor is transparant gezet, dus expliciet terugzetten. */
  color: var(--text);
}
.btn-primary.btn-loading::after { color: var(--primary-ink); }
.btn-danger.btn-loading::after { color: var(--danger); }

/* Een knop die alleen een icoon bevat. */
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 29px; }

/* ── Badges ──────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--neutral-soft);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1;
}

/* Postfases: grijs -> blauw -> groen. Rood/oranje alleen bij aandacht. */
.badge-draft             { background: var(--neutral-soft); color: var(--text-dim); }
.badge-internal_review   { background: var(--neutral-soft); color: var(--text); }
.badge-client_review     { background: var(--primary-soft); color: var(--primary); }
.badge-changes_requested { background: var(--warn-soft); color: var(--warn); }
.badge-approved          { background: var(--ok-soft); color: var(--ok); }
.badge-scheduled         { background: var(--primary-soft); color: var(--primary); }
.badge-published         { background: var(--ok-soft); color: var(--ok); }
.badge-partially_failed  { background: var(--warn-soft); color: var(--warn); }
.badge-failed            { background: var(--danger-soft); color: var(--danger); }

/* Target- en jobstatussen */
.badge-pending           { background: var(--neutral-soft); color: var(--text-dim); }
.badge-publishing        { background: var(--primary-soft); color: var(--primary); }
.badge-running           { background: var(--primary-soft); color: var(--primary); }
.badge-done              { background: var(--ok-soft); color: var(--ok); }
.badge-needs_review      { background: var(--danger-soft); color: var(--danger); }

/* Verbindingsstatus */
.badge-ok                { background: var(--ok-soft); color: var(--ok); }
.badge-expiring          { background: var(--warn-soft); color: var(--warn); }
.badge-broken            { background: var(--danger-soft); color: var(--danger); }

/* Bolletje voor in een badge, bv. de verbindingsstatus. */
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

/* ── Formulieren ─────────────────────────────────────────────────────────── */

.field { display: block; margin: 0 0 14px; }
.field:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.field-label .req { color: var(--danger); margin-left: 2px; }

.field-hint {
  display: block;
  margin-top: 5px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.field-error {
  display: block;
  margin-top: 5px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--danger);
}

.input, .textarea, .select {
  display: block;
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:hover, .textarea:hover, .select:hover {
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus);
}
.input::placeholder, .textarea::placeholder { color: var(--text-dim); }
.input:disabled, .textarea:disabled, .select:disabled {
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: not-allowed;
}

.textarea { min-height: 92px; resize: vertical; line-height: 1.5; }

.select {
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%236b7788' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
}

/* Een input met een fout eronder krijgt een rode rand. */
.field:has(.field-error) .input,
.field:has(.field-error) .textarea,
.field:has(.field-error) .select { border-color: var(--danger); }

/* Kleurkiezer voor de merkkleur van een klant. */
.input-color {
  width: 44px;
  height: 36px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  flex: 0 0 auto;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
}
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }

/* ── Hulpklassen ─────────────────────────────────────────────────────────── */

.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { gap: 8px; }
.stack-lg { gap: 24px; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-tight { gap: 6px; }
.row-top { align-items: flex-start; }
.row-nowrap { flex-wrap: nowrap; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.spacer { flex: 1 1 auto; min-width: 0; }

.muted { color: var(--text-dim); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.right { text-align: right; }

.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.page-title { display: flex; align-items: center; gap: 10px; }

/* Waarschuwingsstrook. Bewust luid: hiermee mist de gebruiker een
   verbroken kanaal niet meer, wat bij Kontentino het probleem was. */
.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-dim);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 14px;
}
.notice-danger { border-left-color: var(--danger); background: var(--danger-soft); }
.notice-warn   { border-left-color: var(--warn);   background: var(--warn-soft); }
.notice-ok     { border-left-color: var(--ok);     background: var(--ok-soft); }
.notice-info   { border-left-color: var(--primary); background: var(--primary-soft); }
.notice svg { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; }

/* ── Tabellen ────────────────────────────────────────────────────────────── */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .col-actions { text-align: right; white-space: nowrap; width: 1%; }

/* Tabellen mogen horizontaal scrollen in plaats van de pagina op te blazen. */
.table-scroll { overflow-x: auto; }

/* ── Modal ───────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(16, 24, 40, .45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px 16px;
  overflow-y: auto;
  animation: fade .12s ease;
}

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(16, 24, 40, .22);
  animation: pop .14s ease;
}

.modal-wide { max-width: 860px; }

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
  font-weight: 600;
}

.modal-body { padding: 18px; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 14px 14px;
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

/* ── Toasts ──────────────────────────────────────────────────────────────── */

.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 40px));
  pointer-events: none;
}

.toast {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 6px 20px rgba(16, 24, 40, .16);
  font-size: 14px;
  pointer-events: auto;
  animation: slide-in .16s ease;
}

.toast-error   { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--ok); }

/* ── Avatar ──────────────────────────────────────────────────────────────── */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
  overflow: hidden;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ── Platform-iconen ─────────────────────────────────────────────────────── */

.platform-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  vertical-align: middle;
}
.platform-icon svg { display: block; width: 100%; height: 100%; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  flex: 0 0 auto;
  border: 2px solid color-mix(in srgb, var(--text-dim) 35%, transparent);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.loading-page {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 50vh;
  color: var(--text-dim);
}

/* ── Lege staat ──────────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 44px 24px;
  text-align: center;
  color: var(--text-dim);
}
.empty-state h3 { color: var(--text); font-size: 15px; }
.empty-state p { max-width: 380px; font-size: 14px; }
.empty-state > :last-child { margin-top: 6px; }

/* ── Tabs ────────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-dim);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-count {
  min-width: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--neutral-soft);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}
.tab.active .tab-count { background: var(--primary-soft); color: var(--primary); }

/* ── Klant-switcher in de topbar ─────────────────────────────────────────── */

.client-switcher { display: flex; align-items: center; gap: 8px; min-width: 0; }
.client-switcher .select { width: auto; min-width: 190px; max-width: 280px; }

.client-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--primary);
  flex: 0 0 auto;
}

/* ── Login ───────────────────────────────────────────────────────────────── */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(16, 24, 40, .07);
  padding: 28px;
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  color: var(--primary);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-dim);
  font-size: 12.5px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Logo in de sidebar-kop ──────────────────────────────────────────────── */

.sidebar-brand { text-decoration: none; overflow: hidden; }
.sidebar-brand:hover { text-decoration: none; }

.sidebar-logo {
  max-width: 100%;
  max-height: 34px;
  object-fit: contain;
  display: block;
}

.sidebar-brand-text {
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  text-align: center;
  /* Twee regels ruimte voor een langere bureaunaam, daarna afkappen. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

/* ── Notificatiebel in de topbar ─────────────────────────────────────────── */

.bell-wrap { position: relative; flex: 0 0 auto; }

.bell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
}
.bell:hover { background: var(--surface-2); color: var(--text); }
.bell svg { width: 19px; height: 19px; }
.bell.has-unread { color: var(--text); }

.bell-count {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  border: 2px solid var(--surface);
  box-sizing: content-box;
}

.bell-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-width: calc(100vw - 24px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(16, 24, 40, .16);
  z-index: 60;
  overflow: hidden;
  animation: pop .12s ease;
}

.bell-panel-head,
.bell-panel-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 14px;
}
.bell-panel-head { border-bottom: 1px solid var(--border); }
.bell-panel-foot {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  justify-content: center;
}

.bell-link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--primary);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.bell-link:hover { text-decoration: underline; }

.bell-panel-body { max-height: min(60vh, 420px); overflow-y: auto; }

.bell-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.bell-item:last-child { border-bottom: 0; }
.bell-item:hover { background: var(--surface-2); }
.bell-item.unread { background: var(--primary-soft); }
.bell-item.unread:hover { background: color-mix(in srgb, var(--primary) 18%, var(--surface)); }

.bell-dot {
  width: 7px;
  height: 7px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--primary);
  flex: 0 0 auto;
}

.bell-item-title {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}
.bell-item-body {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 2px;
}
.bell-item-time {
  display: block;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 3px;
}

/* ── Instellingen: formulier naast voorbeeld ─────────────────────────────── */

.settings-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 420px);
  gap: 16px;
  align-items: start;
}

/* Het voorbeeld blijft in beeld terwijl je door het formulier scrollt: dat is
   het hele punt van een live voorbeeld. */
.settings-preview { position: sticky; top: calc(var(--topbar-h) + 16px); }

/* ── Voorbeeld: app-header ───────────────────────────────────────────────── */

.preview-app {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  font-size: 11px;
}

.preview-app-rail {
  width: 66px;
  flex: 0 0 66px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 8px 6px;
}

.preview-app-logo {
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
.preview-app-logo img { max-width: 100%; max-height: 24px; object-fit: contain; }

.preview-app-item {
  padding: 6px 4px;
  border-radius: 6px;
  text-align: center;
  color: var(--text-dim);
  font-weight: 500;
  margin-bottom: 2px;
}

.preview-app-main { flex: 1; min-width: 0; }

.preview-app-top {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.preview-bell {
  position: relative;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--text-dim);
}
.preview-bell-count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
}

.preview-app-body {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px 10px;
}

.preview-chip {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.preview-btn {
  border: 0;
  border-radius: 6px;
  padding: 7px 14px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: default;
}

/* ── Voorbeeld: e-mail ───────────────────────────────────────────────────── */
/* Zelfde opbouw als supabase/functions/_shared/email/render.ts: 600px kaart,
   1px rand, 8px hoeken, 4px kleurbalk bovenaan, knop als gekleurd blok. Op
   schaal, zodat het naast het formulier past. */

.preview-mail {
  background: #ffffff;
  border: 1px solid #e3e8ef;
  border-radius: 8px;
  overflow: hidden;
  /* Vaste lichte kleuren: een mail heeft geen dark mode, dus het voorbeeld
     moet er ook in de donkere app uitzien zoals de ontvanger hem krijgt. */
  color: #17202f;
}
.preview-mail.is-off { opacity: .55; }

.preview-mail-bar { height: 4px; }
.preview-mail-inner { padding: 18px 20px 16px; }

.preview-mail-head {
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid #eef1f5;
}
.preview-mail-logo { max-height: 30px; max-width: 160px; object-fit: contain; display: block; }
.preview-mail-name { font-size: 15px; font-weight: 700; color: #17202f; }

.preview-mail-title {
  margin: 12px 0 8px;
  font-size: 17px;
  line-height: 1.35;
  color: #17202f;
}

.preview-mail-text {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.55;
  color: #3d4759;
  white-space: pre-line;
}

.preview-mail-facts {
  background: #f7f9fc;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 0 0 14px;
  font-size: 12px;
}
.preview-mail-facts > div {
  display: flex;
  gap: 10px;
  padding: 2px 0;
}
.preview-mail-facts .muted { color: #6b7788; min-width: 74px; flex: 0 0 74px; }
.preview-mail-facts strong { color: #17202f; font-weight: 600; min-width: 0; }
.preview-mail-facts-note {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #dfe4ec;
  color: #8b96a5;
  font-size: 11px;
  font-style: italic;
}

.preview-mail-btn {
  display: inline-block;
  padding: 11px 22px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}

.preview-mail-foot {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #eef1f5;
  font-size: 11px;
  line-height: 1.5;
  color: #6b7788;
  white-space: pre-line;
}

.preview-subject {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
}
.preview-subject .strong { font-size: 14px; margin: 2px 0 3px; }

/* ── Upload-rij in het huisstijlscherm ───────────────────────────────────── */

.upload-row { display: flex; align-items: flex-start; gap: 12px; }

.upload-preview {
  width: 96px;
  height: 60px;
  flex: 0 0 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 6px;
  overflow: hidden;
}
.upload-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
/* Vaste achtergrond per variant: een logo voor de lichte modus moet je op wit
   beoordelen, ook als de app zelf donker staat. */
.upload-preview.is-light { background: #ffffff; }
.upload-preview.is-dark  { background: #14181f; }
.upload-preview.is-tiny  { width: 60px; flex: 0 0 60px; height: 60px; background: var(--surface-2); }
.upload-preview.is-tiny img { max-width: 32px; max-height: 32px; }

/* Een <label> die als knop dient rond een verborgen file-input. */
label.btn { cursor: pointer; }

/* ── E-mail-editor: drie kolommen ────────────────────────────────────────── */

.email-layout {
  display: grid;
  grid-template-columns: minmax(190px, 240px) minmax(0, 1fr) minmax(0, 380px);
  gap: 16px;
  align-items: start;
}

.email-list { position: sticky; top: calc(var(--topbar-h) + 16px); }
.email-list .card-body { max-height: min(70vh, 620px); overflow-y: auto; }
.email-preview { position: sticky; top: calc(var(--topbar-h) + 16px); }

.email-group {
  padding: 9px 14px 5px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.email-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.email-item:hover { background: var(--surface-2); }
.email-item.active {
  background: var(--primary-soft);
  border-left-color: var(--primary);
}
.email-item.is-off .email-item-label { text-decoration: line-through; opacity: .7; }

.email-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.email-item-label { font-size: 13.5px; font-weight: 600; flex: 1; min-width: 0; }
.email-item-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  font-size: 11.5px;
  min-width: 0;
}
.email-item-meta .badge { height: 18px; font-size: 10.5px; padding: 0 7px; }

/* ── Variabele-chips ────────────────────────────────────────────────────── */

.var-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 14px;
}

.var-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.var-chip {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  padding: 4px 8px;
  cursor: pointer;
}
.var-chip:hover { background: var(--primary-soft); border-color: var(--primary); }
/* Beschikbaar maar nergens gebruikt: gedempt, zodat je ziet wat je nog kunt pakken. */
.var-chip.is-unused { color: var(--text-dim); }

/* ── Kanaalgroepen ───────────────────────────────────────────────────────── */

.group-section {
  display: block;
  background: var(--surface);
  border-top: 1px dashed var(--border);
}

.group-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.group-chip {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
  max-width: 100%;
}
.group-chip:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }

.group-chip-move {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}
.group-chip-move button {
  border: 0;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 5px;
  font-size: 8px;
  line-height: 1;
  flex: 1;
}
.group-chip-move button:hover:not(:disabled) { background: var(--surface); color: var(--text); }
.group-chip-move button:disabled { opacity: .3; cursor: default; }

.group-chip-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  padding: 6px 10px;
  cursor: pointer;
  min-width: 0;
}
.group-chip-main .strong { font-size: 13px; max-width: 200px; }
.group-chip-count { font-size: 11.5px; color: var(--text-dim); }

.group-chip-x {
  border: 0;
  border-left: 1px solid var(--border);
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 9px;
  font-size: 16px;
  line-height: 1;
}
.group-chip-x:hover { background: var(--danger-soft); color: var(--danger); }

/* Ledenkiezer in de groep-dialoog: eenvoudige lijst met vinkjes. */
.group-picker {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
}

.group-pick {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
}
.group-pick:last-child { border-bottom: 0; }
.group-pick:hover { background: var(--surface-2); }
.group-pick input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; flex: 0 0 auto; }

/* ── Responsive voor de nieuwe schermen ─────────────────────────────────── */

@media (max-width: 1250px) {
  /* Drie kolommen naast elkaar wordt te smal: het voorbeeld gaat onder de editor. */
  .email-layout { grid-template-columns: minmax(180px, 220px) minmax(0, 1fr); }
  .email-preview { grid-column: 1 / -1; position: static; }
}

@media (max-width: 1000px) {
  .settings-split { grid-template-columns: minmax(0, 1fr); }
  .settings-preview { position: static; }
}

@media (max-width: 760px) {
  .email-layout { grid-template-columns: minmax(0, 1fr); }
  .email-list { position: static; }
  .email-list .card-body { max-height: 260px; }
}

@media (max-width: 640px) {
  /* Paneel over de volle breedte, anders valt hij van het scherm af. */
  .bell-panel {
    position: fixed;
    top: calc(var(--topbar-h) + 4px);
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
  }
  .preview-app-rail { display: none; }
}

/* ── Animaties ───────────────────────────────────────────────────────────── */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(-8px) scale(.98); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .spinner, .btn-loading::after { animation-duration: .7s !important; animation-iteration-count: infinite !important; }
}

/* ==========================================================================
   Responsive
   - < 900px: sidebar klapt in tot alleen iconen
   - < 640px: sidebar wordt een bottom-bar
   ========================================================================== */

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 60px; }

  /* Labels verdwijnen, iconen blijven. De title-attributen op de items
     zorgen dat je nog steeds kunt zien waar je op klikt. */
  .sidebar-item .sidebar-label { display: none; }
  .sidebar-item { padding: 10px 4px; }
  .sidebar-count { top: 2px; right: 5px; }

  .content { padding: 18px 16px 56px; }
  .topbar { padding: 0 14px; gap: 8px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .client-switcher .select { min-width: 140px; }
}

@media (max-width: 640px) {
  .app { display: block; }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: auto;
    height: auto;
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: space-around;
    gap: 0;
    padding: 6px 4px;
    border-right: 0;
    border-top: 1px solid var(--border);
    overflow-x: auto;
    z-index: 30;
    /* Ruimte voor de iOS home-indicator. */
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  /* Het logo hoort niet in een bottom-bar. */
  .sidebar-brand { display: none; }

  .sidebar-item { width: auto; min-width: 52px; flex: 1 1 0; }
  .sidebar-item.active { background: transparent; }
  .sidebar-item.active::before {
    /* Streepje verhuist van links naar boven. */
    left: 6px;
    right: 6px;
    top: -6px;
    bottom: auto;
    width: auto;
    height: 3px;
    border-radius: 0 0 3px 3px;
  }

  .main { min-height: 100vh; }
  .content { padding-bottom: 88px; }  /* ruimte voor de bottom-bar */
  .toast-stack { bottom: 80px; left: 16px; right: 16px; max-width: none; }

  .modal-backdrop { padding: 12px; align-items: flex-end; }
  .modal, .modal-wide { max-width: none; }
  .modal-footer { flex-direction: column-reverse; align-items: stretch; }
  .modal-footer .btn { width: 100%; }

  /* Op mobiel is een tabel met vijf kolommen onleesbaar; laat scrollen. */
  .card-body.is-flush { overflow-x: auto; }
}

/* Printen: alleen de inhoud, geen navigatie. */
@media print {
  .sidebar, .topbar, .toast-stack { display: none !important; }
  .content { padding: 0; max-width: none; }
  .card { border-color: #ccc; box-shadow: none; }
}
