/* ==========================================================================
   Site Builder — styles
   Mirrors the Broker Marketplace builder: white toolbar, gray canvas,
   320px right rail with chat + publish footer.
   ========================================================================== */

:root {
  --purple: #7c3aed;
  --purple-dark: #6d28d9;
  --green: #16a34a;
  --green-dark: #15803d;
  --ink: #1f2430;
  --ink-soft: #5b6472;
  --ink-faint: #9aa3b2;
  --border: #e3e6eb;
  --canvas-bg: #eef0f3;
  --danger: #ef4444;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: #fff;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  font-size: 13px;
}

button { font-family: inherit; }

/* ============================ TOOLBAR ============================ */

#toolbar {
  height: 52px;
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  z-index: 40;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }

.tb-div {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
  flex: 0 0 auto;
}

.tb-spacer { flex: 1 1 auto; min-width: 8px; }

.tb-group {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.tb-btn:hover:not(:disabled) { background: #f1f3f6; color: var(--ink); }
.tb-btn:disabled { opacity: .38; cursor: default; }
.tb-btn.is-active { background: #ede9fe; color: var(--purple-dark); }
.tb-btn svg { display: block; }
.tb-icon { padding: 7px; }

/* segmented device control */
.seg {
  background: #f1f3f6;
  border-radius: 8px;
  padding: 2px;
}
.seg .tb-btn { padding: 6px 8px; }
.seg .tb-btn.is-active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* change-count badge */
.change-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ede9fe;
  color: var(--purple-dark);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---------------- custom dropdowns ---------------- */

.dd { position: relative; flex: 0 0 auto; }

.dd-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  max-width: 240px;
}
.dd-btn:hover { background: #f7f8fa; }
.dd-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dd-chev { color: var(--ink-faint); flex: 0 0 auto; }

.dd-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 230px;
  max-width: 320px;
  max-height: 380px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(20, 25, 40, .14);
  padding: 6px;
  z-index: 60;
}
.dd-panel-wide { min-width: 270px; }

.dd-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}
.dd-item:hover:not(.is-disabled) { background: #f1f3f6; }
.dd-item.is-current { background: #ede9fe; color: var(--purple-dark); font-weight: 600; }
.dd-item.is-disabled { opacity: .55; cursor: not-allowed; }
.dd-item .dd-note {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-faint);
  margin-top: 2px;
}
.dd-group-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-faint);
  padding: 8px 10px 4px;
}

/* ---------------- live/draft pill ---------------- */

.view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  padding: 6px 12px 6px 9px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  flex: 0 0 auto;
}
.view-toggle .view-dot {
  width: 8px; height: 8px;
  border-radius: 999px;
  background: currentColor;
}
.view-toggle.is-live { color: var(--green); border-color: #bbf7d0; background: #f0fdf4; }
.view-toggle.is-draft { color: var(--ink-soft); border-color: var(--border); background: #f7f8fa; }

/* ---------------- + New button ---------------- */

.btn-new {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 8px;
  background: var(--purple);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 14px;
  cursor: pointer;
  flex: 0 0 auto;
}
.btn-new:hover { background: var(--purple-dark); }

/* ---------------- site url chip ---------------- */

.site-url {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  font-size: 12px;
  cursor: pointer;
  padding: 6px 4px;
  flex: 0 0 auto;
}
.site-url:hover { color: var(--ink-soft); }

/* ============================ CANVAS ============================ */

#canvasWrap {
  position: relative;
  flex: 1 1 auto;
  background: var(--canvas-bg);
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 22px;
}

#frameWrap {
  width: 100%;
  max-width: 1440px;
  height: calc(100vh - 52px - 44px);
  min-height: 420px;
  background: #fff;
  box-shadow: 0 2px 14px rgba(20, 25, 40, .10);
  overflow: hidden;
  transition: width .18s ease, border-radius .18s ease;
}

#frameWrap.frame-tablet {
  width: 768px;
  border-radius: 18px;
  border: 10px solid #2b2f36;
  height: calc(100vh - 52px - 64px);
}
#frameWrap.frame-mobile {
  width: 390px;
  border-radius: 26px;
  border: 10px solid #2b2f36;
  height: calc(100vh - 52px - 64px);
}

#pageFrame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #fff;
}

