/* =========================================================
   LKM Performance Dashboard — Extraordinary Edition
   Design System v5 (Animations-Upgrade)
   ========================================================= */

:root {
  /* Kernfarben — aus LKM Brand */
  --color-dark:         #403832;
  --color-orange:       #EC6B3C;
  --color-orange-hover: #D45A2C;
  --color-white:        #FFFFFF;

  /* Hintergründe */
  --color-bg:           #F7F5F3;
  --color-surface:      #FFFFFF;
  --color-border:       #E8E2DC;

  /* Text */
  --color-text:         #403832;
  --color-text-muted:   #9B8E87;
  --color-text-light:   #FFFFFF;

  /* KPI-Semantik */
  --color-success:      #4A8C5C;
  --color-warning:      #EC6B3C;

  /* Geometrie */
  --radius:             8px;
  --radius-pill:        50px;

  /* Easing */
  --ease-snap:          cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- Reset ---------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', sans-serif;
}

html, body {
  min-height: 100%;
}

body {
  font-weight: 400;
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden; /* sonst scrollen die Morph-Kreise horizontal */
}

/* ---------- Animation 1: Morphing Background ---------- */
body::before,
body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  will-change: transform;
}

body::before {
  width: 600px;
  height: 600px;
  top: -200px;
  left: -200px;
  background: radial-gradient(
    circle,
    rgba(236, 107, 60, 0.06) 0%,
    transparent 70%
  );
  animation: morphFloat1 30s ease-in-out infinite;
}

body::after {
  width: 500px;
  height: 500px;
  bottom: -150px;
  right: -150px;
  background: radial-gradient(
    circle,
    rgba(64, 56, 50, 0.05) 0%,
    transparent 70%
  );
  animation: morphFloat2 40s ease-in-out infinite;
}

@keyframes morphFloat1 {
  0%   { transform: translate(0px, 0px) scale(1); }
  33%  { transform: translate(80px, 60px) scale(1.1); }
  66%  { transform: translate(-40px, 80px) scale(0.95); }
  100% { transform: translate(0px, 0px) scale(1); }
}

@keyframes morphFloat2 {
  0%   { transform: translate(0px, 0px) scale(1); }
  33%  { transform: translate(-60px, -80px) scale(1.05); }
  66%  { transform: translate(40px, -40px) scale(1.1); }
  100% { transform: translate(0px, 0px) scale(1); }
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 32px;
  background: var(--color-dark);

  opacity: 0;
  transform: translateY(20px);
  animation: fadeUp 400ms var(--ease-snap) 0ms both;
}

.logo {
  display: flex;
  align-items: center;
}

.logo-bold {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 2px;
  color: var(--color-white);
  line-height: 1;
}

/* Vertikaler Trennstrich zwischen Logo und Subtitel */
.logo-bold::after {
  content: '';
  display: inline-block;
  width: 1px;
  height: 18px;
  margin: 0 12px;
  background: var(--color-white);
  opacity: 0.3;
  vertical-align: middle;
}

.logo-light {
  font-weight: 400;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
  line-height: 1;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Dropdown (auf dunklem Header) */
#kundenSelect {
  font-weight: 500;
  font-size: 14px;
  padding: 8px 36px 8px 16px;
  background-color: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--color-white);
  border-radius: var(--radius);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='rgba(255,255,255,0.7)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M4 6l4 4 4-4'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

#kundenSelect:hover {
  background-color: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
}

#kundenSelect:focus {
  outline: none;
  border-color: var(--color-orange);
}

#kundenSelect option {
  background: var(--color-dark);
  color: var(--color-white);
}

/* Upload-Button — Primär, Orange */
.file-upload {
  position: relative;
  display: inline-block;
}

.file-upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-upload span {
  display: inline-block;
  padding: 10px 20px;
  background: var(--color-orange);
  color: var(--color-white);
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
}

.file-upload:hover span {
  background: var(--color-orange-hover);
  transform: translateY(-1px);
}

.file-upload:focus-within span {
  outline: 2px solid var(--color-white);
  outline-offset: 2px;
}

/* Export-Button — Ghost auf dunklem Header */
.export-btn {
  font-weight: 500;
  font-size: 13px;
  padding: 10px 20px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.6);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
}

.export-btn:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.5);
  color: var(--color-white);
}

.export-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.export-btn:focus-visible {
  outline: 2px solid var(--color-orange);
  outline-offset: 2px;
}

/* ---------- Main Layout ---------- */
.dashboard {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px;
}

/* ---------- State-Toggle: Empty vs. Loaded ---------- */
.dashboard[data-state="empty"] .kpi-grid,
.dashboard[data-state="empty"] .chart-grid {
  display: none;
}

.dashboard[data-state="loaded"] .empty-state {
  display: none;
}

/* ---------- Mode-Toggle: Performance vs. Zeitersparnis ----------
   Das inaktive Mode-Grid wird komplett aus dem Flow genommen, damit
   die Animations-Delays (:nth-child) nur auf den sichtbaren Cards
   laufen. Default (kein data-mode gesetzt): Zeitersparnis-Grids
   versteckt, Performance sichtbar. */
.dashboard:not([data-mode="zeitersparnis"]) .mode-zeitersparnis {
  display: none;
}

.dashboard[data-mode="zeitersparnis"] .mode-performance {
  display: none;
}

