/* Finder KPI — Look „Midnight Glow“ (v12)
 * Dunkles Theme, AE = Blau, RA = Bernstein. Schrift Space Grotesk (lokal, OFL).
 * CSP: nur 'self' — keine externen Fonts, keine Inline-Styles. */
@font-face {
  font-family: "Space Grotesk";
  src: url("/static/fonts/space-grotesk.woff2") format("woff2");
  font-weight: 300 700; font-style: normal; font-display: swap;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  color-scheme: dark;
  --bg: #0A0E18; --card: #121828; --card-2: #182033;
  --line: rgba(255,255,255,0.08); --line-2: rgba(255,255,255,0.05);
  --ink: #E8ECF5; --ink-2: #C9D0DE; --muted: #A3ADC2; --faint: #8590A8;
  --ae: #4D8DFF; --ae-ink: #9DBBFF; --ae-soft: rgba(77,141,255,0.16); --ae-line: rgba(77,141,255,0.30);
  --ra: #FFB547; --ra-ink: #FFCB7A; --ra-soft: rgba(255,181,71,0.15); --ra-line: rgba(255,181,71,0.28);
  --up: #7FEBB8; --up-bg: rgba(61,220,151,0.14);
  --down: #FFB4A8; --down-bg: rgba(255,120,100,0.14);
  --ok: #3DDC97; --warn: #FBBF24; --err: #F87171;
  --radius: 22px; --radius-sm: 14px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --font: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body { font-family: var(--font); background: var(--bg); color: var(--ink); min-height: 100vh;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; position: relative; overflow-x: hidden; }
/* Glow im Hintergrund: fest positioniert, rein dekorativ */
body::before { content: ""; position: fixed; z-index: 0; pointer-events: none; top: -220px; left: -160px;
  width: 720px; height: 560px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(59,109,255,0.34), rgba(59,109,255,0.10) 55%, transparent);
}
body::after { content: ""; position: fixed; z-index: 0; pointer-events: none; top: -160px; right: -220px;
  width: 560px; height: 460px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(124,77,255,0.14), transparent);
}
.wrap { position: relative; z-index: 1; max-width: 1040px; margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom)); }
button { font: inherit; cursor: pointer; color: inherit; }
:focus-visible { outline: 2px solid var(--ae-ink); outline-offset: 2px; }
.num, .kpi-value, .cust-val { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- Header */
.header { margin-bottom: 16px; }
.header-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { height: 32px; width: auto; display: block; flex: none; filter: drop-shadow(0 0 10px rgba(0,159,227,0.55)); }
.brand-name { font-size: 11px; font-weight: 600; letter-spacing: 1.6px; text-transform: uppercase; color: var(--muted); }
.header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.15; }
.header .company { font-size: 11px; color: var(--faint); margin-top: 3px; letter-spacing: 0.3px; }
.user { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.user form { display: inline; }
.btn-ghost { background: rgba(255,255,255,0.06); color: var(--ink); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 14px; font-size: 12.5px; font-weight: 500; min-height: 36px;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease); }
.btn-ghost:hover { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.16); }

.tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin-top: 16px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--line); border-radius: 16px; padding: 4px; max-width: 460px; }
.tab { background: transparent; color: var(--muted); border: 0; border-radius: 12px; height: 42px;
  font-size: 14px; font-weight: 500; transition: background 0.25s var(--ease), color 0.25s var(--ease), transform 0.15s var(--ease); }
.tab:hover { color: var(--ink); }
.tab:active { transform: scale(0.97); }
.tab[aria-selected="true"] { background: var(--ink); color: var(--bg); font-weight: 600;
  box-shadow: 0 4px 18px rgba(232,236,245,0.18); }

.navbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
.nav-center { display: flex; align-items: center; gap: 8px; min-width: 0; }
.nav-btn { background: rgba(255,255,255,0.04); color: var(--ink); border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px; width: 44px; height: 44px; font-size: 20px; line-height: 1; flex: none; display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.2s var(--ease), transform 0.15s var(--ease); }
.nav-btn:hover:not(:disabled) { background: rgba(255,255,255,0.10); }
.nav-btn:active:not(:disabled) { transform: scale(0.94); }
.nav-btn:disabled { opacity: 0.3; cursor: default; }
.subtitle { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.date-pick { position: relative; flex: none; }
.date-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; color-scheme: dark; }
.fresh { font-size: 12px; color: var(--muted); margin-top: 12px; display: inline-flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; max-width: 100%; }
.fresh span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; box-shadow: 0 0 10px var(--ok); }
.dot.warn { background: var(--warn); box-shadow: 0 0 10px var(--warn); }
.dot.err { background: var(--err); box-shadow: 0 0 10px var(--err); }

