/* =====================================================
   DESIGN TOKENS - dark mode + theming
   ===================================================== */
:root {
  --brand: #ee4d2d;
  --brand-dark: #d63f22;
  --brand-light: #fff2ee;
  --ink: #1a1a1a;
  --ink-soft: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f5f5f5;
  --bg2: #eff0f2;
  --card: #fff;
  --card2: #fafafa;
  --ok: #16a34a;
  --danger: #dc2626;
  --warn: #f59e0b;
  --info: #2563eb;
  --radius: 8px;
  --radius-lg: 14px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,.07);
  --shadow-md: 0 8px 24px rgba(0,0,0,.10);
  --shadow-lg: 0 14px 40px rgba(0,0,0,.15);
  --glass: rgba(255,255,255,.75);
  --transition: .18s ease;
  --font: 'Segoe UI', Arial, Helvetica, sans-serif;
}
html[data-theme="dark"] {
  --ink: #f0f0f0;
  --ink-soft: #d1d5db;
  --muted: #9ca3af;
  --line: #2d2d2d;
  --bg: #111;
  --bg2: #1a1a1a;
  --card: #1e1e1e;
  --card2: #252525;
  --glass: rgba(30,30,30,.85);
  --brand-light: #3d1a0e;
  --shadow-sm: 0 2px 8px rgba(0,0,0,.3);
  --shadow-md: 0 8px 24px rgba(0,0,0,.4);
}

/* =====================================================
   BASE
   ===================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100dvh;
  transition: background var(--transition), color var(--transition);
}
a { color: inherit; text-decoration: none; }
img, video { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

/* =====================================================
   TOPBAR
   ===================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  background: linear-gradient(135deg, var(--brand), #f15d3e);
  color: #fff;
  box-shadow: 0 2px 12px rgba(238,77,45,.35);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 16px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; font-size: 17px; }
.brand-logo {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: #fff;
  color: var(--brand);
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 18px;
  object-fit: cover;
}
.brand-logo img { width: 100%; height: 100%; object-fit: cover; border-radius: 7px; }
.search-form { display: flex; min-width: 0; }
.search-form input {
  flex: 1; min-width: 0;
  border: 0; padding: 9px 12px;
  border-radius: 6px 0 0 6px;
  outline: none; background: #fff;
  color: #222; font-size: 14px;
}
.search-form button {
  border: 0; padding: 0 18px;
  border-radius: 0 6px 6px 0;
  background: #ffe0d9;
  color: var(--brand);
  font-weight: 700; font-size: 14px;
}
.search-form button:hover { background: #ffccc0; }
.nav-actions { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.nav-actions a, .nav-actions button { opacity: .95; white-space: nowrap; }
.nav-actions a:hover { opacity: 1; text-decoration: underline; }
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: var(--brand);
  border-radius: 9px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 800;
  min-width: 16px;
  line-height: 1;
}
.nav-badge.danger { background: var(--danger); color: #fff; }
.logout-form { display: contents; }
.admin-alert-strip {
  background: rgba(0,0,0,.18);
  padding: 5px 16px;
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.admin-alert-strip a { text-decoration: underline; opacity: .9; }

/* Theme toggle button */
.theme-toggle {
  background: rgba(255,255,255,.22);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 20px;
  padding: 4px 10px;
  color: #fff;
  font-size: 13px;
  display: flex; align-items: center; gap: 4px;
}
.theme-toggle:hover { background: rgba(255,255,255,.3); }

/* =====================================================
   LAYOUT
   ===================================================== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 16px;
  /* space for mobile bottom nav */
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}
.page-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
}

