/* Gemeinsame Glaswerte für schwebende Elemente; Hauptflächen bleiben unverändert. */
:root {
  --glass-base: rgba(248, 252, 255, .48);
  --glass-top: rgba(255, 255, 255, .28);
  --glass-bottom: rgba(218, 232, 247, .18);
  --glass-edge: rgba(136, 160, 185, .7);
  --glass-glint: rgba(255, 255, 255, .95);
  --glass-shadow: rgba(24, 49, 75, .2);
  --glass-field: rgba(255, 255, 255, .4);
}
/* Dunkles Glas erhält kühle Lichtkanten statt einer weißen, milchigen Fläche. */
html[data-theme="dark"] {
  --glass-base: rgba(23, 36, 51, .48);
  --glass-top: rgba(174, 211, 244, .06);
  --glass-bottom: rgba(10, 20, 35, .18);
  --glass-edge: rgba(139, 174, 203, .5);
  --glass-glint: rgba(215, 238, 255, .23);
  --glass-shadow: rgba(0, 0, 0, .38);
  --glass-field: rgba(8, 19, 33, .2);
}

/* ID-haltige Auswahl überschreibt die alten individuellen Popup-Farben gezielt. */
html :is(#terminkontext, #itemkontext, #loadstatus, .tour-card, .demo-interest,
  .notification, .action-popover, .vis-tooltip, .placement-preview, .week-move-preview) {
  background: linear-gradient(160deg, var(--glass-top), var(--glass-bottom) 65%),
    var(--glass-base) !important;
  color: var(--ink) !important;
  border: 1px solid var(--glass-edge) !important;
  border-radius: 14px;
  box-shadow: inset 0 1px 0 var(--glass-glint),
    0 12px 32px var(--glass-shadow) !important;
  /* Nur der Hintergrund wird weichgezeichnet, Text und Icons bleiben scharf. */
  -webkit-backdrop-filter: blur(18px) saturate(125%);
  backdrop-filter: blur(18px) saturate(125%);
}

/* Deckende Alt-Tabellen dürfen den Glaseffekt nicht vollständig verdecken. */
html :is(#itemkontext, #terminkontext, .vis-tooltip) :is(table, tbody, tr, td, th) {
  background: transparent !important;
  color: var(--ink) !important;
}
html #itemkontext :is(#Hauptadresse, #Lieferadresse, #Kontaktadresse, #Auftragstext) {
  background: var(--glass-field) !important;
  color: var(--ink) !important;
  border-color: var(--glass-edge);
}

