/*
 * مازند موتور بریمانی — استایل کامپوننت‌ها
 * Reusable button, input, badge, card, etc. classes
 * Import after colors_and_type.css
 */

/* ─── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-weight: var(--weight-semibold);
  border: none;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background var(--duration-fast) var(--easing-default),
              color var(--duration-fast) var(--easing-default),
              box-shadow var(--duration-fast) var(--easing-default),
              transform var(--duration-fast) var(--easing-default);
}
.btn:focus-visible { outline: none; box-shadow: var(--shadow-glow-brand); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 1em; height: 1em; flex-shrink: 0; }

/* sizes */
.btn-sm { height: 32px; padding: 0 12px; font-size: var(--text-sm); border-radius: var(--radius-md); }
.btn-md { height: 40px; padding: 0 16px; font-size: var(--text-sm); border-radius: var(--radius-md); }
.btn-lg { height: 48px; padding: 0 20px; font-size: var(--text-base); border-radius: var(--radius-md); }
.btn-xl { height: 56px; padding: 0 24px; font-size: var(--text-md); border-radius: var(--radius-lg); }

/* variants */
.btn-primary {
  background: var(--brand-500);
  color: var(--text-on-brand);
}
.btn-primary:hover:not(:disabled) { background: var(--brand-600); }
.btn-primary:active:not(:disabled) { background: var(--brand-700); }

.btn-secondary {
  background: var(--brand-100);
  color: var(--brand-700);
}
.btn-secondary:hover:not(:disabled) { background: var(--brand-200); }
.btn-secondary:active:not(:disabled) { background: var(--brand-300); }

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  box-shadow: inset 0 0 0 1px var(--border-default);
}
.btn-outline:hover:not(:disabled) { background: var(--bg-hover); box-shadow: inset 0 0 0 1px var(--border-strong); }

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); }

.btn-danger {
  background: var(--danger-500);
  color: white;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-600); }
.btn-danger:focus-visible { box-shadow: var(--shadow-glow-danger); }

.btn-accent {
  background: var(--accent-500);
  color: white;
}
.btn-accent:hover:not(:disabled) { background: var(--accent-600); }
.btn-accent:focus-visible { box-shadow: var(--shadow-glow-accent); }

.btn-icon {
  padding: 0;
  width: 40px;
}
.btn-icon.btn-sm { width: 32px; }
.btn-icon.btn-lg { width: 48px; }

/* ─── Inputs ──────────────────────────────────────────────────── */
.input, .select, .textarea {
  display: block;
  width: 100%;
  height: 40px;
  padding: 0 14px;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--duration-fast) var(--easing-default),
              box-shadow var(--duration-fast) var(--easing-default);
}
.textarea { height: auto; padding: 10px 14px; min-height: 88px; resize: vertical; line-height: var(--leading-normal); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-glow-brand);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--neutral-100);
  color: var(--text-disabled);
  cursor: not-allowed;
}
.input::placeholder, .textarea::placeholder { color: var(--text-tertiary); }
.input.invalid, .select.invalid, .textarea.invalid { border-color: var(--danger-500); }
.input.invalid:focus { box-shadow: var(--shadow-glow-danger); }

.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.input-group .label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.input-group .helper { font-size: var(--text-xs); color: var(--text-tertiary); }
.input-group .helper.error { color: var(--danger-600); }

.input-wrap {
  position: relative;
}
.input-wrap .input { padding-inline-start: 40px; }
.input-wrap > svg, .input-wrap > .icon {
  position: absolute;
  inset-inline-start: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  pointer-events: none;
}

