/* ================================================================== */
/* Inline site editor — drawer + media picker.                          */
/* One rule for the whole form: structure is type + space, and only the     */
/* leaf elements (rows) carry a surface — a slight vertical gradient.       */
/* tabs (Page / Site-wide) → sections → subsections → elements.             */
/* 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.   */
/* ================================================================== */
/* Wider than the form strictly needs: sections carry nested lists, and the
   extra room keeps three-column field rows from wrapping. The docked-mode
   offset below reads the same token, so the page is never overlapped. */
:root {
  --ed-drawer-width: 560px;
}
#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: var(--ed-drawer-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(var(--ed-drawer-width), 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;
}
.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;
  margin: 0 20px;
  padding: 9px 12px;
  border-radius: 3px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(31, 29, 26, 0.05));
}
.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;
}
/* ---------- Top-level tabs ----------
   Two surfaces only: the page the site is showing, and the site-wide settings.
   Nothing else competes for this level, so the form below stays a flat stack of
   sections. */
.editor-tabs {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
  padding: 14px 20px 2px;
}
.editor-tab {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ed-muted);
  padding: 7px 12px;
  border-radius: 3px;
  cursor: pointer;
}
.editor-tab:hover {
  color: var(--ed-ink);
  background: rgba(31, 29, 26, 0.04);
}
.editor-tab.is-active {
  /* The active tab is styled like an element (a slight gradient surface), so
     the tabs read as part of the same form rather than a separate bar. */
  color: var(--ed-ink);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(31, 29, 26, 0.05));
}
.editor-tab:focus-visible {
  outline: 2px solid var(--ed-ink);
  outline-offset: -3px;
}

/* Which page (or gallery) the Page tab is editing — the tab label stays short,
   so the full title + URL live here. */
.editor-context {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  padding: 2px 0 4px;
}
.editor-context-title {
  font-size: 0.84rem;
  font-weight: 800;
}
.editor-context-url {
  font-size: 0.74rem;
  color: var(--ed-muted);
}

#editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 32px;
  display: grid;
  gap: 16px;
  align-content: start;
}
.editor-tabpanel {
  display: grid;
  gap: 14px;
  align-content: start;
}
.editor-tabpanel[hidden] {
  display: none;
}

/* Type scale, top to bottom: tab labels → section headings → subsection
   headings → field labels (headings are ink; field labels stay muted). */
.editor-stack {
  display: grid;
  gap: 1.4rem;
}

/* ---------- 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%;
  accent-color: var(--ed-ink);
}
#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.45rem;
}
/* A row is one element of a list (a nav item, a footer link, a size, a photo…).
   Contiguous rows are delimited by their own gradient wash rather than by
   spacing alone, so a stack of them reads as separate items. */
#site-editor .row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border: 0;
  border-radius: 3px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(31, 29, 26, 0.05));
}

/* Same element treatment, stacked: a photo or paragraph row is taller than a
   one-line link row, so its fields run full width. */
#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 ----------
   Each card is a borderless gradient surface: sections are separated by their
   own tone and the space between them, never by a box. */
#site-editor .sections-list,
#site-editor .products-list {
  display: grid;
  gap: 1.1rem;
}
#site-editor .section-card,
#site-editor .product-card {
  /* A section is a heading and the room around it — no box, no surface. */
  border: 0;
  padding: 0;
  background: none;
  box-shadow: none;
  display: grid;
  gap: 0.7rem;
}
#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.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  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;
}
/* Labelled sub-block inside a section (Watermark, Paragraphs, Photos, an index
   heading). A subsection is a label and its elements — no tint, no indent, no
   rule; the space around the label is what groups it. */
#site-editor .subgroup {
  margin-top: 1rem;
  display: grid;
  gap: 0.5rem;
}
#site-editor .subgroup--flush {
  margin-top: 0;
}
#site-editor .subgroup > strong,
#site-editor .subgroup-header 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;
  /* Same as a section: the heading and the space carry it. */
  border: 0;
  padding: 0;
  background: none;
  box-shadow: none;
}
/* Section/disclosure label — the top of the form's type scale. */
#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-ink);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  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: 4px;
  background: linear-gradient(180deg, var(--ed-paper-2), rgba(31, 29, 26, 0.06));
}

/* ---------- 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;
  }
}
