:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a202c;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --danger: #dc2626;
  --success: #15803d;
  --warning-bg: #fef3c7;
  --radius: 8px;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
code { background: var(--bg); padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.9em; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }
.success { color: var(--success); margin: 0; }

/* Topbar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1000px; margin: 0 auto; padding: 0 1rem;
  display: flex; align-items: center; gap: 1.5rem; height: 56px;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--primary); text-decoration: none; }
.topbar nav { display: flex; gap: 0.25rem; flex: 1; }
.nav-link {
  color: var(--text); text-decoration: none; padding: 0.4rem 0.75rem; border-radius: var(--radius);
}
.nav-link:hover { background: var(--bg); }
.topbar-user { position: relative; }
.user-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.4rem 0.75rem; cursor: pointer; font: inherit; display: flex; align-items: center; gap: 0.5rem;
}
.badge {
  background: var(--bg); border: 1px solid var(--border); border-radius: 99px;
  padding: 0.05rem 0.5rem; font-size: 0.75rem; color: var(--muted);
}
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); min-width: 180px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08); z-index: 10; overflow: hidden;
}
.dropdown a, .dropdown button {
  display: block; width: 100%; text-align: left; padding: 0.6rem 0.9rem;
  background: none; border: none; font: inherit; color: var(--text);
  text-decoration: none; cursor: pointer;
}
.dropdown a:hover, .dropdown button:hover { background: var(--bg); }

/* Layout */
.container { max-width: 1000px; margin: 1.5rem auto; padding: 0 1rem; }
.auth-container {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 1rem;
}
.auth-container .flash { width: 100%; max-width: 400px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; margin-bottom: 1.5rem;
}
.card.narrow { max-width: 480px; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2rem; width: 100%; max-width: 400px;
}
.auth-title { text-align: center; margin: 0; color: var(--primary); }
.auth-subtitle { text-align: center; color: var(--muted); margin: 0.25rem 0 1.5rem; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 0.9rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }
label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 500; }
label.checkbox { flex-direction: row; align-items: center; gap: 0.5rem; }
label.checkbox-small { font-weight: 400; font-size: 0.9rem; }
.stack-tight { display: flex; flex-direction: column; gap: 0.3rem; align-items: flex-start; }
input[type="text"], input[type="password"], input[type="url"], input[type="email"], select, textarea, input[type="file"] {
  font: inherit; padding: 0.5rem 0.7rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); width: 100%;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
/* Maskierte Secret-Eingabe (type="text", damit Passwortmanager nicht anspringen) */
.secret-input { -webkit-text-security: disc; }
.input-group { display: flex; gap: 0.5rem; }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.row-inline { display: flex; gap: 0.4rem; align-items: center; }

