/* SourceLink: rustige werkomgeving, met één herkenbaar element: de gele markeringsstreep onder de kop. */
:root {
    --bg: #ECEFF1;
    --surface: #FFFFFF;
    --ink: #17212B;
    --muted: #5A6772;
    --line: #D2D8DD;
    --field: #F7F9FA;
    --tape: #F2B705;
    --ok: #23704A;
    --warn: #8F5600;
    --bad: #B42318;
    --focus: #1D5FD1;
    --radius: 6px;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12181E;
        --surface: #1B232B;
        --ink: #E6EBEE;
        --muted: #9BA8B3;
        --line: #2E3A45;
        --field: #151C22;
        --ok: #5CC08A;
        --warn: #E3A23B;
        --bad: #F07067;
        --focus: #7AA7FF;
        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(--ink);
    font: 400 15px/1.55 "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; text-underline-offset: 2px; }
code, pre { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 0.85em; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; font-weight: 700; }
p { margin: 0 0 0.75rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Kop met markeringsstreep */
.top { background: var(--ink); color: #fff; position: relative; }
.top::after {
    content: "";
    position: absolute; left: 0; right: 0; bottom: -6px; height: 6px;
    background: repeating-linear-gradient(-45deg, var(--tape) 0 14px, var(--ink) 14px 28px);
}
@media (prefers-color-scheme: dark) { .top { background: #0B1015; } .top::after { background: repeating-linear-gradient(-45deg, var(--tape) 0 14px, #0B1015 14px 28px); } }
.top-inner { max-width: 1180px; margin: 0 auto; padding: 0.9rem 1.25rem; display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.brand { font-weight: 700; text-decoration: none; font-size: 1.05rem; }
.top nav { display: flex; gap: 1.25rem; align-items: center; margin-left: auto; flex-wrap: wrap; }
.top nav a { text-decoration: none; opacity: 0.8; }
.top nav a:hover, .top nav a[aria-current] { opacity: 1; text-decoration: underline; text-decoration-color: var(--tape); text-decoration-thickness: 2px; }
.top nav form { margin: 0; }
/* Tandwiel-menu voor Logic4, gebruikers, systeem en logboek (open/dicht via <details>, zie ui.js voor sluiten bij klik ernaast). */
/* Vaste afmeting: het open menu hangt er los onder en mag de kopbalk nooit groter maken of het tandwiel verschuiven. */
/* Bewust display:block: een flex-<details> krijgt in Chrome als het opengaat een extra vak (::details-content) en schuift dan omhoog. */
.gear { position: relative; display: block; width: 20px; height: 20px; flex: none; overflow: visible; }
.gear summary { list-style: none; cursor: pointer; opacity: 0.8; display: block; width: 20px; height: 20px; line-height: 0; }
.gear summary svg { display: block; }
.gear summary::-webkit-details-marker { display: none; }
.gear summary:hover, .gear[open] summary, .gear summary[aria-current] { opacity: 1; }
.gear summary:focus-visible { outline: 2px solid var(--tape); outline-offset: 3px; border-radius: 4px; }
.gear-menu {
    position: absolute; right: 0; top: calc(100% + 0.6rem); z-index: 50; min-width: 12rem;
    background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); padding: 0.35rem; display: flex; flex-direction: column;
}
.top nav .gear-menu a { opacity: 1; text-decoration: none; padding: 0.5rem 0.75rem; border-radius: 6px; color: var(--ink); }
.top nav .gear-menu a:hover { background: var(--bg); text-decoration: none; }
.top nav .gear-menu a[aria-current] { font-weight: 600; text-decoration: none; }
/* "by Quality Works" achter de naam: klein en gedempt. */
.brand-by { font-weight: 400; font-size: 0.55em; opacity: 0.6; margin-left: 0.25em; }
/* Help / kennisbank */
.help-group { margin-top: 1.75rem; }
.help-group h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }
.help-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 0.9rem; }
.help-card { display: flex; flex-direction: column; gap: 0.35rem; text-decoration: none; color: var(--ink); padding: 1rem 1.1rem; }
.help-card:hover { border-color: var(--focus); }
.help-card[hidden], .help-group[hidden] { display: none; }
.help-layout { display: grid; grid-template-columns: 15rem minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.help-nav { display: flex; flex-direction: column; padding: 0.75rem; position: sticky; top: 1rem; }
.help-nav-group { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0.75rem 0.5rem 0.25rem; }
.help-nav-group:first-child { margin-top: 0.25rem; }
.help-nav a { padding: 0.4rem 0.5rem; border-radius: 6px; text-decoration: none; color: var(--ink); font-size: 0.92rem; }
.help-nav a:hover { background: var(--bg); }
.help-nav a[aria-current] { font-weight: 600; background: var(--bg); }
.help-article { max-width: 46rem; }
.help-article h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }
.help-article h2:first-child { margin-top: 0; }
.help-article ul, .help-article ol { padding-left: 1.4rem; }
.help-article li { margin: 0.35rem 0; }
.help-steps > li { margin: 0.9rem 0; }
.help-tip { background: var(--bg); border-left: 3px solid var(--tape); padding: 0.6rem 0.9rem; border-radius: 0 var(--radius) var(--radius) 0; }
.help-foot { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.help-terms dt { font-weight: 600; margin-top: 1rem; }
.help-terms dd { margin: 0.15rem 0 0; }
@media (max-width: 760px) { .help-layout { grid-template-columns: 1fr; } .help-nav { position: static; } }
.linklike { background: none; border: 0; color: inherit; font: inherit; opacity: 0.8; cursor: pointer; padding: 0; }
.linklike:hover { opacity: 1; text-decoration: underline; }

main { max-width: 1180px; margin: 0 auto; padding: 2.25rem 1.25rem 4rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.panel.flush { padding: 0; }
.empty { text-align: left; padding: 2rem 1.5rem; }
.empty p { max-width: 60ch; color: var(--muted); }
.muted { color: var(--muted); }
.measure { max-width: 72ch; }
.small { font-size: 0.85rem; }
.strong { font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Knoppen */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 2.4rem; padding: 0 1rem;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--surface); color: var(--ink);
    font: 600 0.9rem/1 inherit; font-family: inherit; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--tape); border-color: var(--tape); color: #17212B; }
.btn.primary:hover { filter: brightness(0.95); }
.btn.small { min-height: 2rem; padding: 0 0.75rem; font-size: 0.85rem; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Meldingen */
.flash { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border-left: 4px solid var(--ok); background: var(--surface); }
.flash-error { border-left-color: var(--bad); }
.flash-warning { border-left-color: var(--tape); }
.callout { border-left: 4px solid var(--bad); }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
th.num, td.num { text-align: right; }
td:first-child.num, th:first-child.num { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
/* De cel blijft een gewone tabelcel (met flex liepen de lijnen tussen de rijen niet door); de knoppen staan naast elkaar. */
td.actions { text-align: right; white-space: nowrap; }
td.actions form { display: inline-block; margin: 0 0 0 0.5rem; }
td.wrap { word-break: break-word; }
.log .lvl-error td:first-child { color: var(--bad); font-weight: 600; }
.log .lvl-warning td:first-child { color: var(--warn); font-weight: 600; }

/* Status */
.status { display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 600; text-decoration: none; }
.status::before { content: ""; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--muted); }
.s-ok::before { background: var(--ok); }
.s-errors::before { background: var(--warn); }
.s-failed::before { background: var(--bad); }
.s-running::before { background: var(--tape); }

/* Formulieren */
.form .panel { padding-bottom: 1.4rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem 1.25rem; align-items: start; }
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.25rem; }
.field > span { font-weight: 600; font-size: 0.9rem; }
.field small { color: var(--muted); font-size: 0.82rem; }
input, select {
    font: inherit; color: var(--ink); background: var(--field);
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: 0.5rem 0.65rem; min-height: 2.4rem; width: 100%;
}
input:focus, select:focus { border-color: var(--focus); }
.check { display: flex; gap: 0.55rem; align-items: center; padding-top: 1.9rem; }
.checks .check { padding-top: 0.4rem; }
.checks { padding-top: 1.5rem; }
.check input { width: 1.1rem; height: 1.1rem; min-height: 0; accent-color: var(--ink); }
.mapping td { padding: 0.4rem; }
.mapping td.narrow { width: 1%; }
.mapping td.narrow input { width: 8rem; }
.mapping select { min-width: 15rem; }
#add-row { margin-top: 0.75rem; }
.form-actions, .row-actions { display: flex; gap: 0.6rem; margin: 1.25rem 0; }
.row-actions form { margin: 0; }
.danger-zone { margin-top: 2rem; }

/* Bron bekijken */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; align-items: start; }
.cols .panel { margin-bottom: 0; }
pre { background: var(--field); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem; overflow: auto; max-height: 32rem; margin: 0; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 0.75rem; }
.cols + details { margin-top: 1rem; }

/* Aantallen bij een run */
.counts { display: flex; flex-wrap: wrap; gap: 0.5rem 2.5rem; margin: 1rem 0 0.5rem; }
.counts dt { font-size: 0.85rem; color: var(--muted); }
.counts dd { margin: 0; font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.counts .bad dd { color: var(--bad); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 1.5rem; margin: 0 0 1rem; }
.kv div { display: contents; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* Inloggen */
.login { max-width: 380px; margin: 12vh auto 0; border-top: 6px solid var(--tape); }
.login h1 { font-size: 1.4rem; margin-bottom: 0.25rem; }
.login .btn { width: 100%; margin-top: 1rem; }

@media (max-width: 640px) {
    main { padding-top: 1.5rem; }
    td.actions form { display: block; margin: 0 0 0.5rem; }
    .check { padding-top: 0; }
    .checks { padding-top: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Categorieën */
.head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.head-actions form { margin: 0; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.filters { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; margin: 0.5rem 0 0.75rem; }
.filters .field { margin: 0; min-width: 16rem; }
.filters .check { padding-top: 0; }
.catmap td { vertical-align: middle; }
.warn { color: var(--warn); font-weight: 600; }

/* Doorzoekbare keuzelijst voor productgroepen */
.picker { position: relative; min-width: 18rem; }
.picker-btn {
    font: inherit; color: var(--ink); background: var(--field); text-align: left; cursor: pointer;
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: 0.5rem 2rem 0.5rem 0.65rem; min-height: 2.4rem; width: 100%;
    position: relative; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.picker-btn::after { content: ""; position: absolute; right: 0.75rem; top: 50%; width: 0.45rem; height: 0.45rem; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-70%) rotate(45deg); }
.picker-btn:hover { border-color: var(--muted); }
.picker-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.picker-btn.empty { color: var(--muted); }
.picker-btn.skipped { color: var(--warn); font-weight: 600; }
.picker-pop {
    position: fixed; z-index: 50; display: flex; flex-direction: column; gap: 0.4rem; padding: 0.5rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.picker-pop[hidden] { display: none; }
.picker-pop ul { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.picker-pop li { padding: 0.45rem 0.6rem; border-radius: 4px; cursor: pointer; }
.picker-pop li.active, .picker-pop li:hover { background: var(--field); outline: 1px solid var(--line); }
.picker-pop li[aria-selected="true"] { font-weight: 600; }
.picker-note { margin: 0; padding: 0 0.25rem; }
.suggest { margin-top: 0.4rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; color: var(--muted); }
.suggest strong { color: var(--ink); }
.lvl { padding-left: calc(var(--lvl, 0) * 1.25rem); }

/* Gebruikers */
.narrow-form { max-width: 28rem; }
.narrow-form .check { padding-top: 0.5rem; }
.login .field { margin-top: 0.75rem; }
.login-help { margin-top: 1rem; margin-bottom: 0; }
.login p code { font-size: 0.9em; }

/* Inlogcode */
.code-input { font-size: 1.5rem; letter-spacing: 0.3em; text-align: center; font-variant-numeric: tabular-nums; }
.login .check { padding-top: 0.75rem; }
.resend { margin-top: 1rem; }
.resend p { margin: 0; }
.linklike.inline { color: inherit; opacity: 1; text-decoration: underline; font-size: inherit; }

/* Runlijst en logboek */
.filter-bar { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 0.75rem; }
.filter-bar .field { margin: 0; min-width: 10rem; }
.pager { display: flex; gap: 0.75rem; align-items: center; justify-content: flex-end; margin-top: 0.75rem; }
.nowrap { white-space: nowrap; }

/* Uitleg bij een veld: een (i)-knop naast de titel, de tekst staat in een tooltip (zie ui.js). */
.field { position: relative; }
.tip { display: inline-block; margin-left: 0.4rem; }
.tip:not(:has(.tip-pop small:not([hidden]))) { display: none; }
.tip-btn {
    width: 1.2rem; height: 1.2rem; min-height: 0; padding: 0; border-radius: 50%; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--muted); background: transparent; color: var(--muted);
    font: italic 700 0.75rem/1 Georgia, 'Times New Roman', serif;
}
.tip-btn:hover, .tip.open .tip-btn, .field > span:hover .tip-btn { background: var(--focus); border-color: var(--focus); color: #fff; }
.tip-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.tip-pop {
    display: none; position: absolute; z-index: 40; left: 0; top: 1.7rem;
    width: max-content; max-width: min(26rem, 88vw); padding: 0.6rem 0.8rem;
    background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    font-size: 0.85rem; font-weight: 400; line-height: 1.45; text-align: left;
}
.tip.right .tip-pop { left: auto; right: 0; }
/* De uitleg opent bij hoveren op de i of op de titel, bij focus met het toetsenbord en bij aantikken. */
.tip:hover .tip-pop, .tip.open .tip-pop, .tip:focus-within .tip-pop, .field > span:hover .tip-pop { display: block; }
/* Onzichtbare brug tussen titel en tooltip, zodat de tooltip niet dichtgaat als je naar hem toe beweegt. */
.tip-pop::before { content: ''; position: absolute; left: 0; right: 0; top: -0.7rem; height: 0.7rem; }
.tip-pop small { display: block; color: var(--ink); font-size: inherit; }
.tip-pop small + small { margin-top: 0.4rem; }
.ok-note { color: var(--ok) !important; font-weight: 600; }
.results { min-width: 13rem; }
.details { min-width: 16rem; }

/* Keuze tussen soorten synchronisatie */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.choice { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.85rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--field); cursor: pointer; }
.choice:has(input:checked) { border-color: var(--focus); outline: 1px solid var(--focus); }
.choice input { width: auto; min-height: 0; margin-top: 0.3rem; }
.choice small { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; }

/* Kopjes boven velden in een rij: een titel van twee regels duwt zijn veld niet lager dan de rest. */
.grid.aligned > .field > span:first-child { line-height: 1.35; min-height: 2.7em; display: flex; align-items: flex-end; } /* altijd ruimte voor precies twee regels */
h3.sub { font-size: 1rem; margin: 1.5rem 0 0.5rem; }
h3.sub:first-of-type { margin-top: 1rem; }

/* Voettekst met het Quality Works-logo (inline svg, kleurt mee met het thema). */
.site-footer { max-width: 1180px; margin: 2.5rem auto 0; padding: 1.25rem 1.25rem 2rem; text-align: center; }
/* Het logo heeft de tekstkleur (zwart; in dark mode wit, anders zou het verdwijnen) en is nooit gedempt. */
.site-footer a { position: relative; display: inline-block; color: var(--ink); text-decoration: none; }
/* De tekst is een tooltip boven het logo: zichtbaar bij hover of toetsenbordfocus. */
.site-footer a span {
    position: absolute; bottom: calc(100% + 0.5rem); left: 50%; transform: translateX(-50%); white-space: nowrap;
    background: var(--ink); color: #fff; font-size: 0.8rem; padding: 0.3rem 0.6rem; border-radius: var(--radius);
    opacity: 0; pointer-events: none; transition: opacity 0.15s;
}
.site-footer a:hover span, .site-footer a:focus-visible span { opacity: 1; }
.site-footer svg { display: block; }
/* Lijn van 1 pixel boven de voettekst, even breed als de inhoud. */
.site-footer { position: relative; }
.site-footer::before { content: ''; position: absolute; top: 0; left: 1.25rem; right: 1.25rem; border-top: 1px solid var(--line); }

/* Startpagina: bij een connector met producten en voorraad staan beide runs onder elkaar. */
.run-block + .run-block { margin-top: 0.6rem; }

/* Uitleg-paneel naast het connectorformulier. Standaard dicht; open = twee kolommen met het paneel meescrollend. */
.with-help.open { display: grid; grid-template-columns: minmax(0, 1fr) 23rem; gap: 1.25rem; align-items: start; }
.with-help-main { min-width: 0; }
.help-panel { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08); }
.help-panel[hidden] { display: none; }
.help-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.7rem 1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.help-panel-actions { display: flex; align-items: center; gap: 0.4rem; }
.help-pin { font: inherit; font-size: 0.8rem; background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 0.15rem 0.7rem; cursor: pointer; }
.help-pin:hover { border-color: var(--focus); color: var(--ink); }
.help-pin[aria-pressed="true"] { background: var(--focus); border-color: var(--focus); color: #fff; }
.help-close { font: inherit; font-size: 1.4rem; line-height: 1; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 0.3rem; }
.help-close:hover { color: var(--ink); }
.help-panel-body { padding: 0.25rem 1rem 0.5rem; font-size: 0.92rem; }
.help-panel-body h3 { font-size: 1rem; margin: 0.9rem 0 0.4rem; }
.help-panel-body p { margin: 0.5rem 0; }
.help-panel-body ul { padding-left: 1.2rem; margin: 0.4rem 0; }
.help-pane[hidden] { display: none; }
.help-panel-foot { padding: 0.6rem 1rem 1rem; margin: 0; border-top: 1px solid var(--line); }
@media (min-width: 1600px) { body.help-open main { max-width: 1560px; } }
@media (max-width: 900px) {
    .with-help.open { display: block; }
    .help-panel { position: static; max-height: none; margin-bottom: 1rem; }
}
