:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-soft: #f7f9fc;
  --text: #162033;
  --muted: #647184;
  --line: #cfd7e3;
  --line-soft: #e2e7ef;
  --primary: #256db2;
  --primary-dark: #19558f;
  --primary-soft: #e8f2fd;
  --danger: #b73838;
  --danger-soft: #faeaea;
  --success: #21784f;
  --warning: #a86a0b;
  --radius-lg: 10px;
  --radius-md: 7px;
  --radius-sm: 5px;
  --shadow: 0 8px 24px rgba(25, 43, 70, .08);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  --bg: #111821;
  --panel: #182231;
  --panel-soft: #202c3d;
  --text: #eef4fb;
  --muted: #aab6c7;
  --line: #354458;
  --line-soft: #2a3648;
  --primary: #7db8ff;
  --primary-dark: #9ac8ff;
  --primary-soft: rgba(125, 184, 255, .13);
  --danger: #ff8b8b;
  --danger-soft: rgba(255, 139, 139, .12);
  --success: #7ed6a9;
  --warning: #ffd07c;
  --shadow: 0 8px 24px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.35;
  background: var(--bg);
}
button, input, select, textarea { font: inherit; }
button, label.file-btn { user-select: none; }
button { cursor: pointer; }

.app-shell {
  width: min(1500px, calc(100% - 18px));
  margin: 0 auto;
  padding: 10px 0 28px;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(130px, .7fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-right: 6px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.brand-compact { width: auto; min-width: 0; }
.topbar .brand-compact { display: inline-flex; align-items: center; justify-content: center; padding-right: 0; }
.topbar .brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  margin: 0;
  border: 0;
  outline: 0;
  border-radius: 9px;
  background: transparent !important;
  box-shadow: none !important;
  overflow: visible;
  line-height: 0;
  transform: none !important;
  transition: none !important;
}
.topbar .brand-logo svg {
  display: block;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .22);
}
.topbar .brand-logo:hover,
.topbar .brand-logo:active,
.topbar .brand-logo:focus {
  transform: none !important;
  box-shadow: none !important;
  background: transparent !important;
}
.topbar .brand-logo:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.topbar .brand-logo:hover svg { transform: none !important; }

.title-block h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1;
  letter-spacing: -.04em;
  text-transform: lowercase;
}
.title-block p {
  margin: 3px 0 0;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}