/* Buttons */
.btn {
  font: inherit; font-weight: 500; padding: 0.5rem 1rem; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.btn-mini { padding: 0.1rem 0.45rem; font-size: 0.75rem; font-weight: 400; }
.doc-actions { margin-top: 0.35rem; }
.btn-ghost { background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; white-space: nowrap; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.divider {
  display: flex; align-items: center; gap: 0.75rem; color: var(--muted);
  font-size: 0.85rem; margin: 1.25rem 0;
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* Flash */
.flash {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem;
  border: 1px solid var(--border); background: var(--surface);
}
.flash-success { border-color: var(--success); color: var(--success); }
.flash-error { border-color: var(--danger); color: var(--danger); }
.flash-warning { background: var(--warning-bg); border-color: #d97706; color: #92400e; }
.flash-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: inherit; }

/* HV-Pakete: Liste & Phasen-Zeitleiste */
.hv-item { padding: 0.85rem 0; border-top: 1px solid var(--border); }
.hv-item:first-child { border-top: none; }
.hv-item-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }
.hv-item-head a { text-decoration: none; color: var(--text); }
.hv-item-head a:hover { color: var(--primary); }

.hv-timeline {
  list-style: none; margin: 0; padding: 0;
  display: flex; gap: 0; overflow-x: auto;
}
.hv-phase {
  flex: 1 1 0; min-width: 90px; position: relative;
  text-align: center; padding-top: 1.4rem; color: var(--muted); font-size: 0.8rem;
}
/* Verbindungslinie zwischen den Phasen */
.hv-phase::before {
  content: ""; position: absolute; top: 0.4rem; left: 50%; width: 100%; height: 2px;
  background: var(--border);
}
.hv-phase:last-child::before { display: none; }
.hv-phase-dot {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 0.85rem; height: 0.85rem; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border);
}
.hv-phase.is-done { color: var(--text); }
.hv-phase.is-done::before { background: var(--primary); }
.hv-phase.is-done .hv-phase-dot { background: var(--primary); border-color: var(--primary); }
.hv-phase.is-current { color: var(--primary); font-weight: 600; }
.hv-phase.is-current .hv-phase-dot {
  background: var(--surface); border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

/* Chatbot */
.chat-log {
  display: flex; flex-direction: column; gap: 0.6rem;
  max-height: 50vh; overflow-y: auto; padding: 0.5rem 0; margin-bottom: 1rem;
}
.chat-msg { display: flex; }
.chat-msg.chat-user { justify-content: flex-end; }
.chat-bubble {
  max-width: 80%; padding: 0.55rem 0.8rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg); white-space: normal;
}
.chat-user .chat-bubble { background: var(--primary); color: #fff; border-color: var(--primary); }
.chat-answered { border-top: 1px solid var(--border); padding-top: 0.9rem; }
.chat-prompt { font-weight: 600; margin: 0 0 0.6rem; }
.chat-options { flex-wrap: wrap; gap: 0.4rem; }
.chat-answer { margin: 0; }
/* Frage-Bubble darf breiter werden, damit die Antwort-Optionen Platz haben */
.chat-assistant .chat-bubble:has(.chat-options) { max-width: 100%; }

/* Großes Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1.5rem;
}
.modal-large {
  background: var(--surface); border-radius: var(--radius);
  width: min(1100px, 96vw); max-height: 92vh; display: flex; flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 1.1rem; }
.modal-body-split { display: flex; gap: 1rem; padding: 1rem; overflow: hidden; min-height: 0; }
.modal-scroll { padding: 1rem 1.1rem; overflow-y: auto; }
.modal-body-split .tpl-list { width: 260px; flex: 0 0 260px; overflow-y: auto; max-height: 68vh; transition: flex-basis 0.15s ease, width 0.15s ease; }
.modal-body-split .editor-wrap { flex: 1; min-width: 0; }
.tpl-list h4 { margin: 0; }
.tpl-list-head { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.5rem; }
.tpl-toggle { flex: 0 0 auto; padding: 0.1rem 0.4rem; line-height: 1; }
/* Eingeklappter Zustand: schmale Leiste mit vertikaler Beschriftung */
.modal-body-split .tpl-list.collapsed { width: 34px; flex: 0 0 34px; overflow: hidden; }
.tpl-list.collapsed .tpl-list-head { justify-content: center; margin-bottom: 0.4rem; }
.tpl-collapsed-label {
  writing-mode: vertical-rl; transform: rotate(180deg);
  background: none; border: none; cursor: pointer; padding: 0.2rem 0;
  color: var(--muted); font-size: 0.8rem; font-weight: 600; letter-spacing: 0.02em;
  white-space: nowrap;
}
.tpl-collapsed-label:hover { color: var(--text); }
.tpl-item {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.5rem 0.6rem; margin-bottom: 0.5rem;
}
.tpl-item strong { display: block; }
.tpl-item p { margin: 0.2rem 0 0.4rem; font-size: 0.85rem; }

/* Admin: Phasen-Konfigurationsbaum */
.phase-block { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem; margin-bottom: 1rem; background: var(--surface); }
.step-block { border-left: 3px solid var(--border); padding: 0.6rem 0.8rem; margin: 0.6rem 0 0.6rem 0.5rem; background: var(--bg); border-radius: 0 var(--radius) var(--radius) 0; }
.question-block { border: 1px dashed var(--border); border-radius: var(--radius); padding: 0.6rem; margin-top: 0.5rem; background: var(--surface); }
.options-block { margin-top: 0.5rem; }
.options-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.35rem; }
.option-row { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.35rem; flex-wrap: wrap; }
.block-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.block-title { font-weight: 600; flex: 1; min-width: 160px; }
.mini-label { display: block; font-size: 0.85rem; color: var(--muted); margin-top: 0.4rem; }
.mini-label input, .mini-label select, .mini-label textarea { display: block; width: 100%; margin-top: 0.15rem; }
.checkbox-inline { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; white-space: nowrap; }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }

/* Analyse-Bericht (Leistungsbeschreibung) */
.analysis h3 { font-size: 1.05rem; margin: 0 0 0.5rem; }
.analysis-error {
  border: 1px solid var(--danger); background: #fef2f2; color: var(--danger);
  border-radius: var(--radius); padding: 0.8rem 1rem;
}
.analysis-error p { margin: 0.3rem 0 0; }
.analysis-summary { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; background: var(--bg); }
.analysis-block { margin-top: 0.8rem; border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.8rem; background: var(--surface); }
.analysis-block summary { cursor: pointer; font-weight: 600; }
.analysis-block ul, .analysis-block ol { margin: 0.5rem 0 0.2rem; padding-left: 1.2rem; }
.analysis-block li { margin: 0.2rem 0; }

