/* =============================================================================
 * Inspect Mode — Styles
 * DOM element inspector for the Popsicle editor preview mode.
 * ============================================================================= */

/* ---------- Custom Properties ---------- */
:root {
  --ins-accent: #4080ff;
  --ins-accent-hover: #5a9ef6;
  --ins-bg: #0f1117;
  --ins-bg-dark: #0c0d14;
  --ins-surface: #13151e;
  --ins-border: #1e2030;
  --ins-border-focus: #4080ff;
  --ins-text: #e1e3ea;
  --ins-text-dim: #858b98;
  --ins-text-muted: #555a6a;
  --ins-success: #34d399;
  --ins-panel-w: 320px;
  --ins-z-base: 2147483630;
  --ins-mono: 'SF Mono','Cascadia Code','Fira Code','IBM Plex Mono',monospace;
  --ins-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ---------- Inspect Button in Annotate Cluster ---------- */
.annotate-cluster #btn-inspect.inspect-active {
  color: #ff6090 !important;
}
body.preview-active .annotate-cluster #btn-inspect.inspect-active {
  color: #ff6090 !important;
}

/* Suppress focus outline when shift is pressed on inspect button */
#btn-inspect:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}
#btn-inspect:focus {
  outline: none !important;
  box-shadow: none !important;
}

/* ---------- Hover Overlay (highlight border) ---------- */
.ins-hover-overlay {
  position: absolute;
  pointer-events: none;
  z-index: var(--ins-z-base);
  border: 1.5px solid var(--ins-accent);
  background: rgba(90,158,246,0.04);
  transition: top 0.04s, left 0.04s, width 0.04s, height 0.04s;
  opacity: 0;
}
.ins-hover-overlay.ins-visible { opacity: 1; }

/* ---------- Hover Info Label ---------- */
.ins-hover-label {
  position: absolute;
  pointer-events: none;
  z-index: calc(var(--ins-z-base) + 1);
  font-family: var(--ins-mono);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.5;
  padding: 2px 7px;
  background: var(--ins-accent);
  color: #fff;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.08s ease;
}
.ins-hover-label.ins-visible { opacity: 1; }

/* ---------- Blocking Overlay ---------- */
.ins-blocking-overlay {
  position: absolute;
  inset: 0;
  z-index: calc(var(--ins-z-base) - 2);
  cursor: crosshair;
  display: none;
}

/* ---------- Floating Inspector Panel ---------- */
.ins-panel-host {
  position: fixed;
  top: 0; left: 0;
  width: 0; height: 0;
  z-index: 2147483645;
  pointer-events: none;
}

.ins-panel {
  position: fixed;
  width: var(--ins-panel-w);
  background: var(--ins-bg);
  border: 1px solid var(--ins-border);
  border-radius: 4px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4), 0 0 0 1px rgba(30,32,48,0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--ins-mono);
  color: var(--ins-text-dim);
  pointer-events: auto;
  z-index: 2147483646;
  opacity: 0;
  transform: translateX(40px);
  transition: left 0.25s ease, right 0.25s ease, top 0.25s ease,
              transform 0.25s ease, height 0.25s ease, opacity 0.2s ease;
}
.ins-panel.ins-panel-open {
  opacity: 1;
  transform: translateX(0) !important;
}

/* Panel Header */
.ins-panel-hdr {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--ins-bg-dark);
  border-bottom: 1px solid var(--ins-border);
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
  flex-shrink: 0;
  border-radius: 4px 4px 0 0;
}
.ins-panel-hdr:hover .ins-drag-handle { opacity: 1; }

.ins-drag-handle {
  font-size: 13px;
  color: var(--ins-text-muted);
  cursor: grab;
  opacity: 0;
  transition: opacity 0.15s;
  line-height: 1;
  letter-spacing: -1px;
  flex-shrink: 0;
}
.ins-drag-handle:active { cursor: grabbing; }

