/* ==================================================================
   Aircraft Construction Viewer – Stylesheet
   Ruhige, kontrastreiche Gestaltung; Touch-Flächen ≥ 44 × 44 px
   ================================================================== */

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #1c2530;
  --muted: #5d6a78;
  --line: #d6dde5;
  --accent: #1f5fa8;
  --accent-soft: #e3edf8;
  --bar: rgba(28, 37, 48, 0.78);
  --bar-text: #ffffff;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(20, 30, 45, 0.10);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --panel-w: 380px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body.in-viewer { overflow: hidden; overscroll-behavior: none; }

[hidden] { display: none !important; }

/* ------------------------------------------------------------------
   Ansicht 1: Galerie
   ------------------------------------------------------------------ */
.app-header {
  padding: calc(28px + var(--safe-top)) calc(24px + var(--safe-right)) 8px calc(24px + var(--safe-left));
  max-width: 1200px;
  margin: 0 auto;
}
.app-header h1 { margin: 0 0 4px; font-size: 1.7rem; letter-spacing: -0.01em; }
.app-sub { margin: 0; color: var(--muted); }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px calc(24px + var(--safe-right)) calc(32px + var(--safe-bottom)) calc(24px + var(--safe-left));
}

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.card:hover { box-shadow: 0 6px 18px rgba(20, 30, 45, 0.16); }
.card:active { transform: scale(0.985); }
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.thumb { aspect-ratio: 16 / 10; background: #e4e9ef; }
.thumb img, .thumb svg { display: block; width: 100%; height: 100%; object-fit: cover; }

.card-body { padding: 14px 16px 18px; }
.card-title { margin: 8px 0 2px; font-size: 1.2rem; }
.card-maker { margin: 0; color: var(--muted); font-size: 0.95rem; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
}

/* ------------------------------------------------------------------
   Ansicht 2: Viewer
   ------------------------------------------------------------------ */
.viewer {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  background: #dde3ea;
  overflow: hidden;
}

.canvas-host { position: absolute; inset: 0; }
.canvas-host canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;           /* Gesten gehören dem 3D-Modell */
  -webkit-user-select: none;
  user-select: none;
  outline: none;
}

.toolbar {
  position: absolute;
  top: calc(12px + var(--safe-top));
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 10;
  pointer-events: none;          /* nur die Buttons fangen Eingaben */
}
.toolbar > * { pointer-events: auto; }
.toolbar-left  { left: calc(12px + var(--safe-left)); }
.toolbar-right { right: calc(12px + var(--safe-right)); }

.viewer-title {
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--bar);
  color: var(--bar-text);
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 48px;
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--bar);
  color: var(--bar-text);
  font: inherit;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: background 0.12s ease;
}
.btn:hover { background: rgba(28, 37, 48, 0.9); }
.btn:active { background: rgba(28, 37, 48, 1); }
.btn:focus-visible { outline: 3px solid #8cc0ff; outline-offset: 2px; }
.btn.active { background: var(--accent); }
.btn svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 2.2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* Vollbild-Icon wechseln */
.btn .icon-exit { display: none; }
body.is-fullscreen .btn .icon-enter { display: none; }
body.is-fullscreen .btn .icon-exit { display: inline; }

/* Ladeanzeige */
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(221, 227, 234, 0.85);
  z-index: 20;
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid rgba(31, 95, 168, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.loading-text { font-weight: 600; }
.progress {
  width: min(280px, 70vw);
  height: 6px;
  border-radius: 3px;
  background: rgba(31, 95, 168, 0.15);
  overflow: hidden;
}
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.15s linear; }
.progress-bar.indeterminate { width: 35%; animation: slide 1.1s ease-in-out infinite; }
.loading-pct { font-size: 0.9rem; color: var(--muted); min-height: 1.4em; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(290%); } }

/* Hinweis Vorschau-Geometrie: dezent, unten links */
.hint {
  position: absolute;
  left: calc(12px + var(--safe-left));
  bottom: calc(12px + var(--safe-bottom));
  max-width: min(520px, calc(100% - 24px));
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 248, 225, 0.92);
  border: 1px solid #e6cf85;
  color: #6b5310;
  font-size: 0.85rem;
  z-index: 5;
  pointer-events: none;
}

.error-box {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  max-width: min(460px, calc(100% - 32px));
  padding: 16px 20px;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid #e2a4a4;
  color: #8a1f1f;
  box-shadow: var(--shadow);
  z-index: 15;
}

.gesture-help {
  position: absolute;
  left: 50%;
  bottom: calc(64px + var(--safe-bottom));
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--bar);
  color: var(--bar-text);
  font-size: 0.9rem;
  white-space: nowrap;
  z-index: 6;
  pointer-events: none;
  transition: opacity 0.8s ease;
}
.gesture-help.fade { opacity: 0; }

.toast {
  position: absolute;
  left: 50%;
  top: calc(72px + var(--safe-top));
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 32px));
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--bar);
  color: var(--bar-text);
  font-size: 0.9rem;
  z-index: 30;
}

/* ------------------------------------------------------------------
   Ansicht 3: Details-Panel
   Breit: Seitenpanel rechts · Schmal/Hochformat: Bottom-Sheet
   ------------------------------------------------------------------ */
.panel {
  position: absolute;
  top: calc(72px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  bottom: calc(12px + var(--safe-bottom));
  width: var(--panel-w);
  max-width: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(20, 30, 45, 0.22);
  z-index: 12;
  transform: translateX(calc(100% + 24px));
  visibility: hidden;
  transition: transform 0.25s ease, visibility 0s linear 0.25s;
}
.panel.open {
  transform: none;
  visibility: visible;
  transition: transform 0.25s ease, visibility 0s;
}

.panel-grip { display: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 10px 20px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 1.25rem; }
.btn-icon { padding: 0; background: transparent; color: var(--text); }
.btn-icon:hover, .btn-icon:active { background: var(--accent-soft); }

.panel-body {
  padding: 8px 20px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.panel-body h3 {
  margin: 18px 0 6px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.panel-body p { margin: 0 0 10px; }
.panel-body a { color: var(--accent); }
.muted { color: var(--muted); font-size: 0.92rem; }

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin: 10px 0 0;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

.specs { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.specs th, .specs td { padding: 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.specs th { text-align: left; font-weight: 400; color: var(--muted); padding-right: 12px; }
.specs td { text-align: right; font-weight: 500; white-space: nowrap; }

/* Tablets im Hochformat und Smartphones: Bottom-Sheet */
@media (max-width: 900px) {
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-width: none;
    max-height: 55%;
    border-radius: 18px 18px 0 0;
    padding-bottom: var(--safe-bottom);
    transform: translateY(100%);
  }
  .panel-grip {
    display: block;
    width: 44px; height: 5px;
    margin: 8px auto 0;
    border-radius: 3px;
    background: var(--line);
  }
  .btn-label { display: none; }    /* Platz sparen: nur Icons */
  .btn { padding: 0; }
}

/* Sehr schmale Geräte: Titel ausblenden, damit Buttons nicht kollidieren */
@media (max-width: 480px) {
  .viewer-title { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .card, .gesture-help { transition: none; }
}

.noscript { padding: 24px; text-align: center; }
