/* =========================================================
   Site Editor — UI chrome
   Deliberately uses its own neutral tokens (--ed-*), not the
   site's --primary/--accent vars, so the editor stays legible
   no matter what color palette is applied to the page content.
   ========================================================= */

:root {
  --ed-bg: #1A1C1E;
  --ed-panel: #ffffff;
  --ed-ink: #1A1C1E;
  --ed-ink-soft: #5B6168;
  --ed-border: #E2E4E7;
  --ed-accent: #3A6EA5;
  --ed-accent-ink: #ffffff;
  --ed-danger: #B3361E;
  --ed-success: #2E7D4F;
  --ed-radius: 8px;
  --ed-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Arial, sans-serif;
  --ed-z: 2147483000;
}

#site-editor-root, #site-editor-root * {
  box-sizing: border-box;
  font-family: var(--ed-font);
}

@media (prefers-reduced-motion: reduce) {
  #site-editor-root *, #site-editor-root *::before, #site-editor-root *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Toggle button ---------- */
.ed-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: var(--ed-z);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  background: var(--ed-bg);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.ed-toggle:hover { background: #2a2d30; }
.ed-toggle:focus-visible { outline: 3px solid var(--ed-accent); outline-offset: 2px; }
.ed-toggle svg { width: 18px; height: 18px; flex-shrink: 0; }
.ed-toggle.is-hidden { display: none; }

/* ---------- Panel shell ---------- */
.ed-panel {
  position: fixed;
  z-index: var(--ed-z);
  background: var(--ed-panel);
  color: var(--ed-ink);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease;
}
.ed-panel[hidden] { display: none; }

/* Desktop: right-side sliding panel */
@media (min-width: 720px) {
  .ed-panel {
    top: 0;
    right: 0;
    bottom: 0;
    width: 380px;
    max-width: 92vw;
  }
}

/* Mobile: bottom drawer */
@media (max-width: 719.98px) {
  .ed-panel {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 82vh;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.22);
  }
  .ed-drag-handle {
    width: 36px;
    height: 4px;
    background: var(--ed-border);
    border-radius: 999px;
    margin: 10px auto 2px;
    flex-shrink: 0;
  }
}
@media (min-width: 720px) {
  .ed-drag-handle { display: none; }
}

/* ---------- Panel header ---------- */
.ed-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ed-border);
  flex-shrink: 0;
}
.ed-panel-title { font-size: 1rem; font-weight: 700; margin: 0; }
.ed-status {
  font-size: 0.78rem;
  color: var(--ed-ink-soft);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ed-status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ed-success);
  flex-shrink: 0;
}
.ed-status.is-saving .ed-status-dot { background: #C9951A; }
.ed-close {
  background: none;
  border: none;
  width: 32px; height: 32px;
  border-radius: 6px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ed-ink-soft);
}
.ed-close:hover { background: var(--ed-border); color: var(--ed-ink); }
.ed-close:focus-visible { outline: 2px solid var(--ed-accent); outline-offset: 1px; }

/* ---------- Tabs ---------- */
.ed-tabs {
  display: flex;
  border-bottom: 1px solid var(--ed-border);
  flex-shrink: 0;
  overflow-x: auto;
}
.ed-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 11px 8px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ed-ink-soft);
  cursor: pointer;
  white-space: nowrap;
}
.ed-tab:hover { color: var(--ed-ink); }
.ed-tab.is-active { color: var(--ed-accent); border-bottom-color: var(--ed-accent); }
.ed-tab:focus-visible { outline: 2px solid var(--ed-accent); outline-offset: -2px; }

/* ---------- Panel body ---------- */
.ed-panel-body {
  overflow-y: auto;
  padding: 16px;
  flex: 1;
}
.ed-panel-body[hidden] { display: none; }

.ed-field { margin-bottom: 16px; }
.ed-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ed-ink);
}
.ed-hint {
  font-size: 0.78rem;
  color: var(--ed-ink-soft);
  margin: 4px 0 0;
  line-height: 1.4;
}
.ed-input, .ed-select, .ed-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--ed-border);
  border-radius: 6px;
  font-size: 0.88rem;
  background: #fff;
  color: var(--ed-ink);
}
.ed-input:focus-visible, .ed-select:focus-visible, .ed-textarea:focus-visible {
  outline: 2px solid var(--ed-accent);
  outline-offset: 1px;
}
.ed-textarea { resize: vertical; min-height: 60px; }

