/**
 * Master builder UI stylesheet. Dark theme with three-panel layout.
 * All variables prefixed --pb-* to avoid conflicts with CodeStitch :root vars.
 */

:root {
  --pb-bg: #1e1e1e;
  --pb-surface: #252526;
  --pb-surface-hover: #2d2d30;
  --pb-border: #3e3e42;
  --pb-text: #ccc;
  --pb-text-bright: #fff;
  --pb-text-dim: #ababab;
  --pb-accent: #0078d4;
  --pb-accent-hover: #1a8ae8;
  --pb-accent-subtle: #4b7fad; /* fallback for engines without color-mix() */
  --pb-accent-subtle: color-mix(in srgb, var(--pb-accent) 55%, var(--pb-text-dim));
  --pb-danger: #f44336;
  --pb-danger-hover: #e53935;
  --pb-success: #4caf50;
  --pb-panel-width-left: 320px;
  --pb-toolbar-height: 48px;
  --pb-radius: 4px;
  --pb-transition: 0.15s ease;
  --pb-transition-slow: 0.2s ease;
  --pb-transition-spring: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  --pb-transition-skeleton: 1.5s;
  --pb-active-scale: 0.96;
  --pb-accent-tint: rgba(0,120,212,0.06);
  --pb-input-error-bg: rgba(244,67,54,0.08);

  /* ── Z-index scale ── */
  --pb-z-base: 1;
  --pb-z-raised: 10;
  --pb-z-popover: 100;
  --pb-z-dropdown: 200;
  --pb-z-context-menu: 250;
  --pb-z-modal: 300;
  --pb-z-toolbar-float: 400;
  --pb-z-toast: 500;

  /* ── Surfaces (elevated tiers) ── */
  --pb-surface-2: #2a2a2a;
  --pb-surface-3: #333;
  --pb-bg-elevated: #2a2a2e;

  /* ── Interactive states ── */
  --pb-bg-hover: rgba(255, 255, 255, 0.08);
  --pb-scrollbar-hover: #555;

  /* ── Semantic colors ── */
  --pb-warning: #e67e22;
  --pb-warning-icon: #f0c040;

  /* ── Recovery banner ── */
  --pb-recovery-bg: #2a2a1e;
  --pb-recovery-border: #5a5a2e;

  /* ── Content areas (white bg for thumbnails/previews/iframe) ── */
  --pb-content-bg: #fff;
  --pb-content-placeholder: #222;

  /* ── Shadows ── */
  --pb-shadow-panel: 0 2px 8px rgba(0, 0, 0, 0.18);
  --pb-shadow-dropdown: 0 4px 12px rgba(0, 0, 0, 0.4);
  --pb-shadow-popover: 0 4px 16px rgba(0, 0, 0, 0.3);
  --pb-shadow-modal: 0 8px 32px rgba(0, 0, 0, 0.5);
  --pb-overlay-bg: rgba(0, 0, 0, 0.6);

  /* ── Drag & drop ── */
  --pb-drag-ghost-bg: var(--pb-surface);
  --pb-drag-ghost-border: var(--pb-accent);
  --pb-drag-ghost-shadow: 0 4px 16px rgba(0, 120, 212, 0.3);
  --pb-drag-ghost-opacity: 0.92;
  --pb-drop-zone-color: var(--pb-accent);
  --pb-drop-zone-glow: var(--pb-accent-glow);
  --pb-drop-zone-height-active: 8px;
  --pb-transition-drag: 0.2s ease;

  /* ── Accent-derived translucent backgrounds ── */
  --pb-accent-muted: rgba(0, 120, 212, 0.08);
  --pb-accent-glow: rgba(0, 120, 212, 0.25);
  --pb-danger-muted: rgba(244, 67, 54, 0.15);
  --pb-badge-manual-bg: rgba(74, 158, 255, 0.15);
  --pb-badge-auto-bg: rgba(255, 255, 255, 0.08);
  --pb-shared-bg: rgba(255, 255, 255, 0.02);

  /* ── Typography scale ── */
  --pb-font-xs:   10px;
  --pb-font-sm:   11px;
  --pb-font-base: 12px;
  --pb-font-md:   13px;
  --pb-font-lg:   14px;
  --pb-font-xl:   15px;

  /* ── Border-radius tiers ── */
  --pb-radius-sm:   3px;
  --pb-radius-md:   6px;
  --pb-radius-lg:   8px;
  --pb-radius-pill: 999px;

  /* ── Spacing scale ── */
  --pb-space-1:  2px;
  --pb-space-2:  4px;
  --pb-space-3:  6px;
  --pb-space-4:  8px;
  --pb-space-5:  12px;
  --pb-space-6:  16px;
  --pb-space-8:  24px;
  --pb-space-10: 32px;

  /* ── Hover outline ── */
  --pb-shadow-ring: 0 0 0 1px var(--pb-accent);
  --pb-shadow-glow: 0 0 0 1px var(--pb-accent), 0 0 6px var(--pb-accent-glow);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: var(--pb-font-md);
  color: var(--pb-text);
  background: var(--pb-bg);
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[contenteditable="true"]:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--pb-text-bright);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--pb-accent-glow);
}

