/* Spielwelt: 3D-Stadt bildschirmfüllend, Bedienelemente als schwebende Glasflächen */
body.world-on { overflow: hidden; }
#app.world-mode { padding: 0; height: calc(100vh - var(--bar-h)); height: calc(100dvh - var(--bar-h)); position: relative; }
.world { position: absolute; inset: 0; overflow: hidden; background: #eef1f5; }
.w-stage { position: absolute; inset: 0; z-index: 0; }
.w-canvas, .w-canvas canvas { position: absolute; inset: 0; display: block; touch-action: none; outline: none; }
.w-canvas canvas { cursor: grab; }
.w-canvas canvas:active { cursor: grabbing; }

/* Glas wie in macOS / iOS */
.glass {
  background: rgba(255, 255, 255, .78);
  -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
  border-radius: 20px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, .09), 0 0 0 .5px rgba(0, 0, 0, .07);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .glass { background: rgba(255, 255, 255, .95); } }

/* ---------- Beschriftungen in der Welt ---------- */
.w-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.w-tag {
  position: absolute; left: 0; top: 0; pointer-events: auto; appearance: none; border: 0; font: inherit; color: var(--ink);
  display: flex; align-items: center; gap: 7px; white-space: nowrap; cursor: pointer;
  background: rgba(255, 255, 255, .9); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-radius: 13px; padding: 6px 10px; margin-top: -8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .06);
  transition: opacity .25s var(--ease), box-shadow .2s;
  will-change: transform;
}
.w-tag::after {
  content: ''; position: absolute; left: 50%; bottom: -5px; width: 10px; height: 10px; margin-left: -5px;
  background: inherit; transform: rotate(45deg); border-radius: 2px; box-shadow: 2px 2px 3px rgba(0, 0, 0, .05);
  -webkit-backdrop-filter: none; backdrop-filter: none;
}
.w-tag:hover { box-shadow: 0 8px 24px rgba(0, 0, 0, .16), 0 0 0 .5px rgba(0, 0, 0, .08); }
.w-tag .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.w-tag .t { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.w-tag b { font-size: .84rem; font-weight: 600; letter-spacing: -.01em; }
.w-tag small { font-size: .72rem; color: var(--muted); }
.w-tag i { font-style: normal; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; font-weight: 700; flex: none; }
.w-tag i.ok { background: var(--green); color: #fff; }
.w-tag i.wait { background: #e5e5ea; color: var(--muted); }
.w-tag.station.me { background: #1d1d1f; color: #fff; }
.w-tag.station.me small { color: rgba(255, 255, 255, .7); }
.w-tag.zone { flex-direction: column; gap: 0; padding: 6px 12px 7px; line-height: 1.1; }
.w-tag.zone small { font-size: .7rem; font-weight: 500; }
.w-tag.zone b { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.w-tag.zone.bad b { color: var(--red-ink); }
.w-tag.zone.soft b { font-size: 1.05rem; }
.w-tag.pipe { padding: 4px 9px; gap: 6px; }
.w-tag.pipe b { font-size: .95rem; font-variant-numeric: tabular-nums; }
.w-tag.note { flex-direction: column; gap: 0; line-height: 1.1; padding: 6px 11px; }
.w-tag.note b { color: var(--blue-ink); font-size: 1.05rem; }
.w-tag .sh { display: none; }
.w-labels.far .w-tag.station { padding: 4px 8px; gap: 5px; }
.w-labels.far .w-tag.station small { display: none; }
.w-labels.far .w-tag.station b { font-size: .76rem; }
.w-labels.far .w-tag i { width: 15px; height: 15px; font-size: 9px; }
.w-labels.far .w-tag.note small, .w-labels.far .w-tag.pipe small { display: none; }
.w-labels.tiny .w-tag.station .nm { display: none; }
.w-labels.tiny .w-tag.station .sh { display: block; }
.w-labels.tiny .w-tag.station { padding: 3px 7px; border-radius: 10px; }

/* ---------- Bedienelemente (HUD) ---------- */
.hud { position: absolute; inset: 0; z-index: 1; pointer-events: none; --hud-gap: clamp(10px, 1.2vw, 18px); }
.hud > * { pointer-events: auto; }
.hud-tl { position: absolute; left: var(--hud-gap); top: var(--hud-gap); width: clamp(250px, 21vw, 320px); display: flex; flex-direction: column; gap: 10px; pointer-events: none; max-height: calc(100% - 2 * var(--hud-gap)); }
.hud-tl > * { pointer-events: auto; }
.hud-tr { position: absolute; right: var(--hud-gap); top: var(--hud-gap); display: flex; gap: 8px; align-items: center; }
.hud-br { position: absolute; right: var(--hud-gap); bottom: var(--hud-gap); width: clamp(290px, 23vw, 350px); display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.hud-br > * { pointer-events: auto; }
.hud-msgs { position: absolute; left: 50%; top: var(--hud-gap); transform: translateX(-50%); width: min(520px, calc(100% - 2 * var(--hud-gap))); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.hud-msgs:empty { display: none; }
.hud-msgs .banner { pointer-events: auto; background: rgba(255, 255, 255, .82); -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px); box-shadow: 0 10px 34px rgba(0, 0, 0, .09), 0 0 0 .5px rgba(0, 0, 0, .07); }

/* Woche */
.hud-week { padding: 14px 16px 13px; }
.hud-week .top { display: flex; align-items: baseline; gap: 10px; }
.hud-week h2 { font-size: 1.65rem; letter-spacing: -.028em; font-weight: 700; flex: 1; }
.hud-week .cost { font-size: .82rem; color: var(--muted); text-align: right; line-height: 1.2; }
.hud-week .cost b { display: block; font-size: 1rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.hud-week .status { display: flex; gap: 9px; align-items: flex-start; margin-top: 9px; font-size: .86rem; color: var(--ink-2); line-height: 1.35; }
.hud-week .status .lamp { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--muted-2); box-shadow: 0 0 0 3px rgba(0, 0, 0, .04); }
.hud-week .status.red .lamp { background: var(--red); }
.hud-week .status.yellow .lamp { background: #ffcc00; }
.hud-week .status.green .lamp { background: var(--green); }

/* Kennzahlen */
.hud-kpis { padding: 6px; display: flex; flex-direction: column; overflow: auto; }
.hk {
  appearance: none; border: 0; background: none; font: inherit; color: var(--ink); cursor: pointer; text-align: left;
  display: grid; grid-template-columns: 22px 1fr auto auto; gap: 9px; align-items: center; padding: 8px 10px; border-radius: 12px;
  transition: background .15s;
}
.hk:hover { background: rgba(120, 120, 128, .1); }
.hk svg { width: 18px; height: 18px; color: var(--c-ink); }
.hk .l { font-size: .88rem; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hk .v { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.hk .delta { min-width: 30px; text-align: right; font-size: .78rem; }
.hk.bad .v { color: var(--red-ink); }

/* Team */
.hud-team { padding: 11px 14px; display: flex; align-items: center; gap: 12px; }
.hud-team .avs { display: flex; }
.hud-team .av { position: relative; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: .66rem; font-weight: 600; color: #fff; background: var(--c); box-shadow: 0 0 0 2px #fff; margin-left: -4px; }
.hud-team .av:first-child { margin-left: 0; }
.hud-team .av.empty { background: #e5e5ea; color: var(--muted); }
.hud-team .av.me { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); z-index: 1; }
.hud-team .av .chk { position: absolute; right: -3px; bottom: -3px; width: 14px; height: 14px; border-radius: 50%; background: var(--green); color: #fff; font-size: 8px; display: grid; place-items: center; box-shadow: 0 0 0 1.5px #fff; }
.hud-team .txt { font-size: .84rem; color: var(--ink-2); line-height: 1.25; }
.hud-team .txt b { display: block; color: var(--ink); font-weight: 600; }

/* Bestellung */
.hud-order { padding: 16px; }
.hud-order header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.hud-order header h3 { flex: 1; }
.hud-order header small { color: var(--muted); }
.hud-order .stepper input { background: transparent; }
.hud-order .quick { flex-wrap: nowrap; gap: 5px; }
.hud-order .quick .btn { background: rgba(120, 120, 128, .12); padding: 5px 10px; flex: none; }

#orderSubmit .short { display: none; }

/* Ansicht wählen */
.glass-seg { background: rgba(255, 255, 255, .7); -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px); box-shadow: 0 6px 20px rgba(0, 0, 0, .08), 0 0 0 .5px rgba(0, 0, 0, .07); border-radius: 11px; padding: 3px; }
.glass-seg button { padding: 6px 14px; }
.glass-btn { background: rgba(255, 255, 255, .7); -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px); box-shadow: 0 6px 20px rgba(0, 0, 0, .08), 0 0 0 .5px rgba(0, 0, 0, .07); border-radius: 11px; font-size: .86rem; }
.glass-btn:hover { background: rgba(255, 255, 255, .92); }

/* Info-Blase nach Klick auf Lastwagen / Gebäude */
.hud-pop { position: absolute; left: 50%; bottom: calc(var(--hud-gap) + 8px); transform: translateX(-50%); padding: 12px 16px; font-size: .9rem; max-width: min(420px, calc(100% - 32px)); text-align: center; line-height: 1.4; animation: hud-pop .35s var(--spring); }
@keyframes hud-pop { from { opacity: 0; transform: translate(-50%, 8px); } }
.hud-pop b { font-weight: 600; }
.hud-hint { position: absolute; left: 50%; bottom: calc(var(--hud-gap) + 8px); transform: translateX(-50%); padding: 9px 16px; border-radius: 99px; font-size: .84rem; color: #fff; background: rgba(29, 29, 31, .78); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); white-space: nowrap; transition: opacity .6s; pointer-events: none; }
.hud-hint.gone { opacity: 0; }

/* Woche wechselt: Zahlen leuchten kurz auf */
.hud-week.tick h2 { animation: bump .6s var(--spring); }

/* ---------- MIS: Datenauswertung anstelle der Stadt ---------- */
.hud-mis {
  display: none; position: absolute; left: var(--hud-gap); top: var(--hud-gap); bottom: var(--hud-gap);
  right: calc(clamp(290px, 23vw, 350px) + 2 * var(--hud-gap));
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; scrollbar-width: thin;
  container: mis / inline-size; border-radius: var(--radius);
}
.world.mis-on .hud-mis { display: block; }
.world.mis-on { background: var(--bg); }
.world.mis-on .w-stage, .world.mis-on .hud-tl, .world.mis-on .hud-msgs, .world.mis-on .hud-pop, .world.mis-on .hud-hint { display: none; }

/* Übergang Stadt → MIS: Stadt zoomt unscharf weg, Karten steigen gestaffelt auf */
.world.to-mis .w-stage { display: block; animation: city-out .5s var(--ease) forwards; will-change: opacity, transform, filter; }
.world.to-mis .hud-tl { display: flex; animation: hud-out .3s var(--ease) forwards; pointer-events: none; }
.world.to-mis .hud-msgs { display: flex; animation: fade-out .3s var(--ease) forwards; pointer-events: none; }
.world.to-mis .mis > * { animation: mis-in .6s var(--spring) both; animation-delay: calc(var(--i, 0) * 50ms + 90ms); }
.world.to-mis .mis > #gKpis { animation: none; }
.world.to-mis #gKpis > .kpi { animation: mis-in .6s var(--spring) both; animation-delay: calc(var(--k, 0) * 40ms + 200ms); }
.mis > :nth-child(2) { --i: 1; } .mis > :nth-child(3) { --i: 2; } .mis > :nth-child(4) { --i: 3; }
.mis > :nth-child(5) { --i: 4; } .mis > :nth-child(6) { --i: 5; } .mis > :nth-child(7) { --i: 6; } .mis > :nth-child(8) { --i: 7; }
#gKpis > :nth-child(2) { --k: 1; } #gKpis > :nth-child(3) { --k: 2; } #gKpis > :nth-child(4) { --k: 3; } #gKpis > :nth-child(5) { --k: 4; } #gKpis > :nth-child(6) { --k: 5; }
/* Übergang MIS → Stadt: Auswertung sinkt weg, Stadt wird wieder scharf */
.world.from-mis .hud-mis { display: block; animation: mis-out .32s var(--ease) forwards; pointer-events: none; }
.world.from-mis .w-stage { animation: city-in .7s var(--spring) both; will-change: opacity, transform, filter; }
.world.from-mis .hud-tl { animation: hud-in .55s var(--spring) both .18s; }
@keyframes city-out { to { opacity: 0; transform: scale(1.06); filter: blur(10px) saturate(.6); } }
@keyframes city-in { from { opacity: 0; transform: scale(1.06); filter: blur(10px) saturate(.6); } }
@keyframes hud-out { to { opacity: 0; transform: translateY(-12px); } }
@keyframes hud-in { from { opacity: 0; transform: translateY(-12px); } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes mis-in { from { opacity: 0; transform: translateY(28px) scale(.97); } }
@keyframes mis-out { to { opacity: 0; transform: translateY(20px) scale(.985); } }
.world.no3d .hud-tr { display: none; }
.mis { display: flex; flex-direction: column; gap: 14px; }
.mis #gEvents:empty, .mis #gAmpel:empty { display: none; }
.mis-eyebrow { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: .8rem; font-weight: 600; color: var(--blue-ink); }
.mis-eyebrow svg { width: 15px; height: 15px; }
.mis #gKpis { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@container mis (min-width: 1100px) { .mis #gKpis { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@container mis (max-width: 640px) { .mis #gKpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.mis-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); gap: 14px; }
.mis-chart > header { flex-direction: column; align-items: flex-start; gap: 2px; }
.mis-title { appearance: none; border: 0; background: none; font: inherit; padding: 0; color: var(--c-ink, var(--ink)); display: inline-flex; align-items: center; gap: 7px; cursor: pointer; text-align: left; }
.mis-title svg { width: 17px; height: 17px; flex: none; }
.mis-title h3 { color: var(--ink); }
.mis-title svg:last-child { width: 15px; height: 15px; color: #c7c7cc; transition: transform .3s var(--spring), color .2s; }
.mis-title:hover svg:last-child { color: var(--muted); transform: translateX(2px); }
.hud-mis .mis-stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 0; border: 0; }
.hud-mis .mis-stats .stat { padding: 11px 13px; border: 0; border-radius: 12px; background: var(--fill-2); }
.hud-mis .mis-stats .stat b { font-size: 1.3rem; }
.hud-mis .mis-stats .stat > small { display: block; margin-top: 3px; font-size: .74rem; line-height: 1.3; color: var(--muted); }
#gHistCard > header .btn svg { width: 15px; height: 15px; }

/* ---------- Schmale Bildschirme (Handy hochkant, Tablet hochkant) ---------- */
@media (max-width: 999px) and (min-height: 561px) {
  .hud { --hud-gap: 10px; }
  .hud-tl { left: var(--hud-gap); right: var(--hud-gap); width: auto; gap: 6px; }
  .hud-week { padding: 9px 14px 8px; border-radius: 18px; }
  .hud-week h2 { font-size: 1.2rem; }
  .hud-week .cost { display: flex; gap: 5px; align-items: baseline; font-size: .76rem; }
  .hud-week .cost b { font-size: .92rem; }
  .hud-week .status { margin-top: 3px; font-size: .76rem; gap: 7px; }
  .hud-week .status span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .hud-week .status .lamp { margin-top: 4px; width: 8px; height: 8px; }
  .hud-kpis { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 3px; gap: 0; scrollbar-width: none; border-radius: 16px; }
  .hud-kpis::-webkit-scrollbar { display: none; }
  .hk { grid-template-columns: auto; grid-template-rows: auto auto; gap: 0; padding: 5px 10px; flex: 1 0 auto; min-width: 70px; }
  .hk svg { display: none; }
  .hk .l { font-size: .66rem; color: var(--muted); }
  .hk .v { font-size: .98rem; }
  .hk .delta { display: none; }
  /* Nachrichten kompakt unter der Kopfzeile */
  .hud-msgs { top: calc(var(--top-h, 150px) + 6px); width: calc(100% - 2 * var(--hud-gap)); gap: 6px; }
  .hud-msgs .banner { padding: 7px 11px; font-size: .78rem; gap: 8px; border-radius: 12px; }
  .hud-msgs .banner svg { width: 16px; height: 16px; }
  .hud-msgs .banner > div { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

  /* Bottom Sheet: Kopf + Team, Menge + Senden, Schnellwahl */
  .hud-br {
    left: 0; right: 0; bottom: 0; width: auto; gap: 0; padding: 12px 16px calc(10px + env(safe-area-inset-bottom));
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "head team" "step send" "quick quick" "state state";
    column-gap: 12px; align-items: center;
    background: rgba(255, 255, 255, .86); -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
    border-radius: 22px 22px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, .08), 0 0 0 .5px rgba(0, 0, 0, .07);
  }
  .hud-order { display: contents; }
  .hud-order > header { grid-area: head; margin: 0 0 6px; min-width: 0; }
  .hud-order > header h3 { font-size: .98rem; white-space: nowrap; }
  .hud-order > header small { font-size: .76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hud-order .stepper { grid-area: step; grid-template-columns: 40px 1fr 40px; gap: 6px; }
  .hud-order .stepper .btn { width: 40px; height: 40px; font-size: 1.3rem; }
  .hud-order .stepper input { font-size: 1.75rem; padding: 0; height: 44px; }
  .hud-order #orderSubmit { grid-area: send; width: auto; margin: 0 !important; padding: 11px 18px; font-size: .98rem; }
  .hud-order #orderSubmit .long { display: none; }
  .hud-order #orderSubmit .short { display: inline; }
  .hud-order .quick { grid-area: quick; margin-top: 8px; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; scrollbar-width: none; }
  .hud-order .quick::-webkit-scrollbar { display: none; }
  .hud-order .quick .btn { flex: none; padding: 5px 11px; }
  .hud-order .order-state { grid-area: state; margin-top: 6px; text-align: left; }
  .hud-order .order-state > p { display: none; }
  .hud-order .order-state .banner { padding: 7px 12px; font-size: .82rem; gap: 8px; align-items: center; }
  .hud-order .order-state .banner svg { width: 16px; height: 16px; margin: 0; }
  .hud-order .order-state .banner small, .hud-order .order-state .banner br { display: none; }
  .hud-order > h3, .hud-order > p { grid-column: 1 / -1; }
  .hud-team { grid-area: team; background: none; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; padding: 0 0 6px; border-radius: 0; gap: 8px; justify-self: end; }
  .hud-team .txt { display: none; }
  .hud-team .av { width: 26px; height: 26px; font-size: .6rem; }
  .hud-tr { top: auto; bottom: calc(var(--sheet-h, 160px) + 10px); right: var(--hud-gap); }
  .glass-seg button { padding: 5px 12px; font-size: .8rem; }
  .glass-btn { padding: 6px 10px; }
  .hud-pop, .hud-hint { bottom: calc(var(--sheet-h, 160px) + 58px); }
  /* MIS über der Bestellleiste, unter dem Ansichtswechsel */
  .hud-mis { left: 0; right: 0; top: 0; bottom: calc(var(--sheet-h, 160px) + 52px); padding: 10px; border-radius: 0; }
  .world.no3d .hud-mis { bottom: var(--sheet-h, 160px); }
  .mis { gap: 10px; }
  .mis-grid { gap: 10px; }
}
@media (min-width: 640px) and (max-width: 999px) and (min-height: 561px) {
  /* Tablet hochkant: Sheet-Inhalt nicht über die ganze Breite ziehen */
  .hud-br { padding-left: max(16px, calc(50% - 300px)); padding-right: max(16px, calc(50% - 300px)); }
}
/* Sehr niedrige Höhe (Handy quer): schmale Seitenleisten */
@media (max-height: 560px) {
  .hud-tl { width: clamp(200px, 26vw, 260px); }
  .hud-week { padding: 9px 12px; }
  .hud-week h2 { font-size: 1.2rem; }
  .hud-week .status { display: none; }
  .hk { padding: 5px 8px; }
  .hud-br { width: clamp(230px, 30vw, 300px); }
  .hud-team { display: none; }
  .hud-order { padding: 10px 12px; }
  .hud-order .quick, .hud-order .order-state { display: none; }
  .hud-order .stepper .btn { width: 38px; height: 38px; }
  .hud-order .stepper { grid-template-columns: 38px 1fr 38px; }
  .hud-order #orderSubmit { margin-top: 8px !important; padding: 9px 14px; }
  .hud-tr { top: auto; bottom: var(--hud-gap); right: calc(clamp(230px, 30vw, 300px) + 2 * var(--hud-gap)); }
  .hud-mis { right: calc(clamp(230px, 30vw, 300px) + 2 * var(--hud-gap)); bottom: calc(var(--hud-gap) + 46px); }
  .world.no3d .hud-mis { bottom: var(--hud-gap); }
}
