/*
 * RouteHome – css/layout.css
 * Pfad: css/layout.css
 * Zweck: Strukturelles Layout der App.
 *        KEINE Farben, KEINE Typografie-Styles.
 *        Ausschließlich: Position, Flex, Grid, Größen, Responsive.
 *
 * Wichtige Layout-Regeln:
 *   Portrait  (Standard)  → Map oben (42dvh), Dashboard unten (flex:1)
 *   Landscape (≥768px)    → Map links (60%), Dashboard rechts (40%)
 */

/* ═══════════════════════════════════════════════════════════════
   1. APP ROOT
   Die gesamte App lebt in einem fixed-Viewport.
   Kein Scroll auf document-Ebene.
═══════════════════════════════════════════════════════════════ */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Safe Area für Notch / Dynamic Island / Home-Bar */
  padding-top:    env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left:   env(safe-area-inset-left);
  padding-right:  env(safe-area-inset-right);
}

/* ── Loading State: Content während Init verbergen ── */
.app--loading .app-header,
.app--loading .view-container,
.app--loading .bottom-nav {
  visibility: hidden;
}

.app--loading .loading-screen {
  display: flex;
}

.app--ready .loading-screen {
  display: none;
}

/* ═══════════════════════════════════════════════════════════════
   2. LOADING SCREEN
═══════════════════════════════════════════════════════════════ */
.loading-screen {
  position: absolute;
  inset: 0;
  z-index: 9999;
  display: none;  /* via .app--loading sichtbar */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-6);
  background: var(--c-bg-base);
  animation: fade-in var(--dur-std) var(--ease-out);
}

.loading-logo {
  width: 72px;
  height: 72px;
  border-radius: var(--r-lg);
  object-fit: cover;
}

.loading-bar {
  width: 120px;
  height: 3px;
  background: var(--c-border-strong);
  border-radius: var(--r-full);
  overflow: hidden;
}

.loading-bar__fill {
  width: 40%;
  height: 100%;
  background: var(--c-blue);
  border-radius: var(--r-full);
  animation: loading-slide 1.2s ease-in-out infinite;
}

@keyframes loading-slide {
  0%   { transform: translateX(-100%); width: 40%; }
  50%  { width: 60%; }
  100% { transform: translateX(300%); width: 40%; }
}

/* ═══════════════════════════════════════════════════════════════
   3. APP HEADER
   Fest oben, volle Breite, 56px hoch.
   Auf sehr kleinen Screens (Landscape ohne Tablet): 50px.
═══════════════════════════════════════════════════════════════ */
.app-header {
  flex-shrink: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-3);
  background: var(--c-bg-surface);
  border-bottom: 1px solid var(--c-border);
  z-index: 100;
  position: relative;
}

/* Dekorativer Akzent-Strich am unteren Rand des Headers */
.app-header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1.5px;
  background: linear-gradient(
    90deg,
    transparent      0%,
    var(--c-blue)   30%,
    var(--c-yellow) 70%,
    transparent     100%
  );
  opacity: 0.5;
  pointer-events: none;
}

.app-header__left,
.app-header__right {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

/* Brand (Logo + Name) */
.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: var(--sp-1);
  text-decoration: none;
}

