/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --primary:      #2563eb;
  --primary-dark: #1d4ed8;
  --primary-bg:   #eff6ff;
  --bg:           #f1f5f9;
  --panel:        #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --muted:        #64748b;
  --success:      #16a34a;
  --danger:       #dc2626;
  --header-h:     52px;
  --ctrl-w:       320px;
  --r:            8px;
  --sh:           0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --sh-md:        0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  background: #1e293b;
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  z-index: 10;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Navigation ────────────────────────────────────────────────────────── */
.app-nav {
  display: flex;
  gap: 2px;
  margin-left: 8px;
}
.nav-item {
  padding: 5px 14px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,.6);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: all .15s;
  white-space: nowrap;
}
.nav-item:hover  { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }

/* ── Header right ──────────────────────────────────────────────────────── */
.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.proj-label { font-size: 12px; opacity: .65; }
.header-right select {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  border-radius: 6px;
  padding: 4px 24px 4px 8px;
  font-size: 13px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='white'%3e%3cpath d='M5 8l5 5 5-5'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 5px center;
  background-size: 14px;
}
.header-right select option { color: var(--text); background: #fff; }

.btn-icon-sm {
  width: 26px; height: 26px;
  border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.12);
  color: #fff;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.btn-icon-sm:hover { background: rgba(255,255,255,.25); }

.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: rgba(255,255,255,.3);
  flex-shrink: 0;
  transition: background .3s;
}
.status-ok      { background: #4ade80; }
.status-error   { background: #f87171; }
.status-loading { background: #fbbf24; animation: pulse .9s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ── App sections ──────────────────────────────────────────────────────── */
.app-section {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.app-section.active { display: flex; }
.app-layout {
  display: grid;
  grid-template-columns: var(--ctrl-w) 1fr;
  flex: 1;
  overflow: hidden;
}

/* ── Controls panel ────────────────────────────────────────────────────── */
.ctrl-panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ctrl-section {
  background: var(--bg);
  border-radius: var(--r);
  padding: 10px 12px;
}
.ctrl-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 8px;
}
.w-full { width: 100%; }

/* ── Generator icons ───────────────────────────────────────────────────── */
.gen-section { padding-bottom: 8px; }
.gen-icons {
  display: flex;
  gap: 6px;
}
.gen-icon {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 6px;
  border: 2px solid var(--border);
  background: var(--panel);
  border-radius: var(--r);
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  transition: all .15s;
}
.gen-icon:hover  { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.gen-icon.active { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }

/* ── Palette section ───────────────────────────────────────────────────── */
.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.palette-mgmt-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  border-radius: 4px;
  transition: color .15s;
}
.palette-mgmt-btn:hover { color: var(--primary); }

.palette-select-wrap { position: relative; }

.palette-preview {
  position: absolute;
  left: 0; top: calc(100% + 4px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--sh-md);
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  z-index: 50;
  min-width: 180px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .15s, transform .15s;
}
.palette-select-wrap:hover .palette-preview,
.palette-select-wrap:focus-within .palette-preview {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.palette-preview .swatch {
  width: 18px; height: 18px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,.1);
}

/* ── Sequence mode buttons ─────────────────────────────────────────────── */
.seq-mode-row {
  display: flex;
  gap: 5px;
  margin-top: 8px;
}
.seq-mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px;
  border: 2px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
  font-size: 10px;
}
.seq-mode-btn:hover  { border-color: var(--primary); color: var(--primary); }
.seq-mode-btn.active { border-color: var(--primary); background: var(--primary-bg); color: var(--primary); }
.seq-mode-icon { font-size: 18px; line-height: 1; }
.seq-mode-label { font-size: 10px; font-weight: 600; }

/* ── Form controls ─────────────────────────────────────────────────────── */
select, input[type=text], input[type=number], textarea {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--panel);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.hint { font-size: 11px; color: var(--muted); margin-top: 3px; display: block; }

/* ── Parameter fields ──────────────────────────────────────────────────── */
.param-field         { margin-bottom: 10px; }
.param-field:last-child { margin-bottom: 0; }
.param-label         { display: block; font-size: 12px; font-weight: 500; margin-bottom: 4px; color: var(--text); }
.slider-row          { display: flex; align-items: center; gap: 6px; }
.slider-row input[type=range]  { flex: 1; accent-color: var(--primary); cursor: pointer; }
.slider-row input[type=number] { width: 68px; flex-shrink: 0; }
.num-full            { width: 100%; }
.checkbox-row        { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.checkbox-row input[type=checkbox] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
  cursor: pointer; flex-shrink: 0;
}

/* Stripes orientation buttons */
.orient-btns { display: flex; gap: 4px; }
.orient-btn {
  flex: 1;
  padding: 5px 4px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
  transition: all .15s;
}
.orient-btn:hover  { border-color: var(--primary); color: var(--primary); }
.orient-btn.active { border-color: var(--primary); background: var(--primary-bg); color: var(--primary); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn-primary {
  padding: 8px 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--r);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  display: flex; align-items: center; gap: 5px;
  white-space: nowrap;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary {
  padding: 7px 12px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.btn-danger {
  padding: 8px 14px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--r);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-danger:hover { background: #b91c1c; }
.btn-icon {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  transition: all .15s;
  color: var(--text);
}
.btn-icon:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-bg); color: var(--primary); }
.btn-icon:disabled { opacity: .35; cursor: not-allowed; }
.btn-link { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }

/* ── Sequences panel ───────────────────────────────────────────────────── */
.seq-section  { margin-top: 2px; }
.seq-header   { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.seq-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.seq-item:last-child { border-bottom: none; }
.seq-swatches { display: flex; flex-wrap: wrap; gap: 2px; width: 72px; flex-shrink: 0; }
.swatch {
  width: 15px; height: 15px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,.1);
  display: inline-block;
  flex-shrink: 0;
}
.seq-info    { flex: 1; min-width: 0; }
.seq-name    { display: block; font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seq-meta    { font-size: 10px; color: var(--muted); }
.btn-icon-danger:hover { border-color: var(--danger); background: #fef2f2; color: var(--danger); }
.empty-hint  { font-size: 12px; color: var(--muted); padding: 2px 0; }

/* ── Preview panel ─────────────────────────────────────────────────────── */
.preview-panel {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--bg);
  padding: 12px;
  gap: 10px;
}

/* Checkered background = transparent pattern */
.checkerboard {
  background-color: #c8c8c8;
  background-image:
    linear-gradient(45deg, #aaa 25%, transparent 25%),
    linear-gradient(-45deg, #aaa 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #aaa 75%),
    linear-gradient(-45deg, transparent 75%, #aaa 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.preview-wrap {
  border-radius: var(--r);
  box-shadow: var(--sh);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  flex: 1;
  overflow: hidden;
  position: relative;
}
.preview-placeholder, .preview-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: #555;
  padding: 48px 32px;
  text-align: center;
  background: rgba(255,255,255,.55);
  border-radius: var(--r);
}
.preview-placeholder small { font-size: 12px; }
.preview-placeholder strong { color: var(--primary); }
.ph-icon { font-size: 64px; opacity: .4; line-height: 1; }
.spinner {
  width: 38px; height: 38px;
  border: 3px solid rgba(255,255,255,.4);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#preview-img,
#edit-result-img {
  max-width: 100%;
  max-height: 65vh;
  object-fit: contain;
  display: block;
  border-radius: 4px;
}

/* ── Action bar ────────────────────────────────────────────────────────── */
.action-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--panel);
  border-radius: var(--r);
  padding: 8px 12px;
  box-shadow: var(--sh);
}
.history-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.hist-pos {
  font-size: 12px;
  color: var(--muted);
  min-width: 36px;
  text-align: center;
}
.img-meta-inline {
  flex: 1;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
}
.action-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Saved images strip ────────────────────────────────────────────────── */
.saved-section { flex-shrink: 0; }
.saved-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 24px;
}
.saved-thumb {
  position: relative;
  width: 72px; height: 72px;
  border-radius: 6px;
  overflow: visible;
  cursor: pointer;
  border: 2px solid var(--border);
  box-shadow: var(--sh);
  flex-shrink: 0;
  transition: all .15s;
}
.saved-thumb:hover  { border-color: var(--primary); transform: scale(1.06); }
.saved-thumb.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.2); }
.saved-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 4px;
}
.saved-thumb .del-btn {
  position: absolute;
  top: -6px; right: -6px;
  width: 18px; height: 18px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 10px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 2;
}
.saved-thumb:hover .del-btn { display: flex; }
/* use-btn (↩) in edit strip — top-left corner, primary colour */
.saved-thumb .use-btn {
  top: -6px; right: auto; left: -6px;
  background: var(--primary);
}

