:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e2e8f0;
  --brand: #1d4ed8;
  --brand-dark: #1e40af;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar: merkregel bovenaan, daaronder de navigatie als tab-balk.
   Past op elk formaat: op smalle schermen schuift de tab-balk horizontaal. */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1rem;
  background: #000; border-bottom: 1px solid #333;
  padding: .55rem 1.25rem .45rem; position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; color: #fff; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand img { height: 30px; width: auto; max-width: 160px; object-fit: contain; }
.brand span { overflow-wrap: anywhere; }
.global-search { margin-left: auto; flex: 0 1 230px; min-width: 110px; }
.global-search input { padding: .4rem .6rem; }
.logout { margin-left: 0; }
.topbar nav {
  order: 3; flex: 1 1 100%;
  display: flex; gap: .25rem;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  margin: 0 -.25rem;
}
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a {
  padding: .4rem .75rem; border-radius: 8px; color: #ddd; font-weight: 500;
  white-space: nowrap; flex: 0 0 auto;
}
.topbar nav a:hover { background: #292929; text-decoration: none; }
.topbar nav a.active { background: #fff; color: #111; }
.topbar a:focus-visible, .topbar button:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.global-search input:focus { outline-color: #93c5fd; }
.global-search input::placeholder { color: #59616d; opacity: 1; }
.logout button {
  background: none; border: 1px solid #888; color: #eee;
  padding: .4rem .8rem; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.logout button:hover { border-color: var(--muted); }

/* Layout */
.container { max-width: 1100px; margin: 1.5rem auto; padding: 0 1.5rem; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .6rem .8rem; margin-bottom: 1.2rem;
}
.page-head h1 { font-size: 1.4rem; margin: 0; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.3rem; margin-bottom: 1.2rem;
}
.card.split {
  display: flex; justify-content: space-between; align-items: center;
  gap: .8rem 1rem; flex-wrap: wrap;
}
.version-intro { margin: .25rem 0 0; }
.release-list { display: grid; gap: 1rem; }
.release-card { margin-bottom: 0; }
.release-card.current { border-color: #86efac; box-shadow: 0 0 0 1px #86efac; }
.release-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; }
.release-head h2 { margin: 0; font-size: 1.15rem; }
.release-head > div { display: flex; align-items: center; gap: .55rem; color: var(--muted); }
.release-card ul { margin: .85rem 0 0; padding-left: 1.25rem; }
.release-card li + li { margin-top: .4rem; }
.grid { display: grid; gap: 1.2rem; }
.grid > *, .field-row-3 > *, .form-grid > * { min-width: 0; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* KPI */
.kpi { text-align: left; }
.kpi .label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.kpi .value {
  font-size: clamp(1.15rem, 2.4vw, 1.6rem); font-weight: 700; margin-top: .2rem;
  white-space: nowrap;
}

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .7rem; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tbody tr:hover { background: #fafbfc; }
/* Bedragen: rechts uitgelijnd, gelijke cijferbreedte en nooit afbreken. */
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Forms */
form.stacked label { display: block; margin-bottom: .9rem; font-size: .9rem; color: var(--ink); }
form.stacked label span { display: block; margin-bottom: .25rem; color: var(--muted); font-weight: 500; }
input, select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* Compacte invoerregel-formulieren (werkzaamheid/kostenregel/voorraadcorrectie) */
.form-grid { display: grid; gap: .6rem .8rem; align-items: end; margin-top: 1rem; }
.form-grid label { margin: 0; font-size: .9rem; }
.form-grid label span { display: block; margin-bottom: .25rem; }
.fg-works { grid-template-columns: minmax(170px, 1fr) minmax(200px, 1.2fr) 140px 110px auto; }
.fg-costs { grid-template-columns: 140px minmax(160px, 1fr) minmax(120px, 1fr) 120px auto; }
.fg-stock { grid-template-columns: minmax(180px, 1fr) 130px minmax(140px, 1fr) auto; }
.fg-addwork { grid-template-columns: minmax(140px, 1fr) minmax(160px, 1fr) minmax(180px, 1.2fr) 138px 105px auto; }

/* Multi-select dropdown (standaard werkzaamheden) */
details.multi-select { position: relative; }
details.multi-select > summary {
  list-style: none; cursor: pointer; display: block;
  padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink);
}
details.multi-select > summary::-webkit-details-marker { display: none; }
details.multi-select[open] > summary { outline: 2px solid var(--brand); border-color: var(--brand); }
details.multi-select .options {
  position: absolute; z-index: 30; min-width: 280px; max-width: 92vw; max-height: 280px; overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(31, 41, 51, .14); padding: .35rem; margin-top: .25rem;
}
details.multi-select .options label {
  display: flex; align-items: center; gap: .5rem; padding: .3rem .4rem; margin: 0;
  border-radius: 6px; font-size: .9rem; cursor: pointer; white-space: nowrap;
}
details.multi-select .options label:hover { background: var(--bg); }
details.multi-select .options input[type="checkbox"] { width: auto; margin: 0; }

/* Werkzaamheden-groepen: subitems + inline datum */
.sub-row td { background: #fafbfc; }
.sub-row td:first-child { padding-left: 1.2rem; }
.inline-date { width: auto; padding: .25rem .4rem; font-size: .85rem; }
td.neg .inline-date { color: var(--red); font-weight: 600; }

/* Buttons */
.btn {
  display: inline-block; background: var(--brand); color: #fff; border: none;
  padding: .55rem 1.1rem; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600;
  white-space: nowrap;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: var(--red); }
.btn.small { padding: .3rem .7rem; font-size: .85rem; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }

/* Badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.concept { background: #e5e7eb; color: #374151; }
.badge.verzonden { background: #dbeafe; color: #1e40af; }
.badge.betaald { background: #dcfce7; color: #166534; }
.badge.vervallen { background: #fee2e2; color: #991b1b; }
.badge.geannuleerd { background: #f3f4f6; color: #9ca3af; text-decoration: line-through; }
.badge.besteld { background: #e0e7ff; color: #3730a3; }
.badge.geleverd { background: #cffafe; color: #155e75; }
.badge.gemonteerd { background: #ede9fe; color: #5b21b6; }
.badge.onbetaald { background: #fee2e2; color: #991b1b; }
.badge.klant { background: #e0f2fe; color: #075985; }
.badge.in_te_plannen { background: #f1f5f9; color: #475569; }
.badge.in_behandeling { background: #dbeafe; color: #1e40af; }
.badge.klaar { background: #dcfce7; color: #166534; }

/* Status-select als gekleurde badge (werkzaamheden) */
.badge-select { border: none; border-radius: 999px; padding: .25rem .6rem; font-size: .8rem; font-weight: 600; cursor: pointer; width: auto; }
.badge-select.in_te_plannen { background: #f1f5f9; color: #475569; }
.badge-select.in_behandeling { background: #dbeafe; color: #1e40af; }
.badge-select.klaar { background: #dcfce7; color: #166534; }
.badge-select.geannuleerd { background: #e5e7eb; color: #6b7280; }
.badge.verwacht { background: #fef9c3; color: #854d0e; }
.badge.ingekocht { background: #e5e7eb; color: #374151; }
.badge.in_reparatie { background: #fef3c7; color: #92400e; }
.badge.te_koop { background: #dbeafe; color: #1e40af; }
.badge.verkocht { background: #dcfce7; color: #166534; }

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); font-weight: 600; }
.warn { background: #fef3c7; border: 1px solid #fde68a; color: #92400e; padding: .6rem .8rem; border-radius: 8px; }

/* Flash */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-info { background: #dbeafe; color: #1e40af; }

/* Login */
.login-wrap { max-width: 360px; margin: 8vh auto; }
.login-wrap .card { padding: 2rem; }
.login-wrap h1 { text-align: center; margin-top: 0; }
.login-logo { text-align: center; margin-bottom: 1rem; }
.login-logo img { max-height: 60px; }

/* Line editor */
.lines-table td { vertical-align: middle; }
.lines-table input, .lines-table select { padding: .35rem .45rem; }
.lines-table input[name="line_description"] { min-width: 210px; }
.lines-table input[name="line_unit_price"] { min-width: 110px; }
.lines-table input[name="line_quantity"] { min-width: 65px; }
.lines-table td.actions { width: 40px; }
.link-btn { background: none; border: none; color: var(--red); cursor: pointer; font-size: 1.1rem; }

/* ------------------------- Responsief ------------------------- */
@media (max-width: 1000px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .container { padding: 0 .9rem; margin-top: 1rem; }
  .card { padding: 1rem; }
  .topbar { padding: .5rem .9rem .4rem; }
  th, td { padding: .5rem .5rem; }
  /* Brede tabellen schuiven binnen hun kaart in plaats van het scherm te breken. */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* 16px voorkomt automatisch inzoomen op iOS bij focus op een veld. */
  input, select, textarea { font-size: 16px; }
  .fg-works, .fg-costs, .fg-stock, .fg-addwork { grid-template-columns: 1fr 1fr; }
  .form-grid .btn { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .brand { flex: 1 1 100%; }
  .brand img { max-width: 110px; }
  .global-search { flex: 1 1 140px; margin-left: 0; }
  .topbar nav { min-width: 0; }
  .field-row, .field-row-3 { grid-template-columns: 1fr; gap: 0; }
  .page-head h1 { font-size: 1.25rem; }
}
