:root {
  --bg: #f4f3f0;
  --panel: #ffffff;
  --line: #e2e0db;
  --ink: #1f2124;
  --muted: #7a7d82;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --warn: #9a6a00;
  --err: #b3261e;
  --ok: #2f6b3a;
  --radius: 8px;
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  min-height: 100vh;
}

h2 {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
  font-weight: 600;
}

.muted {
  color: var(--muted);
}
.small {
  font-size: 11px;
}
.mono {
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: center;
}

.top {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.status {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}
.status.warn {
  color: var(--warn);
}
.status.err {
  color: var(--err);
}
.status.ok {
  color: var(--ok);
}
.budget {
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border-radius: 99px;
  background: #eef2ef;
  color: var(--accent);
  white-space: nowrap;
}
.budget.low {
  background: #fbeaea;
  color: var(--err);
}

.layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 320px;
  gap: 12px;
  padding: 12px;
  align-items: start;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 50px;
  max-height: calc(100vh - 62px);
  overflow: auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.row.between {
  justify-content: space-between;
}
.grow {
  flex: 1;
  min-width: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.field > span {
  color: var(--muted);
  font-size: 11px;
}
.field em {
  font-style: normal;
  color: var(--ink);
  float: right;
  font-variant-numeric: tabular-nums;
}
.field.compact {
  gap: 2px;
}
.check {
  display: flex;
  gap: 6px;
  align-items: center;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}
input[type='number'],
select,
textarea {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
textarea {
  width: 100%;
  font: 12px/1.45 ui-monospace, 'SF Mono', Menlo, monospace;
  resize: vertical;
}

.btn {
  font: inherit;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover:not(:disabled) {
  border-color: #c9c6bf;
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn.small {
  padding: 3px 8px;
  font-size: 12px;
}
.btn.wide {
  width: 100%;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn.danger {
  color: var(--err);
}

.segs {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.segs.inline {
  display: inline-flex;
}
.seg {
  flex: 1;
  font: inherit;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 5px 10px;
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
}
.seg:last-child {
  border-right: 0;
}
.seg.on {
  background: var(--ink);
  color: #fff;
}
.seg:disabled {
  color: #bbb;
  cursor: default;
}

.props {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.props-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.grid2 input {
  width: 100%;
}

.center {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.viewbar {
  display: flex;
  gap: 12px;
  align-items: center;
}
.hint {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.viewport {
  aspect-ratio: 3 / 2;
  width: 100%;
  background: #ddd;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
}
.viewport canvas {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

.previewbar {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.previewbar #provider {
  max-width: 300px;
}
.ref img {
  height: 32px;
  width: 48px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--line);
}
.go {
  margin-left: auto;
  padding: 8px 18px;
  font-weight: 600;
}

.promptbox {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
}
.promptbox summary {
  cursor: pointer;
  font-weight: 600;
}
.promptbox[open] summary {
  margin-bottom: 8px;
}
.promptbox .row {
  margin-top: 6px;
}
.passes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.pass {
  margin: 0;
  cursor: zoom-in;
}
.pass img {
  width: 100%;
  display: block;
  border-radius: 4px;
  border: 1px solid var(--line);
}
.pass figcaption {
  font-size: 11px;
  color: var(--muted);
}

.results-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.result {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0;
  background: #fff;
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  font: inherit;
}
.result img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  display: block;
}
.result-meta {
  display: block;
  padding: 4px 6px;
  font-size: 11px;
  color: var(--muted);
}
.result-err {
  display: flex;
  aspect-ratio: 3 / 2;
  align-items: center;
  justify-content: center;
  color: var(--err);
}

.planwrap {
  aspect-ratio: 1 / 1;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafaf8;
}
.planwrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

dialog#modal {
  border: 0;
  border-radius: 10px;
  padding: 14px;
  width: min(1200px, 94vw);
  max-height: 94vh;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
dialog#modal::backdrop {
  background: rgba(20, 20, 20, 0.55);
}
dialog#ask {
  border: 0;
  border-radius: 10px;
  padding: 16px;
  width: min(460px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  background: var(--panel);
  color: var(--ink);
}
dialog#ask::backdrop {
  background: rgba(20, 20, 20, 0.55);
}
#ask-title {
  display: block;
  font-size: 15px;
  overflow-wrap: anywhere;
}
#ask-body p {
  margin: 8px 0 0;
  overflow-wrap: anywhere;
}
#ask-body .warn {
  color: var(--warn);
}
#ask-actions {
  margin-top: 14px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
}
#modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#modal-body pre {
  white-space: pre-wrap;
  font-size: 12px;
  background: var(--bg);
  padding: 8px;
  border-radius: 6px;
}
#modal-actions {
  margin-top: 10px;
}
.modal-img {
  width: 100%;
  max-height: calc(94vh - 170px);
  object-fit: contain;
  display: block;
  border-radius: 6px;
}

.compare {
  position: relative;
  width: 100%;
  max-width: calc((94vh - 170px) * 1.5);
  margin: 0 auto;
  --cut: 50%;
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
}
.compare > img {
  width: 100%;
  display: block;
}
.compare-top {
  position: absolute;
  inset: 0;
  clip-path: inset(0 calc(100% - var(--cut)) 0 0);
}
.compare-top img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.compare-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--cut);
  width: 2px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}