.brand__logo {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.brand__name {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: 800;
  background: linear-gradient(135deg, #fff 0%, var(--c-yellow) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

/* Sprach-Pill */
.lang-pill {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 0 var(--sp-2);
  height: 34px;
  background: var(--c-bg-elevated);
  border: 1px solid var(--c-border);
  border-radius: var(--r-full);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: border-color var(--dur-fast);
  touch-action: manipulation;
  width: auto;
  min-width: 0;
}

.lang-pill:active  { border-color: var(--c-blue); }

.lang-pill__code {
  font-weight: 700;
  font-size: 0.625rem;
  letter-spacing: 0.06em;
  color: var(--c-text-secondary);
  text-transform: uppercase;
}

/* Theme-Icons: wechseln via JS (data-theme Attribut) */
[data-theme="dark"]  .icon-sun  { display: none; }
[data-theme="dark"]  .icon-moon { display: block; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun  { display: block; }

/* ═══════════════════════════════════════════════════════════════
   4. VIEW CONTAINER
   Nimmt den gesamten Raum zwischen Header und Bottom-Nav ein.
   Enthält alle Views; nur eine ist je aktiv.
═══════════════════════════════════════════════════════════════ */
.view-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

/* ═══════════════════════════════════════════════════════════════
   5. VIEWS
   Jede View füllt den gesamten view-container.
   Standardmäßig unsichtbar, aktive View via .view--active.
═══════════════════════════════════════════════════════════════ */
.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Unsichtbar & nicht interaktiv wenn inaktiv */
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition:
    opacity    var(--dur-std) var(--ease-std),
    visibility var(--dur-std) var(--ease-std);
}

.view--active {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  animation: fade-in var(--dur-std) var(--ease-out);
}

/* Scrollbare Views (Route, Info, Settings) */
.view__scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-4);
  -webkit-overflow-scrolling: touch;
}

/* ═══════════════════════════════════════════════════════════════
   6. SPLITSCREEN  (View: map)
   ┌────────────────────┐  Portrait  (Standard)
   │     MAP  PANEL     │  42dvh
   ├────────────────────┤
   │  DASHBOARD PANEL   │  flex:1
   └────────────────────┘

   ┌──────────────┬──────┐  Landscape, ≥768px
   │              │      │  Map: 60%  | Dashboard: 40%
   │  MAP PANEL   │ DASH │  Volle Höhe
   └──────────────┴──────┘
═══════════════════════════════════════════════════════════════ */
.splitscreen {
  flex: 1;
  display: flex;
  flex-direction: column;   /* Portrait: vertikal */
  overflow: hidden;
  min-height: 0;
}

/* ── MAP PANEL ── */
.map-panel {
  flex-shrink: 0;
  height: var(--map-h-portrait);
  min-height: 200px;
  max-height: 48vh;
  position: relative;
  overflow: hidden;
  background: var(--c-bg-base);
}

.map-canvas {
  width: 100%;
  height: 100%;
  position: relative;
}

/* Map-Platzhalter (Phase 1 – bis Mapbox eingebunden ist) */
.map-placeholder {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #0A1628 0%, #0D1E3A 50%, #0A1628 100%);
}

.map-placeholder__grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(37,99,235,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37,99,235,0.05) 1px, transparent 1px);
  background-size: 40px 40px;
}

.map-placeholder__label {
  position: relative;
  font-size: var(--text-sm);
  color: var(--c-text-muted);
  z-index: 1;
}

/* Karten-Controls (rechts unten auf der Karte) */
.map-controls {
  position: absolute;
  right: var(--sp-3);
  bottom: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  z-index: 10;
}

.map-ctrl-btn {
  width: 36px;
  height: 36px;
  background: rgba(11, 19, 43, 0.85);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  color: var(--c-text-primary);
  font-size: var(--text-md);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background var(--dur-fast);
  touch-action: manipulation;
}

.map-ctrl-btn:active { background: var(--c-bg-card); }

/* Wake-Lock-Badge */
.wakelock-badge {
  position: absolute;
  left: var(--sp-3);
  bottom: var(--sp-3);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px var(--sp-2);
  background: rgba(11, 19, 43, 0.80);
  border: 1px solid rgba(34, 197, 94, 0.30);
  border-radius: var(--r-full);
  z-index: 10;
}

.wakelock-badge__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-green);
  flex-shrink: 0;
  transition: background var(--dur-std);
}

.wakelock-badge.inactive .wakelock-badge__dot {
  background: var(--c-red);
}

.wakelock-badge__label {
  font-size: var(--text-xs);
  color: var(--c-green);
  white-space: nowrap;
  transition: color var(--dur-std);
}

.wakelock-badge.inactive .wakelock-badge__label {
  color: var(--c-red);
}

/* Kinder-Fortschrittsbalken */
.kids-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(11, 19, 43, 0.90);
  border-top: 1px solid var(--c-border-strong);
  padding: var(--sp-2) var(--sp-4);
  z-index: 20;
  transform: translateY(100%);       /* standardmäßig ausgeblendet */
  transition: transform var(--dur-std) var(--ease-out);
}