/* Fließtext und Zeitvorschau folgen dem Theme, unabhängig von älteren Einzelfarben. */
html :is(.tour-card, .demo-interest, .notification, .placement-preview,
  .week-move-preview, #loadstatus) :is(h2, strong, span, small, p) {
  color: var(--ink) !important;
}
html :is(.tour-card, .demo-interest) p { color: var(--muted) !important; }
html :is(#terminkontext, #itemkontext) .kontextbtn,
html .action-popover button {
  background: var(--glass-field) !important;
  color: var(--ink) !important;
  border: 1px solid var(--glass-edge);
  border-radius: 7px;
}
html :is(#terminkontext, #itemkontext) .kontextbtn:hover,
html .action-popover button:hover { background: var(--soft-red) !important; }
html :is(.notification-close, .tour-close) { color: var(--ink) !important; }

/* Ohne Unschärfe-Unterstützung bleibt eine vollständig deckende, lesbare Fläche. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  html :is(#terminkontext, #itemkontext, #loadstatus, .tour-card, .demo-interest,
    .notification, .action-popover, .vis-tooltip, .placement-preview, .week-move-preview) {
    background: var(--surface) !important;
  }
}
/* Betriebssysteme können Transparenz reduzieren oder eigene Kontrastfarben vorgeben. */
@media (prefers-reduced-transparency: reduce) {
  html :is(#terminkontext, #itemkontext, #loadstatus, .tour-card, .demo-interest,
    .notification, .action-popover, .vis-tooltip, .placement-preview, .week-move-preview) {
    background: var(--surface) !important;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
@media (forced-colors: active) {
  html :is(#terminkontext, #itemkontext, #loadstatus, .tour-card, .demo-interest,
    .notification, .action-popover, .vis-tooltip, .placement-preview, .week-move-preview) {
    background: Canvas !important; color: CanvasText !important;
    border-color: CanvasText !important; box-shadow: none !important;
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
}
/* Kompakte Informationsfenster statt der historischen Tabellen- und Sprechblasenlayouts. */
html #terminkontext.popup-panel, html #itemkontext.popup-panel {
  display: none; visibility: hidden; position: fixed;
  width: 370px; min-width: 0; height: auto;
  max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px);
  padding: 0; margin: 0; overflow: auto;
  font: 13px/1.5 "Segoe UI", Arial, sans-serif;
  z-index: 5000;
}
html #itemkontext.popup-panel { width: 490px; }
/* Header und Schließen bleiben auch bei längeren Auftragsdaten eindeutig. */
.popup-panel .popup-header {
  display: flex; gap: 12px; align-items: flex-start; justify-content: space-between;
  padding: 18px; border-bottom: 1px solid var(--glass-edge);
}
.popup-header > div { min-width: 0; }
.popup-header small { font-size: 10px; letter-spacing: 1.2px; font-weight: 700; color: var(--muted); }
html #content .popup-panel h2 { font-size: 17px; line-height: 1.35; margin: 5px 0; color: var(--ink); overflow-wrap: anywhere; }
.popup-header p { margin: 5px 0 0; font-size: 12px; color: var(--muted); }
.popup-reference { display: inline-block; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
html .popup-panel .popup-close {
  flex: 0 0 32px; width: 32px; height: 32px; min-height: 32px;
  padding: 0; margin: -5px -5px 0 0; border: 1px solid transparent;
  border-radius: 8px; color: var(--ink); background: transparent; font-size: 24px; cursor: pointer;
}
.popup-close:hover { background: var(--glass-field) !important; }
/* Abschnitte und Felder bilden eine klare Lesereihenfolge, auch auf kleinen Bildschirmen. */
.popup-panel .popup-section { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.popup-panel .popup-section:last-child { border-bottom: 0; }
html .popup-panel h3 { font: 700 13px/1.4 "Segoe UI", Arial, sans-serif; margin: 0 0 10px; color: var(--ink); }
.popup-quick-actions, .popup-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
html .popup-panel label { display: grid; gap: 5px; font-size: 12px; color: var(--muted); }
html .popup-panel input, html .popup-panel select {
  width: 100%; min-width: 0; height: 36px; padding: 6px 9px;
  border: 1px solid var(--glass-edge); border-radius: 7px;
  font: 13px "Segoe UI", Arial, sans-serif; background: var(--field); color: var(--ink);
}
.popup-panel option { background: var(--field); color: var(--ink); }
html .popup-panel .kontextbtn {
  width: 100%; min-width: 0; min-height: 36px; height: auto;
  padding: 7px 9px; margin: 0; font: 600 12px/1.4 "Segoe UI", Arial, sans-serif;
}
.popup-section > .kontextbtn { margin-top: 10px !important; }
html #terminkontext .popup-primary { color: white !important; background: #c00017 !important; border-color: #c00017; }
/* Adressblöcke dürfen umbrechen, ohne das Fenster über den Rand zu drücken. */
.popup-addresses { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
html #itemkontext :is(#Hauptadresse, #Lieferadresse, #Kontaktadresse, #Auftragstext) {
  display: block; width: auto; min-width: 0; height: auto; padding: 0;
  border: 0; background: transparent !important; color: var(--ink);
  font: 13px/1.6 "Segoe UI", Arial, sans-serif; overflow-wrap: anywhere;
}
/* Echter Info-Button mit Tastaturfokus; die umgebende Karte bleibt weiterhin ziehbar. */
html .items .iteminfobtn {
  display: inline-flex; flex: 0 0 24px; align-items: center; justify-content: center;
  width: 24px; height: 24px; min-height: 24px; padding: 0; margin: 0;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); color: var(--ink); font: 700 14px/1 Georgia, serif; cursor: pointer;
}
html .items .iteminfobtn:hover { color: var(--brand); background: var(--soft-red); }
/* SVG-Farbabbildung tauscht ausschließlich im hellen Theme Rot und Weiß im Titel-Logo. */
html:not([data-theme="dark"]) #header .headerlogo { filter: url("#bpl-logo-light-swap"); }
html[data-theme="dark"] #header .headerlogo { filter: none; }
@media (max-width: 520px) {
  .popup-addresses { grid-template-columns: 1fr; }
  .popup-panel .popup-header, .popup-panel .popup-section { padding: 12px 14px; }
}
/* Alte ID-Regeln dürfen Datum, Uhrzeit und Teamauswahl nicht über das Fenster hinaus verbreitern. */
html #terminkontext :is(#moveDate, #moveTime, #selectTeam) {
  box-sizing: border-box; width: 100%; min-width: 0; max-width: 100%;
  margin: 0; font-size: 13px;
}
.popup-fields > label { min-width: 0; width: auto; }
/* Produktwerbung überdeckt keine aktive Bedienhilfe oder Kontextaktion. */
body:has(.tour-card, .popup-panel[style*="display: block"]) .demo-interest {
  visibility: hidden; pointer-events: none;
}

/* Schnelle, weiche Positionswechsel ausschließlich zwischen den Hilfeschritten. */
.tour-card.tour-glide { transition: left 180ms ease-out, top 180ms ease-out; }
.tour-spotlight.tour-glide { transition: left 180ms ease-out, top 180ms ease-out, width 180ms ease-out, height 180ms ease-out; }
.tour-card > p { white-space: pre-line; }
@media (prefers-reduced-motion: reduce) {
  .tour-card.tour-glide, .tour-spotlight.tour-glide { transition: none; }
}
/* Kompaktes Terminmenü nach dem ursprünglichen Dreispalten-Prinzip. */
html #terminkontext.popup-panel { width: 290px; overflow-x: hidden; }
#terminkontext .popup-header { padding: 9px 12px; gap: 7px; }
#terminkontext .popup-header small { display: none; }
html #content #terminkontext h2 { font-size: 13px; margin: 0; line-height: 1.35; }
#terminkontext .popup-header p { font-size: 11px; margin-top: 3px; }
#terminkontext .popup-section { padding: 8px 12px; }
html #terminkontext h3 { font-size: 12px; margin-bottom: 6px; }
#terminkontext .popup-quick-actions { grid-template-columns: 32px minmax(0,1fr) 32px; gap: 4px 8px; align-items: center; text-align: center; }
html #terminkontext .kontextbtn { min-height: 28px; padding: 4px 7px; font-size: 12px; }
html #terminkontext :is(#moveDate,#moveTime,#selectTeam) { height: 30px; padding: 4px 6px; font-size: 12px; }
#terminkontext .popup-fields { gap: 6px; }
#terminkontext .popup-section > .kontextbtn { margin-top: 6px !important; }
html #terminkontext .popup-close { width: 26px; height: 26px; min-height: 26px; flex-basis: 26px; font-size: 20px; }
@media (pointer: coarse) {
  html #terminkontext .kontextbtn { min-height: 36px; }
}
/* Isolierte Übung: eigene Karte und Zielmarkierung liegen über der Abblendung. */
.practice-source {
  position: fixed; z-index: 6003; padding: 14px; border: 2px solid #ff788b;
  border-radius: 10px; background: var(--surface); color: var(--ink);
  font: 600 13px/1.5 "Segoe UI",Arial,sans-serif; white-space: pre-line;
  box-shadow: 0 5px 20px #0004; cursor: grab;
}
.practice-target {
  position: fixed; z-index: 6002; pointer-events: none;
  border: 2px dashed #ff788b; border-radius: 8px; background: #ff788b25;
  color: var(--ink); text-align: center; font: 700 13px/1.5 "Segoe UI",Arial,sans-serif;
}
html #visualization .vis-item.tutorial-event {
  background: #c00017 !important; border: 2px solid #ff8798 !important; color: white !important;
}
.tutorial-event .vis-item-content { color: white !important; }
.tutorial-event .vis-drag-left, .tutorial-event .vis-drag-right { width: 14px !important; }
.practice-edge-start .vis-drag-left, .practice-edge-end .vis-drag-right {
  background: #ffda68aa; border: 2px solid #ffda68; border-radius: 4px;
}
.practice-feedback { padding: 8px; border-radius: 7px; background: var(--field); font-size: 12px; }
.practice-feedback.practice-success { border-left: 3px solid #36875d; }
.practice-alternative, .practice-skip { margin: 0 0 8px; font: 12px/1.4 "Segoe UI",Arial,sans-serif; }
.practice-source[hidden], .practice-target[hidden], .practice-alternative[hidden],
.practice-skip[hidden], .practice-feedback[hidden] { display: none !important; }
/* Die Karten schweben nur wenige Pixel über ihrer vorhandenen Zielposition. */
@keyframes sidebar-arrival {
  0% { transform: translateY(-13px); opacity: 0; }
  75% { transform: translateY(2px); opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}
.items-panel li.sidebar-arrival {
  animation: sidebar-arrival 330ms cubic-bezier(.2,.8,.25,1) var(--arrival-delay,0ms) both;
}
@media (prefers-reduced-motion: reduce) {
  .items-panel li.sidebar-arrival { animation: none; }
}
/* Übungsalternativen passen zur übrigen Hilfe statt zur Browser-Standarddarstellung. */
.tour-card button.practice-alternative, .tour-card button.practice-skip {
  display: block; width: 100%; padding: 7px 9px;
  border: 1px solid var(--glass-edge); border-radius: 7px;
  background: var(--glass-field); color: var(--ink); cursor: pointer;
}
/* Übungsauftrag übernimmt die kompakte Lesereihenfolge der echten Sidebar-Karten. */
.practice-source { box-sizing: border-box; padding: 10px; border-left: 3px solid #c00017; border-radius: 9px; white-space: normal; }
.practice-source strong { display: block; font: 700 12px/1.4 "Segoe UI",Arial,sans-serif; }
.practice-source span { display: block; margin-top: 3px; font: 11px/1.4 "Segoe UI",Arial,sans-serif; }
.practice-source small { display: block; margin-top: 7px; color: var(--muted); font: 10px/1.4 "Segoe UI",Arial,sans-serif; }
/* Ziehen beginnt am Kartencontainer, nicht an einer Textauswahl seiner Beschriftung. */
.practice-source { user-select: none; -webkit-user-select: none; }
.practice-source > * { pointer-events: none; }
