/* Foodix — Stitch Design System — Mobile Optimized */
@import url('https://fonts.googleapis.com/earlyaccess/droidarabickufi.css');

/* تناسق الاستجابة: هاتف <768px | تابلت ≥768px (آيباد وضع طول ~810px) */
:root {
  --primary: #FF7A00;
  --primary-hover: #E67E22;
  --secondary: #008080;
  --background-light: #FFFFFF;
  --background-dark: #0F0F0F;
  --card-light: #FFFFFF;
  --card-dark: #1A1A1A;
  --radius: 24px;
  --radius-sm: 1.25rem;
  --transition: 0.2s ease;
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-top: env(safe-area-inset-top, 0px);
  /* Actual viewport height — set by JS for iOS Safari 100vh fix */
  --vh: 1vh;
  /* Social — like red */
  --like-red: #ef4444;
  /* عرض المحتوى والنوافذ — مستجيب لجميع القوالب */
  --content-max: 430px;
  --modal-max: 380px;
  --auth-form-max: 360px;
}
@media (min-width: 768px) {
  :root {
    --content-max: 560px;
    --modal-max: 480px;
    --auth-form-max: 420px;
  }
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  height: 100%;
  height: -webkit-fill-available;
  overflow-x: hidden;
  overflow-y: scroll;
}
/* Chrome mobile — إصلاح عدم عمل التمرير مع position:fixed */
@media (pointer: coarse) and (max-width: 640px) {
  html, body {
    overflow: scroll !important;
    overflow-x: hidden;
    touch-action: pan-y !important;
    overscroll-behavior-y: auto;
    z-index: 0;
    -webkit-overflow-scrolling: auto !important; /* touch يتعارض مع fixed في Chrome */
  }
main {
  overflow-x: hidden;
  overflow-y: visible;
  touch-action: pan-y !important;
}
  /* السماح بالتمرير عند اللمس على الروابط والأزرار */
  main a, main button {
    touch-action: manipulation;
  }
}
/* إخفاء المحتوى حتى تحميل الخطوط والأيقونات — يمنع ظهور كلمات غريبة */
html.fonts-loading body {
  opacity: 0;
  transition: opacity 0.2s ease;
}
html:not(.fonts-loading) body {
  opacity: 1;
}

/* إزالة المستطيل الأزرق عند التركيز على حقول الإدخال */
#message-input:focus,
#community-search-input:focus {
  outline: none !important;
  box-shadow: none !important;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Droid Arabic Kufi', sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: calc(var(--vh, 1vh) * 100);
  min-height: -webkit-fill-available;
  overflow-x: hidden;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: none;
  overscroll-behavior-y: auto;
  touch-action: pan-y;
  max-width: 100%;
}

