/*
 * Academy — Base Application Styles
 * Note: fonts.css and _variables.css must be linked BEFORE this file.
 */

/* ============================================ */
/* RESET & BASE                                  */
/* ============================================ */

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  font-feature-settings: "tnum" 0;
}

body {
  margin: 0;
  font-family: var(--font-ar);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

html[lang="en"] body {
  font-family: var(--font-en);
  line-height: 1.6;
}

html[dir="rtl"] body {
  text-align: right;
}

/* ============================================ */
/* TYPOGRAPHY                                    */
/* ============================================ */

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--space-4) 0;
  line-height: var(--leading-tight);
  font-weight: var(--font-bold);
  color: var(--gray-900);
}

h1 { font-size: var(--text-5xl); font-weight: var(--font-extra); }
h2 { font-size: var(--text-4xl); }
h3 { font-size: var(--text-3xl); }
h4 { font-size: var(--text-2xl); }
h5 { font-size: var(--text-xl); }
h6 { font-size: var(--text-lg); }

p {
  margin: 0 0 var(--space-4) 0;
  color: var(--text-secondary);
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--duration-base) var(--ease-out);
}

a:hover {
  color: var(--text-link-h);
}

/* الأرقام بـ tabular-nums للأسعار والتقارير */
.tnum, .price, table td.num {
  font-feature-settings: "tnum" 1;
  font-variant-numeric: tabular-nums;
}

/* ============================================ */
/* LAYOUT HELPERS                                */
/* ============================================ */

.container {
  width: 100%;
  max-width: var(--container-lg);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

@media (min-width: 1536px) {
  .container { max-width: var(--container-xl); }
}

main { flex: 1; }

.section {
  padding: var(--space-16) 0;
}

.section--soft { background: var(--bg-soft); }

/* ============================================ */
/* BUTTONS                                       */
/* ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.625rem 1.25rem;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  line-height: 1.4;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--duration-base) var(--ease-out);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-lg { padding: 0.875rem 1.75rem; font-size: var(--text-lg); }
.btn-sm { padding: 0.4rem 0.85rem; font-size: var(--text-sm); }

.btn-primary {
  background: var(--blue-500);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--blue-600); box-shadow: var(--shadow-md); color: #fff; }

.btn-success,
.btn-cta {
  background: var(--green-400);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-success:hover,
.btn-cta:hover { background: var(--green-500); box-shadow: var(--shadow-green); color: #fff; }

.btn-outline {
  background: transparent;
  color: var(--blue-500);
  border-color: var(--blue-500);
}
.btn-outline:hover { background: var(--blue-50); color: var(--blue-600); }

.btn-ghost {
  background: transparent;
  color: var(--gray-700);
}
.btn-ghost:hover { background: var(--gray-100); }

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

/* ============================================ */
/* CARDS                                         */
/* ============================================ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  transition: box-shadow var(--duration-base) var(--ease-out),
              transform var(--duration-base) var(--ease-out);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-elevated {
  box-shadow: var(--shadow);
}

/* ============================================ */
/* BADGES                                        */
/* ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.2rem 0.625rem;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  border-radius: var(--radius-full);
  background: var(--gray-100);
  color: var(--gray-700);
}

.badge-primary { background: var(--blue-500); color: #fff; }
.badge-success { background: var(--green-400); color: #fff; }
.badge-new     { background: var(--green-400); color: #fff; }
.badge-hot     { background: var(--amber-500); color: #fff; }
.badge-discount { background: var(--coral-500); color: #fff; }
.badge-free    { background: var(--success); color: #fff; }
.badge-certified {
  background: var(--blue-500);
  color: #fff;
}

/* ============================================ */
/* PROGRESS                                      */
/* ============================================ */

.progress {
  width: 100%;
  height: 8px;
  background: var(--gray-200);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--green-400);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out);
}

/* ============================================ */
/* FORMS                                         */
/* ============================================ */

.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
textarea,
select {
  display: block;
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-family: inherit;
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--gray-900);
  background: #fff;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  transition: border-color var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out);
}

.form-control:focus,
input:focus,
textarea:focus,
select:focus {
  outline: 0;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 4px rgba(7, 84, 162, 0.15);
}

.form-label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: var(--font-semibold);
  color: var(--gray-800);
}

/* ============================================ */
/* ALERTS / TOASTS                               */
/* ============================================ */

.alert {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius);
  border-inline-start: 4px solid;
  margin-bottom: var(--space-4);
}

.alert-success {
  background: var(--green-50);
  color: var(--green-900);
  border-color: var(--green-400);
}

.alert-info {
  background: var(--blue-50);
  color: var(--blue-900);
  border-color: var(--blue-500);
}

.alert-warning {
  background: #fef3c7;
  color: #78350f;
  border-color: var(--amber-500);
}

.alert-danger {
  background: #fee2e2;
  color: #7f1d1d;
  border-color: var(--danger);
}

