/* 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.final td.delta-cell .delta { color: rgba(255,255,255,.85) !important; }
tr.subgroup td:first-child { color: var(--text-muted); font-size: 12px; padding-top: 14px; }

.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); }
}