.pb-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/**
 * Expand click/tap target to 44px minimum (WCAG 2.5.8) without
 * changing visual size. Works by adding transparent padding and
 * pulling it back with negative margin so layout is unaffected.
 * Only apply to elements whose computed size is below 44px.
 */
.pb-touch-target {
  padding: 10px;
  margin: -10px;
}

input, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--pb-text);
  background: var(--pb-bg);
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius);
}

input:not([type="color"]):not([type="checkbox"]):not([type="range"]):not([type="file"]),
select,
textarea {
  padding: var(--pb-space-3) var(--pb-space-4);
}

/* Three-panel layout */
.pb-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.pb-main {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.pb-panel-left {
  width: var(--pb-panel-width-left);
  min-width: var(--pb-panel-width-left);
  background: var(--pb-surface);
  border-right: 1px solid var(--pb-border);
  box-shadow: var(--pb-shadow-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pb-panel-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: var(--pb-bg);
  overflow: hidden;
  position: relative;
}

/* Panel collapse */
.pb-panel-left {
  transition: width var(--pb-transition-spring), min-width var(--pb-transition-spring), opacity var(--pb-transition-slow);
}

.pb-panel-left.pb-collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
  opacity: 0;
  border-right: none;
  box-shadow: none;
}

.pb-collapse-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: var(--pb-z-raised);
  width: 20px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--pb-surface);
  border: 1px solid var(--pb-border);
  border-radius: 0 var(--pb-radius) var(--pb-radius) 0;
  color: var(--pb-text-dim);
  cursor: pointer;
  transition: color var(--pb-transition), background var(--pb-transition);
}

.pb-collapse-btn:hover {
  color: var(--pb-text-bright);
  background: var(--pb-surface-hover);
}

.pb-collapse-left {
  left: 0;
  border-radius: 0 var(--pb-radius) var(--pb-radius) 0;
  border-left: none;
}

.pb-collapse-left.pb-panel-hidden svg {
  transform: rotate(180deg);
}

@media (max-width: 1200px) {
  .pb-panel-left {
    width: min(300px, 32vw);
    min-width: min(300px, 32vw);
  }
}

@media (max-width: 900px) {
  .pb-panel-left {
    width: min(86vw, 280px);
    min-width: min(86vw, 280px);
  }

  .pb-iframe-wrap {
    padding: var(--pb-space-4);
  }
}

/* iframe container */
.pb-iframe-wrap {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--pb-space-6);
  overflow: auto;
  width: 100%;
}

.pb-iframe-wrap iframe {
  border: 1px solid var(--pb-border);
  background: var(--pb-content-bg);
  transition: width var(--pb-transition), height var(--pb-transition);
  flex-shrink: 0;
}

/* Viewport indicator */
.pb-viewport-label {
  position: absolute;
  bottom: var(--pb-space-4);
  right: var(--pb-space-4);
  font-size: var(--pb-font-sm);
  color: var(--pb-text-dim);
  pointer-events: none;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--pb-border);
  border-radius: var(--pb-radius);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--pb-scrollbar-hover);
}