.ins-panel-title {
  flex: 1;
  font-size: 11px;
  font-weight: 600;
  color: var(--ins-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ins-panel-close {
  background: none;
  border: 1px solid var(--ins-border);
  color: var(--ins-text-muted);
  cursor: pointer;
  padding: 3px 7px;
  display: flex;
  align-items: center;
  transition: all 0.12s;
  flex-shrink: 0;
  border-radius: 3px;
}
.ins-panel-close:hover {
  color: var(--ins-text);
  border-color: #2a2e40;
}

/* Panel Body */
.ins-panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}
.ins-panel-body::-webkit-scrollbar { width: 5px; }
.ins-panel-body::-webkit-scrollbar-track { background: transparent; }
.ins-panel-body::-webkit-scrollbar-thumb { background: var(--ins-border); border-radius: 3px; }
.ins-panel-body::-webkit-scrollbar-thumb:hover { background: #2a2e40; }

/* Panel Footer — fade-up background, no border */
.ins-panel-foot {
  padding: 8px 12px;
  position: relative;
  display: flex;
  justify-content: center;
  border-top: none;
  background: transparent;
}
.ins-panel-foot::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, var(--ins-bg-dark) 30%, transparent 100%);
  pointer-events: none;
  z-index: -1;
}

/* ---------- Panel Resize Handle (bottom edge) ---------- */
.ins-panel-resize-handle {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
  z-index: 10;
  background: transparent;
}
.ins-panel-resize-handle:hover {
  background: rgba(90,158,246,0.15);
}

/* ---------- Merge / Save Button (unified style from div-inspector-stable) ---------- */
.ins-merge-btn,
.ag-popup-btn-submit,
.ag-toolbar-primary {
  /* Shared blue accent button style */
}

.ins-merge-btn {
  width: 100%;
  height: 24px;
  border: 1px solid var(--ins-accent);
  background: var(--ins-accent);
  color: var(--ins-bg);
  font-family: var(--ins-mono);
  font-size: 10.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 3px;
}
.ins-merge-btn svg { flex-shrink: 0; }
.ins-merge-btn:hover {
  background: var(--ins-accent-hover);
  border-color: var(--ins-accent-hover);
}
.ins-merge-btn.saved {
  background: var(--ins-success) !important;
  border-color: var(--ins-success) !important;
  color: var(--ins-bg) !important;
}

