:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --line: #dfe3e8;
  --ink: #1f2933;
  --muted: #7b8794;
  --accent: #1d4ed8;
  --accent-dark: #1e3a8a;
  --ok: #15803d;
  --err: #b91c1c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.brand { display: flex; flex-direction: column; line-height: 1.1; }
.brand strong { font-size: 16px; }
.brand .muted { font-size: 12px; }
.muted { color: var(--muted); font-weight: normal; }

.doctype { display: flex; gap: 6px; margin-left: auto; }
.seg { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span {
  display: block;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  background: #fff;
  white-space: nowrap;
}
.seg input:checked + span {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.actions { display: flex; align-items: center; gap: 12px; }
.user-email { font-size: 12px; color: var(--muted); white-space: nowrap; }
.status { font-size: 13px; min-width: 90px; text-align: right; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }
.status.busy { color: var(--accent); }

/* ---------- Buttons ---------- */
button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 8px 16px;
}
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button.primary.big { padding: 12px 28px; font-size: 16px; }
button.ghost { background: #fff; border-color: var(--line); color: var(--ink); font-size: 13px; padding: 6px 12px; }
button.ghost:hover { background: #f1f5f9; }
button:disabled { opacity: .55; cursor: default; }

/* ---------- Layout ---------- */
.page { max-width: 960px; margin: 0 auto; padding: 22px 20px 80px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 18px; display: flex; align-items: center; gap: 10px; }
.card h3 { margin: 18px 0 10px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.stamm-actions { display: flex; gap: 8px; }

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
}

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.col-span-2 { grid-column: span 2; }

label { display: flex; flex-direction: column; font-size: 13px; gap: 5px; color: #475569; }
input, textarea, select {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

/* ---------- Auftrag ---------- */
.auftrag-card { border-color: var(--accent); }
.auftrag-row { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.auftrag-open { flex: 1; min-width: 240px; }
.auftrag-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Freitext-Zonen + Blöcke ---------- */
.zone {
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px 14px;
  margin: 0 0 16px;
}
.zone legend {
  font-weight: 700;
  font-size: 14px;
  padding: 2px 8px;
  color: var(--accent-dark);
}
.zone legend .muted { font-weight: 400; }
.zone[data-zone="abschnitt1"], .zone[data-zone="abschnitt2"] { border-color: var(--line); }
.zone[data-zone="abschnitt1"] legend, .zone[data-zone="abschnitt2"] legend { color: var(--ink); }

.blocks { display: flex; flex-direction: column; gap: 10px; min-height: 12px; }

.block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
}
.block.dragging { opacity: .5; border-style: dashed; }
.block-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.drag-handle { cursor: grab; color: var(--muted); font-size: 16px; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.block-spacer { flex: 1; }
.block textarea { resize: none; line-height: 1.5; overflow: hidden; min-height: 44px; }
.heading-label { font-size: 13px; font-weight: 600; color: var(--accent-dark); margin-bottom: 10px; }
.zone[data-zone="abschnitt1"] .heading-label, .zone[data-zone="abschnitt2"] .heading-label { color: var(--ink); }
.block textarea[readonly] { background: #f8fafc; color: #475569; cursor: default; }
.block.editing { border-color: var(--accent); }
.lock { background: none; border: 1px solid var(--line); font-size: 12px; padding: 4px 9px; color: var(--accent); white-space: nowrap; }
.block.editing .lock { background: var(--accent); color: #fff; border-color: var(--accent); }
.del-block { background: #fff; border: 1px solid var(--line); color: var(--err); font-size: 12px; padding: 4px 9px; }
.add-block { margin-top: 10px; }
code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---------- Fotos ---------- */
.foto-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 14px; }
.foto-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fafbfc; }
.foto-item img { width: 100%; height: 150px; object-fit: cover; border-radius: 6px; background: #eee; }
.foto-item .foto-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.foto-item input { font-size: 13px; }
.foto-item .del { background: #fff; border: 1px solid var(--line); color: var(--err); padding: 6px 10px; }

/* ---------- Bottom / Preview / Error ---------- */
.bottom-actions { display: flex; justify-content: center; margin: 6px 0 22px; }
#preview { width: 100%; height: 80vh; border: 1px solid var(--line); border-radius: 8px; }
.error-box {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #7f1d1d;
  padding: 14px;
  border-radius: 8px;
  white-space: pre-wrap;
  font-size: 12px;
  max-height: 320px;
  overflow: auto;
}

@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .col-span-2 { grid-column: auto; }
  .foto-list { grid-template-columns: 1fr; }
  .topbar-inner { flex-wrap: wrap; }
  .doctype { margin-left: 0; order: 3; width: 100%; }
}
