:root {
    --bg: #f5f6fa;
    --kaart: #ffffff;
    --tekst: #111827;
    --zacht: #6b7280;
    --rand: #e5e7eb;
    --vlak: #f3f4f6;
    --primair: #2563eb;
    --primair-tekst: #ffffff;
    --gevaar: #dc2626;
    --waarschuwing: #b45309;
    --waarschuwing-bg: #fef3c7;
    --tijdelijk: #7c3aed;
    --tijdelijk-bg: #ede9fe;
    --schaduw: 0 1px 2px rgb(0 0 0 / .05), 0 4px 12px rgb(0 0 0 / .05);
    --radius: 16px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1115;
        --kaart: #1a1d24;
        --tekst: #f3f4f6;
        --zacht: #9ca3af;
        --rand: #2d313a;
        --vlak: #242833;
        --primair: #3b82f6;
        --gevaar: #f87171;
        --waarschuwing: #fbbf24;
        --waarschuwing-bg: #3a2e12;
        --tijdelijk: #c4b5fd;
        --tijdelijk-bg: #2e2645;
        --schaduw: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--tekst);
    font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; word-break: break-all; }

.zacht { color: var(--zacht); }
.hint { color: var(--zacht); font-size: .9rem; }
.laden, .leeg { text-align: center; color: var(--zacht); padding: 48px 16px; }

/* ---------- Layout ---------- */

.topbalk {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
    max-width: 600px;
    margin: 0 auto;
}
.topbalk h1 { font-size: 1.25rem; display: flex; align-items: center; gap: 8px; flex: 1; }
.topbalk h1 img { border-radius: 7px; }

main {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#tabs {
    position: fixed;
    inset: auto 0 0 0;
    display: flex;
    justify-content: center;
    background: var(--kaart);
    border-top: 1px solid var(--rand);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 10;
}
#tabs button {
    flex: 1;
    max-width: 150px;
    border: 0;
    background: none;
    padding: 18px 4px;
    color: var(--zacht);
    font-weight: 600;
    font-size: .95rem;
    cursor: pointer;
    border-top: 3px solid transparent;
}
#tabs button.actief { color: var(--primair); border-top-color: var(--primair); }

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

