/* =========================================================
   BirdPI – Page Styles: Dashboard
   ========================================================= */

body.page-dashboard {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* --- KPI-Grid oben --- */
body.page-dashboard .grid-kpi.top-bar {
  display: grid;
  gap: 8px;
  grid-template-columns: auto auto 1fr auto auto;
}

/* =========================================================
   Responsive: Smartphone (max-width: 600px)
   ========================================================= */
@media (max-width: 600px) {

  /* Dashboard darf auf Mobile scrollen statt 100vh */
  body.page-dashboard {
    height: auto;
    min-height: 100vh;
  }

  /* --- KPI-Grid: 2 Spalten, Top-Art volle Breite --- */
  body.page-dashboard .grid-kpi.top-bar {
    grid-template-columns: 1fr 1fr;
  }

  /* Top-Art-Karte wird per JS in die Middle Row verschoben */

  /* KPI-Karten kompakter */
  .card.kpi {
    min-height: 64px;
    padding: 8px;
    gap: 4px;
  }
  .card .v {
    font-size: 20px;
  }

  /* Status + Wetter: Badges horizontal statt vertikal */
  #status-card .badge-group,
  #weather-card .badge-group {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
  }
  #status-card .badge-group > .badge,
  #weather-card .badge-group > .badge,
  #status-card .badge-group > .tools,
  #weather-card .badge-group > .tools {
    width: auto;
    margin-left: 0;
  }

  /* Spaltenbreiten auf Mobile */
  .middle-row .card table th:nth-child(1) { width: 30%; }
  .middle-row .card table th:nth-child(2) { width: 40%; }
  .middle-row .card table .cat-cell { width: 30%; }

  /* Tabellenzellen kompakter */
  .middle-row .tbl th,
  .middle-row .tbl td {
    padding: 6px 8px;
    font-size: 0.85rem;
  }

  /* Artliste + Detektionstabelle: scrollbar mit begrenzter Hoehe */
  .middle-row > .card:first-child {
    max-height: 160px;
  }
  .middle-row > .card:last-child {
    max-height: 45vh;
  }
  .middle-row > .card > #top {
    font-size: 0.9rem;
  }

  /* Bildkarte: feste Desktop-Groesse auf Mobile aufheben */
  .card.kpi.top.align-top {
    width: auto;
    min-width: 140px;
    max-width: none;
    height: auto;
    max-height: 200px;
  }
}

/* =========================================================
   Responsive: Compact / sehr kleine Phones (max-width: 520px)
   ========================================================= */
body.page-dashboard.compact .grid-kpi.top-bar {
  gap: 4px;
}
body.page-dashboard.compact .card.kpi {
  min-height: 56px;
  padding: 6px;
}
body.page-dashboard.compact .card .v {
  font-size: 18px;
}
body.page-dashboard.compact .card .s {
  font-size: 0.75rem;
}
body.page-dashboard.compact .name-overlay {
  font-size: 0.78rem;
  padding: 2px 4px;
}
body.page-dashboard.compact .middle-row {
  gap: 4px;
}
body.page-dashboard.compact .middle-row .tbl th,
body.page-dashboard.compact .middle-row .tbl td {
  padding: 4px 6px;
  font-size: 0.8rem;
}

/* Top-Art Karte */
.card.kpi.top.align-top {
  width: 200px;
  min-width: 200px;
  max-width: 200px;
  height: 130px;
  max-height: 130px;
  justify-self: center;
  padding: 1px;
  gap: 0;
  display: block;
  overflow: hidden;
}

.top-art-text {
  width: 100%;
  height: 100%;
}

body.page-dashboard #kpi-top {
  position: relative;
  width: 100%;
  height: 100%;
}

body.page-dashboard #kpi-top-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
  transition: opacity 0.6s ease;
}

.name-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.65);
  color: #fff !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  text-align: center;
  padding: 3px 4px;
  font-size: 0.9rem;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  pointer-events: auto;
}

