/* 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;
}


/* ===========================================================
   DARK MODE — complete, polished, and robust
   - Works with OS dark mode AND manual toggles:
     • <html class="dark"> … or …
     • <html data-theme="dark"> … or …
     • <dialog class="listing-editor is-dark"> (scoped toggle)
   - Adds color-scheme, scrollbars, selection, autofill, focus rings
   - Leaves light mode untouched
   =========================================================== */

/* Smooth theme switch just inside the component (respects reduced motion below) */
.listing-editor, .listing-editor * {
  transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
}

/* ---------- 1) Manual dark-mode variable overrides (scoped) ---------- */
:is(.dark, [data-theme="dark"]) .listing-editor,
.listing-editor.is-dark {
  /* Token set tuned for deep contrast and soft surfaces */
  --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);

  /* Native form widgets adopt dark look */
  color-scheme: dark;
}

/* ---------- 2) Component-level polish in dark contexts (manual toggles) ---------- */
:is(.dark, [data-theme="dark"]) .listing-editor,
.listing-editor.is-dark {
  border-color: var(--clr-border);
  background: var(--clr-surface);
  box-shadow: var(--shadow-lg);
}

/* Sticky header/footer: subtle elevation & gradient */
:is(.dark, [data-theme="dark"]) .listing-editor .le-head,
.listing-editor.is-dark .le-head {
  background: linear-gradient(180deg, #0d1218, #0b0f14);
  border-bottom-color: var(--clr-border);
  box-shadow: var(--shadow-sticky);
}
:is(.dark, [data-theme="dark"]) .listing-editor .le-actions,
.listing-editor.is-dark .le-actions {
  background: linear-gradient(180deg, #0b0f14, #0d1218);
  border-top-color: var(--clr-border);
  box-shadow: var(--shadow-sticky);
}

/* Form text & placeholders */
:is(.dark, [data-theme="dark"]) .listing-editor .le-form { color: var(--clr-text); }
:is(.dark, [data-theme="dark"]) .listing-editor .le-form input::placeholder,
:is(.dark, [data-theme="dark"]) .listing-editor .le-form textarea::placeholder { color: #7e8b9b; }

/* Inputs, selects, textareas */
:is(.dark, [data-theme="dark"]) .listing-editor .le-form input,
:is(.dark, [data-theme="dark"]) .listing-editor .le-form select,
:is(.dark, [data-theme="dark"]) .listing-editor .le-form textarea,
.listing-editor.is-dark .le-form input,
.listing-editor.is-dark .le-form select,
.listing-editor.is-dark .le-form textarea {
  background: var(--clr-bg);
  border-color: var(--clr-border);
  color: var(--clr-text);
}
:is(.dark, [data-theme="dark"]) .listing-editor .le-form input:focus,
:is(.dark, [data-theme="dark"]) .listing-editor .le-form select:focus,
:is(.dark, [data-theme="dark"]) .listing-editor .le-form textarea:focus,
.listing-editor.is-dark .le-form input:focus,
.listing-editor.is-dark .le-form select:focus,
.listing-editor.is-dark .le-form textarea:focus {
  border-color: var(--clr-accent);
  background: #0f141a;
  box-shadow: 0 0 0 2px rgba(92, 163, 255, 0.18);
  outline: none;
}

/* Icon buttons & SVGs */
:is(.dark, [data-theme="dark"]) .listing-editor .icon-btn,
.listing-editor.is-dark .icon-btn {
  background: var(--clr-bg);
  border-color: var(--clr-border);
  color: var(--clr-text);
}
:is(.dark, [data-theme="dark"]) .listing-editor .icon-btn:hover,
.listing-editor.is-dark .icon-btn:hover {
  background: var(--clr-hover);
  border-color: var(--clr-accent);
}
:is(.dark, [data-theme="dark"]) .listing-editor .icon-btn svg,
.listing-editor.is-dark .icon-btn svg {
  stroke: currentColor;
  fill: none;
}

/* Ghost buttons (e.g., Delete) */
:is(.dark, [data-theme="dark"]) .listing-editor .btn.btn--ghost,
.listing-editor.is-dark .btn.btn--ghost {
  color: var(--clr-muted);
}
:is(.dark, [data-theme="dark"]) .listing-editor .btn.btn--ghost:hover,
.listing-editor.is-dark .btn.btn--ghost:hover {
  color: var(--clr-text);
  background: var(--clr-hover);
  border-color: var(--clr-border);
}
:is(.dark, [data-theme="dark"]) .listing-editor .btn.btn--danger.btn--ghost:hover,
.listing-editor.is-dark .btn.btn--danger.btn--ghost:hover {
  background: rgba(249, 115, 115, 0.08);
  border-color: rgba(249, 115, 115, 0.28);
}

/* Uploader + dropzone */
:is(.dark, [data-theme="dark"]) .listing-editor .le-uploader,
.listing-editor.is-dark .le-uploader {
  background: linear-gradient(180deg, #0f141a, #0b0f14);
  border-color: var(--clr-border);
}
:is(.dark, [data-theme="dark"]) .listing-editor .le-drop,
.listing-editor.is-dark .le-drop {
  background: var(--clr-surface);
  border-color: var(--clr-border);
}
:is(.dark, [data-theme="dark"]) .listing-editor .le-drop:hover,
.listing-editor.is-dark .le-drop:hover {
  background: #101720;
}
:is(.dark, [data-theme="dark"]) .listing-editor .le-drop.over,
:is(.dark, [data-theme="dark"]) .listing-editor .le-drop:focus-visible,
.listing-editor.is-dark .le-drop.over,
.listing-editor.is-dark .le-drop:focus-visible {
  border-color: var(--clr-accent);
  background: rgba(92, 163, 255, 0.07);
  box-shadow: 0 0 0 3px rgba(92, 163, 255, 0.15);
}
:is(.dark, [data-theme="dark"]) .listing-editor .le-drop__hint,
.listing-editor.is-dark .le-drop__hint { color: var(--clr-muted); }

/* Thumbnails */
:is(.dark, [data-theme="dark"]) .listing-editor .le-thumb,
.listing-editor.is-dark .le-thumb { background: #0e1319; border-color: var(--clr-border); }
:is(.dark, [data-theme="dark"]) .listing-editor .le-thumb .le-remove,
.listing-editor.is-dark .le-thumb .le-remove {
  background: rgba(20, 26, 34, 0.94);
  border-color: var(--clr-border);
  color: var(--clr-text);
  backdrop-filter: saturate(120%) blur(2px);
}

/* Errors */
:is(.dark, [data-theme="dark"]) .listing-editor .le-errors,
.listing-editor.is-dark .le-errors {
  color: var(--clr-danger);
  text-shadow: 0 0 0 transparent; /* crisp text on dark */
}

/* Price toggle (enhanced dark) */
:is(.dark, [data-theme="dark"]) #lePriceWrap .le-checkbox,
.listing-editor.is-dark #lePriceWrap .le-checkbox {
  background: var(--clr-bg);
  border-color: var(--clr-border);
}
:is(.dark, [data-theme="dark"]) #lePriceWrap .le-checkbox:hover,
.listing-editor.is-dark #lePriceWrap .le-checkbox:hover {
  background: var(--clr-hover);
}
:is(.dark, [data-theme="dark"]) #lePriceWrap .le-checkbox input[type="checkbox"],
.listing-editor.is-dark #lePriceWrap .le-checkbox input[type="checkbox"] {
  background: #212b38;
  border-color: #243142;
}
:is(.dark, [data-theme="dark"]) #lePriceWrap .le-checkbox input[type="checkbox"]::after,
.listing-editor.is-dark #lePriceWrap .le-checkbox input[type="checkbox"]::after {
  background: #e8eef6;
  box-shadow: 0 1px 2px rgba(0,0,0,.35);
}

/* Selection color inside the dialog */
:is(.dark, [data-theme="dark"]) .listing-editor ::selection,
.listing-editor.is-dark ::selection {
  background: rgba(92, 163, 255, 0.28);
  color: var(--clr-text);
}

/* Scrollbars (Firefox + WebKit) scoped to the editor */
:is(.dark, [data-theme="dark"]) .listing-editor,
.listing-editor.is-dark {
  scrollbar-color: #2c3949 #0f141a; /* thumb, track */
}
:is(.dark, [data-theme="dark"]) .listing-editor::-webkit-scrollbar,
.listing-editor.is-dark::-webkit-scrollbar { width: 12px; height: 12px; }
:is(.dark, [data-theme="dark"]) .listing-editor::-webkit-scrollbar-track,
.listing-editor.is-dark::-webkit-scrollbar-track { background: #0f141a; }
:is(.dark, [data-theme="dark"]) .listing-editor::-webkit-scrollbar-thumb,
.listing-editor.is-dark::-webkit-scrollbar-thumb {
  background: #2c3949;
  border: 3px solid #0f141a;
  border-radius: 999px;
}
:is(.dark, [data-theme="dark"]) .listing-editor::-webkit-scrollbar-thumb:hover,
.listing-editor.is-dark::-webkit-scrollbar-thumb:hover { background: #344559; }

/* Autofill on dark */
:is(.dark, [data-theme="dark"]) .listing-editor input:-webkit-autofill,
:is(.dark, [data-theme="dark"]) .listing-editor select:-webkit-autofill,
:is(.dark, [data-theme="dark"]) .listing-editor textarea:-webkit-autofill,
.listing-editor.is-dark input:-webkit-autofill,
.listing-editor.is-dark select:-webkit-autofill,
.listing-editor.is-dark textarea:-webkit-autofill {
  -webkit-text-fill-color: var(--clr-text);
  caret-color: var(--clr-text);
  transition: background-color 9999s ease-in-out 0s; /* prevent flash */
  box-shadow: 0 0 0 1000px #0f141a inset;
  border-color: var(--clr-border);
}

/* Stronger, accessible focus ring in dark */
:is(.dark, [data-theme="dark"]) .listing-editor :focus-visible,
.listing-editor.is-dark :focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(92, 163, 255, 0.28) !important;
  border-color: var(--clr-accent) !important;
}

/* Busy button dim remains readable on dark */
:is(.dark, [data-theme="dark"]) .listing-editor #leSubmit.is-busy,
.listing-editor.is-dark #leSubmit.is-busy {
  opacity: .75;
}

/* ---------- 3) Mirror the component polish for OS dark preference ---------- */
@media (prefers-color-scheme: dark) {
  .listing-editor { color-scheme: dark; }

  .listing-editor { border-color: var(--clr-border); background: var(--clr-surface); box-shadow: var(--shadow-lg); }

  .listing-editor .le-head {
    background: linear-gradient(180deg, #0d1218, #0b0f14);
    border-bottom-color: var(--clr-border);
    box-shadow: var(--shadow-sticky);
  }
  .listing-editor .le-actions {
    background: linear-gradient(180deg, #0b0f14, #0d1218);
    border-top-color: var(--clr-border);
    box-shadow: var(--shadow-sticky);
  }

  .listing-editor .le-form { color: var(--clr-text); }
  .listing-editor .le-form input::placeholder,
  .listing-editor .le-form textarea::placeholder { color: #7e8b9b; }

  .listing-editor .le-form input,
  .listing-editor .le-form select,
  .listing-editor .le-form textarea {
    background: var(--clr-bg);
    border-color: var(--clr-border);
    color: var(--clr-text);
  }
  .listing-editor .le-form input:focus,
  .listing-editor .le-form select:focus,
  .listing-editor .le-form textarea:focus {
    border-color: var(--clr-accent);
    background: #0f141a;
    box-shadow: 0 0 0 2px rgba(92, 163, 255, 0.18);
    outline: none;
  }

  .listing-editor .icon-btn {
    background: var(--clr-bg);
    border-color: var(--clr-border);
    color: var(--clr-text);
  }
  .listing-editor .icon-btn:hover {
    background: var(--clr-hover);
    border-color: var(--clr-accent);
  }
  .listing-editor .icon-btn svg { stroke: currentColor; fill: none; }

  .listing-editor .btn.btn--ghost { color: var(--clr-muted); }
  .listing-editor .btn.btn--ghost:hover {
    color: var(--clr-text);
    background: var(--clr-hover);
    border-color: var(--clr-border);
  }
  .listing-editor .btn.btn--danger.btn--ghost:hover {
    background: rgba(249, 115, 115, 0.08);
    border-color: rgba(249, 115, 115, 0.28);
  }

  .listing-editor .le-uploader {
    background: linear-gradient(180deg, #0f141a, #0b0f14);
    border-color: var(--clr-border);
  }
  .listing-editor .le-drop {
    background: var(--clr-surface);
    border-color: var(--clr-border);
  }
  .listing-editor .le-drop:hover { background: #101720; }
  .listing-editor .le-drop.over,
  .listing-editor .le-drop:focus-visible {
    border-color: var(--clr-accent);
    background: rgba(92, 163, 255, 0.07);
    box-shadow: 0 0 0 3px rgba(92, 163, 255, 0.15);
  }
  .listing-editor .le-drop__hint { color: var(--clr-muted); }

  .listing-editor .le-thumb { background: #0e1319; border-color: var(--clr-border); }
  .listing-editor .le-thumb .le-remove {
    background: rgba(20, 26, 34, 0.94);
    border-color: var(--clr-border);
    color: var(--clr-text);
    backdrop-filter: saturate(120%) blur(2px);
  }

  .listing-editor .le-errors { color: var(--clr-danger); text-shadow: 0 0 0 transparent; }

  .listing-editor ::selection { background: rgba(92, 163, 255, 0.28); color: var(--clr-text); }

  .listing-editor { scrollbar-color: #2c3949 #0f141a; }
  .listing-editor::-webkit-scrollbar { width: 12px; height: 12px; }
  .listing-editor::-webkit-scrollbar-track { background: #0f141a; }
  .listing-editor::-webkit-scrollbar-thumb {
    background: #2c3949;
    border: 3px solid #0f141a;
    border-radius: 999px;
  }
  .listing-editor::-webkit-scrollbar-thumb:hover { background: #344559; }

  .listing-editor :focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(92, 163, 255, 0.28) !important;
    border-color: var(--clr-accent) !important;
  }
}

/* ---------- 4) High-contrast & forced-colors safety nets ---------- */
@media (prefers-contrast: more) {
  .listing-editor :focus-visible { box-shadow: 0 0 0 4px rgba(92, 163, 255, 0.45) !important; }
  .listing-editor .le-form input,
  .listing-editor .le-form select,
  .listing-editor .le-form textarea { border-width: 2px; }
}
@media (forced-colors: active) {
  .listing-editor, .listing-editor * {
    forced-color-adjust: auto;
  }
  .listing-editor :focus-visible {
    outline: 2px solid Highlight !important;
    box-shadow: none !important;
  }
}

/* ---------- 5) Respect reduced motion globally for the component ---------- */
@media (prefers-reduced-motion: reduce) {
  .listing-editor, .listing-editor * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
