/* ==============================================================
 * Daneh Sabz – Design system & components
 * Mobile-first · RTL · zero dependencies
 * ============================================================== */

/* ---------- 1. Design tokens ---------- */
:root {
  /* Brand greens */
  --green-900: #1E3F20;
  --green-700: #2D5A27;
  --green-300: #A3C9A8;
  --green-50:  #EBF2EB;

  /* Neutrals */
  --white: #FFFFFF;
  --gray-50: #F8F9FA;
  --gray-200: #E5E7EB;
  --gray-400: #9CA3AF;
  --gray-600: #4B5563;
  --ink: #1A231B;

  /* Semantic */
  --bg: var(--white);
  --surface: var(--white);
  --surface-muted: var(--gray-50);
  --border: var(--gray-200);
  --text: var(--ink);
  --text-muted: var(--gray-600);
  --primary: var(--green-900);
  --primary-hover: var(--green-700);
  --accent: var(--green-300);
  --accent-soft: var(--green-50);
  --danger: #B42318;
  --danger-soft: #FEF3F2;
  --success: #2D5A27;
  --whatsapp: #1E7E45;

  /* Type */
  --font: 'Vazirmatn', 'IRANSans', 'IRANSansX', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;

  /* Shape & depth */
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(30, 63, 32, 0.06);
  --shadow: 0 4px 16px rgba(30, 63, 32, 0.08);
  --shadow-lg: 0 12px 32px rgba(30, 63, 32, 0.14);

  /* Motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 150ms;
  --dur: 280ms;

  --gutter: 16px;
  --container: 1120px;
  --tabbar-h: 76px;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--tabbar-h) + 12px);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
svg { flex-shrink: 0; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.skip-link {
  position: absolute;
  inset-inline-start: 8px;
  top: -48px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--primary);
  color: var(--white);
  border-radius: var(--radius-sm);
  transition: top var(--dur-fast);
}
.skip-link:focus { top: 8px; }

/* ---------- 3. Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;              /* touch target */
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background-color var(--dur-fast), border-color var(--dur-fast),
              color var(--dur-fast), transform var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { cursor: not-allowed; opacity: 0.55; }
.btn--sm { min-height: 38px; padding: 6px 12px; font-size: var(--fs-xs); }

.btn--primary { background: var(--primary); color: var(--white); }
.btn--primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn--ghost { background: var(--surface); border-color: var(--border); color: var(--primary); }
.btn--ghost:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }

.btn--danger-ghost { background: var(--surface); border-color: var(--border); color: var(--danger); }
.btn--danger-ghost:hover:not(:disabled) { background: var(--danger-soft); border-color: #FDA29B; }

/* ---------- 4. Shared bits: tags, live dot, empty state ---------- */
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  padding: 2px 10px;
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1.9;
  color: var(--green-700);
  background: var(--accent-soft);
  border-radius: var(--radius-pill);
}

.live-dot {
  position: relative;
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22A34A;
}
.live-dot::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: inherit;
  animation: live-ping 1.8s var(--ease) infinite;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 40px 16px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ==============================================================
 * CUSTOMER MENU (index.html)
 * ============================================================== */

/* ---------- Header ---------- */
.site-header {
  background:
    radial-gradient(120% 140% at 100% 0%, var(--green-700) 0%, var(--green-900) 60%);
  color: var(--white);
  padding-block: 20px 28px;
}
.site-header__inner { display: grid; gap: 16px; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand__logo { color: rgba(255, 255, 255, 0.12); display: inline-flex; }
.brand__logo svg { border-radius: 14px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.brand__name { font-size: var(--fs-2xl); font-weight: 800; line-height: 1.3; letter-spacing: -0.01em; }
.brand__tagline { font-size: var(--fs-sm); color: var(--green-300); }

.contact-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  font-size: var(--fs-xs);
  font-weight: 500;
  text-decoration: none;
  color: var(--white);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-pill);
  transition: background-color var(--dur-fast);
}
.badge-link:hover { background: rgba(255, 255, 255, 0.18); }
.badge-link svg { color: var(--green-300); }

/* ---------- Sticky tab bar ---------- */
.tabbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-block: 10px;
  background: rgba(255, 255, 255, 0.86);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}

.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
}

/* Sliding pill: in RTL the first tab sits on the right. */
.tabs__indicator {
  position: absolute;
  top: 4px;
  bottom: 4px;
  right: 4px;
  width: calc(50% - 4px);
  background: var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform var(--dur) var(--ease);
}
.tabs[data-active="wholesale"] .tabs__indicator { transform: translateX(-100%); }

