:root {
  --bg: #F5F3F0;
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;
  --primary: #1A6B8A;
  --primary-soft: #E8F4F8;
  --primary-text: #FFFFFF;
  --accent: #D4922A;
  --accent-soft: #FDF3E4;
  --success: #2B8A5E;
  --success-soft: #E6F5EE;
  --danger: #C94040;
  --danger-soft: #FCEAEA;
  --warning: #C98A1A;
  --warning-soft: #FFF8EA;
  --text: #1E2028;
  --text-secondary: #6B6860;
  --text-tertiary: #9A958E;
  --border: #E2DFD9;
  --border-light: #EDEAE6;
  --sidebar-bg: #1E2028;
  --sidebar-text: #B8B5AE;
  --sidebar-active: #FFFFFF;
  --sidebar-hover: rgba(255,255,255,0.06);
  --sidebar-active-bg: rgba(26,107,138,0.25);
  --shadow-sm: 0 1px 2px rgba(30,32,40,0.06);
  --shadow-md: 0 4px 12px rgba(30,32,40,0.08);
  --shadow-lg: 0 8px 24px rgba(30,32,40,0.12);
  --radius: 8px;
  --radius-sm: 5px;
  --radius-lg: 12px;
  --niche-stukadoor: #7C6BB5;
  --niche-boom: #3A9B6D;
  --niche-badkamer: #2E86AB;
  --niche-uitbouw: #C97B2A;
  --niche-loodgieter: #5A7FA0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1114;
    --surface: #1A1D23;
    --surface-raised: #22262E;
    --primary: #3BA0C7;
    --primary-soft: rgba(59,160,199,0.12);
    --primary-text: #FFFFFF;
    --accent: #E8A838;
    --accent-soft: rgba(232,168,56,0.12);
    --success: #3DB87A;
    --success-soft: rgba(61,184,122,0.12);
    --danger: #E05656;
    --danger-soft: rgba(224,86,86,0.12);
    --warning: #E0A830;
    --warning-soft: rgba(224,168,48,0.12);
    --text: #E8E6E1;
    --text-secondary: #8A8780;
    --text-tertiary: #5E5B55;
    --border: #2A2D35;
    --border-light: #22252D;
    --sidebar-bg: #14161A;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #0F1114;
  --surface: #1A1D23;
  --surface-raised: #22262E;
  --primary: #3BA0C7;
  --primary-soft: rgba(59,160,199,0.12);
  --primary-text: #FFFFFF;
  --accent: #E8A838;
  --accent-soft: rgba(232,168,56,0.12);
  --success: #3DB87A;
  --success-soft: rgba(61,184,122,0.12);
  --danger: #E05656;
  --danger-soft: rgba(224,86,86,0.12);
  --warning: #E0A830;
  --warning-soft: rgba(224,168,48,0.12);
  --text: #E8E6E1;
  --text-secondary: #8A8780;
  --text-tertiary: #5E5B55;
  --border: #2A2D35;
  --border-light: #22252D;
  --sidebar-bg: #14161A;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.35);
}

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

body {
  font-family: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: 'Plus Jakarta Sans', 'Segoe UI', system-ui, sans-serif;
  font-weight: 700;
  text-wrap: balance;
}

/* ─── SIDEBAR ─── */
.sidebar { width: 260px; min-width: 260px; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; height: 100vh; position: sticky; top: 0; z-index: 100; overflow-y: auto; }
.sidebar__brand { padding: 24px 20px 20px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar__brand h1 { font-size: 17px; font-weight: 800; color: var(--sidebar-active); letter-spacing: -0.3px; }
.sidebar__brand span { display: block; font-size: 11px; color: var(--sidebar-text); margin-top: 3px; letter-spacing: 0.5px; text-transform: uppercase; font-weight: 500; }
.sidebar__nav { padding: 12px 10px; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.sidebar__nav li a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius); color: var(--sidebar-text); text-decoration: none; font-size: 13.5px; font-weight: 500; transition: background 0.15s, color 0.15s; cursor: pointer; }
.sidebar__nav li a:hover { background: var(--sidebar-hover); color: var(--sidebar-active); }
.sidebar__nav li a.active { background: var(--sidebar-active-bg); color: var(--sidebar-active); font-weight: 600; }
.sidebar__nav li a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.sidebar__nav li a.active svg { opacity: 1; }
.sidebar__nav li a .badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; min-width: 20px; text-align: center; }
.sidebar__divider { margin: 8px 16px; border: none; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar__section-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,0.3); padding: 12px 14px 6px; font-weight: 600; }
.sidebar__sites { padding: 0 10px; list-style: none; display: flex; flex-direction: column; gap: 1px; }
.sidebar__sites li a { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: var(--radius-sm); color: var(--sidebar-text); text-decoration: none; font-size: 12.5px; cursor: pointer; transition: background 0.15s, color 0.15s; }
.sidebar__sites li a:hover { background: var(--sidebar-hover); color: var(--sidebar-active); }
.sidebar__sites li a.active { color: var(--sidebar-active); }
.sidebar__sites .niche-dot, .niche-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.sidebar-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 10px; font-weight: 600; padding: 0 5px; border-radius: 8px; min-width: 16px; text-align: center; line-height: 16px; }

