:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --border-soft: #f1f5f9;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #10b981;
    --success-soft: #d1fae5;
    --warning: #f59e0b;
    --warning-soft: #fef3c7;
    --danger: #ef4444;
    --danger-soft: #fee2e2;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
    --shadow: 0 4px 16px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.75rem; margin: 0 0 .25rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 600; }
h3 { font-size: 1rem; margin: 0 0 .25rem; font-weight: 600; }
p { margin: 0 0 .5rem; }

/* ===== Topbar ===== */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: 60px;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: .75rem; text-decoration: none; color: var(--text); }
.brand-mark { width: 28px; height: 28px; background: var(--primary); border-radius: 6px; }
.brand strong { display: block; font-weight: 700; line-height: 1.1; }
.brand small { display: block; color: var(--muted); font-size: 11px; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.user { text-align: right; }
.user strong { display: block; font-size: 13px; }
.user small { display: block; color: var(--muted); font-size: 11px; }

/* ===== Shell ===== */
.shell { display: flex; min-height: calc(100vh - 60px); }
.sidebar {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1rem .75rem;
    flex-shrink: 0;
}
.sidebar a {
    display: block;
    padding: .55rem .75rem;
    border-radius: 6px;
    color: var(--muted);
    font-weight: 500;
    margin-bottom: .15rem;
    text-decoration: none;
}
.sidebar a:hover { background: var(--border-soft); color: var(--text); text-decoration: none; }
.sidebar a.active { background: var(--primary-soft); color: var(--primary); }
.nav-section { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 1rem .75rem .4rem; font-weight: 600; }
.brand-logo-wrap { text-align: center; margin-bottom: 1.5rem; }
.brand-logo { max-height: 80px; max-width: 240px; }
.uppercase { text-transform: uppercase; letter-spacing: .05em; }
.content { flex: 1; padding: 2rem; max-width: 1200px; }
.full-content { max-width: 980px; margin: 0 auto; padding: 2rem; }

/* ===== Page-head ===== */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.page-head .muted { margin: 0; }

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}
.card.no-pad { padding: 0; overflow: hidden; }
.card.sticky { position: sticky; top: 1rem; }
.card-head {
    margin: -.25rem -1.5rem 1.25rem;
    padding: 0 1.5rem 1rem;
    border-bottom: 1px solid var(--border-soft);
}
.card-head h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -.01em;
}
.card-head p { margin: .35rem 0 0; font-size: 13px; color: var(--muted); }
.card.no-pad .card-head { margin: 0; padding: 1rem 1.5rem; }

/* ===== Stats ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow-sm); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 2rem; font-weight: 700; margin-top: .25rem; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 1.25rem; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem 1rem; border-radius: 6px;
    font-weight: 500; font-size: 14px; line-height: 1;
    border: 1px solid transparent; cursor: pointer; text-decoration: none;
    transition: background .12s, border-color .12s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; }
.btn-outline { border-color: var(--border); background: white; color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-ghost { color: var(--text); background: transparent; }
.btn-ghost:hover { background: var(--border-soft); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; color: white; border-color: #dc2626; }
.btn-danger-outline { color: var(--danger); border-color: var(--danger); background: white; }
.btn-danger-outline:hover { background: var(--danger-soft); color: #991b1b; }
.btn-block { width: 100%; }
.btn-lg { padding: .8rem 1.5rem; font-size: 15px; }
.btn-sm { padding: .35rem .65rem; font-size: 12px; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn-group.right { justify-content: flex-end; margin-top: 1rem; }
.icon-btn { background: none; border: none; cursor: pointer; padding: .5rem; font-size: 16px; color: var(--muted); border-radius: 4px; }
.icon-btn:hover { background: var(--border-soft); color: var(--text); }

/* ===== Forms ===== */
label {
    display: block;
    margin-bottom: 1.1rem;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}
label > small {
    display: block;
    margin-top: .35rem;
    font-weight: 400;
    color: var(--muted);
    line-height: 1.35;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="file"]),
