/* Print Studio CSS - Spreadshirt-style Product Configurator */

:root {
  --ps-sidebar-width: 320px;
  --ps-topbar-height: 56px;
  --ps-accent: #00b2a5;
  --ps-bg: #f2f2f2;
  --ps-panel-bg: #ffffff;
  --ps-border: #e5e5e5;
}

body.ps-page {
    overflow: hidden;
}

#ps-app {
  display: grid;
  grid-template-columns: var(--ps-sidebar-width) 1fr;
  grid-template-rows: var(--ps-topbar-height) 1fr;
  height: 100vh;
  background: var(--ps-bg);
}

/* ── TOP BAR ──────────────────────────────────────────────────────── */
#ps-topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border-bottom: 1px solid var(--ps-border);
  padding: 0 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  z-index: 10;
}

.ps-logo img {
    height: 32px;
}

.ps-product-name {
    font-weight: 700;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* left group (logo + name) must be allowed to shrink so it never
   pushes into the Close button on the right */
#ps-topbar > .d-flex:first-child {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    margin-right: 0.5rem;
}

/* ── SIDEBAR ──────────────────────────────────────────────────────── */
#ps-sidebar {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  background: var(--ps-panel-bg);
  border-right: 1px solid var(--ps-border);
  overflow: hidden;
}

.ps-tool-icons {
  width: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-right: 1px solid var(--ps-border);
  padding: 0.5rem 0;
  gap: 4px;
}

.ps-tool-icon {
  width: 48px;
  height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  font-size: 10px;
  color: #737373;
  transition: background 0.15s, color 0.15s;
}

.ps-tool-icon:hover,
.ps-tool-icon.active {
  background: var(--ps-bg);
  color: var(--ps-accent);
}

.ps-tool-icon svg {
    margin-bottom: 2px;
}

.ps-panels-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.ps-panel {
  display: none;
}

.ps-panel.active {
    display: block;
}

.ps-panel-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

/* ── CANVAS ZONE ──────────────────────────────────────────────────── */
#ps-canvas-zone {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  background: var(--ps-bg);
}

#ps-canvas-wrapper {
  position: relative;
  /* No background — let PNG transparency show through to canvas-zone bg */
  width: 600px;
  height: 600px;
  /* Shift canvas up so it appears visually centred (tabs take space at bottom) */
  margin-bottom: 150px;
}

/* Fabric creates a .canvas-container div — keep it in flow */
/* drop-shadow here follows the actual PNG alpha, not the rectangle */
#ps-canvas-wrapper .canvas-container {
    position: absolute !important;
    top: 0;
    left: 0;
    filter: drop-shadow(0 6px 20px rgba(0,0,0,.20));
}

/* ── CANVAS SLIDE TRANSITION ─────────────────────────────────────── */
@keyframes ps-slide-out-left {
  from { transform: translateX(0);     opacity: 1; }
  to   { transform: translateX(-48px); opacity: 0; }
}
@keyframes ps-slide-in-right {
  from { transform: translateX(48px);  opacity: 0; }
  to   { transform: translateX(0);     opacity: 1; }
}
.ps-canvas-slide-out {
  animation: ps-slide-out-left 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  pointer-events: none;
}
.ps-canvas-slide-in {
  animation: ps-slide-in-right 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* ── AREA TABS ────────────────────────────────────────────────────── */
#ps-area-tabs {
  display: flex;
  gap: 8px;
  position: absolute;
  bottom: 110px;
  z-index: 5;
}

.ps-area-tab {
  width: 64px;
  height: 64px;
  border: 2px solid var(--ps-border);
  border-radius: 4px;
  cursor: pointer;
  overflow: hidden;
  background: #fff;
  transition: border-color 0.15s;
  position: relative;
}

.ps-area-tab.active {
    border-color: var(--ps-accent);
}

.ps-area-tab img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.ps-area-tab span {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 9px;
  text-align: center;
  background: rgba(255,255,255,.85);
  padding: 2px;
}

/* ── PRICE BAR ────────────────────────────────────────────────────── */
#ps-price-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--ps-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
  gap: 1.25rem;
  z-index: 10;
  box-shadow: 0 -2px 8px rgba(0,0,0,.06);
}

.ps-price-bar-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

#ps-price-display {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0;
}

