/* customizer_bracelet.css */

body.designer-mode {
  background-color: #fcfcfc;
  margin: 0;
  font-family: 'DM Sans', sans-serif;
  overflow-x: hidden;
  color: #1c2331;
}

/* === TOOLBAR === */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: #fff;
  border-bottom: 1px solid #eee;
  position: sticky;
  top: 0;
  z-index: 200;
}

.toolbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: #111;
  display: flex;
  align-items: center;
  gap: 5px;
  border-radius: 6px;
  transition: background 0.2s;
}

.toolbar-btn:hover {
  background: #f0f0f0;
}

.toolbar-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.toolbar-btn.clear-all-btn {
  color: #ef4444;
}

.toolbar-btn.clear-all-btn:hover {
  background: #fef2f2;
}

.text-btn {
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}

.toolbar-title {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 2px;
}

@media (max-width: 768px) {
  .toolbar {
    padding: 8px 14px;
    position: sticky;
    top: 0;
    z-index: 300;
  }
  .toolbar-title {
    display: none;
  }
  /* ให้ปุ่มใน toolbar ขนาดพอดีสำหรับ tap */
  .toolbar-btn {
    padding: 10px;
    min-width: 40px;
    min-height: 40px;
    justify-content: center;
  }
  .text-btn {
    padding: 8px 10px;
    font-size: 0.85rem;
  }
}

/* === LAYOUT === */
.app-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px);
  overflow: hidden;
}

@media (min-width: 769px) {
  .app-layout {
    flex-direction: row;
  }
}

/* === STAGE (LEFT / TOP) === */
.stage-section {
  flex: 1;
  background: #f8f9fa;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

@media (max-width: 768px) {
  .stage-section {
    position: relative;
    top: unset;
    z-index: 1;
    padding: 8px 12px;
    background: #fafafa;
    border-bottom: 1px solid #eee;
    flex: 0 0 40%; /* ลดพื้นที่ส่วนกำไลลงเหลือ 40% เพื่อเพิ่มพื้นที่ให้แผงเลือกจี้ด้านล่าง */
    min-height: 0;
    overflow: hidden;
  }
  .stage-card {
    padding: 8px 12px;
    border-radius: 12px;
    box-shadow: none;
    background: transparent;
    height: 100%;
    justify-content: center;
  }
  .instruction-text {
    display: none;
  }
  .bracelet-wrap {
    height: 100%;
  }
}

@media (min-width: 769px) {
  .stage-section {
    border-right: 1px solid #eaeaea;
  }
}

.stage-card {
  width: 100%;
  max-width: 600px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.05);
  padding: 20px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.instruction-text {
  font-size: 0.9rem;
  color: #888;
  margin-top: 20px;
  margin-bottom: 0;
}

/* Freeform Drop Zone */
.bracelet-wrap {
  width: 100%;
  height: 250px; /* Base height for the stage on mobile */
  position: relative;
  border: 2px dashed transparent;
  border-radius: 12px;
  transition: border-color 0.3s;
}

.bracelet-wrap.drag-over {
  border-color: #ff99cc;
  background-color: rgba(255, 153, 204, 0.05);
}

.chain-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 1;
  pointer-events: none; /* Let clicks pass through to charms */
  transform: scale(1.15); /* ขยายขนาดกำไลให้ใหญ่และชัดเจนขึ้นเหมือนในรูป */
  transition: transform 0.3s ease;
}

.freeform-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Dropped Charm Styling */
.dropped-charm {
  position: absolute;
  width: 110px; /* ขนาดจี้บน PC (ปรับใหญ่ขึ้น) */
  height: 110px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.22));
}

@media (max-width: 768px) {
  .chain-background {
    transform: scale(1.25); /* ขยายรูปกำไลบนมือถือให้ใหญ่ขึ้น เพื่อให้สัดส่วนเข้ากับจี้ 95px */
  }
  .dropped-charm {
    width: 105px; /* ขนาดจี้บนมือถือ ใหญ่กดง่าย และสมส่วนกับกำไล (ปรับใหญ่ขึ้น) */
    height: 105px;
  }
}

.dropped-charm:active {
  cursor: grabbing;
}

.dropped-charm img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none; /* Prevents native drag ghosting interfering with interact.js */
}

/* Active Charm (Rotation & Bounding Box) */
.dropped-charm.active {
  outline: 2px solid #007AFF;
}

