* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-ui);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-hover); text-decoration: underline; }

h1, h2, h3 { margin: 0 0 0.75rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

/* Layout */
.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.topbar .brand {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--color-text);
}
.topbar nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.topbar nav a { color: var(--color-text-muted); }
.topbar nav a:hover { color: var(--color-text); text-decoration: none; }

.container {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}
.container-narrow { max-width: 700px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
}
.page-head h1 { margin: 0; }

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
}
.card + .card { margin-top: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }

/* Forms */
.form-row { margin-bottom: 1rem; }
.form-row .help { display: block; color: var(--color-text-muted); font-size: 0.82rem; margin-top: 0.25rem; }
label { display: block; margin-bottom: 0.35rem; font-size: 0.9rem; color: var(--color-text-muted); }
input[type=text],
input[type=email],
input[type=password],
input[type=number],
input[type=date],
input[type=file],
textarea,
select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font: inherit;
}
textarea { min-height: 6rem; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-20);
}
.field-error { color: var(--color-error); font-size: 0.85rem; margin-top: 0.25rem; }

.form-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1rem;
}

button, .btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  background: var(--color-primary);
  color: var(--color-on-primary);
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--color-primary-hover); text-decoration: none; color: var(--color-on-primary); }
.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover { background: var(--color-hover); color: var(--color-text); }
.btn-danger { background: var(--color-error); }
.btn-danger:hover { background: var(--color-error); filter: brightness(0.9); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.85rem; }

/* Login screen */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin: 0 0 1.25rem; font-size: 1.25rem; }

/* Alerts */
.alert {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.92rem;
}
.alert-error {
  background: var(--color-error-bg);
  color: var(--color-error);
  border: 1px solid var(--color-error);
}
.alert-success {
  background: var(--color-primary-20);
  color: var(--color-text);
  border: 1px solid var(--color-primary);
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.93rem;
}
.data-table th,
.data-table td {
  text-align: left;
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--color-border);
}
.data-table th {
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; }
.data-table .actions { text-align: right; white-space: nowrap; }
.data-table .actions a, .data-table .actions form { margin-left: 0.5rem; display: inline-block; }
.empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: 2rem 0;
}

/* Status pills */
.pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text-muted);
}
.pill-concept    { color: var(--color-text-muted); }
.pill-verzonden  { color: var(--color-primary); border-color: var(--color-primary); background: var(--color-primary-20); }
.pill-akkoord    { color: var(--color-secondary); border-color: var(--color-secondary); background: var(--color-secondary-20); }
.pill-verlopen   { color: var(--color-text-muted); }
.pill-afgewezen  { color: var(--color-error); border-color: var(--color-error); background: var(--color-error-bg); }
.pill-betaald    { color: var(--color-secondary); border-color: var(--color-secondary); background: var(--color-secondary-20); }
.pill-archived   { color: var(--color-text-muted); }

/* Inline forms (e.g. archive button) */
.inline-form { display: inline; margin: 0; }
.inline-form button {
  background: transparent;
  color: var(--color-text-muted);
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
}
.inline-form button:hover { color: var(--color-text); text-decoration: underline; }
.inline-form button.danger { color: var(--color-error); }
.inline-form button.danger:hover { color: var(--color-error); filter: brightness(1.2); }

/* Line-item editor (quotes) */
.lines-editor table { width: 100%; border-collapse: collapse; }
.lines-editor th, .lines-editor td { padding: 0.4rem; vertical-align: top; }
.lines-editor input, .lines-editor select { padding: 0.35rem 0.5rem; font-size: 0.9rem; }
.lines-editor .remove-btn { background: transparent; color: var(--color-error); border: none; cursor: pointer; }
.lines-editor .group-header td {
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  padding-top: 0.8rem;
}
.totals-box {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.3rem 1rem;
  max-width: 320px;
  margin-left: auto;
  font-size: 0.95rem;
}
.totals-box .label { color: var(--color-text-muted); }
.totals-box .grand { font-weight: 600; font-size: 1.05rem; }

