:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1c2533;
  --muted: #6b7688;
  --line: #e4e8ef;
  --primary: #2f6fed;
  --primary-d: #2257c8;
  --ok: #1f9d57;
  --ok-bg: #e6f6ec;
  --warn: #b9770a;
  --warn-bg: #fdf3e2;
  --err: #c33;
  --err-bg: #fdeaea;
  --info-bg: #eaf1fe;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20,30,50,.08), 0 1px 2px rgba(20,30,50,.04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overflow-x: hidden; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  overflow-x: hidden;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #eef1f6; padding: .1em .35em; border-radius: 4px; font-size: .9em; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: .7rem 1.25rem; box-shadow: var(--shadow); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--ink); }
.topnav { display: flex; align-items: center; gap: 1rem; }
.container { max-width: 1180px; margin: 1.5rem auto; padding: 0 1.25rem; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1.4rem; margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 1rem; font-size: 1.15rem; }
.card h3 { margin: 0 0 .75rem; font-size: 1.02rem; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.25rem; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.warn { color: var(--warn); }
.pending { color: var(--warn); }

/* buttons */
.btn {
  display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: .5rem .9rem; border-radius: 8px; font-size: .9rem; cursor: pointer; line-height: 1.2;
}
.btn:hover { background: #f7f9fc; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-primary:disabled { background: #b9c6e0; border-color: #b9c6e0; cursor: not-allowed; }
.btn-small { padding: .35rem .65rem; font-size: .82rem; }
.btn-tiny { padding: .25rem .55rem; font-size: .78rem; }
.btn-lg { padding: .7rem 1.3rem; font-size: 1rem; }
.btn-block { width: 100%; }

/* flashes */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; }
.flash-info { background: var(--info-bg); border-color: #cfe0fc; }
.flash-success { background: var(--ok-bg); border-color: #c4ead2; color: #14663a; }
.flash-error { background: var(--err-bg); border-color: #f3c7c7; color: #962020; }

/* login */
.login-card {
  max-width: 360px; margin: 8vh auto; background: var(--card); padding: 2rem;
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 .2rem; font-size: 1.4rem; }
.login-card form { margin-top: 1.25rem; display: flex; flex-direction: column; gap: .9rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
input[type=text], input[type=password], input[type=date], input[type=number], select {
  padding: .5rem .6rem; border: 1px solid #cdd5e2; border-radius: 7px; font-size: .92rem; color: var(--ink); background: #fff;
}
input:focus, select:focus { outline: 2px solid #bcd0fb; border-color: var(--primary); }

/* tables */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; color: var(--muted); font-weight: 600; padding: .5rem .6rem; border-bottom: 2px solid var(--line); }
.table td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:hover { background: #fafbfd; }

.upload-form { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }

/* badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-new, .badge-extracting { background: #eef1f6; color: #5a6678; }
.badge-review { background: var(--warn-bg); color: var(--warn); }
.badge-ready { background: #e7f0ff; color: var(--primary-d); }
.badge-po_created { background: var(--ok-bg); color: #14663a; }
.badge-ignored { background: #eef1f6; color: #8b94a3; }
.badge-error { background: var(--err-bg); color: #962020; }

/* match type tags */
.mtag { display: inline-block; padding: .12rem .5rem; border-radius: 6px; font-size: .75rem; font-weight: 600; }
.mtag-ok { background: var(--ok-bg); color: #14663a; }
.mtag-info { background: var(--info-bg); color: var(--primary-d); }
.mtag-warn { background: var(--warn-bg); color: var(--warn); }
.mtag-err { background: var(--err-bg); color: #962020; }
.mtag-muted { background: #eef1f6; color: #8b94a3; }

/* detail */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.detail-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.meta-form { display: flex; gap: .8rem; align-items: flex-end; flex-wrap: wrap; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.meta-form label { font-size: .78rem; }
.counts { display: flex; gap: 1.4rem; flex-wrap: wrap; margin-bottom: 1rem; font-size: .92rem; }

.lines td { vertical-align: middle; }
.line-form { display: flex; flex-direction: column; gap: .4rem; min-width: 320px; }
.search-row { display: flex; gap: .35rem; }
.search-row .prodsearch { flex: 1; }
.line-buttons { display: flex; gap: .4rem; }
.cell-fact .desc { font-weight: 500; }
.matched-line { margin-bottom: .35rem; }
.line-matched { background: #fbfdfb; }
.line-pending_review { background: #fffdf7; }
.line-ignored { opacity: .55; }
.needs-review td { box-shadow: inset 3px 0 0 var(--warn); }

.addline { margin-top: 1rem; }
.addline summary { cursor: pointer; color: var(--primary); font-size: .9rem; }
.addline-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; align-items: center; }
.addline-form input { flex: 1; min-width: 8rem; }

.po-create { border: 1px solid #cfe0fc; }
.po-done { border: 1px solid #c4ead2; background: #fbfffc; }
.po-form { display: flex; flex-direction: column; gap: .9rem; align-items: flex-start; }
.checkbox { flex-direction: row; align-items: center; gap: .5rem; color: var(--ink); }

/* ── reviewscherm v2 ─────────────────────────────────────────────── */
.btn-danger { color: var(--err); }
.btn-danger:hover { background: var(--err-bg); }

.reviewbar {
  position: sticky; top: 8px; z-index: 5;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .7rem 1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.reviewbar-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.rstats { display: flex; gap: 1.1rem; flex-wrap: wrap; font-size: .9rem; align-items: baseline; }
.rstats .ok { color: var(--ok); font-weight: 600; }
.rstats .pending { color: var(--warn); font-weight: 600; }
.toggle { flex-direction: row; align-items: center; gap: .4rem; font-size: .85rem; color: var(--ink); cursor: pointer; user-select: none; }
.progress { height: 6px; background: #eef1f6; border-radius: 999px; margin-top: .6rem; overflow: hidden; }
.progress-fill { height: 100%; background: var(--ok); border-radius: 999px; transition: width .3s; }

.lines-card { overflow-x: auto; }
.lines { table-layout: fixed; }
.lines th, .lines td { padding: .55rem .6rem; vertical-align: top; }
.lines .c-idx { width: 2.4rem; }
.lines .c-num { width: 5.5rem; text-align: right; white-space: nowrap; }
.cell-fact { width: 22%; }
.cell-fact .desc { font-weight: 600; font-size: .92rem; line-height: 1.3; }
.meta-line { margin-top: .25rem; display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; font-size: .78rem; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .76rem; background: #eef1f6; color: #5a6678; padding: .05rem .35rem; border-radius: 4px; }

/* gekoppeld = compacte regel (geen groot blok meer) */
.confirmed { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.confirmed-main { font-size: .92rem; }
.confirmed-main strong { font-weight: 600; }
.change { margin-left: auto; }
.change summary { cursor: pointer; color: var(--primary); font-size: .8rem; list-style: none; }
.change summary::-webkit-details-marker { display: none; }
.change[open] { width: 100%; margin-top: .5rem; margin-left: 0; }

.pending-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }

/* koppel-bediening */
.line-form { display: flex; flex-direction: column; gap: .4rem; max-width: 660px; }
.prodsel { width: 100%; }
.control-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.searchwrap { display: flex; gap: .3rem; flex: 1; min-width: 200px; }
.searchwrap .prodsearch { flex: 1; }

.line-matched { background: #fbfdfb; }
.line-ignored { opacity: .6; }
.needs-review td { box-shadow: inset 3px 0 0 var(--warn); }

/* filter "alleen te beoordelen" */
#linesTable.filter-pending .line-matched,
#linesTable.filter-pending .line-ignored { display: none; }

.po-ready { border-color: #c4ead2; background: #fbfffc; }

/* ── mobiel (≤760px) ─────────────────────────────────────────────── */
@media (max-width: 760px) {
  .topbar { padding: .6rem .8rem; flex-wrap: wrap; gap: .4rem .7rem; justify-content: center; }
  .brand { flex-direction: column; align-items: center; gap: .25rem; font-size: 1rem; }
  .brand-sub { font-size: .85rem; padding-left: 0; border-left: none; color: var(--primary); letter-spacing: .03em; }
  .topnav { width: 100%; gap: 1.1rem; font-size: .9rem; flex-wrap: wrap; justify-content: center; }
  .container { padding: 0 .7rem; margin: 1rem auto; }
  .card { padding: 1rem; }
  .detail-head { gap: .6rem; }
  .detail-actions { width: 100%; }
  .meta-form { gap: .6rem; }
  .meta-form label, .meta-form input { width: 100%; }
  .addline-form input { flex: 1 1 100% !important; width: 100%; }
  .upload-form, .upload-form input { width: 100%; }
  .btn-lg { width: 100%; }

  /* tabellen -> gelabelde blok-kaarten */
  .table thead { display: none; }
  .table, .table tbody { display: block; }
  .table tr { display: block; border: 1px solid var(--line); border-radius: 10px; padding: .55rem .8rem; margin-bottom: .7rem; }
  .table tbody tr:hover { background: transparent; }
  .table td { display: flex; width: auto; justify-content: space-between; align-items: baseline; gap: 1rem; padding: .3rem 0; border: none; text-align: right; overflow-wrap: anywhere; min-width: 0; }
  .table td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; white-space: nowrap; }
  .table td:not([data-label])::before, .table td[data-label='']::before { content: ''; }

  /* reviewscherm: omschrijving + koppel-bediening als volledige blokken */
  .lines td.cell-fact, .lines td.cell-match { display: block; text-align: left; }
  .lines td.cell-fact::before, .lines td.cell-match::before { display: block; margin-bottom: .25rem; }
  .line-form { max-width: none; }
  .control-actions .btn { flex: 1; }
  .reviewbar-top { gap: .5rem; }
}

/* anker-sprong houdt rekening met sticky balk + topbar (geen sprong naar boven) */
.line { scroll-margin-top: 110px; }
.line:target { animation: flash-row 1.4s ease; }
@keyframes flash-row { 0% { background: #fff7da; } 100% { background: transparent; } }

.attribution { margin-top: .85rem; padding-top: .85rem; border-top: 1px solid var(--line); }
.inline-form { display: flex; gap: .35rem; align-items: center; }
.inline-form input { width: 11rem; }
.topnav a { color: var(--ink); }
.topnav a:hover { color: var(--primary); }

/* ── nieuwe componenten ─────────────────────────────────────────── */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; align-items: stretch; }
@media (max-width: 980px) { .grid-3 { grid-template-columns: 1fr; } }
.clickrow { cursor: pointer; }

.sp-filter { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: .9rem; }
.sp-filter input { flex: 1; min-width: 220px; padding: .5rem .6rem; border: 1px solid #cdd5e2; border-radius: 7px; font-size: .92rem; }
.sp-toggle { display: flex; gap: .3rem; flex-wrap: wrap; }
.sp-toggle .btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.invoice-view { margin-top: .9rem; padding-top: .85rem; border-top: 1px solid var(--line); }
.invoice-view summary { cursor: pointer; color: var(--primary); font-size: .9rem; }
.invoice-view-body { margin-top: .7rem; display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }
.invoice-frame { width: 100%; height: 72vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* ── mobiel polish (extra) ─────────────────────────────────────── */
@media (max-width: 760px) {
  .table td::before { font-size: .7rem; text-transform: uppercase; letter-spacing: .02em; }
  .table tr { padding: .65rem .85rem; }
  .table td { gap: .9rem; }
  .searchwrap { min-width: 100%; }
  .change { margin-left: 0; }
  .invoice-frame { height: 60vh; }
  .sp-filter input { min-width: 100%; }
  .sp-toggle { width: 100%; }
  .sp-toggle .btn { flex: 1; }
}

/* ── logo + mini-mailbox ─────────────────────────────────────────── */
.brand { display: inline-flex; align-items: center; gap: .7rem; }
.brand-logo { height: 42px; width: auto; display: block; }
.brand-sub { font-weight: 600; font-size: 1rem; color: var(--ink); letter-spacing: .005em; white-space: nowrap; }
/* divider/streepje alleen naast het logo op desktop; op telefoon staat 'Inkoopportaal' eronder */
@media (min-width: 761px) { .brand-sub { padding-left: .75rem; border-left: 1.5px solid var(--line); } }

.inbox-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.inbox-head h2 { margin: 0; }
.mini-mail { list-style: none; margin: .6rem 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.mini-mail li { padding: .45rem .6rem; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; flex-direction: column; gap: .15rem; }
.mini-mail li:last-child { border-bottom: none; }
.mini-mail li:hover { background: #f7f9fc; }
.mm-from { font-weight: 600; font-size: .85rem; overflow-wrap: anywhere; }
.mm-sub { font-size: .8rem; overflow-wrap: anywhere; }

@media (max-width: 760px) { .brand-logo { height: 34px; } }
