:root {
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --status-good: #0ca30c;
  --status-critical: #d03b3b;
  --status-warn: #b06a00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --status-warn: #c98500;
  }
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  max-width: 50rem;
  margin: 2rem auto;
  padding: 0 1rem;
  background: var(--page-plane);
  color: var(--text-primary);
}

/* Opt-in für Seiten mit breitem Inhalt (z.B. der 3D-Raum-Layout-Editor), die
   den sonst überall geltenden 50rem-Rahmen brauchen - siehe base.html
   `body_class`-Block. Betrifft nur die eine Seite, die die Klasse setzt. */
body.wide-page { max-width: 72rem; }

a { color: var(--accent); }

header h1 a { color: var(--text-primary); text-decoration: none; }

header {
  margin-bottom: 1.5rem;
}

nav {
  display: flex;
  gap: 1rem;
  align-items: center;
  font-size: 0.9rem;
}

nav .spacer { flex: 1; }
nav a.active { color: var(--text-primary); font-weight: 600; }

.nav-divider { width: 1px; height: 1.1em; background: var(--border); margin: 0 0.25rem; }
.nav-group-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

.breadcrumb { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.75rem; }
.breadcrumb .crumb-sep { margin: 0 0.4rem; color: var(--text-muted); }
.breadcrumb .crumb-current { color: var(--text-primary); font-weight: 500; }

.badge { display: inline-block; font-size: 0.75rem; padding: 0.15rem 0.55rem; border-radius: 999px; border: 1px solid var(--border); margin-left: 0.5rem; font-weight: 500; }
.badge.ok { color: var(--status-good); border-color: var(--status-good); }
.badge.warn { color: var(--status-warn); border-color: var(--status-warn); }
.badge.muted { color: var(--text-muted); }

.card {
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface-1);
}

.card.narrow { max-width: 24rem; }
.card.wide { max-width: none; }

#viewer3d {
  position: relative; /* Bezugsrahmen für den absolut positionierten Hover-Tooltip */
  width: 100%;
  height: 70vh;
  min-height: 420px;
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  touch-action: none; /* verhindert Scroll-Gesten, die mit Drag/Orbit kollidieren */
}

.fixture-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  z-index: 5;
  white-space: nowrap;
}

/* --- Raum-Layout: Sidebar mit Fixture-Bibliothek zum Platzieren per Drag&Drop --- */

#stageSideStatus { margin-left: 0.75rem; }

.room-editor-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.room-editor-row .fixture-sidebar {
  flex: 0 0 16rem;
}

.room-editor-row #viewerCard {
  flex: 1 1 28rem;
  min-width: 20rem;
  margin-bottom: 0;
}

.fixture-sidebar h3 { margin-top: 0; }

.library-group-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 1rem 0 0.4rem 0;
}

.library-group-label:first-child { margin-top: 0; }

.library-fixture-card {
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.5rem;
  cursor: grab;
  background: var(--page-plane);
}

.library-fixture-card:active { cursor: grabbing; }

.library-fixture-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.rgb-swatch {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #dd3333 0deg 120deg, #33aa33 120deg 240deg, #3366dd 240deg 360deg);
  flex-shrink: 0;
  border: 1px solid var(--border);
}

/* Produktfoto im Kachelkopf (Phase 63) - exakt an der Stelle und in der Größe
   des RGB-Punkts, den es ersetzt, damit die Kopfzeile ihre Höhe behält.
   `contain` statt `cover`: ein Strahler soll vollständig zu sehen sein, auch
   wenn das Herstellerfoto ein anderes Seitenverhältnis hat. */
.fixture-thumb {
  width: 1.9rem;
  height: 1.9rem;
  object-fit: contain;
  border-radius: 0.25rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

/* Bild-Bereich im Bearbeitungsformular auf /library. */
.entry-image-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.entry-image-preview {
  width: 7rem;
  height: 7rem;
  object-fit: contain;
  border-radius: 0.4rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
}

.entry-image-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: flex-start;
}

.entry-image-actions input[type="file"] { margin: 0; }

/* 3D-Modell-Bereich im Bearbeitungsformular (Phase 64). */
.entry-model-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

/* Die Vorschau wird per 2D-Canvas gezeichnet (kein Three.js auf dieser Seite) -
   dunkler Grund, damit das hell schattierte Modell darauf ablesbar ist. */
.entryModelPreview {
  border-radius: 0.4rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
}

.entry-model-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: flex-start;
  flex: 1 1 18rem;
}

.entry-model-actions input[type="file"] { margin: 0; }

.model-transform-row label { flex: 0 0 7rem; }

.capability-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.35rem;
}

.cap-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

/* Familien-Kachel: der Kopf klappt die Modus-Liste auf, gezogen werden nur
   die einzelnen Modus-Zeilen (die Kachel selbst ist nicht draggable). */
.library-family-card { cursor: pointer; }
.library-family-card:active { cursor: pointer; }

.library-mode-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.family-mode-count {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  margin-left: auto;
  flex-shrink: 0;
  white-space: nowrap;
}

.family-chevron {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.15s;
}