/* Topbar logout */
.logout-form { display: inline; }
.logout-form button {
  background: transparent;
  color: var(--color-text-muted);
  padding: 0;
  font: inherit;
  cursor: pointer;
}
.logout-form button:hover { color: var(--color-text); }

/* Dashboard */
.dash-logo {
  text-align: center;
  padding: 1.75rem 0 1.25rem;
}
.dash-logo-img {
  max-height: 300px;
  width: auto;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
@media (max-width: 800px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .stats-grid { grid-template-columns: 1fr; } }
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  text-align: center;
}
.stat-card--accent {
  border-color: var(--color-primary);
  background: var(--color-primary-20);
}
.stat-label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.6rem;
}
.stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1;
}

/* Two-column page layout (quote/invoice edit) */
.col-2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}
@media (max-width: 800px) { .col-2 { grid-template-columns: 1fr; } }

/* Charts -------------------------------------------------------------- */
.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.chart-head h2 { margin: 0; }
.chart-sub {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin: 0.35rem 0 0;
  max-width: 62ch;
}
.chart-hero { text-align: right; }
.chart-hero-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.25rem;
  margin: 1.1rem 0 0.4rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 0.45rem; }
.legend-item strong { color: var(--color-text); font-variant-numeric: tabular-nums; }
.swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  display: inline-block;
}
.swatch-portal   { background: var(--series-portal); }
.swatch-archive  { background: var(--series-archive); }
.swatch-quotes   { background: var(--series-quotes); }
.swatch-invoices { background: var(--series-invoices); }
.chart-box { overflow-x: auto; }
.chart-table { margin-top: 1rem; }
.chart-table summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  padding: 0.25rem 0;
}
.chart-table summary:hover { color: var(--color-text); }
.chart-table summary:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.chart-table .data-table { margin-top: 0.6rem; }
.chart-note {
  margin: 0.9rem 0 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Catalogue: manual ordering, collapsing, aligned columns --------------- */
.catalog-hint {
  color: var(--color-text-muted);
  font-size: 0.88rem;
  margin: -0.25rem 0 1rem;
}

/* Fixed layout with shared column widths, so Prijs / BTW / Eenheid line up
   across every subcategory table on the page instead of each table sizing
   its own columns. */
.catalog-table { table-layout: fixed; }
.catalog-table .col-drag    { width: 2.4rem; }
.catalog-table .col-name    { width: auto; }
.catalog-table .col-price   { width: 7.5rem; }
.catalog-table .col-vat     { width: 5rem; }
.catalog-table .col-unit    { width: 6.5rem; }
.catalog-table .col-actions { width: 15rem; }
.catalog-table th.num,
.catalog-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.catalog-table .cell-name { overflow-wrap: anywhere; }
.catalog-table td { vertical-align: middle; }
@media (max-width: 720px) {
  .catalog-table { table-layout: auto; }
  .catalog-table .col-actions { width: auto; }
}

/* Drag handles */
.drag-handle {
  cursor: grab;
  color: var(--color-text-muted);
  user-select: none;
  padding: 0 0.15rem;
  line-height: 1;
}
.drag-handle:active { cursor: grabbing; }
.drag-handle:hover { color: var(--color-text); }
.drag-handle--inline { cursor: default; }
.drag-cell { text-align: center; }
tr.dragging, .sub-block.dragging {
  opacity: 0.55;
  outline: 2px dashed var(--color-primary);
}
.sortable-subs .sub-block { background: var(--color-surface); }

/* Up/down fallback buttons */
.move-group { display: inline-flex; gap: 0.15rem; margin-right: 0.35rem; }
.move-btn {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.05rem 0.35rem;
  font-size: 0.85rem;
  line-height: 1.4;
  cursor: pointer;
}
.move-btn:hover { background: var(--color-hover); color: var(--color-text); }
.move-btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 1px; }

.sort-note {
  color: var(--color-text-muted);
  font-size: 0.82rem;
  margin: 0.6rem 0 0;
  min-height: 1.1em;
}
.sort-note--error { color: var(--color-error); }