select,
textarea {
    display: block;
    width: 100%;
    margin-top: .4rem;
    padding: .6rem .75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: white;
    line-height: 1.4;
    transition: border-color .12s, box-shadow .12s;
    box-sizing: border-box;
}
input[type="file"] {
    display: block;
    width: 100%;
    margin-top: .4rem;
    padding: .5rem .75rem;
    border: 1px dashed var(--border);
    border-radius: 6px;
    background: var(--border-soft);
    font-size: 13px;
    cursor: pointer;
    box-sizing: border-box;
}
input[type="file"]:hover { border-color: var(--primary); background: var(--primary-soft); }
input::placeholder, textarea::placeholder { color: #94a3b8; }
input:hover, select:hover, textarea:hover { border-color: #94a3b8; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
select {
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%2364748b' d='M6 9L1 4h10z'/></svg>");
    background-repeat: no-repeat;
    background-position: right .75rem center;
    padding-right: 2rem;
    cursor: pointer;
}
textarea { resize: vertical; min-height: 88px; line-height: 1.5; }

.check-line {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 500;
    cursor: pointer;
    padding: .35rem 0;
    margin-bottom: .25rem;
}
.check-line input { width: auto; margin: 0; }
.check-line:hover { color: var(--primary); }

/* Grid voor checkbox-lijsten (bijv. bijzondere situaties) */
.check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: .25rem .75rem;
}
@media (max-width: 640px) { .check-grid { grid-template-columns: 1fr; } }

/* Subtiele groepering om checkbox + bijbehorend veld */
.check-block {
    padding: .75rem;
    margin: 0 -.25rem 1rem;
    border-radius: 6px;
    background: var(--border-soft);
    border: 1px solid transparent;
}
.check-block > label:not(.check-line) { margin-bottom: 0; }
.check-block:has(input[type="checkbox"]:checked) {
    background: var(--primary-soft);
    border-color: rgba(37, 99, 235, .2);
}

/* Layout helpers — gap uniform horizontaal + verticaal, sluit aan op label margin */
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1.25rem; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.25rem; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1.25rem; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 1.25rem; }
.form-span-2 { grid-column: span 2; }
.form-span-3 { grid-column: span 3; }
.form-span-full { grid-column: 1 / -1; }
@media (max-width: 720px) {
    .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }
    .form-span-2, .form-span-3, .form-span-full { grid-column: auto; }
}

/* ===== Public signing-shell (no sidebar) ===== */
.public-content { max-width: 800px; margin: 2rem auto; padding: 0 1.5rem 4rem; }
.public-content.wide { max-width: 1200px; }
.signing-shell { }

/* Signing two-column: PDF left (sticky), form right */
.sign-grid { display: grid; grid-template-columns: 1fr 440px; gap: 1.5rem; align-items: start; }
.sign-pdf-col { position: sticky; top: 1rem; }
.sign-pdf-col .otd-pdf-frame { height: calc(100vh - 5rem); min-height: 600px; }
.sign-form-col { min-width: 0; }
@media (max-width: 1024px) {
    .sign-grid { grid-template-columns: 1fr; }
    .sign-pdf-col { position: static; }
    .sign-pdf-col .otd-pdf-frame { height: 560px; }
}

/* Input met prefix-symbool (€, %, etc.) */
.input-prefix {
    position: relative;
    margin-top: .4rem;
}
.input-prefix-symbol {
    position: absolute;
    left: .75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-weight: 500;
    pointer-events: none;
    font-size: 14px;
}
.input-prefix input {
    margin-top: 0 !important;
    padding-left: 1.75rem !important;
}

/* OTD form grid (form + sticky total panel) */
.otd-grid { display: grid; grid-template-columns: 1fr 420px; gap: 1.5rem; align-items: start; }
.otd-main { min-width: 0; }
.otd-side { position: sticky; top: 1rem; display: flex; flex-direction: column; gap: .75rem; }
@media (max-width: 1100px) {
    .otd-grid { grid-template-columns: 1fr; }
    .otd-side { position: static; }
}

/* OTD PDF live preview */
.otd-pdf-card { padding: 0; overflow: hidden; }
.otd-pdf-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: .65rem 1rem; border-bottom: 1px solid var(--border-soft);
}
.otd-pdf-head h2 { font-size: 13px; font-weight: 600; }
.otd-pdf-frame {
    width: 100%; height: 560px; border: none; display: block; background: #f1f5f9;
}
.otd-pdf-empty {
    padding: 2.5rem 1.5rem; text-align: center; color: var(--muted);
    background: var(--border-soft);
}
.otd-pdf-empty .ico { font-size: 2rem; margin-bottom: .5rem; opacity: .5; }