/* ============================================ */
/* HEADER & NAV — Modern RTL-first              */
/* ============================================ */

.site-header {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
  position: sticky;
  top: 0;
  z-index: 100;
  transition: all 0.3s ease;
}
.site-header.is-scrolled {
  background: rgba(255, 255, 255, 0.98);
  border-bottom-color: var(--border);
  box-shadow: 0 4px 20px rgba(7, 84, 162, 0.06);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  gap: 16px;
}
.site-header.is-scrolled .site-header__inner { height: 64px; }

/* === Logo === */
.site-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  font-family: 'Tajawal', sans-serif;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
.site-logo:hover { transform: translateY(-1px); }

.site-logo__icon {
  flex-shrink: 0;
  display: inline-flex;
  filter: drop-shadow(0 4px 10px rgba(7, 84, 162, 0.2));
}
.site-logo__icon svg { display: block; }

.site-logo__text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}
.site-logo__text strong {
  color: var(--blue-700);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.site-logo__text small {
  color: var(--gray-500);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  margin-top: 2px;
  white-space: nowrap;
}

/* === Desktop Nav === */
.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  justify-content: center;
}
.site-nav a {
  color: var(--gray-700);
  font-weight: 600;
  font-size: 15px;
  padding: 9px 16px;
  border-radius: 10px;
  position: relative;
  text-decoration: none;
  transition: all 0.2s ease;
}
.site-nav a::after {
  content: '';
  position: absolute;
  bottom: 4px; inset-inline-start: 50%;
  transform: translateX(-50%);
  width: 0; height: 3px;
  background: var(--green-400);
  border-radius: 2px;
  transition: width 0.25s ease;
}
[dir="rtl"] .site-nav a::after { transform: translateX(50%); }
.site-nav a:hover {
  color: var(--blue-700);
  background: var(--blue-50);
}
.site-nav a:hover::after,
.site-nav a.is-active::after {
  width: 24px;
}
.site-nav a.is-active {
  color: var(--blue-700);
  background: var(--blue-50);
}

/* === Desktop Actions === */
.site-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.site-lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--gray-700);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
  background: #fff;
}
.site-lang-btn:hover {
  border-color: var(--blue-500);
  color: var(--blue-700);
  background: var(--blue-50);
}

.site-action-btn {
  font-weight: 700 !important;
  padding: 9px 18px !important;
}

/* === User Menu (desktop dropdown) === */
.user-menu { position: relative; }
.user-menu__btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}
[dir="rtl"] .user-menu__btn { padding: 6px 6px 6px 10px; }
.user-menu__btn:hover {
  border-color: var(--blue-500);
  background: var(--blue-50);
}
.user-menu__avatar {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 13px;
  flex-shrink: 0;
}
.user-menu__avatar--lg { width: 44px; height: 44px; font-size: 18px; }
.user-menu__name {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-900);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-menu__chevron {
  color: var(--gray-500);
  transition: transform 0.2s ease;
}
.user-menu.is-open .user-menu__chevron { transform: rotate(180deg); }

.user-menu__dropdown {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  min-width: 260px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(7, 84, 162, 0.15);
  padding: 8px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: all 0.2s ease;
  z-index: 200;
}
.user-menu.is-open .user-menu__dropdown {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.user-menu__header {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: linear-gradient(135deg, var(--blue-50), #fff);
  border-radius: 10px;
  margin-bottom: 6px;
}
.user-menu__name-lg {
  font-weight: 700;
  color: var(--gray-900);
  font-size: 14px;
}
.user-menu__header small {
  color: var(--gray-500);
  font-size: 12px;
}
.user-menu__dropdown a,
.user-menu__logout {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--gray-700);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.15s ease;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  font-family: inherit;
  text-align: start;
}
.user-menu__dropdown a:hover { background: var(--blue-50); color: var(--blue-700); }
.user-menu__logout { color: var(--coral-500); }
.user-menu__logout:hover { background: #fee2e2; }
.user-menu__divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

/* === Mobile burger === */
.site-burger {
  display: none;
  flex-direction: column;
  gap: 4px;
  width: 40px; height: 40px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.2s ease;
}
.site-burger:hover { border-color: var(--blue-500); background: var(--blue-50); }
.site-burger span {
  width: 18px; height: 2px;
  background: var(--gray-700);
  border-radius: 2px;
  transition: all 0.25s ease;
}
.site-burger.is-open { background: var(--blue-50); border-color: var(--blue-500); }
.site-burger.is-open span:nth-child(1) { transform: translateY(6px) rotate(45deg); background: var(--blue-700); }
.site-burger.is-open span:nth-child(2) { opacity: 0; }
.site-burger.is-open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); background: var(--blue-700); }

