/* File: /css/listing-editor.css */
/* ===========================================================
   LISTING EDITOR – simple, powerful, responsive modal
   Polished header actions (Delete in header only when editing),
   cleaner spacing, better dark mode, and accessible focus states.
   =========================================================== */

/* --- Base tokens (safe fallbacks) --- */
:root {
  --clr-surface: #ffffff;
  --clr-bg: #f7f8fb;
  --clr-text: #0f172a;
  --clr-muted: #6b7280;
  --clr-border: #e5e7eb;
  --clr-hover: #eef2f7;
  --clr-accent: #2563eb;
  --clr-danger: #dc2626;

  --radius-md: 12px;
  --radius-sm: 8px;

  --shadow-lg: 0 12px 36px rgba(2, 6, 23, .20);
  --shadow-sticky: 0 6px 16px rgba(2, 6, 23, .08);
}

/* === MODAL BACKDROP === */
.listing-editor::backdrop {
  background: rgba(2, 6, 23, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

/* === MAIN MODAL CONTAINER === */
.listing-editor {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  width: min(760px, 94vw);
  max-height: 94vh; /* cap height so content can scroll */

  /* Mobile-safe dynamic viewport height */
  @supports (height: 100dvh) {
    max-height: 94dvh;
  }

  margin: auto;
  padding: 0;
  box-shadow: var(--shadow-lg);
  overflow: hidden;         /* keep outer shell tidy */
  display: flex;
  flex-direction: column;   /* header/actions fixed, form scrolls */
  overscroll-behavior: contain; /* stop background scroll chaining */
}

/* Improve default dialog spacing on tiny phones */
@media (max-width: 420px) {
  .listing-editor {
    width: min(760px, 96vw);
    border-radius: 14px;
  }
}

/* === FORM WRAPPER (scroll container) === */
.le-form {
  padding: 1.25rem;
  color: var(--clr-text);
  flex: 1 1 auto;
  overflow: auto;   /* inner scroll area */
  min-height: 0;    /* required for flex children to allow scroll */
  -webkit-overflow-scrolling: touch; /* smooth iOS scroll */
}

/* Reduce padding on very small screens to fit more */
@media (max-width: 480px) {
  .le-form { padding: 0.9rem; }
}

/* === HEADER (sticky) === */
.le-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 0 0.75rem;
  margin: 0 0 0.5rem;
  border-bottom: 1px solid var(--clr-border);
  background: var(--clr-surface);
  position: sticky;
  top: 0;
  z-index: 3;
}

.le-head h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .2px;
}

.le-head-actions {
  display: inline-flex;
  gap: .4rem;
  align-items: center;
}

/* === ICON BUTTONS === */
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--clr-border);
  background: var(--clr-bg);
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, color .15s;
}

.icon-btn:hover {
  background: var(--clr-hover);
  border-color: var(--clr-accent);
}

.icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
  border-color: var(--clr-accent);
}

/* === GRID LAYOUT === */
.le-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 0.75rem 0 1rem;
  min-width: 0; /* prevent overflow from long content */
}

@media (max-width: 700px) {
  .le-grid { grid-template-columns: 1fr; }
}

/* === FORM FIELDS === */
.le-form label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-weight: 600;
  min-width: 0; /* allow inputs to shrink */
}

.le-form input,
.le-form select,
.le-form textarea {
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--clr-border);
  border-radius: 10px;
  background: var(--clr-bg);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  font-size: 16px; /* avoid iOS zoom */
  min-width: 0;
}

.le-form input::placeholder,
.le-form textarea::placeholder { color: #9aa3af; }

.le-form input:focus,
.le-form select:focus,
.le-form textarea:focus {
  border-color: var(--clr-accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
  outline: none;
  background: #fff;
}

.le-form textarea {
  resize: vertical;
  min-height: 120px;
}

.le-checkbox {
  flex-direction: row !important;
  align-items: center;
  gap: 0.6rem !important;
  font-weight: 600;
}

.req { color: var(--clr-accent); }

/* === FILE UPLOADER === */
.le-uploader {
  border: 1px dashed var(--clr-border);
  border-radius: 12px;
  padding: 0.9rem;
  margin-top: 0.5rem;
  background: linear-gradient(180deg, #fafbfd, #f6f8fb);
}

.le-uploader legend {
  padding: 0 0.25rem;
  font-weight: 800;
  letter-spacing: .2px;
}

.le-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--clr-border);
  border-radius: 12px;
  min-height: 140px;
  background: var(--clr-surface);
  position: relative;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  outline: none;
}

.le-drop:hover {
  background: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.02) inset;
}

