/* =========================================================
   Autobeheer – mobile-first stylesheet
   Kleuren lopen via CSS-variabelen; --accent komt per gebruiker uit de database.
   ========================================================= */

:root {
    --accent: #2563eb;
    --on-accent: #fff;
    --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--surface));
    --accent-strong: color-mix(in srgb, var(--accent) 82%, #000);

    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #f6f7f9;
    --border: #e4e7ec;
    --text: #101828;
    --muted: #667085;
    --danger: #d92d20;
    --success: #079455;
    --info: #1570ef;

    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgb(16 24 40 / .04), 0 1px 3px rgb(16 24 40 / .06);
    --shadow-lg: 0 12px 32px rgb(16 24 40 / .14);
    --sidebar-w: 268px;
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light;
}

[data-theme="donker"] {
    --bg: #0b0e14;
    --surface: #131720;
    --surface-2: #1a1f2b;
    --border: #262c3a;
    --text: #eef1f6;
    --muted: #98a2b3;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-lg: 0 12px 32px rgb(0 0 0 / .5);
    --accent-soft: color-mix(in srgb, var(--accent) 22%, var(--surface));
    color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
    [data-theme="auto"] {
        --bg: #0b0e14;
        --surface: #131720;
        --surface-2: #1a1f2b;
        --border: #262c3a;
        --text: #eef1f6;
        --muted: #98a2b3;
        --shadow: 0 1px 2px rgb(0 0 0 / .4);
        --shadow-lg: 0 12px 32px rgb(0 0 0 / .5);
        --accent-soft: color-mix(in srgb, var(--accent) 22%, var(--surface));
        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 650; display: flex; align-items: center; gap: .5rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.icon { flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- App shell ---------- */

.app { min-height: 100dvh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, var(--sidebar-w));
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .25s ease;
    padding-top: env(safe-area-inset-top);
}
.drawer-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
.scrim {
    position: fixed; inset: 0;
    background: rgb(0 0 0 / .4);
    opacity: 0; pointer-events: none;
    transition: opacity .25s;
    z-index: 30;
}
.drawer-open .scrim { opacity: 1; pointer-events: auto; }

.sidebar-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 16px 12px 20px;
}
.brand {
    display: flex; align-items: center; gap: .65rem;
    color: var(--text); font-weight: 700; min-width: 0;
}
.brand:hover { text-decoration: none; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark {
    display: grid; place-items: center;
    width: 34px; height: 34px; border-radius: 10px;
    background: var(--accent); color: var(--on-accent);
    flex-shrink: 0;
}
.brand-mark.lg { width: 48px; height: 48px; border-radius: 14px; }

.nav { flex: 1; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-section {
    font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); padding: 18px 12px 6px;
}
.nav-link {
    display: flex; align-items: center; gap: .75rem;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text); font-weight: 500;
}
.nav-link .icon { color: var(--muted); }
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent-strong); }
[data-theme="donker"] .nav-link.is-active { color: var(--text); }
.nav-link.is-active .icon { color: var(--accent); }
.nav-badge {
    margin-left: auto; font-size: .68rem; font-weight: 600;
    color: var(--muted); background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 99px; padding: 1px 7px;
}

.sidebar-foot {
    display: flex; align-items: center; gap: 8px;
    padding: 12px; border-top: 1px solid var(--border);
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.user-chip {
    flex: 1; display: flex; align-items: center; gap: .65rem; min-width: 0;
    padding: 6px 8px; border-radius: var(--radius-sm); color: var(--text);
}
.user-chip:hover, .user-chip.is-active { background: var(--surface-2); text-decoration: none; }
.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-meta strong { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: var(--muted); font-size: .78rem; }

.avatar {
    display: grid; place-items: center;
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--accent-soft); color: var(--accent-strong);
    font-weight: 700; font-size: .85rem; flex-shrink: 0;
}
[data-theme="donker"] .avatar { color: var(--text); }
.avatar.lg { width: 56px; height: 56px; font-size: 1.1rem; }
a.avatar:hover { text-decoration: none; }

.icon-btn {
    display: grid; place-items: center;
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: saturate(1.6) blur(14px);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    border-bottom: 1px solid var(--border);
}

.main {
    max-width: 1080px; margin: 0 auto;
    padding: 20px 16px calc(96px + env(safe-area-inset-bottom));
    display: flex; flex-direction: column; gap: 16px;
}