/* === Mobile Drawer === */
.mobile-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  z-index: 998;
  transition: opacity 0.3s ease;
  display: none; /* hidden by default — only shown at mobile breakpoint */
}
.mobile-drawer-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-drawer {
  position: fixed;
  top: 0;
  inset-inline-end: 0;
  width: min(340px, 88vw);
  height: 100vh;
  background: #fff;
  z-index: 999;
  flex-direction: column;
  /* RTL (default): drawer pinned to LEFT (inset-inline-end = left) → hide off-left */
  transform: translateX(-110%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.15);
  display: none; /* hidden by default — only at mobile breakpoint */
  visibility: hidden;
}
[dir="ltr"] .mobile-drawer {
  /* LTR: drawer pinned to RIGHT → hide off-right */
  transform: translateX(110%);
  box-shadow: 20px 0 60px rgba(0, 0, 0, 0.15);
}
.mobile-drawer.is-open {
  transform: translateX(0);
  visibility: visible;
}

.mobile-drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--blue-50), #fff);
}
.mobile-drawer__close {
  width: 36px; height: 36px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-700);
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.mobile-drawer__close:hover { border-color: var(--coral-400); color: var(--coral-500); }

.mobile-drawer__user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.mobile-drawer__user .user-menu__name-lg { font-size: 15px; }
.mobile-drawer__user small {
  color: var(--gray-500);
  font-size: 12px;
  display: block;
}

.mobile-drawer__nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.mobile-drawer__nav a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 14px;
  color: var(--gray-700);
  font-size: 15px;
  font-weight: 600;
  border-radius: 10px;
  text-decoration: none;
  transition: all 0.2s ease;
}
.mobile-drawer__nav a:hover { background: var(--blue-50); color: var(--blue-700); }
.mobile-drawer__nav a.is-active {
  background: linear-gradient(90deg, var(--blue-50), transparent);
  color: var(--blue-700);
  border-inline-start: 3px solid var(--green-400);
}
.mobile-drawer__nav a svg {
  color: var(--gray-400);
  transition: color 0.2s ease;
  flex-shrink: 0;
}
.mobile-drawer__nav a:hover svg,
.mobile-drawer__nav a.is-active svg { color: var(--blue-500); }

.mobile-drawer__divider {
  height: 1px;
  background: var(--border);
  margin: 10px 6px;
}

.mobile-drawer__footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}

/* === Responsive breakpoints === */

/* Tablet: hide desktop nav, show burger + enable drawer */
@media (max-width: 1024px) {
  .site-nav { display: none; }
  .site-burger { display: flex; }
  .site-actions .site-lang-btn span,
  .user-menu__name { display: none; }
  .site-lang-btn { padding: 8px 10px; }
  .mobile-drawer { display: flex; }
  .mobile-drawer-overlay { display: block; }
}

/* Phone: tighter logo, hide some actions */
@media (max-width: 640px) {
  .site-header__inner { height: 64px; gap: 10px; }
  .site-header.is-scrolled .site-header__inner { height: 56px; }
  .site-logo__icon svg { width: 30px; height: 30px; }
  .site-logo__text strong { font-size: 15px; }
  .site-logo__text small { display: none; }
  .site-actions { gap: 6px; }
  .site-lang-btn,
  .site-actions .site-action-btn { display: none; }
}

/* ============================================ */
/* FOOTER                                        */
/* ============================================ */

.site-footer {
  background: var(--blue-700);
  color: var(--blue-100);
  padding: var(--space-12) 0 var(--space-6);
  margin-top: var(--space-16);
}

.site-footer a { color: var(--blue-100); }
.site-footer a:hover { color: #fff; }

.site-footer__bottom {
  border-top: 1px solid var(--blue-600);
  margin-top: var(--space-8);
  padding-top: var(--space-4);
  font-size: var(--text-sm);
  text-align: center;
  color: var(--blue-200);
}

/* ============================================ */
/* HERO                                          */
/* ============================================ */

.hero {
  background: linear-gradient(135deg, var(--blue-500) 0%, var(--blue-700) 100%);
  color: #fff;
  padding: var(--space-20) 0;
  position: relative;
  overflow: hidden;
}

.hero h1 { color: #fff; }
.hero p  { color: var(--blue-100); font-size: var(--text-lg); }

/* ============================================ */
/* UTILITIES                                     */
/* ============================================ */

.text-center { text-align: center; }
.text-primary-blue { color: var(--blue-500); }
.text-primary-green { color: var(--green-400); }
.bg-blue { background: var(--blue-500); color: #fff; }
.bg-green { background: var(--green-400); color: #fff; }
.bg-soft { background: var(--bg-soft); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

.grid { display: grid; gap: var(--space-6); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

/* Focus visibility (accessibility) */
*:focus-visible {
  outline: 3px solid var(--blue-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================ */
/* RTL/LTR adjustments                           */
/* ============================================ */

/* site-nav handles RTL naturally via flex + logical properties */

/* Reverse icon-only directional icons in RTL */
[dir="rtl"] .icon-flip { transform: scaleX(-1); }