/* Toast notifications */
.pb-toast-container {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--pb-z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--pb-space-4);
  pointer-events: none;
}

.pb-toast {
  background: var(--pb-surface);
  color: var(--pb-text-bright);
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius);
  padding: var(--pb-space-4) var(--pb-space-6);
  font-size: var(--pb-font-md);
  box-shadow: var(--pb-shadow-dropdown);
  animation: pb-toast-in 0.2s ease;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--pb-space-4);
}

.pb-toast-action {
  background: none;
  border: none;
  color: var(--pb-accent);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  padding: 0;
  white-space: nowrap;
}

.pb-toast.pb-toast-error {
  border-color: var(--pb-danger);
}

.pb-toast.pb-toast-success {
  border-color: var(--pb-success);
}

.pb-toast-check { flex-shrink: 0; color: var(--pb-success); }
.pb-toast-check path {
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
  animation: pb-check-draw 0.4s 0.1s ease forwards;
}
@keyframes pb-check-draw {
  to { stroke-dashoffset: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .pb-toast-check path { animation: none; stroke-dashoffset: 0; }
}

@keyframes pb-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Command Palette ── */

.pb-cmd-overlay { z-index: var(--pb-z-modal); }
.pb-cmd-palette {
  width: 480px;
  max-width: 90vw;
  max-height: 400px;
  margin: 15vh auto 0;
  background: var(--pb-surface);
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius-lg);
  box-shadow: var(--pb-shadow-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pb-cmd-input {
  width: 100%;
  padding: var(--pb-space-5) var(--pb-space-6);
  border: none;
  border-bottom: 1px solid var(--pb-border);
  background: transparent;
  color: var(--pb-text);
  font-size: var(--pb-font-lg);
  outline: none;
  box-sizing: border-box;
}
.pb-cmd-input::placeholder { color: var(--pb-text-dim); }
.pb-cmd-results {
  overflow-y: auto;
  max-height: 320px;
  padding: var(--pb-space-2) 0;
}
.pb-cmd-item {
  display: flex;
  align-items: center;
  padding: var(--pb-space-4) var(--pb-space-6);
  cursor: pointer;
  gap: var(--pb-space-4);
}
.pb-cmd-item:hover, .pb-cmd-item-active {
  background: var(--pb-bg-hover);
}
.pb-cmd-item[aria-disabled="true"] {
  opacity: 0.4;
  cursor: default;
}
.pb-cmd-label { flex: 1; color: var(--pb-text); font-size: var(--pb-font-md); }
.pb-cmd-shortcut { color: var(--pb-text-dim); font-size: var(--pb-font-sm); font-family: monospace; }
.pb-cmd-section { color: var(--pb-text-dim); font-size: var(--pb-font-sm); }
.pb-cmd-empty {
  padding: var(--pb-space-8) var(--pb-space-6);
  text-align: center;
  color: var(--pb-text-dim);
  font-size: var(--pb-font-md);
}

/* ── Export progress bar ── */
.pb-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--pb-border);
  border-radius: var(--pb-radius-sm);
  overflow: hidden;
}

.pb-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--pb-accent);
  border-radius: var(--pb-radius-sm);
  transition: width var(--pb-transition-slow);
}

.pb-export-phase {
  color: var(--pb-text-dim);
  font-size: var(--pb-font-base);
  margin-top: var(--pb-space-4);
}

/* ── Preview pulse on theme change ── */
.pb-preview-pulse { animation: pb-glow-pulse 0.4s ease; }
@keyframes pb-glow-pulse {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: inset 0 0 0 2px var(--pb-accent); }
}

.pb-preview-page-switch { animation: pb-page-switch-fade 0.2s ease; }
@keyframes pb-page-switch-fade {
  0% { opacity: 0.35; }
  100% { opacity: 1; }
}

/* Template selector modal */
.pb-modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--pb-overlay-bg);
  z-index: var(--pb-z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pb-fade-in 0.15s ease;
}

.pb-modal-overlay.pb-modal-overlay-closing {
  animation: pb-fade-out 0.16s ease forwards;
  pointer-events: none;
}

@keyframes pb-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pb-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

