/* ================================================================== */
/* Inline site editor — drawer + media picker.                          */
/* All rules are scoped under #site-editor so the editor's form styles   */
/* never collide with the public site's classes (.icon-button, etc.).    */
/* Fixed light "panel" colours keep the editor legible over any theme.   */
/* ================================================================== */
#site-editor {
  --ed-ink: #1f1d1a;
  --ed-ink-2: #56524b;
  --ed-muted: #8a857a;
  --ed-line: rgba(31, 29, 26, 0.14);
  --ed-paper: #fbfaf6;
  --ed-paper-2: #f3eee3;
  --ed-accent: #1f1d1a;
  --ed-danger: #a44a2c;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}
#site-editor[hidden] {
  display: none;
}

/* Docked mode: an open drawer narrows the page instead of covering it, so the
   site header/nav stay visible and clickable — you navigate the site to switch
   the editor's context. Requires body{position:relative} (styles.css) so the
   absolute header tracks body's narrowed width. body's width:100% must yield
   to auto here or the margin would overflow-clip instead of narrowing.
   Small screens keep the overlay behavior. */
@media (min-width: 900px) {
  html.editor-open body {
    width: auto;
    margin-right: 460px; /* must match #editor-panel width */
  }
}

/* ---------- Launcher ---------- */
#editor-toggle {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 150;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--ed-ink);
  color: #fff;
  border: 1px solid var(--ed-ink);
  padding: 11px 18px;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  box-shadow: 6px 6px 0 rgba(31, 29, 26, 0.18);
}
#editor-toggle .editor-toggle-icon {
  font-size: 13px;
}

/* Phones: collapse the launcher to a compact icon button so it stops sitting
   on top of page text (marquee CTA, footer copy). font-size: 0 hides the
   "Customize" text node while keeping it as the accessible name. */
@media (max-width: 720px) {
  #editor-toggle {
    font-size: 0;
    letter-spacing: 0;
    gap: 0;
    width: 46px;
    height: 46px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }
  #editor-toggle .editor-toggle-icon {
    font-size: 17px;
  }
}

/* ---------- Drawer ---------- */
#editor-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 160;
  width: min(460px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--ed-paper);
  color: var(--ed-ink);
  border-left: 1px solid var(--ed-line);
  box-shadow: -8px 0 28px rgba(31, 29, 26, 0.16);
}
#editor-panel[hidden] {
  display: none;
}
.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--ed-line);
}
.editor-head h2 {
  margin: 0;
  font-family: "EB Garamond", Georgia, serif;
  font-style: italic;
  font-size: 24px;
  color: var(--ed-ink);
}
.editor-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
/* ---------- Save bar (draft → server persistence) ---------- */
.editor-savebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--ed-line);
  background: #fff;
}
.editor-savebar[hidden] {
  display: none;
}
.editor-savebar-text {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ed-ink-2);
}
.editor-savebar[data-state="dirty"] .editor-savebar-text::before {
  content: "●";
  color: #d9a514;
  margin-right: 7px;
}
.editor-savebar[data-state="error"] .editor-savebar-text {
  color: var(--ed-danger);
  text-transform: none;
  letter-spacing: 0.02em;
}
.editor-savebar[data-state="saved"] .editor-savebar-text {
  color: #2f6f4f;
}
.editor-savebar[data-state="saved"] .editor-savebar-actions {
  display: none;
}
.editor-savebar-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}
.editor-save {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  background: var(--ed-ink);
  color: #fff;
  border: 1px solid var(--ed-ink);
  border-radius: 6px;
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.45rem 1.1rem;
}
.editor-save:hover:not(:disabled) {
  background: #000;
}
.editor-save:disabled,
.editor-savebar .ghost-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 32px;
  display: grid;
  gap: 8px;
  align-content: start;
}

/* ---------- Collapsible groups ----------
   Flat: no card chrome. Groups read as document sections — an uppercase
   heading with a caret, separated by whitespace and a single hairline. */
.editor-group {
  border: 0;
  background: none;
}
.editor-group + .editor-group {
  border-top: 1px solid var(--ed-line);
  padding-top: 6px;
}
.editor-group-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  list-style: none;
  padding: 12px 0 8px;
}
.editor-group-summary::-webkit-details-marker {
  display: none;
}
/* Hierarchy scale: group titles (largest) → card titles → subgroup labels →
   field labels (smallest), reinforced by indentation on open card bodies. */
.editor-group-title {
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.editor-group-body {
  padding: 2px 0 12px;
  display: grid;
  gap: 14px;
}
.editor-stack {
  display: grid;
  gap: 16px;
}

/* ---------- Form controls ---------- */
#site-editor .field {
  display: grid;
  gap: 0.3rem;
}
#site-editor .field > span {
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ed-muted);
}
#site-editor .field-inline {
  flex: 1 1 0;
  min-width: 7rem;
}
#site-editor .field-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}
/* Quiet controls: text inputs and selects are underlines, textareas are soft
   filled fields — no outlined boxes stacking inside boxes. */
