/*  builder.css – Oberflaeche des RickCV-Editors.
 *  Bewusst getrennt von styles.css: das Dokument liegt in einem iframe und
 *  teilt sich keine Stile mit dem Editor.
 */

:root {
  --ui-bg: #f2f4f6;
  --ui-panel: #ffffff;
  --ui-panel-2: #f8f9fb;
  --ui-line: #dfe3e8;
  --ui-text: #22262b;
  --ui-muted: #6b7280;
  --ui-accent: #286f6f;
  --ui-accent-soft: #e6f0ef;
  --ui-danger: #b3403a;
  --ui-radius: 10px;
  --ui-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --ui-header-h: 56px;
  --ui-sidebar-w: 420px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ui-bg: #16191d;
    --ui-panel: #1e2227;
    --ui-panel-2: #23282e;
    --ui-line: #333a42;
    --ui-text: #e6e8ea;
    --ui-muted: #9aa3ad;
    --ui-accent: #4fa8a1;
    --ui-accent-soft: #1f3230;
    --ui-danger: #e0736c;
    --ui-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ui-text);
  background: var(--ui-bg);
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* ------------------------------------------------------------------ Kopfzeile */

.app-header {
  height: var(--ui-header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-line);
  position: relative;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-right: 8px;
}

.brand small {
  font-weight: 400;
  color: var(--ui-muted);
  letter-spacing: 0;
}

.header-spacer {
  flex: 1;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--ui-line);
  background: var(--ui-panel-2);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}

.btn:hover {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent);
}

.btn-primary {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.08);
  background: var(--ui-accent);
  color: #fff;
}

.btn-small {
  padding: 3px 8px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-icon {
  padding: 3px 7px;
  font-size: 13px;
  line-height: 1.2;
  min-width: 28px;
  justify-content: center;
}

.btn-danger:hover {
  border-color: var(--ui-danger);
  color: var(--ui-danger);
  background: transparent;
}

/* -------------------------------------------------------------------- Layout */

.app-main {
  display: flex;
  height: calc(100% - var(--ui-header-h));
  align-items: stretch;
}

.editor {
  width: var(--ui-sidebar-w);
  min-width: 300px;
  max-width: 70vw;
  flex-shrink: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--ui-panel);
  border-right: 1px solid var(--ui-line);
  padding-bottom: 40vh;
}

.resizer {
  width: 6px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  margin-left: -3px;
  z-index: 10;
}

.resizer:hover {
  background: var(--ui-accent-soft);
}

/* ------------------------------------------------------------------ Sektionen */

.section {
  border-bottom: 1px solid var(--ui-line);
}

.section > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  user-select: none;
}

.section > summary::-webkit-details-marker {
  display: none;
}

.section > summary::before {
  content: "▸";
  color: var(--ui-muted);
  font-size: 11px;
  transition: transform 0.15s;
}

.section[open] > summary::before {
  transform: rotate(90deg);
}

.section > summary:hover {
  background: var(--ui-panel-2);
}

.section-count {
  margin-left: auto;
  font-weight: 400;
  font-size: 12px;
  color: var(--ui-muted);
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-line);
  border-radius: 20px;
  padding: 1px 8px;
}

.section-body {
  padding: 4px 16px 18px;
}

.hint {
  color: var(--ui-muted);
  font-size: 12px;
  margin: 0 0 12px;
}

/* ---------------------------------------------------------------- Formularfeld */

.field {
  margin-bottom: 12px;
}

.field > label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ui-muted);
  margin-bottom: 4px;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="url"],
.field input[type="email"],
.field select,
.field textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  background: var(--ui-panel-2);
}

.field textarea {
  resize: vertical;
  min-height: 64px;
  line-height: 1.45;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--ui-accent);
  outline-offset: -1px;
  border-color: var(--ui-accent);
}

.field-row {
  display: flex;
  gap: 10px;
}

.field-row > .field {
  flex: 1;
  min-width: 0;
}

/* Schalter */
.field-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.field-toggle input {
  width: 34px;
  height: 20px;
  appearance: none;
  background: var(--ui-line);
  border-radius: 20px;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}

.field-toggle input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}

.field-toggle input:checked {
  background: var(--ui-accent);
}

.field-toggle input:checked::after {
  transform: translateX(14px);
}

.field-toggle label {
  cursor: pointer;
  font-size: 13px;
}

/* Schieberegler */
.field-range .range-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.field-range output {
  font-size: 12px;
  color: var(--ui-muted);
  font-variant-numeric: tabular-nums;
}