.knop {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 8px 16px;
    border-radius: 12px;
    border: 1px solid var(--rand);
    background: var(--kaart);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.knop.primair { background: var(--primair); border-color: var(--primair); color: var(--primair-tekst); }
.knop.gevaar { color: var(--gevaar); }
.knop.klein { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.knop:disabled { opacity: .5; cursor: default; }

.link {
    border: 0;
    background: none;
    padding: 8px 0;
    color: var(--primair);
    font-weight: 600;
    cursor: pointer;
}
.link.gevaar { color: var(--gevaar); }

.pil {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
    background: var(--vlak);
    color: var(--zacht);
    white-space: nowrap;
}
.pil.waarschuwing { background: var(--waarschuwing-bg); color: var(--waarschuwing); }
.pil.tijdelijk { background: var(--tijdelijk-bg); color: var(--tijdelijk); }

/* ---------- Medicijnkaart ---------- */

.kaart {
    background: var(--kaart);
    border-radius: var(--radius);
    box-shadow: var(--schaduw);
    border: 1px solid var(--rand);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.kaart.medicijn { border-top: 6px solid var(--kleur); }

.kaart-kop { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kaart-kop h2 { flex: 1; min-width: 0; }

.instructie {
    background: var(--vlak);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: .95rem;
    white-space: pre-line;
}
.instructie.tijdelijk { background: var(--tijdelijk-bg); }

.geef-rij { display: flex; gap: 10px; align-items: stretch; }

.stepper {
    display: flex;
    align-items: center;
    border: 1px solid var(--rand);
    border-radius: 14px;
    overflow: hidden;
}
.stepper button {
    width: 44px;
    height: 100%;
    min-height: 64px;
    border: 0;
    background: var(--vlak);
    font-size: 1.4rem;
    cursor: pointer;
}
.stepper output { min-width: 64px; text-align: center; line-height: 1.1; }
.stepper output b { display: block; font-size: 1.5rem; }
.stepper output small { color: var(--zacht); font-size: .75rem; }
.stepper.aangepast output b { color: var(--waarschuwing); }

.geef {
    flex: 1;
    min-height: 64px;
    border: 0;
    border-radius: 14px;
    background: var(--kleur);
    color: #fff;
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform .08s;
}
.geef:active { transform: scale(.98); }
.geef:disabled { opacity: .6; }
.geef small { display: block; font-size: .8rem; font-weight: 500; opacity: .85; }
.geef.bezig { box-shadow: 0 0 0 3px var(--kaart), 0 0 0 5px var(--kleur); }

.voortgang { display: flex; gap: 6px; }
.voortgang span { flex: 1; height: 10px; border-radius: 99px; background: var(--vlak); }
.voortgang span.vol { background: var(--kleur); }

.telling-acties { display: flex; justify-content: space-between; margin-top: -8px; }

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 0;
}
.stats div { background: var(--vlak); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.stats dt { font-size: .75rem; color: var(--zacht); text-transform: uppercase; letter-spacing: .03em; }
.stats dd { margin: 0; font-weight: 700; }
.stats dd small { display: block; font-weight: 400; color: var(--zacht); font-size: .8rem; }

.puffer { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; }
.puffer-kop { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.puffer-kop b { font-size: 1.3rem; }
.puffer-kop .link { padding: 0; }
.balk { height: 8px; background: var(--vlak); border-radius: 99px; overflow: hidden; }
.balk span { display: block; height: 100%; background: var(--kleur); border-radius: 99px; }
.puffer.laag { color: var(--waarschuwing); font-weight: 600; }
.puffer.laag .balk span { background: var(--waarschuwing); }

.kaart-voet { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }

/* ---------- Geschiedenis ---------- */

.filters { display: flex; gap: 8px; align-items: center; }
.filters select { flex: 1; }

.dag h3 { font-size: 1rem; }
.dag h3::first-letter { text-transform: uppercase; }
.dag-kop { display: flex; flex-direction: column; gap: 4px; padding: 0 4px 8px; }
.dag-totalen { display: flex; gap: 6px; flex-wrap: wrap; }
.dag-totalen .pil { background: color-mix(in srgb, var(--kleur) 15%, transparent); color: var(--tekst); }

.lijst {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--kaart);
    border: 1px solid var(--rand);
    border-radius: var(--radius);
    overflow: hidden;
}
.lijst li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.lijst li + li { border-top: 1px solid var(--rand); }
.lijst .leeg-dag { color: var(--zacht); font-size: .9rem; }
.stip { width: 10px; height: 10px; border-radius: 50%; background: var(--kleur); flex: none; }
.lijst .tijd { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.2em; }
.lijst .info { flex: 1; min-width: 0; }
.lijst .info small { display: block; color: var(--zacht); }
.lijst .notitie { font-style: italic; }

/* ---------- Beheer ---------- */

.blok { display: flex; flex-direction: column; gap: 10px; }
.blok > h2 { padding: 0 4px; }
.beheer-item { flex-wrap: wrap; }
.beheer-item .knoppen { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; padding-left: 22px; }

/* ---------- Formulieren & dialoog ---------- */

input, select, textarea {
    width: 100%;
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--rand);
    border-radius: 10px;
    background: var(--kaart);
}
input[type="color"] { padding: 4px; height: 44px; }
input[type="checkbox"] { width: 20px; min-height: 20px; height: 20px; }
textarea { resize: vertical; }

.veld { display: flex; flex-direction: column; gap: 4px; }
.veld > span { font-weight: 600; font-size: .9rem; }
.veld small { color: var(--zacht); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; }

dialog {
    width: min(520px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    border: 0;
    border-radius: var(--radius);
    padding: 0;
    background: var(--kaart);
    color: var(--tekst);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
dialog .knoppen { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
dialog .flex { flex: 1; }

.kopieer-rij { display: flex; gap: 8px; }
.kopieer-rij input { flex: 1; font-size: .85rem; }

/* ---------- Toast ---------- */

#toast {
    position: fixed;
    left: 50%;
    bottom: calc(84px + env(safe-area-inset-bottom));
    transform: translate(-50%, 20px);
    width: max-content;
    max-width: calc(100vw - 32px);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: #111827;
    color: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgb(0 0 0 / .25);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 20;
}
#toast.zichtbaar { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { border: 0; background: none; color: #93c5fd; font-weight: 700; cursor: pointer; padding: 4px; white-space: nowrap; }

@media (prefers-color-scheme: dark) {
    #toast { background: #f3f4f6; color: #111827; }
    #toast button { color: #1d4ed8; }
}