#site-editor input[type="text"],
#site-editor textarea,
#site-editor select {
  width: 100%;
  color: var(--ed-ink);
  font: inherit;
  font-size: 0.85rem;
}
#site-editor input[type="text"],
#site-editor select {
  min-height: 2.1rem;
  padding: 0 0.15rem;
  border: 0;
  border-bottom: 1px solid var(--ed-line);
  border-radius: 0;
  background: transparent;
}
#site-editor input[type="text"]:focus,
#site-editor select:focus {
  outline: none;
  border-bottom-color: var(--ed-ink);
}
#site-editor textarea {
  min-height: 3.2rem;
  padding: 0.55rem 0.65rem;
  border: 0;
  border-radius: 8px;
  background: #fff;
  font: 0.8rem/1.5 ui-monospace, Menlo, Consolas, monospace;
}
#site-editor textarea:focus {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--ed-ink);
}
#site-editor textarea.auto-grow {
  overflow: hidden;
  resize: none;
}
#site-editor input[type="range"] {
  width: 100%;
}
#site-editor .grid-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: 0.6rem;
}
#site-editor .form-hint,
#site-editor .muted {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ed-muted);
  font-weight: 400;
}

/* ---------- Rows / lists / controls ---------- */
#site-editor .row-list {
  display: grid;
  gap: 0.5rem;
}
#site-editor .row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.5rem;
}
#site-editor .row-stack {
  flex-direction: column;
  align-items: stretch;
}
#site-editor .row-list-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}
#site-editor .row-controls {
  display: flex;
  gap: 0.3rem;
  margin-left: auto;
}
#site-editor .subgroup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
/* Buttons are soft filled chips — no outlines. */
#site-editor .icon-button {
  -webkit-appearance: none;
  appearance: none;
  background: #efece2;
  border: 0;
  border-radius: 6px;
  color: var(--ed-ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  height: 1.9rem;
  min-width: 1.9rem;
  padding: 0 0.45rem;
}
#site-editor .icon-button:hover:not(:disabled) {
  background: #e3dfd0;
}
#site-editor .icon-button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
#site-editor .icon-button.danger:hover:not(:disabled) {
  background: #fbeae5;
  color: var(--ed-danger);
}
#site-editor .secondary-button,
#site-editor .ghost-button {
  -webkit-appearance: none;
  appearance: none;
  background: #efece2;
  border: 0;
  border-radius: 999px;
  color: var(--ed-ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.45rem 0.9rem;
}
#site-editor .secondary-button:hover,
#site-editor .ghost-button:hover {
  background: #e3dfd0;
}
#site-editor .select-inline {
  min-height: 1.9rem;
  width: auto;
  padding: 0 0.5rem;
}

/* ---------- Add-section control ---------- */
#site-editor .add-section {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
#site-editor .add-section-toggle.is-open {
  background: var(--ed-ink);
  color: #fff;
}
#site-editor .add-section-menu {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
}
#site-editor .add-section-menu[hidden] {
  display: none;
}
#site-editor .add-section-option {
  -webkit-appearance: none;
  appearance: none;
  background: #fff;
  border: 0;
  border-radius: 999px;
  color: var(--ed-ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.4rem 0.8rem;
  box-shadow: inset 0 0 0 1px var(--ed-line);
}
#site-editor .add-section-option:hover {
  background: var(--ed-ink);
  color: #fff;
  box-shadow: none;
}
@media (prefers-reduced-motion: no-preference) {
  #site-editor .add-section-menu {
    animation: ed-fade-in 0.16s ease;
  }
}
@keyframes ed-fade-in {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Per-section jump control: right-aligned before the ↑↓✕ controls, quiet
   until hovered. margin-left:auto claims the spacer so the row reads
   [title …………… ⌖ ↑ ↓ ✕]. */
#site-editor .jump-button {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--ed-muted);
}
#site-editor .jump-button:hover:not(:disabled) {
  background: #efece2;
  color: var(--ed-ink);
}
/* The jump button claims the row spacer, so the ↑↓✕ controls that follow it
   must not also take an auto margin (two auto margins would split the space
   and strand the jump button mid-row). */
#site-editor .jump-button ~ .row-controls {
  margin-left: 0;
}

/* ---------- Section / product / gallery cards ----------
   Flat list rows separated by hairlines — not stacked bordered boxes. */