/* Collapsing a main category */
.collapse-btn {
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.collapse-btn:hover { background: transparent; color: var(--color-primary); }
.collapse-btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; }
.collapse-btn .chevron { transition: transform 0.15s ease; font-size: 0.8em; }
.cat-root.collapsed .collapse-btn .chevron { transform: rotate(-90deg); }
.cat-head h2, .sub-head h3 { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.cat-count {
  color: var(--color-text-muted);
  font-size: 0.78rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
@media (prefers-reduced-motion: reduce) {
  .collapse-btn .chevron { transition: none; }
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Search bars and type-to-filter dropdowns ------------------------------ */
.search-bar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.search-bar input[type=search] {
  flex: 1 1 22rem;
  max-width: 32rem;
  margin: 0;
}
.search-count {
  color: var(--color-text-muted);
  font-size: 0.85rem;
}
.filter-input { margin-bottom: 0.35rem; }
.filter-note {
  display: block;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  margin: -0.15rem 0 0.35rem;
  min-height: 1em;
}

.lines-warning {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--color-error);
  background: var(--color-error-bg);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 0.88rem;
}

/* Type-to-search combobox over a <select> --------------------------------- */
.combo { position: relative; }
.combo .combo-native {
  /* The select keeps the value and stays in the form; the combo box is what
     you see. Not display:none, so a required select would still be focusable
     if this pattern is ever used on one. */
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  margin: 0;
}
.combo-input { width: 100%; margin: 0; }
.combo.open .combo-input {
  border-color: var(--color-primary);
  outline: 2px solid var(--color-primary-20);
  outline-offset: 0;
}
.combo-list {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  max-height: 17rem;
  overflow-y: auto;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px var(--color-overlay);
}
.combo-option {
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.92rem;
}
.combo-option:hover,
.combo-option.active { background: var(--color-primary-20); }
.combo-option[aria-selected=true] { font-weight: 600; }
.combo-empty {
  padding: 0.4rem 0.55rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  list-style: none;
}
.combo-status {
  display: block;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  min-height: 1em;
  margin-top: 0.15rem;
}

/* Hoofdcategorieën are a sortable list too */
.sortable-roots { display: block; }
.sortable-roots .cat-root.dragging { outline: 2px dashed var(--color-primary); }
.cat-head h2 .drag-handle { font-size: 0.9em; }

/* A combobox that was submitted without a choice */
.combo.invalid .combo-input {
  border-color: var(--color-error);
  outline: 2px solid var(--color-error-bg);
}
.combo.invalid .combo-status { color: var(--color-error); }

/* A paid invoice reads as done at a glance ------------------------------- */
.data-table tr.row-paid { background: var(--color-success-bg); }
.data-table tr.row-paid td { border-bottom-color: var(--color-success); }
.data-table tr.row-paid td:first-child { box-shadow: inset 3px 0 0 var(--color-success); }
/* Paid is the one status worth reading as good news, so it goes green rather
   than sharing the secondary blue with everything else. */
.pill-betaald {
  color: var(--color-success);
  border-color: var(--color-success);
  background: var(--color-success-bg);
}

/* Address lookup on a form ---------------------------------------------- */
.address-lookup {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: -0.4rem 0 1rem;
}
.address-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  min-height: 1.2em;
}
.address-status--ok { color: var(--color-success); }
.address-status--error { color: var(--color-error); }

/* Three across: ex. BTW, percentage, incl. BTW */
.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
}
@media (max-width: 700px) { .grid-3 { grid-template-columns: 1fr; } }

/* A date field with its "Vandaag" shortcut */
.date-with-today {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.date-with-today input[type=date] { flex: 1 1 auto; }
.date-with-today button { white-space: nowrap; }

/* The brand doubles as the way home */
.topbar a.brand { color: var(--color-text); text-decoration: none; }
.topbar a.brand:hover { color: var(--color-primary); text-decoration: none; }
.topbar a.brand:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; border-radius: 2px; }