/* ── Split-Galerie ─────────────────────────────────────────────────────── */
.edit-split-grid {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  overflow-y: auto;
}
.split-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px;
}
.split-header-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.split-save-all {
  font-size: 12px;
  padding: 4px 12px;
}
.split-parts-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.split-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 8px;
  min-width: 100px;
  flex: 1 1 120px;
  max-width: 200px;
  box-shadow: var(--sh);
}
.split-card img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  object-fit: contain;
  display: block;
}
.split-card-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}
.split-card-actions {
  display: flex;
  gap: 4px;
}
.split-card-actions .btn-icon {
  width: 26px; height: 26px;
  font-size: 12px;
  padding: 0;
}

/* ── Coming soon sections ──────────────────────────────────────────────── */
.coming-soon {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
  padding: 60px;
}
.coming-soon h2 { font-size: 22px; font-weight: 700; color: var(--text); }
.coming-soon p  { font-size: 14px; }

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal {
  background: var(--panel);
  border-radius: 12px;
  padding: 24px;
  width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,.2);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal h2          { font-size: 16px; font-weight: 700; }
.modal-body-text   { font-size: 13px; color: var(--muted); line-height: 1.5; }
.modal-btns        { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

/* ── Editor section ────────────────────────────────────────────────────── */
/* 4-column icon grid for the 8 editors */
.editor-icons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}
.editor-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  border: 2px solid var(--border);
  background: var(--panel);
  border-radius: var(--r);
  cursor: pointer;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  transition: all .15s;
  line-height: 1.2;
  text-align: center;
}
.editor-icon:hover  { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.editor-icon.active { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }

/* Source image picker (left panel) */
.edit-source-wrap { position: relative; }
.edit-source-thumb {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--r);
  border: 2px dashed var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.edit-source-thumb img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}