.bottomnav {
    position: fixed; inset: auto 0 0 0; z-index: 20;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.6) blur(14px);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a, .bottomnav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 0 7px; font: inherit; font-size: .7rem; font-weight: 500;
    color: var(--muted); background: none; border: 0; cursor: pointer;
}
.bottomnav a:hover { text-decoration: none; }
.bottomnav .is-active { color: var(--accent); }

@media (min-width: 960px) {
    .only-mobile { display: none !important; }
    .sidebar { transform: none; width: var(--sidebar-w); }
    .scrim { display: none; }
    .main-wrap { margin-left: var(--sidebar-w); }
    .main { padding: 36px 40px 48px; gap: 20px; }
}
@media (max-width: 959px) {
    .hide-mobile { display: none !important; }
}

/* ---------- Pagina-kop ---------- */

.page-head {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
    margin-bottom: 4px;
}
.eyebrow { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.back { display: inline-block; font-size: .9rem; margin-bottom: 6px; color: var(--muted); }

/* ---------- Kaarten ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.card-head .muted { font-size: .9rem; }
@media (min-width: 640px) { .card { padding: 24px; } }

.stack { display: flex; flex-direction: column; gap: 16px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

/* ---------- Statistieken ---------- */

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat {
    display: flex; flex-direction: column; gap: 2px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px; color: var(--text);
    transition: border-color .15s, transform .15s;
}
.stat:hover { text-decoration: none; border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.stat-wide { grid-column: 1 / -1; }
.stat-icon {
    display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
    background: var(--accent-soft); color: var(--accent); margin-bottom: 10px;
}
.stat-label { font-size: .85rem; color: var(--muted); }
.stat-value { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .8rem; color: var(--muted); }
@media (min-width: 760px) {
    .stats { grid-template-columns: repeat(3, 1fr); gap: 16px; }
    .stat-wide { grid-column: auto; }
}

/* ---------- Lege staat ---------- */

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 24px 8px; color: var(--muted); }
.empty p { max-width: 46ch; }
.empty-icon { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 18px; background: var(--accent-soft); color: var(--accent); }

/* ---------- Lijsten ---------- */

.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--border); }
.list-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: var(--text); }
.list-item:hover { background: var(--surface-2); text-decoration: none; }
.list-item.is-muted { opacity: .6; }
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list-main small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
@media (min-width: 640px) { .list-item { padding: 14px 24px; } }

.badge {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 99px;
    background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
    white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }
[data-theme="donker"] .badge-accent { color: var(--text); }
.badge-muted { opacity: .8; }

/* ---------- Formulieren ---------- */

.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px 16px; }
@media (min-width: 640px) {
    .form-grid { grid-template-columns: 1fr 1fr; }
    .form-grid .full { grid-column: 1 / -1; }
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .label { font-size: .875rem; font-weight: 600; }
.req { color: var(--danger); }

input[type="text"], input[type="email"], input[type="password"], input[type="tel"],
input[type="number"], input[type="date"], input:not([type]), select, textarea {
    width: 100%;
    font: inherit; font-size: 16px; /* voorkomt inzoomen op iOS */
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 12px;
    min-height: 46px;
    transition: border-color .15s, box-shadow .15s;
    appearance: none;
}
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23667085' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
input[readonly], fieldset[disabled] input, fieldset[disabled] select { background: var(--surface-2); color: var(--muted); }
.has-error input, .has-error select { border-color: var(--danger); }
.field-error { font-size: .82rem; color: var(--danger); }
.field-hint { font-size: .82rem; color: var(--muted); }

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 46px; }
.pw-toggle {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    width: 38px; height: 38px; display: grid; place-items: center;
    background: none; border: 0; color: var(--muted); cursor: pointer; border-radius: 8px;
}
.pw-toggle:hover { color: var(--text); }