.pb-modal {
  background: var(--pb-surface);
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius-lg);
  width: 90vw;
  max-width: 1000px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--pb-shadow-modal);
}

.pb-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--pb-space-5) var(--pb-space-6);
  border-bottom: 1px solid var(--pb-border);
}

.pb-modal-header h2 {
  font-size: var(--pb-font-xl);
  font-weight: 600;
  color: var(--pb-text-bright);
}

.pb-modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--pb-radius);
  font-size: 18px;
  color: var(--pb-text-dim);
  padding: 8px;
  margin: -8px;
}

.pb-modal-close:hover {
  background: var(--pb-surface-hover);
  color: var(--pb-text-bright);
}

.pb-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--pb-space-6);
}

/* Common button styles */
.pb-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--pb-space-3);
  padding: var(--pb-space-3) var(--pb-space-5);
  border-radius: var(--pb-radius);
  font-size: var(--pb-font-base);
  font-weight: 500;
  transition: background var(--pb-transition), color var(--pb-transition);
  white-space: nowrap;
}

.pb-btn-primary {
  background: var(--pb-accent);
  color: var(--pb-text-bright);
}

.pb-btn-primary:hover {
  background: var(--pb-accent-hover);
}

.pb-btn-ghost {
  color: var(--pb-text);
}

.pb-btn-ghost:hover {
  background: var(--pb-surface-hover);
  color: var(--pb-text-bright);
}

.pb-btn-danger {
  color: var(--pb-danger);
}

.pb-btn-danger:hover {
  background: var(--pb-danger-muted);
}

.pb-btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--pb-radius);
  color: var(--pb-text);
  transition: background var(--pb-transition), color var(--pb-transition);
}

.pb-btn-icon:hover {
  background: var(--pb-surface-hover);
  color: var(--pb-text-bright);
}

.pb-btn-icon.pb-active {
  background: var(--pb-accent);
  color: var(--pb-text-bright);
}

/* ── Size modifier ── */
.pb-btn-sm {
  padding: var(--pb-space-2) var(--pb-space-4);
  font-size: var(--pb-font-sm);
  font-weight: normal;
  white-space: nowrap;
}

/* ── Outline modifier (bordered button on elevated surface) ── */
.pb-btn-outline {
  border: 1px solid var(--pb-border);
  background: var(--pb-bg-elevated);
  color: var(--pb-text-bright);
}

.pb-btn-outline:hover {
  background: var(--pb-bg-hover);
}

/* ── Universal disabled treatment ── */
button:disabled,
.pb-btn:disabled,
.pb-btn-icon:disabled,
.pb-sl-btn:disabled,
button[aria-disabled="true"],
.pb-btn[aria-disabled="true"],
.pb-btn-icon[aria-disabled="true"],
.pb-sl-btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Grayscale on icon buttons only — avoids hurting text readability */
.pb-btn-icon:disabled {
  filter: grayscale(1);
}

/* Auto-save recovery banner */
.pb-recovery-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--pb-space-4) var(--pb-space-6);
  background: var(--pb-recovery-bg);
  border-bottom: 1px solid var(--pb-recovery-border);
  gap: var(--pb-space-5);
  animation: pb-fade-in 0.2s ease;
}

.pb-recovery-content {
  display: flex;
  align-items: center;
  gap: var(--pb-space-4);
  font-size: var(--pb-font-md);
  color: var(--pb-text);
}

.pb-recovery-content svg {
  color: var(--pb-warning-icon);
  flex-shrink: 0;
}

.pb-recovery-content strong {
  color: var(--pb-text-bright);
}

.pb-recovery-actions {
  display: flex;
  gap: var(--pb-space-4);
  flex-shrink: 0;
}

/* Loading skeletons */
@keyframes pb-skeleton-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

.pb-skeleton {
  background: var(--pb-surface-hover);
  border-radius: var(--pb-radius);
  animation: pb-skeleton-pulse var(--pb-transition-skeleton) ease-in-out infinite;
}

.pb-skeleton-row {
  display: flex;
  align-items: center;
  gap: var(--pb-space-4);
  padding: var(--pb-space-4) var(--pb-space-5);
}