/* ─── Badges / Chips ──────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 10px;
  height: 22px;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; }
.badge-brand { background: var(--brand-100); color: var(--brand-700); }
.badge-accent { background: var(--accent-100); color: var(--accent-700); }
.badge-success { background: var(--success-50); color: var(--success-700); }
.badge-warning { background: var(--warning-50); color: var(--warning-700); }
.badge-danger { background: var(--danger-50); color: var(--danger-700); }
.badge-info { background: var(--info-50); color: var(--info-700); }
.badge-neutral { background: var(--neutral-100); color: var(--neutral-700); }
.badge-outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border-default); color: var(--text-secondary); }
.badge-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* ─── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--duration-fast) var(--easing-default);
}
.card-hover:hover { box-shadow: var(--shadow-md); }
.card-padded { padding: var(--space-6); }
.card-padded-sm { padding: var(--space-4); }
.card-flat { box-shadow: none; border: 1px solid var(--border-subtle); }

/* ─── Avatar ──────────────────────────────────────────────────── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-100);
  color: var(--brand-700);
  font-weight: var(--weight-semibold);
  font-family: var(--font-sans);
  border-radius: var(--radius-full);
  overflow: hidden;
  flex-shrink: 0;
}
.avatar-xs { width: 24px; height: 24px; font-size: 10px; }
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-md { width: 40px; height: 40px; font-size: 14px; }
.avatar-lg { width: 56px; height: 56px; font-size: 18px; }
.avatar-xl { width: 80px; height: 80px; font-size: 24px; }

/* ─── Tabs ────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0;
}
.tab {
  position: relative;
  padding: 10px 16px;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: color var(--duration-fast) var(--easing-default);
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--brand-700); font-weight: var(--weight-semibold); }
.tab.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  inset-inline: 8px;
  height: 2px;
  background: var(--brand-500);
  border-radius: 2px 2px 0 0;
}

/* ─── Toggle ──────────────────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--neutral-300);
  border-radius: 999px;
  transition: background var(--duration-fast) var(--easing-default);
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  inset-inline-end: 2px;
  top: 2px;
  background: white;
  border-radius: 50%;
  transition: transform var(--duration-fast) var(--easing-default);
  box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle-slider { background: var(--brand-500); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ─── Checkbox / Radio ────────────────────────────────────────── */
.check, .radio {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-surface);
  cursor: pointer;
  transition: background var(--duration-fast) var(--easing-default),
              border-color var(--duration-fast) var(--easing-default);
  position: relative;
}
.check { border-radius: 5px; }
.radio { border-radius: 50%; }
.check:checked, .radio:checked { background: var(--brand-500); border-color: var(--brand-500); }
.check:checked::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  top: 2px;
  left: 5px;
}
.radio:checked::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  background: white;
  border-radius: 50%;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

/* ─── Sidebar nav item ────────────────────────────────────────── */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 14px;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--duration-fast) var(--easing-default),
              color var(--duration-fast) var(--easing-default);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: var(--brand-50);
  color: var(--brand-700);
  font-weight: var(--weight-semibold);
}
.nav-item .badge { margin-inline-start: auto; }

/* ─── Tables ──────────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-family: var(--font-sans);
}
.table th {
  text-align: start;
  font-weight: var(--weight-semibold);
  font-size: var(--text-xs);
  text-transform: none;
  color: var(--text-tertiary);
  padding: 12px 16px;
  background: var(--neutral-50);
  border-bottom: 1px solid var(--border-subtle);
}
.table th:first-child { border-start-start-radius: var(--radius-md); }
.table th:last-child { border-start-end-radius: var(--radius-md); }
.table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--duration-fast) var(--easing-default); }
.table tbody tr:hover { background: var(--bg-hover); }

/* ─── Divider ─────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border-subtle); border: 0; margin: var(--space-4) 0; }

/* ─── Stat (KPI) card body ────────────────────────────────────── */
.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.stat-label { font-size: var(--text-sm); color: var(--text-secondary); font-weight: var(--weight-medium); }
.stat-value { font-family: var(--font-display); font-size: var(--text-3xl); font-weight: var(--weight-bold); color: var(--text-primary); line-height: 1; }
.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}
.stat-delta.up { color: var(--success-700); background: var(--success-50); }
.stat-delta.down { color: var(--danger-700); background: var(--danger-50); }
.stat-delta.flat { color: var(--text-secondary); background: var(--neutral-100); }

/* ─── Utility helpers ─────────────────────────────────────────── */
.hstack { display: flex; align-items: center; gap: var(--space-3); }
.vstack { display: flex; flex-direction: column; gap: var(--space-3); }
.spacer { flex: 1; }
.center { display: flex; align-items: center; justify-content: center; }

/* ─── جدول‌های واکنش‌گرا: اسکرول افقی روی موبایل ─── */
@media (max-width: 760px) {
  .card:has(.table) { overflow-x: auto !important; }
  table.table { min-width: 560px; }
}

