/* ============================================================================
 * product-edit-base.css — Product Editor redesign foundation (t-001, worker-1)
 *
 * Loads FIRST of the nine partials. Provides:
 *   1. Brand-token aliases (sourced from colors_and_type.css; mirrored so this
 *      file still works if that stylesheet 404s).
 *   2. Two-pane shell scaffolding (.pe-shell / .pe-form / .pe-preview).
 *   3. Section, action-bar, and button primitives.
 *   4. SAFETY-NET fallbacks for the shared .pe-field component (t-008) and the
 *      grid/affix helpers, so the page is fully usable from t-001 alone. Later
 *      partials (layout w3, fields w8, sections, polish w9) override these.
 * ========================================================================== */

:root {
  /* Mirror of colors_and_type.css tokens (works even if it's absent). */
  --terra-50:#FBF3EC; --terra-300:#E09F6F; --terra-400:#D17A40;
  --terra-500:#B8451F; --terra-600:#9E3818; --terra-700:#7E2D12;
  --ink:#1A1412; --ink-soft:#3A2F2A; --ink-muted:#7A6F68; --ink-faint:#C9BEB4;
  --canvas:#FBF7F1; --canvas-soft:#F3EADC;
  --border:rgba(26,20,18,0.10); --border-soft:rgba(26,20,18,0.08);
  --danger-500:#DC2626; --danger-700:#B91C1C;
  --font-display:'Fraunces', ui-serif, Georgia, serif;
  --font-body:'DM Sans', system-ui, -apple-system, sans-serif;

  /* Editor-scoped tokens */
  --pe-radius:14px;
  --pe-radius-sm:10px;
  --pe-gap:20px;
  --pe-shadow:0 2px 8px -2px rgb(26 20 18 / 0.06);
  --pe-shadow-lift:0 10px 28px -10px rgb(26 20 18 / 0.16);
  --pe-actionbar-h:68px;
  --pe-topbar-h:65px;
}

[hidden] { display: none !important; }

/* ── Page wrapper ─────────────────────────────────────────────────────────── */
.pe-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px calc(var(--pe-actionbar-h) + 40px);
}
.pe-intro {
  margin: 0 0 22px;
  color: var(--ink-muted);
  font-family: var(--font-body);
  font-size: 14px; line-height: 1.55;
  max-width: 60ch;
}

/* ── Two-pane shell (t-003 layout overrides breakpoints/sticky offsets) ─────── */
.pe-shell {
  display: grid;
  grid-template-columns: minmax(0, 58fr) minmax(0, 42fr);
  gap: 24px;
  align-items: start;
}
.pe-form { min-width: 0; }
.pe-preview {
  min-width: 0;
  position: sticky;
  top: calc(var(--pe-topbar-h) + 16px);
}
@media (max-width: 900px) {
  /* Fallback single-column reflow; t-003 owns the polished mobile strategy. */
  .pe-shell { grid-template-columns: 1fr; }
  .pe-preview { position: static; order: -1; }
}

/* ── Section card ─────────────────────────────────────────────────────────── */
.pe-section {
  background: #fff;
  border: 1px solid var(--border-soft);
  border-radius: var(--pe-radius);
  box-shadow: var(--pe-shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.pe-section__head {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.pe-section__head h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 19px; line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
  color: var(--ink);
}
.pe-section__sub {
  margin: 0;
  font-family: var(--font-body);
  font-size: 13px; line-height: 1.5;
  color: var(--ink-muted);
}
.pe-section__body { padding: 18px 20px 20px; display: grid; gap: 16px; }

/* ── Preview card placeholder (t-002 replaces contents) ─────────────────────── */
#pe-preview-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--pe-radius);
  background: #fff;
  box-shadow: var(--pe-shadow);
  min-height: 280px;
}
#pe-preview-card[data-empty="true"]::before {
  content: "Your product preview appears here as you type.";
  display: flex; align-items: center; justify-content: center;
  height: 100%; min-height: 280px;
  padding: 32px;
  text-align: center;
  color: var(--ink-faint);
  font-family: var(--font-body);
  font-size: 14px; line-height: 1.5;
}

/* ── Grid helpers (sections/layout may refine) ──────────────────────────────── */
.pe-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 560px) {
  .pe-grid--2 { grid-template-columns: 1fr 1fr; }
  .pe-grid--3 { grid-template-columns: repeat(3, 1fr); }
}

/* ── SAFETY-NET .pe-field component (t-008 owns the real one) ────────────────── */
.pe-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.pe-field__label {
  font-family: var(--font-body);
  font-size: 13px; font-weight: 600; color: var(--ink-soft);
}
.pe-field__req { color: var(--terra-600); margin-left: 2px; }
.pe-field__opt { color: var(--ink-muted); font-weight: 400; margin-left: 4px; font-size: 12px; }
.pe-field__input {
  appearance: none; -webkit-appearance: none;
  width: 100%; min-height: 44px;
  padding: 10px 14px;
  font: inherit; font-family: var(--font-body); font-size: 15px; line-height: 1.4;
  color: var(--ink); background: #fff;
  border: 1px solid rgba(26,20,18,0.14);
  border-radius: var(--pe-radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea.pe-field__input { min-height: 110px; resize: vertical; padding-top: 12px; }
select.pe-field__input {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237A6F68' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}
.pe-field__input::placeholder { color: var(--ink-faint); }
.pe-field__input:hover { border-color: rgba(26,20,18,0.24); }
.pe-field__input:focus {
  outline: none;
  border-color: var(--terra-500);
  box-shadow: 0 0 0 3px rgba(184,69,31,0.12);
}
.pe-field__hint { font-size: 12px; color: var(--ink-muted); line-height: 1.45; }
.pe-field__error { display: none; font-size: 12px; font-weight: 500; color: var(--danger-700); }
.pe-field--narrow { max-width: 240px; }

/* Affix (RM prefix) — t-005/t-008 may refine */
.pe-field__inputwrap { position: relative; }
.pe-field__inputwrap--affix .pe-field__affix {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 13px; font-weight: 600; color: var(--ink-muted); pointer-events: none;
}
.pe-field__inputwrap--affix .pe-field__input { padding-left: 42px; }

/* Error state */
.pe-field--error .pe-field__label { color: var(--danger-700); }
.pe-field--error .pe-field__input { border-color: var(--danger-500); background: #FEF2F2; }
.pe-field--error .pe-field__error { display: block; }

/* ── Action bar (sticky save bar; t-003 refines sticky/stack) ───────────────── */
.pe-actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  background: rgba(251,247,241,0.96);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.pe-actionbar__inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.pe-actionbar__status { flex: 1; min-width: 0; font-size: 13px; color: var(--ink-muted); }
.pe-actionbar__status.is-warn { color: var(--danger-700); font-weight: 500; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.pe-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-family: var(--font-body); font-size: 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .05s ease;
}
.pe-btn:active { transform: translateY(1px); }
.pe-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.pe-btn--primary { background: var(--terra-500); color: #fff; }
.pe-btn--primary:hover:not(:disabled) { background: var(--terra-600); }
.pe-btn--secondary { background: #fff; border-color: rgba(26,20,18,0.16); color: var(--ink); }
.pe-btn--secondary:hover:not(:disabled) { background: var(--canvas-soft); border-color: rgba(26,20,18,0.28); }

@media (prefers-reduced-motion: reduce) {
  .pe-field__input, .pe-btn { transition: none; }
}