/* ---------- Box Model Visualization ---------- */
.ins-bm-wrap {
  padding: 14px 12px;
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(to right, transparent, var(--ins-border) 20%, var(--ins-border) 80%, transparent) 1;
}
.ins-bm-margin {
  position: relative;
  background: rgba(244,180,100,0.10);
  border: 1px dashed rgba(244,180,100,0.3);
  padding: 18px 24px;
  text-align: center;
}
.ins-bm-border {
  position: relative;
  background: rgba(90,158,246,0.08);
  border: 1px dashed rgba(90,158,246,0.3);
  padding: 18px 24px;
}
.ins-bm-padding {
  position: relative;
  background: rgba(92,207,122,0.08);
  border: 1px dashed rgba(92,207,122,0.3);
  padding: 18px 24px;
}
.ins-bm-content {
  background: rgba(180,142,173,0.12);
  border: 1px dashed rgba(180,142,173,0.3);
  padding: 8px 4px;
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: #b48ead;
}
.ins-bm-label {
  position: absolute;
  font-size: 8.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  opacity: 0.7;
}
.ins-bm-label-m { top: 2px; left: 4px; color: #d4976c; }
.ins-bm-label-b { top: 2px; left: 4px; color: #5a9ef6; }
.ins-bm-label-p { top: 2px; left: 4px; color: #5ccf7a; }
.ins-bm-val {
  position: absolute;
  font-size: 9.5px;
  font-weight: 600;
  color: var(--ins-text);
}
.ins-bm-mt { top: 4px; left: 50%; transform: translateX(-50%); }
.ins-bm-mb { bottom: 4px; left: 50%; transform: translateX(-50%); }
.ins-bm-ml { left: 5px; top: 50%; transform: translateY(-50%); }
.ins-bm-mr { right: 5px; top: 50%; transform: translateY(-50%); }
.ins-bm-bt { top: 4px; left: 50%; transform: translateX(-50%); }
.ins-bm-bb { bottom: 4px; left: 50%; transform: translateX(-50%); }
.ins-bm-blw { left: 5px; top: 50%; transform: translateY(-50%); }
.ins-bm-bbr { right: 5px; top: 50%; transform: translateY(-50%); }
.ins-bm-pt { top: 4px; left: 50%; transform: translateX(-50%); }
.ins-bm-pb { bottom: 4px; left: 50%; transform: translateX(-50%); }
.ins-bm-pl { left: 5px; top: 50%; transform: translateY(-50%); }
.ins-bm-pr { right: 5px; top: 50%; transform: translateY(-50%); }

/* ---------- CSS Sections — dividers fade on both sides ---------- */
.ins-section {
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(to right, transparent, var(--ins-border) 15%, var(--ins-border) 85%, transparent) 1;
}
.ins-sec-hdr {
  padding: 8px 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ins-text-muted);
  cursor: pointer;
  user-select: none;
  transition: color 0.12s;
  display: flex;
  align-items: center;
}
.ins-sec-hdr:hover { color: var(--ins-text-dim); }
.ins-chev {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 6px;
  flex-shrink: 0;
  transition: transform 0.15s;
}
.ins-sec-body { padding: 0 0 6px; }
.ins-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 12px;
  font-size: 10.5px;
  line-height: 1;
}
.ins-row:hover { background: rgba(90,158,246,0.04); }
.ins-lbl {
  width: 110px;
  flex-shrink: 0;
  color: var(--ins-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.ins-inp {
  flex: 1;
  min-width: 0;
  padding: 3px 6px;
  background: var(--ins-surface);
  border: 1px solid var(--ins-border);
  color: var(--ins-text);
  font-family: var(--ins-mono);
  font-size: 10.5px;
  outline: none;
  transition: border-color 0.12s;
  height: 22px;
}
.ins-inp:focus { border-color: var(--ins-accent); }
.ins-vwrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.ins-color-picker {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border: 1px solid #2a2e40;
  background: none;
  cursor: pointer;
  padding: 0;
  border-radius: 2px;
}
.ins-color-picker::-webkit-color-swatch-wrapper { padding: 2px; }
.ins-color-picker::-webkit-color-swatch { border: none; border-radius: 1px; }

/* ---------- Sidebar Integration (Inspect Mode Active) ---------- */
#sidebar.ins-sidebar-active .chat-area,
#sidebar.ins-sidebar-active .chat-input-area,
#sidebar.ins-sidebar-active .chat-welcome {
  transition: opacity 0.35s ease, filter 0.35s ease, transform 0.35s ease;
}
#sidebar.ins-sidebar-active .chat-area,
#sidebar.ins-sidebar-active .chat-input-area,
#sidebar.ins-sidebar-active .chat-welcome {
  opacity: 0;
  filter: blur(8px);
  transform: translateX(-20px);
  pointer-events: none;
}

/* Keep sidebar header visible — inspector docks below it */
#sidebar.ins-sidebar-active .sidebar-header {
  opacity: 1 !important;
  filter: none !important;
  transform: none !important;
  pointer-events: auto !important;
  z-index: 35;
}

/* Inspect sidebar panel (replacing chat) — starts below the header */
.ins-sidebar-content {
  position: absolute;
  top: 48px; /* below the sidebar-header */
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  z-index: 20;
  background: var(--bg-sidebar);
  opacity: 0;
  transform: translateX(30px);
  filter: blur(6px);
  transition: opacity 0.35s ease, filter 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}
.ins-sidebar-content.ins-sidebar-visible {
  opacity: 1;
  transform: translateX(0);
  filter: blur(0);
  pointer-events: auto;
}

/* Sidebar docked header — transparent, compact, aligned */
.ins-sidebar-content .ins-panel-hdr {
  background: transparent;
  padding: 8px 6px 8px 6px;
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(to right, transparent, var(--ins-border) 15%, var(--ins-border) 85%, transparent) 1;
  border-radius: 0;
}
/* Close button in docked mode: square, fully rounded, bordered */
.ins-sidebar-content .ins-panel-close {
  background: none;
  border: 1px solid var(--ins-border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
}
.ins-sidebar-content .ins-panel-close:hover {
  background: rgba(255,255,255,0.06);
}
/* Drag handle hidden by default in docked mode, visible on header hover */
.ins-sidebar-content .ins-drag-handle {
  opacity: 0;
  cursor: grab;
  transition: opacity 0.15s;
}
.ins-sidebar-content .ins-panel-hdr:hover .ins-drag-handle {
  opacity: 1;
}
.ins-sidebar-content .ins-drag-handle:active {
  cursor: grabbing;
}

/* Sidebar docked footer — same fade-up style */
.ins-sidebar-content .ins-panel-foot {
  padding: 8px 12px;
  border-top: none;
  background: transparent;
  position: relative;
}
.ins-sidebar-content .ins-panel-foot::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, var(--bg-sidebar, var(--ins-bg-dark)) 30%, transparent 100%);
  pointer-events: none;
  z-index: -1;
}

