/*
 * Site Builder — Layout & Component Styles
 * Extends covey.css with builder-specific styles.
 */

/* ========================================================================
   TOP BAR
   ======================================================================== */

.builder-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-left .logo { font-size: 20px; }

.topbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ========================================================================
   BUILDER PAGE — fills viewport, prevents body scroll
   ======================================================================== */

#page-builder.active {
  display: flex !important;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: hidden;
  z-index: 1;
}

/* ========================================================================
   THREE-PANEL LAYOUT
   ======================================================================== */

.builder-body {
  display: flex;
  flex: 1 1 0%;
  min-height: 0;
  overflow: hidden;
}

/* ========================================================================
   COMPONENT PALETTE (left)
   ======================================================================== */

.palette {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: 2px 0 8px rgba(45, 42, 38, 0.06);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  z-index: 2;
}

.palette-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-light);
}

.palette-list {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius);
  cursor: grab;
  transition: all var(--transition);
  user-select: none;
}

.palette-item:hover {
  background: var(--cream);
  color: var(--text);
}

.palette-item:active {
  cursor: grabbing;
}

.palette-item.dragging {
  opacity: 0.4;
}

/* ========================================================================
   CANVAS (center)
   ======================================================================== */

.canvas-area {
  flex: 1;
  overflow-y: auto;
  background: var(--cream-dark);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 32px;
  min-width: 0;
}

.canvas {
  width: 100%;
  max-width: 800px;
  min-height: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  position: relative;
}

.canvas-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 80px 40px;
  color: var(--text-light);
  font-size: 15px;
}

/* Drop indicator */
.drop-indicator {
  height: 3px;
  background: var(--plum);
  border-radius: 2px;
  margin: 0 16px;
  transition: opacity 0.15s;
  pointer-events: none;
}

/* Canvas component wrapper */
.canvas-component {
  position: relative;
  border: 2px solid transparent;
  border-radius: var(--radius);
  margin: 0;
  cursor: pointer;
  transition: border-color var(--transition);
}

.canvas-component:hover {
  border-color: var(--border);
}

.canvas-component.selected {
  border-color: var(--plum);
  box-shadow: 0 0 0 3px var(--plum-light);
}

.canvas-component.drag-over-above::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 16px;
  right: 16px;
  height: 3px;
  background: var(--plum);
  border-radius: 2px;
  z-index: 5;
}

.canvas-component.drag-over-below::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 16px;
  right: 16px;
  height: 3px;
  background: var(--plum);
  border-radius: 2px;
  z-index: 5;
}

/* Component drag handle */
.component-drag-handle {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: grab;
  opacity: 0;
  transition: opacity var(--transition);
  z-index: 5;
}

.canvas-component:hover .component-drag-handle,
.canvas-component.selected .component-drag-handle {
  opacity: 1;
}

.component-drag-handle:active { cursor: grabbing; }

/* Component type label */
.component-type-label {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--plum);
  background: var(--plum-light);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  opacity: 0;
  transition: opacity var(--transition);
  z-index: 5;
}

.canvas-component:hover .component-type-label,
.canvas-component.selected .component-type-label {
  opacity: 1;
}

/* ========================================================================
   RENDERED COMPONENT STYLES (inside canvas)
   ======================================================================== */

.comp-hero {
  padding: 48px 40px;
  text-align: center;
}

.comp-hero h1 {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 400;
  line-height: 1.2;
  margin-bottom: 12px;
  color: var(--text);
}

.comp-hero p {
  font-size: 16px;
  color: var(--text-muted);
  max-width: 500px;
  margin: 0 auto 20px;
  line-height: 1.6;
}

.comp-hero .hero-cta {
  display: inline-block;
  padding: 12px 28px;
  font-size: 15px;
  font-weight: 500;
  color: #fff;
  background: var(--plum);
  border-radius: 6px;
}

/* --- Heading --- */

.comp-heading {
  padding: 32px 40px 16px;
}