/* Schweregrad-Badges */
.sev-badge { font-weight: 600; }
.sev-kritisch   { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.sev-wesentlich { background: var(--warning-bg); border-color: #fde68a; color: #92400e; }
.sev-empfehlung { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

.verdict-badge { border-radius: 99px; padding: 0.1rem 0.7rem; font-size: 0.8rem; font-weight: 600; border: 1px solid transparent; }
.verdict-geeignet { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.verdict-geeignet_nach_ueberarbeitung { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }
.verdict-nicht_geeignet { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.verdict-unbekannt { background: var(--bg); color: var(--muted); border-color: var(--border); }

/* Einzelner Kritikpunkt */
.finding { border: 1px solid var(--border); border-left-width: 4px; border-radius: var(--radius); padding: 0.7rem 0.9rem; margin-bottom: 0.7rem; background: var(--surface); }
.sev-border-kritisch   { border-left-color: #dc2626; }
.sev-border-wesentlich { border-left-color: #d97706; }
.sev-border-empfehlung { border-left-color: #2563eb; }
.finding-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.35rem; }
.finding-spacer { flex: 1; }
.finding-problem { margin: 0.2rem 0; font-weight: 500; }
.finding-impact, .finding-action { margin: 0.25rem 0; font-size: 0.92rem; }
.finding .lbl { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
.finding-quote { margin: 0.35rem 0; padding: 0.25rem 0.7rem; border-left: 3px solid var(--border); color: var(--muted); font-style: italic; }
.finding-proposed { margin-top: 0.4rem; }
.finding-proposed pre { margin: 0.2rem 0 0; padding: 0.6rem 0.8rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); white-space: pre-wrap; word-break: break-word; font-size: 0.85rem; }
.applied-tag { color: var(--success); font-weight: 600; font-size: 0.85rem; }

/* Dimension-Scores */
.dim-scores { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.5rem; }
.dim-row { display: grid; grid-template-columns: 1fr 120px 60px; align-items: center; gap: 0.6rem; font-size: 0.88rem; }
.dim-bar { background: var(--bg); border: 1px solid var(--border); border-radius: 99px; height: 8px; overflow: hidden; }
.dim-bar-fill { height: 100%; background: var(--primary); }
.dim-val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .dim-row { grid-template-columns: 1fr 70px; } .dim-row .dim-bar { display: none; } }

/* Versionen */
.versions-toggle {
  display: flex; flex: 1; align-items: center; gap: 0.4rem; flex-wrap: nowrap;
  background: none; border: none; cursor: pointer; padding: 0.2rem 0;
  color: var(--muted); text-align: left; white-space: nowrap;
}
.versions-toggle:hover { color: var(--text); }
.versions-toggle-label { font-size: 0.9rem; font-weight: 500; }
.versions-caret { font-size: 0.8rem; width: 1em; flex: 0 0 auto; }
.versions-count { flex: 0 0 auto; }
.version-table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; font-size: 0.9rem; }
.version-table th, .version-table td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.version-table th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.origin-badge { font-weight: 600; }
.origin-template { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.origin-ki_optimierung { background: #f5f3ff; border-color: #ddd6fe; color: #6d28d9; }
.origin-manuell { background: var(--bg); color: var(--muted); }
.version-md { white-space: pre-wrap; word-break: break-word; font-size: 0.85rem; line-height: 1.5; margin: 0; }

/* Analyse-Panel im Editor-Modal */
.modal-xl { width: min(1400px, 97vw); }
.analysis-panel {
  width: 460px; flex: 0 0 460px; overflow-y: auto; max-height: 72vh;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.8rem 0.9rem; background: var(--bg);
}
.analysis-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.analysis-panel-head h4 { margin: 0; }
.analysis-panel .analysis-summary { padding: 0.6rem 0.75rem; }
.analysis-panel .finding { margin-bottom: 0.4rem; }
.finding-nav { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin: 0.8rem 0 0.5rem; font-size: 0.85rem; }
.finding-actions { margin-top: 0.6rem; padding-top: 0.5rem; border-top: 1px dashed var(--border); }
.analysis-raw { font-size: 0.85rem; line-height: 1.5; white-space: normal; word-break: break-word; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.75rem; max-height: 55vh; overflow-y: auto; }
@media (max-width: 900px) {
  .modal-body-split { flex-wrap: wrap; overflow-y: auto; }
  .modal-body-split .tpl-list,
  .modal-body-split .analysis-panel { width: 100%; flex: 1 1 100%; max-height: none; }
  .modal-body-split .editor-wrap { flex: 1 1 100%; }
}
