/* Tablet und Handy (ab 0.11.0).
   Drei Stufen nach Fensterbreite – unabhängig davon, ob mit Maus oder Finger bedient wird:
     bis 1100 px  die Ebenenliste wird zur Schublade (Knopf ▤ in der Kopfzeile)
     bis  900 px  Kopfzeile ohne Schriftzug, „Projekt importieren“ wandert ins Menü
     Hochformat bis 900 px oder Breite bis 640 px: die Fotoansicht wird zum Blatt, das von unten hochgezogen wird
     bis  640 px  Handy: knappe Kopfzeile, Werkzeuge als Symbolleiste
   Größere Schaltflächen gibt es überall dort, wo der Finger das Hauptzeigegerät ist (pointer: coarse).
   Dieselben Bedingungen stehen in js/mobil.js (MQ) – bei Änderungen beide Stellen anpassen. */

#btn-ebenen, .nur-schmal, .nur-handy, .blatt-knopf, .schleier, .fortschritt-linie { display: none; }

/* ---------- gilt immer */
html, body { overscroll-behavior: none; }
body { touch-action: pan-x pan-y; -webkit-tap-highlight-color: transparent; }   /* kein Zoomen der ganzen Seite mit zwei Fingern */
#viewport, #bt-canvas { touch-action: none; }
#viewport { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
dialog { max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow: auto; }
.lade { width: min(360px, calc(100% - 32px)); }
.hinweis { max-width: calc(100% - 24px); text-align: center; }
.topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
.wz-s { margin-right: .4em; }
.menu-pop button:disabled { opacity: .45; cursor: default; }
.menu-info { padding: 8px 10px; color: #cfe7b0; font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

/* Knöpfe über dem Modell: ganze Ansicht; Messung abschließen */
.ansicht-knoepfe { position: absolute; right: 12px; top: 12px; z-index: 5; display: flex; flex-direction: column; gap: 6px; }
.ansicht-knoepfe .btn { width: 36px; height: 36px; padding: 0; font-size: 17px; background: #1d2024e6; }
.mess-aktionen { position: absolute; left: 50%; bottom: 66px; transform: translateX(-50%); z-index: 5; display: flex; gap: 6px; padding: 4px;
  background: #1d2024f2; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 22px #0009; max-width: calc(100% - 16px); }

/* Lupe: erscheint, wenn ein Finger im Modell liegen bleibt – der Messpunkt sitzt unter dem Fadenkreuz */
.lupe { position: absolute; left: 0; top: 0; width: 150px; height: 150px; border-radius: 50%; border: 2px solid var(--accent);
  box-shadow: 0 6px 24px #000c; pointer-events: none; z-index: 8; background: #16191d; }

/* ---------- Fingerbedienung: größere Ziele */
@media (pointer: coarse) {
  html, body { font-size: 15px; }
  .small { font-size: 13px; }
  .btn { padding: 9px 14px; min-height: 42px; }
  .btn.sm { padding: 6px 12px; min-height: 38px; }
  .topbar .btn { padding: 6px 12px; min-height: 38px; }
  #links details > summary, .ebene-zeile, .stand-kopf { min-height: 44px; }
  #links input[type=checkbox], .row input[type=checkbox] { width: 22px; height: 22px; }
  .eintrag { padding: 9px 8px; }
  .eintrag .x { padding: 8px 10px; font-size: 16px; }
  .ebene-zeile .e-weg { padding: 10px; font-size: 16px; }
  .menu-pop a, .menu-pop button { padding: 12px 14px; }
  /* 16 px: darunter vergrößert Safari die Seite beim Antippen eines Eingabefelds */
  dialog input, dialog select, dialog textarea, .login-box input, #projektwahl { font-size: 16px; }
  dialog input, dialog select, dialog textarea { padding: 10px 11px; }
  input[type=range] { min-height: 30px; }
  .werkzeugleiste .tool { padding: 11px 14px; }
  .ansicht-knoepfe .btn { width: 44px; height: 44px; }
  .lbl.befund, .lbl.kp { padding: 6px 10px; font-size: 13px; }
  .bt-kopf .btn.sm { min-width: 42px; }
  .kachel .cap { font-size: 12px; }
  .aw-eintrag { padding: 10px 8px; }
  .teiler::after { left: 5px; width: 4px; height: 48px; margin-top: -24px; }
}
@media (pointer: coarse) and (min-width: 1101px) {
  .layout { grid-template-columns: 290px minmax(0, 1fr) 14px var(--rechts, 380px); }
}
/* ohne Mauszeiger gibt es kein „Darüberfahren“: Löschen und Bearbeiten immer zeigen */
@media (hover: none) {
  .eintrag .x { opacity: 1; }
  .ebene-zeile .e-weg { visibility: visible; }
}

/* ---------- bis 1100 px: Ebenenliste als Schublade */
@media (max-width: 1100px) {
  #btn-ebenen { display: inline-flex; align-items: center; justify-content: center; font-size: 17px; min-width: 38px; padding: 4px 8px; }
  body.ebenen-auf #btn-ebenen { border-color: var(--accent); color: var(--accent); }
  .layout { grid-template-columns: minmax(0, 1fr) 6px var(--rechts, 340px); }
  .panel.left { position: fixed; top: 48px; bottom: 0; left: 0; width: min(330px, 88vw); z-index: 30; border-right: 1px solid var(--line);
    transform: translateX(-104%); visibility: hidden; transition: transform .18s ease, visibility 0s .18s;
    box-shadow: 8px 0 30px #000a; padding-bottom: env(safe-area-inset-bottom); }
  body.ebenen-auf .panel.left { transform: none; visibility: visible; transition: transform .18s ease; }
  .schleier { position: fixed; inset: 48px 0 0 0; z-index: 29; background: #0007; }
  body.ebenen-auf .schleier { display: block; }
  .gast-hinweis { max-width: 30vw; }
}
@media (max-width: 1100px) and (pointer: coarse) {
  .layout { grid-template-columns: minmax(0, 1fr) 14px var(--rechts, 340px); }
}

/* ---------- bis 900 px: knappere Kopfzeile */
@media (max-width: 900px) {
  #version, .brand.mit-logo .brand-text, .brand-text small, #btn-import { display: none; }
  .nur-schmal { display: block; }
  .layout { grid-template-columns: minmax(0, 1fr) 6px var(--rechts, 300px); }
}
@media (max-width: 900px) and (pointer: coarse) {
  .layout { grid-template-columns: minmax(0, 1fr) 14px var(--rechts, 300px); }
}

/* ---------- Hochformat oder Handy: Fotoansicht als Blatt von unten (zu · halb · voll, siehe js/mobil.js) */
@media (max-width: 900px) and (orientation: portrait), (max-width: 640px) {
  .statusbar { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); bottom: calc(46px + env(safe-area-inset-bottom)); }
  body.fotos-halb .layout, body.fotos-voll .layout { bottom: 46vh; bottom: 46dvh; }
  .teiler { display: none; }
  .panel.right { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(46px + env(safe-area-inset-bottom));
    border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: 0 -8px 30px #0008;
    transition: height .2s ease; padding-bottom: env(safe-area-inset-bottom); }
  body.fotos-halb .panel.right { height: 46vh; height: 46dvh; }
  body.fotos-voll .panel.right { height: calc(100vh - 48px); height: calc(100dvh - 48px); }
  .fotos-kopf { padding: 0 12px 8px; }
  #fotos-griff { position: relative; height: 46px; margin: 0; padding-top: 8px; cursor: grab; touch-action: none; -webkit-user-select: none; user-select: none; }
  #fotos-griff::before { content: ""; position: absolute; left: 50%; top: 6px; width: 44px; height: 4px; margin-left: -22px; border-radius: 2px; background: #5b636d; }
  .blatt-knopf { display: inline-flex; align-items: center; }
  #btn-fotofenster { display: none; }
  .fortschritt-linie { display: block; position: absolute; left: 0; right: 0; top: 0; height: 3px; z-index: 6; background: #ffffff14; }
  .fortschritt-linie span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
  .toast { bottom: calc(62px + env(safe-area-inset-bottom)); max-width: 92vw; }
  .werkzeugleiste { bottom: 10px; }
  .mess-aktionen { bottom: 72px; }
}

/* ---------- bis 640 px: Handy */
@media (max-width: 640px) {
  .topbar { gap: 6px; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .kopf-trenner, #btn-bericht, #btn-teilen, .gast-hinweis, .topbar .spacer { display: none; }
  .nur-handy { display: block; }
  .firmenlogo { height: 28px; max-width: 84px; padding: 2px 4px; margin-right: 0; }
  #projektwahl, .projekt-titel { flex: 1 1 0; min-width: 0; max-width: none; font-size: 14px; }
  .werkzeugleiste { left: 8px; right: 8px; transform: none; max-width: none; }
  .werkzeugleiste .tool { display: flex; flex-direction: column; align-items: center; gap: 1px; flex: 1 1 0; min-width: 0; padding: 6px 2px; font-size: 10.5px; }
  .wz-s { margin: 0; font-size: 17px; line-height: 1.15; }
  .wz-trenner { margin: 6px 1px; }
  .ansicht-knoepfe { right: 8px; top: 8px; }
  .hinweis { max-width: calc(100% - 124px); } /* mittig, ohne den Knopf rechts oben zu verdecken */
  .zwei { grid-template-columns: 1fr; gap: 0; }
  dialog { width: calc(100vw - 16px); padding: 14px; }
  dialog menu { flex-wrap: wrap; }
  .pfadwahl { flex-wrap: wrap; }
  .bt-kopf { flex-wrap: wrap; gap: 6px; padding: 6px 8px; justify-content: space-between; }
  .bt-kopf .spacer { display: none; }
  #bt-titel { flex: 1 1 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
  .start-box { min-width: 0; width: 92vw; padding: 22px 18px 16px; }
  .start-logo { height: 96px !important; max-width: 70vw !important; }
  .start-titel { font-size: 26px; }
  .start-unter { font-size: 15px; }
}
