:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --accent: #60a5fa;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --shadow: 0 18px 38px rgba(15, 23, 42, 0.12);
  --radius: 18px;
  --transition: 0.25s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: radial-gradient(circle at 20% 20%, #e5edff 0, #f3f4f6 30%, #e5e7eb 60%, #e2e8f0 100%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 18px;
  padding: 48px 20px 64px;
  direction: rtl;
}

/* احترام تفضيل تقليل الحركة */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* عنوان الصفحة + شرح سريع */
h1 {
  width: min(900px, 100%);
  text-align: center;
  font-size: clamp(1.15rem, 2.2vw, 1.7rem);
  line-height: 1.3;
  letter-spacing: 0.2px;
  margin-bottom: 6px;
  animation: fadeUp 500ms ease both;
}

body > p {
  width: min(900px, 100%);
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  animation: fadeUp 520ms ease both;
}

/* شريط البحث */
#input {
  width: min(720px, 100%);
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px solid rgba(37, 99, 235, 0.2);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(6px);
  font-size: 1rem;
  color: var(--text);
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.08);
  transition: var(--transition);
}

#input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 12px 34px rgba(37, 99, 235, 0.16);
  background: #fff;
}

/* زر البحث */
#research {
  padding: 14px 26px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  background: linear-gradient(120deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.4px;
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.35);
  transition: var(--transition);
}

#research:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.4);
}

#research:active {
  transform: translateY(0);
}

/* loading state: زر البحث */
body.is-loading #research {
  opacity: 0.9;
  filter: saturate(0.9);
}

/* منطقة النتائج */
#products {
  width: min(1100px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 18px;
  margin-top: 14px;
}

/* النتيجة كبطاقة (الرابط) */
#products a.result-card {
  display: block;
  border-radius: var(--radius);
  transform: translateY(8px);
  opacity: 0;
  transition: transform 420ms ease, opacity 420ms ease;
  will-change: transform, opacity;
}

#products a.result-card.show {
  transform: translateY(0);
  opacity: 1;
}

#products img,
#products img.result-img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  border: 1px solid rgba(148, 163, 184, 0.18);
  transition: transform var(--transition), box-shadow var(--transition);
}

#products img:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18);
}

/* زر الرجوع */
.back-link {
  width: min(720px, 100%);
  text-decoration: none;
}

.back-link button {
  width: 100%;
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid rgba(37, 99, 235, 0.22);
  background: rgba(255, 255, 255, 0.7);
  color: var(--primary-dark);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  transition: var(--transition);
}

.back-link button:hover {
  transform: translateY(-2px);
  background: #fff;
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.14);
}

/* رسائل الخطأ */
#products p {
  grid-column: 1 / -1;
  text-align: center;
  background: rgba(239, 68, 68, 0.08);
  color: #b91c1c;
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: var(--radius);
  padding: 16px;
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(248, 113, 113, 0.18);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 640px) {
  body {
    padding-top: 36px;
    gap: 14px;
  }

  #input {
    padding: 14px 16px;
  }

  #research {
    width: 100%;
    text-align: center;
  }

  #products {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  #products img {
    height: 140px;
  }
}