.kids-bar.kids-bar--visible {
  transform: translateY(0);
}

.kids-bar__inner {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.kids-bar__track {
  flex: 1;
  height: 8px;
  background: var(--c-bg-elevated);
  border-radius: var(--r-full);
  overflow: hidden;
}

.kids-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--c-blue), var(--c-yellow));
  border-radius: var(--r-full);
  width: 0%;
  transition: width 1s linear;
}

.kids-bar__eta {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--c-text-primary);
  white-space: nowrap;
}

/* ── DASHBOARD PANEL ── */
.dashboard-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--c-bg-surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  overflow: hidden;
  min-height: 0;
  position: relative;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}

/* Drag-Handle */
.drag-handle {
  flex-shrink: 0;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.drag-handle:active { cursor: grabbing; }

.drag-handle__pill {
  width: 40px;
  height: 4px;
  background: var(--c-text-muted);
  border-radius: var(--r-full);
  opacity: 0.45;
  transition: width var(--dur-fast), opacity var(--dur-fast);
}

.drag-handle:hover .drag-handle__pill,
.drag-handle:active .drag-handle__pill {
  width: 56px;
  opacity: 0.8;
}

/* ═══════════════════════════════════════════════════════════════
   7. TAB-NAVIGATION (im Dashboard-Panel)
═══════════════════════════════════════════════════════════════ */
.tab-nav {
  flex-shrink: 0;
  display: flex;
  background: var(--c-bg-surface);
  border-bottom: 1px solid var(--c-border);
}

.tab-nav__btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: var(--sp-2) var(--sp-3);
  color: var(--c-text-muted);
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  min-height: 54px;
  position: relative;
  transition: color var(--dur-fast);
  touch-action: manipulation;
}

.tab-nav__btn svg {
  transition: transform var(--dur-fast) var(--ease-out);
}

.tab-nav__btn[aria-selected="true"] {
  color: var(--c-blue);
}

.tab-nav__btn[aria-selected="true"] svg {
  transform: scale(1.1);
}

/* Aktiv-Indikator: Linie am unteren Rand */
.tab-nav__btn[aria-selected="true"]::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 16%;
  right: 16%;
  height: 2.5px;
  background: var(--c-blue);
  border-radius: var(--r-full);
}

/* ── Tab-Panels ── */
.tab-panel {
  flex: 1;
  display: none;       /* per HTML hidden-Attribut gesteuert */
  flex-direction: column;
  min-height: 0;
  animation: fade-in var(--dur-std) var(--ease-out);
}

.tab-panel:not([hidden]) {
  display: flex;
}

.tab-panel--active:not([hidden]) {
  display: flex;
}

.tab-panel__scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-4);
  padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.tab-panel__placeholder {
  font-size: var(--text-sm);
  color: var(--c-text-muted);
  text-align: center;
  padding: var(--sp-8) var(--sp-4);
}


/* ═══════════════════════════════════════════════════════════════
   8. BOTTOM NAVIGATION
   Nur auf Views außer Map sichtbar (View: map hat Tab-Nav intern).
   Auf der Map-View: Bottom-Nav ist ausgeblendet via JS-Klasse.
═══════════════════════════════════════════════════════════════ */
.bottom-nav {
  flex-shrink: 0;
  display: flex;
  height: var(--bottom-nav-h);
  background: var(--c-bg-surface);
  border-top: 1px solid var(--c-border);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--c-text-muted);
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  transition: color var(--dur-fast);
  touch-action: manipulation;
  position: relative;
}

.bottom-nav__item svg {
  transition: transform var(--dur-fast) var(--ease-out);
}

.bottom-nav__item--active {
  color: var(--c-blue);
}

.bottom-nav__item--active svg {
  transform: scale(1.1);
}

/* Aktiv-Indikator */
.bottom-nav__item--active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 2.5px;
  background: var(--c-blue);
  border-radius: 0 0 var(--r-full) var(--r-full);
}

