/* Ruhiges, industrietaugliches Design. Ampelfarben nur funktional einsetzen. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #dde1e6;
  --text: #1f2933;
  --text-muted: #5f6b7a;
  --primary: #1f4e79;
  --primary-soft: #e8eef5;
  --ok: #2e7d4f;
  --ok-soft: #e6f2ea;
  --warn: #b7791f;
  --warn-soft: #fbf3e2;
  --crit: #b42318;
  --crit-soft: #fbe9e7;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); }

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; flex-direction: column; }
.brand-name { font-size: 18px; font-weight: 650; }
.brand-sub { font-size: 13px; color: var(--text-muted); }
.meta { font-size: 13px; color: var(--text-muted); text-align: right; }
.meta .badge { margin-left: 8px; }

.app-nav {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.app-nav a {
  padding: 12px 14px;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-weight: 500;
}

.app-nav a:hover { color: var(--text); }
.app-nav a[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); }

.app-main {
  flex: 1;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 24px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.lead { color: var(--text-muted); margin: 0 0 20px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-crit { background: var(--crit-soft); color: var(--crit); }

.notice {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 16px;
}
.notice-error { border-color: var(--crit); background: var(--crit-soft); }
.notice-warn { border-color: var(--warn); background: var(--warn-soft); }

.state-loading, .state-empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--text-muted);
}

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
table.data th { color: var(--text-muted); font-weight: 600; font-size: 13px; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

details summary { cursor: pointer; color: var(--text-muted); font-size: 14px; }
.data-status p { font-size: 13px; color: var(--text-muted); margin: 12px 0 0; }
.data-status table { margin-top: 12px; }

/* KPI-Kacheln: farbiger Rand links = Ampel, sonst neutral */
.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 1024px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .tiles { grid-template-columns: 1fr; } }
.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  min-height: 118px;
}
a.tile:hover { border-color: var(--primary); }
a.tile:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.tile-ok { border-left-color: var(--ok); }
.tile-warn { border-left-color: var(--warn); }
.tile-crit { border-left-color: var(--crit); }
.tile-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.tile-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.tile-value { font-size: 28px; font-weight: 650; line-height: 1.2; }
.tile-sub { font-size: 13px; color: var(--text-muted); }

/* Filterzeile: eine Zeile ueber allen Inhalten, die sie betrifft */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
  margin-bottom: 20px;
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.field-grow { flex: 1 1 260px; }
.field input, .field select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  min-height: 36px;
}
.field input:focus-visible, .field select:focus-visible, .btn-link:focus-visible, button.sort:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.btn-link {
  font: inherit;
  font-size: 14px;
  background: none;
  border: 0;
  color: var(--primary);
  cursor: pointer;
  padding: 8px 4px;
}
.btn-link:hover { text-decoration: underline; }

