/* ── CSS-Variablen & Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --imi-dark:   #05263d;
  --imi-navy:   #0b3c5d;
  --imi-teal:   #00bfae;
  --imi-teal-d: #00897b;
  --imi-bg:     #f8fafc;
  --imi-border: #d1dce6;
  --imi-muted:  #5a7080;
  --imi-light:  #e7f3fd;

  /* Tool-spezifisch */
  --chart-bg:   #ffffff;
  --stat-bg:    #f0f7ff;
  --stat-accent:#0b3c5d;
  --sidebar-w:  260px;
}

/* ── Base & Layout ───────────────────────────────────────────────────────── */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--imi-bg);
  color: #333;
  line-height: 1.6;
  font-size: 15px;
}
.container {
  max-width: 1200px;
  margin: 30px auto;
  padding: 0 20px;
}
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: linear-gradient(90deg, var(--imi-dark) 0%, var(--imi-navy) 100%);
  padding: 15px 25px;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.sitename {
  font-size: 24px;
  font-weight: 700;
  text-decoration: none;
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.sitename img { height: 32px; width: auto; }

/* ── Navigation / Breadcrumb ─────────────────────────────────────────────── */
.breadcrumb { margin-top: 8px; font-size: 12px; color: #cbd5e1; }
.breadcrumb a { color: #fff; text-decoration: none; }
.breadcrumb a:hover { color: var(--imi-teal); }
.back-link {
  display: inline-block;
  margin-bottom: 15px;
  text-decoration: none;
  color: var(--imi-navy);
  font-size: 14px;
  font-weight: 700;
}
.back-link:hover { color: var(--imi-teal-d); }

/* ── Intro-Box ───────────────────────────────────────────────────────────── */
.imi-intro {
  background: linear-gradient(90deg, var(--imi-light), #f4faff);
  border-left: 5px solid var(--imi-navy);
  padding: 24px 28px;
  border-radius: 4px;
  margin-bottom: 22px;
}
.imi-intro h2 { margin-bottom: 10px; color: var(--imi-navy); font-size: 20px; }
.imi-intro p  { font-size: 15px; color: #444; }

/* ── Content-Box ─────────────────────────────────────────────────────────── */
.content-box {
  background: #fff;
  border: 1px solid var(--imi-border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,.05);
  margin-bottom: 22px;
}
.box-header {
  background: var(--imi-navy);
  color: #fff;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.box-body { padding: 24px 28px; }

/* ── Formular-Elemente ───────────────────────────────────────────────────── */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--imi-muted);
  margin-bottom: 4px;
  margin-top: 14px;
}
label:first-of-type { margin-top: 0; }
input[type=text],
input[type=number],
select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--imi-border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: #333;
  transition: border .2s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--imi-navy);
  box-shadow: 0 0 0 3px rgba(11,60,93,.12);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  transition: all .2s;
  font-family: inherit;
  min-height: 44px;
}
.btn:focus-visible { outline: 3px solid var(--imi-teal); outline-offset: 2px; }
.btn-primary  { background: var(--imi-navy);  color: #fff; }
.btn-primary:hover  { background: #1565a0; }
.btn-outline  { background: #fff; color: var(--imi-navy); border: 2px solid var(--imi-navy); }
.btn-outline:hover  { background: var(--imi-navy); color: #fff; }
.btn-sm  { padding: 8px 14px; font-size: 13px; min-height: 40px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

/* ── Drop-Zone ───────────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--imi-border);
  border-radius: 10px;
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: #fafcff;
  position: relative;
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--imi-teal);
  background: #edfaf9;
}
.drop-zone:focus-visible {
  outline: 3px solid var(--imi-teal);
  outline-offset: 2px;
}
.drop-zone-icon {
  font-size: 48px;
  margin-bottom: 12px;
  color: var(--imi-teal);
  line-height: 1;
}
.drop-zone-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--imi-navy);
  margin-bottom: 6px;
}
.drop-zone-sub {
  font-size: 14px;
  color: var(--imi-muted);
  margin-bottom: 14px;
}
.drop-zone-formats {
  display: inline-block;
  background: var(--imi-navy);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  padding: 4px 14px;
  border-radius: 20px;
}

/* ── File Info & Error ───────────────────────────────────────────────────── */
.file-info {
  margin-top: 14px;
  padding: 12px 16px;
  background: #edfaf9;
  border-left: 4px solid var(--imi-teal);
  border-radius: 4px;
  font-size: 14px;
  color: var(--imi-navy);
  font-weight: 600;
}
.parse-error {
  margin-top: 14px;
  padding: 12px 16px;
  background: #fff0f0;
  border-left: 4px solid #ef5350;
  border-radius: 4px;
  font-size: 14px;
  color: #c62828;
  font-weight: 600;
}

/* ── Viz Layout (Sidebar + Chart) ────────────────────────────────────────── */
.viz-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 20px;
  align-items: start;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.control-sidebar {
  background: #fff;
  border: 1px solid var(--imi-border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.05);
  overflow: hidden;
  margin-bottom: 22px;
}
.sidebar-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--imi-border);
}
.sidebar-section:last-child { border-bottom: none; }
.sidebar-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--imi-muted);
  margin-bottom: 10px;
}
.sidebar-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--imi-border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: #333;
  cursor: pointer;
}
.sidebar-select:focus {
  outline: none;
  border-color: var(--imi-navy);
  box-shadow: 0 0 0 3px rgba(11,60,93,.12);
}
.sidebar-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--imi-border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  margin-top: 4px;
}
.sidebar-input:focus {
  outline: none;
  border-color: var(--imi-navy);
  box-shadow: 0 0 0 3px rgba(11,60,93,.12);
}
.hint {
  font-size: 10px;
  font-weight: 400;
  color: #999;
  text-transform: none;
  letter-spacing: 0;
}
.sub-label {
  font-size: 11px;
  color: var(--imi-muted);
  margin-top: 8px;
  display: block;
}

/* ── Chart Type Grid ─────────────────────────────────────────────────────── */
.chart-type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.chart-type-btn {
  padding: 8px 4px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  border: 1.5px solid var(--imi-border);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--imi-navy);
  cursor: pointer;
  transition: all .15s;
  min-height: 44px;
  text-align: center;
}
.chart-type-btn:hover {
  border-color: var(--imi-teal);
  background: #edfaf9;
}
.chart-type-btn.active,
.chart-type-btn[aria-pressed="true"] {
  background: var(--imi-navy);
  color: #fff;
  border-color: var(--imi-navy);
}
.chart-type-btn:focus-visible {
  outline: 3px solid var(--imi-teal);
  outline-offset: 2px;
}

