/* ── Reset & isolation ───────────────────────────────────────────────────── */

.pf-designer {
  all: initial;
  display: block;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #1f2937;
}

.pf-designer *,
.pf-designer *::before,
.pf-designer *::after {
  box-sizing: border-box;
}

/* ── Loading & error states ──────────────────────────────────────────────── */

.pf-designer--loading,
.pf-designer--error {
  padding: 2rem;
  text-align: center;
  color: #6b7280;
}

.pf-designer--error {
  color: #dc2626;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

.pf-designer__layout {
  display: flex;
  gap: 1rem;
  padding: 1rem 0;
}

.pf-canvas-wrap {
  flex: 1;
  min-width: 0;
}

.pf-canvas-scroll {
  overflow: auto;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  background: #f9fafb;
}

.pf-designer__sidebar-wrap {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ── Modal mode ──────────────────────────────────────────────────────────── */

.pf-designer--modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100000;
  background: rgba(0, 0, 0, 0.5);
  padding: 2rem;
  overflow-y: auto;
}

.pf-designer--modal.pf-designer--open {
  display: block;
}

.pf-designer--modal .pf-designer__layout {
  background: #fff;
  border-radius: 8px;
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
}

.pf-designer__close-btn {
  padding: 0.6rem 1rem;
  background: #fff;
  color: #374151;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}

.pf-designer__close-btn:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

/* ── Open designer button (rendered by PHP) ──────────────────────────────── */

.pf-open-designer {
  margin: 1rem 0;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

.pf-sidebar {
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  background: #fff;
  overflow: hidden;
}

.pf-sidebar__tabs {
  display: flex;
  border-bottom: 1px solid #e5e7eb;
}

.pf-sidebar__tab {
  flex: 1;
  padding: 0.5rem 0.25rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #6b7280;
  border-bottom: 2px solid transparent;
  text-transform: none;
  letter-spacing: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.pf-sidebar__tab:hover:not(:disabled) {
  color: #1f2937;
}

.pf-sidebar__tab--active {
  color: #2563eb;
  border-bottom-color: #2563eb;
}

.pf-sidebar__tab:disabled {
  opacity: 0.4;
  cursor: default;
}

.pf-sidebar__content {
  padding: 0.75rem;
}

.pf-sidebar__heading {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: #374151;
}

.pf-sidebar__tab-content p {
  margin: 0;
  color: #6b7280;
  font-size: 13px;
}

/* ── Add tools ───────────────────────────────────────────────────────────── */

.pf-add-tools {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pf-add-tools__btn {
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #fff;
  color: #1f2937;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}

.pf-add-tools__btn:hover:not(:disabled) {
  border-color: #2563eb;
  color: #2563eb;
}

.pf-add-tools__btn--active {
  border-color: #2563eb;
  background: #eff6ff;
  color: #2563eb;
}

.pf-add-tools__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Element properties ──────────────────────────────────────────────────── */

.pf-element__props {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pf-element__field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 13px;
}

.pf-element__field span {
  color: #6b7280;
  flex-shrink: 0;
}

.pf-element__field select,
.pf-element__field input[type="number"] {
  width: 120px;
  padding: 0.25rem 0.5rem;
  border: 1px solid #d1d5db;
  border-radius: 3px;
  font-size: 13px;
}

.pf-element__field input[type="color"] {
  width: 40px;
  height: 28px;
  padding: 0;
  border: 1px solid #d1d5db;
  border-radius: 3px;
  cursor: pointer;
}

.pf-element__color-swatches {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.pf-element__swatch {
  width: 24px;
  height: 24px;
  border: 2px solid #d1d5db;
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
}

.pf-element__swatch--active {
  border-color: #2563eb;
  box-shadow: 0 0 0 1px #2563eb;
}

.pf-zone-fill {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5e7eb;
}

.pf-element__hint {
  font-size: 13px;
  color: #6b7280;
  margin-top: 12px;
}

.pf-element__toggles {
  display: flex;
  gap: 4px;
}

.pf-element__toggle {
  width: 32px;
  height: 32px;
  border: 1px solid #d1d5db;
  border-radius: 3px;
  background: #fff;
  color: #1f2937;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.pf-element__toggle--active {
  background: #eff6ff;
  border-color: #2563eb;
  color: #2563eb;
}

.pf-element__align {
  margin-top: 0.75rem;
}

.pf-element__align-label {
  font-size: 12px;
  color: #64748b;
  display: block;
  margin-bottom: 4px;
}

.pf-element__align-btns {
  display: flex;
  gap: 4px;
}

.pf-element__align-btn {
  padding: 4px 8px;
  font-size: 14px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
  color: #334155;
}

.pf-element__align-btn:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}

.pf-element__delete-btn {
  margin-top: 0.75rem;
  padding: 0.4rem 0.75rem;
  background: #fee2e2;
  color: #dc2626;
  border: 1px solid #fca5a5;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.pf-element__delete-btn:hover {
  background: #fecaca;
}

/* ── Views ───────────────────────────────────────────────────────────────── */

.pf-views {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.pf-views__btn {
  padding: 0.4rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #fff;
  color: #1f2937;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}

.pf-views__btn--active {
  border-color: #2563eb;
  background: #eff6ff;
  color: #2563eb;
  font-weight: 500;
}

/* ── Save button ─────────────────────────────────────────────────────────── */

.pf-designer__save-btn {
  padding: 0.6rem 1rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}

.pf-designer__save-btn:hover:not(:disabled) {
  background: #1d4ed8;
}

.pf-designer__save-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.pf-designer__save-btn--saved {
  background: #16a34a;
  opacity: 1 !important;
}

.pf-designer__save-btn--saved:hover {
  background: #16a34a;
}

/* ── Focus styles for keyboard navigation ────────────────────────────────── */

.pf-designer button:focus-visible,
.pf-designer [role="tab"]:focus-visible,
.pf-designer input:focus-visible,
.pf-designer select:focus-visible {
  outline: 2px solid #1e88e5;
  outline-offset: 2px;
}

/* ── Screen-reader only utility ──────────────────────────────────────────── */

.pf-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;
}

/* ── Error ────────────────────────────────────────────────────────────────── */

.pf-designer__error {
  padding: 0.5rem 0.75rem;
  background: #fee2e2;
  color: #dc2626;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}

/* ── Cart integration: design-required state ────────────────────────────── */

.single_add_to_cart_button.pf-design-required {
  position: relative;
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── Mobile responsive ──────────────────────────────────────────────────── */

@media (max-width: 767px) {
  /* Stack layout vertically */
  .pf-designer__layout {
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem 0;
  }

  /* Canvas takes full width */
  .pf-canvas-wrap {
    width: 100%;
  }

  /* Canvas scroll container should not overflow horizontally */
  .pf-canvas-scroll {
    overflow-x: hidden;
    overflow-y: auto;
  }

  /* Sidebar becomes full-width bottom panel */
  .pf-designer__sidebar-wrap {
    width: 100%;
    flex-shrink: 1;
    gap: 0.5rem;
  }

  /* Collapsible sidebar — hide both tabs and content when collapsed */
  .pf-sidebar--collapsed .pf-sidebar__tabs,
  .pf-sidebar--collapsed .pf-sidebar__content {
    display: none;
  }

  .pf-sidebar__collapse-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: #f9fafb;
    border: none;
    border-top: 1px solid #e5e7eb;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
  }

  .pf-sidebar__collapse-toggle::after {
    content: '▲';
    font-size: 10px;
    transition: transform 0.2s;
  }

  .pf-sidebar--collapsed .pf-sidebar__collapse-toggle::after {
    transform: rotate(180deg);
  }

  /* Enlarge all interactive elements for touch (44px min target) */
  .pf-sidebar__tab {
    padding: 0.75rem 0.25rem;
    font-size: 14px;
    min-height: 44px;
  }

  .pf-add-tools__btn {
    padding: 0.75rem;
    font-size: 14px;
    min-height: 44px;
  }

  .pf-element__toggle {
    width: 44px;
    height: 44px;
    font-size: 15px;
  }

  .pf-element__swatch {
    width: 32px;
    height: 32px;
  }

  .pf-element__align-btn {
    padding: 8px 12px;
    font-size: 16px;
    min-height: 44px;
    min-width: 44px;
  }

  .pf-element__delete-btn {
    padding: 0.75rem;
    font-size: 14px;
    min-height: 44px;
  }

  .pf-views__btn {
    padding: 0.75rem;
    font-size: 14px;
    min-height: 44px;
  }

  .pf-designer__save-btn {
    padding: 0.75rem 1rem;
    font-size: 15px;
    min-height: 48px;
  }

  .pf-designer__close-btn {
    padding: 0.75rem 1rem;
    font-size: 15px;
    min-height: 48px;
  }

  .pf-element__field select,
  .pf-element__field input[type="number"] {
    width: 100%;
    padding: 0.5rem;
    font-size: 14px;
    min-height: 40px;
  }

  .pf-element__field input[type="color"] {
    width: 48px;
    height: 40px;
  }

  .pf-element__field {
    flex-wrap: wrap;
  }

  /* Modal: fullscreen on mobile for maximum canvas space */
  .pf-designer--modal {
    padding: 0;
  }

  .pf-designer--modal .pf-designer__layout {
    padding: 0.5rem;
    border-radius: 0;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }

  /* Canvas fills available vertical space in mobile modal */
  .pf-designer--modal .pf-canvas-wrap {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
  }

  .pf-designer--modal .pf-canvas-scroll {
    border: none;
    background: #e8eaed;
    border-radius: 4px;
  }
}

/* Hide collapse toggle on desktop */
@media (min-width: 768px) {
  .pf-sidebar__collapse-toggle {
    display: none;
  }
}

/* Toolbar */
.pf-toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: #f9fafb; border-bottom: 1px solid #e5e7eb; }
.pf-toolbar__group { display: flex; gap: 4px; }
.pf-toolbar__separator { width: 1px; height: 24px; background: #ddd; }
.pf-toolbar__btn { padding: 4px 10px; border: 1px solid #ccc; border-radius: 4px; background: white; cursor: pointer; font-size: 14px; line-height: 1; color: #333; }
.pf-toolbar__btn:hover:not(:disabled) { background: #f0f0f0; }
.pf-toolbar__btn--active { border-color: #2271b1; background: #e8f0fe; color: #2271b1; }
.pf-toolbar__btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pf-toolbar__group--options { align-items: center; gap: 8px; font-size: 12px; color: #666; }
.pf-toolbar__option { display: flex; align-items: center; gap: 4px; }
.pf-toolbar__option input[type="range"] { width: 80px; }
.pf-toolbar__option input[type="color"] { width: 28px; height: 24px; padding: 0; border: 1px solid #ccc; border-radius: 3px; cursor: pointer; }

/* Clip Art section in AddTab */
.pf-clipart-section { margin-top: 16px; }
.pf-clipart-collection { margin-bottom: 12px; }
.pf-clipart-collection__name { font-size: 12px; font-weight: 600; margin: 0 0 4px; color: #555; }
.pf-clipart-collection__grid { display: grid; grid-template-columns: repeat(4, 48px); gap: 4px; }
.pf-clipart-collection__item { width: 48px; height: 48px; border: 1px solid #ddd; border-radius: 3px; background: #fff; cursor: pointer; padding: 2px; }
.pf-clipart-collection__item:hover { border-color: #0073aa; box-shadow: 0 0 0 1px #0073aa; }
.pf-clipart-collection__item img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }

/* Image Filters */
.pf-filters__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.pf-filters__title { font-weight: 600; font-size: 13px; color: #1f2937; }
.pf-filters__reset { font-size: 11px; color: #2271b1; background: none; border: none; cursor: pointer; }
.pf-filters__presets { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.pf-filters__preset { padding: 4px 8px; border: 1px solid #ddd; border-radius: 4px; background: #f9fafb; cursor: pointer; font-size: 10px; color: #333; }
.pf-filters__preset--active { border-color: #2271b1; background: #e8f0fe; color: #2271b1; font-weight: 600; }
.pf-filters__slider { display: block; margin-bottom: 6px; }
.pf-filters__slider-header { display: flex; justify-content: space-between; font-size: 11px; color: #666; margin-bottom: 2px; }
.pf-filters__slider input[type="range"] { width: 100%; }

/* Curved Text */
.pf-curved-text__presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 10px; }
.pf-curved-text__preset { padding: 6px; border: 1px solid #ddd; border-radius: 4px; background: white; cursor: pointer; text-align: center; font-size: 9px; color: #666; }
.pf-curved-text__preset--active { border-color: #2271b1; background: #e8f0fe; color: #2271b1; }
.pf-curved-text__preset svg { display: block; margin: 0 auto 2px; }

/* Design Templates */
.pf-design-templates { margin-bottom: 14px; }
.pf-design-templates__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 14px; }
.pf-design-templates__item { padding: 0; border: 1px solid #ddd; border-radius: 4px; background: white; cursor: pointer; overflow: hidden; text-align: center; color: #333; }
.pf-design-templates__item:hover { border-color: #2271b1; }
.pf-design-templates__item img { width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.pf-design-templates__placeholder { width: 100%; aspect-ratio: 4/3; background: #f3f4f6; display: flex; align-items: center; justify-content: center; font-size: 11px; color: #999; }
.pf-design-templates__name { display: block; padding: 4px; font-size: 10px; color: #666; }
.pf-design-templates__category-filter { width: 100%; padding: 4px; margin-bottom: 8px; border: 1px solid #ddd; border-radius: 3px; font-size: 11px; }
