/* ===========================================================================
   RadPlan · Auswertungs-Hub – Shell, Navigation, Zeitraum, Dashboard
   + gemeinsame Bausteine (ah-*), die ALLE Module wiederverwenden, damit der
   Hub trotz paralleler Modulentwicklung konsistent aussieht (hell & dunkel).
   =========================================================================== */

/* ---- Modal-Rahmen ---- */
.modal-analytics {
  width: min(1280px, 96vw);
  height: min(860px, 92vh);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.ah-hd {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--gray-200);
  flex-wrap: wrap;
  position: relative;
}
/* Feine Akzentlinie am Kopf des Hubs — signalisiert "Dashboard", nicht "Formular". */
.ah-hd::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: var(--grad-hairline, transparent);
  opacity: .8;
  pointer-events: none;
}
.ah-hd-left { min-width: 0; margin-right: auto; }
.ah-close { flex: none; }

/* ---- Zeitraum-Leiste ---- */
.ah-range-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ah-range-pills { display: inline-flex; gap: 4px; background: var(--gray-100, rgba(148,163,184,.12)); padding: 3px; border-radius: 999px; }
.ah-range-pill {
  border: none; background: transparent; cursor: pointer;
  font: 600 11px/1 var(--font-sans); color: var(--text-3);
  padding: 6px 11px; border-radius: 999px;
  transition: background var(--dur-2, .15s) var(--ease-out, ease), color var(--dur-2, .15s) var(--ease-out, ease), box-shadow var(--dur-2, .15s) var(--ease-out, ease);
}
.ah-range-pill:hover { color: var(--text-1); }
.ah-range-pill.active {
  background: var(--surface-raised, #fff);
  color: var(--text-1);
  box-shadow: 0 1px 2px rgba(0,0,0,.10), 0 4px 10px rgba(var(--accent-rgb),.16), inset 0 0 0 1px rgba(var(--accent-rgb),.18);
}
.ah-range-custom { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-3); }
.ah-range-custom input { font: inherit; padding: 4px 6px; border: 1px solid var(--gray-200); border-radius: 6px; background: var(--gray-50); color: var(--text-1); transition: border-color var(--dur-2, .15s) var(--ease-out, ease), box-shadow var(--dur-2, .15s) var(--ease-out, ease); }
.ah-range-custom input:focus-visible { border-color: rgba(var(--accent-rgb),.55); box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.14); }
.ah-range-static { font-size: 11px; color: var(--text-faint); }

/* ---- Body: Navigation + Inhalt ---- */
/* Unlike every other dialog, the Auswertungs-Hub doesn't use the shared
   .modal-bd wrapper (it has its own nav+content shell), so it never picked up
   the .modal-bd ink/gray pin from modals-base.css. Every ah-* component
   (kpi tiles, cards, tables, legends) assumes a fixed light card — exactly
   the assumption .modal-bd exists to guarantee — so without this pin all of
   that text resolves to the dark-theme (near-white) ink/gray values and
   disappears on the always-light modal surface. Mirrors .modal-bd verbatim. */