/* Chevron dreht sich für jede aufklappbare Kachel, nicht nur für Familien:
   auf /library sind auch Einzelkacheln und Modus-Zeilen aufklappbar. Bewusst
   mit `>` statt als Nachfahren-Selektor - sonst würde eine offene
   Familien-Kachel auch die Chevrons ihrer Modus-Zeilen mitdrehen. */
.library-fixture-card.open > .library-fixture-head .family-chevron,
.family-mode-row.open > .family-mode-head .family-chevron { transform: rotate(90deg); }

/* Schiebt das Chevron einer Einzelkachel nach rechts. Modus-Zeilen brauchen das
   nicht - dort tut das schon das "Nch"-Badge, und ein zweites margin-left:auto
   würde den freien Platz zwischen beiden aufteilen. */
.tile-chevron-end { margin-left: auto; }

.family-mode-list {
  display: none;
  margin-top: 0.4rem;
  border-top: 1px solid var(--border);
  padding-top: 0.15rem;
}

.library-family-card.open .family-mode-list { display: block; }

.family-mode-row {
  padding: 0.35rem 0.3rem;
  border-radius: 0.3rem;
  cursor: grab;
}

.family-mode-row:hover { background: var(--surface-1); }
.family-mode-row:active { cursor: grabbing; }

.family-mode-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
}

.family-mode-label { color: var(--text-primary); }

.mode-ch-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  margin-left: auto;
  flex-shrink: 0;
}

/* Kanaltexte einer Vorlage (`channel_notes`, Phase 77) - aufklappbar, weil eine
   16-Kanal-Liste die schmale Raum-Editor-Sidebar sonst sprengen würde.
   Zugeklappt kostet sie genau eine Zeile. */
.channel-notes {
  margin-top: 0.35rem;
  font-size: 0.72rem;
}

/* Eigenes Dreieck statt des Browser-Markers, damit es wie das Chevron der
   Kacheln aussieht und sich genauso dreht. */
.channel-notes-summary {
  cursor: pointer;
  color: var(--text-muted);
  list-style: none;
}

.channel-notes-summary::-webkit-details-marker { display: none; }

.channel-notes-summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 0.3rem;
  transition: transform 0.15s;
}

.channel-notes[open] > .channel-notes-summary::before { transform: rotate(90deg); }
.channel-notes-summary:hover { color: var(--text-secondary); }

.channel-note-list {
  margin-top: 0.25rem;
  border-top: 1px solid var(--border);
  padding-top: 0.25rem;
}

/* Drei Spalten statt einer Tabelle: die Nummer bleibt schmal und rechtsbündig,
   der Parametername bekommt so viel Platz wie er braucht, der Text den Rest. */
.channel-note-row {
  display: grid;
  grid-template-columns: 1.4rem minmax(4rem, auto) 1fr;
  gap: 0.4rem;
  align-items: baseline;
  padding: 0.1rem 0;
}

.channel-note-num {
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.channel-note-param { color: var(--text-secondary); }
.channel-note-text { color: var(--text-muted); }

/* --- Kacheln außerhalb der Sidebar: Vorlagen-Auswahl in Schritt 3 der
   Rig-Seite (.tile-picker) und Bibliotheksverwaltung /library (.library-tiles).
   Gleiche Kacheln wie in der Sidebar (fixture_tiles.js), aber angeklickt statt
   gezogen. --- */

.tile-picker .library-fixture-card,
.tile-picker .family-mode-row,
.library-tiles .library-fixture-card,
.library-tiles .family-mode-row { cursor: pointer; }

/* Aufklappbarer Rumpf einer Kachel - auf /library das Bearbeitungsformular. */
.tile-body { display: none; }

.library-fixture-card.open > .tile-body,
.family-mode-row.open > .tile-body {
  display: block;
  margin-top: 0.5rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

/* Die Vorlagen-Auswahl ist mehrspaltig, damit ein wachsender Katalog nicht die
   halbe Seite füllt; die Kategorie-Überschrift läuft über die volle Breite.
   Auf /library bleibt es bewusst einspaltig - dort klappt in der Kachel ein
   volles Formular auf, das in einer schmalen Spalte unbrauchbar wäre. */
.tile-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 0 0.6rem;
  align-items: start;
  margin-top: 0.6rem;
}

.tile-picker .library-group-label { grid-column: 1 / -1; }

/* Eigene volle Zeile in #fixtureLibraryRow: als normal breites Flex-Item wäre
   die Auswahl nur so breit wie ihr Inhalt, und das Raster darin fiele auf eine
   einzige Spalte zusammen. "+ Benutzerdefiniert" rutscht dadurch darunter. */
#templatePickerDetails { flex: 1 1 100%; }

/* Kein `display`-Override hier: alles außer `list-item` nimmt Chrome das
   Aufklapp-Dreieck weg, und dann sieht die Zeile nicht mehr aufklappbar aus. */
#templatePickerDetails > summary {
  cursor: pointer;
  margin-bottom: 0.25rem;
}

.placed-fixtures-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.placed-fixture-tile {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-secondary);
}

.placed-fixture-tile:hover {
  border-color: var(--accent);
}

.placed-fixture-tile.active {
  border-color: var(--accent);
}