/* Diagramme */
.chart { position: relative; width: 100%; }
/* Feste Diagrammhoehen als Klassen (keine Inline-Styles, damit eine strikte CSP moeglich ist) */
.chart-h240 { height: 240px; }
.chart-h260 { height: 260px; }
.chart-h320 { height: 320px; }
.chart-h360 { height: 360px; }
.chart-fallback { padding: 32px 8px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table.data-sortable th { padding: 0; white-space: nowrap; }
button.sort {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 8px 10px;
  width: 100%;
  text-align: inherit;
  cursor: pointer;
}
button.sort:hover { color: var(--text); }
table.data tbody tr:hover { background: #f8f9fb; }
table.data tr.row-crit { background: var(--crit-soft); }
table.data tr.row-crit:hover { background: #f7dcd8; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; white-space: nowrap; }
.unit { color: var(--text-muted); font-size: 12px; }
.flag {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 50%;
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 700;
  font-size: 11px;
}
.flag-text { color: var(--crit); font-weight: 600; }

/* Einkauf */
.card-alert { border-left: 4px solid var(--crit); }
.chart-note { font-size: 13px; color: var(--text-muted); margin: -4px 0 12px; }
.chart-note.note-warn strong { color: var(--warn); }
.trend { white-space: nowrap; color: var(--text-muted); }
.trend-down { color: var(--crit); font-weight: 600; }
.trend-up { color: var(--ok); font-weight: 600; }
.muted { color: var(--text-muted); }
.badge-muted { background: #eef0f3; color: var(--text-muted); }

/* Kopfzeile: Aktionen */
.header-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: flex-end; }
.btn-primary, .btn-secondary {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  padding: 7px 14px;
  min-height: 36px;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; border: 1px solid var(--primary); }
.btn-primary:hover { background: #173d60; }
.btn-secondary { background: var(--surface); color: var(--primary); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); }
.btn-icon { font: inherit; font-size: 22px; line-height: 1; background: none; border: 0; cursor: pointer; color: var(--text-muted); padding: 4px 8px; }
.btn-primary:focus-visible, .btn-secondary:focus-visible, .btn-icon:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.error-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  background: var(--crit-soft);
  border-bottom: 1px solid var(--crit);
  font-size: 14px;
}
.error-banner[hidden] { display: none; }

/* Upload-Dialog */
.upload-dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  color: var(--text);
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.18);
}
.upload-dialog::backdrop { background: rgba(16, 24, 40, 0.45); }
.upload-dialog h3 { font-size: 15px; margin: 20px 0 4px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; }
.privacy { font-size: 14px; background: var(--primary-soft); border-radius: 6px; padding: 10px 12px; }
#upload-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  text-align: center;
  padding: 24px 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
}
.dropzone strong { color: var(--text); font-size: 15px; }
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }
#upload-input:focus-visible + .dropzone { outline: 2px solid var(--primary); outline-offset: 2px; }
.upload-results { list-style: none; padding: 0; margin: 12px 0 0; }
.upload-results li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.templates { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.state-empty h2 { color: var(--text); }

/* Hinweise (Modul E) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.chip {
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.chip-n { opacity: 0.7; margin-left: 2px; }
.insights { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
@media (max-width: 900px) { .insights { grid-template-columns: 1fr; } }
.insight {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.insight-crit { border-left-color: var(--crit); }
.insight-warn { border-left-color: var(--warn); }
.insight-ok { border-left-color: var(--ok); }
.insight-head { display: flex; align-items: center; gap: 10px; }
.insight-cat { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.insight h3 { font-size: 16px; margin: 4px 0 0; line-height: 1.35; }
.insight p { margin: 0; font-size: 14px; }
.insight-rec { background: #f6f7f9; border-radius: 6px; padding: 8px 10px; margin-top: 4px !important; }
.insight .action-link { margin-top: 4px; align-self: flex-start; }
.teaser { display: flex; justify-content: space-between; align-items: center; gap: 16px; text-decoration: none; color: inherit; }
a.teaser:hover { border-color: var(--primary); }
.teaser-label { font-size: 13px; color: var(--text-muted); }
.teaser-title { font-weight: 600; }

/* Handlungsbedarf */
.actions { list-style: none; margin: 0; padding: 0; }
.action {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.action:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.action-crit .dot { background: var(--crit); }
.action-warn .dot { background: var(--warn); }
.action-body { flex: 1; min-width: 0; }
.action-title { font-weight: 600; }
.action-detail { font-size: 13px; color: var(--text-muted); }
.action-link { font-size: 13px; white-space: nowrap; text-decoration: none; margin-top: 2px; }
.action-link:hover { text-decoration: underline; }
details ul { margin: 8px 0 0; padding-left: 20px; font-size: 13px; }

@media (max-width: 640px) {
  .app-header, .app-nav, .app-main, .app-footer { padding-left: 16px; padding-right: 16px; }
  .meta { text-align: left; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media print {
  .app-nav { display: none; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