/* ── PRICE COLUMNS (Pack | Base | Extra | Total) ─────────────────── */
.ps-pcol {
  display: flex;
  flex-direction: column;
  align-items: right;
  padding: 0 0.7rem;
  min-width: 64px;
}

.ps-pcol-total { padding-right: 0; }

.ps-plabel {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #999;
  font-weight: 600;
  white-space: nowrap;
  margin-bottom: 2px;
}

.ps-pval {
  font-size: 0.92rem;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
}

.ps-pval-extra { color: var(--ps-accent); }

.ps-pval-total {
  font-size: 1.35rem;
  font-weight: 700;
  color: #1a1a1a;
}

.ps-pdivider {
  width: 1px;
  height: 30px;
  background: var(--ps-border);
  flex-shrink: 0;
}

/* ── QTY STEPPER ─────────────────────────────────────────────────── */
.ps-qty-stepper {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--ps-border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.ps-qty-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  color: #555;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ps-qty-btn:hover {
  background: var(--ps-bg);
  color: var(--ps-accent);
}

.ps-qty-input {
  width: 42px;
  height: 34px;
  border: none;
  border-left: 1.5px solid var(--ps-border);
  border-right: 1.5px solid var(--ps-border);
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: #222;
  -moz-appearance: textfield;
  background: #fff;
}

.ps-qty-input::-webkit-inner-spin-button,
.ps-qty-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}



/* ── COLOR SWATCH ─────────────────────────────────────────────────── */
.ps-color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
  overflow: hidden;
  display: inline-block;
}

.ps-color-swatch.active {
    border-color: var(--ps-accent);
}

.ps-color-swatch-half {
  width: 50%;
  height: 100%;
  float: left;
}

/* ── PRINTSHOP ATTRIBUTE SELECTORS ───────────────────────────────── */
.ps-attr-group .form-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ps-muted, #888);
  margin-bottom: 6px;
  display: block;
}

.ps-attr-values-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ps-attr-value-btn {
  background: var(--ps-surface);
  color: var(--ps-text);
  border: 1px solid var(--ps-border, #444);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  line-height: 1.4;
}

.ps-attr-value-btn small {
  opacity: 0.7;
}

.ps-attr-value-btn:hover {
  border-color: var(--ps-accent);
}

.ps-attr-value-btn.active {
  border-color: var(--ps-accent);
  background: var(--ps-surface);
  border-radius: 4px;
  color: var(--ps-text);
}

/* ── FLOATING TOOLBAR ─────────────────────────────────────────────── */
#ps-floating-toolbar {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: #fff;
  border: 1px solid var(--ps-border);
  border-radius: 6px;
  padding: 6px;
  display: none;
  gap: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
  z-index: 20;
}

#ps-floating-toolbar.visible {
    display: flex;
}

/* ── BORDER TOGGLE BUTTON ─────────────────────────────────────────── */
.ps-border-toggle-btn.active {
  color: var(--ps-accent);
}

/* ── AREAS PANEL CARDS ────────────────────────────────────────────── */
#ps-areas-panel-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.ps-area-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 2px solid var(--ps-border);
  border-radius: 6px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s, background 0.15s;
}

.ps-area-card:hover {
  border-color: var(--ps-accent);
  background: var(--ps-bg);
}

.ps-area-card.active {
  border-color: var(--ps-accent);
  background: #e8faf9;
}

.ps-area-card-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--ps-bg);
  border: 1px solid var(--ps-border);
}

.ps-area-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ps-area-card-info {
  flex: 1;
  min-width: 0;
}

.ps-area-card-name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ps-area-card-hint {
  font-size: 0.78rem;
  color: #888;
  margin-top: 2px;
}

.ps-area-card-badge {
  font-size: 0.72rem;
  background: var(--ps-accent);
  color: #fff;
  border-radius: 20px;
  padding: 2px 8px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
}

.ps-area-card.active .ps-area-card-badge {
  opacity: 1;
}


.ps-tab-strip {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--ps-border);
    padding-bottom: 0.5rem;
}

.ps-tab {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-weight: 500;
    color: #737373;
    transition: color 0.15s;
}

.ps-tab.active {
    color: var(--ps-accent);
    border-bottom: 2px solid var(--ps-accent);
}

/* search input */
#ps-design-search {
  border-radius: 10px;
}