.comp-heading h1 {
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.15;
}

.comp-heading h2 {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.2;
}

.comp-heading h3 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.25;
}

.comp-heading h4 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.comp-heading h5 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.comp-heading h6 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  line-height: 1.4;
}

.heading-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.6;
}

/* --- Columns --- */

.comp-columns {
  padding: 32px 40px;
}

.columns-grid {
  display: grid;
}

.columns-1 { grid-template-columns: 1fr; }
.columns-2 { grid-template-columns: 1fr 1fr; }
.columns-3 { grid-template-columns: 1fr 1fr 1fr; }

.col-item {
  padding: 20px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--cream);
}

.col-icon {
  font-size: 28px;
  margin-bottom: 10px;
  line-height: 1;
}

.col-item h4 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.col-item p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* --- Text Block --- */

.comp-text-block {
  padding: 32px 40px;
}

.comp-text-block p {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
}

.comp-image {
  padding: 24px 40px;
  text-align: center;
}

.comp-image img {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.comp-image .image-placeholder {
  background: var(--cream);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  color: var(--text-light);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* --- Image Carousel --- */

.comp-carousel {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  margin: 0;
  background: var(--cream-dark);
}

.carousel-track {
  position: relative;
  width: 100%;
  height: 100%;
}

.carousel-slide {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.carousel-slide.active {
  opacity: 1;
}

.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.85);
  border: none;
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  z-index: 3;
  box-shadow: var(--shadow);
}

.carousel-arrow:hover {
  background: #fff;
  box-shadow: var(--shadow-md);
}

.carousel-prev { left: 12px; }
.carousel-next { right: 12px; }

.carousel-dots {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 3;
}

.carousel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transition: all var(--transition);
  cursor: pointer;
}

.carousel-dot.active {
  background: #fff;
  transform: scale(1.2);
}

.carousel-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-light);
  font-size: 14px;
  background: var(--cream);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
}

/* --- CTA Button --- */

.comp-cta-button {
  padding: 24px 40px;
  text-align: center;
}

.comp-cta-button a {
  display: inline-block;
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
}

.comp-event-list {
  padding: 32px 40px;
}

.comp-event-list h3 {
  font-family: var(--font-display);
  font-size: 22px;
  margin-bottom: 16px;
  color: var(--text);
}

.event-preview-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
}

.event-preview-item:last-child { border-bottom: none; }

.event-date-box {
  width: 48px;
  height: 48px;
  background: var(--plum-light);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.event-date-box .month {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--plum);
}

.event-date-box .day {
  font-size: 18px;
  font-weight: 700;
  color: var(--plum);
  line-height: 1;
}

.event-info h4 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.event-info span {
  font-size: 13px;
  color: var(--text-muted);
}

.comp-contact-form {
  padding: 32px 40px;
}

.comp-contact-form h3 {
  font-family: var(--font-display);
  font-size: 22px;
  margin-bottom: 16px;
  color: var(--text);
}

.contact-preview-field {
  margin-bottom: 12px;
}

.contact-preview-field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.contact-preview-field .mock-input {
  height: 38px;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.contact-preview-field .mock-textarea {
  height: 80px;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.contact-preview-btn {
  display: inline-block;
  padding: 10px 24px;
  background: var(--plum);
  color: #fff;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  margin-top: 4px;
}

/* ========================================================================
   MEMBER SIGNUP COMPONENT
   ======================================================================== */

.comp-member-signup {
  padding: 40px;
  text-align: center;
}

.comp-member-signup h3 {
  font-family: var(--font-display);
  font-size: 26px;
  margin-bottom: 8px;
  color: var(--text);
}

.signup-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  max-width: 500px;
  margin: 0 auto 28px;
  line-height: 1.6;
}

.signup-tiers {
  display: grid;
  gap: 16px;
  text-align: left;
}

.signup-tiers-1 { grid-template-columns: 1fr; max-width: 360px; margin: 0 auto; }
.signup-tiers-2 { grid-template-columns: repeat(2, 1fr); }
.signup-tiers-3 { grid-template-columns: repeat(3, 1fr); }

.signup-tier-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: all var(--transition);
}