/* ── Bottom-Nav ausblenden wenn Map-View aktiv ── */
.app:has(.view--map.view--active) .bottom-nav {
  display: none;
}

/* ═══════════════════════════════════════════════════════════════
   9. SIDE DRAWER
═══════════════════════════════════════════════════════════════ */
.side-drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(300px, 85vw);
  z-index: 500;
  background: var(--c-bg-surface);
  border-right: 1px solid var(--c-border-strong);
  padding-top: max(var(--sp-4), env(safe-area-inset-top));
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform var(--dur-slow) var(--ease-out);
  box-shadow: var(--shadow-lg);
}

.side-drawer[aria-hidden="false"] {
  transform: translateX(0);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 499;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-std);
}

.drawer-backdrop.drawer-backdrop--visible {
  opacity: 1;
  pointer-events: auto;
}

/* ═══════════════════════════════════════════════════════════════
   10. MODAL OVERLAY (globaler Slot)
═══════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 700;
  background: rgba(0, 0, 0, 0.70);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-std);
}

.modal-overlay[aria-hidden="false"] {
  opacity: 1;
  pointer-events: auto;
}

/* Inhalts-Sheet (von unten rein) */
.modal-sheet {
  width: 100%;
  max-width: 540px;
  max-height: 85dvh;
  background: var(--c-bg-surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  border: 1px solid var(--c-border-strong);
  border-bottom: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: sheet-up var(--dur-slow) var(--ease-out);
}

/* ═══════════════════════════════════════════════════════════════
   11. TOAST CONTAINER
═══════════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  top: calc(var(--header-h) + var(--sp-3));
  left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  align-items: center;
  pointer-events: none;
  width: calc(100% - var(--sp-8));
  max-width: 400px;
}

/* ═══════════════════════════════════════════════════════════════
   12. TABLET LANDSCAPE (≥768px, Querformat)
   Splitscreen wird zu Side-by-Side.
   Drag-Handle, Kids-Bar werden angepasst.
═══════════════════════════════════════════════════════════════ */
@media screen and (orientation: landscape) and (min-width: 768px) {

  /* Splitscreen: horizontal */
  .splitscreen {
    flex-direction: row;
  }

  /* Karte: linke Seite, volle Höhe */
  .map-panel {
    width: 60%;
    height: 100%;        /* überschreibt var(--map-h-portrait) */
    min-height: unset;
    max-height: unset;
    flex-shrink: 0;
  }

  /* Dashboard: rechte Seite, volle Höhe */
  .dashboard-panel {
    width: 40%;
    height: 100%;
    border-radius: 0;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.30);
  }

  /* Drag-Handle brauchen wir im Landscape nicht */
  .drag-handle { display: none; }

  /* Header: kompakter im Landscape */
  .app-header { height: 50px; }
  :root { --header-h: 50px; }

  /* Kids-Bar im Landscape: sticky am unteren Rand der Karte */
  .kids-bar {
    position: sticky;
    bottom: 0;
    z-index: 20;
  }
}

/* ═══════════════════════════════════════════════════════════════
   13. PORTRAIT  (explizite Regeln, Mobile-First)
═══════════════════════════════════════════════════════════════ */
@media screen and (orientation: portrait) {
  .splitscreen       { flex-direction: column; }
  .dashboard-panel   { border-radius: var(--r-xl) var(--r-xl) 0 0; }
}

/* ═══════════════════════════════════════════════════════════════
   14. GROSSE TABLETS / DESKTOP (≥1024px)
═══════════════════════════════════════════════════════════════ */
@media screen and (min-width: 1024px) and (orientation: landscape) {
  .map-panel       { width: 62%; }
  .dashboard-panel { width: 38%; }
}

/* ═══════════════════════════════════════════════════════════════
   15. KLEINE SCREENS (< 360px Breite)
═══════════════════════════════════════════════════════════════ */
@media screen and (max-width: 360px) {
  .brand__name         { display: none; }    /* Logo reicht bei <360px           */
  .tab-nav__btn span   { display: none; }    /* Nur Icons in der Tab-Nav         */
  .bottom-nav__item span { display: none; }  /* Nur Icons in der Bottom-Nav      */
}