.rotator-handle {
  position: absolute;
  top: -35px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 24px;
  background-color: #fff;
  border: 2px solid #007AFF;
  border-radius: 50%;
  cursor: grab;
  display: none;
  touch-action: none;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.rotator-handle:active {
  cursor: grabbing;
}

.dropped-charm.active .rotator-handle {
  display: block;
}

/* Connecting line for rotator */
.rotator-handle::after {
  content: '';
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 11px;
  background-color: #007AFF;
}

/* Floating Trash */
.floating-trash {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 10;
}

.floating-trash.show {
  opacity: 1;
  visibility: visible;
}

.floating-trash.drag-over {
  transform: scale(1.1);
  background: #ffeeee;
}

/* === CONTROL PANEL (RIGHT / BOTTOM) === */
.control-panel {
  width: 100%;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (max-width: 768px) {
  .control-panel {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }
}

@media (min-width: 769px) {
  .bracelet-wrap {
    height: 400px; /* Larger stage on desktop */
  }
  
  .control-panel {
    width: 45%;
    max-width: 450px;
    min-width: 350px;
    height: 100%;
  }
}

/* Chain Settings */
.chain-settings {
  padding: 15px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  background: #fafafa;
}

.setting-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.setting-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #888;
  letter-spacing: 1px;
}

.color-options {
  display: flex;
  gap: 8px;
}

.color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.2s;
}

.color-dot.active {
  border-color: #111;
  transform: scale(1.1);
}

.style-select {
  padding: 6px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
}

/* Categories */
.category-header {
  padding: 12px 20px 4px;
}
.active-category-title {
  font-size: 1rem;
  margin: 0;
  text-align: center;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 500;
  color: #111;
}

.filters-scroll {
  overflow-x: auto;
  padding: 8px 16px 4px;
  border-bottom: 1px solid #f0f0f0;
}
.filters-scroll::-webkit-scrollbar { display: none; }

.filters-track {
  display: flex;
  gap: 20px;
  padding-bottom: 8px;
}

/* --- Filter buttons: Italian charm style --- */
.filter-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #888;
  padding: 0;
  min-width: 56px;
  transition: color 0.2s;
}

.filter-btn.active {
  color: #111;
}

/* วงกลมไอคอน */
.filter-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #f5f5f5;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.4rem;
  transition: all 0.25s ease;
  overflow: hidden;
}

.filter-icon img {
  width: 70%;
  height: 70%;
  object-fit: contain;
  pointer-events: none;
}

/* Active: วงกลม pink เหมือน Italian */
.filter-btn.active .filter-icon {
  background: #e91e63;
  box-shadow: 0 4px 12px rgba(233,30,99,0.25);
  color: #fff;
}

.filter-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
}

/* Search */
.search-bar-wrap {
  padding: 0 20px 10px;
}
.search-input {
  width: 100%;
  padding: 10px 15px;
  border: 1px solid #eee;
  border-radius: 8px;
  background: #f9f9f9;
  font-family: inherit;
  font-size: 0.9rem;
  box-sizing: border-box;
}

/* Charms Grid — Bracelet charm style */
.charms-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, 100px);
  gap: 12px;
  justify-content: center;
  align-content: start;
}

@media (max-width: 768px) {
  .charms-grid {
    grid-template-columns: repeat(auto-fill, 100px);
    gap: 10px;
    padding: 8px 12px 130px;
    justify-content: center;
  }
}

/* Charm card: โปร่งใส ไม่มีกรอบ เหมือน Italian */
.charm-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: grab;
  background: transparent;
  border: none;
  padding: 6px 4px;
  border-radius: 10px;
  transition: background 0.15s ease;
  gap: 4px;
  width: 100px; /* ล็อคขนาด card ให้เท่ากันทุก อัน */
}

.charm-card:hover {
  background: #f8f8f8;
}

.charm-card:active {
  cursor: grabbing;
}

/* กล่องรูปภาพ: ขนาดคงที่เสมอทุก screen */
.charm-img-box {
  width: 90px;
  height: 90px;
  flex-shrink: 0;
  background: transparent;
  border-radius: 0;
  padding: 0;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.2s ease;
  overflow: hidden;
}

.charm-card:hover .charm-img-box {
  transform: scale(1.08);
}

.charm-img-box img {
  width: 90px;
  height: 90px;
  object-fit: contain;
  pointer-events: none;
  display: block;
  flex-shrink: 0;
}

.charm-price {
  font-size: 0.75rem;
  font-weight: 600;
  color: #555;
  letter-spacing: 0.2px;
}

/* Summary card — redesigned as single row on mobile */
.summary-card {
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid #eee;
}

@media (max-width: 768px) {
  .summary-card {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: #fff;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(0,0,0,0.10);
    /* single row layout */
    display: flex;
    align-items: center;
    gap: 10px;
  }
  /* ซ่อน summary-top ปกติ แสดงแค่ inline บน mobile */
  .summary-card .summary-top {
    display: none;
  }
  .checkout-btn {
    flex: 1;
    padding: 12px 16px;
    font-size: 0.95rem;
    border-radius: 10px;
    white-space: nowrap;
  }
}

/* Mobile inline price + count (แสดงแค่ใน mobile) */
.summary-mobile-left {
  display: none;
}

@media (max-width: 768px) {
  .summary-mobile-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex-shrink: 0;
  }
  .summary-mobile-price {
    font-size: 1.15rem;
    font-weight: 800;
    color: #111;
    line-height: 1.2;
  }
  .summary-mobile-count {
    font-size: 0.75rem;
    color: #999;
    font-weight: 500;
  }
}

.summary-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.total-label {
  font-size: 0.9rem;
  color: #666;
}

