/* DentaPlan 2.3 workspaces (VORAAA-89, flag layout_v23, ADR 0004): Planen in 2/3 columns, Details anpassen and the
 * Herleitung beside the cards, the HKP stage as Was fehlt | Positionen | Kosten, Beraten, Unterschrift and the
 * ZE-Reparatur using the width. Concept: docs/design/v2.3-desktop.md § 3.5–3.8, mockups web/design/v2.3 (#plan,
 * #plan-details, #hkp). Every layout rule is scoped to html.l23 and a min-width ≥ 1024, so the phone (< 600) and
 * the tablet (600–1023) stay as in 2.2; the wrappers the screens add (.ws-c, .ws-sign, .ws-rep-*) are
 * display: contents there (.ws-sign and .ws-rep-* are only rendered with the flag). Tokens only, no inline styles (CSP). */

/* ---------- wrappers that only lay out from 1024/1440 ---------- */
.p21 .ws-c, .ws-sign, .ws-rep-a, .ws-rep-b, .ws-rep-c, .ws-consult, .ws-consult-a, .ws-consult-b { display: contents; }
/* Unterschrift (only rendered with layout_v23): display: contents breaks the 2.2 ".card + .card" gap between
 * "Ablauf" and the Patientenlink – restore it below 1024 so the phone and tablet stay as in 2.2 (VORAAA-94 D3) */
@media (max-width: 1023px) { .timeline-card + .ws-sign > .card:first-child { margin-top: var(--sp-4); } }
/* Reparatur (wrappers only with layout_v23): same for the last damage card and "Ergebnis" (VORAAA-96 D5) */
@media (max-width: 1023px) { .ws-rep-b:has(> .card:last-child) + .ws-rep-c > .card:first-child { margin-top: var(--sp-4); } }
.p21-side, .p21-acts, .h21-side, .rep-cost23, .hl-open23 { display: none; }