.pb-skeleton-thumb {
  width: 40px;
  height: 28px;
  flex-shrink: 0;
}

.pb-skeleton-text {
  height: 12px;
  flex: 1;
}

.pb-skeleton-text-short {
  height: 12px;
  width: 60%;
}

.pb-iframe-loading {
  position: absolute;
  inset: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--pb-space-5);
  color: var(--pb-text-dim);
  font-size: var(--pb-font-md);
  z-index: var(--pb-z-base);
  pointer-events: none;
}

.pb-iframe-loading .pb-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--pb-border);
  border-top-color: var(--pb-accent);
  border-radius: 50%;
  animation: pb-spin 0.8s linear infinite;
}

@keyframes pb-spin {
  to { transform: rotate(360deg); }
}

/* Empty state */
.pb-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--pb-space-10) var(--pb-space-6);
  color: var(--pb-text-dim);
  text-align: center;
  gap: var(--pb-space-4);
}

.pb-empty-state svg {
  width: 48px;
  height: 48px;
  opacity: 0.4;
}

.pb-empty-state-subtitle {
  font-size: var(--pb-font-sm);
  color: var(--pb-text-dim);
  margin-top: var(--pb-space-1);
}

/* ── Empty-state call-to-action arrow ── */
.pb-empty-state .pb-sl-add-btn {
  position: relative;
}

.pb-empty-state .pb-sl-add-btn::before {
  content: '↓';
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 16px;
  color: var(--pb-accent);
  animation: pb-arrow-bounce 1.5s ease-in-out infinite;
}

@keyframes pb-arrow-bounce {
  0%, 100% { transform: translateX(-50%) translateY(0); opacity: 0.5; }
  50% { transform: translateX(-50%) translateY(-4px); opacity: 1; }
}

/* ── Custom tooltip ── */
.pb-tooltip {
  position: fixed;
  z-index: var(--pb-z-toast);
  max-width: 240px;
  padding: var(--pb-space-2) var(--pb-space-4);
  background: var(--pb-surface);
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius);
  box-shadow: var(--pb-shadow-dropdown);
  color: var(--pb-text-bright);
  font-size: var(--pb-font-sm);
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--pb-transition);
}

.pb-tooltip.pb-tooltip-show {
  opacity: 1;
}

.pb-tooltip-kbd {
  display: inline-block;
  margin-left: var(--pb-space-2);
  padding: 1px var(--pb-space-2);
  background: var(--pb-bg);
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius-sm);
  font-size: var(--pb-font-xs);
  font-family: inherit;
  color: var(--pb-text-dim);
}

/* ── Bouncing dots loader ── */
.pb-dots-loader {
  display: flex;
  gap: 6px;
}

.pb-dots-loader span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pb-accent);
  animation: pb-bounce 1.2s ease-in-out infinite;
}

.pb-dots-loader span:nth-child(2) { animation-delay: 0.15s; }
.pb-dots-loader span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pb-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Placeholder styling ── */
::placeholder {
  color: var(--pb-text-dim);
  opacity: 0.6;
}

/* Skeleton card variant (palette grid) */
.pb-skeleton-card {
  border-radius: var(--pb-radius);
  aspect-ratio: 16 / 9;
}

/* Entrance / exit animations */
@keyframes pb-fade-slide-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pb-fade-slide-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-4px); }
}

@keyframes pb-toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(8px); }
}

.pb-animate-in  { animation: pb-fade-slide-in var(--pb-transition) both; }
/* Quick Colors during text editing */
.pb-quick-colors { border-top: 1px solid var(--pb-border); margin-top: var(--pb-space-4); }