/* ---------------------------------------------------------------- Banner */
.banner { border-radius: var(--radius-sm); padding: 12px 16px; font-size: 13px; margin-bottom: 14px; display: none; line-height: 1.5; }
.banner.show { display: block; }
.banner.warn { background: rgba(251,191,36,0.10); border: 1px solid rgba(251,191,36,0.35); color: #FDE68A; }
.banner.err { background: rgba(248,113,113,0.10); border: 1px solid rgba(248,113,113,0.40); color: #FECACA; }

/* ---------------------------------------------------------------- KPI-Karten */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 14px; }
.kpi-card { position: relative; border-radius: var(--radius); padding: 18px 20px 16px; overflow: hidden;
  border: 1px solid var(--line); background: var(--card); }
.kpi-card.ae { background: linear-gradient(160deg, var(--ae-soft), rgba(18,24,40,0.92) 58%); border-color: var(--ae-line); }
.kpi-card.ra { background: linear-gradient(160deg, var(--ra-soft), rgba(18,24,40,0.92) 58%); border-color: var(--ra-line); }
.kpi-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }
.kpi-card.ae .kpi-label { color: var(--ae-ink); } .kpi-card.ra .kpi-label { color: var(--ra-ink); }
.kpi-value { font-size: 42px; font-weight: 700; margin-top: 8px; letter-spacing: -1.8px; line-height: 1.05; color: var(--ink); }
.kpi-sub { font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { font-size: 12px; background: rgba(255,255,255,0.06); color: var(--ink-2); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.chip b { font-weight: 700; }
.chip .up { color: var(--up); } .chip .down { color: var(--down); }
.spark { display: block; width: 100%; height: auto; max-height: 96px; margin-top: 12px; overflow: visible; }
main.anim .spark-dot { animation: fadein 1.3s ease-in; }

.data-note { font-size: 12px; color: var(--muted); background: rgba(255,255,255,0.03); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 14px; line-height: 1.55; }
.data-note strong, .data-note b { color: var(--ink-2); }

/* ---------------------------------------------------------------- Sektionen */
.two-col { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 14px; }
.section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; }
.two-col .section { margin-bottom: 0; }
.section h2 { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 14px; letter-spacing: -0.2px; }
.section h2.ae { color: var(--ae-ink); } .section h2.ra { color: var(--ra-ink); }
.chart-container { position: relative; height: 250px; }
.chart-container.small { height: 210px; }

.cust { margin-bottom: 13px; }
.cust:last-child { margin-bottom: 0; }
.cust-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.cust-name { font-size: 14px; font-weight: 500; color: var(--ink); min-width: 0; overflow-wrap: anywhere; }
.cust-num { font-size: 11px; color: var(--faint); font-weight: 400; margin-left: 6px; }
.cust-val { font-size: 14px; font-weight: 600; white-space: nowrap; color: var(--ink); }
.cust-bar { height: 5px; border-radius: 5px; background: rgba(255,255,255,0.06); overflow: hidden; }
.cust-bar > div { height: 100%; border-radius: 5px; transform-origin: left center; }
.ae .cust-bar > div { background: linear-gradient(90deg, #2F6BEB, var(--ae)); box-shadow: 0 0 10px rgba(77,141,255,0.45); }
.ra .cust-bar > div { background: linear-gradient(90deg, #F59E0B, var(--ra)); box-shadow: 0 0 10px rgba(255,181,71,0.40); }
.empty { font-size: 13px; color: var(--faint); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; padding: 10px 12px; color: var(--faint); font-weight: 600; text-transform: uppercase;
  font-size: 11px; letter-spacing: 0.8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.num, td.num { text-align: right; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); color: var(--ink-2); }
tbody tr { transition: background 0.15s var(--ease); }
tbody tr:hover td { background: rgba(255,255,255,0.025); }
td.lbl { white-space: nowrap; color: var(--ink); }
.sm { display: none; }
tr.total td { font-weight: 700; color: var(--ink); border-top: 1px solid rgba(255,255,255,0.16); border-bottom: 0; background: rgba(255,255,255,0.03); }
tr.off td { color: var(--faint); }
tr.off td.ae-cell, tr.off td.ra-cell { color: var(--faint); font-weight: 400; }
.ae-cell { color: var(--ae-ink); font-weight: 600; } .ra-cell { color: var(--ra-ink); font-weight: 600; }
.delta-pos { color: var(--up); } .delta-neg { color: var(--down); }
.tag-hol { font-size: 11px; color: var(--faint); margin-left: 6px; }

.assessment { background: linear-gradient(160deg, rgba(124,77,255,0.10), var(--card) 60%); }
.assessment h2 { color: var(--ink); }
.assessment p { font-size: 14px; line-height: 1.65; color: var(--ink-2); }
.assessment p + p { margin-top: 8px; }

.loading { text-align: center; color: var(--faint); padding: 48px 0; font-size: 14px; }
.foot { text-align: center; font-size: 11px; color: var(--faint); margin-top: 8px; }

/* ---------------------------------------------------------------- Animationen
 * Nur beim Wechsel von Ansicht/Datum (Klasse .anim am <main>), nicht beim Auffrischen.
 * Detail-Animationen ohne Verzoegerung/fill: startet eine nicht, bleibt das Element sichtbar. */
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes draw { from { stroke-dasharray: var(--len, 1000); stroke-dashoffset: var(--len, 1000); }
  to { stroke-dasharray: var(--len, 1000); stroke-dashoffset: 0; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
main.anim > * { animation: rise 0.5s var(--ease) both; }
main.anim > *:nth-child(2) { animation-delay: 0.06s; }
main.anim > *:nth-child(3) { animation-delay: 0.12s; }
main.anim > *:nth-child(4) { animation-delay: 0.18s; }
main.anim > *:nth-child(n+5) { animation-delay: 0.24s; }
main.anim .cust-bar > div { animation: grow 0.9s var(--ease); }
main.anim .spark-line { animation: draw 1.2s var(--ease); }
main.anim .spark-area { animation: fadein 1.4s ease-in; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------- Login */
.login-wrap { position: relative; z-index: 1; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: rgba(18,24,40,0.85); border: 1px solid var(--line);
  border-radius: 26px; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,0.45); animation: rise 0.6s var(--ease) both; }
.login-card .header { margin: 0; padding: 28px 24px 4px; text-align: center; }
.login-card .logo { height: 54px; margin: 0 auto 16px; }
.login-card .header h1 { font-size: 26px; }
.login-card .header .company { font-size: 12px; color: var(--muted); margin-top: 6px; }
.login-card form { padding: 22px 24px 26px; display: grid; gap: 16px; }
.login-card label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; display: grid; gap: 8px; }
.login-card input { font: inherit; font-size: 16px; padding: 13px 14px; background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 12px; color: var(--ink); text-transform: none; letter-spacing: 0; font-weight: 400;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease); }
.login-card input:focus { outline: none; border-color: var(--ae); background: rgba(77,141,255,0.08); box-shadow: 0 0 0 3px rgba(77,141,255,0.22); }
.btn-primary { background: var(--ink); color: var(--bg); border: 0; border-radius: 12px; padding: 14px; font-weight: 700; font-size: 15px;
  margin-top: 4px; transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease); box-shadow: 0 6px 24px rgba(232,236,245,0.16); }
.btn-primary:hover { box-shadow: 0 8px 30px rgba(232,236,245,0.26); }
.btn-primary:active { transform: scale(0.98); }
.error { background: rgba(248,113,113,0.10); border: 1px solid rgba(248,113,113,0.40); color: #FECACA; border-radius: 12px; padding: 11px 13px; font-size: 13px; }

[hidden] { display: none !important; }

/* ---------------------------------------------------------------- Admin (Benutzerverwaltung) */
a.btn-ghost { text-decoration: none; display: inline-flex; align-items: center; }
.btn-sm { min-height: 30px; padding: 5px 12px; font-size: 12px; }
.banner.ok { background: var(--up-bg); border: 1px solid rgba(61,220,151,0.35); color: var(--up); }
.admin-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; max-width: 720px; }
.admin-form label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; display: grid; gap: 8px; }
.admin-form .opt { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--faint); }
.admin-form input { font: inherit; font-size: 16px; padding: 12px 14px; background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 12px; color: var(--ink); letter-spacing: 0; font-weight: 400; }
.admin-form input:focus { outline: none; border-color: var(--ae); background: rgba(77,141,255,0.08); box-shadow: 0 0 0 3px rgba(77,141,255,0.22); }
.admin-form .admin-hint, .admin-form .btn-primary { grid-column: 1 / -1; }
.admin-form .btn-primary { justify-self: start; padding: 12px 22px; }
.admin-hint { font-size: 13px; color: var(--muted); }
.admin-hint code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--ink); background: rgba(255,255,255,0.06);
  padding: 2px 8px; border-radius: 6px; user-select: all; overflow-wrap: anywhere; }