.total-amount {
  font-size: 1.2rem;
  font-weight: 700;
  margin-left: 5px;
}

.summary-count {
  font-size: 0.85rem;
  color: #888;
}

.checkout-btn {
  width: 100%;
  padding: 15px;
  background: #111;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.3s;
}

.checkout-btn:hover {
  background: #333;
}

/* === BRACELET SELECTION OVERLAY === */
.chain-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.chain-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.chain-modal {
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.05);
  max-width: 920px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.chain-overlay.hidden .chain-modal {
  transform: scale(0.95);
}

/* ── Header row: back | title | spacer ── */
.chain-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
  flex-shrink: 0;
}

.chain-modal-back {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #555;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid #eee;
  background: #fafafa;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.chain-modal-back:hover {
  background: #f0f0f0;
  color: #111;
  border-color: #ddd;
}

.chain-modal-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.25rem;
  color: #111;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-align: center;
  margin: 0;
  flex: 1;
}

/* mirror spacer = same width as back button to keep title visually centered */
.chain-modal-header-spacer {
  flex-shrink: 0;
  min-width: 100px; /* approx width of back btn */
}

/* ── Subtitle ── */
.chain-modal-subtitle {
  color: #888;
  font-size: 0.88rem;
  text-align: center;
  margin: 8px 24px 20px;
}

/* ── Options grid ── */
.chain-options-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding: 0 24px 28px;
}

/* Responsive */
@media (max-width: 700px) {
  .chain-modal-header {
    padding: 16px 16px 0;
  }

  .chain-modal-title {
    font-size: 1rem;
  }

  .chain-modal-header-spacer {
    min-width: 80px;
  }

  .chain-modal-subtitle {
    margin: 6px 16px 16px;
    font-size: 0.82rem;
  }

  .chain-options-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 0 16px 20px;
  }
}

.chain-card-option {
  background: #fcfcfc;
  border: 1px solid #eee;
  border-radius: 16px;
  padding: 15px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
}

.chain-card-option:hover {
  transform: translateY(-5px);
  border-color: #ff99cc;
  box-shadow: 0 12px 25px rgba(255, 153, 204, 0.15);
  background: #fff;
}

.chain-card-img-wrap {
  width: 100%;
  aspect-ratio: 1.2;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #f6f6f6;
  box-sizing: border-box;
}

.chain-card-img-wrap img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  mix-blend-mode: multiply;
  transition: transform 0.3s ease;
}

.chain-card-option:hover .chain-card-img-wrap img {
  transform: scale(1.05);
}

.chain-card-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chain-card-name {
  font-size: 1rem;
  font-weight: 700;
  color: #111;
}

.chain-card-color-lbl {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  display: inline-block;
  align-self: center;
}

.chain-card-color-lbl.silver-lbl {
  background: #eef2f5;
  color: #5d6e7c;
}

.chain-card-color-lbl.gold-lbl {
  background: #fdf6e2;
  color: #b78a0a;
}

.chain-card-color-lbl.rosegold-lbl {
  background: #fdeef0;
  color: #b5566b;
}

/* ─── ORDER MODAL ─── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
}

.modal-backdrop.open {
  display: block;
}

.modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -48%) scale(0.96);
  opacity: 0;
  transition: transform 0.22s ease, opacity 0.22s ease, background-color 0.3s ease;
  width: min(480px, 92vw);
  background: #fff;
  border-radius: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3);
  z-index: 101;
  overflow: hidden;
  border: 1px solid #ddd;
}

.modal.open {
  display: block;
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.75rem 1.75rem 1rem;
  border-bottom: 1px solid #ddd;
}

.modal-eyebrow {
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #666;
  margin-bottom: 4px;
  font-family: 'DM Sans', sans-serif;
}

.modal-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.5rem;
  font-weight: 400;
  color: #111;
  letter-spacing: 0.02em;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  color: #999;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
  margin-top: 2px;
}

.modal-close:hover {
  color: #111;
  background: #eee;
}

.modal-body {
  padding: 1.25rem 1.75rem 1.75rem;
}

.modal-summary {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 1rem;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
  font-size: 13.5px;
}

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

.summary-item span:first-child {
  color: #666;
}

.summary-item span:last-child {
  font-weight: 500;
  color: #111;
}

.modal-total {
  padding: 1rem;
  background: #f9f9f9;
  border-radius: 0;
  border: 1px solid #ddd;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: #000;
}

.modal-note {
  font-size: 12px;
  color: #666;
  text-align: center;
  margin-bottom: 1rem;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 10px;
  align-items: stretch;
  justify-content: center;
}

.line-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 24px;
  background: #06C755;
  color: #fff;
  border: none;
  border-radius: 0;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.18s, transform 0.12s;
  flex: 1;
  justify-content: center;
}

.line-btn:hover {
  background: #05a648;
}

.modal-cancel {
  padding: 14px 20px;
  background: #fff;
  color: #111;
  border: 1px solid #ddd;
  border-radius: 0;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.modal-cancel:hover {
  background: #eee;
}
