/* ===== bend.css: ظاهر ابزار خم کردن طرح ===== */
.bd-grid { display: grid; gap: 16px; }
@media (min-width: 860px) {
  .bd-grid { grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); align-items: start; gap: 24px; }
}

/* ---- پیش‌نمایش ---- */
.bd-preview {
  position: sticky;
  top: calc(var(--h-head) + env(safe-area-inset-top, 0px) + 8px);
  z-index: 5;
  background: var(--bg);
  padding-bottom: 4px;
}
@media (min-width: 860px) { .bd-preview { top: calc(var(--h-head) + env(safe-area-inset-top, 0px) + 20px); } }

.bd-stage {
  min-height: 160px;
  display: grid; place-items: center;
  padding: 12px;
  border: 1px solid var(--line); border-radius: 16px;
  background-color: #e9edef;
  background-image:
    linear-gradient(45deg, #d3d9dc 25%, transparent 25%, transparent 75%, #d3d9dc 75%),
    linear-gradient(45deg, #d3d9dc 25%, transparent 25%, transparent 75%, #d3d9dc 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  overflow: hidden;
}
.bd-stage.on-dark {
  background-color: #3a4651;
  background-image:
    linear-gradient(45deg, #2c363f 25%, transparent 25%, transparent 75%, #2c363f 75%),
    linear-gradient(45deg, #2c363f 25%, transparent 25%, transparent 75%, #2c363f 75%);
}
.bd-stage canvas { display: block; max-width: 100%; }
.bd-empty { margin: 0; padding: 12px; text-align: center; font-size: 14px; color: #3d4a52; }
.bd-stage.on-dark .bd-empty { color: #c5cace; }
.bd-meta { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 8px 4px 0; font-size: 13px; color: var(--fg2); min-height: 20px; }
.bd-meta p { margin: 0; }

/* ---- کنترل‌ها ---- */
.bd-controls .field:last-child { margin-bottom: 0; }
.bd-controls fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px 12px 0; margin: 0 0 16px; min-width: 0; }
.bd-controls legend { padding: 0 8px; font-size: 14px; font-weight: 600; color: var(--accent); }
.bd-row { display: grid; gap: 0 12px; }
@media (min-width: 420px) { .bd-row.two { grid-template-columns: 1.4fr 1fr; } }
.bd-controls select {
  width: 100%; min-height: 44px; background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit; font-size: 16px;
}
.bd-controls select:disabled { opacity: .6; }
.bd-controls textarea { min-height: 88px; font-family: var(--font-ui); line-height: 1.7; }
.bd-controls .range-head { display: flex; justify-content: space-between; align-items: baseline; }
.bd-controls output { font-size: 13px; color: var(--fg2); font-variant-numeric: tabular-nums; }
.bd-controls input[type="range"] { width: 100%; min-height: 32px; accent-color: var(--accent); }
.bd-controls input[type="color"] {
  width: 56px; height: 44px; padding: 3px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg label {
  flex: 1 1 0; min-width: 72px; text-align: center; cursor: pointer;
  min-height: 44px; display: grid; place-items: center; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 9999px; background: transparent;
  font-size: 14px; font-weight: 500; color: var(--fg2);
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--badge-bg); color: var(--accent); border-color: var(--accent); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 15px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.check small { display: block; font-size: 12px; color: var(--fg3); }

.bd-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.bd-actions .btn { flex: 1 1 140px; }
.bd-actions .btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }

.bd-result { margin-top: 16px; text-align: center; }
.bd-result img { max-width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.bd-result p { margin: 8px 0 0; font-size: 13px; color: var(--fg2); }

.bd-controls .lbl { font-size: 14px; font-weight: 500; color: var(--fg2); }

@media (min-width: 420px) { .bd-row.eq { grid-template-columns: 1fr 1fr; } }

/* ---- انتخاب فایل ---- */
.bd-drop {
  display: grid; place-items: center; gap: 4px; text-align: center; cursor: pointer;
  min-height: 96px; padding: 16px; border: 2px dashed var(--line); border-radius: 14px;
  color: var(--fg2); font-size: 14px; background: transparent;
}
.bd-drop strong { color: var(--fg); font-size: 15px; }
.bd-drop.over, .bd-drop:focus-visible { border-color: var(--accent); outline: none; background: var(--badge-bg); }
.bd-drop small { color: var(--fg3); font-size: 12px; }
.bd-file { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }

/* ---- نوع خمیدگی ---- */
.bd-modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.bd-modes label {
  display: grid; justify-items: center; align-content: center; gap: 4px; cursor: pointer; text-align: center;
  min-height: 72px; padding: 8px 4px; border: 1px solid var(--line); border-radius: 12px;
  font-size: 12px; color: var(--fg2);
}
.bd-modes input { position: absolute; opacity: 0; pointer-events: none; }
.bd-modes label:has(input:checked) { background: var(--badge-bg); color: var(--accent); border-color: var(--accent); }
.bd-modes label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.bd-modes svg { width: 44px; height: 28px; fill: currentColor; fill-opacity: .25; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }

.bd-amount { display: grid; grid-template-columns: 1fr 88px; gap: 12px; align-items: center; }
.bd-amount input[type="number"] {
  width: 100%; min-height: 44px; background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; font: inherit; font-size: 16px; text-align: center;
}

/* موبایل: ارتفاع پیش‌نمایش محدود تا کنترل‌ها زیر عکس نروند */
@media (max-width: 859px) {
  .bd-stage { max-height: 38vh; max-height: 38dvh; }
  .bd-stage canvas, .bd-stage img { max-height: calc(38dvh - 26px); max-height: calc(38vh - 26px); width: auto; height: auto; object-fit: contain; }
}
