/* =============================================================================
   SMJ Marketplace Pro — Photo Upload v2.0
   Modern card/grid UI inspired by OLX / CarDekho.
   Zero inline styles. All sizing via CSS custom properties.
   ============================================================================= */

/* ── Design tokens (inherit from :root if set, fallback otherwise) ────────── */
.smj-upload-zone {
  --upload-radius    : 14px;
  --upload-border    : #d1d5db;
  --upload-border-act: var(--smj-primary, #1a6fb5);
  --upload-bg        : #fafafa;
  --upload-bg-drag   : #eff6ff;
  --upload-text      : #6b7280;
  --upload-thumb-size: 100px;
  --upload-gap       : 10px;
  --upload-cover-bg  : var(--smj-primary, #1a6fb5);
}

/* ── Upload zone ─────────────────────────────────────────────────────────── */
.smj-upload-zone {
  position     : relative;
  border       : 2px dashed var(--upload-border);
  border-radius: var(--upload-radius);
  background   : var(--upload-bg);
  padding      : 20px 16px 16px;
  cursor       : pointer;
  transition   : border-color .18s, background .18s;
  user-select  : none;
  box-sizing   : border-box;
}
.smj-upload-zone:hover,
.smj-upload-zone:focus-within {
  border-color: var(--upload-border-act);
  background  : var(--upload-bg-drag);
}
.smj-upload-zone--drag {
  border-color: var(--upload-border-act);
  background  : var(--upload-bg-drag);
  box-shadow  : 0 0 0 4px rgba(26,111,181,.12);
}

/* ── Empty-state hint (icon + text) ─────────────────────────────────────── */
.smj-upload-hint {
  display        : flex;
  flex-direction : column;
  align-items    : center;
  gap            : 8px;
  padding        : 12px 0 4px;
  pointer-events : none;
  transition     : opacity .18s;
}
.smj-upload-hint--hidden,
.smj-hidden { display: none; }

.smj-upload-hint__icon {
  font-size  : 36px;
  line-height: 1;
}
.smj-upload-hint__title {
  font-size  : 15px;
  font-weight: 700;
  color      : var(--smj-text, #1f2937);
  margin     : 0;
}
.smj-upload-hint__sub {
  font-size  : 13px;
  color      : var(--upload-text);
  margin     : 0;
  text-align : center;
  line-height: 1.5;
}

/* ── Action buttons row ──────────────────────────────────────────────────── */
.smj-upload-actions {
  display        : flex;
  gap            : 8px;
  justify-content: center;
  flex-wrap      : wrap;
  margin-top     : 14px;
  pointer-events : auto;
}
.smj-upload-btn {
  display     : inline-flex;
  align-items : center;
  gap         : 6px;
  padding     : 8px 18px;
  border-radius: 8px;
  font-size   : 13px;
  font-weight : 600;
  cursor      : pointer;
  transition  : background .15s, transform .1s, box-shadow .15s;
  border      : 1.5px solid var(--smj-primary, #1a6fb5);
  background  : var(--smj-primary, #1a6fb5);
  color       : #fff;
  text-decoration: none;
  white-space : nowrap;
}
.smj-upload-btn:hover {
  background : var(--smj-primary-dk, #135091);
  border-color: var(--smj-primary-dk, #135091);
  transform  : translateY(-1px);
  box-shadow : 0 3px 10px rgba(26,111,181,.25);
  color      : #fff;
  text-decoration: none;
}
.smj-upload-btn--outline {
  background: #fff;
  color     : var(--smj-primary, #1a6fb5);
}
.smj-upload-btn--outline:hover {
  background: var(--smj-primary-alpha-10, rgba(26,111,181,.08));
  color     : var(--smj-primary, #1a6fb5);
}

/* ── Visually hidden real inputs ─────────────────────────────────────────── */
.smj-input-hidden {
  position: absolute;
  width   : 1px; height: 1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
  padding: 0; margin: -1px;
}

/* ── Photo grid (new + existing) ─────────────────────────────────────────── */
.smj-upload-grid {
  display              : grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--upload-thumb-size), 1fr));
  gap                  : var(--upload-gap);
  margin-top           : 14px;
}
.smj-upload-grid:empty { display: none; }

/* ── Preview card (new upload) ───────────────────────────────────────────── */
.smj-preview-card {
  position     : relative;
  border-radius: 10px;
  overflow     : hidden;
  aspect-ratio : 1;
  background   : #f3f4f6;
  border       : 2px solid transparent;
  transition   : border-color .18s, transform .15s;
}
.smj-preview-card--cover {
  border-color: var(--upload-cover-bg);
  box-shadow  : 0 0 0 1px var(--upload-cover-bg);
}
.smj-preview-card:hover { transform: scale(1.02); }

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

/* Cover badge */
.smj-cover-badge {
  position    : absolute;
  bottom      : 4px;
  left        : 4px;
  background  : var(--upload-cover-bg);
  color       : #fff;
  font-size   : 10px;
  font-weight : 700;
  padding     : 2px 6px;
  border-radius: 4px;
  letter-spacing: .03em;
  pointer-events: none;
}

/* Remove (×) button */
.smj-preview-remove {
  position    : absolute;
  top         : 4px;
  right       : 4px;
  width       : 22px; height: 22px;
  border-radius: 50%;
  background  : rgba(0,0,0,.55);
  color       : #fff;
  border      : none;
  cursor      : pointer;
  display     : flex;
  align-items : center;
  justify-content: center;
  opacity     : 0;
  transition  : opacity .15s, background .15s;
  padding     : 0;
  line-height : 1;
}
.smj-preview-card:hover .smj-preview-remove,
.smj-preview-remove:focus { opacity: 1; }
.smj-preview-remove:hover  { background: rgba(220,38,38,.85); }

/* Set cover star button */
.smj-preview-star {
  position    : absolute;
  bottom      : 4px;
  right       : 4px;
  width       : 22px; height: 22px;
  border-radius: 50%;
  background  : rgba(0,0,0,.45);
  color       : #facc15;
  border      : none;
  cursor      : pointer;
  display     : flex;
  align-items : center;
  justify-content: center;
  font-size   : 12px;
  opacity     : 0;
  transition  : opacity .15s, background .15s;
  padding     : 0;
}
.smj-preview-card:hover .smj-preview-star,
.smj-preview-star:focus { opacity: 1; }
.smj-preview-star:hover { background: rgba(0,0,0,.65); }

/* ── Existing image card (edit mode) ─────────────────────────────────────── */
.smj-existing-card {
  position     : relative;
  border-radius: 10px;
  overflow     : hidden;
  aspect-ratio : 1;
  background   : #f3f4f6;
  border       : 2px solid #e5e7eb;
  transition   : transform .15s, opacity .25s;
}
.smj-existing-card--cover {
  border-color: var(--upload-cover-bg);
  box-shadow  : 0 0 0 1px var(--upload-cover-bg);
}
.smj-existing-card:hover { transform: scale(1.02); }

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

.smj-existing-remove {
  position    : absolute;
  top         : 4px;
  right       : 4px;
  width       : 22px; height: 22px;
  border-radius: 50%;
  background  : rgba(0,0,0,.55);
  color       : #fff;
  border      : none;
  cursor      : pointer;
  display     : flex;
  align-items : center;
  justify-content: center;
  opacity     : 0;
  transition  : opacity .15s, background .15s;
  padding     : 0;
  font-size   : 14px;
  font-weight : 700;
  line-height : 1;
}
.smj-existing-card:hover .smj-existing-remove,
.smj-existing-remove:focus { opacity: 1; }
.smj-existing-remove:hover { background: rgba(220,38,38,.85); }

.smj-existing-main-badge {
  position   : absolute;
  bottom     : 4px;
  left       : 4px;
  background : var(--upload-cover-bg);
  color      : #fff;
  font-size  : 10px;
  font-weight: 700;
  padding    : 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

/* Fade-out animation when removing */
.smj-card-removing {
  opacity  : 0;
  transform: scale(.85);
  pointer-events: none;
}

/* ── Progress bar ────────────────────────────────────────────────────────── */
.smj-upload-progress {
  height        : 4px;
  background    : #e5e7eb;
  border-radius : 2px;
  margin-top    : 12px;
  overflow      : hidden;
  display       : none;
}
.smj-upload-progress--visible { display: block; }

.smj-upload-progress-fill {
  height          : 100%;
  width           : 0%;
  background      : var(--smj-primary, #1a6fb5);
  border-radius   : 2px;
  transition      : width .2s ease;
}

.smj-upload-progress-text {
  font-size  : 11px;
  color      : var(--smj-muted, #6b7280);
  text-align : right;
  margin-top : 2px;
  display    : none;
}
.smj-upload-progress--visible + .smj-upload-progress-text { display: block; }

/* ── Error list ──────────────────────────────────────────────────────────── */
.smj-upload-errors {
  display    : none;
  list-style : none;
  margin     : 10px 0 0;
  padding    : 10px 14px;
  background : #fef2f2;
  border     : 1px solid #fca5a5;
  border-radius: 8px;
  font-size  : 13px;
  color      : #b91c1c;
  gap        : 4px;
}
.smj-upload-errors--visible { display: flex; flex-direction: column; }
.smj-upload-errors li::before { content: '⚠ '; }

/* ── Counter ─────────────────────────────────────────────────────────────── */
.smj-upload-meta {
  display    : flex;
  align-items: center;
  justify-content: space-between;
  margin-top : 10px;
  font-size  : 12px;
  color      : var(--smj-muted, #6b7280);
}
.smj-upload-count { font-weight: 700; }
.smj-count--warn  { color: #d97706; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .smj-upload-zone { --upload-thumb-size: 80px; --upload-gap: 8px; }
  .smj-upload-hint__title { font-size: 14px; }
  .smj-upload-btn { padding: 7px 14px; font-size: 12px; }
}
@media (max-width: 360px) {
  .smj-upload-zone { --upload-thumb-size: 72px; }
}

/* ── Validation error state (applied by smj-form-validation.js) ──────────── */
.smj-upload-zone.smj-err {
  border-color: var(--smj-error, #ef4444);
  background  : var(--smj-error-bg, #fff8f8);
  box-shadow  : 0 0 0 3px rgba(239, 68, 68, .12);
}

/* =============================================================================
   SMJ Upload v3.0 — Additions
   ============================================================================= */

/* ── Loading state overlay ──────────────────────────────────────────────── */
.smj-upload-zone--loading {
  pointer-events: none;
  opacity: .75;
}

.smj-upload-spinner {
  position       : absolute;
  inset          : 0;
  display        : flex;
  align-items    : center;
  justify-content: center;
  background     : rgba(255,255,255,.55);
  border-radius  : var(--upload-radius);
  z-index        : 10;
}

.smj-spinner-svg {
  width    : 40px;
  height   : 40px;
  animation: smj-spin 1s linear infinite;
}
@keyframes smj-spin { to { transform: rotate(360deg); } }

.smj-spinner-track { stroke: #e5e7eb; }
.smj-spinner-head  { stroke: var(--smj-primary, #1a6fb5); }

/* ── Drag-to-reorder states ─────────────────────────────────────────────── */
.smj-preview-card[draggable="true"] { cursor: grab; }
.smj-preview-card[draggable="true"]:active { cursor: grabbing; }

.smj-drag-src {
  opacity  : 0.45;
  transform: scale(0.94);
  transition: opacity .15s, transform .15s;
}

.smj-drag-over {
  outline       : 2.5px dashed var(--upload-cover-bg, #1a6fb5);
  outline-offset: 2px;
  transform     : scale(1.04);
}

/* ── Star button — always visible when hovered, pulse on cover ─────────── */
.smj-preview-star--active {
  opacity    : 1 !important;
  color      : #fbbf24 !important;
  background : rgba(0,0,0,.55) !important;
}

/* ── Validation error on upload zone ────────────────────────────────────── */
.smj-upload-zone.smj-err {
  border-color: #ef4444 !important;
  background  : #fff8f8 !important;
  box-shadow  : 0 0 0 3px rgba(239,68,68,.12) !important;
  animation   : smj-shake .32s ease;
}

@keyframes smj-shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-4px); }
  40%      { transform: translateX(4px); }
  60%      { transform: translateX(-3px); }
  80%      { transform: translateX(3px); }
}

/* =============================================================================
   SMJ Upload v4.0 — Status bar + Submit guard
   ============================================================================= */

/* ── Prominent upload status bar ─────────────────────────────────────────── */
.smj-status-bar {
  margin-top    : 12px;
  padding       : 10px 14px;
  border-radius : 10px;
  background    : #f8fafc;
  border        : 1px solid #e2e8f0;
  transition    : background .2s, border-color .2s;
  font-size     : 13px;
}

/* Track + animated fill */
.smj-status-bar__track {
  height        : 6px;
  background    : #e5e7eb;
  border-radius : 999px;
  overflow      : hidden;
  margin-bottom : 8px;
}
.smj-status-bar__fill {
  height        : 100%;
  width         : 0%;
  border-radius : 999px;
  background    : var(--smj-primary, #1a6fb5);
  transition    : width .25s ease, background .25s;
}

/* Row: icon + label + percentage */
.smj-status-bar__row {
  display        : flex;
  align-items    : center;
  gap            : 7px;
}
.smj-status-bar__icon  { font-size: 15px; line-height: 1; flex-shrink: 0; }
.smj-status-bar__label {
  flex        : 1;
  font-weight : 500;
  color       : #374151;
  line-height : 1.4;
}
.smj-status-bar__pct {
  font-weight : 700;
  color       : var(--smj-primary, #1a6fb5);
  font-size   : 12px;
  min-width   : 32px;
  text-align  : right;
}

/* ── State variants ─────────────────────────────────────────────────── */
/* Uploading — blue animated fill */
.smj-status-bar--uploading {
  background  : #eff6ff;
  border-color: #bfdbfe;
}
.smj-status-bar--uploading .smj-status-bar__fill {
  background  : var(--smj-primary, #1a6fb5);
  /* Animated shimmer while uploading */
  background  : linear-gradient(90deg,
    var(--smj-primary, #1a6fb5) 0%,
    #60a5fa 50%,
    var(--smj-primary, #1a6fb5) 100%);
  background-size: 200% 100%;
  animation   : smj-shimmer 1.4s linear infinite;
}
@keyframes smj-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.smj-status-bar--uploading .smj-status-bar__label { color: #1e40af; }

/* Done — green */
.smj-status-bar--done {
  background  : #f0fdf4;
  border-color: #bbf7d0;
}
.smj-status-bar--done .smj-status-bar__fill {
  background  : #16a34a;
  width       : 100% !important;
}
.smj-status-bar--done .smj-status-bar__label { color: #15803d; }

/* Empty — neutral */
.smj-status-bar--empty {
  background  : #f9fafb;
  border-color: #e5e7eb;
}
.smj-status-bar--empty .smj-status-bar__fill { width: 0% !important; }
.smj-status-bar--empty .smj-status-bar__label { color: #9ca3af; }

/* Error — red */
.smj-status-bar--error {
  background  : #fef2f2;
  border-color: #fca5a5;
}
.smj-status-bar--error .smj-status-bar__fill {
  width      : 100% !important;
  background : #ef4444 !important;
}
.smj-status-bar--error .smj-status-bar__label { color: #b91c1c; }

/* ── Submit button disabled states ───────────────────────────────────────── */
[name="tmp_submit_listing"]:disabled,
[name="tmp_submit_listing"].smj-submit--no-images,
[name="tmp_submit_listing"].smj-submit--uploading {
  opacity        : 0.45 !important;
  pointer-events : none !important;
  cursor         : not-allowed !important;
  /* Preserve the button shape/colour — only dim it */
  filter         : grayscale(20%);
  transform      : none !important;
  box-shadow     : none !important;
}

/* Extra visual cue while upload is in flight */
[name="tmp_submit_listing"].smj-submit--uploading {
  position: relative;
  overflow: hidden;
}
[name="tmp_submit_listing"].smj-submit--uploading::after {
  content   : '';
  position  : absolute;
  inset     : 0;
  background: linear-gradient(90deg,
    transparent 0%, rgba(255,255,255,.18) 50%, transparent 100%);
  background-size: 200% 100%;
  animation : smj-shimmer 1.4s linear infinite;
  border-radius: inherit;
}

/* ── Tooltip under disabled submit (optional enhancement) ────────────────── */
.smj-submit-tooltip {
  display      : block;
  text-align   : center;
  margin-top   : 8px;
  font-size    : 12.5px;
  color        : #9ca3af;
  font-weight  : 500;
  min-height   : 18px;
  transition   : color .2s;
}
