/**
 * KMCC customizer — all frontend styling.
 * Loaded by KMCC_Frontend only on the customizer product template.
 */

:root{
  --ink:#17181B;
  --paper:#F3F4F1;
  --stage-a:#DEDFDA;
  --stage-b:#EFEFEC;
  --line:#CBCCC4;
  --line-soft:#DEDFD8;
  --coral:#E15A45;
  --coral-dark:#B5442F;
  --moss:#5F6E45;
  --moss-dark:#4A5636;
  --panel:#FFFFFF;
  --muted:#75766E;

  --rail-w:  clamp(40px, 4.6%, 56px);
  --panel-w: clamp(320px, 38%, 450px);
  --stage-h: clamp(373px, 52.5vh, 549px);
  --stage-h: clamp(373px, 52.5dvh, 549px);
}
.case-customizer-wrap * { box-sizing: border-box; }
body.kmcc-no-scroll { overflow: hidden; }

.case-customizer-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 15px 36px;
  font-family: 'Inter', sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}

.customizer-layout {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--panel-w);
  grid-template-rows: var(--stage-h) auto auto;
  grid-template-areas:
    "rail  stage  controls"
    ".     save   controls"
    ".     models controls";
  column-gap: 14px;
  row-gap: 12px;
  align-items: start;
}
.thumb-rail     { grid-area: rail; }
.stage-shell    { grid-area: stage; }
.save-row       { grid-area: save; }
.model-block    { grid-area: models; }
.controls-panel { grid-area: controls; }