.admin-confirm { border-color: rgba(248,113,113,0.45); }
.admin-confirm p { font-size: 14px; color: var(--ink-2); line-height: 1.5; }
.admin-actions { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.btn-danger { background: var(--err); color: #1A0606; border: 0; border-radius: 12px; padding: 11px 20px; font-weight: 700; font-size: 14px; }
.btn-danger:hover { filter: brightness(1.08); }
.admin-table td { vertical-align: middle; }
.admin-head .header-top { flex-wrap: wrap; }
@media (max-width: 640px) { .admin-form { grid-template-columns: 1fr; } .admin-form .btn-primary { justify-self: stretch; }
  .admin-head .user { margin-left: auto; } }

/* ---------------------------------------------------------------- AE/RA-Umschalter: nur auf dem Handy */
.kpi-switch { display: none; }
.kpi-btn { flex: 1; border: 0; border-radius: 10px; height: 40px; font-size: 13.5px; font-weight: 600;
  background: transparent; color: var(--muted); transition: background 0.25s var(--ease), color 0.25s var(--ease); }
.kpi-btn.ae[aria-pressed="true"] { background: var(--ae); color: #fff; box-shadow: 0 4px 16px rgba(77,141,255,0.40); }
.kpi-btn.ra[aria-pressed="true"] { background: var(--ra); color: #1A1206; box-shadow: 0 4px 16px rgba(255,181,71,0.35); }

@media (max-width: 640px) {
  .wrap { padding: calc(14px + env(safe-area-inset-top)) 14px calc(24px + env(safe-area-inset-bottom)); }
  .logo { height: 28px; }
  .header h1 { font-size: 19px; }
  .header .company { display: none; }
  .tabs { max-width: none; }
  .kpi-switch { display: flex; gap: 4px; margin-top: 8px; background: rgba(255,255,255,0.05);
    border: 1px solid var(--line); padding: 4px; border-radius: 14px; }
  body[data-kpi="ae"] .kpi-card.ra, body[data-kpi="ae"] .section.ra,
  body[data-kpi="ae"] .ra-cell, body[data-kpi="ae"] .ra-col { display: none; }
  body[data-kpi="ra"] .kpi-card.ae, body[data-kpi="ra"] .section.ae,
  body[data-kpi="ra"] .ae-cell, body[data-kpi="ra"] .ae-col { display: none; }
  .kpi-grid, .two-col { grid-template-columns: 1fr; gap: 12px; }
  .kpi-value { font-size: 40px; }
  .section { padding: 16px 16px; }
  .kpi-card { padding: 16px 18px 14px; }
  th, td { padding: 9px 8px; }
  .lg { display: none; } .sm { display: inline; }
  td.lbl { white-space: normal; line-height: 1.3; }
  td.lbl .tag-hol { display: block; margin-left: 0; }
  .section .table-wrap { margin: 0 -4px; }
  .hide-sm { display: none; }
  .chart-container { height: 220px; }
  .subtitle { font-size: 15px; }
}
@media print {
  :root { color-scheme: light; }
  body::before, body::after { display: none; }
  .tabs, .nav-btn, .user, .date-pick, .kpi-switch { display: none !important; }
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