.field-range input[type="range"] {
  width: 100%;
  accent-color: var(--ui-accent);
}

/* Farbwahl */
.color-input {
  display: flex;
  gap: 8px;
  align-items: center;
}

.color-input input[type="color"] {
  width: 38px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  background: var(--ui-panel-2);
  cursor: pointer;
  flex-shrink: 0;
}

.color-input input[type="text"] {
  flex: 1;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
}

.swatches {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  cursor: pointer;
  padding: 0;
}

/* Icon-Feld */
.icon-input {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-input .icon-preview {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  background: var(--ui-panel-2);
  color: var(--ui-accent);
  flex-shrink: 0;
  font-size: 20px;
}

/* -------------------------------------------------------------------- Listen */

.list-item {
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius);
  margin-bottom: 10px;
  background: var(--ui-panel-2);
  overflow: hidden;
}

.list-item > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  cursor: pointer;
  list-style: none;
  font-size: 13px;
}

.list-item > summary::-webkit-details-marker {
  display: none;
}

.list-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.list-item-badge {
  font-size: 11px;
  color: var(--ui-muted);
  font-weight: 400;
  white-space: nowrap;
}

.list-item-body {
  padding: 10px;
  border-top: 1px solid var(--ui-line);
  background: var(--ui-panel);
}

.list-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.add-row {
  display: flex;
  gap: 8px;
}

.empty-note {
  color: var(--ui-muted);
  font-size: 13px;
  font-style: italic;
  padding: 6px 0 10px;
}

/* --------------------------------------------------------------- Bildeditor */

.photo-editor {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.photo-stage {
  position: relative;
  width: 150px;
  flex-shrink: 0;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  overflow: hidden;
  background: repeating-conic-gradient(#e8e8e8 0% 25%, #f7f7f7 0% 50%) 50% / 16px 16px;
  cursor: grab;
  touch-action: none;
}

.photo-stage.dragging {
  cursor: grabbing;
}

.photo-stage.is-circle {
  border-radius: 50%;
}

.photo-stage img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}

.photo-stage-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--ui-muted);
  font-size: 12px;
  text-align: center;
  padding: 8px;
}

.photo-controls {
  flex: 1;
  min-width: 0;
}

.drop-zone {
  border: 2px dashed var(--ui-line);
  border-radius: var(--ui-radius);
  padding: 14px;
  text-align: center;
  color: var(--ui-muted);
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 12px;
  transition: border-color 0.12s, background 0.12s;
}

.drop-zone:hover,
.drop-zone.over {
  border-color: var(--ui-accent);
  background: var(--ui-accent-soft);
  color: var(--ui-text);
}

/* ------------------------------------------------------------------ Vorschau */

.preview {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--ui-bg);
}

.preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--ui-line);
  background: var(--ui-panel);
  font-size: 13px;
}

.preview-bar .status {
  color: var(--ui-muted);
  font-size: 12px;
  margin-left: auto;
}

.preview-scroll {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

.preview-stage {
  transform-origin: top left;
  width: 820px;
  margin: 0 auto;
}

.preview-stage iframe {
  width: 820px;
  border: 0;
  display: block;
  background: #c4c4c4;
}

/* ------------------------------------------------------------------ Hinweise */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--ui-text);
  color: var(--ui-bg);
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--ui-shadow);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
  font-size: 13px;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --------------------------------------------------------- Schmale Bildschirme */

.mobile-tabs {
  display: none;
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app-main {
    flex-direction: column;
    height: auto;
  }

  .editor,
  .preview {
    width: 100%;
    max-width: none;
    height: auto;
  }

  .resizer {
    display: none;
  }

  .mobile-tabs {
    display: flex;
    gap: 8px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--ui-line);
    background: var(--ui-panel);
    position: sticky;
    top: 0;
    z-index: 15;
  }

  .mobile-tabs .btn {
    flex: 1;
    justify-content: center;
  }

  body.show-preview .editor {
    display: none;
  }

  body:not(.show-preview) .preview {
    display: none;
  }

  .header-actions .btn span.label {
    display: none;
  }
}

/* ------------------------------------------------------ Vorschau-Skalierung */

.preview-canvas {
  margin: 0 auto;
  overflow: hidden;
}

.section-body hr,
.list-item-body hr {
  border: 0;
  border-top: 1px solid var(--ui-line);
  margin: 16px 0 14px;
}