.edit-source-hint { font-size: 11px; color: var(--muted); text-align: center; padding: 8px; }

/* Source picker modal grid */
.source-pick-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
  min-height: 48px;
}
.source-pick-thumb {
  width: 80px; height: 80px;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid var(--border);
  flex-shrink: 0;
  transition: all .15s;
  position: relative;
}
.source-pick-thumb:hover { border-color: var(--primary); transform: scale(1.06); }
.source-pick-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.source-pick-thumb .spt-name {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.55); color: #fff;
  font-size: 9px; padding: 2px 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Palette management modal ──────────────────────────────────────────── */
.modal-wide { width: 480px; max-width: calc(100vw - 32px); }

.modal-scroll-body {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 4px 0;
}
.modal-scroll-body.empty::after {
  content: "Noch keine eigenen Paletten";
  display: block;
  padding: 12px 14px;
  font-size: 12px;
  color: var(--muted);
}

.modal-divider { border: none; border-top: 1px solid var(--border); margin: 2px 0; }
.modal-section-title { font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }

/* Palette item in management list */
.custom-pal-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
}
.custom-pal-item:last-child { border-bottom: none; }
.custom-pal-name { flex: 1; font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.custom-pal-swatches { display: flex; gap: 2px; flex-shrink: 0; }

/* Color picker grid (new palette form) */
.color-grid { display: flex; flex-direction: column; gap: 5px; }
.color-row  { display: flex; align-items: center; gap: 6px; }
.color-row input[type=color] {
  width: 36px; height: 30px;
  border: 1px solid var(--border); border-radius: 5px;
  padding: 2px; cursor: pointer; flex-shrink: 0;
  background: var(--panel);
}
.color-row input[type=text] {
  width: 90px; flex-shrink: 0; font-family: monospace; font-size: 12px;
}
.color-row .btn-rm {
  width: 24px; height: 24px;
  border: none; background: none; color: var(--muted);
  font-size: 15px; cursor: pointer; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: color .15s;
}
.color-row .btn-rm:hover { color: var(--danger); }
.add-color-btn {
  background: none; border: 1px dashed var(--border);
  color: var(--muted); border-radius: 6px;
  padding: 5px 10px; font-size: 12px; cursor: pointer;
  transition: all .15s; width: 100%; margin-top: 2px;
}
.add-color-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: #1e293b;
  color: #fff;
  border-radius: var(--r);
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--sh-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  white-space: nowrap;
  max-width: calc(100vw - 40px);
}
.toast.show    { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: #15803d; }
.toast.error   { background: var(--danger); }
.toast.info    { background: #0369a1; }