.signup-tier-card:hover {
  box-shadow: var(--shadow-md);
}

.signup-tier-card.featured {
  border-color: var(--plum);
  box-shadow: 0 0 0 1px var(--plum);
}

.signup-popular {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--plum);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 12px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.signup-tier-card h4 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.signup-price {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: 16px;
}

.signup-price span {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-muted);
}

.signup-features {
  list-style: none;
  margin-bottom: 20px;
  flex: 1;
}

.signup-features li {
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 0;
  line-height: 1.4;
}

.signup-features li::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  background: var(--green);
  -webkit-mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center/contain no-repeat;
}

.signup-btn {
  display: block;
  text-align: center;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
}

.signup-btn:hover {
  border-color: var(--plum);
  color: var(--plum);
}

.signup-btn-featured {
  background: var(--plum);
  color: #fff;
  border-color: var(--plum);
}

.signup-btn-featured:hover {
  background: var(--plum-dark);
  color: #fff;
}

/* ========================================================================
   PROPERTY EDITOR (right)
   ======================================================================== */

.props-panel {
  width: 300px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -2px 0 8px rgba(45, 42, 38, 0.06);
  flex-shrink: 0;
  overflow-y: auto;
  z-index: 2;
}

.props-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 24px;
  color: var(--text-light);
  font-size: 13px;
  text-align: center;
}

.props-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-light);
}

.props-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

#props-fields {
  padding: 16px;
}

#props-fields .field { margin-bottom: 14px; }

#props-fields .field label {
  font-size: 13px;
  margin-bottom: 4px;
}

#props-fields .field input,
#props-fields .field select,
#props-fields .field textarea {
  font-size: 13px;
  padding: 8px 12px;
  height: 36px;
}

#props-fields .field textarea {
  height: auto;
  min-height: 80px;
}

#props-fields .field input[type="color"] {
  height: 36px;
  padding: 4px;
  cursor: pointer;
}

/* Checkbox field */
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.checkbox-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--plum);
}

.checkbox-field label {
  font-size: 13px;
  color: var(--text);
  margin: 0;
}

/* ========================================================================
   VERSION HISTORY DRAWER
   ======================================================================== */

.drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(45, 42, 38, 0.4);
}

.drawer-content {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 360px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.version-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

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

.version-info { flex: 1; }

.version-number {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.version-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.version-actions {
  display: flex;
  gap: 6px;
}

/* ========================================================================
   PREVIEW MODE
   ======================================================================== */

.builder-body.preview-mode .palette,
.builder-body.preview-mode .props-panel {
  display: none;
}

.builder-body.preview-mode .canvas-area {
  padding: 0;
}

.builder-body.preview-mode .canvas {
  max-width: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.builder-body.preview-mode .canvas-component {
  border: none !important;
  box-shadow: none !important;
  cursor: default;
}

.builder-body.preview-mode .component-drag-handle,
.builder-body.preview-mode .component-type-label {
  display: none !important;
}

/* ========================================================================
   TOAST
   ======================================================================== */

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateX(20px);
  transition: all 0.3s ease;
  max-width: 320px;
}

.toast-visible {
  opacity: 1;
  transform: translateX(0);
}

.toast-success { background: var(--green-bg); color: var(--green); }
.toast-error { background: var(--red-bg); color: var(--red); }
.toast-info { background: var(--blue-bg); color: var(--blue); }

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

@media (max-width: 1024px) {
  .palette { width: 180px; }
  .props-panel { width: 240px; }
}

@media (max-width: 768px) {
  .topbar-actions .btn span { display: none; }
  .palette { width: 56px; }
  .palette-header { display: none; }
  .palette-item span { display: none; }
  .palette-item { justify-content: center; padding: 12px; }
  .props-panel { width: 200px; }
}