.tabs__tab {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 52px;
  padding: 6px 8px;
  font-size: var(--fs-md);
  font-weight: 700;
  line-height: 1.5;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color var(--dur) var(--ease);
}
.tabs__tab small { font-size: 0.6875rem; font-weight: 500; opacity: 0.8; }
.tabs__tab[aria-selected="true"] { color: var(--white); }
.tabs__tab[aria-selected="true"] small { color: var(--green-300); opacity: 1; }

/* ---------- Menu body ---------- */
.menu { padding-block: 16px 40px; }

.menu__status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.panel:focus-visible { outline-offset: 6px; }
.panel--enter-left  { animation: panel-in-left var(--dur) var(--ease); }
.panel--enter-right { animation: panel-in-right var(--dur) var(--ease); }

.wholesale-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 14px;
  padding: 10px 14px;
  font-size: var(--fs-sm);
  color: var(--green-900);
  background: var(--accent-soft);
  border: 1px solid #D3E4D5;
  border-radius: var(--radius);
}
.wholesale-note svg { margin-top: 4px; color: var(--green-700); }

.product-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

/* ---------- Product card ---------- */
.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
}
.card:active { transform: scale(0.99); }

@media (hover: hover) {
  .card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent);
  }
}

.card.is-out { background: var(--surface-muted); }
.card.is-out .card__title,
.card.is-out .price { color: var(--gray-400); }
.card.is-out .tag { color: var(--gray-600); background: var(--gray-200); }

.card.is-updated { animation: card-updated 1.4s var(--ease); }

.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.card__titles { min-width: 0; }
.card__title { font-size: var(--fs-lg); font-weight: 800; line-height: 1.5; color: var(--green-900); }
.card__subtitle {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-muted);
  text-align: right;         /* keep aligned with the Persian title */
  letter-spacing: 0.02em;
}
.card__meta { font-size: var(--fs-xs); color: var(--text-muted); }

.stock {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  font-size: var(--fs-xs);
  font-weight: 700;
  line-height: 1.9;
  border-radius: var(--radius-pill);
}
.stock::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.stock--in  { color: var(--success); background: var(--accent-soft); }
.stock--out { color: var(--danger); background: var(--danger-soft); }

.card__pricing {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 12px;
  background: var(--surface-muted);
  border-radius: var(--radius);
}
.card.is-out .card__pricing { background: var(--white); }

/* Retail size segmented control */
.size-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.size-toggle__btn {
  min-height: 36px;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.size-toggle__btn[aria-checked="true"] { color: var(--green-900); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }

.pricing-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.moq {
  padding: 1px 8px;
  font-weight: 700;
  color: #7A4B00;
  background: #FFF4DB;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.price {
  display: flex;
  align-items: baseline;
  gap: 6px;
  color: var(--green-900);
  font-variant-numeric: tabular-nums;
}
.price__value { font-size: var(--fs-xl); font-weight: 800; letter-spacing: -0.01em; }
.price__unit { font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted); }
.price__hint { font-size: var(--fs-xs); color: var(--text-muted); }

.btn--order {
  width: 100%;
  min-height: 48px;
  font-size: var(--fs-md);
  color: var(--white);
  background: var(--primary);
  box-shadow: 0 6px 14px rgba(30, 63, 32, 0.18);
}
.btn--order:hover:not(:disabled) { background: var(--whatsapp); }
.btn--order:disabled { background: var(--gray-200); color: var(--gray-600); box-shadow: none; opacity: 1; }

.site-footer {
  padding-block: 24px calc(24px + env(safe-area-inset-bottom));
  font-size: var(--fs-xs);
  text-align: center;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}

/* ==============================================================
 * ADMIN (admin.html)
 * ============================================================== */
.page-admin { background: var(--surface-muted); }

.admin-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-block: 12px;
  color: var(--white);
  background: var(--green-900);
  box-shadow: var(--shadow);
}
.admin-header__inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.admin-header__title { font-size: var(--fs-lg); font-weight: 800; }
.admin-header .btn--ghost { background: rgba(255,255,255,.1); color: var(--white); border-color: rgba(255,255,255,.2); }
.admin-header .btn--ghost:hover { background: rgba(255,255,255,.2); border-color: rgba(255,255,255,.3); }

.sync-status { display: flex; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--green-300); }

