/* ===========================================================
   فروشگاه قطعات خودرو — Stylesheet
   RTL-first, logical properties used throughout so the layout
   stays correct in a right-to-left document.
   =========================================================== */

:root {
  --font-main: 'Vazirmatn', Tahoma, sans-serif;

  /* Light theme (default) */
  --bg: #f6f7fb;
  --bg-elevated: #ffffff;
  --bg-subtle: #eef0f6;
  --text: #1a1d29;
  --text-muted: #5c6178;
  --border: #e2e4ee;
  --primary: #d6392b;
  --primary-hover: #b82f22;
  --primary-contrast: #ffffff;
  --accent: #1f6feb;
  --success-bg: #e6f6ec;
  --success-text: #1a7f43;
  --error-bg: #fdecea;
  --error-text: #c0392b;
  --shadow: 0 1px 2px rgba(20, 22, 40, 0.04), 0 4px 16px rgba(20, 22, 40, 0.06);
  --shadow-lg: 0 8px 30px rgba(20, 22, 40, 0.12);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --transition: 180ms ease;
}

[data-theme='dark'] {
  --bg: #0f1117;
  --bg-elevated: #171a24;
  --bg-subtle: #1e2230;
  --text: #eef0f6;
  --text-muted: #9ba1b8;
  --border: #2a2e3f;
  --primary: #ef5b4c;
  --primary-hover: #f37363;
  --primary-contrast: #14161f;
  --accent: #5b9dff;
  --success-bg: #113322;
  --success-text: #4ad991;
  --error-bg: #3a1a18;
  --error-text: #ff8a7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

body {
  margin: 0;
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background var(--transition), color var(--transition);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 1180px;
  margin-inline: auto;
  padding-inline: 20px;
}

main.container {
  flex: 1;
  padding-block: 32px 60px;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------- Header ---------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(8px);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  padding-block: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.15rem;
  white-space: nowrap;
}

.brand-icon {
  font-size: 1.4rem;
}

.main-nav {
  display: flex;
  gap: 4px;
  margin-inline-start: auto;
  flex-wrap: wrap;
}

.main-nav a {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
  transition: background var(--transition), color var(--transition);
}

.main-nav a:hover {
  background: var(--bg-subtle);
  color: var(--text);
}

.main-nav a.active {
  background: var(--primary);
  color: var(--primary-contrast);
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: 999px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1.1rem;
  position: relative;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--primary);
}

.theme-icon {
  position: absolute;
  transition: opacity var(--transition), transform var(--transition);
}

.theme-icon-moon {
  opacity: 0;
  transform: scale(0.6) rotate(-30deg);
}

[data-theme='dark'] .theme-icon-sun {
  opacity: 0;
  transform: scale(0.6) rotate(30deg);
}

[data-theme='dark'] .theme-icon-moon {
  opacity: 1;
  transform: scale(1) rotate(0);
}

[data-theme='light'] .theme-icon-sun {
  opacity: 1;
  transform: scale(1) rotate(0);
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform 100ms ease;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--bg-subtle);
}

.btn-danger {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: transparent;
}

.btn-danger:hover {
  background: var(--error-text);
  color: #fff;
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

/* ---------------- Hero ---------------- */
.hero {
  text-align: center;
  padding-block: 20px 32px;
}

.hero h1 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  margin-block-end: 8px;
}

.hero p {
  color: var(--text-muted);
  font-size: 1.05rem;
}

/* ---------------- Filters ---------------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  margin-block-end: 20px;
}

.filter-search {
  flex: 2 1 240px;
}

.filter-select {
  flex: 1 1 160px;
}

input[type='text'],
input[type='number'],
input[type='password'],
input[type='file'],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
select:focus,
textarea:focus,
.theme-toggle:focus-visible,
.btn:focus-visible,
a:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

.results-meta {
  color: var(--text-muted);
  margin-block-end: 14px;
  font-size: 0.9rem;
}

/* ---------------- Product grid ---------------- */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}

.product-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  display: flex;
  flex-direction: column;
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.product-image {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--bg-subtle);
  overflow: hidden;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-image-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 2.4rem;
  color: var(--text-muted);
  opacity: 0.5;
}