/* category tag pills */
#ps-category-tabs .btn {
  border-radius: 20px !important;
  font-size: 0.8rem;
  padding: 3px 12px;
}

#ps-category-tabs .btn.active {
  background: var(--ps-accent);
  border-color: var(--ps-accent);
  color: #fff;
}

.ps-design-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-top: 0.5rem;
}

/* Upload history thumbnails — 2 columns so each square is larger */
.ps-upload-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.ps-upload-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  background: var(--ps-bg);
  transition: border-color 0.15s, transform 0.1s;
}

.ps-upload-thumb:hover {
  border-color: var(--ps-accent);
  transform: scale(1.04);
}

.ps-upload-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
  display: block;
}

.ps-upload-del {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  padding: 0;
  line-height: 1;
  font-size: 13px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.ps-upload-thumb:hover .ps-upload-del {
  display: flex;
}

.ps-upload-del:hover {
  background: #d9534f;
}

.ps-design-item {
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  background: var(--ps-bg);
  transition: border-color 0.15s, transform 0.1s;
}

.ps-design-item:hover {
    border-color: var(--ps-accent);
    transform: scale(1.04);
}

.ps-design-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
}

/* ── TEXT TOOL ────────────────────────────────────────────────────── */
.ps-text-textarea {
  resize: vertical;
  min-height: 80px;
  font-size: 0.95rem;
  line-height: 1.5;
  border-radius: 8px;
}

.ps-font-select,
.ps-color-input {
    width: 100%;
    margin-bottom: 0.5rem;
    border-radius: 8px;
}

.ps-size-slider {
    width: 100%;
    margin-bottom: 0.5rem;
}

.ps-toggle-btn {
  padding: 4px 10px;
  border: 1px solid var(--ps-border);
  border-radius: 6px;
  cursor: pointer;
  background: #fff;
  font-weight: 700;
  transition: background 0.15s;
}

.ps-toggle-btn.active {
    background: var(--ps-accent);
    color: #fff;
    border-color: var(--ps-accent);
}

/* ── UPLOAD AREA ──────────────────────────────────────────────────── */
.ps-upload-area {
    cursor: pointer;
    border-style: dashed !important;
    border-radius: 12px !important;
    min-height: 150px;
    transition: border-color 0.15s, background 0.15s;
}

.ps-upload-area:hover {
    border-color: var(--ps-accent) !important;
    background: #f0fffe;
}

/* ── PRODUCT MODAL ────────────────────────────────────────────────── */
#ps-product-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center;
  justify-content: center;
}

#ps-product-modal.open {
    display: flex;
}

.ps-product-modal-inner {
  background: #fff;
  border-radius: 8px;
  width: min(90vw, 800px);
  max-height: 80vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.ps-related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.ps-related-item {
  border: 2px solid var(--ps-border);
  border-radius: 6px;
  padding: 0.75rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s;
}

.ps-related-item:hover {
    border-color: var(--ps-accent);
}

.ps-related-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    margin-bottom: 0.5rem;
}

/* ── CART PREVIEW ─────────────────────────────────────────────────── */
.ps-cart-previews {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.ps-cart-previews > div {
    width: 48px;
    height: 48px;
    border: 1px solid #e5e5e5;
    border-radius: 3px;
    overflow: hidden;
}

.ps-cart-previews img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE
   Desktop  >= 1024px : 2-col grid, sidebar 320px  (base styles)
   Tablet   768-1023px: sidebar 240px, canvas scale(0.85)
   Mobile   <  768px  : flex-column, sidebar = horizontal bottom nav
   Small    <  400px  : canvas scale(0.50)
   ══════════════════════════════════════════════════════════════════ */

/* ── TABLET ───────────────────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --ps-sidebar-width: 240px; }

  /* Shrink canvas 15 % so it comfortably fits the narrower canvas zone.
     DOM size stays 600x600 (Fabric requirement). Visual = 510px.
     margin-bottom recalculated: original 150px - 600*0.15 = 60px */
  #ps-canvas-wrapper {
    transform: scale(0.85);
    transform-origin: top center;
    margin-bottom: 60px;
  }

  .ps-design-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ── MOBILE ───────────────────────────────────────────────────────── */
