/* ============================================
   SUPERB TRACKING - App Styles (bereinigt v0.3)
   ============================================ */

   html, body {
    height: 100vh;       /* fallback for browsers without dvh */
    height: 100dvh;      /* dynamic viewport: tracks mobile browser toolbars */
    margin: 0;
    padding: 0;
    overflow: hidden;
}

#app-layout {
    height: 100vh;
    height: 100dvh;
    display: flex;
}

/* ============================================
   SIDEBAR
   ============================================ */
#sidebar {
    background: #0f172a;
    color: #e2e8f0;
    width: 260px;
    flex-shrink: 0;
    transition: width 0.3s ease;
    box-shadow: 4px 0 12px rgba(0,0,0,0.25);
}

#sidebar.collapsed {
    width: 72px !important;
}

#sidebar.collapsed .nav-link span {
    display: none;
}

/* ============================================
   SIDEBAR NAVIGATION (verbesserte Specificity)
   ============================================ */
   #sidebar #nav-menu .nav-link,
   #sidebar #nav-footer .nav-link {
    color: #cbd5e1;
    padding: 14px 18px;
    border-radius: 8px;
    margin: 2px 6px;
    font-weight: 500;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    text-decoration: none;
    border-left: 4px solid transparent;   /* Platz für aktiven Rahmen */
}

/* Hover */
#sidebar #nav-menu .nav-link:hover,
#sidebar #nav-footer .nav-link:hover {
    background-color: #1e2937;
    color: #ffffff;
    transform: translateX(3px);
}

/* Active State — dezent (feiner blauer Rahmen) */
#sidebar #nav-menu .nav-link.active,
#sidebar #nav-footer .nav-link.active {
    background-color: #1e2937;
    border-left: 4px solid #3b82f6;
    color: #ffffff;
    font-weight: 600;
}

/* ============================================
   SIDEBAR SCROLL + MAP FILTER PANEL
   ============================================ */
   #sidebar {
    overflow-y: auto !important;
    max-height: 100vh;
    max-height: 100dvh;
}

/* ============================================
   MAP FILTER PANEL (direkt unter Map-Link)
   ============================================ */
/* KEIN eigenes Scrollen mehr – die Sidebar übernimmt alles */
#map-filter-panel {
    max-height: none;
    overflow-y: visible;
    overflow-x: hidden;
    padding: 12px 0 8px 0;
    border-top: 1px solid #334155;
    margin-top: 4px;
}

/* Filter-Container etwas luftiger */
#sidebar-filters-container {
    padding-left: 12px;
    padding-right: 12px;
}


/* ============================================
   LOGOUT BUTTON — Einheitlich & zuverlässig
   ============================================ */
#btn-logout-sidebar,
.btn-logout {
    --bs-btn-bg: #3b82f6;
    --bs-btn-color: #ffffff;
    --bs-btn-border-color: #3b82f6;

    --bs-btn-hover-bg: #2563eb;
    --bs-btn-hover-color: #ffffff;
    --bs-btn-hover-border-color: #2563eb;

    --bs-btn-active-bg: #1e40af;
    --bs-btn-active-color: #ffffff;
    --bs-btn-active-border-color: #1e40af;

    font-weight: 600;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1 !important;
}

#btn-logout-sidebar i,
#btn-logout-sidebar span,
.btn-logout i,
.btn-logout span {
    color: inherit !important;
}

#btn-logout-sidebar:hover,
.btn-logout:hover {
    background-color: #2563eb !important;
    color: #ffffff !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.45);
}

#btn-logout-sidebar:active,
.btn-logout:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

#btn-logout-sidebar i {
    font-size: 1.15rem;
}

/* Collapsed Sidebar: Text ausblenden */
#sidebar.collapsed #btn-logout-sidebar span {
    display: none;
}

#sidebar.collapsed #btn-logout-sidebar {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

/* ============================================
   MAIN AREA + MAP
   ============================================ */
#main-area {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

#main-content,
#map-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    background: #f8fafc;
}

#map-wrapper:not(.d-none) {
    display: block;
}

#map {
    width: 100% !important;
    height: 100% !important;
}

/* ============================================
   RESPONSIVE SIDEBAR (Mobile Drawer)
   ============================================ */
@media (min-width: 768px) {
    #sidebar {
        position: static !important;
        transform: none !important;
        width: 260px !important;
        visibility: visible !important;
        box-shadow: 4px 0 12px rgba(0,0,0,0.25);
    }
    #sidebar.collapsed {
        width: 72px !important;   /* keep collapse working on desktop */
    }
}

@media (max-width: 767.98px) {
    #sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        width: 260px !important;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.4);
        visibility: visible !important;
    }

    #sidebar.mobile-open {
        transform: translateX(0);
    }
}

/* ============================================
   TOAST CONTAINER
   ============================================ */
.toast-container {
    z-index: 1100;
}


/* AeroButton im Sidebar Footer anpassen */
#logout-button-container .aviation-btn {
    width: 100% !important;
    margin-top: 4px;
}