.toolbar, .button-group, .modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
}
.btn {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--panel-soft);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { color: #fff; border-color: var(--primary-dark); background: var(--primary-dark); }
[data-theme="dark"] .btn.primary { color: #0b1724; border-color: var(--primary-dark); background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: rgba(183, 56, 56, .35); background: var(--danger-soft); }
.btn.small { min-height: 28px; padding: 0 9px; }

.layout { display: grid; gap: 10px; }
.card, .section-card, .hero, .kpi, .result-box, .source-details {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 320px);
  gap: 12px;
  align-items: stretch;
  padding: 12px;
}
.eyebrow { margin: 0 0 4px; color: var(--muted); font-weight: 900; letter-spacing: .06em; text-transform: uppercase; font-size: 11px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin: 0 0 5px; font-size: 1.65rem; line-height: 1.05; letter-spacing: -.04em; }
.lead { margin: 0; max-width: 900px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.hero-note { padding: 10px; border: 1px solid var(--line-soft); border-radius: var(--radius-md); background: var(--panel-soft); display: grid; gap: 4px; align-content: center; }
.hero-note strong { font-size: .95rem; }
.hero-note span { color: var(--muted); }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.kpi { padding: 10px; min-height: 88px; display: flex; flex-direction: column; justify-content: space-between; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi strong { font-size: 1.35rem; letter-spacing: -.04em; overflow-wrap: anywhere; }
.kpi small { color: var(--muted); font-size: 11px; }
.status-card.status-good { border-color: rgba(33,120,79,.45); background: color-mix(in srgb, var(--panel) 74%, rgba(33,120,79,.22)); }
.status-card.status-warn { border-color: rgba(168,106,11,.45); background: color-mix(in srgb, var(--panel) 74%, rgba(168,106,11,.20)); }
.status-card.status-bad { border-color: rgba(183,56,56,.45); background: var(--danger-soft); }

.section-card { padding: 10px; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.section-number { margin: 0 0 2px; color: var(--primary); font-weight: 900; letter-spacing: .08em; font-size: 11px; }
.section-head h2 { margin: 0; font-size: 1rem; line-height: 1.15; letter-spacing: -.02em; }
.section-help { margin: 0; color: var(--muted); max-width: 520px; line-height: 1.35; text-align: right; font-size: 12px; }

.choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.choice {
  display: block;
  min-height: 126px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px;
  background: var(--panel-soft);
  transition: border-color .16s ease, background .16s ease;
}
.choice:hover { border-color: var(--primary); }
.choice.is-active { background: var(--primary-soft); border-color: var(--primary); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-title { display: block; font-weight: 850; font-size: .98rem; margin-bottom: 6px; letter-spacing: -.02em; }
.choice-text { display: block; color: var(--muted); line-height: 1.35; font-size: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  background: var(--panel-soft);
}
.field.wide { grid-column: span 2; }
.field.required > span::after { content: " *"; color: var(--primary); }
.field > span { color: var(--muted); font-size: 11px; font-weight: 800; }
.field small { color: var(--muted); line-height: 1.3; font-size: 11px; }
input, select, textarea {
  width: 100%;
  min-height: 32px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--panel);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.unit-input { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.unit-input input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.unit-input span { display: grid; place-items: center; min-width: 50px; border: 1px solid var(--line); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--panel); color: var(--muted); padding: 0 8px; }
.notice { padding: 8px 10px; border-radius: var(--radius-md); border: 1px solid var(--line-soft); line-height: 1.35; margin-bottom: 8px; color: var(--muted); }
.notice.soft { background: var(--primary-soft); }
.model, .basis { display: none; }
.model.show, .basis.show { display: flex; }
.hide { display: none !important; }

.result-grid { display: grid; grid-template-columns: 1.35fr .8fr; gap: 8px; margin-bottom: 8px; }
.result-box { padding: 10px; background: var(--panel-soft); box-shadow: none; }
.result-box h3 { margin: 0 0 6px; font-size: .92rem; }
.explanation { color: var(--muted); line-height: 1.45; }
.rating { display: inline-flex; align-items: center; min-height: 30px; padding: 5px 9px; border-radius: var(--radius-sm); font-weight: 850; margin-bottom: 6px; border: 1px solid var(--line); }
.rating-neutral { background: var(--panel-soft); color: var(--muted); }
.rating-good { background: color-mix(in srgb, var(--panel) 80%, var(--success)); color: var(--success); }
.rating-warn { background: color-mix(in srgb, var(--panel) 78%, var(--warning)); color: var(--warning); }
.rating-bad { background: var(--danger-soft); color: var(--danger); }
#ratingText { color: var(--muted); line-height: 1.35; margin-bottom: 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 6px 7px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
th { color: var(--muted); background: var(--panel-soft); font-size: 11px; font-weight: 800; text-transform: none; letter-spacing: 0; }
tbody tr:hover { background: var(--primary-soft); }
tbody tr:last-child td { border-bottom: 0; }
td:nth-child(2) { font-weight: 780; white-space: nowrap; }
.source-details { margin-top: 8px; padding: 8px; background: var(--panel-soft); box-shadow: none; }
.source-details summary { cursor: pointer; font-weight: 800; }
.source-details p { color: var(--muted); line-height: 1.45; margin: 8px 0 0; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 50; opacity: 0; transform: translateY(10px); transition: .2s ease; background: var(--text); color: var(--panel); border-radius: 999px; padding: 10px 14px; pointer-events: none; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translateY(0); }

@supports not (color: color-mix(in srgb, white, black)) {
  .status-card.status-good, .status-card.status-warn, .rating-good, .rating-warn { background: var(--panel-soft); }
}

@media (max-width: 1180px) {
  .topbar { grid-template-columns: 1fr; }
  .toolbar { justify-content: flex-start; }
  .hero { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choice-grid, .form-grid, .result-grid { grid-template-columns: 1fr; }
  .field.wide { grid-column: auto; }
  .section-head { flex-direction: column; }
  .section-help { text-align: left; }
}

@media (hover: none) and (pointer: coarse) {
  button, select, input, textarea, summary, .btn { min-height: 38px; }
  input, select, textarea { font-size: 16px; }
}

@media (max-width: 680px) {
  .app-shell { width: min(100% - 10px, 1500px); padding-top: 5px; }
  .topbar, .section-card, .hero { padding: 8px; }
  .kpi-grid { grid-template-columns: 1fr; }
  body { font-size: 12px; }
}

@media print {
  html, body { background: #fff !important; }
  .no-print, dialog, .topbar, .toast { display: none !important; }
  .app-shell { width: 100%; margin: 0; padding: 0; }
  .card, .section-card, .hero, .kpi, .result-box, .source-details { box-shadow: none; background: #fff; break-inside: avoid; }
}

/* v6 · Layout-Fix: keine horizontale Seitenbreite + Logo links ausrichten
   Ziel: Die Gesamtseite darf nicht nach links/rechts scrollbar werden.
   Tabellen dürfen weiterhin nur innerhalb ihres eigenen Tabellenrahmens scrollen. */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  position: relative;
}

.app-shell {
  width: min(1500px, calc(100vw - 18px));
  max-width: calc(100vw - 18px);
  overflow-x: clip;
}

.topbar,
.layout,
.card,
.section-card,
.hero,
.kpi-grid,
.choice-grid,
.form-grid,
.result-grid,
.result-box,
.notice,
.field,
.unit-input,
.table-wrap,
.source-details {
  min-width: 0;
  max-width: 100%;
}

.topbar {
  width: 100%;
  grid-template-columns: auto minmax(0, .75fr) minmax(0, 1.55fr);
  overflow: hidden;
}

.topbar > * {
  min-width: 0;
}

.topbar .brand,
.topbar .brand-compact {
  justify-self: start;
  justify-content: flex-start;
  align-items: center;
}

.topbar .brand-logo {
  flex: 0 0 auto;
}

.title-block {
  min-width: 0;
  overflow: hidden;
}

.title-block h1,
.title-block p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  min-width: 0;
  max-width: 100%;
  justify-content: flex-end;
  overflow: hidden;
}

.toolbar .btn,
.toolbar label.btn {
  flex: 0 1 auto;
}

input,
select,
textarea,
button,
.btn {
  min-width: 0;
  max-width: 100%;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrap table {
  max-width: none;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "brand title"
      "toolbar toolbar";
    align-items: center;
  }

  .topbar .brand {
    grid-area: brand;
    justify-self: start;
  }

  .topbar .title-block {
    grid-area: title;
  }

  .topbar .toolbar {
    grid-area: toolbar;
    justify-content: flex-start;
    width: 100%;
    padding-top: 6px;
    border-top: 1px solid var(--line-soft);
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100vw - 10px, 1500px);
    max-width: calc(100vw - 10px);
  }

  .topbar .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .topbar .toolbar .btn,
  .topbar .toolbar label.btn {
    width: 100%;
  }
}

@supports not (overflow: clip) {
  .app-shell {
    overflow-x: hidden;
  }
}