.total-amount {
    background: var(--primary-soft);
    border: 1px solid #93c5fd;
    border-radius: 6px;
    padding: 1rem 1.25rem;
    text-align: center;
}
.total-amount span { display: block; }
.total-amount strong {
    display: block;
    font-size: 1.75rem;
    color: var(--primary);
    margin-top: .25rem;
    font-variant-numeric: tabular-nums;
}

/* Signature pad */
.signature-pad-wrap {
    margin-top: .5rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    align-items: flex-start;
}
.signature-pad {
    width: 100%;
    max-width: 600px;
    height: 200px;
    border: 2px dashed var(--border);
    border-radius: 6px;
    background: white;
    cursor: crosshair;
    touch-action: none;
}
.signature-pad.has-ink { border-style: solid; border-color: var(--primary); }

/* Subtiel scheidingslijntje + kop tussen veld-groepen binnen card */
.card hr.field-divider {
    border: none;
    border-top: 1px solid var(--border-soft);
    margin: 1rem -.5rem 1.25rem;
}
.field-group-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    margin: 0 0 .9rem;
}

.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: .5rem; }
.subform { border: 1px solid var(--border); border-radius: 6px; padding: 1rem; background: var(--border-soft); margin-bottom: 1rem; }
.subform legend { font-weight: 600; padding: 0 .35rem; }
.filter-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem 1.25rem; align-items: end; }

/* Card-spacing for forms */
.card label:last-child { margin-bottom: .25rem; }
.card-head + label, .card-head + .form-row, .card-head + .form-grid-2, .card-head + .form-grid-3 { margin-top: .25rem; }
.card-head h2 { font-size: 1rem; }
.card-head p { margin-top: .25rem; font-size: 13px; }