@media (max-width: 767px) {

  /* Replace grid with a vertical flex stack */
  #ps-app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    height: 100vh; /* fallback */
  }

  #ps-topbar {
    flex-shrink: 0;
    padding: 0 1rem;
  }

  .ps-product-name { font-size: 0.9rem; }

  /* Canvas zone fills the middle — overflow:hidden clips the 600px DOM canvas */
  #ps-canvas-zone {
    flex: 1;
    min-height: 0;
    grid-column: unset;
    grid-row: unset;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow: hidden;
    padding-top: 1rem;
  }

  /* Scale the 600x600 DOM canvas visually to 60 %.
     transform-origin: top center keeps it horizontally centred.
     Negative margin-bottom reclaims dead space below visual canvas:
     600 * (1 - 0.60) = 240 px */
  #ps-canvas-wrapper {
    width: 600px;
    height: 600px;
    transform: scale(0.60);
    transform-origin: top center;
    margin-bottom: -240px;
  }

  #ps-area-tabs { bottom: 68px; gap: 6px; }
  .ps-area-tab  { width: 50px; height: 50px; }

  /* Compact price bar */
  #ps-price-bar { padding: 0.4rem 0.75rem; gap: 0.75rem; }
  #ps-add-to-cart-btn { font-size: 0.875rem; padding: 0.35rem 0.85rem; }

  /* Sidebar becomes a bottom sheet */
  #ps-sidebar {
    flex-shrink: 0;
    flex-direction: column;
    grid-column: unset;
    grid-row: unset;
    border-right: none;
    border-top: 1px solid var(--ps-border);
    overflow: visible;
    height: auto;
  }

  /* Tool icons: horizontal bottom navigation bar */
  .ps-tool-icons {
    order: 2;
    flex-direction: row;
    width: 100%;
    height: 50px;
    border-right: none;
    border-top: 1px solid var(--ps-border);
    justify-content: space-around;
    padding: 0 0.25rem;
    flex-shrink: 0;
    overflow-x: auto;
  }

  .ps-tool-icon { width: 48px; height: 48px; font-size: 9px; border-radius: 8px; }

  /* Panel drawer: collapsed by default, expands when a panel is active.
     :has() is supported in Chrome 105+, Safari 15.4+, Firefox 121+ */
  .ps-panels-wrap {
    order: 1;
    max-height: 0;
    overflow: hidden;
    padding: 0;
    transition: max-height 0.28s ease, padding 0.28s ease;
  }

  #ps-sidebar:has(.ps-panel.active) .ps-panels-wrap {
    max-height: 44dvh;
    max-height: 44vh; /* fallback */
    padding: 0.5rem 0.75rem;
    overflow-y: auto;
  }

  .ps-design-grid   { grid-template-columns: repeat(4, 1fr); }
  .ps-upload-area   { min-height: 120px; }
  #ps-floating-toolbar { top: 0.5rem; right: 0.5rem; }
}

/* ── LOADING OVERLAY ─────────────────────────────────────────────── */
#ps-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
}

#ps-loading-overlay.d-none {
  display: none !important;
}

.ps-loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(0, 0, 0, 0.6);
  padding: 2rem 2.5rem;
  border-radius: 0.5rem;
}

/* ── SMALL MOBILE ─────────────────────────────────────────────────── */
@media (max-width: 399px) {
  /* 600 * (1 - 0.50) = 300 px reclaimed below visual canvas */
  #ps-canvas-wrapper {
    transform: scale(0.50);
    margin-bottom: -300px;
  }

  #ps-area-tabs { bottom: 62px; }
  .ps-area-tab  { width: 44px; height: 44px; }
  .ps-design-grid { grid-template-columns: repeat(3, 1fr); }
  #ps-price-bar   { padding: 0.35rem 0.5rem; gap: 0.5rem; }
  .ps-pval-total  { font-size: 1.1rem; }
  .ps-pcol        { padding: 0 0.4rem; min-width: 48px; }
  .ps-plabel      { font-size: 0.55rem; }
}

/* ── Notification toast ───────────────────────────────────────────────────── */
.ps-notification {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  max-width: 380px;
  padding: 0.875rem 1.25rem;
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.4;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  animation: ps-notif-in 0.2s ease;
}
.ps-notification-error {
  background: #fff3f3;
  color: #c0392b;
  border: 1px solid #e8a0a0;
}
.ps-notification-success {
  background: #f0faf5;
  color: #1a7a4a;
  border: 1px solid #7ecba1;
}
@keyframes ps-notif-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
