:root {
  --red: #c8102e;
  --red-dark: #9a0c22;
  --navy: #0f1c4d;
  --navy-mid: #1a2a6c;
  --ink: #1a1a1f;
  --muted: #5c5c66;
  --line: #d8d8de;
  --bg: #f3f2ef;
  --paper: #ffffff;
  --focus: #2b4acb;
  --ok: #1b7a3d;
  --err: #b42318;
  --radius: 6px;
  --font: "Source Sans 3", "Segoe UI", sans-serif;
  --display: "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.45;
}

.screen { display: none; }
.screen.active { display: block; }

/* —— Login —— */
#loginScreen.active {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(200, 16, 46, 0.35), transparent 55%),
    radial-gradient(900px 500px at 100% 100%, rgba(15, 28, 77, 0.55), transparent 50%),
    linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 45%, var(--red) 100%);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--paper);
  border-radius: 10px;
  padding: 2rem 1.75rem 1.5rem;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

.login-logo {
  display: block;
  max-width: 200px;
  max-height: 72px;
  margin: 0 auto 1.25rem;
}

.login-panel h1 {
  font-family: var(--display);
  font-size: 1.65rem;
  font-weight: 700;
  text-align: center;
  color: var(--navy);
}

.login-sub {
  text-align: center;
  color: var(--muted);
  margin: 0.35rem 0 1.4rem;
  font-size: 0.95rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.login-form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0.75rem 0 0.3rem;
}

.login-form input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
}

.pw-row { position: relative; }
.pw-toggle {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 1rem;
  padding: 0.35rem;
}

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.85rem;
}

/* —— Topbar —— */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--navy);
  color: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  background: #fff;
  border-radius: 4px;
  padding: 2px;
}

.topbar-brand strong {
  display: block;
  font-size: 0.95rem;
}

.user-badge {
  display: block;
  font-size: 0.78rem;
  opacity: 0.85;
}

.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* —— Form —— */
.form-wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

.intro {
  color: var(--muted);
  margin-bottom: 1rem;
}

.drafts-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.drafts-panel__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.drafts-panel__head h2 {
  font-family: var(--display);
  font-size: 1.05rem;
  color: var(--navy);
}

.drafts-panel__list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.draft-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  background: #fafafa;
}

.draft-row__meta {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 12rem;
}

.draft-row__title {
  font-weight: 600;
}

.draft-row__time {
  font-size: 0.8rem;
  color: var(--muted);
}

.draft-row__actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.drafts-panel__empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.edit-banner {
  background: #fff4e5;
  border: 1px solid #f0c36d;
  color: #7a4b00;
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* Pflichtfeld-Farben */
.grid > label.is-required,
.grid > fieldset.is-required {
  background: #ffe5e5;
  border: 1px solid #f5b5b5;
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
}

.grid > label.is-required.is-filled,
.grid > fieldset.is-required.is-filled {
  background: #e6f7ea;
  border-color: #9fd5ad;
}

.grid > label.is-removed,
.grid > fieldset.is-removed {
  display: none;
}

body.form-edit-mode .grid > label.is-removed,
body.form-edit-mode .grid > fieldset.is-removed {
  display: none;
}

.removed-panel {
  background: #f7f7f9;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}

.removed-panel h3 {
  font-size: 0.95rem;
  color: var(--navy);
  margin-bottom: 0.5rem;
}

.removed-panel__list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.removed-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.55rem 0.25rem 0.75rem;
  font-size: 0.82rem;
}

.removed-chip button {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  border: 0;
  background: var(--navy);
  color: #fff;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  cursor: pointer;
}

.field-edit {
  display: none;
  margin-top: 0.45rem;
  gap: 0.4rem;
  flex-direction: column;
  font-weight: 400;
}

body.form-edit-mode .field-edit {
  display: flex;
}

.field-edit__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.field-edit__remove {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--err);
  background: #fff;
  color: var(--err);
  border-radius: var(--radius);
  padding: 0.3rem 0.55rem;
  cursor: pointer;
}

.field-edit__remove:hover {
  background: #fdecea;
}

.option-edit {
  display: none;
  margin: 0.25rem 0 0.45rem 1.4rem;
}

body.form-edit-mode .option-edit {
  display: block;
}

.option-edit input {
  width: min(100%, 28rem);
  font: inherit;
  font-weight: 400;
  padding: 0.35rem 0.5rem;
  border: 1px dashed #6b7bb5;
  border-radius: var(--radius);
  background: #fff;
}

.field-edit__req {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--navy);
}

.field-edit__label {
  font: inherit;
  font-weight: 400;
  padding: 0.4rem 0.5rem;
  border: 1px dashed var(--navy-mid);
  border-radius: var(--radius);
  background: #fff;
}

.toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
}

.toc a {
  text-decoration: none;
  color: var(--navy);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
}

.toc a:hover { border-color: var(--red); color: var(--red); }

.sec {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.25rem 1.25rem 1.5rem;
  margin-bottom: 1rem;
  scroll-margin-top: 5rem;
}

.sec h2 {
  font-family: var(--display);
  font-size: 1.25rem;
  color: var(--navy);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--red);
}

.muted { color: var(--muted); font-weight: 400; font-size: 0.85em; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 1rem;
}

.grid > label,
.grid > fieldset {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.grid > label.full,
.grid > fieldset.full { grid-column: 1 / -1; }

.grid input[type="text"],
.grid input[type="email"],
.grid input[type="tel"],
.grid input[type="number"],
.grid input[type="date"],
.grid select,
.grid textarea {
  font: inherit;
  font-weight: 400;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fafafa;
}

.grid input:focus,
.grid select:focus,
.grid textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--focus) 45%, white);
  border-color: var(--focus);
  background: #fff;
}

.checks {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  background: #fafafa;
}

.checks legend {
  padding: 0 0.35rem;
  font-size: 0.88rem;
}

.checks label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  font-weight: 400;
  margin: 0.25rem 0;
}

.submit-bar {
  position: sticky;
  bottom: 0;
  background: color-mix(in srgb, var(--bg) 88%, white);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--line);
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: stretch;
}

/* —— Buttons —— */
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0.65rem 1rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn.primary {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.btn.primary:hover { background: var(--red-dark); }

.btn.ghost {
  background: transparent;
  color: inherit;
  border-color: color-mix(in srgb, currentColor 35%, transparent);
}

.topbar .btn.ghost { color: #fff; }
.topbar .btn.ghost:hover { background: rgba(255, 255, 255, 0.1); }

.btn:disabled { opacity: 0.6; cursor: wait; }

.msg {
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.msg.error {
  background: #fdecea;
  color: var(--err);
  border: 1px solid #f5c2c0;
}

.msg.ok {
  background: #e8f6ee;
  color: var(--ok);
  border: 1px solid #b7e0c5;
}

.msg.info {
  background: #eef1fb;
  color: var(--navy);
  border: 1px solid #c9d2f0;
}

/* —— Success —— */
#successScreen.active {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background: var(--bg);
}

.success-panel {
  width: min(480px, 100%);
  background: var(--paper);
  border-radius: 10px;
  padding: 2rem;
  text-align: center;
  border: 1px solid var(--line);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}

.success-panel h1 {
  font-family: var(--display);
  color: var(--navy);
  margin-bottom: 0.75rem;
}

.success-panel p { color: var(--muted); margin-bottom: 1.25rem; }
.success-panel .btn { width: 100%; margin-bottom: 0.5rem; }

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
}