/* Variant smart defaults */
.pb-variant-recommended { border-color: var(--pb-accent); }
.pb-variant-badge {
  font-size: var(--pb-font-xs);
  color: var(--pb-accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.pb-variant-divider {
  grid-column: 1 / -1;
  text-align: center;
  font-size: var(--pb-font-sm);
  color: var(--pb-text-dim);
  border-top: 1px solid var(--pb-border);
  padding-top: var(--pb-space-4);
  margin-top: var(--pb-space-2);
}

.pb-animate-out { animation: pb-fade-slide-out var(--pb-transition) both; pointer-events: none; }
.pb-toast-exit  { animation: pb-toast-out 0.2s ease forwards; }

@media (prefers-reduced-motion: reduce) {
  .pb-animate-in, .pb-animate-out, .pb-toast-exit, .pb-toast, .pb-preview-pulse, .pb-preview-page-switch,
  .pb-skeleton, .pb-iframe-loading .pb-spinner, .pb-sl-inline-loading-spinner, .pb-autosave-saving .pb-autosave-icon,
  .pb-modal-overlay.pb-modal-overlay-closing {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
  .pb-skeleton { opacity: 0.6 !important; }
  .pb-tooltip { transition: none; }
  .pb-empty-state .pb-sl-add-btn::before { animation: none !important; opacity: 1 !important; }
  .pb-dots-loader span { animation: none !important; opacity: 0.7 !important; }
}

/* ── Scroll-fade affordance ── */
.pb-scroll-fade { position: relative; }
.pb-scroll-fade::before,
.pb-scroll-fade::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transition: opacity var(--pb-transition);
}
.pb-scroll-fade::before {
  left: 0;
  background: linear-gradient(to right, var(--pb-surface), transparent);
}
.pb-scroll-fade::after {
  right: 0;
  background: linear-gradient(to left, var(--pb-surface), transparent);
}
.pb-scroll-fade.pb-can-scroll-left::before  { opacity: 1; }
.pb-scroll-fade.pb-can-scroll-right::after { opacity: 1; }

/* Active / pressed states */
.pb-btn:active,
.pb-btn-icon:active,
.pb-btn-sm:active,
.pb-props-btn:active,
.pb-nudge-btn:active,
.pb-spacing-preset:active,
.pb-template-pill:active,
.pb-section-card-add:active,
.pb-sl-btn:active,
.pb-sl-insert-btn:active,
.pb-page-tab:active,
.pb-page-tab-add:active,
.pb-toolbar-template-btn:active,
.pb-fmt-btn:active,
.pb-modal-close:active,
.pb-category-tab:active {
  transform: scale(var(--pb-active-scale));
  filter: brightness(1.3);
  transition: transform 0.05s ease, filter 0.05s ease;
}

/* Input error state */
.pb-input-error {
  border-color: var(--pb-danger) !important;
  background: var(--pb-input-error-bg) !important;
}

/* Keyboard shortcuts modal */
.pb-shortcuts-list {
  display: flex;
  flex-direction: column;
  gap: var(--pb-space-2);
}

.pb-shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--pb-space-3) 0;
  border-bottom: 1px solid var(--pb-border);
}

.pb-shortcut-row:last-child {
  border-bottom: none;
}

.pb-shortcut-keys {
  font-family: monospace;
  font-size: var(--pb-font-base);
  color: var(--pb-text-bright);
  background: var(--pb-surface-hover);
  padding: var(--pb-space-1) var(--pb-space-4);
  border-radius: var(--pb-radius);
  border: 1px solid var(--pb-border);
}

.pb-shortcut-desc {
  font-size: var(--pb-font-base);
  color: var(--pb-text);
}

/* --- Code Injection Modal --- */
.pb-code-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--pb-border);
  margin-bottom: var(--pb-space-5);
}

.pb-code-tab {
  padding: var(--pb-space-3) var(--pb-space-6);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--pb-text);
  cursor: pointer;
  font-size: var(--pb-font-md);
}

.pb-code-tab.pb-active {
  color: var(--pb-text-bright);
  border-bottom-color: var(--pb-accent);
}

.pb-code-tab-content {
  display: none;
}

.pb-code-tab-content.pb-code-tab-content-active {
  display: block;
  animation: pb-fade-slide-in var(--pb-transition) both;
}

.pb-code-textarea {
  width: 100%;
  min-height: 200px;
  padding: var(--pb-space-5);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: var(--pb-font-base);
  line-height: 1.5;
  background: var(--pb-bg);
  color: var(--pb-text-bright);
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius);
  resize: vertical;
  tab-size: 2;
  box-sizing: border-box;
  transition: border-color var(--pb-transition);
}