/* =====================================================
   PANEL / CARD
   ===================================================== */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20px 0 10px;
}
.section-title h2, .section-title h1 { margin: 0; font-size: 19px; }
.search-filters {
  display: grid;
  grid-template-columns: 1.5fr repeat(3, minmax(110px, .7fr)) auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

/* =====================================================
   TYPOGRAPHY HELPERS
   ===================================================== */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.price { color: var(--brand); font-weight: 800; }
.old-price { color: var(--muted); text-decoration: line-through; font-size: 13px; }

/* =====================================================
   PRODUCT GRID
   ===================================================== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}
.product-card, .deal-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
  display: block;
}
.product-card:hover, .deal-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}
.product-card:active { transform: scale(.98); }
.product-media { position: relative; }
.product-media img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--bg2);
}
.badge-stack {
  position: absolute;
  top: 6px; left: 6px;
  display: flex; flex-direction: column; gap: 4px;
}
.product-card-body { padding: 9px; }
.product-name {
  min-height: 38px;
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--ink);
  margin-bottom: 4px;
}
.price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.live-dot {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}
.live-dot::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  background: var(--ok);
  border-radius: 50%;
  animation: pulse-dot 2s ease infinite;
}
@keyframes pulse-dot {
  0%,100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.7); }
}
.sold-meter {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 6px 0 4px;
  overflow: hidden;
}
.sold-meter span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--warn), var(--brand));
  border-radius: 2px;
  transition: width .6s ease;
}
.product-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

/* =====================================================
   BADGES
   ===================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: .3px;
  text-transform: uppercase;
}
.badge.sale { background: var(--brand); color: #fff; }
.badge.trend { background: #7c3aed; color: #fff; }
.badge.hot { background: var(--warn); color: #fff; }
.badge.new { background: var(--ok); color: #fff; }
.badge.neutral { background: var(--line); color: var(--muted); }
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.working { background: #dbeafe; color: #1d4ed8; }
.badge.shipping { background: #e0e7ff; color: #3730a3; }
.badge.done { background: #dcfce7; color: #166534; }
.badge.danger { background: #fee2e2; color: #991b1b; }

/* =====================================================
   BUTTONS
   ===================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--card);
  cursor: pointer;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition), transform .1s ease;
}
.btn:hover { filter: brightness(.96); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.warn { background: var(--warn); color: #fff; border-color: var(--warn); }
.btn.ghost { background: transparent; border-color: currentColor; }
.btn.block { width: 100%; }
.btn.compact { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* =====================================================
   ALERTS
   ===================================================== */
.alert {
  border-radius: 8px;
  padding: 12px 14px;
  margin: 10px 0;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}
.alert.success { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.alert.danger { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.alert.warning { border-color: #fde68a; background: #fffbeb; color: #92400e; }
html[data-theme="dark"] .alert.success { background: #052e16; border-color: #166534; color: #bbf7d0; }
html[data-theme="dark"] .alert.danger { background: #2d0d0d; border-color: #991b1b; color: #fca5a5; }
html[data-theme="dark"] .alert.warning { background: #1c1404; border-color: #92400e; color: #fde68a; }

/* =====================================================
   FORMS
   ===================================================== */
.form-grid { display: grid; gap: 10px; }
label { display: grid; gap: 5px; font-weight: 600; font-size: 14px; }
input, select, textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  background: var(--card);
  color: var(--ink);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(238,77,45,.12);
}
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }

/* =====================================================
   TABS
   ===================================================== */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab { padding: 10px 14px; border-bottom: 3px solid transparent; white-space: nowrap; color: var(--muted); font-size: 15px; }
.tab.active { color: var(--brand); border-color: var(--brand); font-weight: 700; }

/* =====================================================
   HERO (homepage)
   ===================================================== */
.living-hero {
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  margin-bottom: 16px;
  min-height: 180px;
  background: linear-gradient(135deg, #ee4d2d, #ff8c42);
}
.living-hero .hero-img {
  width: 100%;
  max-height: 340px;
  object-fit: cover;
  display: block;
}
.hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, rgba(0,0,0,.55) 30%, transparent 80%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 20px 22px;
  gap: 10px;
}
.hero-title {
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0,0,0,.4);
  line-height: 1.2;
}
.hero-meta { display: flex; gap: 10px; flex-wrap: wrap; }
.hero-chip {
  background: rgba(255,255,255,.22);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}
.hero-chip .dot { width: 6px; height: 6px; background: #4ade80; border-radius: 50%; animation: pulse-dot 1.4s ease infinite; }
.hero-cta { display: flex; gap: 8px; flex-wrap: wrap; }
.hero-cta .btn { min-height: 38px; font-size: 13px; }
.hero-cta .btn.primary { background: var(--brand); border-color: var(--brand); }
.hero-cta .btn.ghost { border-color: rgba(255,255,255,.7); color: #fff; }

/* Live strip */
.live-strip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  overflow: hidden;
}
.live-strip-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  color: var(--brand);
  white-space: nowrap;
}
.live-strip-label::before {
  content: '';
  width: 8px; height: 8px;
  background: var(--brand);
  border-radius: 50%;
  animation: pulse-dot 1.2s ease infinite;
}
.live-strip-items { display: flex; gap: 10px; overflow: hidden; position: relative; flex: 1; }
.live-strip-item {
  white-space: nowrap;
  animation: scroll-left 24s linear infinite;
  color: var(--ink-soft);
}
@keyframes scroll-left {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* Curiosity rail */
.curiosity-rail {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin-bottom: 16px;
  padding-bottom: 2px;
}
.curiosity-rail::-webkit-scrollbar { display: none; }
.curiosity-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--line);
  background: var(--card);
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  transition: all var(--transition);
  min-height: 36px;
  flex-shrink: 0;
}
.curiosity-chip:hover, .curiosity-chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  transform: translateY(-1px);
}

/* Progress reward card */
.reward-card {
  background: linear-gradient(135deg, #ee4d2d, #ff8c42);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
}
.reward-card h3 { font-size: 16px; margin-bottom: 8px; }
.progress-bar {
  height: 8px;
  background: rgba(255,255,255,.3);
  border-radius: 4px;
  margin: 8px 0;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: #fff;
  border-radius: 4px;
  transition: width .8s cubic-bezier(.34,1.56,.64,1);
}
.reward-steps { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.reward-step {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px;
  opacity: .85;
}
.reward-step.done { opacity: 1; }
.reward-step.done::before { content: 'ok'; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-orbit {
  position: relative;
  width: 80px; height: 80px;
  margin: 0 auto 16px;
}
.empty-orbit span {
  position: absolute;
  inset: 0;
  border: 2px dashed var(--line);
  border-radius: 50%;
  animation: spin 8s linear infinite;
}
.empty-orbit i {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  font-size: 28px;
  font-style: normal;
}
.empty-orbit i::after { content: ''; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state h3 { font-size: 17px; color: var(--ink); margin-bottom: 6px; }
.empty-state p { font-size: 14px; margin-bottom: 14px; }

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--line) 25%, var(--bg2) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.skeleton-card .skeleton-img { aspect-ratio: 1/1; }
.skeleton-card .skeleton-body { padding: 9px; display: grid; gap: 8px; }
.skeleton-card .skeleton-line { height: 12px; border-radius: 4px; }
.skeleton-card .skeleton-line.short { width: 60%; }

/* Toast stack */
.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 80px;
  z-index: 500;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  max-width: 340px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  pointer-events: all;
  animation: toast-in .3s cubic-bezier(.34,1.56,.64,1);
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast.success { border-left: 4px solid var(--ok); }
.toast.warning { border-left: 4px solid var(--warn); }
.toast.info { border-left: 4px solid var(--info); }
.toast.leaving { animation: toast-out .25s ease forwards; }
.toast-icon { font-size: 18px; flex-shrink: 0; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(60px) scale(.9); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(60px) scale(.9); }
}

/* =====================================================
   POPUP NOTICE
   ===================================================== */
.popup-notice {
  position: fixed;
  right: 16px;
  bottom: 80px;
  max-width: 360px;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  animation: toast-in .3s cubic-bezier(.34,1.56,.64,1);
}

/* =====================================================
   AUTH PAGE - single shell + segmented tabs
   ===================================================== */
.auth-shell {
  max-width: 520px;
  margin: 24px auto;
}
.auth-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.auth-header {
  background: linear-gradient(135deg, #ee4d2d, #ff8c42);
  padding: 22px 20px 20px;
  color: #fff;
}
.auth-header h1 { font-size: 20px; margin-bottom: 4px; }
.auth-header p { font-size: 13px; opacity: .9; }
.auth-segment {
  display: flex;
  border-bottom: 2px solid var(--line);
  background: var(--card2);
}
.auth-seg-btn {
  flex: 1;
  padding: 12px 6px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all var(--transition);
  min-height: 44px;
}
.auth-seg-btn.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  background: var(--card);
}
.auth-pane { display: none; padding: 20px; animation: fade-up .2s ease; }
.auth-pane.active { display: block; }
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
/* Progressive form fields */
.auth-field {
  display: grid;
  gap: 6px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height .35s ease, opacity .25s ease, margin .25s ease;
  margin-bottom: 0;
}
.auth-field.visible {
  max-height: 80px;
  opacity: 1;
  margin-bottom: 10px;
}
.auth-field label { font-weight: 600; font-size: 14px; }

/* Auth animation / commerce flow */
.commerce-flow {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  padding: 16px 0 8px;
  position: relative;
  overflow: hidden;
  min-height: 110px;
}
.parcel-runner {
  position: absolute;
  bottom: 10px;
  left: -40px;
  animation: parcel-move 5s linear infinite;
}
.parcel-runner span {
  display: block;
  width: 28px; height: 20px;
  background: var(--warn);
  border-radius: 4px;
  position: relative;
}
.parcel-runner span::after {
  content: '';
  position: absolute;
  top: -6px; left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--brand);
}
@keyframes parcel-move {
  0% { left: -40px; opacity: 0; }
  5% { opacity: 1; }
  90% { opacity: 1; }
  100% { left: calc(100% + 40px); opacity: 0; }
}

.role-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 52px;
}
.role-card strong { font-size: 11px; text-align: center; color: var(--ink); }
.role-card small { font-size: 10px; color: var(--muted); text-align: center; }
.cartoon-person { position: relative; height: 56px; width: 40px; }
.cartoon-person .head {
  width: 22px; height: 22px;
  background: #fbbf24;
  border-radius: 50%;
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  border: 2px solid #d97706;
}
.cartoon-person .head i {
  position: absolute;
  bottom: 5px; left: 50%;
  transform: translateX(-50%);
  width: 10px; height: 3px;
  background: #d97706;
  border-radius: 2px;
  font-style: normal;
  display: block;
}
.cartoon-person .body {
  position: absolute;
  top: 22px; left: 50%;
  transform: translateX(-50%);
  width: 18px; height: 22px;
  border-radius: 4px;
}
.role-card.buyer .body { background: #3b82f6; }
.role-card.seller .body { background: var(--brand); }
.role-card.packer .body { background: #8b5cf6; }
.role-card.shipper .body { background: #10b981; }
.role-card.admin .body { background: #374151; }

.cartoon-person .arm {
  position: absolute;
  top: 26px;
  width: 7px; height: 16px;
  border-radius: 4px;
  animation: arm-wave 2.4s ease-in-out infinite;
}
.cartoon-person .arm.left { left: 2px; transform-origin: top center; }
.cartoon-person .arm.right { right: 2px; transform-origin: top center; animation-delay: .3s; }
.role-card.buyer .arm { background: #3b82f6; }
.role-card.seller .arm { background: var(--brand); }
.role-card.packer .arm { background: #8b5cf6; }
.role-card.shipper .arm { background: #10b981; }
.role-card.admin .arm { background: #374151; }
@keyframes arm-wave {
  0%,100% { transform: rotate(-8deg); }
  50% { transform: rotate(14deg); }
}
.cartoon-person .tool {
  position: absolute;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 6px; height: 10px;
  background: rgba(0,0,0,.15);
  border-radius: 3px;
}

/* Role step active indicator */
.role-card.active .head { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(238,77,45,.3); }

/* Flow timeline compact */
.order-timeline {
  display: flex;
  gap: 0;
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
}
.order-timeline::before {
  content: '';
  position: absolute;
  top: 14px;
  left: 14px; right: 14px;
  height: 2px;
  background: var(--line);
  z-index: 0;
}
.order-timeline span {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  font-size: 11px;
  color: var(--muted);
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 0 4px;
}
.order-timeline span i {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--line);
  display: block;
  font-style: normal;
  flex-shrink: 0;
}
.order-timeline span.done i { background: var(--ok); border-color: var(--ok); }
.order-timeline span.active i { background: var(--brand); border-color: var(--brand); box-shadow: 0 0 0 3px rgba(238,77,45,.25); }
.order-timeline span.done { color: var(--ok); }
.order-timeline span.active { color: var(--brand); font-weight: 700; }

/* =====================================================
   PRODUCT DETAIL
   ===================================================== */
.product-detail {
  display: grid;
  grid-template-columns: minmax(300px, 480px) 1fr;
  gap: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.media-main {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card2);
}
.media-main img, .media-main video {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}
.zoom-lens {
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0;
  background-repeat: no-repeat;
  background-size: 220%;
  transition: opacity .12s ease;
}
.media-main.zooming .zoom-lens { opacity: 1; }
.thumbs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  margin-top: 10px;
}
.thumb {
  border: 2px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: var(--card);
  position: relative;
}
.thumb.active { border-color: var(--brand); }
.thumb img { width: 100%; aspect-ratio: 1/1; object-fit: cover; }
.video-badge {
  position: absolute; right: 4px; bottom: 4px;
  background: rgba(0,0,0,.7); color: #fff;
  border-radius: 3px; padding: 2px 5px; font-size: 10px;
}
.product-info h1 { font-size: 22px; color: var(--ink); margin-bottom: 10px; line-height: 1.3; }
.product-price { font-size: 28px; color: var(--brand); font-weight: 800; margin: 10px 0; }
.variant-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
.variant-list label {
  display: inline-flex; border: 1.5px solid var(--line);
  padding: 8px 10px; border-radius: 6px; font-weight: 500;
  cursor: pointer; gap: 6px; align-items: center;
}
.variant-list input[type="radio"]:checked + label,
.variant-list label:has(input:checked) { border-color: var(--brand); background: var(--brand-light); }
.variant-list input[type="radio"] { width: auto; }
.sticky-buy {
  display: flex; gap: 8px; margin-top: 14px;
  position: sticky;
  bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  background: var(--card);
  padding: 8px 0;
  z-index: 30;
  border-top: 1px solid var(--line);
}
.sticky-buy .btn { flex: 1; min-height: 44px; }

/* =====================================================
   CART / ORDERS
   ===================================================== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { border-bottom: 1px solid var(--line); padding: 10px 12px; text-align: left; vertical-align: middle; }
th { color: var(--ink-soft); background: var(--card2); font-size: 13px; }
tr:last-child td { border-bottom: none; }
.cart-list, .seller-card-list {
  display: grid;
  gap: 10px;
}
.cart-item, .list-card {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
}
.cart-item input[type="number"] {
  width: 78px;
}
.checkout-panel {
  margin-top: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.address-choice {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--card2);
}
.address-choice p {
  margin: 5px 0 8px;
  color: var(--muted);
}
.checkout-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.checkout-total strong {
  color: var(--brand);
  font-size: 18px;
}
.qr-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--card2);
}
.qr-box summary {
  cursor: pointer;
  font-weight: 700;
}
.qr-box img {
  width: 180px;
  height: 180px;
  margin-top: 10px;
}
.order-card {
  align-items: start;
}
.product-editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, .8fr);
  gap: 12px;
}
.product-preview .product-card {
  max-width: 280px;
}
.quality-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.quality-list span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  background: var(--card2);
}
.quality-list span.done {
  border-color: #86efac;
  color: #166534;
  background: #f0fdf4;
}
.shop-hero {
  padding: 0;
  overflow: hidden;
}
.shop-hero > img {
  width: 100%;
  aspect-ratio: 1200 / 320;
  object-fit: cover;
  background: var(--bg2);
}
.shop-hero-body {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
}
.shop-logo {
  width: 58px;
  height: 58px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 24px;
}
.shop-meta {
  color: var(--muted);
  font-size: 13px;
}

/* =====================================================
   DASHBOARD / STATS
   ===================================================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  transition: box-shadow var(--transition);
}
.stat:hover { box-shadow: var(--shadow-sm); }
.stat strong { display: block; font-size: 24px; margin-top: 6px; color: var(--brand); }

/* =====================================================
   SIDEBAR MENU
   ===================================================== */
.side-menu { display: grid; gap: 2px; align-content: start; }
.side-menu a {
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--ink-soft);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition), color var(--transition);
}
.side-menu a.active, .side-menu a:hover {
  background: var(--brand-light);
  color: var(--brand);
}

/* =====================================================
   CHAT
   ===================================================== */
.chat-layout { display: grid; grid-template-columns: 260px 1fr; gap: 12px; min-height: 400px; }
.chat-list, .chat-window { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.chat-list a { display: block; padding: 12px; border-bottom: 1px solid var(--line); transition: background var(--transition); }
.chat-list a:hover { background: var(--card2); }
.messages { padding: 12px; max-height: 440px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 76%; padding: 9px 12px; border-radius: 12px; background: var(--card2); font-size: 14px; }
.msg.me { margin-left: auto; background: var(--brand-light); color: #7c2d12; }
.msg.system { margin: 6px auto; background: #fffbeb; color: #92400e; font-size: 12px; max-width: 90%; text-align: center; }
html[data-theme="dark"] .msg.me { background: #3d1a0e; color: #ffcbb5; }
.context-card { display: flex; gap: 8px; border: 1px solid var(--line); padding: 8px; border-radius: 8px; background: var(--card); }
.context-card img { width: 64px; height: 64px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }

/* =====================================================
   MOBILE BOTTOM NAV
   ===================================================== */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 150;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -4px 16px rgba(0,0,0,.08);
}
.mobile-bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  font-size: 10px;
  color: var(--muted);
  min-height: 52px;
  flex: 1;
  transition: color var(--transition);
}
.mobile-bottom-nav a.active { color: var(--brand); font-weight: 700; }
.mobile-bottom-nav a span {
  width: 22px; height: 22px;
  border-radius: 4px;
  display: block;
  background: currentColor;
  -webkit-mask: center/contain no-repeat;
  mask: center/contain no-repeat;
}

/* Nav icons via emoji fallback (SVG mask preferred in production) */
.mobile-bottom-nav a:nth-child(1) span { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z'/%3E%3C/svg%3E"); }
.mobile-bottom-nav a:nth-child(2) span { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E"); }
.mobile-bottom-nav a:nth-child(3) span { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm.5-13H11v6l5.25 3.15.75-1.23-4.5-2.67V7z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm.5-13H11v6l5.25 3.15.75-1.23-4.5-2.67V7z'/%3E%3C/svg%3E"); }
.mobile-bottom-nav a:nth-child(4) span { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 18c-1.1 0-1.99.9-1.99 2S5.9 22 7 22s2-.9 2-2-.9-2-2-2zM1 2v2h2l3.6 7.59-1.35 2.45c-.16.28-.25.61-.25.96C5 16.1 6.9 18 9 18h12v-2H9.42c-.14 0-.25-.11-.25-.25l.03-.12.9-1.63H19c.75 0 1.41-.41 1.75-1.03l3.58-6.49A1 1 0 0 0 23.5 5H5.21l-.94-2H1zm16 16c-1.1 0-1.99.9-1.99 2s.89 2 1.99 2 2-.9 2-2-.9-2-2-2z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 18c-1.1 0-1.99.9-2S5.9 22 7 22s2-.9 2-2-.9-2-2-2zM1 2v2h2l3.6 7.59-1.35 2.45c-.16.28-.25.61-.25.96C5 16.1 6.9 18 9 18h12v-2H9.42c-.14 0-.25-.11-.25-.25l.03-.12.9-1.63H19c.75 0 1.41-.41 1.75-1.03l3.58-6.49A1 1 0 0 0 23.5 5H5.21l-.94-2H1zm16 16c-1.1 0-1.99.9-1.99 2s.89 2 1.99 2 2-.9 2-2-.9-2-2-2z'/%3E%3C/svg%3E"); }
.mobile-bottom-nav a:nth-child(5) span { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E"); }

/* =====================================================
   PAGE TRANSITION
   ===================================================== */
@keyframes page-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.container { animation: page-in .2s ease; }

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 1023px) {
  .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: repeat(2, 1fr); }
  .product-detail { grid-template-columns: 1fr; }
  .thumbs { grid-template-columns: repeat(5, 1fr); }
}
@media (max-width: 767px) {
  body { font-size: 14px; }
  .topbar-inner {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 8px 12px;
  }
  .search-form { grid-column: 1 / -1; order: 3; }
  .brand { font-size: 15px; }
  .brand-logo { width: 30px; height: 30px; }
  .nav-actions { gap: 6px; font-size: 12px; }
  .nav-actions .hide-mobile { display: none; }
  .container { padding: 10px 12px; padding-bottom: calc(66px + env(safe-area-inset-bottom, 8px)); }
  .page-grid { grid-template-columns: 1fr; }
  .page-grid > aside { order: 2; }
  .page-grid > section { order: 1; }
  .panel { padding: 12px; }
  .search-filters {
    grid-template-columns: 1fr 1fr;
  }
  .search-filters input[name="q"],
  .search-filters button {
    grid-column: 1 / -1;
  }
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .product-card-body { padding: 7px; }
  .product-name { font-size: 12px; min-height: 32px; }
  .auth-shell { margin: 0; }
  .auth-panel { border-radius: 0; border: none; }
  .product-detail {
    padding: 12px;
    border-radius: 0;
    margin: 0 -12px;
    border-left: none; border-right: none;
  }
  .product-info h1 { font-size: 18px; }
  .product-price { font-size: 22px; }
  .thumbs { display: flex; overflow-x: auto; gap: 6px; }
  .thumb { flex: 0 0 56px; }
  .sticky-buy {
    bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  }
  .dashboard-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat strong { font-size: 20px; }
  .cart-item, .list-card {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .cart-item .price, .list-card .price {
    justify-self: start;
  }
  .cart-item input[type="number"] {
    width: 100%;
  }
  .checkout-panel {
    margin-left: -2px;
    margin-right: -2px;
    padding: 12px;
  }
  .product-editor-grid {
    grid-template-columns: 1fr;
  }
  .shop-hero-body {
    grid-template-columns: auto 1fr;
  }
  .shop-hero-body form {
    grid-column: 1 / -1;
  }
  .product-preview .product-card {
    max-width: none;
  }
  .quality-list {
    grid-template-columns: 1fr;
  }
  .chat-layout { grid-template-columns: 1fr; }
  .chat-list { max-height: 180px; overflow: auto; }
  .msg { max-width: 88%; }
  .popup-notice { left: 10px; right: 10px; bottom: calc(68px + env(safe-area-inset-bottom, 0px)); max-width: none; }
  .toast-stack { right: 10px; left: 10px; bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }
  .toast { max-width: none; }
  .mobile-bottom-nav { display: flex; }
  .side-menu { display: flex; overflow-x: auto; gap: 4px; -webkit-overflow-scrolling: touch; }
  .side-menu a { white-space: nowrap; padding: 8px 10px; }
  .commerce-flow { padding: 10px 0 6px; gap: 6px; }
  .role-card { min-width: 42px; }
  .order-timeline span { font-size: 10px; }
  .living-hero { border-radius: 0; margin: 0 -12px 12px; }
  .living-hero .hero-img { max-height: 220px; }
  .hero-title { font-size: 17px; }
  .hero-overlay { padding: 14px 14px; }
  .product-detail { grid-template-columns: 1fr; }
}

/* =====================================================
   REDUCED MOTION
   ===================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
