/* Typst-Editor: strikt auf .typsteditor scopen */
.typsteditor {
  /* Design-Variablen (leichtes, modernes Theme) */
  --te-bg: #ffffff;
  --te-panel: #ffffff;
  --te-ink: #111827;        /* slate-900 */
  --te-muted: #6b7280;      /* slate-500 */
  --te-border: #e5e7eb;     /* gray-200 */
  --te-accent: #2563eb;     /* blue-600 */
  --te-accent-hover: #1d4ed8; /* blue-700 */
  --te-ok: #16a34a;         /* green-600 */
  --te-warn: #ca8a04;       /* yellow-600 */
  --te-err: #dc2626;        /* red-600 */

  --te-radius: 12px;
  --te-shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);

  /* Responsive Typografie/Abstände */
  --te-space: clamp(10px, 1.5vw, 16px);
  --te-font-size: clamp(14px, 1.1vw, 16px);
  --te-code-size: clamp(12px, 1vw, 15px);

  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--te-ink);
}

.typsteditor * { box-sizing: border-box; }

/* Toolbar */
.typsteditor .toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--te-space) * .75) var(--te-space);
  background: var(--te-panel);
  border: 1px solid var(--te-border);
  border-radius: var(--te-radius);
  padding: calc(var(--te-space) * .75);
  box-shadow: var(--te-shadow);
  font-size: var(--te-font-size);
}
.typsteditor .toolbar .grow { flex: 1 1 auto; }
.typsteditor .status { color: var(--te-muted); }

/* Buttons + Inputs */
.typsteditor button {
  appearance: none;
  border: 1px solid var(--te-border);
  background: #f8fafc;
  color: var(--te-ink);
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease, transform .02s ease;
  font-size: var(--te-font-size);
}
.typsteditor button.primary {
  background: var(--te-accent);
  color: #fff;
  border-color: var(--te-accent);
}
.typsteditor button:hover { border-color: #d1d5db; }
.typsteditor button.primary:hover { background: var(--te-accent-hover); border-color: var(--te-accent-hover); }
.typsteditor button:active { transform: translateY(1px); }
.typsteditor button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--te-accent), transparent 30%);
  outline-offset: 2px;
}

.typsteditor input[type="text"] {
  background: #f9fafb;
  border: 1px solid var(--te-border);
  color: var(--te-ink);
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
  min-width: 220px;
  font-size: var(--te-font-size);
}
.typsteditor input[type="text"]:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--te-accent), white 40%);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--te-accent), transparent 80%);
}

/* Grid-Layout: mobil 1-spaltig, ab 960px 2-spaltig */
.typsteditor .grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--te-space);
  margin-top: var(--te-space);
}
@media (min-width: 960px) {
  .typsteditor .grid {
    grid-template-columns: minmax(300px, 1fr) minmax(300px, 1fr);
    align-items: start;
  }
}

/* Cards */
.typsteditor .card {
  background: var(--te-panel);
  border: 1px solid var(--te-border);
  border-radius: var(--te-radius);
  box-shadow: var(--te-shadow);
  overflow: clip;
}
.typsteditor .card .header {
  padding: .6rem .85rem;
  border-bottom: 1px solid var(--te-border);
  color: var(--te-muted);
  font-weight: 600;
  font-size: var(--te-font-size);
}
.typsteditor .card .body {
  padding: .8rem;
}

/* Editor (Textarea) – skaliert mit Viewport */
.typsteditor textarea[data-role="input"],
.typsteditor textarea#typstinput {
  width: 100%;
  min-height: clamp(220px, 42vh, 640px);
  resize: vertical;
  border: 1px solid var(--te-border);
  background: #f9fafb;
  color: var(--te-ink);
  border-radius: 10px;
  padding: .8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  line-height: 1.45;
  font-size: var(--te-code-size);
}
.typsteditor textarea[data-role="input"]::placeholder { color: var(--te-muted); }

/* Vorschau – skaliert; SVG-Hintergrund bleibt transparent */
.typsteditor .preview {
  min-height: clamp(150px, 32vh, 520px);
}
.typsteditor .preview svg {
  display: block;
  width: 100%;
  height: auto;
  background: transparent !important;
}

/* Fehlerpanel */
.typsteditor .err-summary { 
  margin: .2rem 0 .6rem; 
  color: var(--te-err); 
  font-weight: 700; 
  font-size: var(--te-font-size);
}
.typsteditor .diag-list { display: grid; gap: .6rem; }
.typsteditor .diag {
  background: #fef2f2;                 /* rot-50 */
  border: 1px solid #fecaca;           /* rot-200 */
  border-radius: 10px;
  padding: .6rem .7rem;
}
.typsteditor .diag .title { color: #b91c1c; font-weight: 700; margin-bottom: .25rem; }
.typsteditor .diag .meta { color: #7f1d1d; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; font-size: .9rem; }
.typsteditor .diag .hint { color: #7c2d12; margin-top: .35rem; }

/* Farben für Schweregrade (falls gesetzt) */
.typsteditor .title.warn { color: var(--te-warn); }
.typsteditor .title.err  { color: var(--te-err); }
