/* =========================================================
   App CSS – global styles for all pages
   ---------------------------------------------------------
   Struktur:
   0) Reset/Body
   1) Theme (data-bs-theme)
   2) Branding (Navbar/Logos)
   3) Components (Cards, Tables, Forms)
   4) Charts (ECharts container)
   5) Map/Leaflet
   6) Tooltips/Badges
   7) Footer
   8) Responsive helpers
   9) Page-specific scopes (.page-*)
   ========================================================= */

/* 0) Reset / Body */
html, body { height: 100%; margin: 0; padding: 0; }
body {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  transition: background-color .3s, color .3s;
}
main { flex: 1 0 auto; }

/* 1) Theme Tokens (Dark) */
[data-bs-theme="dark"] {
  --bs-body-bg: #1f2430;
  --bs-body-color: #f3f6fb;
  --bs-secondary-color: #cfd7e3;
  --bs-border-color: #465166;
  --bs-secondary-bg: #232a38;
  --bs-tertiary-bg: #263041;
  --bs-link-color: #8ab4ff;
  --bs-table-striped-bg: color-mix(in srgb, var(--bs-tertiary-bg) 82%, white 18%);
  --bs-table-hover-bg:   color-mix(in srgb, var(--bs-tertiary-bg) 70%, white 30%);
}

/* 🔆 Dark Mode – bessere Lesbarkeit von Headlines & Muted */
[data-bs-theme="dark"] h1,
[data-bs-theme="dark"] h2,
[data-bs-theme="dark"] h3,
[data-bs-theme="dark"] h4,
[data-bs-theme="dark"] h5,
[data-bs-theme="dark"] h6,
[data-bs-theme="dark"] .text-dark {
  color: #f8f9fa !important;
}
[data-bs-theme="dark"] .text-muted { color: var(--bs-secondary-color) !important; }
[data-bs-theme="dark"] a { color: var(--bs-link-color); }

/* 2) Branding / Navbar / Logos */
.navbar-custom {
  background: #f8f9fa;
  color: #212529;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
  margin: 0;
  padding-inline: 1rem;
  z-index: 1001;
}
.navbar-custom .navbar-brand {
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: .5px;
  color: #212529 !important;
  padding-top: 1px !important;
  padding-bottom: 1px !important;
  display: flex;
  align-items: center;
}
.navbar-brand img { object-fit: contain; }

.logo-dark { display: none; }
[data-bs-theme="dark"] .logo-light { display: none; }
[data-bs-theme="dark"] .logo-dark  { display: inline; }

