/* App-spezifische Styles. Tokens kommen aus /shared/style.css. */

main { max-width: 1400px; margin: 0 auto; padding: var(--sp-6); }

/* ---------- Header / Tabs / Period-Picker ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  padding: 0 var(--sp-6);
  height: 56px;
  gap: var(--sp-5);
}
.tabs { display: flex; gap: 4px; align-items: stretch; height: 100%; }
.tab {
  appearance: none; border: 0; background: transparent;
  padding: 0 16px; font: inherit; color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: flex; align-items: center;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--brand-2); font-weight: 600; }

.header-right { margin-left: auto; display: flex; align-items: center; gap: var(--sp-3); }
.period-picker-label {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.period-picker {
  appearance: none;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); padding: 6px 28px 6px 10px;
  font: inherit; font-size: 13px; color: var(--text); cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.period-picker:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(30,64,175,.12); }

/* ---------- Tab-Inhalte ---------- */
.tab-content { display: none; }
.tab-content.is-active { display: block; }

.empty-state {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-8) var(--sp-6); text-align: center;
  box-shadow: var(--shadow-sm);
}
.empty-state h2 { margin: 0 0 var(--sp-3); font-size: 18px; }
.empty-state p { margin: 0; color: var(--text-muted); }

.missing-banner {
  background: var(--warn-bg); border: 1px solid #fde68a; color: #78350f;
  padding: 10px 14px; border-radius: var(--r-sm); font-size: 13px;
  margin-bottom: var(--sp-4);
}

.section-title {
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em;
  margin: var(--sp-6) 0 10px;
}

/* ---------- KPI-Tiles ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: var(--sp-5); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.kpi-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.kpi-delta { font-size: 12px; margin-top: 2px; color: var(--text-muted); min-height: 16px; }
.kpi-delta.pos { color: var(--pos); }
.kpi-delta.neg { color: var(--neg); }

/* ---------- Filter (Button + Popover) ---------- */
.filter-control {
  position: relative; margin-bottom: var(--sp-4);
  display: flex; align-items: center; gap: 10px;
}
.filter-btn {
  appearance: none; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: inherit; font-size: 13px; font-weight: 500;
  padding: 8px 14px; border-radius: var(--r-sm); cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; box-shadow: var(--shadow-sm);
  transition: border-color .12s;
}
.filter-btn:hover, .filter-btn.open { border-color: var(--brand-2); }
.filter-btn-counter {
  background: var(--brand-2); color: #fff; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; font-variant-numeric: tabular-nums;
}
.filter-btn-arrow { color: var(--text-muted); transition: transform .12s; font-size: 10px; }
.filter-btn.open .filter-btn-arrow { transform: rotate(180deg); }
.filter-summary { font-size: 13px; color: var(--text-muted); }

