:root {
    --bg-dark: #0f1117;
    --bg-card: #1a1d27;
    --bg-sidebar: #141620;
    --bg-input: #232738;
    --bg-hover: #252a3a;
    --border: #2a2f42;
    --text: #e4e6f0;
    --text-muted: #8b90a5;
    --text-heading: #ffffff;
    --blue: #3b82f6;
    --blue-hover: #2563eb;
    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, 0.12);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.12);
    --orange: #f59e0b;
    --orange-bg: rgba(245, 158, 11, 0.12);
    --purple: #8b5cf6;
    --purple-bg: rgba(139, 92, 246, 0.12);
    --cyan: #06b6d4;
    --tap-target: 48px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

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

button, input, select, textarea { font-family: inherit; font-size: 14px; }

/* Layout */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}
.sidebar-brand {
    padding: 18px;
    border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column;
    align-items: center; gap: 6px;
}
.sidebar-logo { height: 42px; }
.sidebar-brand span { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 2px; }
.sidebar-nav { flex: 1; list-style: none; padding: 12px 0; overflow-y: auto; }
.sidebar-nav li a {
    display: block;
    padding: 14px 20px;
    color: var(--text);
    border-left: 3px solid transparent;
    min-height: var(--tap-target);
    font-size: 15px;
}
.sidebar-nav li a:hover { background: var(--bg-hover); color: var(--text-heading); text-decoration: none; }
.sidebar-nav li a.active { background: var(--bg-hover); border-left-color: var(--blue); color: var(--text-heading); }

.sidebar-bottom { padding: 12px 16px; border-top: 1px solid var(--border); }
.theme-toggle { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; padding: 6px; }
.sidebar-user { margin-top: 8px; font-size: 12px; }
.user-name { font-weight: 600; color: var(--text-heading); }
.user-role { color: var(--text-muted); margin-bottom: 8px; font-size: 11px; }
.account-link, .logout-btn {
    display: inline-block; padding: 6px 10px; background: var(--bg-input);
    border-radius: 4px; font-size: 12px; margin-right: 4px; color: var(--text);
}
.logout-btn { color: var(--red); }

.main-content { flex: 1; margin-left: 240px; padding: 20px; max-width: 100vw; overflow-x: hidden; }
.menu-toggle {
    display: none;
    position: fixed; top: 12px; left: 12px; z-index: 200;
    width: var(--tap-target); height: var(--tap-target);
    background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text); font-size: 22px;
    border-radius: 8px; cursor: pointer;
}

/* Mobile-first breakpoint */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); width: 80%; max-width: 300px; }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; padding: 60px 14px 20px; }
    .menu-toggle { display: flex; align-items: center; justify-content: center; }
}

/* Login page */
.login-page { display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-container {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; padding: 30px; max-width: 420px; width: 100%;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-logo { height: 64px; margin-bottom: 8px; }
.login-brand h1 { color: var(--text-heading); font-size: 24px; }
.login-sub { color: var(--text-muted); font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login-form label { font-size: 13px; color: var(--text-muted); }
.login-form input {
    padding: 14px 12px; background: var(--bg-input);
    border: 1px solid var(--border); border-radius: 6px; color: var(--text);
    font-size: 16px; min-height: var(--tap-target);
}
.login-form input:focus { outline: none; border-color: var(--blue); }
.login-footer { text-align: center; margin-top: 20px; color: var(--text-muted); font-size: 11px; }

/* Page header */
.page-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-header h1 { color: var(--text-heading); font-size: 24px; }
.page-header .muted { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.kpi-card.kpi-orange { border-color: var(--orange); background: linear-gradient(135deg, var(--bg-card), rgba(245,158,11,0.08)); }
.kpi-card.kpi-green { border-color: var(--green); background: linear-gradient(135deg, var(--bg-card), rgba(34,197,94,0.08)); }
.kpi-card.kpi-highlight { border-color: var(--blue); background: linear-gradient(135deg, var(--bg-card), rgba(59,130,246,0.08)); }
.kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
.kpi-value { font-size: 26px; font-weight: 600; color: var(--text-heading); }
.kpi-value.small { font-size: 15px; }

/* Panels */
.panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.panel-header h2 { font-size: 17px; color: var(--text-heading); }

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
    display: inline-block; padding: 10px 16px;
    border-radius: 6px; font-size: 14px; font-weight: 500;
    cursor: pointer; text-decoration: none; border: none;
    min-height: var(--tap-target); box-sizing: border-box;
    line-height: 1.4;
}
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-hover); color: white; }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger { background: var(--red); color: white; }
.btn-large { padding: 14px 24px; font-size: 16px; }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table thead th {
    padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border);
    color: var(--text-muted); font-weight: 500;
    text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px;
}
.data-table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover td { background: var(--bg-hover); }
.data-table.compact thead th, .data-table.compact tbody td { padding: 6px 10px; }
.td-right { text-align: right; }