.le-drop.over,
.le-drop:focus-visible {
  border-color: var(--clr-accent);
  background: rgba(37, 99, 235, 0.05);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.le-drop__hint {
  text-align: center;
  color: var(--clr-muted);
  padding: 0.25rem 0.5rem;
  font-weight: 500;
}

.le-file {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* === PREVIEW GALLERY === */
.le-previews {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.6rem;
}

@media (max-width: 520px) {
  .le-previews {
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 0.5rem;
  }
}

.le-thumb {
  position: relative;
  border: 1px solid var(--clr-border);
  border-radius: 10px;
  overflow: hidden;
  background: #f1f5f9;
  aspect-ratio: 1 / 1; /* guarantees square cells */
}

.le-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.le-thumb .le-remove {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--clr-border);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.le-thumb .le-remove:hover { transform: scale(1.05); }
.le-thumb .le-remove:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(37,99,235,.3);
}

/* === ERRORS === */
.le-errors {
  color: var(--clr-danger);
  margin-top: 0.6rem;
  min-height: 1.25rem;
  font-weight: 700;
}

/* === ACTIONS (sticky footer) === */
.le-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  padding-bottom: max(0.25rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--clr-border);
  background: var(--clr-surface);
  position: sticky;
  bottom: 0;
  z-index: 3;
  box-shadow: 0 -2px 8px rgba(0,0,0,.03);
}

.le-spacer { flex: 1; }

/* === BUSY STATE === */
#leSubmit.is-busy {
  opacity: 0.7;
  pointer-events: none;
}

/* === HEADER DELETE (ghost button) === */
.btn.btn--ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--clr-muted);
  padding: 0.35rem 0.55rem;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  line-height: 1;
  transition: color .15s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.btn.btn--ghost:hover {
  background: var(--clr-hover);
  border-color: var(--clr-border);
  color: #111827;
}

.btn.btn--danger.btn--ghost {
  color: var(--clr-danger);
}

.btn.btn--danger.btn--ghost:hover {
  background: rgba(220, 38, 38, 0.06);
  border-color: rgba(220, 38, 38, 0.2);
  color: var(--clr-danger);
}

/* Hide text on very small screens to keep header compact */
@media (max-width: 420px) {
  .btn.btn--ghost .btn-text { display: none; }
}

/* === Small accessibility niceties === */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* === Dark mode support (optional but nice) === */
@media (prefers-color-scheme: dark) {
  :root {
    --clr-surface: #0b0f14;
    --clr-bg: #0f141a;
    --clr-text: #e8eef6;
    --clr-muted: #98a4b3;
    --clr-border: #1f2732;
    --clr-hover: #131a22;
    --clr-accent: #5ca3ff;
    --clr-danger: #f97373;
    --shadow-lg: 0 14px 40px rgba(0,0,0,.55);
    --shadow-sticky: 0 6px 16px rgba(0,0,0,.35);
  }
  .listing-editor { border-color: var(--clr-border); }
  .le-head,
  .le-actions { box-shadow: var(--shadow-sticky); }
  .le-drop { background: #0b0f14; }
  .le-thumb { background: #0e1319; }
  .le-thumb .le-remove { background: rgba(20, 26, 34, 0.92); color: var(--clr-text); }
  .btn.btn--ghost:hover { color: #e8eef6; }
}
/* Ensure dialog is totally hidden unless open */
dialog.listing-editor:not([open]) {
  display: none !important;
}
/* ===========================================================
   Required Field Titles — underline only the label text
   =========================================================== */

/* Hide all asterisks/req markers */
.req {
  display: none !important;
}

/* Underline only the label's title text for required fields */
.le-form label[for][required],
.le-form label > .label-head[required] {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 2px;
  text-decoration-color: var(--clr-accent);
}



/* Dark mode */
@media (prefers-color-scheme: dark) {
  .le-form label[for][required],
  .le-form label:has(> input[required]),
  .le-form label:has(> select[required]),
  .le-form label:has(> textarea[required]) {
    text-decoration-color: var(--clr-accent);
  }
}
/* ===========================================
   Contact for Price — inline switch + layout
   (works with existing markup)
   =========================================== */

/* Wrap price + toggle on one row; help on second row */
#lePriceWrap.le-price-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: .75rem .75rem;
}
#lePriceWrap .le-help {
  grid-column: 1 / -1;
  margin-top: .25rem;
}

/* Make the toggle look like a pill switch chip */
#lePriceWrap .le-checkbox {
  border: 1px solid var(--clr-border);
  background: var(--clr-surface);
  padding: .5rem .6rem;
  border-radius: 12px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(0,0,0,.02) inset;
  transition: background .15s, border-color .15s, box-shadow .15s;
  cursor: pointer;
}

