:root {
  /* Dealerflow huisstijl, gelijk aan het portaal en de registraties-app. */
  --ink: #1b2a44;
  --text: #1b2a44;
  --text-2: #33415a;
  --muted: #5b6679;
  --faint: #8e97a6;
  --line: #e4e0d8;
  --line-soft: #eee9e0;
  --field-line: #d3cdc2;
  --bg: #faf8f4;
  --surface: #fff;
  --subtle: #f3f0ea;
  --focus: #e8692a;
  --accent: #e8692a;
  --accent-soft: #fdeee5;
  --nav-bg: #1b2a44;
  --nav-bg-2: #243656;
  --nav-line: #2c3d5c;
  --nav-text: #c9d2e0;
  --nav-muted: #8391a8;
  --selected: #fdeee5;
  --selected-line: #e8692a;
  --radius: 12px;
  --gap: 18px;
  --pad: 24px;
  font-family: "Plus Jakarta Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; }

/* --- Knoppen --- */
button { border: 0; border-radius: 8px; padding: 10px 14px; background: var(--ink); color: #fff; cursor: pointer; }
button:hover { opacity: .9; }
button:disabled { opacity: .6; cursor: progress; }
button.secondary { background: var(--line); color: var(--ink); }
button.small { padding: 6px 10px; font-size: 12px; }
button.danger { background: #b91c1c; }
.icon-btn { padding: 4px 10px; background: transparent; color: var(--text-2); font-size: 28px; line-height: 1; }

/* --- Topbalk --- */
.topbar { min-height: 82px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 var(--pad); }
.brand { flex: 1; min-width: 0; }
.topbar h1 { font-size: 22px; margin: 0; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.menu-btn { display: none; }
.account { display: flex; align-items: center; gap: 10px; }
.account-name { font-size: 13px; color: var(--text-2); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tenant-box { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.tenant-box select { margin: 0; min-width: 220px; max-width: 280px; padding: 8px 10px; font-weight: 600; color: var(--ink); border-color: var(--ink); }
.tenant-name { font-size: 13px; font-weight: 600; color: var(--ink); background: var(--subtle); border-radius: 999px; padding: 6px 12px; }

/* --- Indeling en navigatie --- */
.layout { display: grid; grid-template-columns: 190px minmax(0, 1fr); min-height: calc(100vh - 82px); }
.sidebar { padding: 20px 12px; border-right: 1px solid var(--nav-line); background: var(--nav-bg); color: var(--nav-text); min-width: 0; }
.nav-btn { display: block; width: 100%; text-align: left; margin-bottom: 4px; background: transparent; color: var(--nav-text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-btn:hover { background: var(--nav-bg-2); color: #fff; opacity: 1; }
.nav-btn.active { background: var(--accent); color: #fff; }
.nav-btn:disabled { opacity: .4; cursor: not-allowed; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--nav-muted); font-weight: 700; margin: 14px 10px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-group:first-child { margin-top: 0; }
.sidebar-foot { display: none; }
.nav-backdrop { display: none; }
.content { padding: var(--pad); min-width: 0; }
.content-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.content-head h2 { margin: 0; }
.content-head p { margin: 4px 0 0; color: var(--muted); }

/* --- Kaarten en rasters --- */
.grid { display: grid; grid-template-columns: minmax(310px, 440px) minmax(0, 1fr); gap: var(--gap); align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 2px rgba(0, 0, 0, .03); }
.card h3 { margin: 0 0 16px; font-size: 16px; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Stamgegevens: lijst links, geselecteerd record rechts. */
.entity-grid { grid-template-columns: minmax(0, 1fr) minmax(320px, 440px); }
.form-card { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; }
.back-btn { display: none; }
fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.plain:disabled input, fieldset.plain:disabled select, fieldset.plain:disabled textarea { background: #f9fafb; color: var(--text); border-color: var(--line); opacity: 1; -webkit-text-fill-color: var(--text); }
.review-actions { display: contents; }
.search { margin: 0 0 12px; }

/* --- Formulieren --- */
label { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 600; }
label .hint { display: block; font-weight: 400; margin-top: 4px; }
input, select, textarea { width: 100%; margin-top: 6px; padding: 10px 11px; border: 1px solid var(--field-line); border-radius: 8px; background: var(--surface); color: var(--ink); }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
input[aria-invalid="true"] { border-color: #dc2626; background: #fff7f7; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; }
.form-grid label { grid-column: 1 / -1; }
.form-grid label.half { grid-column: auto; }
.req { color: #b91c1c; }
.field-error { display: block; color: #b91c1c; font-size: 12px; font-weight: 500; margin-top: 4px; }
.field-error:empty { display: none; }
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }
.actions.tight { margin-top: 0; }
.sticky-actions button { flex: 1; }
.form-card .sticky-actions { position: sticky; bottom: 0; background: var(--surface); padding: 12px 0 18px; margin-bottom: -18px; border-top: 1px solid var(--line-soft); }
.hint { color: var(--muted); font-size: 12px; }

/* --- Tabellen --- */
.table-wrap { overflow: auto; max-height: 70vh; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; border-bottom: 1px solid var(--line-soft); padding: 10px; vertical-align: top; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface); color: var(--muted); font-weight: 600; z-index: 1; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 260px; }
tfoot th { position: static; color: var(--ink); border-top: 2px solid var(--line); }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f9fafb; }
tr.clickable:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
tr.selected, tr.selected:hover { background: var(--selected); box-shadow: inset 3px 0 0 var(--selected-line); }
tr.current { background: #fdf5ee; }
.row-actions { display: flex; gap: 6px; }

/* --- Labels en meldingen --- */
.pill { background: var(--subtle); border-radius: 999px; padding: 4px 9px; font-size: 12px; }
.badge { display: inline-block; border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 600; }
.badge.on { background: #ecfdf5; color: #047857; }
.badge.off { background: #f3f4f6; color: var(--muted); }
.badge.warn { background: #fffbeb; color: #92400e; }
.badge.err { background: #fef2f2; color: #b91c1c; }
.boolean-true { color: #047857; }
.boolean-false { color: var(--faint); }
.status { margin-bottom: 14px; border-radius: 9px; padding: 11px 13px; font-size: 13px; }
.status.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.status.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.status button { margin-left: 10px; }
.confirm { margin-top: 4px; border: 1px solid #fecaca; background: #fef2f2; border-radius: 10px; padding: 12px; }
.confirm p { margin: 0 0 10px; font-size: 13px; color: #7f1d1d; }
.hidden { display: none !important; }

/* --- Dialoog en login --- */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(650px, 92vw); box-shadow: 0 20px 60px rgba(0, 0, 0, .22); }
dialog::backdrop { background: rgba(17, 24, 39, .4); }
.dialog-card { padding: 20px; }
.dialog-card h2 { margin: 0; }
.login-gate { display: flex; justify-content: center; padding: 60px 20px; }
.login-gate .card { width: min(430px, 100%); }

/* --- Bedrijvenbeheer --- */
.logo-thumb { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px; background: var(--subtle); color: #4b5563; font-size: 12px; font-weight: 700; overflow: hidden; }
.logo-thumb img, .logo-preview img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.company-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--gap); align-items: start; }
.company-main { display: grid; gap: var(--gap); min-width: 0; }
.company-side { display: grid; gap: 14px; position: sticky; top: 16px; }
.logo-preview { height: 140px; border: 1px solid var(--line); border-radius: 10px; display: flex; align-items: center; justify-content: center; background: #f9fafb; color: var(--faint); font-size: 34px; font-weight: 700; margin-bottom: 12px; overflow: hidden; padding: 8px; }
.file-drop { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 1.5px dashed #cbd5e1; border-radius: 10px; padding: 14px; text-align: center; cursor: pointer; font-weight: 600; }
.file-drop.over, .file-drop:hover { border-color: var(--focus); background: var(--accent-soft); }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-drop:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Tabbladen (bedrijfsgegevens / boekhoudkoppeling) */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab { flex: 0 0 auto; background: transparent; color: var(--muted); border-radius: 8px 8px 0 0; border-bottom: 2px solid transparent; font-weight: 600; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tab:disabled { cursor: not-allowed; opacity: .5; }

/* --- Facturatie --- */
.inline-filter { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 12px; }
.inline-filter select { margin: 0; width: auto; padding: 6px 8px; }

/* ===================== Tablet en mobiel ===================== */
@media (max-width: 900px) {
  :root { --pad: 16px; --gap: 14px; }

  .topbar { min-height: 60px; flex-wrap: wrap; padding: 8px var(--pad); gap: 8px 10px; position: sticky; top: 0; z-index: 30; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; font-size: 24px; }
  .topbar h1 { font-size: 18px; }
  .topbar p { display: none; }
  .desktop-only { display: none !important; }
  .topbar-actions { flex: 1 1 100%; }
  .topbar-actions:not(:has(> :not(.hidden, .desktop-only))) { display: none; }
  .tenant-box { flex: 1; }
  .tenant-box select { min-width: 0; max-width: none; flex: 1; }

  /* Zijbalk wordt een uitschuifmenu. */
  .layout { display: block; min-height: 0; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; width: min(290px, 85vw); display: flex; flex-direction: column; overflow-y: auto; border-right: 1px solid var(--nav-line); box-shadow: 0 0 40px rgba(0, 0, 0, .18); transform: translateX(-105%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open { overflow: hidden; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(17, 24, 39, .4); }
  .sidebar > * { flex-shrink: 0; }
  .nav-btn { min-height: 44px; }
  .sidebar-foot { display: flex; flex-direction: column; gap: 8px; margin-top: auto; padding-top: 14px; border-top: 1px solid var(--nav-line); }
  .sidebar-foot .account-name { max-width: none; padding: 0 4px; color: #fff; }
  .sidebar-foot button.secondary { background: var(--nav-bg-2); color: #fff; }

  .content-head { flex-wrap: wrap; }
  .grid, .company-layout { grid-template-columns: 1fr; }

  /* Stamgegevens: lijst of detail, niet allebei. */
  .entity-grid .form-card { display: none; position: static; max-height: none; overflow: visible; }
  .entity-grid.show-detail .form-card { display: block; }
  .entity-grid.show-detail .list-card { display: none; }
  .back-btn { display: block; width: 100%; margin-bottom: 14px; }
  .form-card, table.cards tr { scroll-margin-top: 140px; }
  .table-wrap { max-height: none; }

  /* Opslaan-knoppen blijven onderaan in beeld. */
  .form-card .sticky-actions { bottom: 0; margin: 16px -18px -18px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 -6px 16px rgba(0, 0, 0, .06); }
  .company-layout { display: flex; flex-direction: column; align-items: stretch; }
  .company-side { display: contents; }
  .company-side .sticky-actions { position: sticky; bottom: 0; z-index: 5; margin: 0 calc(-1 * var(--pad)); padding: 12px var(--pad) calc(12px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 16px rgba(0, 0, 0, .06); }

  /* Aanraakvriendelijk; 16px voorkomt inzoomen op iOS. */
  button { min-height: 44px; }
  button.small { min-height: 36px; padding: 8px 12px; }
  input, select, textarea { font-size: 16px; padding: 11px 12px; }
}

@media (max-width: 700px) {
  /* Tabellen worden kaarten: één kaart per regel, kolomnaam links. */
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tfoot, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; margin-bottom: 10px; background: var(--surface); }
  table.cards tr.selected { border-color: var(--selected-line); box-shadow: none; }
  table.cards td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border: 0; padding: 7px 0; white-space: normal; text-align: right; overflow-wrap: anywhere; }
  table.cards td + td { border-top: 1px solid var(--line-soft); }
  table.cards td[data-label]::before { content: attr(data-label); flex: 0 0 40%; text-align: left; font-weight: 600; color: var(--muted); }
  table.cards td[data-label=""]::before { display: none; }
  table.cards td:not([data-label]) { justify-content: flex-start; text-align: left; }
  table.cards td.wrap { min-width: 0; }
  table.cards tfoot tr { display: flex; justify-content: space-between; border: 0; background: transparent; padding: 6px 0; }
  table.cards tfoot th { display: block; border: 0; padding: 4px 0; }
  table.cards .row-actions { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid label.half { grid-column: 1 / -1; }
  .content-head .actions { width: 100%; }
  .content-head .actions button { flex: 1; }
}