/* Thumbnail rail -------------------------------------------------- */
.thumb-rail{
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.rail-item{
  position: relative;
  min-width: 0;
}
.rail-thumb{
  display: block;
  width: 100%;
  aspect-ratio: 260 / 547;
  border-radius: 8px;
  border: 2px solid var(--line-soft);
  background: #fff center / cover no-repeat;
  padding: 0;
  cursor: pointer;
  transition: border-color .12s ease, transform .12s ease;
}
.rail-item:hover .rail-thumb{ transform: translateY(-2px); }
.rail-thumb.active{ border-color: var(--coral); }

.rail-remove{
  position: absolute;
  top: 3px;
  right: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.94);
  color: var(--ink);
  font-size: 13px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s ease;
  box-shadow: 0 1px 3px rgba(23,24,27,.2);
}
.rail-item:hover .rail-remove,
.rail-remove:focus-visible{ opacity: 1; }
.rail-remove:hover{ background: #fff; border-color: var(--coral); color: var(--coral); }
@media (hover: none){
  .rail-remove{ opacity: 1; }
  .rail-item:hover .rail-thumb{ transform: none; }
}
.thumb-rail:empty::before{
  content: "";
  display: block;
  width: 100%;
  aspect-ratio: 260 / 547;
  border: 1.5px dashed var(--line);
  border-radius: 8px;
}

/* Right panel ----------------------------------------------------- */
.controls-panel{
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  padding: 16px;
  min-width: 0;
}
.case-customizer-wrap h1.product-title {
  font-family: 'Fraunces', serif;
  font-weight: 500;
  font-size: clamp(19px, 1.7vw, 23px);
  margin: 0 0 14px;
  line-height: 1.2;
}
.panel-divider{
  height: 1px;
  background: var(--line-soft);
  margin: 14px 0;
}

/* Stage ----------------------------------------------------------- */
.stage-shell{
  position: relative;
  border-radius: 20px;
  background:
    radial-gradient(ellipse 60% 45% at 30% 20%, rgba(255,255,255,.5), transparent 60%),
    linear-gradient(160deg, var(--stage-a), var(--stage-b));
  padding: clamp(10px, 1.4vw, 14px) clamp(10px, 2vw, 16px) clamp(8px, 1.2vw, 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  height: var(--stage-h);
}
.stage-shell::before,
.stage-shell::after{
  content:"";
  position:absolute;
  border-radius:50%;
  filter:blur(26px);
  mix-blend-mode:multiply;
  opacity:.16;
  pointer-events:none;
}
.stage-shell::before{
  width:260px;height:340px;
  background:#8b8d80;
  top:-90px; left:-60px;
  transform:rotate(18deg);
}
.stage-shell::after{
  width:200px;height:260px;
  background:#8b8d80;
  bottom:-100px; right:-40px;
  transform:rotate(-24deg);
}
.canvas-holder{
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 16px 22px rgba(30,30,25,.16));
}
.canvas-holder canvas,
.canvas-holder .canvas-container{ touch-action: none; }
#editorCanvas{ display: block; border-radius: 34px; }
.placeholder{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  padding: 0 34px;
  z-index: 10;
}
.placeholder span{
  font-size: 13.5px;
  color: #9a9c92;
  line-height: 1.5;
  font-weight: 500;
}

/* Right column --------------------------------------------------- */
.block{
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  padding: 14px 16px;
}
.block-label{
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}
.model-grid{
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.model-card{
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 6px;
  background: #fff;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  transition: all .15s ease;
}
.model-card.active{
  border-color: var(--coral);
  background: #FBEFEC;
}
.model-chip{
  width: 18px; height: 30px;
  border-radius: 6px;
  border: 2px solid #3d3d3a;
  position: relative;
  flex: none;
}
.model-chip.pro::after{
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 7px; height: 7px;
  border-radius: 2px;
  background: #3d3d3a;
}
.model-name{
  font-size: 11.5px;
  font-weight: 500;
  text-align: center;
}
.tabs{
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.tab-btn{
  flex: 1;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}
.tab-btn.active{
  border-color: var(--ink);
  color: var(--ink);
  background: #f2f2ef;
}
.tab-panel{ display: none; }
.tab-panel.active{ display: block; }
.preset-grid{
  display: grid;
  --preset-cols: 6;
  grid-template-columns: repeat(var(--preset-cols), 1fr);
  gap: 8px;
}
.preset-swatch{
  aspect-ratio: 260 / 547;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  background-color: var(--stage-b);
  background-size: cover;
  background-position: center;
  padding: 0;
  transition: transform .12s ease, border-color .12s ease;
}
.preset-swatch:hover { transform: translateY(-2px); }
.preset-swatch.active{ border-color: var(--coral); }
.preset-more{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}
.preset-count{
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--muted);
}
.view-more-btn {
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: all .15s ease;
}
.view-more-btn:hover { background: #f7f7f4; border-color: #a9aa9f; }
.upload-drop{
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
}
.upload-drop p{ margin: 0; font-size: 12.5px; color: var(--muted); }
.upload-drop strong{ color: var(--ink); }
#fileInput{ display: none; }
.upload-hint{
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}
.upload-warn{
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: #FBEFEC;
  border: 1px solid #EBC4B9;
  color: var(--coral-dark);
  font-size: 11.5px;
  line-height: 1.45;
}
.upload-warn[hidden]{ display: none; }

/* Progress bars --------------------------------------------------- */
.kmcc-progress{ margin: 10px 0 0; }
.kmcc-progress[hidden]{ display: none; }
.kmcc-progress-track{
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--line-soft);
  overflow: hidden;
}
.kmcc-progress-bar{
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--coral), var(--coral-dark));
  transition: width .18s ease;
}
.kmcc-progress.is-done  .kmcc-progress-bar{
  background: linear-gradient(90deg, var(--moss), var(--moss-dark));
}
.kmcc-progress.is-error .kmcc-progress-bar{ background: var(--coral-dark); }
.kmcc-progress-label{
  margin: 6px 0 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.kmcc-progress.is-done  .kmcc-progress-label{ color: var(--moss-dark); }
.kmcc-progress.is-error .kmcc-progress-label{ color: var(--coral-dark); }

.stage-progress{
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  width: min(210px, 74%);
  margin: 0;
  padding: 8px 12px 9px;
  border-radius: 10px;
  background: rgba(255,255,255,.9);
  box-shadow: 0 2px 10px rgba(23,24,27,.14);
  z-index: 4;
  pointer-events: none;
}
.stage-progress .kmcc-progress-label{ margin-top: 5px; text-align: center; }

/* Save & preview -------------------------------------------------- */
.save-row{
  margin-top: 0;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  padding: 12px 16px;
  min-width: 0;
}
.save-preview-btn{
  width: 100%;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  padding: 11px 18px;
  border-radius: 8px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  transition: opacity .15s ease;
}
.save-preview-btn:disabled{
  opacity: .4;
  cursor: not-allowed;
}
.gate-note{
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
}
.gate-note.ok{ color: var(--moss); }
.gate-note.error{ color: var(--coral-dark); }

/* Attention blink — applied briefly by nudge() to the relevant section */
@keyframes kmcc-blink {
  0%   { box-shadow: 0 0 0 0   rgba(225,90,69,0);   border-color: inherit; }
  20%  { box-shadow: 0 0 0 4px rgba(225,90,69,0.35); border-color: var(--coral); }
  60%  { box-shadow: 0 0 0 4px rgba(225,90,69,0.35); border-color: var(--coral); }
  100% { box-shadow: 0 0 0 0   rgba(225,90,69,0);   border-color: inherit; }
}
.kmcc-blink {
  animation: kmcc-blink 0.7s ease 2;
  border-radius: 10px;
}

/*
 * FIX: The add-to-cart button is truly disabled (not just styled) when
 * the gate is locked. pointer-events:none stops theme ajax handlers from
 * wiring up their own click listener via jQuery delegation. The disabled
 * attribute stops browser-native click events AND jQuery's :disabled check.
 * Both are required — pointer-events alone doesn't block jQuery .trigger().
 */
.customizer-wc-summary .single_add_to_cart_button[disabled],
.customizer-wc-summary .single_add_to_cart_button.kmcc-locked {
  opacity: .45 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
}

/* Modal ---------------------------------------------------------- */
.modal-backdrop{
  position: fixed; inset: 0;
  background: rgba(23,24,27,.45);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 999999; opacity: 0;
  transition: opacity .18s ease;
}
.modal-backdrop[hidden]{ display: none; }
.modal-backdrop.open{ opacity: 1; }
.modal{
  background: var(--panel);
  border-radius: 16px;
  width: min(780px,100%);
  max-height: 85vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 26px 60px rgba(23,24,27,.22);
}
.modal-head{
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--line-soft);
}
.modal-head h2{ font-size: 20px; margin: 0; font-family: 'Fraunces', serif; font-weight: 500; }
.modal-close{ border: none; background: none; font-size: 24px; cursor: pointer; color: var(--muted); }
.modal-filters{
  display: flex; gap: 6px; padding: 12px 22px;
  border-bottom: 1px solid var(--line-soft);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.filter-btn{
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font-size: 12.5px; cursor: pointer; color: var(--muted);
  white-space: nowrap;
}
.filter-btn[aria-selected="true"]{ background: var(--ink); color: #fff; border-color: var(--ink); }
.filter-btn .filter-n{ font-family: 'IBM Plex Mono', monospace; font-size: 10px; margin-left: 5px; opacity: 0.7; }
.modal-body{
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 20px 22px; position: relative; min-height: 320px;
}
.design-grid{ display: grid; grid-template-columns: repeat(6,1fr); gap: 10px; }
.design-tile{ aspect-ratio: 260 / 547; border-radius: 8px; border: 2px solid transparent; background-size: cover; cursor: pointer; position: relative; overflow: hidden; padding:0; }
.design-tile:hover { transform: translateY(-2px); }
.design-tile.active{ border-color: var(--coral); }
.design-tile .tile-name{ position: absolute; inset: auto 0 0 0; padding: 12px 4px 4px; font-family: 'IBM Plex Mono', monospace; font-size: 9px; text-transform: uppercase; color: #fff; text-align: center; background: linear-gradient(to top, rgba(23,24,27,.75), transparent); opacity: 0; transition: opacity .15s ease; }
.design-tile:hover .tile-name { opacity: 1; }
.modal-foot{ display: flex; justify-content: space-between; align-items: center; padding: 12px 22px; border-top: 1px solid var(--line-soft); background: #FCFCFA; }
.pager{ display: flex; gap: 4px; flex-wrap: wrap; }
.page-btn{ min-width: 28px; height: 28px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; font-size: 12px; }
.page-btn[aria-current="page"]{ background: var(--ink); color: #fff; }

/* WooCommerce form ------------------------------------------------ */
.customizer-wc-summary form.cart {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.customizer-wc-summary .variations { width: 100%; border: none; margin: 0; }
.customizer-wc-summary .variations td { padding: 4px 0; display: block; width: 100%; }
.customizer-wc-summary .variations select {
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}
.customizer-wc-summary .woocommerce-variation-add-to-cart {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}
.customizer-wc-summary .single_add_to_cart_button {
  background-color: var(--coral) !important;
  color: #fff !important;
  border-radius: 8px !important;
  padding: 12px 24px !important;
  font-weight: 500 !important;
  border: none !important;
}

/* ---------- Tablet / single column ---------- */
@media (max-width: 860px){
  .customizer-layout{
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas:
      "stage"
      "save"
      "rail"
      "models"
      "controls";
    row-gap: 12px;
    justify-items: center;
  }
  :root{
    --stage-h: clamp(292px, 39.5vh, 396px);
    --stage-h: clamp(292px, 39.5dvh, 396px);
  }
  .stage-shell,
  .thumb-rail,
  .save-row,
  .model-block,
  .controls-panel{ width: 100%; max-width: 560px; }

  .thumb-rail{
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .rail-item{ width: 36px; flex: none; }
  .thumb-rail:empty::before{ width: 36px; flex: none; }
  .rail-item:hover .rail-thumb{ transform: none; }

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

/* ---------- Phone ---------- */
@media (max-width: 600px){
  :root{
    --stage-h: clamp(268px, 37vh, 340px);
    --stage-h: clamp(268px, 37dvh, 340px);
  }
  .case-customizer-wrap{ padding: 14px 12px 32px; }
  .controls-panel{ padding: 12px; }
  .case-customizer-wrap h1.product-title{ font-size: 20px; margin: 0 0 12px; }
  .stage-shell{ border-radius: 16px; }
  .stage-shell::before{ width:170px; height:220px; top:-70px; left:-50px; }
  .stage-shell::after { width:130px; height:170px; bottom:-70px; right:-30px; }
  .canvas-holder{ filter: drop-shadow(0 12px 18px rgba(30,30,25,.14)); }
  .placeholder{ padding: 0 20px; }

  .block{ padding: 12px; border-radius: 12px; }
  .save-row{ padding: 12px; border-radius: 12px; }
  .model-grid{ grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .model-card{ padding: 8px 4px; gap: 4px; min-height: 56px; justify-content: center; }
  .model-chip{ width: 14px; height: 24px; }
  .model-name{ font-size: 10px; line-height: 1.2; }
  .tab-btn{ padding: 11px 8px; }
  .preset-grid{ --preset-cols: 4; }
  .preset-more{ flex-direction: column; align-items: stretch; gap: 8px; }
  .preset-count{ text-align: center; }
  .view-more-btn{ width: 100%; padding: 11px 16px; }
  .upload-drop{ padding: 18px 14px; }
  .preset-swatch:hover, .design-tile:hover{ transform: none; }

  /* Modal becomes a bottom sheet */
  .modal-backdrop{ padding: 0; align-items: flex-end; }
  .modal{
    width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: 16px 16px 0 0;
  }
  .modal-head{ padding: 14px 16px; }
  .modal-head h2{ font-size: 18px; }
  .modal-close{ font-size: 30px; width: 34px; height: 34px; }
  .modal-filters{ padding: 10px 16px; }
  .filter-btn{ padding: 9px 14px; }
  .modal-body{ padding: 14px 16px; min-height: 0; }
  .design-grid{ grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .design-tile .tile-name{ opacity: 1; font-size: 8px; }
  .modal-foot{ padding: 10px 16px; flex-wrap: wrap; gap: 8px; }
  .page-btn{ min-width: 34px; height: 34px; }

  /* Woo form */
  .customizer-wc-summary .variations select,
  .customizer-wc-summary .quantity input{
    font-size: 16px;
    min-height: 44px;
  }
  .customizer-wc-summary .woocommerce-variation-add-to-cart{ flex-wrap: wrap; }
  .customizer-wc-summary .single_add_to_cart_button{
    flex: 1 1 100%;
    width: 100%;
    min-height: 48px;
    padding: 14px 20px !important;
  }
}