/* ================================ Planen ================================ */
.p21-hero { display: grid; gap: 4px; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-lg); background: var(--accent-50); margin-bottom: var(--sp-3); }
.p21-hero > span { font-size: var(--fs-sm); color: var(--ink-2); }
.p21-hero > div { display: flex; align-items: center; gap: var(--sp-2); }
.p21-hero b { font-size: 30px; font-weight: var(--fw-semi); letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; line-height: 1.15; }
.p21-cost .sums small, .p21-regions small { display: block; font-size: var(--fs-xs); color: var(--ink-3); font-weight: var(--fw-regular); }
.p21-regions { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--line); font-size: var(--fs-sm); }
.p21-regions dd .own { font-weight: var(--fw-semi); white-space: nowrap; }
.p21-cost .linkish { margin-top: var(--sp-2); min-height: 32px; }
.p21-check .entry-h .tiny { display: inline-flex; align-items: center; gap: 4px; color: var(--ok-ink); }
.p21-check .entry-h .tiny svg { width: 14px; height: 14px; }
.p21-check .checks { margin: 0; }
.p21-acts { gap: var(--sp-2); padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.p21-acts .info { display: grid; font-size: var(--fs-sm); color: var(--ink-2); }
.p21-acts .info b { color: var(--ink); }
.p21-acts .acts { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.p21-acts .acts .btn { flex: 1 1 auto; }
.hl21 .hl-sheet .section-title h2 { display: none; } /* the panel head already says "Herleitung" */
.hl21 .hl-sheet .card { box-shadow: none; border: 0; padding: 0; margin: 0; background: transparent; }

@media (min-width: 1024px) {
  /* laptop: Befund | Therapie from 1024 (2.2: only from 1081); Details/Herleitung take the Befund's place */
  html.l23 .p21 .plan { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: var(--gap-ws); }
  html.l23 .p21.det-open .plan { grid-template-columns: minmax(0, 1fr) var(--pane-w); }
  html.l23 .p21.det-open .plan > .entry { display: none; }
  html.l23 .plan .det21 { position: sticky; top: var(--sp-4); left: auto; right: auto; bottom: auto; z-index: auto; max-width: none; margin: 0; border-radius: var(--radius);
    max-height: calc(100vh - 2 * var(--sp-4) - 84px); overflow-y: auto; /* refined by SHELL23.fit (.ws-fit) */ overscroll-behavior: contain; padding-bottom: var(--sp-4); }
  html.l23 .p21 .det-scrim { display: none; }
  html.l23 .plan .det-foot { position: static; background: none; padding-bottom: 0; }
}
@media (min-width: 1440px) {
  /* desktop: Befund | Therapie | Kosten & Prüfung (sticky); the Fall bar's actions move into the third column */
  html.l23 .p21 .plan, html.l23 .p21.det-open .plan { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) var(--pane-w); }
  html.l23 .p21.det-open .plan > .entry { display: block; }
  html.l23 .p21 .ws-c { display: flex; flex-direction: column; gap: var(--sp-3); position: sticky; top: var(--sp-4); max-height: calc(100vh - 2 * var(--sp-4)); min-width: 0; }
  html.l23 .p21 .ws-c > .det21 { position: static; max-height: none; flex: 0 1 auto; min-height: 0; box-shadow: var(--shadow); }
  html.l23 .p21-side:not([hidden]) { display: grid; gap: var(--sp-3); align-content: start; flex: 0 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  html.l23 .p21-side .card { margin: 0; }
  html.l23 .p21-acts { display: grid; flex: none; }
  html.l23 .p21 .therapy .p21-checks { display: none; } /* the Prüfung is in the third column */
  html.l23 .fb-ws { display: none; }
  html.l23 .p21.ws3 { padding-bottom: var(--sp-6); }
}
@media (min-width: 1920px) {
  html.l23 .p21 .plan, html.l23 .p21.det-open .plan { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) var(--pane-w); }
}

/* ================================ HKP stage ================================ */
.hkp21 .h21-c { display: contents; }
.h21-side { gap: var(--sp-2); padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.h21-side .info { display: grid; font-size: var(--fs-sm); color: var(--ink-2); }
.h21-side .info b { color: var(--ink); font-size: var(--fs-md); }
.h21-side .acts { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.h21-side .acts .btn { flex: 1 1 auto; }
.h21-side .acts .btn-primary { flex-basis: 100%; }
.h21-cost .linkish { margin-top: var(--sp-3); min-height: 32px; }

@media (min-width: 1024px) {
  /* laptop: Was noch fehlt + Kosten (left) | Positionen (right, full height); the bar stays */
  html.l23 .hkp21 { grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.2fr); grid-template-areas: "a b" "c b"; gap: var(--gap-ws); }
  html.l23 .hkp21 > section:first-child { grid-area: a; }
  html.l23 .hkp21 .h21-cost { grid-area: c; }
  html.l23 .hkp21 .hkp21-pos { grid-area: b; grid-column: auto; }
  html.l23 .hl-open23 { display: inline-flex; }
  /* positions never scroll sideways: the table fits its column, long fee texts wrap */
  html.l23 .hkp21-pos .lines-scroll { overflow-x: visible; }
  html.l23 .hkp21-pos .lines { table-layout: auto; }
  html.l23 .hkp21-pos .pos-label { min-width: 0; overflow-wrap: anywhere; }
  html.l23 .hkp21-pos .lines td, html.l23 .hkp21-pos .lines th { padding-right: 8px; }
  html.l23 .hkp21-pos .input-xs { width: 64px; }
}
@media (min-width: 1440px) {
  /* desktop: Was noch fehlt (sticky) | Positionen | Kosten + actions (sticky); no bar */
  html.l23 .hkp21 { grid-template-columns: 340px minmax(0, 1fr) var(--pane-w); grid-template-areas: "a b c"; }
  html.l23 .hkp21 > section:first-child { position: sticky; top: var(--sp-4); }
  html.l23 .hkp21 .h21-c { grid-area: c; display: flex; flex-direction: column; gap: var(--sp-3); position: sticky; top: var(--sp-4); max-height: calc(100vh - 2 * var(--sp-4)); min-width: 0; }
  html.l23 .hkp21 .h21-c .h21-cost { flex: 0 1 auto; min-height: 0; overflow-y: auto; }
  html.l23 .h21-side { display: grid; flex: none; }
  /* the 340 px column: the lab field and "Zurück zu Planen" go below the text (as on the phone) */
  html.l23 .hkp21 ol.todo li { grid-template-columns: auto minmax(0, 1fr); }
  html.l23 .hkp21 ol.todo li > :nth-child(3) { grid-column: 2; justify-self: start; }
}
@media (min-width: 1920px) {
  html.l23 .hkp21 { grid-template-columns: 380px minmax(0, 1fr) var(--pane-w); }
}

/* ================================ Beraten ================================ */
@media (min-width: 1024px) {
  /* option cards side by side over the full width (2.2: 250 px cards and an empty rest of the row) */
  html.l23 .ws-consult .optgrid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--gap-ws); }
  html.l23 .ws-consult .optgrid-1 { grid-template-columns: minmax(0, 640px); }
}
@media (min-width: 1440px) {
  /* desktop: options | "Wie entschieden?", estimate note and Patientenlink in a sticky right column */
  html.l23 .ws-consult { display: grid; grid-template-columns: minmax(0, 1fr) var(--pane-w); gap: var(--gap-ws); align-items: start; }
  html.l23 .ws-consult-a { display: block; min-width: 0; }
  html.l23 .ws-consult-b { display: block; position: sticky; top: var(--sp-4); min-width: 0; padding-top: var(--sp-4); }
  html.l23 .ws-consult-b > :first-child { margin-top: 0; }
  html.l23 .ws-consult-b .via { flex-direction: column; align-items: stretch; }
}