.compare-legend {
  width: 100%;
  max-width: calc((94vh - 170px) * 1.5);
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
}
.compare-legend input {
  flex: 1;
}
.thumbs {
  display: flex;
  gap: 8px;
}
.thumbs img {
  width: 200px;
  border-radius: 4px;
  cursor: pointer;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .side {
    position: static;
    max-height: none;
  }
}

/* Startseite ↔ Editor (app.js schaltet die Klasse am body) */
body.mode-boot main.layout,
body.mode-start main.layout,
body:not(.mode-start) #start,
body:not(.mode-editor) #to-start,
body:not(.mode-editor) #to-payload,
#to-payload[hidden] {
  display: none;
}
.budget:empty {
  display: none;
}
.crumbs {
  display: flex;
  align-items: center;
  min-width: 0;
  white-space: nowrap;
}
.crumbs span:empty {
  display: none;
}
.crumbs span + span:not(:empty)::before {
  content: ' · ';
  white-space: pre;
}
.crumbs #proj-name {
  color: var(--ink);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

/* Schmale Fenster: Kopfzeile in zwei Zeilen statt seitlich scrollen. Zeile 1 Titel, Projekt, Zurück;
   Zeile 2 Meldung (umbrechend) und Budget */
@media (max-width: 600px) {
  .top {
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 8px 12px;
  }
  .top > strong {
    white-space: nowrap;
  }
  .top-poc {
    display: none;
  }
  .top::after {
    content: '';
    flex-basis: 100%;
    order: 1;
  }
  .crumbs {
    flex: 1 1 0;
  }
  .crumbs > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .crumbs #proj-name {
    flex: 0 1 auto;
    max-width: none;
  }
  .crumbs > span:last-child {
    flex: none;
  }
  .status {
    order: 2;
    flex: 1 1 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .status:empty {
    display: none;
  }
  /* «Stand in Payload sichern» in die zweite Zeile, neben Meldung und Budget */
  #to-payload {
    order: 3;
  }
  .budget {
    order: 3;
    margin-left: auto;
  }
}
.start-loading {
  padding: 24px 16px;
}
.start-fallback {
  max-width: 560px;
  margin: 24px auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}
.start-fallback .status {
  white-space: normal;
}

/* Hinweise zum Modell (Import, Planauswertung) */
.warnbox {
  border: 1px solid #ecd9a8;
  background: #fbf6e8;
  border-radius: var(--radius);
  padding: 6px 10px;
  color: var(--warn);
}
.warnbox[hidden] {
  display: none;
}
.warnbox summary {
  cursor: pointer;
}
.warnbox ul {
  margin: 6px 0 2px;
  padding-left: 18px;
  color: var(--ink);
}

/* Symbolbild und Prompt-Hinweise */
.tag-symbol {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 99px;
  border: 1px solid #ecd9a8;
  background: #fbf6e8;
  color: var(--warn);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  vertical-align: 1px;
}
.tag-symbol[hidden] {
  display: none;
}
.prompt-notes {
  margin: 6px 0;
  color: var(--muted);
}
.prompt-notes[hidden] {
  display: none;
}
.result-tags {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

/* In Medien übernehmen (lokaler Stub) */
.medien-box {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f7f8f6;
}
.medien-box[hidden] {
  display: none;
}
.medien-box p {
  margin: 2px 0;
}
.medien-ok {
  color: var(--ok);
}
.medien-ok a {
  color: var(--accent);
}