/* ─── MAIN ─── */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px 28px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; }
.topbar__title { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.topbar__actions { display: flex; gap: 8px; align-items: center; }
.content { padding: 24px 28px; flex: 1; }

/* ─── BUTTONS ─── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 500; font-family: inherit; cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.btn:hover { border-color: var(--text-tertiary); }
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn--primary:hover { opacity: 0.9; border-color: var(--primary); }
.btn--danger { color: var(--danger); }
.btn--danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn--sm { padding: 5px 10px; font-size: 12px; }

/* ─── KPI CARDS ─── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); }
.kpi-card__label { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; margin-bottom: 8px; }
.kpi-card__value { font-family: 'Plus Jakarta Sans', sans-serif; font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.kpi-card__sub { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }
.kpi-card--danger .kpi-card__value { color: var(--danger); }
.kpi-card--success .kpi-card__value { color: var(--success); }
.kpi-card--accent .kpi-card__value { color: var(--accent); }
.kpi-card--primary .kpi-card__value { color: var(--primary); }

/* ─── STATUS ─── */
.status { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.2px; }
.status--new { background: var(--accent-soft); color: var(--accent); }
.status--contacted { background: var(--primary-soft); color: var(--primary); }
.status--replied { background: var(--success-soft); color: var(--success); }
.status--won { background: var(--success-soft); color: var(--success); }
.status--lost { background: var(--danger-soft); color: var(--danger); }
.status--noreply { background: var(--danger-soft); color: var(--danger); }

.status-select { padding: 4px 8px; border-radius: 20px; border: 1px solid var(--border); font-size: 11.5px; font-weight: 600; font-family: inherit; cursor: pointer; background: var(--surface); color: var(--text); }
.status-select:focus { outline: none; border-color: var(--primary); }

/* ─── TABLES ─── */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.table-toolbar { padding: 14px 18px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border-light); flex-wrap: wrap; }
.table-toolbar__title { font-weight: 700; font-size: 14px; margin-right: auto; font-family: 'Plus Jakarta Sans', sans-serif; }
.filter-pills { display: flex; gap: 4px; flex-wrap: wrap; }
.filter-pill { padding: 5px 12px; border-radius: 20px; border: 1px solid var(--border); background: transparent; color: var(--text-secondary); font-size: 12px; font-weight: 500; font-family: inherit; cursor: pointer; transition: all 0.15s; }
.filter-pill:hover { border-color: var(--primary); color: var(--primary); }
.filter-pill.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
thead th { text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border-light); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border-light); font-size: 13px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--primary-soft); }
.cell-name { font-weight: 600; color: var(--text); }
.cell-sub { font-size: 11.5px; color: var(--text-tertiary); }
.cell-site { display: flex; align-items: center; gap: 6px; }
.cell-actions { display: flex; gap: 4px; }
.action-btn { width: 30px; height: 30px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.15s; font-size: 14px; }
.action-btn:hover { border-color: var(--primary); color: var(--primary); }
.action-btn--success:hover { border-color: var(--success); color: var(--success); background: var(--success-soft); }
.action-btn--danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-tertiary); }
.empty-state h3 { font-size: 15px; color: var(--text-secondary); margin-bottom: 4px; }
.empty-state p { font-size: 13px; }

/* ─── MODAL ─── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1000; display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: 520px; max-width: 92vw; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); transform: translateY(10px); transition: transform 0.2s; }
.modal-overlay.open .modal { transform: translateY(0); }
.modal__header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border-light); display: flex; align-items: center; justify-content: space-between; }
.modal__header h2 { font-size: 16px; font-weight: 700; }
.modal__close { background: none; border: none; color: var(--text-tertiary); cursor: pointer; font-size: 20px; padding: 4px; line-height: 1; }
.modal__body { padding: 20px 24px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.3px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 13.5px; font-family: inherit; transition: border-color 0.15s; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-group textarea { resize: vertical; min-height: 70px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal__footer { padding: 16px 24px 20px; display: flex; justify-content: flex-end; gap: 8px; }

/* ─── SITE CARDS ─── */
.site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.site-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); transition: box-shadow 0.15s; }
.site-card:hover { box-shadow: var(--shadow-md); }
.site-card__header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; }
.site-card__niche { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; padding: 3px 8px; border-radius: 4px; }
.site-card__name { font-size: 15px; font-weight: 700; margin-bottom: 2px; font-family: 'Plus Jakarta Sans', sans-serif; }
.site-card__city { font-size: 12.5px; color: var(--text-secondary); }
.site-card__webhook { margin-top: 8px; }
.site-card__stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border-light); }
.site-card__stat-value { font-family: 'Plus Jakarta Sans', sans-serif; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.site-card__stat-label { font-size: 10.5px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.3px; }
.site-card__actions { display: flex; gap: 4px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-light); }
.site-card__actions .btn { flex: 1; justify-content: center; font-size: 12px; padding: 6px 8px; }