/* ── Mode Badge ──────────────────────────────────────────────────────────── */
.mode-badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  background: var(--imi-light);
  color: var(--imi-navy);
  border: 1px solid var(--imi-border);
}
.mode-badge.auto { background: #edfaf9; color: var(--imi-teal-d); border-color: var(--imi-teal); }

/* ── Y-Axis List ─────────────────────────────────────────────────────────── */
.y-axis-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
  padding-right: 4px;
}
.y-axis-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 5px;
  background: #f8fafc;
  border: 1px solid var(--imi-border);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.y-axis-item:hover { background: #edfaf9; }
.y-axis-item input[type=checkbox] {
  width: 16px; height: 16px;
  cursor: pointer;
  accent-color: var(--imi-teal);
}
.y-axis-item label {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: #333;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.y-color-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Toggle ──────────────────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.toggle-label {
  font-size: 13px;
  color: #444;
  margin: 0;
  font-weight: 500;
}
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 22px;
  cursor: pointer;
  transition: .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--imi-teal); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }
.toggle input:focus-visible + .toggle-slider {
  outline: 3px solid var(--imi-teal);
  outline-offset: 2px;
}

/* ── Outlier Controls ────────────────────────────────────────────────────── */
.outlier-controls { margin-top: 12px; }

/* ── Chart Box ───────────────────────────────────────────────────────────── */
.chart-box-body {
  padding: 16px;
  position: relative;
  min-height: 340px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
#main-chart { max-width: 100%; }
.rows-badge {
  font-size: 11px;
  font-weight: 600;
  background: rgba(255,255,255,.2);
  padding: 2px 10px;
  border-radius: 12px;
  letter-spacing: .04em;
}
.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255,255,255,.85);
  font-size: 14px;
  color: var(--imi-muted);
  border-radius: 0 0 8px 8px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--imi-border);
  border-top-color: var(--imi-teal);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Stats Grid ──────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
}
.stat-card {
  background: var(--stat-bg);
  border-radius: 8px;
  padding: 14px 10px;
  text-align: center;
  border: 1px solid #d0e8f7;
}
.stat-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--imi-muted);
  margin-bottom: 6px;
}
.stat-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--stat-accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* ── Multi Stats ─────────────────────────────────────────────────────────── */
.multi-stats {
  margin-top: 14px;
  border-top: 1px solid var(--imi-border);
  padding-top: 14px;
}
.multi-series-stat {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 6px;
  background: #f8fafc;
  border-left: 4px solid var(--imi-teal);
}
.multi-series-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--imi-navy);
  margin-bottom: 6px;
}
.multi-series-vals {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--imi-muted);
}
.multi-series-vals span { font-weight: 600; color: #333; }

/* ── Data Preview Table ──────────────────────────────────────────────────── */
#data-preview table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
#data-preview th {
  background: var(--imi-navy);
  color: #fff;
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
#data-preview td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--imi-border);
  color: #333;
  white-space: nowrap;
}
#data-preview tr:nth-child(even) td { background: #f8fafc; }
#data-preview tr:hover td { background: #edfaf9; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  font-size: 13px;
  color: #64748b;
  margin-top: 40px;
  padding-bottom: 30px;
}
footer a { color: var(--imi-navy); text-decoration: none; margin: 0 10px; }
footer a:hover { color: var(--imi-teal-d); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .viz-layout {
    grid-template-columns: 1fr;
  }
  .control-sidebar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .sidebar-section:last-child,
  .sidebar-section:nth-last-child(2) {
    grid-column: span 1;
  }
}
@media (max-width: 680px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .control-sidebar {
    grid-template-columns: 1fr;
  }
  .box-body { padding: 16px; }
  .chart-type-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 420px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