/* Status badges */
.status { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 500; text-transform: capitalize; }
.status-actief, .status-geschouwd, .status-admin, .status-ingediend, .status-geaccepteerd { background: var(--green-bg); color: var(--green); }
.status-te_schouwen, .status-concept, .status-monteur, .status-calculator { background: rgba(59,130,246,0.12); color: var(--blue); }
.status-in_behandeling, .status-pending { background: var(--orange-bg); color: var(--orange); }
.status-niet_toegankelijk, .status-vervallen, .status-afgekeurd { background: var(--red-bg); color: var(--red); }
.status-afgerond { background: rgba(6,182,212,0.12); color: var(--cyan); }
.status-on-hold, .status-lezen { background: rgba(139,146,168,0.12); color: var(--text-muted); }

/* Forms */
.form-grid { display: flex; flex-direction: column; gap: 14px; max-width: 720px; }
.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.form-row input, .form-row select, .form-row textarea {
    padding: 12px; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); font-size: 15px;
    min-height: var(--tap-target);
}
.form-row textarea { min-height: 80px; resize: vertical; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; border-color: var(--blue); }
.form-actions { margin-top: 8px; display: flex; gap: 8px; }

.form-grid-horiz { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.form-col { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 120px; }
.form-col-actions { flex-direction: row; align-self: flex-end; }
.inline-input { padding: 10px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; color: var(--text); }

/* Filter bar */
.filter-bar { margin-bottom: 14px; }
.filter-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter-form label { font-size: 12px; color: var(--text-muted); }

/* Monteur-dashboard: grote tap-targets voor adressen */
.adres-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.adres-card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
    padding: 14px; display: block; color: var(--text);
    min-height: 80px; transition: transform 0.1s;
}
.adres-card:hover { transform: translateY(-2px); border-color: var(--blue); text-decoration: none; color: var(--text); }
.adres-card.adres-te_schouwen { border-left: 4px solid var(--blue); }
.adres-card.adres-in_behandeling { border-left: 4px solid var(--orange); }
.adres-card.adres-geschouwd { border-left: 4px solid var(--green); opacity: 0.75; }
.adres-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 4px; }
.adres-sub { color: var(--text-muted); font-size: 13px; }

/* Progress bar */
.progress-bar { position: relative; height: 20px; background: var(--bg-input); border-radius: 10px; overflow: hidden; min-width: 100px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--blue), var(--green)); transition: width 0.4s; }
.progress-txt { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; }

/* Flash messages */
.flash-messages { position: fixed; top: 12px; right: 12px; z-index: 1000; max-width: 400px; }
.flash { padding: 12px 16px; border-radius: 6px; margin-bottom: 8px; animation: slideIn 0.3s; }
.flash-success { background: var(--green-bg); border-left: 4px solid var(--green); color: var(--green); }
.flash-error { background: var(--red-bg); border-left: 4px solid var(--red); color: var(--red); }
.flash-warning { background: var(--orange-bg); border-left: 4px solid var(--orange); color: var(--orange); }