/* ============================================
   ASSET LAST POSITION POPOVER MAP
   ============================================ */
   .popover-asset-map {
    --bs-popover-max-width: 290px !important;
    max-width: 290px !important;
  }
  
  .popover-asset-map .popover-body {
    padding: 6px !important;
    margin: 0 !important;
  }
  
  .asset-map-wrapper {
    width: 265px;
    height: 195px;
    border-radius: 8px;
    overflow: hidden;
    background: #0f172a;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
  }
  
  .asset-map-wrapper img {
    width: 100% !important;
    height: 100% !important;
    display: block !important;
    border-radius: 6px;
  }

/* ============================================
   MAP (MapLibre) ASSET INFO POPUPS
   Make them wider and prevent button/text overflow
   ============================================ */
.map-popup .maplibregl-popup-content {
  min-width: 320px !important;
  max-width: 360px !important;
  padding: 8px 10px;
  font-size: 0.95rem;
  box-sizing: border-box;
}

.map-popup .maplibregl-popup-content > div {
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Make the action buttons at the bottom more flexible */
.map-popup .maplibregl-popup-content .d-flex.gap-2 {
  gap: 6px !important;
  flex-wrap: wrap;
}

.map-popup .maplibregl-popup-content .btn {
  font-size: 0.8rem;
  padding: 4px 6px;
  min-width: 0;
  flex: 1 1 auto;
  white-space: normal;
  text-align: center;
  line-height: 1.2;
}

/* ============================================
   MAP FLOATING ASSET INFO PANEL
   Docked top-left, decoupled from the marker so it stays put while the
   camera zooms out to fit the route.
   ============================================ */
.map-info-panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 6;
  width: 340px;
  max-width: calc(100% - 24px);
  max-height: calc(100% - 24px);
  overflow-y: auto;
  background: #fff;
  color: #111;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  padding: 12px 14px;
  font-size: 0.95rem;
  box-sizing: border-box;
}

.map-info-panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
}
.map-info-panel-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.map-info-panel-toggle,
.map-info-panel-close {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 1rem;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}
.map-info-panel-toggle:hover,
.map-info-panel-close:hover { background: #f1f5f9; color: #111; }

/* Collapsed: show only the header bar (frees the map on mobile). */
.map-info-panel.collapsed .map-info-panel-body { display: none; }

.map-info-panel-body { margin-top: 6px; }

.map-info-panel .js-sensor-badge:hover {
  background: #e0f2fe !important;
  border-color: #38bdf8 !important;
}

/* Footer status line (history loading etc.) — spinner only as tall as the row. */
.map-info-panel-status {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #e5e7eb;
  font-size: 1.05rem;
  color: #6b7280;
}
.map-info-panel-status[hidden] { display: none; }
.map-info-panel-status svg { display: block; flex: 0 0 auto; }

/* ============================================
   MAP CONTROL BAR — collapsible on mobile
   Desktop: arrow toggle hidden, controls always shown.
   Mobile: only the arrow shows; tapping it reveals the controls as a
   right-aligned column, which folds back up after any control is used.
   ============================================ */
.map-controls-toggle { display: none; }
.map-controls-row,
.map-controls-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

@media (max-width: 767.98px) {
  .map-controls {
    flex-direction: column;
    align-items: flex-end;
  }
  .map-controls-row { align-items: center; }
  .map-controls-toggle { display: flex; align-items: center; justify-content: center; }
  /* Collapsed = just the arrow. The selector unfolds to its left on expand, */
  .map-controls:not(.expanded) .map-layer-select { display: none; }
  .map-layer-select { max-width: 55vw; }
  /* and the icon buttons unfold into a narrow column below the arrow — pinned
     to button width so it never inherits the (wide) selector's width. */
  .map-controls .map-controls-wrap { display: none; }
  .map-controls.expanded .map-controls-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    align-self: flex-end;
    width: max-content;
  }
}

/* ============================================
   MAP SENSOR HISTORY SIDEBAR
   Slides in from the right, spans up to 50% of the map width.
   ============================================ */
.map-sensor-sidebar {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 50%;
  min-width: 320px;
  z-index: 7;
  display: none;            /* toggled to flex when opened */
  flex-direction: column;
  background: #ffffff;
  box-shadow: -6px 0 24px rgba(0, 0, 0, 0.22);
  box-sizing: border-box;
}

.map-sensor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 14px 8px;
  border-bottom: 1px solid #e5e7eb;
}

.map-sensor-close {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}
.map-sensor-close:hover { background: #f1f5f9; color: #111; }

.map-sensor-ranges {
  padding: 8px 14px;
}

.map-sensor-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 14px 16px;
}

.map-sensor-card {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
  background: #fff;
}

/* Responsive grid of sensor charts — shared by the map sidebar and the
   asset detail page. Auto-fills columns: 1 in the narrow sidebar, several
   across the wide asset detail card. */
.sensor-chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.sensor-card {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}

/* Subtle reload button overlaid in the corner of the asset detail mini-map */
.asset-map-reload {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.85);
  color: #334155;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  opacity: 0.65;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.asset-map-reload:hover { opacity: 1; }

.ssr-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 8px;
  margin-bottom: 6px;
}