/* ─── WEBHOOK DISPLAY ─── */
.webhook-display { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.webhook-display code { font-size: 12px; color: var(--primary); word-break: break-all; }

/* ─── SEARCH ─── */
.search-input { padding: 7px 12px 7px 32px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 13px; font-family: inherit; width: 200px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%239A958E' viewBox='0 0 24 24'%3E%3Cpath d='M21 21l-4.35-4.35M11 19a8 8 0 100-16 8 8 0 000 16z' stroke='%239A958E' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: 10px center; }
.search-input:focus { outline: none; border-color: var(--primary); }

/* ─── TOAST ─── */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 18px; border-radius: var(--radius); font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); animation: slideIn 0.25s ease; transition: opacity 0.3s; }
.toast--info { background: var(--sidebar-bg); color: var(--sidebar-active); }
.toast--success { background: var(--success); color: #fff; }
.toast--error { background: var(--danger); color: #fff; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── VIEW ─── */
.view { display: none; }
.view.active { display: block; }

/* ─── NICHE COLORS ─── */
.niche-stukadoor { background: rgba(124,107,181,0.12); color: var(--niche-stukadoor); }
.niche-boom { background: rgba(58,155,109,0.12); color: var(--niche-boom); }
.niche-badkamer { background: rgba(46,134,171,0.12); color: var(--niche-badkamer); }
.niche-uitbouw { background: rgba(201,123,42,0.12); color: var(--niche-uitbouw); }
.niche-loodgieter { background: rgba(90,127,160,0.12); color: var(--niche-loodgieter); }
.niche-schilder, .niche-dakdekker, .niche-elektricien, .niche-timmerman, .niche-glazenwasser, .niche-schoonmaak, .niche-verhuizer, .niche-tuinman, .niche-other { background: rgba(120,120,140,0.12); color: #7878A0; }
.dot-stukadoor { background: var(--niche-stukadoor); }
.dot-boom { background: var(--niche-boom); }
.dot-badkamer { background: var(--niche-badkamer); }
.dot-uitbouw { background: var(--niche-uitbouw); }
.dot-loodgieter { background: var(--niche-loodgieter); }
.dot-schilder, .dot-dakdekker, .dot-elektricien, .dot-timmerman, .dot-glazenwasser, .dot-schoonmaak, .dot-verhuizer, .dot-tuinman, .dot-other { background: #7878A0; }

/* ─── FOCUS ─── */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .site-grid { grid-template-columns: 1fr; }
}

/* Settings */
.settings-section { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; margin-bottom: 20px; }
.settings-section__title { display: flex; align-items: center; gap: 8px; font-size: 1.1rem; font-weight: 700; margin: 0 0 4px; color: var(--text); }
.settings-section__title svg { color: var(--primary); flex-shrink: 0; }
.settings-section__desc { color: var(--text-secondary); font-size: 0.9rem; margin: 0 0 20px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; color: var(--text); }
.form-input { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem; background: var(--bg); color: var(--text); box-sizing: border-box; }
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.webhook-urls { display: flex; flex-direction: column; gap: 8px; }
.webhook-url-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg); border-radius: 8px; border: 1px solid var(--border-light); }
.webhook-url-row__site { font-weight: 600; font-size: 0.85rem; min-width: 180px; color: var(--text); }
.webhook-url-row__url { flex: 1; font-size: 0.78rem; color: var(--text-secondary); word-break: break-all; }
.webhook-url-row .btn--sm { padding: 4px 12px; font-size: 0.75rem; white-space: nowrap; }
.toggle-label { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.toggle-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }
.settings-actions { text-align: right; margin-top: 8px; }
.btn--lg { padding: 12px 32px; font-size: 1rem; }
.badge--green { background: var(--success-soft); color: var(--success); }
.badge--blue { background: var(--primary-soft); color: var(--primary); }
.badge--grey { background: var(--bg); color: var(--text-secondary); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
