/**
 * extensions/customily-block/assets/customily-shopify.css
 *
 * Storefront styling for the Customily theme app extension block
 * (extensions/customily-block/blocks/customily-canvas.liquid) and its field
 * snippets (extensions/customily-block/snippets/customily-field-*.liquid).
 * Scoped under #customily-container so it never leaks into the surrounding
 * theme. Class names here must match the ones the Liquid snippets render and
 * the ones customily-shopify.js reads/toggles (.cl-swatch-selected,
 * .customily-canvas-wrapper, ._cl_field_group, etc.) - see those files for
 * the JS/markup side of this contract.
 */

#customily-container,
#customily-container *,
#customily-container *::before,
#customily-container *::after {
  box-sizing: border-box;
}

#customily-container {
  width: 100%;
  max-width: 100%;
}

/* Canvas — hidden inline; shown only inside the preview modal */
.customily-canvas-wrapper {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  pointer-events: none;
}

#preview-canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* Preview modal — transform:none prevents Shopify theme transforms on
   ancestors from breaking position:fixed viewport anchoring */
#customily-preview-modal {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  right: auto !important;
  bottom: auto !important;
  z-index: 999999 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: rgba(0, 0, 0, 0.4) !important;
  transform: none !important;
  contain: layout !important;
}

#customily-preview-modal[style*="display: none"] {
  display: none !important;
}

.cl-preview-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.cl-preview-content {
  position: relative;
  z-index: 1;
  max-width: 600px;
  width: 90vw;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  padding: 20px;
  line-height: 1.4;
}

.cl-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.cl-preview-header__title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.125rem;
  font-weight: 600;
  color: #1e293b;
}

.cl-preview-header__close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #374151;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cl-preview-header__close:hover {
  background: #f3f4f6;
}

.cl-preview-subtitle {
  font-size: 0.8125rem;
  color: #6b7280;
  margin: 0 0 12px;
}

.cl-preview-content canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  margin-bottom: 12px;
}

.cl-preview-trust {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.cl-preview-trust__item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.8125rem;
  color: #374151;
}

.cl-preview-trust__item svg {
  flex-shrink: 0;
  margin-top: 1px;
}

.cl-preview-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.cl-preview-atc {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  background: #1e293b;
  color: #fff;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}

.cl-preview-atc:hover {
  background: #334155;
}

.cl-preview-close-btn {
  padding: 12px 24px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  color: #374151;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
}

.cl-preview-close-btn:hover {
  background: #f9fafb;
}

/* Preview button */
.cl-preview-button {
  cursor: pointer;
  margin-top: 0.5rem;
  margin-bottom: 1rem;
  border: 1px solid #2f80ed;
  border-radius: 5px;
  padding: 10px;
  color: #000;
  text-align: center;
  font-size: 0.9375rem;
  transition: background 0.15s;
}

.cl-preview-button:hover {
  background: rgba(47, 128, 237, 0.06);
}

/* Options card — matches WooCommerce gray card style */
.cl_options {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: #f9f9f9;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  padding: 1rem 1.25rem;
}

.cl-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cl-field label {
  font-weight: 500;
  font-size: 0.875rem;
  line-height: 1.3;
}

.cl-required {
  color: #dc2626;
  margin-left: 2px;
}

.cl-input,
.cl-select,
.cl-textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
  color: inherit;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.cl-input:focus,
.cl-select:focus,
.cl-textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.cl-input:disabled,
.cl-select:disabled,
.cl-textarea:disabled {
  background: #f3f4f6;
  color: #9ca3af;
  cursor: not-allowed;
}

.cl-textarea {
  min-height: 80px;
  resize: vertical;
}

.cl-help-text {
  font-size: 0.75rem;
  color: #6b7280;
  margin: 0;
}

/* Swatches */
.cl-swatch-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.cl-swatch {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border: 2px solid #e5e5e5;
  border-radius: 4px;
  cursor: pointer;
  padding: 2px;
  background-color: #fff;
  background-size: cover;
  background-position: center;
  transition: border-color 0.15s, transform 0.15s;
}

.cl-swatch:hover {
  border-color: #9ca3af;
  transform: scale(1.05);
}

.cl-swatch:focus-visible {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.cl-swatch-selected {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.cl-swatch img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 2px;
  pointer-events: none;
}

/* File upload */
.cl-file-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.cl-file-input {
  /* Visually hidden but still accessible/clickable via the styled button
     (customily-shopify.js triggers it programmatically); not display:none so
     the browser's native file dialog behavior stays reliable. */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.cl-file-button {
  padding: 0.625rem 1rem;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  transition: background 0.15s;
}

.cl-file-button:hover {
  background: #e5e7eb;
}

.cl-file-button:focus-visible {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.cl-file-name {
  font-size: 0.875rem;
  color: #374151;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

/* Options toggle */
.cl_options_toggle {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  margin-bottom: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.cl_options_toggle:hover {
  background: #f3f4f6;
}

.cl-toggle {
  display: block;
}

/* Conditional field groups: customily-shopify.js sets inline
   style="display:none" on ._cl_field_group elements whose show/hide
   conditions aren't met (see checkAllConditions()); this just guards against
   any theme CSS overriding that inline style with !important elsewhere. */
._cl_field_group[style*="display: none"] {
  display: none !important;
}

/* Gallery overlay — covers the product gallery when personalizing.
   Uses inset:0 to match the slider dimensions exactly (no aspect-ratio
   assumption) so it never overflows into the thumbnail strip. */
.cl-gallery-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  overflow: hidden;
}

.cl-gallery-overlay canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Mobile sticky preview bar — matches WooCommerce woa-clp-top */
.cl-sticky-preview {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  height: 129px !important;
  z-index: 999998 !important;
  background: #fff !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.cl-sticky-preview[style*="display: none"] {
  display: none !important;
}

.cl-sticky-hit {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 112px;
  width: 112px;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.cl-sticky-hit canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.cl-sticky-zoom {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* Bottom PREVIEW bar — matches WooCommerce woa-cl-previewbar */
.cl-preview-bar {
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  z-index: 999998 !important;
  padding: 14px;
  background: transparent;
}

.cl-preview-bar[style*="display: none"] {
  display: none !important;
}

.cl-preview-bar__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  background: #1e293b;
  color: #fff;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.cl-preview-bar__btn:active {
  background: #334155;
}

/* Responsive */
@media (min-width: 750px) {
  .cl-sticky-preview,
  .cl-preview-bar {
    display: none !important;
  }
}

@media (max-width: 749px) {
  .cl-swatch {
    width: 40px;
    height: 40px;
  }

  .cl-file-wrapper {
    flex-wrap: wrap;
  }

  .cl-file-name {
    width: 100%;
    max-width: none;
  }

  #customily-preview-modal {
    background: rgba(18, 17, 24, 0.92) !important;
    align-items: flex-end !important;
  }

  .cl-preview-content {
    max-width: 100vw;
    width: 100vw;
    border-radius: 16px 16px 0 0;
    padding: 20px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
    max-height: 92vh;
    overflow-y: auto;
  }
}

@media (max-width: 480px) {
  .cl_options {
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .cl-input,
  .cl-select,
  .cl-textarea,
  .cl-file-button,
  .cl_options_toggle {
    font-size: 16px;
  }

  .cl-swatch {
    width: 36px;
    height: 36px;
  }
}

/* Inline add-to-cart validation error, replaces the previous alert() so the
   message appears next to the button the customer just pressed. */
.cl-atc-error {
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-left: 3px solid #d72c0d;
  background: #fff4f4;
  color: #8e1600;
  font-size: 0.875rem;
  line-height: 1.4;
}