.ssr-card-title { font-weight: 600; font-size: 0.9rem; }

.ssr-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.72rem;
  color: #475569;
}
.ssr-stat b { color: #111; }

.ssr-card-canvas {
  position: relative;
  height: 150px;
}

@media (max-width: 575.98px) {
  .map-sensor-sidebar { width: 100%; min-width: 0; }
}

/* ============================================
   DESIGN TOKENS (shell redesign)
   ============================================ */
:root {
  --brand-primary: #2563eb;
  --brand-primary-hover: #1d4ed8;
  --ink: #0f172a;
  --ink-soft: #475569;
  --line: #e5e7eb;
}

/* ============================================
   SIDEBAR — head, nav, footer, collapse
   ============================================ */
#sidebar { background: #0f172a; }

.sidebar-head {
  height: 68px;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.sidebar-logo { height: 40px; width: auto; max-width: 180px; transition: max-width 0.2s ease; }

.sidebar-collapse-btn {
  width: 28px; height: 28px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: #cbd5e1;
  border-radius: 8px;
  align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}
.sidebar-collapse-btn:hover { background: #1e2937; color: #fff; }

.sidebar-nav { padding: 14px 8px; gap: 4px; }
.sidebar-nav-footer { padding: 6px 8px 4px; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.08); padding: 8px 12px 12px; }

/* Collapsed sidebar */
#sidebar.collapsed .sidebar-logo { max-width: 40px; object-fit: cover; object-position: left; }
#sidebar.collapsed .sidebar-head { justify-content: center; }
#sidebar.collapsed .nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
#sidebar.collapsed .nav-link i { margin-right: 0 !important; }
#sidebar.collapsed .nav-link .badge { display: none; }

/* ============================================
   TOPBAR
   ============================================ */
#topbar { min-height: 62px; gap: 12px; }
.min-w-0 { min-width: 0; }

.topbar-app-name {
  font-weight: 700; color: var(--ink); line-height: 1.1;
  font-size: 0.95rem; letter-spacing: 0.01em;
}

/* Breadcrumb */
.breadcrumb-bar {
  display: flex; align-items: center; flex-wrap: nowrap;
  gap: 6px; margin: 2px 0 0; font-size: 0.78rem; min-width: 0;
}
.breadcrumb-bar .bc-home { color: #94a3b8; display: inline-flex; }
.breadcrumb-bar .bc-home:hover { color: var(--brand-primary); }
.breadcrumb-bar .bc-sep { color: #cbd5e1; font-size: 0.6rem; }
.breadcrumb-bar .bc-link { color: var(--ink-soft); text-decoration: none; white-space: nowrap; }
.breadcrumb-bar .bc-link:hover { color: var(--brand-primary); text-decoration: underline; }
.breadcrumb-bar .bc-current { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Metric / Imperial toggle */
.unit-toggle {
  display: inline-flex; background: #f1f5f9; border: 1px solid var(--line);
  border-radius: 999px; padding: 2px; gap: 2px;
}
.unit-toggle .unit-opt {
  border: 0; background: transparent; color: var(--ink-soft);
  font-size: 0.78rem; font-weight: 600; padding: 4px 12px; border-radius: 999px;
  cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
}
.unit-toggle .unit-opt.active {
  background: #fff; color: var(--brand-primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* Notification bell */
.topbar-icon-btn {
  position: relative; width: 40px; height: 40px;
  border: 1px solid var(--line); background: #fff; color: #475569;
  border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.topbar-icon-btn:hover { background: #f8fafc; color: var(--ink); border-color: #cbd5e1; }
.topbar-badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 18px; height: 18px; padding: 0 4px;
  background: #ef4444; color: #fff; font-size: 0.62rem; font-weight: 700;
  border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
}

/* User block */
.topbar-user-btn {
  display: inline-flex; align-items: center; gap: 10px;
  border: 0; background: transparent; cursor: pointer; padding: 4px 6px; border-radius: 10px;
  transition: background 0.15s ease;
}
.topbar-user-btn:hover { background: #f1f5f9; }
.topbar-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-primary), #1e40af);
  color: #fff; font-weight: 700; font-size: 0.82rem;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.topbar-user-meta { flex-direction: column; align-items: flex-start; line-height: 1.15; min-width: 0; }
.topbar-user-name { font-weight: 600; color: var(--ink); font-size: 0.82rem; white-space: nowrap; }
.topbar-user-role { color: #94a3b8; font-size: 0.7rem; white-space: nowrap; }
.topbar-user-caret { color: #94a3b8; font-size: 0.7rem; }

/* ============================================
   SOFT BADGE PILLS (status) — reusable
   ============================================ */
.badge-soft { font-weight: 600; border-radius: 999px; padding: 0.3em 0.7em; font-size: 0.72rem; }
.badge-soft-blue  { background: #e0edff; color: #1d4ed8; }
.badge-soft-green { background: #dcfce7; color: #15803d; }
.badge-soft-red   { background: #fee2e2; color: #b91c1c; }
.badge-soft-amber { background: #fef3c7; color: #b45309; }
.badge-soft-gray  { background: #f1f5f9; color: #475569; }