#site-editor .sections-list,
#site-editor .products-list {
  display: grid;
  gap: 0;
}
#site-editor .section-card,
#site-editor .product-card {
  border: 0;
  border-radius: 0;
  padding: 0.55rem 0;
  background: none;
  display: grid;
  gap: 0.7rem;
}
#site-editor .section-card + .section-card,
#site-editor .product-card + .product-card {
  border-top: 1px solid var(--ed-line);
}
#site-editor details.section-card > summary,
#site-editor details.product-card > summary {
  list-style: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
#site-editor details.section-card > summary::-webkit-details-marker,
#site-editor details.product-card > summary::-webkit-details-marker {
  display: none;
}
#site-editor .section-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
#site-editor .section-type {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ed-ink);
}
#site-editor .accordion-caret::before {
  content: "\25B8";
  display: inline-block;
  color: var(--ed-muted);
  font-size: 0.8rem;
  transition: transform 0.15s ease;
}
#site-editor details[open] > summary .accordion-caret::before {
  transform: rotate(90deg);
}
#site-editor .accordion-title {
  font-weight: 700;
  font-size: 0.86rem;
}
#site-editor .section-card-body,
#site-editor .section-fields {
  display: grid;
  gap: 0.7rem;
}
/* Open card bodies indent under their header with a soft inset rule, so the
   nesting depth stays readable without bordered boxes. */
#site-editor .section-card-body {
  margin-top: 0.2rem;
  padding-left: 12px;
  border-left: 2px solid rgba(31, 29, 26, 0.08);
}
#site-editor .subgroup {
  margin-top: 0.7rem;
  display: grid;
  gap: 0.5rem;
}
#site-editor .subgroup--flush {
  margin-top: 0;
}
#site-editor .subgroup > strong {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ed-ink-2);
}

/* Flat "more options" disclosure — a plain text toggle rather than another
   nested card, so optional fields fold away without box-in-box clutter. */
#site-editor details.editor-more {
  display: grid;
  gap: 0.7rem;
}
#site-editor .editor-more-summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
  -webkit-user-select: none;
  user-select: none;
  color: var(--ed-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
#site-editor .editor-more-summary::-webkit-details-marker {
  display: none;
}
#site-editor .editor-more-summary:hover {
  color: var(--ed-ink);
}

/* ---------- Image input ---------- */
#site-editor .image-input {
  display: grid;
  gap: 0.3rem;
}
#site-editor .image-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: end;
}
#site-editor .image-input-pick {
  -webkit-appearance: none;
  appearance: none;
  background: var(--ed-ink);
  border: 0;
  border-radius: 999px;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0 0.9rem;
  min-height: 2.1rem;
}
#site-editor .image-input-pick:hover {
  background: #000;
}
#site-editor .image-input-preview {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--ed-paper-2);
  border: 1px solid var(--ed-line);
}

/* ---------- Media picker modal (inside #site-editor) ---------- */
#media-picker {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
#media-picker[hidden] {
  display: none;
}
.media-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 29, 26, 0.55);
}
.media-picker-card {
  position: relative;
  width: min(820px, 100%);
  max-height: 88vh;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 0.75rem;
  padding: 1.1rem;
  background: var(--ed-paper);
  border-radius: 12px;
  border: 1px solid var(--ed-line);
  overflow: hidden;
}
.media-picker-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.media-picker-heading h2 {
  margin: 0;
  font-family: "EB Garamond", Georgia, serif;
  font-style: italic;
}
.media-picker-message {
  margin: 0;
  min-height: 1rem;
  font-size: 0.8rem;
  color: var(--ed-ink-2);
}
.media-picker-message.is-error {
  color: var(--ed-danger);
}
#media-picker .media-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 1.2rem 1rem;
  border: 1px dashed var(--ed-muted);
  border-radius: 12px;
  background: var(--ed-paper-2);
  cursor: pointer;
  text-align: center;
}
#media-picker .media-drop:hover,
#media-picker .media-drop.is-dragover {
  border-color: var(--ed-ink);
  background: #fff;
}
.media-drop-headline {
  font-weight: 700;
}
.media-drop-help {
  font-size: 0.8rem;
  color: var(--ed-muted);
}
#media-picker .media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
  overflow-y: auto;
  padding-right: 0.25rem;
}
#media-picker .media-card {
  display: grid;
  gap: 0.4rem;
  padding: 0.5rem;
  background: #fff;
  border: 1px solid var(--ed-line);
  border-radius: 8px;
  cursor: pointer;
}
#media-picker .media-card:hover {
  border-color: var(--ed-ink);
}
.media-card-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--ed-paper-2);
  border-radius: 6px;
}
.media-card-meta {
  display: grid;
  gap: 0.05rem;
  font-size: 0.72rem;
  min-width: 0;
}
.media-card-filename {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.media-card-sub {
  color: var(--ed-muted);
}

@media (max-width: 480px) {
  #editor-panel {
    width: 100vw;
  }
  #editor-toggle {
    right: 12px;
    bottom: 12px;
  }
}
