:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --ink: #1d2430;
    --muted: #6b7380;
    --line: #e3e6eb;
    --accent: #1f5fbf;
    --accent-ink: #ffffff;
    --good: #18794e;
    --bad: #c0392b;
    --warn: #b26a00;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

/* ---------- top bar ---------- */
.topbar { background: var(--ink); color: #fff; }
.topbar-inner {
    max-width: 1400px; margin: 0 auto; padding: 0 20px;
    display: flex; align-items: center; gap: 32px; height: 52px;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 16px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
    color: #c9cfd8; text-decoration: none; padding: 6px 12px; border-radius: 6px;
}
.topbar nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.topbar nav a.active { color: #fff; background: rgba(255,255,255,.15); }

.container { max-width: 1400px; margin: 0 auto; padding: 24px 20px 60px; }

.page-head {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    margin-bottom: 20px;
}
.page-head h1 { margin: 0; font-size: 24px; }
.head-actions { display: flex; align-items: center; gap: 10px; }

h2 { font-size: 16px; margin: 0 0 14px; }
h2 + h2, .card h2:not(:first-child) { margin-top: 22px; }

/* ---------- cards & layout ---------- */
.card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px 20px; margin-bottom: 20px;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin-bottom: 12px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card, .card + .grid-2 { margin-top: 20px; }
.quote-top { margin-bottom: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- forms ---------- */
.form label, label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 12px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
input, select, textarea {
    display: block; width: 100%; margin-top: 4px;
    font: inherit; color: inherit;
    padding: 7px 10px; border: 1px solid #cdd2da; border-radius: 6px; background: #fff;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,95,191,.15);
}
textarea { resize: vertical; }
textarea.full { margin: 0; }
label.check { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; padding-top: 22px; font-weight: 600; }
label.check input { width: auto; margin: 2px 0 0; }
label.check .hint { flex-basis: 100%; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 3px; }
h2 .hint { display: inline; font-size: 12px; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }

.preview {
    background: #f0f5fd; border: 1px solid #d5e2f7; border-radius: 6px;
    padding: 10px 12px; margin-bottom: 14px; font-size: 13px;
}

.alert { background: #fdecea; color: var(--bad); padding: 8px 12px; border-radius: 6px; }
.notice { background: #e6f4ec; color: var(--good); padding: 8px 12px; border-radius: 6px; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border-radius: 6px; border: 1px solid #cdd2da;
    background: #fff; color: var(--ink); font: inherit; font-weight: 600;
    text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f3f5f8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .6; cursor: default; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tbody tr:hover { background: #fafbfc; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.actions { white-space: nowrap; text-align: right; }
.actions form { display: inline; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.profit { color: var(--good); }
.neg { color: var(--bad) !important; }
.sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }

.empty {
    background: var(--card); border: 1px dashed #c8ced8; border-radius: var(--radius);
    padding: 40px; text-align: center;
}

/* ---------- quote editor ---------- */
.add-bar { display: flex; gap: 8px; align-items: center; }
.add-bar input { width: 320px; margin: 0; }

.lines td { vertical-align: top; }
.lines input { margin: 0; padding: 5px 8px; }
.lines input.desc { min-width: 220px; }
.lines input.n { width: 90px; text-align: right; margin-left: auto; }
.lines input.money { width: 100px; }
.lines input.pct { width: 70px; }
.lines .qty { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.lines .qty span { color: var(--muted); font-size: 12px; min-width: 34px; text-align: left; }
.mini-check { display: flex; align-items: center; gap: 5px; font-weight: 400; font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.mini-check input { width: auto; margin: 0; }
.tag { display: inline-block; font-size: 11px; color: var(--muted); }
.tag.labor { background: #fff3dc; color: var(--warn); padding: 1px 6px; border-radius: 4px; font-weight: 600; }
.row-actions { white-space: nowrap; }
.icon {
    border: 1px solid transparent; background: none; cursor: pointer; font-size: 15px;
    width: 26px; height: 26px; border-radius: 5px; color: var(--muted);
}
.icon:hover:not(:disabled) { background: #eef0f3; color: var(--ink); }
.icon.danger:hover { color: var(--bad); }
.icon:disabled { opacity: .3; cursor: default; }
.empty-lines { text-align: center; padding: 20px 0 6px; margin: 0; }

.totals { display: grid; grid-template-columns: 1fr auto; margin: 0; row-gap: 8px; column-gap: 0; }
.totals dd { padding-left: 20px; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totals dd .sub { display: block; }
.totals .sep { border-top: 1px solid var(--line); padding-top: 8px; }
.totals .grand { font-size: 20px; font-weight: 700; color: var(--ink); border-top: 2px solid var(--ink); padding-top: 10px; }

#productSearch { width: 200px; margin: 0; }

/* ---------- login ---------- */
.user-box { margin-left: auto; display: flex; align-items: center; gap: 10px; color: #c9cfd8; font-size: 13px; }
.user-box button {
    background: none; border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 6px;
    padding: 4px 10px; font: inherit; cursor: pointer;
}
.user-box button:hover { background: rgba(255,255,255,.1); }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-box { width: 100%; max-width: 380px; padding: 28px; }
.login-brand { font-weight: 700; font-size: 18px; }
.login-company { margin-bottom: 4px; }
.login-box h1 { font-size: 20px; margin: 18px 0 6px; }
.login-box p.muted { margin-top: 0; }
.btn.block { width: 100%; justify-content: center; padding: 10px; }
code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---------- alleen op mobiel zichtbaar ---------- */
.mobile-bar { display: none; }

/* =========================================================
   Mobiel (telefoon / smalle tablet)
   ========================================================= */
@media (max-width: 760px) {
    body { font-size: 15px; }
    /* 16px voorkomt dat iOS inzoomt bij het typen */
    input, select, textarea { font-size: 16px; padding: 9px 10px; }

    /* menu */
    .topbar-inner { height: auto; flex-wrap: wrap; gap: 4px 12px; padding: 8px 12px; }
    .brand { font-size: 15px; }
    .user-box { order: 2; }
    .user-box span { display: none; }
    .topbar nav {
        order: 3; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
        margin: 0 -4px; padding-bottom: 2px;
    }
    .topbar nav a { white-space: nowrap; padding: 8px 12px; }

    .container { padding: 14px 12px 40px; }
    .page-head { flex-wrap: wrap; margin-bottom: 14px; }
    .page-head h1 { font-size: 20px; }
    .page-head form, .head-actions { width: 100%; }
    .head-actions { flex-wrap: wrap; }
    .head-actions .btn, .page-head form .btn { flex: 1; justify-content: center; padding: 10px; }
    #saveStatus { width: 100%; order: 3; font-size: 13px; }

    .card { padding: 14px; margin-bottom: 14px; border-radius: 10px; }
    .grid-2 { gap: 14px; }
    .grid-2 + .card, .card + .grid-2, .quote-top { margin-top: 0; margin-bottom: 14px; }
    .form .row { grid-template-columns: 1fr; gap: 0; }
    label.check { padding-top: 0; }
    .btn { padding: 10px 14px; }
    .btn.small { padding: 7px 11px; font-size: 13px; }
    .card-head { align-items: stretch; }
    #productSearch { width: 100%; }

    /* ----- tabellen als kaarten ----- */
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tbody tr {
        border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; margin-bottom: 10px;
        background: #fff;
    }
    .table tbody tr:hover { background: #fff; }
    /* label links, waarde(n) rechts onder elkaar */
    .table td {
        display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 12px; align-items: center;
        border-bottom: 1px solid #f0f1f4; padding: 7px 0; text-align: right;
    }
    .table td:last-child { border-bottom: 0; }
    .table td::before {
        content: attr(data-label); grid-row: 1 / span 3;
        color: var(--muted); font-size: 13px; text-align: left;
    }
    .table td > .qty, .table td > input, .table td > label { justify-self: end; }
    .table td:not([data-label])::before, .table td[data-label=""]::before { display: none; }
    .table td > * { text-align: right; }
    .table:not(.lines) td:first-child { display: block; text-align: left; font-size: 16px; padding-top: 4px; }
    .table:not(.lines) td:first-child::before { display: none; }
    .table td.actions { justify-content: flex-end; flex-wrap: wrap; gap: 6px; padding-top: 10px; }
    .table td.actions::before { display: none; }

    /* ----- offerteregels ----- */
    .add-bar { flex-wrap: wrap; width: 100%; }
    .add-bar input { width: 100%; }
    .add-bar .btn { flex: 1; justify-content: center; }
    .table-wrap { overflow: visible; }

    .lines tbody tr { position: relative; padding-top: 10px; }
    .lines tbody tr.is-labor { border-left: 3px solid var(--warn); }
    .lines td { align-items: center; }
    .lines td.cell-desc { display: block; padding-right: 96px; text-align: left; }
    .lines td.cell-desc::before { display: none; }
    .lines input.desc { min-width: 0; width: 100%; font-weight: 600; text-align: left; }
    .lines td.cell-desc .sub { text-align: left; }

    /* tabelkaarten niet nog eens in een kaart */
    .card:has(> .table):not(:has(form.form)), .card:has(> .table-wrap) { background: transparent; border: 0; padding: 0; }
    .card:has(> .table-wrap) .card-head { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
    .lines input.n, .lines input.money, .lines input.pct { width: 120px; }
    .lines .qty span { min-width: 44px; }
    .lines td.cell-need > div, .lines td.cell-need > label { justify-content: flex-end; }
    .lines tr.no-pkg td.cell-need, .lines tr.is-labor td.cell-need { display: none; }
    .lines td.row-actions {
        position: absolute; top: 10px; right: 8px; width: auto;
        border: 0; padding: 0; display: flex; gap: 2px;
    }
    .lines td.row-actions::before { display: none; }
    .icon { width: 30px; height: 34px; font-size: 17px; }

    /* totaal-balk onderin */
    body:has(.mobile-bar) { padding-bottom: 76px; }
    .mobile-bar {
        display: flex; align-items: center; gap: 8px;
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
        background: #fff; border-top: 1px solid var(--line);
        box-shadow: 0 -4px 16px rgba(0,0,0,.06);
    }
    .mobile-bar-total { flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
    .mobile-bar-total .muted { font-size: 12px; }
    .mobile-bar-total strong { font-size: 18px; }
    .mobile-bar-total .sub { color: var(--good); }
    .totals .grand { font-size: 18px; }

    /* login */
    .login-box { padding: 22px; }
}