/* Hover/focus feedback for the whole chip */
#lePriceWrap .le-checkbox:hover {
  background: var(--clr-hover);
  border-color: var(--clr-accent);
}
#lePriceWrap .le-checkbox:has(input:focus-visible) {
  box-shadow: 0 0 0 3px rgba(37,99,235,.18);
  border-color: var(--clr-accent);
}

/* Visually style the checkbox as a switch */
#lePriceWrap .le-checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--clr-border);
  border: 1px solid var(--clr-border);
  position: relative;
  outline: none;
  flex: 0 0 auto;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
#lePriceWrap .le-checkbox input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
  transition: transform .18s ease;
}
#lePriceWrap .le-checkbox input[type="checkbox"]:checked {
  background: var(--clr-accent);
  border-color: var(--clr-accent);
}
#lePriceWrap .le-checkbox input[type="checkbox"]:checked::after {
  transform: translateX(18px);
}

/* Better disabled styling for price input when toggle is on */
#priceInput.is-disabled,
#priceInput:disabled {
  background: repeating-linear-gradient(
      -45deg,
      #f3f4f6,
      #f3f4f6 8px,
      #eef2f7 8px,
      #eef2f7 16px
    );
  color: #9aa3af;
  border-color: var(--clr-border);
}
#priceInput.is-disabled::placeholder { color: #b6beca; }

/* Tighten label of price for visual alignment */
#lePriceWrap label[for="priceInput"] {
  margin: 0;
}

/* Small screens: stack neatly */
@media (max-width: 520px) {
  #lePriceWrap.le-price-wrap {
    grid-template-columns: 1fr 1fr;
  }
}
@media (max-width: 420px) {
  #lePriceWrap.le-price-wrap {
    grid-template-columns: 1fr;
  }
  #lePriceWrap .le-checkbox {
    justify-content: space-between;
  }
}

/* Dark mode polish */
@media (prefers-color-scheme: dark) {
  #lePriceWrap .le-checkbox {
    background: var(--clr-bg);
    border-color: var(--clr-border);
  }
  #lePriceWrap .le-checkbox:hover {
    background: var(--clr-hover);
  }
  #priceInput.is-disabled,
  #priceInput:disabled {
    background: repeating-linear-gradient(
      -45deg,
      #0f141a,
      #0f141a 8px,
      #131a22 8px,
      #131a22 16px
    );
    color: #98a4b3;
  }
}

/* Reduced motion respect */
@media (prefers-reduced-motion: reduce) {
  #lePriceWrap .le-checkbox input[type="checkbox"]::after {
    transition: none;
  }
}


/* Hide "(up to X)" in uploader legend */
.le-uploader .le-legend-sub {
  display: none !important;
}
/* Visually hide legend but keep it accessible */
.le-uploader legend {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(100%);
  overflow: hidden; white-space: nowrap;
}