.ah-body {
  display: flex; flex: 1; min-height: 0;
  --ink-rgb: 15,23,42;
  --ink-strong: #0F172A;
  --text-1: #0F172A;
  --text-2: rgba(15,23,42,.88);
  --text-3: rgba(15,23,42,.76);
  --text-faint: rgba(15,23,42,.68);
  --gray-50: #F8FAFC;
  --gray-100: #F1F5F9;
  --gray-150: #E9EFF6;
  --gray-200: #E2E8F0;
  --gray-300: #CBD5E1;
  --gray-400: #94A3B8;
  --gray-500: #64748B;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1E293B;
  --gray-900: #0F172A;
  color: var(--text-1);
}
.ah-nav {
  flex: none; width: 224px; padding: 12px 10px; gap: 2px;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--gray-200);
  overflow-y: auto; background: var(--gray-50);
}
.ah-nav-item {
  display: flex; align-items: center; gap: 10px;
  border: none; background: transparent; cursor: pointer; text-align: left;
  padding: 10px 12px; border-radius: 10px;
  font: 600 12.5px/1.2 var(--font-sans); color: var(--text-2);
  position: relative;
  transition: background var(--dur-2, .14s) var(--ease-out, ease), color var(--dur-2, .14s) var(--ease-out, ease);
}
.ah-nav-item:hover { background: var(--gray-100, rgba(148,163,184,.14)); color: var(--text-1); }
.ah-nav-item.active {
  background: var(--grad-accent-soft, rgba(14,165,233,.14));
  color: var(--accent, #0EA5E9);
}
/* Aktiver Tab: schlanker Gradient-Indikator statt Flatline-Unterstreichung —
   links im vertikalen Desktop-Nav, unten in der horizontal scrollenden
   Mobile-Leiste (siehe Media-Query weiter unten). */
.ah-nav-item.active::before {
  content: "";
  position: absolute;
  left: 2px; top: 14%; bottom: 14%;
  width: 3px;
  border-radius: 999px;
  background: var(--accent-grad, var(--accent, #0EA5E9));
}
.ah-nav-ico { display: inline-flex; width: 18px; justify-content: center; flex: none; }
.ah-nav-ico svg { width: 16px; height: 16px; }
.ah-nav-item.active .ah-nav-ico svg { filter: drop-shadow(0 0 4px rgba(var(--accent-rgb),.35)); }

.ah-content { flex: 1; min-width: 0; overflow-y: auto; padding: 18px 20px 28px; }
.ah-content.ah-fade { animation: ahFade .22s ease; }
@keyframes ahFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---- Gemeinsame Bausteine (von allen Modulen genutzt) ---- */
.ah-section-title {
  font-size: 12.5px; font-weight: 800; color: var(--text-1);
  margin: 18px 0 10px; letter-spacing: .01em;
  display: flex; align-items: center; gap: 8px;
}
.ah-section-title:first-child { margin-top: 0; }
/* Kleiner Gradient-Marker vor jeder Sektionsüberschrift — bindet die dichten
   Tabellen/Karten-Blöcke optisch an die Akzentfarbe des Hubs. */
.ah-section-title::before {
  content: "";
  width: 3px; height: 12px; border-radius: 999px; flex: none;
  background: var(--accent-grad, var(--accent, #0EA5E9));
  opacity: .85;
}
.ah-sub { font-size: 11px; color: var(--text-faint); font-weight: 600; }

.ah-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.ah-kpi {
  background: var(--gray-50); border: 1px solid var(--gray-200);
  border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 3px;
  transition: border-color var(--dur-2, .16s) var(--ease-out, ease), box-shadow var(--dur-2, .16s) var(--ease-out, ease), transform var(--dur-2, .16s) var(--ease-out, ease);
}
.ah-kpi:hover { border-color: var(--gray-300); box-shadow: 0 4px 14px rgba(0,0,0,.06); transform: translateY(-1px); }
.ah-kpi-label { font-size: 10.5px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.ah-kpi-value { font-size: 24px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.ah-kpi-sub { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

.ah-card { background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--card-radius, var(--radius)); padding: 14px 16px; transition: border-color var(--dur-2, .16s) var(--ease-out, ease); }
.ah-card + .ah-card { margin-top: 12px; }

/* Tabellen */
.ah-table-wrap { overflow-x: auto; border: 1px solid var(--gray-200); border-radius: var(--radius); }
.ah-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ah-table th, .ah-table td { padding: 8px 10px; text-align: right; white-space: nowrap; }
.ah-table th { font-size: 10px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; background: var(--gray-100, rgba(148,163,184,.10)); position: sticky; top: 0; }
.ah-table th:first-child, .ah-table td:first-child { text-align: left; }
.ah-table tbody tr { border-top: 1px solid var(--gray-200); }
.ah-table tbody tr.clickable { cursor: pointer; transition: background var(--dur-1, .12s) var(--ease-out, ease); }
.ah-table tbody tr.clickable:hover { background: var(--gray-100, rgba(148,163,184,.12)); }
.ah-td-num { font-variant-numeric: tabular-nums; }

/* Pillen / Badges */
.ah-pill { display: inline-block; font-size: 10px; font-weight: 800; padding: 2px 9px; border-radius: 999px; border: 1px solid currentColor; line-height: 1.4; }
.ah-pill-good { color: #15803D; background: rgba(21,128,61,.10); }
.ah-pill-warn { color: #B45309; background: rgba(245,158,11,.12); }
.ah-pill-bad  { color: #B91C1C; background: rgba(239,68,68,.10); }

/* Fortschritts-/Wertbalken */
.ah-bar { position: relative; height: 8px; background: var(--gray-200); border-radius: 999px; overflow: hidden; }
.ah-bar > div { position: absolute; left: 0; top: 0; height: 100%; border-radius: 999px; transition: width var(--dur-4, .4s) var(--ease-out, ease); }

/* Leerzustand / Fehler */
.ah-empty { font-size: 12.5px; color: var(--text-faint); font-style: italic; padding: 28px 8px; text-align: center; }
.ah-error { color: #B91C1C; font-style: normal; }
.ah-ok-banner {
  font-size: 12px; color: #15803D; background: rgba(21,128,61,.08);
  border: 1px solid rgba(21,128,61,.2); border-radius: var(--radius);
  padding: 12px 14px; font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4);
}

/* ---- Dashboard (Modul „Übersicht") ---- */
.ah-dash-head { margin-bottom: 14px; }
.ah-dash-title { font-size: 16px; font-weight: 800; color: var(--text-1); letter-spacing: -.01em; }
.ah-dash-meta { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; font-variant-numeric: tabular-nums; }
.ah-tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.ah-tile {
  text-align: left; cursor: pointer; border: 1px solid var(--gray-200);
  background: var(--gray-50); border-radius: var(--card-radius, var(--radius)); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden;
  transition: transform var(--dur-2, .16s) var(--ease-spring-soft, ease), box-shadow var(--dur-2, .16s) var(--ease-out, ease), border-color var(--dur-2, .16s) var(--ease-out, ease);
}
/* Zarter oberer Sheen-Akzent — signalisiert "anklickbare Kennzahl", ohne
   die Ampel-Semantik der Werte selbst zu berühren. */
.ah-tile::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 2px;
  background: var(--grad-hairline, transparent);
  opacity: 0; transition: opacity var(--dur-2, .16s) var(--ease-out, ease);
}
.ah-tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lift-hover, var(--shadow-md));
  border-color: var(--gray-300);
}
.ah-tile:hover::before { opacity: 1; }
.ah-tile-label { font-size: 11px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; }
.ah-tile-value { font-size: 30px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.ah-tile-unit { font-size: 14px; font-weight: 700; margin-left: 2px; opacity: .7; }
.ah-tile-sub { font-size: 11px; color: var(--text-faint); }
.ah-tile-bar { height: 5px; background: var(--gray-200); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.ah-tile-bar > div { height: 100%; border-radius: 999px; transition: width var(--dur-4, .5s) var(--ease-out, ease); }

.ah-dash-section { margin-top: 22px; }
.ah-alert-list { display: flex; flex-direction: column; gap: 6px; }
.ah-alert {
  display: flex; align-items: center; gap: 10px; cursor: pointer; text-align: left; width: 100%;
  border: 1px solid var(--gray-200); background: var(--gray-50); border-radius: 10px; padding: 10px 12px;
  font-size: 12.5px; color: var(--text-1);
  transition: background var(--dur-2, .14s) var(--ease-out, ease), border-color var(--dur-2, .14s) var(--ease-out, ease), transform var(--dur-1, .1s) var(--ease-out, ease);
}
.ah-alert:hover { background: var(--gray-100, rgba(148,163,184,.12)); border-color: var(--gray-300); transform: translateX(1px); }
.ah-alert-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.ah-alert-high .ah-alert-dot { background: #EF4444; box-shadow: 0 0 8px rgba(239,68,68,.55); }
.ah-alert-mid .ah-alert-dot { background: #F59E0B; box-shadow: 0 0 8px rgba(245,158,11,.5); }
.ah-alert-text { flex: 1; }
.ah-alert-go { color: var(--text-faint); font-size: 18px; transition: transform var(--dur-2, .14s) var(--ease-out, ease), color var(--dur-2, .14s) var(--ease-out, ease); }
.ah-alert:hover .ah-alert-go { transform: translateX(2px); color: var(--text-2); }

/* ---- Responsive ---- */
@media (max-width: 720px) {
  /* Full-bleed, not "fits its content": on mobile this is a dedicated app
     screen, not a floating dialog. updateModalLayout() (render-grid.js)
     still measures content height and toggles .modal-fit-content /
     .modal-fit-viewport on every .modal — including this one — to make
     small dialogs hug their content. For the analytics hub that shrink-to-
     content behavior is wrong (a short "Übersicht" tab would collapse the
     whole hub to a small floating card, leaving dead space above/below).
     The two-class selectors below outrank the single-class rules that set
     `height: auto !important` / a fitted max-height, so the hub always
     fills the true viewport regardless of which tab's content is showing. */
  /* The generic .overlay centers its child inside a padded box (var(--overlay-pad)
     on every side). A child sized to exactly the viewport (100vw/var(--app-vh))
     then overflows that padded box symmetrically and, at the overlay's default
     zero scroll position, ends up shifted upward by one pad's worth — clipped
     at the top and leaving a gap at the bottom that exposes the app shell
     behind it. Stripping the overlay's own padding/centering here lets the
     full-bleed modal sit flush at 0/0 instead. */
  /* !important: core.css/mobile-optimization.css set padding-bottom and
     align-items on .overlay (and body.is-mobile .overlay) with !important
     of their own for the normal centered-dialog / bottom-sheet cases; an
     ID selector alone doesn't outrank an !important declaration, so this
     needs !important too to actually win. */
  #modal-analytics { padding: 0 !important; align-items: stretch !important; justify-content: stretch !important; }
  .modal-analytics { width: 100vw; height: var(--app-vh); border-radius: 0; }
  .modal-analytics.modal-fit-content,
  .modal-analytics.modal-fit-viewport {
    height: var(--app-vh) !important;
    max-height: var(--app-vh) !important;
  }

  .ah-body { flex-direction: column; }
  .ah-nav {
    width: 100%; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    border-right: none; gap: 6px;
    border-bottom: 1px solid var(--gray-200); padding: 8px 10px;
    /* Snap + hidden scrollbar + faded edges signal "more tabs this way"
       without needing extra markup, and keep touch scrolling smooth on iOS. */
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    mask-image: linear-gradient(to right, transparent, black 14px, black calc(100% - 14px), transparent);
    -webkit-mask-image: linear-gradient(to right, transparent, black 14px, black calc(100% - 14px), transparent);
  }
  .ah-nav::-webkit-scrollbar { display: none; }
  .ah-nav-item {
    /* WebKit/Safari can miscompute intrinsic widths for shrinkable flex
       items inside an overflow-x:auto row, especially right after layout
       changes (modal open, tab switch) — items can render compressed
       below their text width, so neighboring labels visually overlap.
       Pinning every tab to its natural content width removes the
       shrink calculation entirely: items can only ever be their own
       width, never less, so labels can never overlap regardless of
       engine quirks. */
    flex: 0 0 auto;
    white-space: nowrap;
    scroll-snap-align: start;
  }
  .ah-nav-lbl { font-size: 11.5px; }
  /* In der horizontalen Leiste liest sich ein linker Balken als Fehlausrichtung —
     der Indikator wandert an die Unterkante jedes Tabs. */
  .ah-nav-item.active::before {
    left: 12%; right: 12%; top: auto; bottom: 1px;
    width: auto; height: 3px;
  }
}

/* ---- Portrait-/Schmal-Mobile (Hochkant) ---- */
@media (max-width: 560px) {
  /* Header darf nicht überlappen: Titel+Close bleiben in einer Zeile
     (order steuert die visuelle Reihenfolge unabhängig von der DOM-
     Reihenfolge), die Range-Bar bricht als einzige in eine eigene,
     volle Zeile um. Vorher beanspruchten sowohl .ah-hd-left als auch
     .ah-range-bar `flex-basis: 100%`, wodurch beide je eine eigene Zeile
     erzwangen und der Close-Button — als letztes Element ohne eigene
     Breitenregel — isoliert in eine dritte Zeile darunter rutschte. */
  .ah-hd { gap: 6px 12px; padding: 12px 14px; }
  .ah-hd-left { order: 1; flex: 1 1 auto; min-width: 0; }
  .ah-hd-left * { overflow-wrap: anywhere; }
  .ah-hd-left .modal-hd-sub {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .ah-close { order: 2; flex: none; }
  .ah-range-bar { order: 3; flex: 1 1 100%; gap: 8px; min-width: 0; }
  /* Range-Pills horizontal scrollbar statt Überlappung. */
  .ah-range-pills {
    flex: 1 1 auto; max-width: 100%;
    overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch; scrollbar-width: thin;
  }
  .ah-range-pill { flex: none; white-space: nowrap; }
  .ah-range-custom { flex-wrap: wrap; }
  .ah-range-custom input { min-width: 0; flex: 1 1 120px; }

  /* Inhalt: Padding reduzieren, kein horizontales Mitscrollen. */
  .ah-content { padding: 14px 12px 24px; }
  .ah-body { min-width: 0; }
  .ah-content > * { min-width: 0; }

  /* KPI-Grid: 2 Spalten, kompaktere Werte. */
  .ah-kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .ah-kpi { padding: 10px 11px; }
  .ah-kpi-value { font-size: 20px; }
  .ah-kpi-label { font-size: 9.5px; }

  /* Tabellen: kompakter, Wrap begrenzt die Breite und kapselt Sticky-Header. */
  .ah-table-wrap {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    contain: paint;
  }
  .ah-table { font-size: 11px; }
  .ah-table th, .ah-table td { padding: 6px 7px; }
  .ah-table th { font-size: 9px; }

  /* Tiles + Alerts 1-spaltig / kompakter. */
  .ah-tile-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .ah-tile { padding: 12px 13px; }
  .ah-tile-value { font-size: 24px; }
  .ah-dash-title { font-size: 15px; }
  .ah-alert { font-size: 12px; padding: 9px 11px; align-items: flex-start; }
  .ah-alert-text { overflow-wrap: anywhere; min-width: 0; }
}

@media (max-width: 380px) {
  .ah-content { padding: 12px 10px 22px; }
  /* Sehr schmal: alles einspaltig, Werte weiter verkleinern. */
  .ah-kpi-grid { grid-template-columns: 1fr; }
  .ah-kpi-value { font-size: 22px; }
  .ah-tile-grid { grid-template-columns: 1fr; }
  .ah-tile-value { font-size: 26px; }
  .ah-table { font-size: 10.5px; }
  .ah-table th, .ah-table td { padding: 5px 6px; }
  .ah-section-title { font-size: 12px; }
}