/* Grüner Akzent auf den KPI-Cards im Zeitersparnis-Mode — überschreibt
   den orangen border-top aus .kpi-card. */
.dashboard[data-mode="zeitersparnis"] .kpi-card {
  border-top-color: var(--color-success);
}

/* ---------- Empty State ---------- */
.empty-state {
  position: relative;
  z-index: 1;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 80px 40px;
  text-align: center;
  max-width: 560px;
  margin: 60px auto;

  opacity: 0;
  transform: translateY(20px);
  animation: fadeUp 600ms var(--ease-snap) 150ms both;
}

.empty-state-badge {
  display: inline-block;
  background: var(--color-dark);
  color: var(--color-white);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 3px;
  padding: 6px 16px;
  border-radius: 4px;
  margin-bottom: 32px;
}

.empty-state-headline {
  font-weight: 800;
  font-size: 32px;
  line-height: 1.2;
  color: var(--color-text);
  margin-bottom: 12px;
}

.empty-state-text {
  font-weight: 400;
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text-muted);
  max-width: 380px;
  margin: 0 auto 32px;
}

.empty-state-btn {
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 14px 36px;
  background: var(--color-orange);
  color: var(--color-white);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
}

.empty-state-btn:hover {
  background: var(--color-orange-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(236, 107, 60, 0.3);
}

.empty-state-btn:focus-visible {
  outline: 2px solid var(--color-dark);
  outline-offset: 3px;
}

.empty-state-hint {
  font-weight: 400;
  font-size: 13px;
  color: var(--color-text-muted);
  max-width: 380px;
  margin: 16px auto 0;
}

/* ---------- KPI Grid ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
  position: relative;
  z-index: 1;
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 3px solid var(--color-orange);
  border-radius: var(--radius);
  padding: 24px;

  /* Animation 3: Staggered Card Reveal (direkt auf dem Element) */
  opacity: 0;
  transform: translateY(24px);
  animation: cardReveal 900ms var(--ease-snap) both;
}

.kpi-card:nth-child(1) { animation-delay: 200ms; }
.kpi-card:nth-child(2) { animation-delay: 400ms; }
.kpi-card:nth-child(3) { animation-delay: 600ms; }
.kpi-card:nth-child(4) { animation-delay: 800ms; }

.kpi-label {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.kpi-value {
  font-weight: 800;
  font-size: 40px;
  line-height: 1;
  color: var(--color-text);
}

/* Trend-Card: positive/negative Farbgebung via data-direction
   (das Attribut wird von dashboard.js gesetzt) */
#kpiTrend[data-direction="up"] {
  color: var(--color-success);
}

#kpiTrend[data-direction="down"] {
  color: var(--color-warning);
}

/* ---------- Chart Grid ---------- */
.chart-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  z-index: 1;
}

.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 28px 32px;
  width: 100%;

  /* Chart-Container blendet sanft nach den KPIs ein; das
     Draw-On der Datenreihen selbst läuft parallel in Chart.js. */
  opacity: 0;
  transform: translateY(20px);
  animation: fadeUp 700ms var(--ease-snap) both;
}

.chart-grid .chart-card:nth-child(1) { animation-delay: 1000ms; }
.chart-grid .chart-card:nth-child(2) { animation-delay: 1400ms; }
.chart-grid .chart-card:nth-child(3) { animation-delay: 1800ms; }

.chart-title {
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--color-text-muted);
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 24px;
}

.chart-canvas-wrapper {
  position: relative;
  width: 100%;
  height: 320px;
}

.chart-canvas-wrapper canvas {
  display: block;
}

/* ---------- Keyframes ---------- */

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardReveal {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Barrierefreiheit: bewegte Übergänge deaktivieren */
@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after,
  .site-header,
  .empty-state,
  .kpi-card,
  .chart-card {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* ---------- Responsive: 768px ---------- */
@media (max-width: 768px) {
  .site-header {
    flex-wrap: wrap;
    gap: 8px;
    height: auto;
    padding: 12px 16px;
  }

  .logo-bold {
    font-size: 18px;
  }

  .logo-bold::after {
    margin: 0 10px;
    height: 16px;
  }

  .logo-light {
    font-size: 12px;
  }

  .header-controls {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
  }

  #kundenSelect {
    flex: 1 1 160px;
    min-width: 0;
  }

  .dashboard {
    padding: 16px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
  }

  .kpi-card {
    padding: 18px 20px;
  }

  .kpi-value {
    font-size: 32px;
  }

  .chart-card {
    padding: 20px 16px;
  }

  .chart-canvas-wrapper {
    height: 260px;
  }

  .chart-title {
    font-size: 12px;
    margin-bottom: 20px;
  }

  .empty-state {
    padding: 56px 24px;
    margin: 24px auto;
  }

  .empty-state-headline {
    font-size: 26px;
  }

  .empty-state-text {
    font-size: 14px;
  }

  .empty-state-btn {
    padding: 12px 28px;
    font-size: 13px;
  }

  /* Morph-Kreise auf Mobile etwas kleiner — sonst beanspruchen
     sie auf schmalen Screens zu viel Viewport. */
  body::before {
    width: 400px;
    height: 400px;
  }

  body::after {
    width: 350px;
    height: 350px;
  }
}