.filter-popover {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 5;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  padding: 14px 16px; box-shadow: 0 8px 24px rgba(15,23,42,.12);
  min-width: 480px; max-width: 760px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.filter-popover.hidden { display: none; }
.filter-popover-header {
  flex-basis: 100%; display: flex; align-items: center; gap: 10px;
  margin-bottom: 4px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.filter-label {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.chip {
  appearance: none; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-muted); font: inherit; font-size: 12px; font-weight: 500;
  padding: 5px 11px; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .12s;
}
.chip:hover { border-color: var(--brand-2); color: var(--text); }
.chip.active { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.chip.active:hover { background: #1e3a8a; }
.chip-check { font-size: 10px; opacity: 0; transition: opacity .12s; }
.chip.active .chip-check { opacity: 1; }
.chip-action {
  appearance: none; border: 0; background: transparent; color: var(--brand-2);
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  padding: 4px 6px;
}
.chip-action:hover { text-decoration: underline; }

.loc-code {
  display: inline-block; padding: 1px 6px; min-width: 28px; text-align: center;
  background: var(--brand-soft); color: var(--brand-2);
  border-radius: 4px; font-size: 11px; font-weight: 700;
  margin-right: 8px; font-variant-numeric: tabular-nums;
  vertical-align: 1px;
}
.chip.active .loc-code { background: rgba(255,255,255,.2); color: #fff; }

/* ---------- Ranking ---------- */
.ranking {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 16px 18px; box-shadow: var(--shadow-sm);
  margin-bottom: var(--sp-5);
}
.ranking-row {
  display: grid; grid-template-columns: 200px 1fr 120px;
  gap: 12px; align-items: center; padding: 4px 0;
}
.ranking-name { font-size: 13px; color: var(--text); font-weight: 500; }
.ranking-bar-wrap { background: var(--surface-2); border-radius: 4px; height: 14px; overflow: hidden; }
.ranking-bar { height: 100%; background: linear-gradient(90deg, #1e40af, #3b82f6); border-radius: 4px; }
.ranking-bar.neg { background: linear-gradient(90deg, #dc2626, #f87171); }
.ranking-value { text-align: right; font-weight: 600; font-size: 13px; }

/* ---------- Tabelle ---------- */
.table-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  overflow: hidden; box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: right; font-size: 12px; font-weight: 600; color: var(--text-muted);
  padding: 12px 12px 10px; line-height: 1.35;
  background: #f8fafc; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap; vertical-align: top;
}
thead th:first-child, thead th.col-position, thead th.col-standort { text-align: left; }
thead th .sub { display: block; font-weight: 400; color: var(--text-soft); font-size: 11px; text-transform: none; letter-spacing: 0; margin-top: 2px; min-height: 14px; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
thead th.sorted { color: var(--brand-2); }
thead th .sort-arrow { display: inline-block; width: 10px; margin-left: 4px; opacity: .35; }
thead th.sorted .sort-arrow { opacity: 1; }

tbody td { padding: 9px 12px; border-bottom: 1px solid #f1f5f9; text-align: right; }
tbody td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.expandable { cursor: pointer; }
tbody tr.expandable:hover td { background: #f8fafc; }

/* VJV row variants */
tr.lvl-1 td:first-child { padding-left: 28px; color: var(--text); }
tr.aggregate td { font-weight: 600; background: #f8fafc; }
tr.aggregate td:first-child { color: var(--text); }
tr.result td { background: var(--info-bg); font-weight: 700; }
tr.result td:first-child { color: var(--brand-2); }
tr.final td { background: var(--brand-2); color: #fff; font-weight: 700; }
tr.final td:first-child { color: #fff; }
tr.subgroup td:first-child { color: var(--text-muted); font-size: 12px; padding-top: 14px; }

/* Δ%-Pille (inline neben dem Wert in Vergleichsspalten) */
.delta-pill {
  display: inline-block; margin-left: 8px;
  font-size: 11px; font-weight: 500;
  padding: 1px 7px; border-radius: 999px;
  white-space: nowrap; vertical-align: 1px;
}
.delta-pill.pos   { background: var(--pos-bg); color: var(--pos); }
.delta-pill.neg   { background: var(--neg-bg); color: var(--neg); }
.delta-pill.muted { color: var(--text-soft); }
tr.final .delta-pill.pos,
tr.final .delta-pill.neg,
tr.final .delta-pill.muted { background: rgba(255,255,255,.18); color: rgba(255,255,255,.92); }

/* Referenz-Spalten (Aktuell + YTD-Aktuell) — visuell hervorgehoben */
thead th.col-ref { color: var(--brand-2); background: var(--info-bg); }
thead th.col-ref .sub { color: var(--brand-2); }
tbody td.col-ref {
  background: var(--info-bg);
  border-left: 2px solid var(--brand-2); border-right: 2px solid var(--brand-2);
  font-weight: 600;
}
tr.aggregate td.col-ref { background: var(--brand-soft); }
tr.result td.col-ref    { background: #bfdbfe; }
tr.final td.col-ref     { background: #1e3a8a; border-color: #1e3a8a; }

.muted { color: var(--text-muted); }
.cell-empty { color: var(--text-soft); }

/* Caret + Aufschlag-Bar */
.caret { display: inline-block; width: 14px; color: var(--text-soft); font-size: 11px; transition: transform .12s; }
tr.open .caret { transform: rotate(90deg); color: var(--brand-2); }

.pct-cell { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.pct-bar { width: 60px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.pct-fill { height: 100%; background: var(--brand-2); border-radius: 3px; }
.pct-fill.warn { background: var(--warn); }
.pct-fill.neg  { background: var(--neg); }

/* Delta-Zelle */
.delta { font-size: 12px; }
.delta.pos { color: var(--pos); }
.delta.neg { color: var(--neg); }
.delta-arrow { display: inline-block; width: 10px; }

/* Detail-Drawer */
tr.detail-row { display: none; }
tr.detail-row.show { display: table-row; }
tr.detail-row td {
  background: #f8fafc; padding: 0;
}
.detail-inner {
  padding: 16px 24px 18px;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
}
.detail-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 12px 14px;
}
.detail-card.current { border-color: var(--brand-2); background: var(--brand-soft); }
.detail-card-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.detail-card-period { font-size: 12px; font-weight: 600; color: var(--text); margin-top: 2px; }
.detail-card-value { font-size: 18px; font-weight: 700; margin-top: 6px; }
.detail-card-line { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.detail-card-line span:last-child { font-weight: 600; color: var(--text); }

@media (max-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .detail-inner { grid-template-columns: repeat(2, 1fr); }
}

/* ======================== Mobile (< 700px) ======================== */
/* Layout-Idee: identische Inhalte wie Desktop. Allgemeine Header-Anpassungen
   (flex-wrap, brand klein, user-menu kompakt, app-nav full-width) liegen in
   shared/style.css. App-spezifisch hier: Tabs + Period-Picker. */
@media (max-width: 700px) {
  main { padding: var(--sp-3); }

  /* Mobile-Header NICHT sticky (iOS-Safari-Render-Bug bei sticky +
     flex-wrap + Multi-Row). Override muss hier in app.css stehen, weil
     shared/style.css vor app.css geladen wird und sonst der Default
     `position: sticky` (oben in dieser Datei) gewinnt. */
  .app-header {
    position: static;
    height: auto;
    padding: 8px 12px 10px;
    gap: 6px 8px;
  }

  /* `.header-right` aufloesen, damit Picker als direktes Flex-Item des
     Headers per `order` + `flex: 1 0 100%` in eine eigene Zeile rutscht. */
  .header-right { display: contents; }
  .period-picker-label { display: none; }

  /* Tabs als Zeile 2 — innerhalb des Header-Padding-Box, expliziter
     Background damit beim sticky-Scroll nichts durchscheint. */
  .tabs {
    order: 4;
    flex: 1 0 100%;
    margin: 6px 0 0;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    background: var(--surface);
  }
  .tab {
    flex: 1;
    justify-content: center;
    padding: 10px 8px;
    font-size: 13px;
    background: var(--surface);
  }

  /* Period-Picker als Zeile 3 — full-width, eigener Background */
  .period-picker {
    order: 5;
    flex: 1 0 100%;
    width: 100%;
    margin-top: 6px;
    padding: 8px 28px 8px 12px;
    font-size: 14px;
    background-color: var(--surface);
  }

  /* KPIs einspaltig statt 2x2, etwas kompakter */
  .kpi-row { grid-template-columns: 1fr; gap: 8px; }
  .kpi { padding: 10px 14px; }
  .kpi-value { font-size: 18px; }

  /* Tabellen: horizontaler Scroll, erste Spalte sticky links */
  .table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-card table { min-width: 640px; }
  thead th { padding: 10px 8px; font-size: 11px; }
  tbody td { padding: 8px 10px; font-size: 13px; }
  thead th:first-child,
  tbody td:first-child {
    position: sticky; left: 0; z-index: 1;
    box-shadow: 1px 0 0 var(--border);
  }
  thead th:first-child            { background: #f8fafc; }
  tbody td:first-child            { background: var(--surface); }
  tr.aggregate td:first-child     { background: #f8fafc; }
  tr.result td:first-child        { background: var(--info-bg); }
  tr.final td:first-child         { background: var(--brand-2); color: #fff; }
  tr.subgroup td:first-child      { background: var(--bg); }
  tr.expandable:hover td:first-child { background: #f8fafc; }
  tr.lvl-1 td:first-child { padding-left: 18px; }

  /* Δ%-Pille bei Mobile in eigene Zeile (sonst zu eng) */
  .delta-pill { display: block; margin-left: 0; margin-top: 3px; width: fit-content; margin-left: auto; }

  /* Filter-Popover: full-width statt 480px */
  .filter-popover {
    min-width: 0; max-width: none;
    left: 0; right: 0;
    width: calc(100vw - 24px);
    margin: 0 12px;
  }
  .filter-control { flex-wrap: wrap; }
  .filter-summary { font-size: 12px; }

  /* Ranking-Bar: kompakter, Name vor Bar in eigener Zeile */
  .ranking-row {
    grid-template-columns: 1fr auto;
    grid-template-areas: "name value" "bar bar";
    gap: 4px 12px;
  }
  .ranking-name { grid-area: name; font-size: 12px; }
  .ranking-value { grid-area: value; font-size: 12px; }
  .ranking-bar-wrap { grid-area: bar; height: 10px; }

  /* Detail-Drawer einspaltig, kompakter */
  .detail-inner { grid-template-columns: 1fr; padding: 12px; gap: 8px; }

  .section-title { margin: var(--sp-5) 0 8px; }
  .missing-banner { font-size: 12px; padding: 8px 12px; }
  .empty-state { padding: var(--sp-5) var(--sp-3); }
  .empty-state h2 { font-size: 16px; }
}
