/* ============================================================
   On-page editor (admin project only; the middleware adds this file).
   1. the page itself, held still and made room for the bar
   2. editing affordances on the page (text, photos, sections, links)
   3. the editor's own UI (bar, menus, dialogs, picker, settings)
   ============================================================ */

:root { --edit-h: calc(56px + env(safe-area-inset-top)); --ed-shadow: 0 18px 50px rgba(42, 40, 48, 0.22), 0 2px 8px rgba(42, 40, 48, 0.12); --ed-warm: #d9a441; --ed-good: #7fb08a; --ed-bad: #b4524f; }

/* ---------- 1. the page, still ---------- */
html[data-edit] body { padding-top: calc(var(--head-total) + var(--edit-h)); }
html[data-edit] body[data-page="home"] { padding-top: calc(var(--bar-h) + var(--edit-h)); }
html[data-edit] .site-head { top: var(--edit-h); }
html[data-edit] body[data-page="home"] .hero-frame { height: calc(100svh - var(--bar-h) - var(--edit-h)); }
html[data-edit] .hero-frame { height: calc(100svh - var(--head-total) - var(--edit-h)); }
html[data-edit] .hero-curtain { display: none; }
html[data-edit] .hero-slide img { transform: none !important; }
html[data-edit] .hero-dot.is-active::after { animation: none; transform: scaleX(1); }
html[data-edit] .rise, html[data-edit] [data-reveal] { animation: none; opacity: 1; transform: none; transition: none; }
html[data-edit] .unveil { clip-path: none; animation: none; }
html[data-edit] .process-stage { height: auto; padding-block: 4rem; }
html[data-edit] .process-media img { transform: none; }
html[data-edit] .process-copy { min-height: 0; display: grid; gap: 2rem; }
html[data-edit] .process-step { position: static; opacity: 1; transform: none; }
html[data-edit] .plate-fig img.alt { display: none; }          /* the hover photo is photo 2; reorder it in the gallery */
html[data-edit] .gallery-main { cursor: default; }
html[data-edit] img[data-cms-img] { -webkit-user-drag: none; user-select: none; }
html[data-edit] .ed-dragging, html[data-edit] .ed-dragging * { cursor: grabbing !important; user-select: none !important; }

/* ---------- 2. editing on the page ---------- */
/* text */
html.ed-ready .ed-text { cursor: text; border-radius: 3px; transition: outline-color 0.15s ease; outline: 1px dashed transparent; outline-offset: 4px; }
html.ed-ready .ed-text:hover { outline-color: currentColor; }
html.ed-ready .ed-text.ed-editing { outline: 2px solid var(--blue); outline-offset: 4px; caret-color: var(--blue); }
.band .ed-text.ed-editing, .hero .ed-text.ed-editing { outline-color: #fff; caret-color: #fff; }

/* photos: hover hint, drop target, drag ghost, upload cover */
.ed-spot { position: fixed; z-index: 900; pointer-events: none; border-radius: 6px; box-shadow: inset 0 0 0 2px var(--blue), 0 0 0 1px rgba(255, 255, 255, 0.6); }
.ed-spot[hidden] { display: none; }
.ed-spot::after { content: attr(data-label); position: absolute; left: 0.6rem; top: 0.6rem; background: var(--blue); color: #fff; font: 500 0.72rem/1 var(--font); letter-spacing: 0.02em; padding: 0.45rem 0.7rem; border-radius: 999px; white-space: nowrap; }
.ed-spot-target { box-shadow: inset 0 0 0 3px var(--blue), 0 0 0 2px #fff; background: rgba(82, 112, 175, 0.22); }
.ed-ghost { position: fixed; left: 0; top: 0; z-index: 1001; pointer-events: none; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; box-shadow: var(--ed-shadow); border: 2px solid #fff; }
.ed-ghost img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ed-busy { position: absolute; z-index: 800; display: grid; place-items: center; background: rgba(42, 40, 48, 0.62); color: #fff; font: 500 0.85rem/1.2 var(--font); border-radius: 6px; pointer-events: none; text-align: center; padding: 1rem; }
.ed-busy.bad { background: rgba(180, 82, 79, 0.85); }

/* sections */
html[data-edit] [data-cms-show] { position: relative; }
.ed-eye { position: absolute; top: 0.8rem; right: var(--gutter); z-index: 20; display: inline-flex; align-items: center; gap: 0.45rem; font: 500 0.72rem/1 var(--font); letter-spacing: 0.02em; color: var(--ink); background: rgba(251, 249, 245, 0.94); border: 1px solid var(--line); border-radius: 999px; padding: 0.5rem 0.8rem; box-shadow: 0 2px 10px rgba(42, 40, 48, 0.08); opacity: 0.55; transition: opacity 0.2s ease, background 0.2s ease; }
[data-cms-show]:hover > .ed-eye, .ed-eye:focus-visible { opacity: 1; }
.ed-eye:hover { background: #fff; }
.cms-hidden { outline: 2px dashed var(--ink-faint); outline-offset: -2px; }
.cms-hidden > :not(.ed-eye) { opacity: 0.28; filter: grayscale(0.7); }
.cms-hidden > .ed-eye { opacity: 1; background: var(--ink); color: var(--putty); border-color: var(--ink); }

/* where a tile or photo links to */
html[data-edit] .ed-has-link { position: relative; }
.ed-link { position: absolute; top: 0.7rem; left: 0.7rem; z-index: 6; font: 500 0.72rem/1 var(--font); letter-spacing: 0.02em; color: var(--ink); background: rgba(251, 249, 245, 0.94); border: 1px solid var(--line); border-radius: 999px; padding: 0.5rem 0.8rem; box-shadow: 0 2px 10px rgba(42, 40, 48, 0.1); max-width: calc(100% - 1.4rem); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: none; }
.ed-link:hover { background: #fff; }
.ed-hero-tools { position: absolute; z-index: 45; top: calc(var(--head-h) + 0.9rem); right: var(--gutter); display: flex; gap: 0.5rem; align-items: center; }
.ed-hero-tools .ed-link { position: static; max-width: none; }
.ed-hero-count { font: 500 0.72rem/1 var(--font); color: #fff; background: rgba(42, 40, 48, 0.55); padding: 0.55rem 0.8rem; border-radius: 999px; }

/* ---------- 3. the editor's own UI ---------- */
.ed-bar { position: fixed; top: 0; left: 0; right: 0; height: var(--edit-h); z-index: 1000; display: flex; align-items: center; gap: 1rem; padding: env(safe-area-inset-top) clamp(0.8rem, 2vw, 1.4rem) 0; background: var(--ink); color: var(--putty); font: 400 0.88rem/1.2 var(--font); }
.ed-bar-left, .ed-bar-right { display: flex; align-items: center; gap: 0.6rem; }
.ed-bar-right { margin-left: auto; }
.ed-brand { font-size: 0.66rem; font-weight: 500; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-faint); }
.ed-select { font: inherit; color: var(--putty); background: rgba(244, 240, 234, 0.08); border: 1px solid rgba(244, 240, 234, 0.2); border-radius: 8px; padding: 0.5rem 2rem 0.5rem 0.7rem; appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-size: 5px 5px; background-repeat: no-repeat; max-width: 22rem; }
.ed-select option { color: var(--ink); }
.ed-status { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: rgba(244, 240, 234, 0.85); white-space: nowrap; }
.ed-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ed-good); flex: none; }
.ed-status.is-unsaved::before { background: var(--ed-warm); }
.ed-status.is-saved::before { background: #9db3de; }
.ed-status.is-busy::before { background: var(--putty); animation: ed-pulse 0.9s ease-in-out infinite alternate; }
.ed-status.is-bad { color: #f1b9b6; }
.ed-status.is-bad::before { background: var(--ed-bad); }
@keyframes ed-pulse { to { opacity: 0.3; } }

.ed-btn { font: 500 0.78rem/1 var(--font); letter-spacing: 0.04em; color: inherit; background: transparent; border: 1px solid currentColor; border-radius: 999px; padding: 0.7rem 1.1rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 0.4rem; transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease; }
.ed-btn:hover:not(:disabled) { background: rgba(244, 240, 234, 0.12); }
.ed-btn:disabled { opacity: 0.38; cursor: default; }
.ed-btn-quiet { border-color: transparent; }
.ed-btn-exit { border-color: rgba(244, 240, 234, 0.35); }
.ed-btn-solid { background: var(--blue); border-color: var(--blue); color: #fff; }
.ed-btn-solid:hover:not(:disabled) { background: var(--blue-deep); border-color: var(--blue-deep); }
.ed-btn-hot { background: var(--putty); color: var(--ink); border-color: var(--putty); }
.ed-btn-hot:hover:not(:disabled) { background: #fff; }
.ed-bar .ed-btn:focus-visible, .ed-select:focus-visible { outline: 2px solid #9db3de; outline-offset: 2px; }

.ed-history { display: flex; gap: 0.1rem; padding-right: 0.4rem; margin-right: 0.2rem; border-right: 1px solid rgba(244, 240, 234, 0.18); }
.ed-history .ed-btn { padding-inline: 0.75rem; }
.ed-history span { font-size: 1rem; line-height: 0; }
.ed-more { position: relative; }
.ed-more-menu, .ed-menu { background: var(--putty); color: var(--ink); border-radius: 12px; box-shadow: var(--ed-shadow); padding: 0.4rem; min-width: 230px; display: grid; }
.ed-more-menu { position: absolute; right: 0; top: calc(100% + 8px); }
.ed-more-menu[hidden] { display: none; }
.ed-more-menu button, .ed-menu button { font: 400 0.9rem/1.3 var(--font); text-align: left; color: var(--ink); background: none; border: 0; border-radius: 8px; padding: 0.65rem 0.8rem; cursor: pointer; }
.ed-more-menu button:hover:not(:disabled), .ed-menu button:hover, .ed-menu button:focus-visible { background: var(--linen); outline: none; }
.ed-more-menu button:disabled { opacity: 0.4; cursor: default; }
.ed-menu { position: fixed; z-index: 1100; max-height: 70vh; overflow-y: auto; }
.ed-menu-title { font: 500 0.66rem/1 var(--font); letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-soft); padding: 0.6rem 0.8rem 0.4rem; }
.ed-menu button[aria-checked="true"] { color: var(--blue); font-weight: 500; }
.ed-menu button[aria-checked="true"]::after { content: " ✓"; }

.ed-dialog { position: fixed; inset: 0; z-index: 1200; background: rgba(42, 40, 48, 0.45); display: grid; place-items: center; padding: 1rem; }
.ed-dialog-box { background: var(--putty); color: var(--ink); border-radius: var(--r); padding: 1.6rem 1.6rem 1.3rem; width: min(460px, 100%); box-shadow: var(--ed-shadow); font-family: var(--font); }
.ed-dialog-box h2 { font-size: 1.3rem; font-weight: 400; letter-spacing: -0.01em; margin-bottom: 0.5rem; }
.ed-dialog-box p { color: var(--ink-soft); line-height: 1.5; }
.ed-dialog-btns { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; margin-top: 1.4rem; }
.ed-dialog .ed-btn { color: var(--ink); }
.ed-dialog .ed-btn:hover:not(:disabled) { background: var(--linen); }
.ed-dialog .ed-btn-solid { color: #fff; }
.ed-dialog .ed-btn-solid:hover { background: var(--blue-deep); }

.ed-toast { position: fixed; left: 50%; bottom: 1.5rem; z-index: 1300; transform: translate(-50%, 1rem); background: var(--ink); color: var(--putty); font: 500 0.85rem/1.3 var(--font); padding: 0.85rem 1.3rem; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity 0.25s ease, transform 0.35s var(--ease-out); max-width: calc(100vw - 2rem); }
.ed-toast.show { opacity: 1; transform: translate(-50%, 0); }
.ed-toast.bad { background: var(--ed-bad); color: #fff; }

.ed-picker { position: fixed; inset: 0; z-index: 1150; background: rgba(42, 40, 48, 0.45); display: grid; place-items: center; padding: 1rem; }
.ed-picker[hidden] { display: none; }
.ed-picker-box { background: var(--putty); color: var(--ink); border-radius: var(--r); width: min(980px, 100%); max-height: 86vh; display: grid; grid-template-rows: auto 1fr; overflow: hidden; box-shadow: var(--ed-shadow); font-family: var(--font); }
.ed-picker-head { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.3rem; border-bottom: 1px solid var(--line-soft); }
.ed-picker-head strong { font-weight: 500; }
.ed-picker-head .ed-btn { margin-left: auto; color: var(--ink); }
.ed-picker-grid { overflow-y: auto; padding: 1rem 1.3rem 1.3rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.8rem; }
.ed-pick-wrap { position: relative; }
.ed-pick { display: grid; gap: 0.4rem; width: 100%; text-align: left; font: 400 0.78rem/1.3 var(--font); color: var(--ink-soft); background: none; border: 0; padding: 0; cursor: pointer; }
.ed-pick img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--linen); border: 2px solid transparent; transition: border-color 0.15s ease; }
.ed-pick:hover img { border-color: var(--line); }
.ed-pick.is-current img { border-color: var(--blue); }
.ed-pick span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ed-pick-add { aspect-ratio: 1; place-content: center; justify-items: center; text-align: center; border: 1.5px dashed var(--ink-faint); border-radius: 8px; padding: 1rem; color: var(--ink); }
.ed-pick-add:hover { border-color: var(--blue); color: var(--blue); }
.ed-pick-add .big { font-size: 2rem; font-weight: 300; line-height: 1; }
.ed-pick-del { position: absolute; top: 0.4rem; right: 0.4rem; width: 1.8rem; height: 1.8rem; border-radius: 50%; border: 0; background: rgba(42, 40, 48, 0.72); color: #fff; font-size: 1.1rem; line-height: 1; cursor: pointer; }
.ed-pick-del:hover { background: var(--ed-bad); }
.ed-note { font: italic 400 0.85rem/1.45 var(--font); color: var(--ink-soft); }

.ed-panel { position: fixed; top: var(--edit-h); right: 0; bottom: 0; z-index: 950; width: min(400px, 100%); background: var(--putty); color: var(--ink); border-left: 1px solid var(--line); box-shadow: var(--ed-shadow); overflow-y: auto; padding: 1.2rem 1.4rem 2rem; font-family: var(--font); display: grid; align-content: start; gap: 1rem; }
.ed-panel[hidden] { display: none; }
.ed-panel-head { display: flex; align-items: center; justify-content: space-between; }
.ed-panel-head strong { font-size: 1.15rem; font-weight: 400; }
.ed-panel-head .ed-btn { color: var(--ink); }
.ed-panel fieldset { border: 0; border-top: 1px solid var(--line-soft); padding-top: 1rem; display: grid; gap: 0.8rem; }
.ed-panel legend { font: 500 0.66rem/1 var(--font); letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-soft); padding-right: 0.5rem; }
.ed-field { display: grid; gap: 0.35rem; font-size: 0.85rem; color: var(--ink-soft); }
.ed-field input, .ed-field textarea { font: 400 0.95rem/1.4 var(--font); color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.75rem; width: 100%; resize: vertical; }
.ed-field input:focus, .ed-field textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: transparent; }

.ed-bar.is-broken { gap: 1.2rem; }
.ed-bar.is-broken .ed-btn { margin-left: auto; }

@media (max-width: 1200px) {
  .ed-brand { display: none; }
  .ed-select { max-width: 14rem; }
  .ed-bar { gap: 0.7rem; }
  .ed-history .ed-btn { font-size: 0; gap: 0; padding-inline: 0.6rem; }
  .ed-history span { font-size: 1.1rem; }
  .ed-status { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 860px) {
  .ed-status { font-size: 0.75rem; }
  .ed-select { max-width: 10rem; }
  .ed-bar { gap: 0.4rem; }
  .ed-btn { padding: 0.6rem 0.75rem; }
  .ed-btn-quiet { padding-inline: 0.5rem; }
}

/* the chooser's actions: upload, swap, move within a gallery */
.ed-pick-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; padding: 0.8rem 1.3rem 0; color: var(--ink); }
.ed-pick-actions .ed-btn { color: var(--ink); }
.ed-pick-actions .ed-btn-solid { color: #fff; }
.ed-pick-actions .ed-btn:hover:not(:disabled) { background: var(--linen); }
.ed-pick-actions .ed-btn-solid:hover { background: var(--blue-deep); }
.ed-upload { cursor: pointer; }
.ed-pick-move { display: inline-flex; gap: 0.5rem; align-items: center; margin-left: auto; }
.ed-more-settings { display: none; }

/* swapping by tapping */
.ed-swap-banner { position: fixed; top: var(--edit-h); left: 0; right: 0; z-index: 1001; display: flex; align-items: center; justify-content: center; gap: 1rem; padding: 0.7rem 1rem; background: var(--blue); color: #fff; font: 500 0.92rem/1.2 var(--font); box-shadow: 0 6px 20px rgba(42, 40, 48, 0.18); }
.ed-swap-banner[hidden] { display: none; }
.ed-swap-banner .ed-btn { border-color: rgba(255, 255, 255, 0.7); padding: 0.5rem 0.9rem; }
html.ed-swapping img[data-cms-img] { outline: 2px dashed rgba(82, 112, 175, 0.9); outline-offset: -2px; cursor: copy; }

/* phones and tablets: nothing to hover, so the section and link buttons always show */
@media (hover: none) {
  .ed-eye { opacity: 1; }
  html.ed-ready .ed-text { outline-color: transparent; }
}

/* phones: the bar splits — Exit, page and status at the top; Undo, Redo, More, Save, Publish at the bottom */
@media (max-width: 760px) {
  :root { --ed-bottom: calc(60px + env(safe-area-inset-bottom)); }
  html[data-edit] body { padding-bottom: var(--ed-bottom); }
  .ed-bar { gap: 0.5rem; }
  .ed-select { flex: 1; max-width: none; min-width: 0; }
  .ed-status { font-size: 0; gap: 0; flex: none; overflow: visible; width: 14px; justify-content: center; }
  .ed-status::before { width: 10px; height: 10px; }
  .ed-bar-right { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; margin: 0; gap: 0.3rem; justify-content: space-between; background: var(--ink); padding: 0.55rem 0.6rem calc(0.55rem + env(safe-area-inset-bottom)); border-top: 1px solid rgba(244, 240, 234, 0.12); }
  .ed-bar-right [data-ed-settings] { display: none; }
  .ed-more-settings { display: block; }
  .ed-history { border: 0; padding: 0; margin: 0; order: -1; }
  .ed-history .ed-btn { font-size: 0; padding: 0.6rem 0.75rem; }
  .ed-history span { font-size: 1.25rem; }
  .ed-more-menu { top: auto; bottom: calc(100% + 10px); right: auto; left: 0; }
  .ed-bar-right .ed-btn { padding: 0.7rem 0.95rem; }
  .ed-btn-exit { padding: 0.6rem 0.8rem; }
  .ed-toast { bottom: calc(var(--ed-bottom) + 0.8rem); }
  .ed-panel { top: var(--edit-h); bottom: var(--ed-bottom); width: 100%; border-left: 0; }
  .ed-picker { padding: 0; place-items: stretch; }
  .ed-picker-box { width: 100%; max-height: none; height: 100%; border-radius: 0; grid-template-rows: auto auto 1fr; padding-top: env(safe-area-inset-top); }
  .ed-picker-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; padding: 0.8rem 1rem calc(1rem + env(safe-area-inset-bottom)); }
  .ed-pick span { font-size: 0.7rem; }
  .ed-pick-actions { padding: 0.8rem 1rem 0; }
  .ed-pick-actions > .ed-btn, .ed-pick-actions > .ed-upload { flex: 1 1 45%; justify-content: center; }
  .ed-pick-move { margin: 0; width: 100%; justify-content: space-between; }
  .ed-eye span { display: none; }
  .ed-eye { padding: 0.55rem; }
  .cms-hidden > .ed-eye span { display: inline; }
  .ed-hero-tools { top: calc(var(--head-h) + 0.5rem); left: var(--gutter); right: var(--gutter); flex-wrap: wrap; }
  .ed-hero-tools .ed-link { white-space: normal; }
}
@media (max-width: 380px) {
  .ed-bar-right { gap: 0.15rem; padding-inline: 0.4rem; }
  .ed-bar-right .ed-btn { padding: 0.65rem 0.6rem; font-size: 0.72rem; letter-spacing: 0.02em; }
  .ed-history .ed-btn { padding: 0.6rem 0.5rem; font-size: 0; }
}
