/* Apple Design System — Lightweight, Self-Hosted, 100% RTL Persian */
:root {
  --bg: #f5f5f7;
  --bg-top: #ffffff;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --sidebar-bg: rgba(245, 245, 247, 0.78);
  --field-bg: rgba(118, 118, 128, 0.08);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #1d1d1f;
  --accent-hover: #000000;
  --blue: #0071e3;
  --green: #047857;
  --green-bg: rgba(16, 185, 129, 0.12);
  --amber: #b45309;
  --amber-bg: rgba(245, 158, 11, 0.14);
  --red: #dc2626;
  --red-bg: rgba(239, 68, 68, 0.12);
  --radius-card: 22px;
  --radius-sm: 12px;
  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.045), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-float: 0 22px 54px rgba(0, 0, 0, 0.08);
  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 0%, var(--bg-top) 0%, var(--bg) 70%);
  color: var(--text);
  font-family: 'Yekan', Tahoma, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  direction: rtl;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* Tactile instant pointer-down response */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: transform 100ms ease-out, background-color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-solid); color: var(--text); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { background: #f2f2f7; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: rgba(220, 38, 38, 0.2); }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.18); }
.btn-sm { padding: 7px 12px; font-size: 12px; border-radius: 10px; }
.btn-full { width: 100%; padding: 12px 18px; }

/* Translucent Materials */
.glass-card {
  background: var(--surface);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border: 1px solid var(--line);
  border-top-color: rgba(255, 255, 255, 0.8);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}
.glass-bar {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--line);
}

/* Auth & Installer Centered Shell */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
}
.auth-card {
  width: 100%;
  max-width: 440px;
  padding: 34px 30px;
  box-shadow: var(--shadow-float);
  animation: surfaceIn 340ms var(--ease-spring) both;
}
@keyframes surfaceIn {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.wayfind {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  font-size: 12px;
  color: var(--muted);
}
.wayfind a:hover { color: var(--text); }

/* Optical Typography */
.display-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}
.subtitle {
  margin: 0 0 22px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}

/* Forms */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #3a3a3c;
  margin-bottom: 6px;
}
.input, .select, .textarea {
  width: 100%;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--field-bg);
  font-size: 13px;
  transition: background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}
.input:focus, .select:focus, .textarea:focus {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.22);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12);
  outline: none;
}
.textarea { resize: vertical; min-height: 76px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }

/* Segmented Control */
.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(118, 118, 128, 0.1);
  margin-bottom: 18px;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}
.segmented button.is-active {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Status Alerts & Pills */
.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 16px;
}
.alert-err { background: var(--red-bg); color: var(--red); }
.alert-ok { background: var(--green-bg); color: var(--green); }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.pill-green { background: var(--green-bg); color: var(--green); }
.pill-amber { background: var(--amber-bg); color: var(--amber); }
.pill-red { background: var(--red-bg); color: var(--red); }
.pill-neutral { background: rgba(0, 0, 0, 0.06); color: var(--muted); }

/* Admin CMS Shell */
.cms-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}
.cms-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--sidebar-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-left: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.cms-brand {
  padding: 6px 10px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}
.cms-brand strong { display: block; font-size: 15px; }
.cms-brand span { font-size: 11.5px; color: var(--muted); }

.cms-nav-group { margin-bottom: 16px; }
.cms-nav-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
  padding: 0 10px 6px;
}
.cms-nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  margin-bottom: 3px;
  border-radius: 11px;
  border: 0;
  background: transparent;
  font-size: 12.5px;
  font-weight: 600;
  color: #3a3a3c;
  cursor: pointer;
  text-align: right;
  transition: background-color 140ms ease, color 140ms ease, transform 100ms ease-out;
}
.cms-nav-item:hover { background: rgba(0, 0, 0, 0.05); color: var(--text); }
.cms-nav-item:active { transform: scale(0.98); }
.cms-nav-item.is-active { background: var(--accent); color: #ffffff; }

.cms-main {
  padding: 28px 32px 60px;
  max-width: 1120px;
  width: 100%;
}
.cms-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}
.cms-section {
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow-card);
  margin-bottom: 18px;
}
.cms-section h2 { margin: 0 0 14px; font-size: 15px; font-weight: 700; }

.kpi-card {
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow-card);
}
.kpi-card .kpi-label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kpi-card .kpi-val { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }

.row-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.row-item:last-child { border-bottom: 0; padding-bottom: 0; }

.checkerboard {
  background-image: linear-gradient(45deg, #ececf0 25%, transparent 25%),
    linear-gradient(-45deg, #ececf0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ececf0 75%),
    linear-gradient(-45deg, transparent 75%, #ececf0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 22px;
  z-index: 9999;
  background: rgba(29, 29, 31, 0.92);
  backdrop-filter: blur(12px);
  color: #ffffff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
  animation: surfaceIn 240ms var(--ease-spring) both;
}
.toast.is-err { background: rgba(220, 38, 38, 0.94); }

.mobile-bar { display: none; }

@media (max-width: 900px) {
  .cms-shell { grid-template-columns: 1fr; }
  .cms-sidebar {
    position: fixed;
    inset: 0 0 0 auto;
    width: 260px;
    z-index: 90;
    transform: translateX(100%);
    transition: transform 280ms var(--ease-spring);
  }
  .cms-sidebar.is-open { transform: translateX(0); box-shadow: -12px 0 40px rgba(0,0,0,0.14); }
  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 80;
  }
  .cms-main { padding: 20px 16px 48px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .glass-card, .glass-bar, .cms-sidebar, .toast {
    background: #ffffff;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .toast { background: #1d1d1f; }
}