.pb-code-textarea:focus {
  border-color: var(--pb-accent);
}

/* --- Link Manager --- */
.pb-lm-search {
  margin-bottom: var(--pb-space-4);
  flex-shrink: 0;
}

.pb-lm-table-wrap {
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius);
}

.pb-lm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--pb-font-base);
}

.pb-lm-table th {
  position: sticky;
  top: 0;
  background: var(--pb-bg-elevated);
  text-align: left;
  padding: var(--pb-space-3) var(--pb-space-4);
  font-weight: 600;
  color: var(--pb-text-bright);
  border-bottom: 1px solid var(--pb-border);
}

.pb-lm-cell {
  padding: var(--pb-space-3) var(--pb-space-4);
  border-bottom: 1px solid var(--pb-border);
  color: var(--pb-text);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pb-lm-href {
  cursor: pointer;
  color: var(--pb-accent);
  text-decoration: underline;
  text-decoration-style: dotted;
}

.pb-lm-href:hover {
  color: var(--pb-text-bright);
}

.pb-lm-href-edit {
  width: 100%;
  font-size: var(--pb-font-base);
  padding: var(--pb-space-1) var(--pb-space-2);
}

.pb-lm-bulk {
  flex-shrink: 0;
  margin-top: var(--pb-space-5);
  padding-top: var(--pb-space-5);
  border-top: 1px solid var(--pb-border);
}

.pb-lm-bulk-title {
  font-size: var(--pb-font-base);
  font-weight: 600;
  color: var(--pb-text-bright);
  margin-bottom: var(--pb-space-3);
}

.pb-lm-bulk-row {
  display: flex;
  gap: var(--pb-space-3);
  align-items: center;
}

.pb-lm-bulk-input {
  flex: 1;
  min-width: 0;
  font-size: var(--pb-font-base);
}

/* --- Revision History --- */
.pb-rev-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--pb-space-4);
  border-bottom: 1px solid var(--pb-border);
}

.pb-rev-item:last-child {
  border-bottom: none;
}

.pb-rev-info {
  display: flex;
  flex-direction: column;
  gap: var(--pb-space-1);
  min-width: 0;
}

.pb-rev-name {
  font-size: var(--pb-font-md);
  font-weight: 500;
  color: var(--pb-text-bright);
  cursor: default;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pb-rev-meta {
  display: flex;
  gap: var(--pb-space-4);
  font-size: var(--pb-font-sm);
  color: var(--pb-text-dim);
}

.pb-rev-badge {
  padding: 1px var(--pb-space-3);
  border-radius: var(--pb-radius-sm);
  font-size: var(--pb-font-xs);
  font-weight: 600;
  text-transform: uppercase;
}

.pb-rev-badge-manual {
  background: var(--pb-badge-manual-bg);
  color: var(--pb-accent);
}

.pb-rev-badge-auto {
  background: var(--pb-badge-auto-bg);
  color: var(--pb-text-dim);
}

.pb-rev-actions {
  display: flex;
  gap: var(--pb-space-2);
  flex-shrink: 0;
}

.pb-rev-rename-input {
  font-size: var(--pb-font-md);
  padding: 1px var(--pb-space-2);
  width: 180px;
}

.pb-rev-footer {
  font-size: var(--pb-font-sm);
  color: var(--pb-text-dim);
}

.pb-rev-total {
  font-size: var(--pb-font-sm);
}

/* ══════════════════════════════════════════════════════════
   Drag & Drop Utilities
   ══════════════════════════════════════════════════════════ */

@keyframes pb-drop-zone-pulse {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 1; }
}

/* Scoped drag-active state — applied to .pb-sl-body during panel drag */
.pb-sl-body.pb-drag-active {
  cursor: grabbing;
  user-select: none;
}
.pb-sl-body.pb-drag-active .pb-sl-row {
  cursor: grabbing;
}

/* Reduced motion — targets the actual animated pseudo-elements */
@media (prefers-reduced-motion: reduce) {
  .pb-sl-row.pb-sl-drop-above::before,
  .pb-sl-row.pb-sl-drop-below::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