@keyframes slideIn { from { transform: translateX(400px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.online-status { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 999; padding: 8px 16px; border-radius: 20px; font-size: 12px; display: none; }
.online-status.offline { display: block; background: var(--orange-bg); color: var(--orange); border: 1px solid var(--orange); }

/* Utils */
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.empty-state { text-align: center; padding: 32px 16px; color: var(--text-muted); }
.info-list { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; }
.info-list dt { color: var(--text-muted); }

/* Light theme — overschrijf CSS-vars zodat alles automatisch meeswitcht.
 * Twee selectors zodat het werkt met:
 *  - body.light (door JS toggle vanaf app.js)
 *  - html.theme-light (pre-render inline-script in <head>, voorkomt FOUC)
 */
body.light,
html.theme-light body {
    --bg-dark: #f0f2f5;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-input: #f5f6f8;
    --bg-hover: #e8eaef;
    --border: #d8dce6;
    --text: #1f2937;
    --text-muted: #6b7280;
    --text-heading: #111827;
    --green-bg: rgba(34, 197, 94, 0.10);
    --red-bg: rgba(239, 68, 68, 0.10);
    --orange-bg: rgba(245, 158, 11, 0.10);
    --purple-bg: rgba(139, 92, 246, 0.10);
}
body.light,
html.theme-light body { background: var(--bg-dark); color: var(--text); }
body.light .sidebar,
html.theme-light body .sidebar { box-shadow: 2px 0 8px rgba(0,0,0,0.05); }
body.light .menu-toggle,
html.theme-light body .menu-toggle { background: white; color: var(--text); }

/* ==================================================================== */
/*  M2 — Schouw form-engine styling                                      */
/* ==================================================================== */

/* Radio buttons als grote tap-targets (tablet-vriendelijk) */
.radio-group {
    display: flex; flex-wrap: wrap; gap: 8px;
    margin-top: 4px;
}
.radio-btn {
    flex: 1; min-width: 110px;
    display: flex; align-items: center; justify-content: center;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    min-height: var(--tap-target);
    font-weight: 500;
    transition: all 0.15s;
    user-select: none;
}
.radio-btn:hover { background: var(--bg-hover); border-color: var(--blue); }
.radio-btn.selected {
    background: rgba(59,130,246,0.15);
    border-color: var(--blue);
    color: var(--blue);
}
.radio-btn input[type=radio] { display: none; }

/* Checkbox/multi-checkbox als kaart */
.checkbox-large, .multi-check-group label {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 6px;
    min-height: var(--tap-target);
    font-size: 14px;
    user-select: none;
}
.multi-check-group { display: flex; flex-wrap: wrap; gap: 6px; }
.multi-check-group label { flex: 1; min-width: 160px; }
.checkbox-large input, .multi-check-group input { width: 22px; height: 22px; accent-color: var(--blue); cursor: pointer; }
.checkbox-large.selected, .multi-check-group label.selected {
    background: rgba(59,130,246,0.15); border-color: var(--blue);
}

/* Photo/signature placeholders */
.photo-placeholder {
    padding: 20px; border: 2px dashed var(--border); border-radius: 8px;
    text-align: center; color: var(--text-muted);
    background: rgba(139,146,168,0.04);
}

/* Schouw sections — zichtbaarheid via data-show-if */
.schouw-section { transition: opacity 0.2s; }

/* Sticky bottom-bar voor submit-knoppen */
.sticky-bottom {
    position: sticky; bottom: 12px;
    margin-top: 20px;
    border: 2px solid var(--blue);
    box-shadow: 0 -4px 16px rgba(0,0,0,0.3);
    z-index: 10;
}

/* Formulier-kies op start-scherm */
.formulier-kies-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.formulier-kies-card {
    display: block;
    padding: 16px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}
.formulier-kies-card input[type=radio] { display: none; }
.formulier-kies-card:hover:not(.disabled) { border-color: var(--blue); }
.formulier-kies-card input[type=radio]:checked + .kies-inhoud { color: var(--blue); }
.formulier-kies-card:has(input:checked) { border-color: var(--blue); background: rgba(59,130,246,0.1); }
.formulier-kies-card.disabled { opacity: 0.45; cursor: not-allowed; }
.kies-inhoud { display: flex; flex-direction: column; gap: 8px; }
.kies-inhoud strong { font-size: 15px; color: var(--text-heading); }

.info-box {
    padding: 12px 14px;
    background: rgba(59,130,246,0.08);
    border-left: 3px solid var(--blue);
    border-radius: 4px;
    margin: 8px 0;
    font-size: 13px;
}

.danger-zone { border-color: var(--red); }
.danger-zone h3 { color: var(--red); margin-bottom: 10px; }

/* ==================================================================== */
/*  M4 — Foto-upload + signature styling                                  */
/* ==================================================================== */

.photo-veld { margin-top: 4px; }
.photo-upload-controls { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.photo-camera-btn { position: relative; cursor: pointer; }
.photo-camera-btn input { position: absolute; top: 0; left: 0; opacity: 0; cursor: pointer; }

.photo-grid, .photo-grid-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px; margin-top: 8px;
}
.photo-item {
    position: relative; aspect-ratio: 1;
    border-radius: 8px; overflow: hidden;
    background: var(--bg-input); border: 1px solid var(--border);
}
.photo-item img {
    width: 100%; height: 100%; object-fit: cover; display: block;
}
.photo-verwijder {
    position: absolute; top: 4px; right: 4px;
    width: 28px; height: 28px;
    background: rgba(0,0,0,0.7); color: white;
    border: none; border-radius: 50%; cursor: pointer;
    font-size: 16px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
}
.photo-verwijder:hover { background: var(--red); }
.photo-uploading {
    grid-column: 1 / -1;
    padding: 20px; background: rgba(59,130,246,0.1);
    text-align: center; border-radius: 8px;
    color: var(--blue); font-size: 13px;
}
.photo-grid-view img { cursor: pointer; transition: transform 0.15s; }
.photo-grid-view img:hover { transform: scale(1.05); }

.signature-veld {
    display: flex; flex-direction: column; gap: 8px; margin-top: 4px;
}
.signature-canvas {
    width: 100%; max-width: 600px; height: 200px;
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: 8px;
    touch-action: none;
    cursor: crosshair;
}
.signature-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sig-status { font-size: 13px; }

.signature-img {
    max-width: 300px; background: #ffffff;
    border: 1px solid var(--border); border-radius: 4px;
    padding: 4px;
}

/* Tabs voor adressen-status filter */
.tab-bar {
    display: flex; gap: 4px; flex-wrap: wrap;
    margin-bottom: 14px; border-bottom: 2px solid var(--border);
}
.tab-link {
    padding: 10px 16px;
    color: var(--text-muted);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    font-size: 14px; font-weight: 500;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-flex; align-items: center; gap: 6px;
    min-height: var(--tap-target);
}
.tab-link:hover { color: var(--text); background: var(--bg-hover); text-decoration: none; }
.tab-link.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
    background: rgba(59,130,246,0.06);
}
.tab-badge {
    background: var(--bg-input);
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    min-width: 22px;
    text-align: center;
}
.tab-link.active .tab-badge { background: var(--blue); color: white; }

/* Camera-modal (live stream) */
.camera-modal {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.95);
    z-index: 10000;
    align-items: center; justify-content: center;
    padding: 16px;
}
.camera-modal.open { display: flex; }
.camera-inner {
    background: #000; border-radius: 12px;
    max-width: 900px; width: 100%;
    display: flex; flex-direction: column; gap: 12px;
    padding: 16px;
    max-height: 95vh;
}
#camera-stream {
    width: 100%; max-height: 70vh; object-fit: contain;
    background: #000; border-radius: 8px;
}
.camera-controls {
    display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
}
.camera-preview { max-height: 100px; overflow-x: auto; display: flex; gap: 6px; }
.cam-thumb {
    position: relative; width: 80px; height: 80px; flex-shrink: 0;
    border-radius: 6px; overflow: hidden;
    background: var(--bg-card);
}
.cam-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cam-thumb .upload-spinner {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.4); color: white; font-size: 20px;
}
.cam-thumb:not(.uploading) .upload-spinner { background: rgba(34,197,94,0.3); }