/* ─── حالت focus بصری برای تب‌ها ─── */
.ptab:focus-visible,
.tab:focus-visible {
  outline: none;
  box-shadow: var(--shadow-glow-brand);
  border-radius: var(--radius-sm);
}

/* ─── بازخورد اعتبارسنجی فرم (پس از تعامل کاربر) ─── */
.input:user-invalid,
.select:user-invalid,
.textarea:user-invalid {
  box-shadow: inset 0 0 0 1.5px var(--danger-500);
  border-color: var(--danger-500);
}

/* ─── مقایسهٔ کالا (صفحهٔ جزئیات محصول) ─── */
.compare-heads { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: stretch; }
.compare-heads > div { padding: 18px; border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); }
@media (max-width: 600px) { .compare-heads { grid-template-columns: 1fr; } .compare-pick { min-height: 120px; } }
.compare-slot { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.compare-pick { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 180px; border: 2px dashed var(--border-strong); border-radius: var(--radius-lg); background: transparent; color: var(--brand-600); font-weight: 700; font-size: 14px; cursor: pointer; transition: border-color .15s, background .15s; }
.compare-pick:hover { border-color: var(--brand-500); background: var(--brand-50); }
.compare-table { width: 100%; border-collapse: collapse; min-width: 520px; }
.compare-table th, .compare-table td { padding: 12px 14px; text-align: center; border-bottom: 1px solid var(--border-subtle); font-size: 13.5px; }
.compare-table thead th { background: var(--bg-subtle); font-weight: 700; font-size: 13px; }
.compare-table thead th:first-child { width: 130px; }
.compare-table td.lbl { color: var(--text-tertiary); font-weight: 600; background: var(--bg-subtle); text-align: start; }

/* ─── مودال انتخاب کالا برای مقایسه ─── */
.compare-modal-overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(15,18,20,0.5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.compare-modal { width: 100%; max-width: 760px; background: var(--bg-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); overflow: hidden; }
.compare-modal-head { display: flex; align-items: center; justify-content: space-between; flex-direction: row-reverse; padding: 16px 18px; border-bottom: 1px solid var(--border-subtle); }
.compare-modal-search { padding: 14px 18px; border-bottom: 1px solid var(--border-subtle); }
.compare-modal-search .input { padding-inline-start: 40px; }
.compare-modal-search > svg { position: absolute; inset-inline-start: 32px; top: 50%; transform: translateY(-50%); }
.compare-modal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 18px; max-height: 60vh; overflow-y: auto; }
.compare-pick-card { display: flex; flex-direction: column; gap: 8px; text-align: start; padding: 12px; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); background: var(--bg-surface); cursor: pointer; transition: border-color .15s, box-shadow .15s; min-height: 220px; }
.compare-pick-card:hover { border-color: var(--brand-500); box-shadow: var(--shadow-sm); }
.compare-pick-card .thumb { width: 100%; height: 110px; border-radius: var(--radius-md); overflow: hidden; }
.compare-pick-card .nm { font-size: 12.5px; font-weight: 700; line-height: 1.6; color: var(--text-primary); }
@media (max-width: 680px) { .compare-modal-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 460px) { .compare-modal-grid { grid-template-columns: 1fr; } }

/* ─── گفت‌وگوی تأیید (`<x-confirm-dialog>`) ───
   عنصر بومی <dialog> است: وسط‌چین‌شدن، لایهٔ پشت، Esc و قفل فوکوس از مرورگر می‌آید و
   اینجا فقط پوستهٔ بصری نوشته می‌شود. بستهٔ آن display:none است، پس داخل هر ردیفِ
   فلکس هم بگذاریمش چیدمان را تکان نمی‌دهد. */
.confirm-dlg { width: min(400px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-xl); }
.confirm-dlg::backdrop { background: rgba(15,18,20,0.5); }
.confirm-dlg__title { font-family: var(--font-display); font-size: 17px; font-weight: 800; margin: 0 0 8px; }
.confirm-dlg__msg { font-size: 13.5px; line-height: 1.9; color: var(--text-secondary); margin: 0 0 20px; }
.confirm-dlg__acts { display: flex; gap: 8px; }
.confirm-dlg__acts form { flex: 1; }
.confirm-dlg__acts .btn { width: 100%; justify-content: center; }