/* Schakelaar */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 46px; font-weight: 500; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
    width: 44px; height: 26px; border-radius: 99px; background: var(--border);
    position: relative; transition: background .2s; flex-shrink: 0;
}
.switch-track::after {
    content: ""; position: absolute; top: 3px; left: 3px;
    width: 20px; height: 20px; border-radius: 50%; background: #fff;
    box-shadow: 0 1px 2px rgb(0 0 0 / .25); transition: transform .2s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Segmented control */
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; gap: 2px; width: fit-content; max-width: 100%; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: 8px 14px; border-radius: 9px; font-size: .9rem; font-weight: 500; color: var(--muted); cursor: pointer; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

/* Kleurstalen */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; position: relative; width: 52px; }
.swatch input[type="radio"] { position: absolute; opacity: 0; }
.swatch span {
    width: 40px; height: 40px; border-radius: 50%; background: var(--c);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 18%, transparent); transition: transform .15s;
}
.swatch small { font-size: .7rem; color: var(--muted); }
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); transform: scale(.92); }
.swatch input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 4px; }
.swatch-company span { background: conic-gradient(from 45deg, var(--c) 0 50%, color-mix(in srgb, var(--c) 55%, #fff) 0); }
.swatch-custom input[type="color"] {
    width: 40px; height: 40px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
    background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
}
.swatch-custom input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.swatch-custom input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 50%; }
.swatch-custom input[type="color"]::-moz-color-swatch { border: 0; border-radius: 50%; }
.swatch-custom:has(input[type="radio"]:checked) input[type="color"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }

.color-row { display: flex; align-items: center; gap: 12px; }
.color-row input[type="color"] { width: 56px; height: 40px; border: 1px solid var(--border); border-radius: 10px; padding: 3px; background: var(--surface); cursor: pointer; }

/* ---------- Knoppen ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 10px 18px;
    font: inherit; font-weight: 600; font-size: .95rem;
    color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 12px;
    cursor: pointer; white-space: nowrap;
    transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-block { width: 100%; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
@media (max-width: 639px) {
    .page-head .btn span { display: none; }
    .page-head .btn { padding: 10px 12px; }
    .sticky-actions {
        position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 10;
        background: color-mix(in srgb, var(--bg) 90%, transparent);
        backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
        margin: 0 -16px; padding: 10px 16px; border-top: 1px solid var(--border);
    }
    .sticky-actions .btn { flex: 1; }
}

/* ---------- Meldingen ---------- */

.alert, .toast {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 14px; border-radius: 12px; font-size: .92rem;
    border: 1px solid transparent;
}
.alert .icon, .toast .icon { margin-top: 2px; }
.alert-error, .toast-error { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-info { background: color-mix(in srgb, var(--info) 10%, var(--surface)); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.toast-success { background: color-mix(in srgb, var(--success) 10%, var(--surface)); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.toast { animation: toast-in .3s ease; }
.toast.is-leaving { opacity: 0; transform: translateY(-6px); transition: all .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- Profiel ---------- */

.profile-card { display: flex; align-items: center; gap: 16px; }

/* ---------- Inloggen ---------- */

.auth-body {
    background:
        radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
        radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
        var(--bg);
    min-height: 100dvh;
}
.auth { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 20px; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-size: 1.25rem; font-weight: 700; }
.auth-card { width: 100%; max-width: 420px; padding: 28px 24px; display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow-lg); }
.auth-title { font-size: 1.5rem; }
.auth-foot { font-size: .8rem; color: var(--muted); }

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

/* =========================================================
   Stap 3 – Leveranciers & klanten
   ========================================================= */

[hidden] { display: none !important; }
[data-soort="bedrijf"] .only-particulier,
[data-soort="particulier"] .only-bedrijf,
[data-lev="0"] .only-lev { display: none !important; }
@media (min-width: 640px) { .form-grid .full-wrap { grid-column: 1 / -1; } }
.full-wrap { display: flex; flex-direction: column; }

input[type="search"] {
    width: 100%; font: inherit; font-size: 16px; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 11px 12px; min-height: 46px; appearance: none;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }

.toolbar { display: flex; flex-direction: column; gap: 10px; }
.toolbar .segmented { width: 100%; }
.toolbar .segmented label { flex: 1; text-align: center; }
.search { position: relative; flex: 1; display: block; }
.search .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 40px; }
@media (min-width: 760px) {
    .toolbar { flex-direction: row; align-items: center; }
    .toolbar .segmented { width: auto; }
    .toolbar .segmented label { flex: none; }
}

.avatar-square { border-radius: 10px; }
.head-meta { margin-top: 6px; }

.segmented-lg { width: 100%; }
.segmented-lg label { flex: 1; }
.segmented-lg span { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 14px; font-size: .95rem; }
@media (min-width: 640px) { .segmented-lg { width: auto; align-self: flex-start; } .segmented-lg label { flex: none; min-width: 150px; } }

.switch-row { display: flex; flex-wrap: wrap; gap: 4px 28px; }
.ophaal-fields { margin-top: 12px; }

.btn-danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.danger-zone summary { cursor: pointer; font-weight: 600; color: var(--danger); display: flex; align-items: center; gap: 8px; list-style: none; }
.danger-zone summary::-webkit-details-marker { display: none; }
.danger-zone[open] summary { margin-bottom: 12px; }
