/* ============================================================
   UI/UX-fixes en overzichtelijkheid (laadt als allerlaatste)
   Gemeten problemen:
   - kleine tekst <12px (codes, avatars, tabelkoppen, labels)
   - onderdelencatalogus liep over het uurprijsveld heen
   - afgekapte regels op overzicht/berichten
   - rapport bewerken 17.000px lang op telefoon
   ============================================================ */

/* ---------- Leesbaarheid: minimaal 12px, rustige labels ---------- */
.avatar-sm, .wt-av, .wt-av-sm { font-size: 12px !important; }
.wt-av-sm { width: 28px !important; height: 28px !important; }
.wd-code { font-size: 11.5px; padding: 1px 6px; min-width: 30px; }
.tbl th { font-size: 12px; text-transform: none; letter-spacing: 0; color: var(--ink-soft); font-weight: 600; }
.field label, .customer-facts dt, .wt-feiten dt, .wt-kpi-label, .wt-vinkjes legend, .kpi-label, .report-search-label { font-size: 12.5px !important; text-transform: none !important; letter-spacing: 0 !important; font-weight: 600; }
.field label { color: var(--ink-soft); }
.customer-facts dt, .wt-feiten dt { color: var(--ink-faint); }
.ov-staaf span { font-size: 11.5px; }
.bn-item { font-size: 11.5px; }