/* ---------- Buttons ---------- */
.ed-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 6px;
  border: 1px solid var(--ed-border);
  background: #fff;
  color: var(--ed-ink);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}
.ed-btn:hover { background: #F3F4F5; }
.ed-btn:focus-visible { outline: 2px solid var(--ed-accent); outline-offset: 1px; }
.ed-btn-primary { background: var(--ed-accent); border-color: var(--ed-accent); color: var(--ed-accent-ink); }
.ed-btn-primary:hover { background: #2f5c8a; }
.ed-btn-danger { color: var(--ed-danger); border-color: #F2C9C0; }
.ed-btn-danger:hover { background: #FCEEEA; }
.ed-btn-block { width: 100%; }
.ed-btn-sm { padding: 6px 10px; font-size: 0.78rem; }

/* ---------- Edit-mode toggle switch ---------- */
.ed-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #F6F7F8;
  border-radius: var(--ed-radius);
  margin-bottom: 14px;
}
.ed-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.ed-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.ed-switch-track {
  position: absolute;
  inset: 0;
  background: #C7CBD1;
  border-radius: 999px;
  transition: background 0.15s ease;
}
.ed-switch-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.15s ease;
}
.ed-switch input:checked ~ .ed-switch-track { background: var(--ed-accent); }
.ed-switch input:checked ~ .ed-switch-thumb { transform: translateX(18px); }
.ed-switch input:focus-visible ~ .ed-switch-track { outline: 2px solid var(--ed-accent); outline-offset: 2px; }

/* ---------- Color palette grid ---------- */
.ed-palette-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.ed-palette-btn {
  border: 1px solid var(--ed-border);
  border-radius: var(--ed-radius);
  padding: 8px;
  background: #fff;
  cursor: pointer;
  text-align: left;
}
.ed-palette-btn:hover { border-color: var(--ed-accent); }
.ed-palette-btn.is-active { border-color: var(--ed-accent); border-width: 2px; padding: 7px; }
.ed-palette-btn:focus-visible { outline: 2px solid var(--ed-accent); outline-offset: 1px; }
.ed-palette-swatch {
  display: flex;
  height: 22px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}
.ed-palette-swatch span { flex: 1; }
.ed-palette-name { font-size: 0.76rem; font-weight: 600; }

/* ---------- Custom color rows ---------- */
.ed-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.ed-color-row label {
  flex: 1;
  font-size: 0.82rem;
  color: var(--ed-ink);
}
.ed-color-row input[type="color"] {
  width: 34px; height: 34px;
  padding: 0;
  border: 1px solid var(--ed-border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}
.ed-color-row input[type="text"] {
  width: 86px;
  padding: 6px 8px;
  border: 1px solid var(--ed-border);
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: ui-monospace, monospace;
  flex-shrink: 0;
}

/* ---------- Font preview ---------- */
.ed-font-preview {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--ed-border);
  border-radius: 6px;
  font-size: 1.05rem;
  background: #FAFAFA;
}

/* ---------- Image rows ---------- */
.ed-image-row {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--ed-border);
  border-radius: var(--ed-radius);
  margin-bottom: 10px;
}
.ed-image-thumb {
  width: 56px; height: 56px;
  flex-shrink: 0;
  border-radius: 6px;
  border: 1px solid var(--ed-border);
  object-fit: cover;
  background: #F6F7F8;
}
.ed-image-meta { flex: 1; min-width: 0; }
.ed-image-name { font-size: 0.84rem; font-weight: 600; margin-bottom: 6px; }
.ed-image-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ed-file-input { display: none; }
.ed-error-text { color: var(--ed-danger); font-size: 0.78rem; margin-top: 6px; }

.ed-divider { border: none; border-top: 1px solid var(--ed-border); margin: 18px 0; }
.ed-note-box {
  background: #F6F7F8;
  border-radius: var(--ed-radius);
  padding: 10px 12px;
  font-size: 0.78rem;
  color: var(--ed-ink-soft);
  line-height: 1.5;
  margin-bottom: 16px;
}

/* ---------- Inline text-editing mode (applies to the real page, not the panel) ---------- */
body.ed-edit-mode [data-edit-key],
body.ed-edit-mode [data-biz] {
  cursor: text;
  border-radius: 3px;
  outline: 1px dashed transparent;
  outline-offset: 2px;
  transition: outline-color 0.1s ease, background-color 0.1s ease;
}
body.ed-edit-mode [data-edit-key]:hover,
body.ed-edit-mode [data-biz]:hover {
  outline-color: var(--ed-accent);
  background: rgba(58, 110, 165, 0.06);
}
body.ed-edit-mode [data-edit-key]:focus,
body.ed-edit-mode [data-biz]:focus {
  outline: 2px solid var(--ed-accent);
  outline-offset: 2px;
  background: rgba(58, 110, 165, 0.08);
}

/* ---------- Toast ---------- */
.ed-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(8px);
  z-index: var(--ed-z);
  background: var(--ed-bg);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.ed-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Undo / redo in the panel header ---- */
.ed-header-actions { display: flex; align-items: center; gap: 6px; }
.ed-iconbtn {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--ed-border); background: var(--ed-panel); color: var(--ed-ink);
  border-radius: 6px; cursor: pointer; font-size: 15px; line-height: 1; padding: 0;
}
.ed-iconbtn:hover:not(:disabled) { background: #F3F4F5; }
.ed-iconbtn:disabled { opacity: 0.35; cursor: not-allowed; }
.ed-iconbtn:focus-visible { outline: 2px solid var(--ed-accent); outline-offset: 1px; }

/* ---- Warning / info boxes ---- */
.ed-warn {
  background: #FFF6E0; border: 1px solid #EBCB7A; color: #5C4200;
  border-radius: 6px; padding: 10px 12px; font-size: 0.8rem; line-height: 1.45; margin-bottom: 14px;
}
.ed-ok {
  background: #EAF6EE; border: 1px solid #A9D6B8; color: #1D5A35;
  border-radius: 6px; padding: 10px 12px; font-size: 0.8rem; line-height: 1.45; margin-bottom: 14px;
}
.ed-field-error { color: var(--ed-danger); font-size: 0.78rem; margin-top: 4px; }
.ed-section-title { font-size: 0.82rem; font-weight: 700; margin: 18px 0 8px; }

/* ---- Form-field cards and section rows ---- */
.ed-fcard {
  border: 1px solid var(--ed-border); border-radius: 8px; margin-bottom: 8px; background: var(--ed-panel);
}
.ed-fcard-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.ed-fcard-head .ed-fname { flex: 1; min-width: 0; font-size: 0.84rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-fcard.is-off .ed-fname { color: var(--ed-ink-soft); font-weight: 500; }
.ed-fcard details { border-top: 1px solid var(--ed-border); padding: 8px 10px 10px; }
.ed-fcard summary { font-size: 0.78rem; color: var(--ed-accent); cursor: pointer; padding: 2px 0 8px; }
.ed-fcard summary:focus-visible { outline: 2px solid var(--ed-accent); outline-offset: 2px; }
.ed-check-inline { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; margin: 6px 0; }
.ed-check-inline input { width: 18px; height: 18px; }

/* ---- Pre-publication checklist ---- */
.ed-checklist { list-style: none; margin: 0 0 14px; padding: 0; }
.ed-checklist li {
  border: 1px solid var(--ed-border); border-left-width: 4px; border-radius: 6px;
  padding: 8px 10px; margin-bottom: 6px; font-size: 0.8rem; line-height: 1.4;
}
.ed-checklist li.is-error { border-left-color: var(--ed-danger); background: #FCEEEA; }
.ed-checklist li.is-suggestion { border-left-color: #C9951A; background: #FFFBEF; }
.ed-checklist li strong { display: block; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 2px; }
.ed-checklist li.is-error strong { color: var(--ed-danger); }
.ed-checklist li.is-suggestion strong { color: #8A5A00; }

/* Keep the page visible beside / above the open panel so edits can be seen live */
@media (min-width: 720px) {
  body.ed-panel-open { padding-right: 380px; transition: padding-right 0.2s ease; }
}
@media (max-width: 719.98px) {
  body.ed-panel-open { padding-bottom: 60vh; }
}