/* loading spinner */
.spinner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(238, 240, 243, .7);
  z-index: 20;
}
.spinner {
  width: 34px; height: 34px;
  border-radius: 999px;
  border: 3px solid #d6dae1;
  border-top-color: var(--purple);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* stale-draft banner */
.stale-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--amber-bg);
  color: var(--amber);
  border: 1px solid #fcd34d;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 12.5px;
  font-weight: 600;
  z-index: 25;
  box-shadow: 0 4px 14px rgba(180, 120, 20, .18);
  max-width: min(640px, 90%);
}
.stale-banner button {
  border: 0; background: transparent; color: inherit;
  cursor: pointer; padding: 2px; display: flex;
}

/* floating element inspector */
.select-panel {
  position: absolute;
  top: 64px;
  left: 32px;
  width: 250px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(20, 25, 40, .16);
  padding: 12px;
  z-index: 30;
}
.select-close {
  position: absolute;
  top: 8px; right: 8px;
  border: 0; background: transparent; color: var(--ink-faint);
  cursor: pointer; padding: 4px; display: flex;
}
.select-close:hover { color: var(--ink); }
.select-tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .05em;
  color: var(--purple-dark);
  background: #ede9fe;
  border-radius: 5px;
  padding: 3px 7px;
  margin-bottom: 7px;
}
.select-text {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.45;
  margin-bottom: 10px;
  word-break: break-word;
  max-height: 66px;
  overflow: hidden;
}
.select-actions { display: flex; gap: 6px; }
.select-actions button {
  flex: 1;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 7px 4px;
  cursor: pointer;
  color: var(--ink);
}
.select-actions button:hover { background: #f4f5f7; }
.select-actions button.danger { color: var(--danger); border-color: #fecaca; }
.select-actions button.danger:hover { background: #fef2f2; }

/* ============================ RIGHT RAIL ============================ */

#rail {
  flex: 0 0 320px;
  width: 320px;
  background: #fff;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 35;
}

.rail-pane {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---- chat ---- */
.chat-crumb {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.crumb-page { font-weight: 700; font-size: 13.5px; }
.crumb-path { color: var(--ink-faint); font-size: 11.5px; }

.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg { max-width: 92%; }

.msg-user {
  align-self: flex-end;
  background: var(--purple);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
  padding: 10px 13px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-assistant { align-self: flex-start; max-width: 94%; }
.msg-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--purple-dark);
  background: #f5f3ff;
  border: 1px solid #e9e4fb;
  border-radius: 999px;
  padding: 3px 9px;
  margin-bottom: 6px;
}
.msg-bubble {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px 14px 14px 14px;
  padding: 10px 13px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
#chatInput {
  flex: 1 1 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 13px;
  outline: none;
  min-width: 0;
}
#chatInput:focus { border-color: var(--purple); box-shadow: 0 0 0 3px #ede9fe; }
.send-btn {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  border: 0;
  border-radius: 999px;
  background: var(--purple);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.send-btn:hover:not(:disabled) { background: var(--purple-dark); }
.send-btn:disabled { opacity: .5; cursor: default; }

/* ---- versions ---- */
.versions-head { padding: 12px 14px 6px; }
.btn-snapshot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
}
.btn-snapshot:hover { background: #f4f5f7; }

.versions-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.version-card {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
}
.version-meta { margin-bottom: 8px; }
.version-label { font-weight: 700; font-size: 12.5px; }
.version-time { font-size: 11.5px; color: var(--ink-faint); margin-top: 2px; }
.version-actions { display: flex; gap: 6px; }
.version-actions button {
  flex: 1;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 4px;
  cursor: pointer;
}
.version-actions button:hover { background: #f4f5f7; }
.version-actions .v-restore { color: var(--purple-dark); border-color: #d9cffb; }
.version-actions .v-restore:hover { background: #f5f3ff; }
.version-actions .v-delete { color: var(--danger); }
.versions-empty {
  color: var(--ink-faint);
  font-size: 12.5px;
  text-align: center;
  padding: 24px 8px;
  line-height: 1.5;
}

/* ---- rail footer ---- */
.rail-footer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  background: #fff;
}
.footer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.draft-pill {
  flex: 1 1 auto;
  background: #f1f3f6;
  color: var(--ink-soft);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  padding: 9px 12px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-publish {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  border-radius: 9px;
  background: var(--green);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 18px;
  cursor: pointer;
}
.btn-publish:hover:not(:disabled) { background: var(--green-dark); }
.btn-publish:disabled { opacity: .5; cursor: default; }

.draft-status { font-size: 11.5px; color: var(--ink-faint); margin-bottom: 4px; }
.draft-status.has-changes { color: var(--amber); font-weight: 600; }

.link-btn {
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  font-size: 11.5px;
  cursor: pointer;
  padding: 2px 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 8px;
}
.link-btn:hover { color: var(--ink-soft); text-decoration: underline; }

.url-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  background: #f0fdf4;
  border: 1px solid #d9f2e2;
  border-radius: 8px;
  padding: 7px 9px;
}
.url-lock { color: var(--green); flex: 0 0 auto; }
.url-text {
  flex: 1 1 auto;
  font-size: 11.5px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.url-btn {
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 3px;
  display: flex;
  border-radius: 5px;
}
.url-btn:hover { color: var(--ink); background: #e6f6ec; }

/* ============================ TOASTS ============================ */

#toasts {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: #1f2430;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,.22);
  animation: toast-in .18s ease;
  max-width: min(520px, 90vw);
  text-align: center;
}
.toast.error { background: #b91c1c; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================ MODAL ============================ */

/* The `hidden` attribute must always win over component display rules. */
[hidden] { display: none !important; }

.modal-overlay[hidden] { display: none !important; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 25, 40, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
}
.modal {
  background: #fff;
  border-radius: 14px;
  width: min(440px, 92vw);
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,.25);
}
.modal h3 { margin: 0 0 10px; font-size: 16px; }
.modal-body { font-size: 13px; color: var(--ink-soft); line-height: 1.55; margin-bottom: 16px; }
.modal-body ul { margin: 8px 0 0; padding-left: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-field { display: block; margin: 0 0 12px; }
.modal-field:last-child { margin-bottom: 2px; }
.modal-field > span { display: block; font-size: 12px; font-weight: 600; color: var(--ink); margin-bottom: 5px; }
.modal-field input[type="text"] {
  width: 100%; box-sizing: border-box;
  font: inherit; font-size: 13px; color: var(--ink);
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.modal-field input[type="text"]:focus { outline: 2px solid var(--purple); outline-offset: 1px; border-color: var(--purple); }
.btn-secondary {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary:hover { background: #f4f5f7; }
.btn-primary {
  border: 0;
  border-radius: 8px;
  background: var(--purple);
  color: #fff;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:hover { background: var(--purple-dark); }
.btn-primary.is-green { background: var(--green); }
.btn-primary.is-green:hover { background: var(--green-dark); }

/* ============================ RESPONSIVE ============================ */

@media (max-width: 1100px) {
  #rail {
    position: fixed;
    top: 52px;
    right: 0;
    bottom: 0;
    width: min(340px, 92vw);
    box-shadow: -12px 0 32px rgba(20, 25, 40, .16);
    transform: translateX(105%);
    transition: transform .2s ease;
  }
  #rail.open { transform: translateX(0); }
  .tb-btn span { display: none; }
  .tb-btn { padding: 8px; }
}

/* ============================ LOCK SCREEN ============================ */
body.locked #toolbar,
body.locked #canvasWrap,
body.locked #rail { display: none !important; }
.lock-screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  align-items: center;
  justify-content: center;
  background: var(--canvas-bg);
  padding: 20px;
}
body.locked .lock-screen { display: flex; }
.lock-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 36px 30px;
  width: 100%;
  max-width: 350px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(31,36,48,.12);
}
.lock-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: #f3efff;
  color: var(--purple);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lock-card h2 { margin: 0 0 6px; font-size: 20px; color: var(--ink); }
.lock-sub { margin: 0 0 20px; font-size: 13px; color: var(--ink-soft); }
.lock-input {
  width: 100%;
  padding: 11px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  color: var(--ink);
}
.lock-input:focus { outline: 2px solid var(--purple); outline-offset: -1px; border-color: var(--purple); }
.lock-go { width: 100%; padding: 11px; font-size: 14px; }
.lock-go:disabled { opacity: .6; cursor: wait; }
.lock-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; }