.list-item-body > .list-item {
  margin-top: 4px;
  margin-bottom: 0;
}

/* ================================================================ Hinweise */

.note {
  font-size: 12.5px;
  line-height: 1.5;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 12px;
  border: 1px solid var(--ui-line);
  background: var(--ui-panel-2);
}

.note-info {
  border-left: 3px solid var(--ui-accent);
}

.note-warn {
  border-left: 3px solid var(--ui-danger);
  background: color-mix(in oklab, var(--ui-danger), transparent 92%);
}

/* ---------------------------------------------------------- Unterblöcke */

.sub-block {
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius);
  margin-bottom: 12px;
  background: var(--ui-panel-2);
  overflow: hidden;
}

.sub-block > summary {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  list-style: none;
}

.sub-block > summary::-webkit-details-marker {
  display: none;
}

.sub-block > summary::before {
  content: "▸ ";
  color: var(--ui-muted);
  font-size: 10px;
}

.sub-block[open] > summary::before {
  content: "▾ ";
}

.sub-block-body {
  padding: 10px;
  border-top: 1px solid var(--ui-line);
  background: var(--ui-panel);
}

/* ------------------------------------------------------------ Icon-Feld */

.icon-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  background: var(--ui-panel-2);
  cursor: pointer;
  text-align: left;
}

.icon-button:hover {
  border-color: var(--ui-accent);
  background: var(--ui-accent-soft);
}

.icon-button-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--ui-accent);
}

.icon-button-preview .rc-icon {
  width: 20px;
  height: 20px;
}

.icon-button-preview .material-symbols-outlined {
  font-size: 20px;
}

.icon-button-name {
  font-size: 12.5px;
  color: var(--ui-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shade-custom {
  margin-top: 8px;
  width: 100%;
  height: 32px;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  background: var(--ui-panel-2);
  padding: 2px;
  cursor: pointer;
}

/* ---------------------------------------------------------- Icon-Picker */

body.picker-open {
  overflow: hidden;
}

.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 15, 19, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}

.picker-overlay[hidden] {
  display: none;
}

.picker-panel {
  width: min(640px, 100%);
  max-height: min(680px, 90vh);
  display: flex;
  flex-direction: column;
  background: var(--ui-panel);
  border: 1px solid var(--ui-line);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.picker-head {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--ui-line);
}

.picker-search {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  background: var(--ui-panel-2);
  font-size: 14px;
}

.picker-search:focus {
  outline: 2px solid var(--ui-accent);
  outline-offset: -1px;
}

.picker-sets {
  display: flex;
  gap: 6px;
  padding: 10px 12px 0;
}

.picker-set {
  padding: 5px 12px;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--ui-panel-2);
  cursor: pointer;
  font-size: 12.5px;
}

.picker-set.is-active {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #fff;
  font-weight: 600;
}

.picker-note {
  margin: 8px 12px 0;
  font-size: 12px;
  color: var(--ui-muted);
}

.picker-grid {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
  align-content: start;
}

.picker-group {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ui-muted);
  padding: 10px 2px 2px;
}

.picker-item {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--ui-panel-2);
  cursor: pointer;
  color: var(--ui-text);
}

.picker-item:hover {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent);
}

.picker-item:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 1px;
}

.picker-item.is-current {
  border-color: var(--ui-accent);
  background: var(--ui-accent-soft);
}

.picker-item .rc-icon {
  width: 22px;
  height: 22px;
}

.picker-item .material-symbols-outlined {
  font-size: 22px;
}

.picker-empty {
  grid-column: 1 / -1;
  color: var(--ui-muted);
  text-align: center;
  padding: 32px 0;
}

/* ---------------------------------------------------------- Seitenzahl */

.page-count {
  font-size: 12px;
  color: var(--ui-muted);
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  padding: 1px 9px;
  white-space: nowrap;
}

/* ------------------------------------------------------- ATS-Textfeld */

.ats-preview {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.ats-preview[readonly] {
  color: var(--ui-muted);
  background: var(--ui-panel-2);
}

/* Hinweis für Browser, deren Druckausgabe vom Layout abweicht */

.browser-warn {
  font-size: 12px;
  color: var(--ui-danger);
  border: 1px solid color-mix(in oklab, var(--ui-danger), transparent 60%);
  background: color-mix(in oklab, var(--ui-danger), transparent 92%);
  border-radius: 999px;
  padding: 1px 10px;
  white-space: nowrap;
  cursor: help;
}

.browser-warn[hidden] {
  display: none;
}