/* ---------- Overzicht: regels niet afkappen, maar netjes afbreken ---------- */
.ov-tijdlijn span, .ov-lijst span { white-space: normal; overflow: visible; text-overflow: clip; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.message-main span { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Calculatie: catalogus in eigen kolom, geen overlap ---------- */
.calc-grid { align-items: start; }
.calc-grid > .box { display: flex; flex-direction: column; min-height: 0; }
.catalog-list { display: grid !important; grid-template-columns: 1fr; gap: 6px; max-height: 320px; overflow-y: auto; padding: 2px 4px 2px 0; flex: 0 0 auto; align-content: start; }
.catalog-btn { width: 100%; justify-content: flex-start; min-height: 44px; border-radius: 12px !important; font-weight: 500; }
.catalog-btn[disabled] { opacity: 0.45; }
.catalog-search { width: 100%; min-height: 44px; border: 1px solid #ddd5ca; border-radius: 999px; padding: 0 16px; margin-bottom: 10px; font: inherit; }

/* ---------- Rapport bewerken: inklapbare secties ---------- */
.wd-sectie { margin-bottom: 14px; padding: 0; border: 0; background: #fff; border-radius: 22px; box-shadow: var(--shadow); scroll-margin-top: 150px; overflow: clip; }
.wd-sectie-kop { width: 100%; display: flex; align-items: center; gap: 16px; padding: 20px 24px; min-height: 76px; border: 0; background: transparent; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.wd-sectie-kop:hover { background: #fffaf4; }
.wd-sectie-kop:focus-visible { outline: 3px solid rgba(255, 119, 0, 0.35); outline-offset: -3px; }
.wd-sectie-titel { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.wd-sectie .wd-sectie-kop h2 { margin: 0; font-size: 24px; }
.wd-sectie .wd-sectie-kop h2::before { content: none; }
.wd-sectie-sam { font-size: 14px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wd-let-tekst { color: var(--accent-dark); font-weight: 600; }
.wd-chevron { flex: 0 0 36px; width: 36px; height: 36px; border-radius: 50%; background: var(--paper-2); position: relative; transition: transform .2s, background .2s; }
.wd-chevron::after { content: ""; position: absolute; left: 12px; top: 10px; width: 10px; height: 10px; border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); transform: rotate(45deg); }
.wd-sectie.open .wd-chevron, details[open] > summary .wd-chevron { transform: rotate(180deg); background: var(--ink); }
.wd-sectie.open .wd-chevron::after, details[open] > summary .wd-chevron::after { border-color: #fff; }
.wd-sectie-inhoud { padding: 4px 24px 26px; border-top: 1px solid var(--line-soft); animation: wdOpen .22s ease; }
.wd-sectie-inhoud > .box, .wd-sectie-inhoud > .grid > .box, .wd-sectie-inhoud .grid > .box { box-shadow: none; border: 1px solid var(--line-soft); }
.wd-sectie-inhoud > .box:first-child, .wd-sectie-inhoud > .grid:first-child, .wd-sectie-inhoud > p:first-child { margin-top: 18px; }
@keyframes wdOpen { from { opacity: 0; transform: translateY(-4px); } }
.section-nav button { position: relative; }
.section-nav button.open { color: var(--ink); font-weight: 600; }
.wd-let { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.wd-allesknop { margin-left: auto; background: var(--paper-2) !important; color: var(--ink) !important; font-weight: 600 !important; }

/* ---------- Medewerkers: rechten als uitklapkaarten ---------- */
details.wt-recht-kaart { padding: 0; overflow: hidden; }
details.wt-recht-kaart:not([open]) > :not(summary) { display: none; }
.wt-recht-sam { list-style: none; display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 64px; cursor: pointer; }
.wt-recht-sam::-webkit-details-marker { display: none; }
.wt-recht-sam > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.wt-recht-sam .muted { font-size: 13px; }
details.wt-recht-kaart > :not(summary) { margin-left: 16px; margin-right: 16px; }
details.wt-recht-kaart > :last-child { margin-bottom: 16px; }
details.wt-recht-kaart[open] { box-shadow: var(--shadow-hover); }

/* ---------- Tabelkaarten mobiel: niets meer buiten de kaart ---------- */
@media (max-width: 760px) {
  .tbl td { flex-wrap: wrap; }
  .tbl td > * { min-width: 0; max-width: 100%; }
  .tbl td .muted { white-space: normal; }
  .tbl-wrap { overflow-x: visible; }

  /* Nieuw rapport / formulieren: blad begint bovenaan in beeld */
  .modal-backdrop { overflow-y: auto; }
  .modal { max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; }

  /* Rapport bewerken */
  .wd-sectie { border-radius: 18px; margin-left: -4px; margin-right: -4px; scroll-margin-top: 130px; }
  .wd-sectie-kop { padding: 16px; min-height: 68px; gap: 12px; }
  .wd-sectie .wd-sectie-kop h2 { font-size: 20px; }
  .wd-sectie-sam { font-size: 13px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .wd-sectie-inhoud { padding: 4px 14px 18px; }
  .wd-allesknop { display: none; }
  .report-editor { padding-bottom: 80px; }
  .catalog-list { max-height: 260px; }

  /* A4-rapport op telefoon: leesbaar schalen */
  .rapport { font-size: 12.5px; padding: 18px 16px; }
  .rapport .rp-tbl, .rapport .rp-meta-tbl { font-size: 12px; }
  .rp-cols { grid-template-columns: 1fr !important; }
}

/* Kentekencodes: iets groter */
.wd-code { font-size: 12px; }
/* A4-rapport op het scherm leesbaar; print houdt de A4-maten */
@media screen {
  .rapport { font-size: 13px; }
  .rapport .rp-tbl, .rapport .rp-meta-tbl { font-size: 12.5px; }
  .rp-code { font-size: 10px; }
  .rp-vin em, .rp-foto figcaption span { font-size: 10px; }
  .rp-foto figcaption { font-size: 12px; }
  .rp-muted, .rp-bron { font-size: 12px; }
}
@media (max-width: 760px) {
  /* Afrondbalk niet over de inhoud: alleen tonen als de kop uit beeld is */
  .wd-balk { transition: transform .25s, opacity .25s; }
  .wd-balk.verborgen { transform: translateY(140%); opacity: 0; pointer-events: none; }
  .rp-calc-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ===== Mobiele bugfixes ronde 2 ===== */
@media (max-width: 1099px) {
  /* Calculatie: kolommen onder elkaar (was 316px + 0px → knoppen over alles heen) */
  .calc-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .calc-grid > .box { grid-column: auto !important; width: 100%; }
}
@media (max-width: 760px) {
  /* Tel/mail/terug-links: groter tikvlak */
  .tbl td a[href^="tel:"], .tbl td a[href^="mailto:"], a.wt-tel, .customer-facts a, .wt-feiten a, a.back-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 2px; }
  a.back-link { margin-bottom: 4px; }

  /* Modals: sluitknop vast 44x44, knoppenbalk binnen het blad */
  .modal-close { flex: 0 0 44px; width: 44px !important; min-width: 44px; height: 44px; display: grid; place-items: center; }
  .modal-head { gap: 12px; align-items: flex-start; }
  .modal-head > :first-child { min-width: 0; flex: 1; }
  .modal-body { overflow-x: hidden; }
  .modal-foot { position: sticky; bottom: 0; margin: 8px 0 0 !important; width: auto; flex-wrap: wrap; justify-content: stretch; padding-left: 16px; padding-right: 16px; }
  .modal-body .modal-foot { bottom: calc(-16px - env(safe-area-inset-bottom)); margin: 8px -16px -16px !important; }
  .modal-foot .btn { flex: 1 1 140px; white-space: normal; }
  .modal-body > :last-child:not(.modal-foot) { margin-bottom: 4px; }

  /* Verstuur-naar-klant: tekst loopt niet meer weg */
  .verstuur-preview { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; max-width: 100%; }
  .verstuur-link a { display: inline-block; min-height: 44px; line-height: 1.4; padding: 10px 0; }

  /* Lightbox: grotere pijlen */
  .lb-nav { width: 48px !important; height: 48px !important; font-size: 26px; }

  /* A4-rapport: CONCEPT-watermerk binnen het papier */
  .rapport { overflow: hidden; }
  .rp-concept { font-size: 64px; }
}

@media (max-width: 760px) {
  .wd-scan-acties { width: 100%; }
  .wd-scan-acties > * { flex: 1 1 100%; min-width: 0; }
  .wd-land { width: 100%; text-overflow: ellipsis; }
  .melding-stack { left: 12px; right: 12px; width: auto; }
  .melding-pop { max-width: 100%; }
}