.product-image-placeholder-lg {
  font-size: 4rem;
  aspect-ratio: 4/3;
  border-radius: var(--radius-md);
}

.badge {
  position: absolute;
  top: 10px;
  inset-inline-end: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-out {
  background: var(--error-bg);
  color: var(--error-text);
}

.product-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.product-category {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
}

.product-name {
  margin: 0;
  font-size: 1rem;
  line-height: 1.4;
}

.product-brand {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.product-footer {
  margin-top: auto;
  padding-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.product-price {
  font-weight: 800;
  font-size: 0.98rem;
}

.product-stock {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}

.in-stock {
  background: var(--success-bg);
  color: var(--success-text);
}

.out-stock {
  background: var(--error-bg);
  color: var(--error-text);
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* ---------------- Breadcrumb ---------------- */
.breadcrumb {
  display: flex;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-block-end: 18px;
  flex-wrap: wrap;
}

.breadcrumb a:hover {
  color: var(--primary);
}

/* ---------------- Product detail ---------------- */
.product-detail {
  display: grid;
  grid-template-columns: minmax(260px, 420px) 1fr;
  gap: 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.product-detail-image img {
  border-radius: var(--radius-md);
  width: 100%;
  object-fit: cover;
}

.product-detail-info h1 {
  margin-block: 6px 10px;
  font-size: 1.6rem;
}

.product-detail-brand,
.product-detail-sku,
.product-detail-models {
  margin: 4px 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.product-detail-price-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-block: 18px;
}

.product-detail-price {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
}

.product-description {
  margin-block-start: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.product-description h2 {
  font-size: 1.05rem;
  margin-block-end: 8px;
}

.product-description p {
  color: var(--text-muted);
  white-space: pre-line;
}

/* ---------------- Auth ---------------- */
.auth-page {
  display: flex;
  justify-content: center;
  padding-block: 30px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  font-size: 1.4rem;
  margin-block-end: 4px;
}

.auth-sub {
  color: var(--text-muted);
  margin-block-end: 20px;
  font-size: 0.9rem;
}

/* ---------------- Forms (shared) ---------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-block-end: 16px;
}

.form-group label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 4px 20px;
}

.form-group-full {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-block-start: 10px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-block-start: 8px;
}

.checkbox-label input {
  width: auto;
}

.current-image {
  margin-block-start: 10px;
}

.current-image img {
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* ---------------- Alerts ---------------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-block-end: 16px;
  font-weight: 600;
}

.alert-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.alert-success {
  background: var(--success-bg);
  color: var(--success-text);
}

/* ---------------- Admin ---------------- */
.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-block-end: 20px;
}

.admin-toolbar h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

.admin-sub {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.admin-toolbar-actions {
  display: flex;
  gap: 10px;
}

.admin-search {
  display: flex;
  gap: 8px;
  margin-block-end: 18px;
  max-width: 420px;
}

.admin-table-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: auto;
  box-shadow: var(--shadow);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.admin-table th,
.admin-table td {
  padding: 12px 14px;
  text-align: start;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  vertical-align: middle;
}

.admin-table th {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--bg-subtle);
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.admin-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.admin-thumb-placeholder {
  display: grid;
  place-items: center;
  background: var(--bg-subtle);
  font-size: 1.2rem;
}

.admin-row-actions {
  display: flex;
  gap: 8px;
}

.admin-row-actions form {
  display: inline;
}

.admin-form-page {
  max-width: 860px;
}

.part-form {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

/* ---------------- Error page ---------------- */
.error-page {
  text-align: center;
  padding-block: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.error-icon {
  font-size: 3rem;
}

/* ---------------- Footer ---------------- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  margin-top: 40px;
}

.footer-inner {
  padding-block: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer-sub {
  margin-block-start: 4px;
  font-size: 0.78rem;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 780px) {
  .product-detail {
    grid-template-columns: 1fr;
  }

  .header-inner {
    flex-wrap: wrap;
  }

  .main-nav {
    order: 3;
    margin-inline-start: 0;
    width: 100%;
  }
}

@media (max-width: 520px) {
  .admin-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-toolbar-actions {
    justify-content: space-between;
  }
}