/* الموقع للهواتف والتابلت — إظهار رسالة "مصمم للجوال" فقط على الشاشات الكبيرة (حواسيب) */
/* iPad 10 وضع طول: عرض ~810px — نسمح بالاستخدام. عتبة التابلت حتى 1024px */
.phones-only-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #fff 0%, #f8fafc 100%);
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.dark .phones-only-overlay {
  background: linear-gradient(135deg, #0f0f0f 0%, #1a1a1a 100%);
}
@media (min-width: 1025px) {
  .phones-only-overlay {
    display: flex !important;
  }
  body > *:not(#phones-only-overlay) {
    display: none !important;
  }
}
@media (max-width: 1024px) {
  .phones-only-overlay {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
    position: fixed !important;
    top: -99999px !important;
    left: -99999px !important;
    width: 1px !important;
    height: 1px !important;
    min-width: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    clip-path: inset(100%) !important;
  }
}
.phones-only-content {
  max-width: min(320px, 90vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
/* حاويات المحتوى المستجيب — استخدم مع Tailwind: max-w-[430px] md:max-w-[560px] للنص الرئيسي، max-w-[380px] md:max-w-[480px] للنوافذ */
.content-container { max-width: var(--content-max); margin-left: auto; margin-right: auto; }
.modal-container { max-width: var(--modal-max); }

/* صفحات الحساب — مناسبة لجميع الهواتف */
.auth-page {
  min-height: calc(var(--vh, 1vh) * 100);
  min-height: 100dvh;
  min-height: 100svh;
  padding-top: max(1rem, env(safe-area-inset-top, 0));
  padding-bottom: max(1rem, env(safe-area-inset-bottom, 0));
  padding-left: max(1rem, env(safe-area-inset-left, 0));
  padding-right: max(1rem, env(safe-area-inset-right, 0));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: auto;
}
/* صفحة استكمال البروفايل — إصلاح السكرول في Chrome: الاعتماد على تمرير المستند */
.profile-form-touch.auth-page {
  min-height: auto;
  overflow-y: visible;
  overscroll-behavior-y: auto;
}
/* تأكيد أن body هو حاوية التمرير في صفحة البروفايل (Chrome) */
body.page-profile-form {
  overflow-y: auto !important;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.auth-input, .auth-btn {
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
/* تحسين اللمس في صفحات الحساب — أزرار وروابط تستجيب فوراً */
.auth-page button, .auth-page .auth-btn, .auth-page a {
  touch-action: manipulation;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
/* السماح بالتمرير العمودي عند لمس حقول النموذج في صفحات الحساب */
.auth-page input, .auth-page select, .auth-page textarea {
  touch-action: manipulation;
}

/* Touch targets — minimum 44px */
button, a, input, select, textarea {
  touch-action: manipulation;
}

/* Prevent zoom on input focus (iOS) — 16px minimum */
@media (max-width: 639px) {
  input:not([type="hidden"]):not(.otp-input), select, textarea {
    font-size: 16px !important;
  }
  .otp-input {
    font-size: 24px !important; /* OTP stays large for readability */
  }
}

/* المحتوى الرئيسي — ارتفاع صحيح على الهواتف (iOS Safari) */
/* منع التمرير الأفقي — التصميم ثابت العرض */
main {
  overflow-x: hidden;
  overflow-y: visible;
  touch-action: inherit;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 639px) {
  main.min-h-main {
    min-height: calc(var(--vh, 1vh) * 100);
    min-height: 100dvh;
  }
}

/* العناصر المخفية — لا تعترض الأحداث أبداً (حل مشكلة نوافذ/طبقات غير مرئية) */
.hidden[style*="position: fixed"],
.hidden[style*="position:fixed"],
[class*="fixed"].hidden,
#comments-modal.hidden,
#comments-modal-overlay.hidden,
#missing-ingredients-modal.hidden,
#loading-modal.htmx-indicator {
  pointer-events: none !important;
}

/* إخفاء السكرول بار نهائياً */
* {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
*::-webkit-scrollbar {
  display: none;
}

.hide-scrollbar {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.hide-scrollbar::-webkit-scrollbar {
  display: none;
}

/* صف القصص — من حافة الشاشة لحافتها */
.stories-row-full-bleed {
  width: 100vw;
  max-width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
}

/* صفحة المجتمع: البوست يملأ عرض الصفحة — إزالة الحدود الجانبية للبطاقات */
.community-feed .post-card {
  border-left-width: 0;
  border-right-width: 0;
}

.recipe-card-gradient {
  background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.8) 100%);
  pointer-events: none;
}

/* أيقونات المنشور — Bootstrap Icons بحجم ووضوح مناسب */
.post-like-btn .bi,
.post-comments-open-btn .bi,
.post-share-btn .bi,
.post-save-btn .bi {
  font-size: 1.25rem;
  transition: transform 0.15s ease, color 0.15s ease;
}
.post-like-btn:active .bi,
.post-comments-open-btn:active .bi,
.post-share-btn:active .bi,
.post-save-btn:active .bi {
  transform: scale(0.9);
}

/* Header & Nav — transparent at start, blur on scroll */
.main-header.header-scrolled {
  background: rgba(255, 255, 255, 0.85) !important;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom-color: rgba(226, 232, 240, 0.6) !important;
}
.dark .main-header.header-scrolled {
  background: rgba(15, 15, 15, 0.9) !important;
  border-bottom-color: rgba(51, 65, 85, 0.5) !important;
}
.bottom-nav-transition {
  transition: background 0.3s, backdrop-filter 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.bottom-nav-base {
  background: rgba(0, 128, 128, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}
.bottom-nav-transition.nav-scrolled {
  background: rgba(0, 128, 128, 0.9) !important;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top-color: rgba(255, 255, 255, 0.25) !important;
  box-shadow: 0 -8px 30px rgba(0, 128, 128, 0.3);
}

/* Background icons layer — لا تعترض اللمس أبداً */
.bg-icons-layer,
.bg-icons-layer * {
  pointer-events: none !important;
}

/* Background food icons — أكبر وأكثر شفافية */
.bg-icon {
  position: absolute;
  font-size: 32px;
  opacity: 0.18;
  color: var(--primary);
  animation: bgIconFloat 4s ease-in-out infinite;
}
.dark .bg-icon { opacity: 0.12; }
.bg-icon-right { right: 8px; }
.bg-icon-left { left: 8px; }
.bg-icon-1 { top: 18%; color: var(--primary); animation-delay: 0s; }
.bg-icon-2 { top: 42%; color: var(--secondary); animation-delay: 0.7s; }
.bg-icon-3 { top: 66%; color: var(--primary); animation-delay: 1.4s; }
.bg-icon-4 { top: 22%; color: var(--secondary); animation-delay: 0.3s; }
.bg-icon-5 { top: 48%; color: var(--primary); animation-delay: 1s; }
.bg-icon-6 { top: 72%; color: var(--secondary); animation-delay: 1.7s; }
@keyframes bgIconFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* Buttons */
.btn-primary {
  background: var(--primary);
  color: white;
  font-weight: 700;
  border-radius: var(--radius-sm);
  padding: 0.875rem 1.5rem;
  min-height: 44px;
  border: none;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 24px rgba(255, 122, 0, 0.25);
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 28px rgba(255, 122, 0, 0.35);
  background: var(--primary-hover);
}
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: white;
  color: var(--secondary);
  border: 2px solid var(--secondary);
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.5rem;
  min-height: 44px;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn-secondary:hover {
  background: var(--secondary);
  color: white;
}

/* Show prompt button — شفاف مع blur */
.show-prompt-btn {
  background: rgba(255, 255, 255, 0.5) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(226, 232, 240, 0.6) !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
}
.dark .show-prompt-btn {
  background: rgba(26, 26, 26, 0.5) !important;
  border-color: rgba(51, 65, 85, 0.5) !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.show-prompt-btn:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
}
.dark .show-prompt-btn:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* Chat form — modern design */
.chat-form-modern {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04), 0 0 0 1px rgba(255, 122, 0, 0.06);
  overflow: hidden;
}
.dark .chat-form-modern {
  background: rgba(26, 26, 26, 0.95);
  border-color: rgba(51, 65, 85, 0.6);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 128, 128, 0.1);
}
.chat-form-inner {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-input-wrap {
  position: relative;
}
.chat-textarea {
  width: 100%;
  min-height: 88px;
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.5;
  caret-color: var(--primary);
  line-height: 1.4;
  color: #0f172a;
  background: #f8fafc;
  border: none;
  border-radius: 14px;
  resize: none;
  outline: none;
  transition: background 0.2s, box-shadow 0.2s;
}
.chat-textarea::placeholder {
  color: rgba(148, 163, 184, 0.5);
  font-size: 13px;
}
.chat-textarea:focus {
  background: #fff;
  box-shadow: 0 0 0 1px rgba(255, 122, 0, 0.12);
}
.dark .chat-textarea {
  color: #f1f5f9;
  background: rgba(51, 65, 85, 0.4);
}
.dark .chat-textarea::placeholder {
  color: rgba(100, 116, 139, 0.5);
  font-size: 13px;
}
.dark .chat-textarea:focus {
  background: rgba(51, 65, 85, 0.6);
  box-shadow: 0 0 0 1px rgba(255, 122, 0, 0.15);
}
.chat-submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  color: white;
  background: var(--primary);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.chat-submit-btn:hover {
  background: #e66d00;
  box-shadow: 0 8px 20px rgba(255, 122, 0, 0.35);
  transform: translateY(-1px);
}
.chat-submit-btn:active {
  transform: translateY(0);
}
.chat-submit-btn .material-symbols-rounded {
  font-size: 20px;
}

/* HTMX */
.htmx-request .htmx-indicator,
.htmx-indicator.htmx-request { display: flex !important; align-items: center; justify-content: center; pointer-events: auto; }
.htmx-indicator { display: none; pointer-events: none; }
#loading-modal.htmx-indicator { pointer-events: none; }
#loading-modal.htmx-indicator.htmx-request { display: flex !important; align-items: center; justify-content: center; pointer-events: auto; }

/* Loading dots animation */
.loading-dot {
  animation: loadingBounce 0.6s ease-in-out infinite;
  opacity: 0.4;
}
@keyframes loadingBounce {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50% { transform: translateY(-8px); opacity: 1; }
}

/* RTL */
[dir="rtl"] .phase { text-align: right; }
.timer-display { font-variant-numeric: tabular-nums; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-fade-in { animation: fadeIn 0.4s ease-out forwards; }

/* Post card — بطاقة المشاركة في المجتمع */
.post-card {
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: box-shadow var(--transition);
}
.dark .post-card {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.post-card:hover {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
}
.dark .post-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* Post actions — شريط أزرار الإجراءات */
.post-actions {
  min-height: 48px;
  gap: 4px;
}
.post-actions .icon-btn {
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  transition: background 0.2s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.post-actions .icon-btn:hover {
  background: rgba(148, 163, 184, 0.2);
}
.dark .post-actions .icon-btn:hover {
  background: rgba(148, 163, 184, 0.12);
}
.post-actions .icon-btn:active {
  transform: scale(0.92);
}
.post-actions .material-symbols-rounded {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  font-size: 22px !important;
}
.post-actions .material-symbols-rounded.fill-current {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* Icon button — زر أيقونة عام */
.icon-btn {
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover {
  background: rgba(148, 163, 184, 0.12);
}
.icon-btn:active {
  transform: scale(0.98);
}

/* Comment input — حقل التعليق */
.comment-input {
  min-height: 40px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.4;
  border-radius: 12px;
  caret-color: var(--primary);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.comment-input:focus {
  outline: none;
  box-shadow: 0 0 0 1px rgba(255, 122, 0, 0.2);
}

/* Load more button */
.load-more-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Bottom sheet modal — نافذة منبثقة من الأسفل */
.comments-modal {
  pointer-events: auto;
}
.comments-modal.hidden {
  pointer-events: none;
}
.comments-modal:not(.hidden) {
  transform: translateY(0);
}
.comments-modal.hidden {
  transform: translateY(100%);
}