/* Sidebar docked section dividers — fade both sides */
.ins-sidebar-content .ins-section {
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(to right, transparent, var(--ins-border) 15%, var(--ins-border) 85%, transparent) 1;
}
.ins-sidebar-content .ins-bm-wrap {
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(to right, transparent, var(--ins-border) 20%, var(--ins-border) 80%, transparent) 1;
}

/* ---------- Side-tabs texture when inspector docked ---------- */
.side-tabs.ins-texture-active::after {
  content: '';
  display: block;
  flex: 1;
  min-height: 0;
  width: 30px;
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 4px,
    rgba(255, 255, 255, 0.06) 4px,
    rgba(255, 255, 255, 0.06) 5px
  );
  opacity: 1;
  margin-top: 4px;
  transition: opacity 0.35s ease;
}

/* ---------- Vertical Chat Tab (when inspector docked) ---------- */
.ins-chat-tab {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%) translateX(-100%);
  z-index: 2147483647;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-sidebar, #000);
  border: 1px solid #1A1A1A;
  border-left: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-family: var(--ins-font);
  font-size: 11px;
  font-weight: 500;
  color: var(--ins-text-dim);
  letter-spacing: 0.04em;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.25s ease,
              color 0.15s ease,
              background 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}
.ins-chat-tab.ins-chat-tab-visible {
  transform: translateY(-50%) translateX(0);
  opacity: 1;
  pointer-events: auto;
}
.ins-chat-tab:hover {
  color: var(--ins-text);
  background: rgb(32, 32, 32);
}
.ins-chat-tab i {
  font-size: 12px;
  writing-mode: horizontal-tb;
}

/* Sidebar pull handle (left edge) — legacy, kept for compatibility */
.ins-sidebar-handle {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%) translateX(-100%);
  width: 16px;
  height: 48px;
  background: var(--bg-sidebar);
  border: 1px solid #1A1A1A;
  border-left: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  z-index: 2147483647;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.25s ease;
  opacity: 0;
  pointer-events: none;
}
.ins-sidebar-handle.ins-handle-visible {
  transform: translateY(-50%) translateX(0);
  opacity: 1;
  pointer-events: auto;
}
.ins-sidebar-handle:hover {
  background: rgba(255,255,255,0.06);
}
.ins-sidebar-handle::after {
  content: '';
  width: 3px;
  height: 20px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
}

/* ---------- Shift-Drag Reposition Popup ---------- */
.ins-reposition-popup {
  position: fixed;
  z-index: 2147483647;
  background: var(--ins-bg);
  border: 1px solid var(--ins-border);
  border-radius: 6px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--ins-font);
  font-size: 11px;
  color: var(--ins-text);
  animation: insPopIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes insPopIn {
  from { opacity: 0; transform: scale(0.9) translateY(4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.ins-reposition-btn {
  padding: 4px 10px;
  border-radius: 3px;
  border: none;
  cursor: pointer;
  font-family: var(--ins-mono);
  font-size: 10px;
  font-weight: 500;
  transition: all 0.12s;
}
.ins-reposition-save {
  background: var(--ins-accent);
  color: var(--ins-bg);
  border: 1px solid var(--ins-accent);
}
.ins-reposition-save:hover {
  background: var(--ins-accent-hover);
  border-color: var(--ins-accent-hover);
}
.ins-reposition-discard {
  background: transparent;
  color: var(--ins-text-muted);
  border: 1px solid var(--ins-border);
}
.ins-reposition-discard:hover {
  color: var(--ins-text);
  border-color: #2a2e40;
}

/* ---------- Inspect Toast (centered to preview container) ---------- */
.ins-toast {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 2147483647;
  font-family: var(--ins-font);
  font-size: 12px;
  font-weight: 600;
  color: var(--ins-bg);
  background: var(--ins-accent);
  padding: 6px 14px;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(90,158,246,0.3);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  white-space: nowrap;
}
.ins-toast.ins-toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Shift-Drag Visual Cue ---------- */
.ins-dragging-ghost {
  position: absolute;
  pointer-events: none;
  z-index: calc(var(--ins-z-base) + 5);
  border: 2px dashed var(--ins-accent);
  background: rgba(90,158,246,0.08);
  border-radius: 2px;
  transition: none;
}