/* ===== Tables ===== */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .75rem 1.25rem; border-bottom: 1px solid var(--border); font-weight: 600; }
.data-table td { padding: .75rem 1.25rem; border-bottom: 1px solid var(--border-soft); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: var(--bg); }
.data-table .right { text-align: right; }
.mono { font-variant-numeric: tabular-nums; font-family: "SF Mono", Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.center { text-align: center; }
.right { text-align: right; }
.pagination-wrap { padding: 1rem 1.25rem; border-top: 1px solid var(--border-soft); }

/* ===== Row list ===== */
.row-list { list-style: none; padding: 0; margin: 0; }
.row-list li { display: flex; justify-content: space-between; align-items: center; padding: .75rem 0; border-bottom: 1px solid var(--border-soft); }
.row-list li:last-child { border: none; }
.row-list .row-right { display: flex; align-items: center; gap: .75rem; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 20px; font-size: 11px; font-weight: 600; letter-spacing: .01em; }
.badge-green { background: var(--success-soft); color: #065f46; }
.badge-amber { background: var(--warning-soft); color: #92400e; }
.badge-red { background: var(--danger-soft); color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }

/* ===== Alerts ===== */
.alert { padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: var(--success-soft); border-color: var(--success); color: #065f46; }
.alert-warn { background: var(--warning-soft); border-color: var(--warning); color: #92400e; }
.alert ul { margin: .25rem 0 0 1.25rem; padding: 0; }

/* ===== Form-error ===== */
.form-error { color: var(--danger); font-size: 13px; margin: 0 0 .5rem; }
.form-error ul { margin: 0 0 0 1.25rem; padding: 0; }

/* ===== Auth ===== */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: var(--bg); }
.auth-card { max-width: 420px; width: 100%; }

/* ===== Empty states ===== */
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty-large { padding: 3rem 1rem; }
.empty strong { color: var(--text); display: block; margin-bottom: .5rem; }

/* ===== Check page ===== */
.check-grid { display: grid; grid-template-columns: 1fr 400px; gap: 1.5rem; align-items: start; }
@media (max-width: 1024px) { .check-grid { grid-template-columns: 1fr; } }
.result-score { padding: 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.result-score-green { background: var(--success-soft); border-color: var(--success); color: #065f46; }
.result-score-amber { background: var(--warning-soft); border-color: var(--warning); color: #92400e; }
.result-score-red { background: var(--danger-soft); border-color: var(--danger); color: #991b1b; }
.result-score small { text-transform: uppercase; letter-spacing: .05em; font-size: 11px; }
.result-score strong { display: block; font-size: 1.4rem; margin-top: .25rem; }
.result-list { display: grid; grid-template-columns: 1fr auto; gap: .35rem 1rem; margin: 0; }
.result-list dt { color: var(--muted); font-size: 13px; }
.result-list dd { margin: 0; text-align: right; }

/* ===== Check show ===== */
.big-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.big-stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow-sm); }
.big-stat span { display: block; }
.big-stat strong { display: block; font-size: 1.75rem; margin-top: .25rem; }
.big-stat-green { background: var(--success-soft); border-color: var(--success); color: #065f46; }
.big-stat-amber { background: var(--warning-soft); border-color: var(--warning); color: #92400e; }
.big-stat-red { background: var(--danger-soft); border-color: var(--danger); color: #991b1b; }
.big-number { font-size: 2.25rem; font-weight: 700; margin: .5rem 0; }
.kv-grid { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.5rem; margin: 0; }
.kv-grid dt { color: var(--muted); }
.kv-grid dd { margin: 0; }

/* ===== Snippet / pre ===== */
.snippet, pre { background: #0f172a; color: #e2e8f0; padding: 1rem; border-radius: 6px; font-size: 12px; overflow: auto; line-height: 1.5; }

/* ===== Tier cards ===== */
.tier-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.tier-card { padding: 1rem; border: 1px solid var(--border); border-radius: 6px; }
.tier-card.active { border-color: var(--primary); background: var(--primary-soft); }
.tier-card ul { list-style: none; padding: 0; margin: .5rem 0 0; font-size: 12px; }
.tier-card ul li { padding: .15rem 0; }

/* ===== Landing ===== */
.landing { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }
.landing-header { display: flex; justify-content: space-between; padding: 1rem 0; }
.hero { text-align: center; padding: 5rem 1rem 4rem; }
.hero h1 { font-size: 2.5rem; max-width: 700px; margin: 0 auto 1.25rem; }
.hero p { font-size: 1.1rem; color: var(--muted); max-width: 600px; margin: 0 auto 2rem; }
.cta { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; padding: 0 0 4rem; }
.feature { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }
.feature-ico { width: 40px; height: 40px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700; margin-bottom: .75rem; }

/* ===== API key ===== */
.api-key-row { display: flex; gap: .5rem; align-items: center; }
.api-key-row code { flex: 1; background: var(--border-soft); padding: .55rem .75rem; border-radius: 6px; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }

/* ===== Spinner ===== */
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; margin-left: .35rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Dialog ===== */
dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); max-width: 500px; width: 90%; }
dialog::backdrop { background: rgba(15, 23, 42, .5); }
.explain-text { background: var(--border-soft); border: 1px solid var(--border); padding: 1rem; border-radius: 6px; white-space: pre-wrap; font-size: 14px; margin-bottom: 1rem; }

/* ===== Signature preview ===== */
.sig-preview { max-height: 80px; display: block; background: var(--border-soft); padding: .5rem; border-radius: 6px; border: 1px solid var(--border); margin-top: .5rem; }

/* ===== Stat card colors ===== */
.stat-card-blue  { border-top: 3px solid var(--primary); }
.stat-card-green { border-top: 3px solid var(--success); }
.stat-card-amber { border-top: 3px solid var(--warning); }
.stat-card-purple{ border-top: 3px solid #8b5cf6; }
.stat-value.primary { color: var(--primary); }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }

/* ===== Danger zone ===== */
.danger-zone { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--border-soft); }

/* ===== Letter type pill ===== */
.type-pill {
    display: inline-block;
    font-size: 11px; font-weight: 600;
    padding: 2px 10px; border-radius: 20px;
}

/* ===== Pagination ===== */
.pagination-wrap nav { display: flex; align-items: center; gap: .25rem; }
.pagination-wrap span, .pagination-wrap a {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 32px; height: 32px; padding: 0 .5rem;
    border-radius: 6px; font-size: 13px; color: var(--muted);
    border: 1px solid transparent;
    text-decoration: none;
}
.pagination-wrap a:hover { background: var(--border-soft); color: var(--text); text-decoration: none; }
.pagination-wrap [aria-current="page"] span {
    background: var(--primary); color: white; border-color: var(--primary);
}

/* ===== Toast/flash ===== */
.flash-success {
    position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 999;
    background: var(--text); color: white;
    padding: .75rem 1.25rem; border-radius: 8px;
    font-size: 14px; box-shadow: var(--shadow);
    animation: slideUp .25s ease;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Section divider ===== */
.section-divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