/* Dark gradient for navbars on dark theme */
[data-bs-theme="dark"] .navbar-custom {
  background: linear-gradient(90deg, #0d1117 0%, #161b22 50%, #1f2937 100%);
  box-shadow: 0 2px 8px rgba(255,255,255,.08);
}
[data-bs-theme="dark"] .navbar { background-color: #111827 !important; color: #e5e7eb; box-shadow: 0 2px 4px rgba(0,0,0,.35); }

/* 3) Components */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  align-items: stretch;
}
.kpi-card { border-left: 4px solid var(--bs-primary); background: var(--bs-light-bg-subtle, #f8f9fa); height: 100%; }
.kpi-value { font-size: 1.3rem; font-weight: 600; }
[data-bs-theme="dark"] .card { background-color: var(--bs-tertiary-bg); border-color: var(--bs-border-color); }
[data-bs-theme="dark"] .card-header { background-color: color-mix(in srgb, var(--bs-tertiary-bg) 85%, black 15%); border-bottom-color: var(--bs-border-color); }

[data-bs-theme="dark"] .form-control, 
[data-bs-theme="dark"] .form-select {
  background-color: #232a38; 
  color: var(--bs-body-color); 
  border-color: var(--bs-border-color);
}

/* Tables */
[data-bs-theme="dark"] .table {
  --bs-table-color: var(--bs-body-color);
  --bs-table-bg: transparent;
  --bs-table-border-color: var(--bs-border-color);
}
.table thead.table-light { background-color: var(--bs-light, #f8f9fa) !important; }
[data-bs-theme="dark"] .table thead { background-color: #3a4252 !important; color: #f1f3f7 !important; }
[data-bs-theme="dark"] .table-striped>tbody>tr:nth-of-type(odd)>* { --bs-table-accent-bg: #2b3241; }
[data-bs-theme="dark"] .table-hover>tbody>tr:hover>* { --bs-table-accent-bg: #353d4f; }

/* 4) Charts (ECharts container) */
.echart {
  width: 100%;
  height: 260px;
  background: var(--bs-body-bg);
  border: 1px solid rgba(0,0,0,.06);
  border-radius: .5rem;
  padding: .5rem;
}
[data-bs-theme="light"] .echart { background: #f8f9fa !important; }
[data-bs-theme="dark"]  .echart { background: var(--bs-tertiary-bg); border: 1px solid var(--bs-border-color); }

/* 5) Map / Leaflet */
#map {
  flex: 1 1 auto;
  width: 100%;
  transition: filter .5s ease;
}
.page-map #map { min-height: 60vh; } /* safety for map page */
[data-bs-theme="dark"] #map { filter: brightness(0.93) saturate(0.95); }

/* Station markers */
.station-marker {
  background: #dc3545;
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.3);
}

/* Leaflet custom control */
.leaflet-control-allstations {
  background: rgba(255,255,255,.9);
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: .8rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.leaflet-control-allstations:hover { background: #f1f1f1; }
[data-bs-theme="dark"] .leaflet-control-allstations {
  background: rgba(40,40,40,.8);
  color: #eee;
  border-color: #666;
}
[data-bs-theme="dark"] .leaflet-control-allstations:hover { background: rgba(60,60,60,.9); }

/* Leaflet zoom buttons in dark */
[data-bs-theme="dark"] .leaflet-control-zoom a {
  background: rgba(50,50,50,.9);
  color: #ddd;
  border-color: #555;
}
[data-bs-theme="dark"] .leaflet-control-zoom a:hover {
  background: rgba(70,70,70,.9);
  color: #fff;
}

/* 6) Tooltips / Labels (stations) */
.station-label.leaflet-tooltip {
  background: #fff;
  border: 1px solid #dc3545;
  border-radius: 2px;
  padding: .5px 4px;
  font-size: .75rem;
  line-height: 1.1;
  color: #000;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
  cursor: pointer;
}
.station-label.leaflet-tooltip::before { display: none !important; }
[data-bs-theme="dark"] .station-label.leaflet-tooltip {
  background: #1e1e1e;
  border-color: #f87171;
  color: #f8f9fa;
}

/* 7) Footer badges */
.map-footer, #footer, #footer-inner {
  font-size: .85rem; 
  user-select: none;
}
.map-footer {
  position: fixed; bottom: 8px; left: 12px;
  color: #000;
  background: rgba(255,255,255,.6);
  backdrop-filter: blur(2px);
  z-index: 1000;
  line-height: 1.2;
  padding: 2px 8px;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
[data-bs-theme="dark"] .map-footer {
  color: #f8f9fa;
  background: rgba(30,30,30,.6);
  box-shadow: 0 1px 3px rgba(255,255,255,.1);
}

/* 8) Responsive helpers */
@media (max-width: 768px) {
  #obsTable { font-size: .9rem; }
  #tableSection { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* stacked table under 576px */
@media (max-width: 576px) {
  .table-stack thead { display: none; }
  .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr {
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    padding: .5rem .75rem; margin-bottom: .5rem;
    background-color: var(--bs-body-bg); border-radius: .25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
  }
  .table-stack td { border: none !important; padding: .25rem 0 !important; }
  .table-stack td::before { content: attr(data-label); display: block; font-weight: 600; opacity: .75; margin-bottom: .125rem; }
  .table-stack .actions .btn, .table-stack .actions input[type="password"] { width: 100%; }
}

/* 9) Page-specific scopes */
.page-map body, .page-station body, .page-admin body, .page-login body { background: var(--bs-body-bg); }

/* --- Admin page layout fix (schmal & zentriert) --- */
.page-admin main {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
}
.page-admin .page-container {
  width: 100%;
  max-width: 900px;
}

/* --- Station page: volle Breite & Charts nebeneinander --- */
.page-station .container-fluid { 
  max-width: 100% !important;
  padding-left: 1rem;
  padding-right: 1rem;
}
/* Falls HTML die Klasse .chart-col nutzt, hier das Layout erzwingen */
.page-station .chart-col { flex: 0 0 100%; max-width: 100%; }
@media (min-width: 992px) {
  .page-station .chart-col { flex: 0 0 50%; max-width: 50%; }
}

[data-bs-theme="dark"] .navbar-custom .navbar-brand,
[data-bs-theme="dark"] .navbar-custom .navbar-brand *,
[data-bs-theme="dark"] .brand-inline h4 {
  color: #f8f9fa !important;
  text-shadow: 0 0 0.01px rgba(0,0,0,0.01); /* minimal, gegen Subpixel-Fransen */
}
/* optional: theme-toggle button animation (falls vorhanden) */
#themeToggle { transition: all .25s ease; }
#themeIcon { transition: transform .3s ease; }
#themeToggle.active #themeIcon { transform: rotate(180deg); }
