/* Editor UI V3 — per-element modal, grips, cursor guides */
:root {
  --ed-bg: #fafafa;
  --ed-panel: #ffffff;
  --ed-ink: #1a1a1a;
  --ed-muted: #717171;
  --ed-line: #e6e6e6;
  --ed-soft: #f1f1f1;
  --ed-accent: #1a1a1a;
  --ed-ui: "Inter", system-ui, sans-serif;
}

.btn-login {
  border-radius: 999px;
  padding: 0.5rem 0.95rem;
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--ink);
  background: transparent;
}
.btn-login:hover { border-color: var(--ink); }
body.is-editing .btn-login { display: none; }

.brand-logo {
  display: block;
  height: 36px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
}

.ed-chrome { pointer-events: none; }
.ed-chrome > * { pointer-events: auto; }

.ed-top {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1rem;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--ed-line);
  font-family: var(--ed-ui);
}
.ed-top-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.ed-logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: #111;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.ed-top strong { display: block; font-size: 0.92rem; font-weight: 600; color: var(--ed-ink); }
.ed-sub { display: block; font-size: 0.75rem; color: var(--ed-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.ed-top-actions { display: flex; gap: 0.45rem; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.ed-btn {
  font-family: var(--ed-ui);
  border-radius: 10px;
  padding: 0.55rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--ed-line);
  background: #fff;
  color: var(--ed-ink);
  cursor: pointer;
}
.ed-btn:hover { background: var(--ed-soft); }
.ed-btn.primary { background: #111; color: #fff; border-color: #111; }
.ed-btn.primary:hover { background: #000; }
.ed-btn.ghost { background: transparent; }
.ed-btn.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

body.is-editing {
  padding-top: 64px;
  padding-bottom: 24px;
}
body.is-editing .topbar { top: 56px; }

body.is-editing .section {
  outline: 1px solid transparent;
  transition: outline-color .15s ease, box-shadow .15s ease;
}
body.is-editing .section:hover { outline-color: #d4d4d4; }
body.is-editing .section.sortable-ghost { opacity: 0.4; }

.section-handle {
  display: none;
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 6;
  background: #111;
  color: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--ed-ui);
  letter-spacing: 0.02em;
  cursor: grab;
}
body.is-editing .section-handle { display: inline-flex; align-items: center; gap: 0.35rem; }
.section-handle::before { content: "⠿"; opacity: 0.7; }

/* Per-element chrome */
body.is-editing .pl-el {
  position: relative;
  transition: box-shadow .15s ease, outline-color .15s ease;
}
body.is-editing [data-edit] {
  outline: 1px dashed rgba(0,0,0,0.16);
  outline-offset: 3px;
  border-radius: 4px;
  cursor: text;
}
body.is-editing a.pl-el[data-el-kind="button"],
body.is-editing [data-link] {
  cursor: pointer;
  outline: 1px solid rgba(27,122,110,0.4);
  outline-offset: 3px;
}
body.is-editing .pl-el.is-focused {
  outline: 2px solid #111 !important;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(0,0,0,0.05);
  z-index: 4;
}
body.is-editing .pl-el.is-dragging {
  z-index: 40;
  opacity: 0.92;
  cursor: grabbing !important;
}
body.is-editing [data-media] {
  outline: 2px dashed rgba(228, 87, 46, 0.55);
  cursor: pointer;
}

.pl-el-tools {
  display: none;
  position: absolute;
  top: -12px;
  left: -8px;
  z-index: 8;
  gap: 4px;
  align-items: center;
}
body.is-editing .pl-el:hover > .pl-el-tools,
body.is-editing .pl-el.is-focused > .pl-el-tools {
  display: inline-flex;
}
.pl-el-grip,
.pl-el-paint {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid #e6e6e6;
  background: #111;
  color: #fff;
  font-size: 0.72rem;
  line-height: 1;
  cursor: grab;
  display: grid;
  place-items: center;
  padding: 0;
  font-family: var(--ed-ui);
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}
.pl-el-paint {
  cursor: pointer;
  background: #fff;
  color: #111;
  font-size: 0.85rem;
}
.pl-el-paint:hover { background: #f5f5f5; }
.pl-el-grip:active { cursor: grabbing; }

/* Modal */
.ed-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10,10,10,0.38);
  display: grid;
  place-items: center;
  padding: 1rem;
  font-family: var(--ed-ui);
}
.ed-modal[hidden] { display: none !important; }
.ed-modal-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 18px;
  border: 1px solid var(--ed-line);
  box-shadow: 0 30px 80px rgba(0,0,0,0.22);
  overflow: hidden;
  animation: ed-pop .18s ease;
}
@keyframes ed-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.ed-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.15rem 0.85rem;
  border-bottom: 1px solid var(--ed-line);
}
.ed-modal-kicker {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ed-muted);
}
.ed-modal-head h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  font-family: var(--ed-ui);
}
.ed-icon {
  border: none;
  background: var(--ed-soft);
  width: 28px; height: 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
}
.ed-modal-body {
  padding: 1rem 1.15rem;
  display: grid;
  gap: 1rem;
  max-height: min(62vh, 520px);
  overflow: auto;
}
.ed-modal-foot {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.9rem 1.15rem 1.1rem;
  border-top: 1px solid var(--ed-line);
  background: #fafafa;
}
.ed-label {
  display: grid;
  gap: 0.45rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ed-muted);
}
.ed-label input, .ed-label select, .ed-label textarea,
#btn-link-fields input, #btn-link-fields select,
#style-body select, #style-body input {
  border: 1px solid var(--ed-line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  color: var(--ed-ink);
  background: #fff;
  width: 100%;
  box-sizing: border-box;
}
.ed-hint { font-size: 0.78rem; color: var(--ed-muted); margin: 0; line-height: 1.45; }
.ed-logo-drop {
  border: 1px dashed #cfcfcf;
  border-radius: 16px;
  padding: 1.15rem;
  display: grid;
  gap: 0.65rem;
  background:
    radial-gradient(circle at 20% 20%, rgba(228,87,46,0.08), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(14,124,134,0.08), transparent 42%),
    #fafafa;
  text-align: center;
}
.ed-logo-drop strong {
  font-size: 0.95rem;
  color: var(--ed-ink);
}
.ed-swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.45rem; }
.ed-swatch {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 2px solid transparent;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}
.ed-swatch.active { border-color: #111; transform: scale(1.06); }
.ed-color-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.ed-color-row input[type="color"] {
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--ed-line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.ed-color-row input[type="text"] {
  flex: 1;
  border: 1px solid var(--ed-line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font: inherit;
}

/* Cursor guides */
.guides {
  position: fixed;
  inset: 0;
  z-index: 65;
  pointer-events: none;
}
.guides[hidden] { display: none !important; }
.guide-v,
.guide-h {
  position: absolute;
  background: transparent;
}
.guide-v {
  top: 0; bottom: 0; width: 0;
  border-left: 1px dashed rgba(228, 87, 46, 0.85);
  left: 0;
}
.guide-h {
  left: 0; right: 0; height: 0;
  border-top: 1px dashed rgba(14, 124, 134, 0.85);
  top: 0;
}
.guide-hud {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17,17,17,0.92);
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  white-space: nowrap;
  max-width: min(92vw, 720px);
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.ed-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 110;
  background: #111;
  color: #fff;
  padding: 0.75rem 1.15rem;
  border-radius: 999px;
  font-family: var(--ed-ui);
  font-size: 0.88rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
.ed-toast[hidden] { display: none !important; }

/* Soft hover transition for styled buttons */
a[data-el-kind="button"],
.btn-solid,
.btn-ghost {
  transition: background .18s ease, color .18s ease, border-color .18s ease, transform .18s ease;
}

@media (max-width: 720px) {
  .ed-sub { display: none; }
  .ed-modal-card { border-radius: 16px 16px 0 0; align-self: end; width: 100%; }
  .mk-panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: min(58vh, 520px);
    border-left: none;
    border-top: 1px solid var(--ed-line);
    border-radius: 18px 18px 0 0;
    transform: translateY(calc(100% - 48px));
  }
  body.is-editing.mk-open .mk-panel { transform: translateY(0); }
  body.is-editing.mk-open #app { margin-right: 0; }
  .mk-fab { display: none; }
}

/* Marketplace panel */
.mk-fab {
  display: none;
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 72;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  border: 1px solid var(--ed-line);
  border-right: none;
  border-radius: 12px 0 0 12px;
  background: #fff;
  color: var(--ed-ink);
  font-family: var(--ed-ui);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.85rem 0.45rem;
  cursor: pointer;
  box-shadow: -8px 0 24px rgba(0,0,0,0.06);
}
body.is-editing .mk-fab { display: inline-flex; align-items: center; }
body.is-editing.mk-open .mk-fab { display: none; }

.mk-panel {
  position: fixed;
  top: 56px;
  right: 0;
  bottom: 0;
  width: min(320px, 92vw);
  z-index: 74;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(16px);
  border-left: 1px solid var(--ed-line);
  font-family: var(--ed-ui);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .22s ease;
  box-shadow: -20px 0 50px rgba(0,0,0,0.08);
}
body.is-editing.mk-open .mk-panel { transform: translateX(0); }
body.is-editing.mk-open #app {
  margin-right: min(320px, 92vw);
  transition: margin-right .22s ease;
}
.mk-panel[hidden] { display: none !important; }
body.is-editing .mk-panel[hidden] { display: flex !important; }

.mk-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.85rem;
  border-bottom: 1px solid var(--ed-line);
}
.mk-kicker {
  margin: 0 0 0.2rem;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ed-muted);
}
.mk-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}
.mk-intro {
  margin: 0;
  padding: 0.85rem 1rem 0;
  font-size: 0.78rem;
  color: var(--ed-muted);
  line-height: 1.45;
}
.mk-list {
  padding: 0.85rem;
  overflow: auto;
  display: grid;
  gap: 0.65rem;
  align-content: start;
}
.mk-card {
  border: 1px solid var(--ed-line);
  border-radius: 14px;
  padding: 0.85rem;
  background: #fff;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem;
  align-items: start;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.mk-card:hover {
  border-color: #cfcfcf;
  box-shadow: 0 10px 28px rgba(0,0,0,0.05);
}
.mk-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #111;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
}
.mk-card h4 {
  margin: 0 0 0.2rem;
  font-size: 0.88rem;
  font-weight: 600;
}
.mk-card p {
  margin: 0 0 0.65rem;
  font-size: 0.75rem;
  color: var(--ed-muted);
  line-height: 1.4;
}
.mk-card-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.mk-card .ed-btn { padding: 0.4rem 0.7rem; font-size: 0.75rem; border-radius: 8px; }
.mk-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--teal, #1b7a6e);
  margin-bottom: 0.25rem;
}