.admin { padding-block: 16px 64px; display: grid; gap: 16px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat__value { font-size: var(--fs-xl); font-weight: 800; color: var(--green-900); line-height: 1.4; }
.stat__label { font-size: var(--fs-xs); color: var(--text-muted); }

.toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toolbar .btn { width: 100%; }

.editor-list { display: grid; gap: 14px; }

.editor {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur), box-shadow var(--dur);
  animation: fade-up var(--dur) var(--ease);
}
.editor.is-dirty { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.editor.is-new { border-style: dashed; }
.editor.is-out .editor__title { color: var(--gray-400); }
.editor.is-removing { animation: fade-out var(--dur) var(--ease) forwards; }

.editor__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.editor__titles { min-width: 0; }
.editor__title { font-size: var(--fs-lg); font-weight: 800; color: var(--green-900); line-height: 1.5; overflow-wrap: anywhere; }
.editor__subtitle { font-size: var(--fs-xs); color: var(--text-muted); text-align: right; min-height: 1em; }

.editor__group {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.editor__group legend { padding-inline: 6px; font-size: var(--fs-sm); font-weight: 700; color: var(--green-700); }

.field-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field__label { font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted); }
.field__hint { font-size: var(--fs-xs); color: var(--green-700); }

.input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 16px;            /* prevents iOS zoom on focus */
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input:focus { outline: none; border-color: var(--green-700); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.input[dir="ltr"] { text-align: left; font-variant-numeric: tabular-nums; }

.field__affix { position: relative; display: flex; }
.field__affix .input { padding-right: 72px; } /* input is dir=ltr, suffix sits on the right */
.field__suffix {
  position: absolute;
  inset-block: 0;
  right: 12px;
  display: flex;
  align-items: center;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  pointer-events: none;
}

.tags--preview:empty { display: none; }
.tags--preview { margin-top: 6px; }

.editor__error {
  padding: 8px 12px;
  font-size: var(--fs-sm);
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
}

.editor__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.editor__actions .btn--primary { flex: 1 1 160px; }
.editor__delete { margin-inline-start: auto; }

/* Stock switch */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  cursor: pointer;
  font-size: var(--fs-xs);
  font-weight: 700;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track {
  position: relative;
  width: 46px;
  height: 26px;
  background: var(--gray-200);
  border-radius: var(--radius-pill);
  transition: background-color var(--dur) var(--ease);
}
.switch__track::after {
  content: '';
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  background: var(--white);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch__track { background: var(--green-700); }
.switch input:checked + .switch__track::after { transform: translateX(-20px); }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--accent); outline-offset: 2px; }
.switch__label { min-width: 48px; color: var(--success); }
.switch input:not(:checked) ~ .switch__label { color: var(--danger); }

/* Toasts */
.toast-region {
  position: fixed;
  inset-inline: var(--gutter);
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 50;
  display: grid;
  justify-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: 420px;
  padding: 10px 16px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--white);
  background: var(--green-900);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--dur) var(--ease);
}
.toast--error { background: var(--danger); }
.toast--info { background: var(--gray-600); }
.toast.is-leaving { animation: toast-out var(--dur) var(--ease) forwards; }

/* ==============================================================
 * Keyframes
 * ============================================================== */
@keyframes panel-in-left  { from { opacity: 0; transform: translateX(-16px); } }
@keyframes panel-in-right { from { opacity: 0; transform: translateX(16px); } }
@keyframes fade-up  { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade-out { to { opacity: 0; transform: scale(0.97); } }
@keyframes toast-in  { from { opacity: 0; transform: translateY(12px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(12px); } }
@keyframes live-ping { 75%, 100% { transform: scale(2.4); opacity: 0; } }
@keyframes card-updated {
  0%   { box-shadow: 0 0 0 0 rgba(163, 201, 168, 0.9); border-color: var(--green-700); }
  100% { box-shadow: 0 0 0 14px rgba(163, 201, 168, 0); }
}

/* ==============================================================
 * Responsive – progressively enhance from mobile
 * ============================================================== */
@media (min-width: 560px) {
  :root { --gutter: 24px; }
  .product-grid { grid-template-columns: repeat(2, 1fr); }
  .field-grid { grid-template-columns: repeat(2, 1fr); }
  .field--full { grid-column: 1 / -1; }
  .toolbar { display: flex; flex-wrap: wrap; }
  .toolbar .btn { width: auto; }
  .toolbar .btn--danger-ghost { margin-inline-start: auto; }
}

@media (min-width: 768px) {
  .site-header { padding-block: 32px 40px; }
  .site-header__inner { grid-template-columns: 1fr auto; align-items: center; }
  .brand__name { font-size: 2rem; }
  .tabs { max-width: 480px; margin-inline: auto; }
  .field-grid--3 { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1024px) {
  .product-grid { grid-template-columns: repeat(3, 1fr); gap: 18px; }
  .editor-list { grid-template-columns: repeat(2, 1fr); align-items: start; }
  .field-grid--3 { grid-template-columns: 1fr 1fr; }
  .field-grid--3 > .field:first-child { grid-column: 1 / -1; }
}

/* Motion safety: shorten (not remove) animations so animationend still fires. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