#kpi-total.v {
  display: grid;
  align-items: center;
  justify-content: center;
}

/* --- Badge-Gruppen --- */
body.page-dashboard .badge-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}
body.page-dashboard .badge-group > .badge,
body.page-dashboard .badge-group > .tools {
  width: 100%;
  justify-content: flex-start;
}
body.page-dashboard .badge-group > .tools > .badge {
  width: 100%;
  justify-content: flex-start;
}

/* --- Links in Listen/Tabelle --- */
body.page-dashboard #tbl a,
body.page-dashboard #top a {
  color: var(--fg);
  opacity: 1;
  text-decoration: none;
}
body.page-dashboard #kpi-top-name a {
  color: #fff;
  opacity: 1;
  text-decoration: none;
}
body.page-dashboard #tbl a:hover,
body.page-dashboard #top a:hover,
body.page-dashboard #kpi-top-name a:hover {
  text-decoration: underline;
}

/* --- Mittlere Reihe (Artliste + Tabelle) --- */
.middle-row {
  flex: 1;
  display: grid;
  min-height: 0;
  gap: 8px;
  grid-template-columns: 0.7fr 2fr;
}

@media (max-width: 600px) {
  .middle-row {
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    flex: none;
  }
  /* Bildkarte (per JS an Position 1): links oben, darf wachsen */
  .middle-row > .card.kpi.top {
    grid-row: 1;
    grid-column: 1;
    height: auto;
    max-height: 200px;
  }
  /* Artliste: rechts neben Bildkarte, scrollbar */
  .middle-row > .card.kpi:not(.top) {
    grid-row: 1;
    grid-column: 2;
    max-height: 160px;
    overflow-y: auto;
  }
  /* Detektionstabelle: volle Breite darunter */
  .middle-row > .card:last-child {
    grid-row: 2;
    grid-column: 1 / -1;
  }
}

.middle-row > .card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.scroll-card {
  flex: 1;
  overflow-y: auto;
}

.middle-row .card .inner.scroll-card {
  width: 100%;
  height: 100%;
}

.middle-row .card table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--tbl-b);
}
.middle-row .card table {
  width: 100%;
  table-layout: fixed;
}
.middle-row .card table th:nth-child(1) { width: 28%; }
.middle-row .card table th:nth-child(2) { width: 40%; }
.middle-row .card table th:nth-child(3) { width: 32%; }

.middle-row > .card > #top {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* --- Disk-Ring (Speicher) --- */
.disk-ring {
  flex-shrink: 0;
}
.disk-ring-bg {
  stroke: var(--grid, #2a4a43);
}
.disk-ring-fg {
  stroke: var(--ok, #4ade80);
  transition: stroke-dasharray 0.6s ease, stroke 0.3s;
}
.disk-ring-fg.warn { stroke: var(--accent, #e8874a); }
.disk-ring-fg.crit { stroke: var(--high, #ef4444); }

#disk-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: inherit;
}
#disk-badge.storage-warn {
  border-color: var(--mid);
  animation: storage-pulse 2s ease-in-out infinite;
}
#disk-badge.storage-crit {
  border-color: var(--high);
  animation: storage-pulse 1s ease-in-out infinite;
}
@keyframes storage-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .6; }
}

/* --- Standort-Badge --- */
.site-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.site-badge .ico-maps-pin-line {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.site-swap-hint {
  width: 12px;
  height: 12px;
  opacity: 0.4;
  transition: opacity 0.2s;
  flex-shrink: 0;
}
.site-badge:hover .site-swap-hint {
  opacity: 1;
}

/* --- Wetter-Widget --- */
#weather-card .weather-main {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1rem;
}
#weather-card .weather-main .ico {
  width: 20px;
  height: 20px;
}
#weather-card .weather-details {
  display: flex;
  gap: 10px;
  font-size: 0.82rem;
  opacity: 0.85;
}
#weather-card .weather-detail {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
#weather-card .weather-detail .ico {
  width: 14px;
  height: 14px;
}