/* ================================ Unterschrift ================================ */
@media (min-width: 1024px) {
  /* laptop: Patientenlink | Unterschrift am Tablet + PDFs; Kasse und Status below the link */
  html.l23 .ws-sign { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "a b" "c b"; gap: var(--gap-ws); align-items: start; margin-top: var(--sp-4); }
  html.l23 .ws-sign .grid-2 { display: contents; }
  html.l23 .ws-sign #link-card { grid-area: a; }
  html.l23 .ws-sign .sign-card { grid-area: b; }
  html.l23 .ws-sign .kasse-card { grid-area: c; }
  html.l23 .ws-sign .card { margin: 0; }
  html.l23 .ws-sign .hx-one .kasse-card { grid-column: 1 / -1; }
}
@media (min-width: 1440px) {
  /* desktop: Patientenlink | Unterschrift | Kasse und Status – the lifecycle 1 → 2 → 3 left to right */
  html.l23 .ws-sign { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "a b c"; }
}

/* ================================ ZE-Reparatur ================================ */
@media (min-width: 1024px) {
  /* laptop: Bestand (chart + Zahnersatz) | Schaden; the action bar sits at the bottom of the window */
  html.l23 .rep-page { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "a b" "a c"; gap: 0 var(--gap-ws); align-items: start; padding-bottom: 120px; }
  html.l23 .ws-rep-a { display: block; grid-area: a; min-width: 0; }
  html.l23 .ws-rep-b { display: block; grid-area: b; min-width: 0; }
  html.l23 .ws-rep-c { display: block; grid-area: c; min-width: 0; }
  html.l23 .ws-rep-a .existing { grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); }
  html.l23 .ws-rep-b > h2:first-child { margin-top: var(--sp-4); }
  html.l23 .ws-rep-b .tiles { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
  html.l23 .ws-rep-c > .card { margin-top: var(--sp-4); }
  html.l23 .rep-page .cfg-bar { position: fixed; left: var(--rail-w); right: 0; bottom: 0; margin: 0; border-radius: 0; border-width: 1px 0 0; box-shadow: none; padding: var(--sp-3) var(--gutter); }
  html.l23.has-panel .rep-page .cfg-bar { right: var(--pane-w); }
  /* Details anpassen of the repair: docked at the right from 1024 (2.2: from 1081) */
  html.l23 #app > .rd-open { padding-right: calc(var(--pane-w) + var(--sp-4)); }
  html.l23 .det21.rd21 { position: fixed; top: var(--sp-4); right: var(--sp-4); bottom: var(--sp-4); left: auto; width: var(--pane-w); max-width: none; max-height: none; margin: 0; z-index: var(--z-sheet); border-radius: var(--radius); overflow-y: auto; overscroll-behavior: contain; }
  html.l23 #rd-scrim { display: none; }
  html.l23 .rd21 .det-foot { position: static; background: none; }
  html.l23 #app > .rd-open .rep-page .cfg-bar { right: calc(var(--pane-w) + var(--sp-4) * 2); }
}
@media (min-width: 1440px) {
  /* desktop: Bestand | Schaden | Herleitung + "Reparatur-HKP erstellen" (sticky); no bar */
  html.l23 .rep-page { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) var(--pane-w); grid-template-areas: "a b c"; padding-bottom: var(--sp-6); }
  html.l23 .ws-rep-c { display: flex; flex-direction: column; gap: var(--sp-3); position: sticky; top: var(--sp-4); max-height: calc(100vh - 2 * var(--sp-4)); padding-top: var(--sp-4); }
  html.l23 .ws-rep-c > .card { margin: 0; flex: 0 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  html.l23 .ws-rep-c .derived .k { grid-template-columns: minmax(0, 1fr) auto; }
  html.l23 .ws-rep-c .derived .k span:first-child { grid-column: 1 / -1; }
  html.l23 .rep-page .cfg-bar { position: static; flex: none; border-radius: var(--radius); border-width: 1px; box-shadow: var(--shadow); padding: var(--sp-3) var(--sp-4); background: var(--card); }
  html.l23 .rep-page .cfg-bar .btn-primary { flex: 1 1 100%; }
  html.l23 .ws-rep-b .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

/* panel headings get the focus on open (tabindex -1, for screen readers): no ring, also after D / H */
.det21 .det-head h2:focus-visible { outline: 0; box-shadow: none; }