.placed-fixture-name {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.placed-fixture-tile.active .placed-fixture-name {
  color: var(--accent);
  font-weight: 600;
}

.tile-group-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.tileGroupInput {
  width: 8rem;
  font-size: 0.72rem;
  padding: 0.1rem 0.3rem;
}

#viewerToolbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

#viewerToolbar label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

#viewerToolbar input[type="number"] { width: 6rem; }

table { width: 100%; border-collapse: collapse; }

th, td {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

form label {
  display: block;
  margin-bottom: 0.75rem;
}

form input, form select {
  display: block;
  width: 100%;
  padding: 0.4rem;
  margin-top: 0.25rem;
  box-sizing: border-box;
}

button, .button-link {
  padding: 0.5rem 1rem;
  font-size: 1rem;
  cursor: pointer;
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  text-decoration: none;
  display: inline-block;
  margin-right: 0.5rem;
}

.button-link.primary, button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

button.danger { color: var(--status-critical); border-color: var(--status-critical); }

.error { color: var(--status-critical); }
.ok { color: var(--status-good); }
.warn { color: var(--status-warn); }

.log {
  background: #111;
  color: #ddd;
  padding: 1rem;
  border-radius: 0.4rem;
  max-height: 24rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- Landingpage --- */

.hero {
  text-align: center;
  padding: 2.5rem 1rem;
  margin-bottom: 2rem;
}

.hero .lead {
  max-width: 34rem;
  margin: 1rem auto 1.5rem auto;
  color: var(--text-secondary);
}

.cta-row { display: flex; justify-content: center; gap: 0.75rem; }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
}

.feature-grid .card h3 { margin-top: 0; }
.feature-grid .card p { color: var(--text-secondary); font-size: 0.9rem; }

/* --- Fixture-Editor (Muster aus dmx_agent/web/static/style.css) --- */

.fixture-edit-card {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1rem;
  background: var(--surface-1);
}

.fixture-edit-card h4 {
  margin: 0.75rem 0 0.4rem 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.fixture-tile-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  user-select: none;
}

.fixture-tile-chevron {
  color: var(--text-muted);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.fixture-edit-card:not(.collapsed) .fixture-tile-chevron { transform: rotate(90deg); }

.fixture-tile-name {
  font-weight: 600;
}

.fixture-tile-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.fixture-edit-card.collapsed .fixture-tile-body { display: none; }

.fixture-tile-body { margin-top: 0.75rem; }

.row {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.row label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: var(--text-secondary);
  gap: 0.25rem;
}

.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.kv-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  align-items: center;
}

.kv-row input { padding: 0.3rem 0.5rem; }
.kv-row .paramName { flex: 2; }
.kv-row .paramOffset, .kv-row .paramValue { flex: 1; max-width: 6rem; }
/* Der Kanaltext (Phase 77) bekommt den meisten Platz - er ist ein Satz,
   kein Bezeichner. */
.kv-row .paramNote { flex: 3; }

/* Kanalbelegung ohne Bibliotheks-Rechte: nur lesbar, bewusst ruhiger als die
   Eingabefelder darüber - es soll nicht wie ein deaktiviertes Formular wirken,
   sondern wie eine Angabe zum Gerät (Phase 61). */
.kv-row.readonly .paramName {
  flex: 2;
  font-family: var(--font-mono, monospace);
  font-size: 0.9rem;
}

.kv-row.readonly .paramValueText {
  flex: 1;
  max-width: 9rem;
  color: var(--text-muted, #8a8f98);
  font-size: 0.9rem;
}

/* `flex-start` statt `center`: die aufgeklappte Vorlagen-Auswahl ist hoch, ein
   mittig zentrierter "+ Benutzerdefiniert"-Knopf schwebte daneben im Nichts.
   So bleiben beide Einstiege oben nebeneinander. */
#fixtureLibraryRow {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.notice {
  padding: 0.6rem 0.9rem;
  border-radius: 0.375rem;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.notice.ok { background: rgba(12, 163, 12, 0.12); color: var(--status-good); }
.notice.error { background: rgba(208, 59, 59, 0.12); color: var(--status-critical); }
.notice.warn { background: rgba(176, 106, 0, 0.12); color: var(--status-warn); }

.token-box {
  display: block;
  padding: 0.6rem 0.9rem;
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  word-break: break-all;
  margin: 0.5rem 0;
}

/* --- Fortschritt eines laufenden Builds, neben dem Startknopf (Phase 42) --- */

.build-start-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.build-start-row form { margin: 0; }

.build-progress {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 12rem;
}

/* Verdünnter Akzent-Ton als Spur statt eines eigenen Grauwerts - passt sich
   damit automatisch dem hellen wie dem dunklen Thema an. */
.build-progress-track {
  flex: 1;
  height: 0.55rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  overflow: hidden;
}

/* Übergang, damit die Sprünge zwischen den Etappen nicht hart einrasten -
   der Fortschritt kommt in groben Stufen, nicht kontinuierlich. */
.build-progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.4s ease;
}

.build-progress-text {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--text-secondary);
  min-width: 3.2rem;
  text-align: right;
}
