/* ============================================================
   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: visible; }
  .rp-concept { font-size: clamp(40px, 13vw, 56px); left: 50% !important; letter-spacing: 0.08em; white-space: nowrap; }
  .rp-calc-wrap { overflow-x: auto; max-width: 100%; margin-right: -4px; }
  .rp-calc-wrap::after { content: "← veeg voor alle kolommen →"; display: block; text-align: center; font-size: 12px; color: var(--ink-faint); padding-top: 6px; }
}

@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%; }
}

/* Kopbalk mobiel: bel en avatar naast elkaar, verticaal gecentreerd */
@media (max-width: 760px) {
  .sidebar { align-items: center; }
  .sidebar-foot { flex-direction: row !important; align-items: center; gap: 8px; margin: 0 0 0 auto; height: 60px; }
  .sidebar-foot .wk-bel-m { margin: 0; }
  .sidebar-foot .user-chip { width: 44px; height: 44px; padding: 2px; justify-content: center; border-radius: 999px; box-shadow: var(--shadow-btn); background: #fff; }
  .sidebar-foot .user-avatar { width: 40px; height: 40px; }
  .wk-bel-m .wk-teller { top: -4px; right: -4px; }
}

/* ============================================================
   Agenda: nette kaarten, dagstrip op telefoon
   ============================================================ */
.wt-agenda-bar { margin-bottom: 8px; }
.wt-weekrij { display: flex; align-items: center; gap: 10px; margin: 6px 0 16px; }
.wt-weekrij .wt-weeklabel { flex: 1; margin: 0; display: flex; flex-direction: column; align-items: center; gap: 0; font-family: var(--sans); }
.wt-weekrij .wt-weeklabel strong { font-size: 16px; font-weight: 600; }
.wt-weekrij .wt-weeklabel .muted { font-size: 12.5px; }
.wt-pijl { flex: 0 0 44px; width: 44px; height: 44px; border: 0; border-radius: 999px; background: var(--paper-2); color: var(--ink); display: grid; place-items: center; cursor: pointer; }
.wt-pijl svg { width: 20px; height: 20px; }
.wt-pijl:hover { background: var(--ink); color: #fff; }
.wt-vandaagknop { flex: 0 0 auto; }

/* Afspraakkaart */
.wt-item { border: 0 !important; border-radius: 16px !important; background: #fff; box-shadow: 0 0 0 1px var(--line-soft), 0 6px 16px -10px rgba(160, 96, 30, 0.35); overflow: hidden; position: relative; }
.wt-item::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; background: var(--wt-kleur, var(--accent)); }
.wt-item-hoofd { display: flex !important; flex-direction: row !important; align-items: flex-start; gap: 12px; padding: 14px 14px 12px 18px !important; width: 100%; text-align: left; background: transparent; border: 0; font: inherit; color: inherit; cursor: pointer; }
.wt-item-tijd { flex: 0 0 auto; display: flex; flex-direction: column; min-width: 46px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.wt-item-tijd b { font-size: 15px; font-weight: 700; color: var(--ink); }
.wt-item-tijd i { font-style: normal; font-size: 12.5px; color: var(--ink-faint); }
.wt-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.wt-item-titel { font-size: 15px !important; font-weight: 600; line-height: 1.3; }
.wt-item-klant { font-size: 13.5px !important; color: var(--ink-soft); }
.wt-item-adres { font-size: 13px; color: var(--ink-faint); overflow-wrap: anywhere; }
.wt-item-wie { margin-top: 4px; gap: 6px; font-size: 12.5px !important; color: var(--ink-soft); }
.wt-item-wie .wt-av { margin: 0 !important; }
.wt-item-acties { display: flex; gap: 8px; padding: 0 14px 14px 18px; flex-wrap: wrap; }
.wt-item-acties .wt-item-link { display: inline-flex !important; align-items: center; gap: 7px; min-height: 40px !important; padding: 0 14px !important; border: 0 !important; border-radius: 999px; background: var(--paper-2); color: var(--ink) !important; font-size: 13.5px !important; font-weight: 600; text-decoration: none !important; flex: 0 1 auto; }
.wt-item-acties .wt-item-link::before { content: none !important; }
.wt-item-acties .wt-item-link svg { width: 17px; height: 17px; color: var(--accent-dark); flex: 0 0 auto; }
.wt-item-acties .wt-item-link:hover { background: #fde8d2; }
.wt-item-acties .wt-maps { background: var(--ink) !important; color: #fff !important; }
.wt-item-acties .wt-maps svg { color: #ffb36b; }

/* Weekraster computer: compacte kaarten */
.wt-week .wt-item-hoofd { flex-direction: column !important; gap: 4px; padding: 10px 10px 8px 14px !important; }
.wt-week .wt-item-tijd { flex-direction: row; gap: 4px; }
.wt-week .wt-item-tijd b, .wt-week .wt-item-tijd i { font-size: 12.5px; }
.wt-week .wt-item-tijd i::before { content: "– "; }
.wt-week .wt-item-titel { font-size: 13.5px !important; }
.wt-week .wt-item-adres { font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.wt-week .wt-item-acties { padding: 0 10px 10px 14px; gap: 6px; }
.wt-week .wt-item-acties .wt-item-link { min-height: 34px !important; padding: 0 10px !important; font-size: 12.5px !important; }
.wt-week .wt-item-acties .wt-tel span { display: none; }

@media (max-width: 760px) {
  /* Chips: één veegbare rij */
  .wt-chips { flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 2px 18px 6px; scroll-padding: 18px; }
  .wt-chips::-webkit-scrollbar { display: none; }
  .wt-chip { flex: 0 0 auto; }
  .wt-weeknav { display: none; }

  /* Dagstrip */
  .wt-dagstrip { display: grid; grid-template-columns: repeat(7, minmax(44px, 1fr)); gap: 2px; margin: 0 -10px 16px; }
  .wt-agenda.box { padding-left: 12px !important; padding-right: 12px !important; }
  .wt-dagknop { display: flex; flex-direction: column; align-items: center; gap: 1px; min-height: 64px; padding: 8px 0 6px; border: 0; border-radius: 14px; background: transparent; font: inherit; color: var(--ink-soft); cursor: pointer; }
  .wt-dagknop span { font-size: 12px; text-transform: capitalize; }
  .wt-dagknop b { font-size: 18px; font-weight: 600; color: var(--ink); }
  .wt-dagknop i { font-style: normal; height: 10px; line-height: 8px; font-size: 14px; letter-spacing: 1px; color: var(--accent); }
  .wt-dagknop.vandaag b { color: var(--accent-dark); }
  .wt-dagknop.actief { background: var(--ink); color: rgba(255,255,255,.75); box-shadow: 0 8px 18px -10px rgba(24, 54, 74, .8); }
  .wt-dagknop.actief b { color: #fff; }
  .wt-dagknop.actief i { color: #ffb36b; }

  .wt-mdag-kop { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-family: var(--sans) !important; font-size: 17px !important; font-weight: 600; margin: 0 0 12px !important; }
  .wt-mdag-n { margin-left: auto; font-size: 13px; font-weight: 500; color: var(--ink-faint); }
  .wt-daglijst .wt-item { margin-bottom: 12px; }
  .wt-leeg-dag { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 12px; border-radius: 16px; background: var(--paper); color: var(--ink-soft); text-align: center; }
  .wt-agenda.box { padding: 18px; }
}

/* ============================================================
   Paginakop op telefoon: titel en actie naast elkaar, geen dubbel merk
   ============================================================ */
@media (max-width: 760px) {
  .page-title::before { content: none !important; }
  .page-head { display: grid !important; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 12px; row-gap: 6px; margin-bottom: 18px; }
  .page-head > div { display: contents; }
  .page-head .page-title { grid-column: 1; grid-row: 2; margin: 0; }
  .page-head .page-sub { grid-column: 1 / -1; grid-row: 3; margin: 0; }
  .page-head .back-link { grid-column: 1 / -1; grid-row: 1; }
  .page-head > .btn, .page-head > div + .btn { grid-column: 2; grid-row: 2; width: auto !important; min-width: 0 !important; padding: 0 16px; }
  .page-head > .btn + .btn { grid-row: 4; grid-column: 1 / -1; }
}
