/* =========================================================================
   منصة اللياقة — نظام التصميم الأساسي
   Modern Minimal · RTL · Glassmorphism خفيف · تركواز/أخضر
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@500;600;700;800;900&family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&display=swap');

/* ---------------------------- المتغيرات (Tokens) --------------------------- */
:root {
  /* الألوان الأساسية */
  --primary-h: 189;
  --primary: #0E9AA7;
  --primary-dark: #0B7A85;
  --primary-light: #5FC9D0;
  --primary-50: #EAFAFB;
  --primary-100: #D1F1F3;

  --secondary: #379E6F;
  --secondary-light: #6FC79A;
  --secondary-50: #EAFBF2;

  --success: #2FB380;
  --success-50: #E9FAF3;
  --warning: #F5A524;
  --warning-50: #FEF6E8;
  --danger: #E5484D;
  --danger-50: #FDECEC;

  /* الخلفيات والأسطح */
  --bg: #F6F8F9;
  --surface: #FFFFFF;
  --surface-alt: #FBFCFD;
  --border: #E7ECEE;
  --border-soft: #EEF2F3;

  /* النصوص */
  --text: #16232B;
  --text-muted: #5C7078;
  --text-faint: #8DA0A7;
  --text-on-primary: #FFFFFF;

  /* الظلال */
  --shadow-sm: 0 1px 2px rgba(16, 40, 46, 0.04), 0 1px 1px rgba(16, 40, 46, 0.03);
  --shadow-md: 0 6px 20px rgba(16, 40, 46, 0.06), 0 2px 6px rgba(16, 40, 46, 0.04);
  --shadow-lg: 0 16px 40px rgba(16, 40, 46, 0.10), 0 4px 12px rgba(16, 40, 46, 0.05);
  --shadow-glow: 0 8px 24px rgba(14, 154, 167, 0.20);

  /* الأبعاد */
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 20px;
  --radius-full: 999px;

  /* الحركة */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 150ms;
  --dur: 220ms;

  /* الخطوط */
  --font-display: 'Cairo', 'IBM Plex Sans Arabic', sans-serif;
  --font-body: 'IBM Plex Sans Arabic', 'Cairo', sans-serif;

  --sidebar-w: 264px;
  --topbar-h: 68px;
  --bottomnav-h: 68px;
}

[data-theme="dark"] {
  --bg: #0F1517;
  --surface: #171F22;
  --surface-alt: #1C2528;
  --border: #26333730;
  --border-soft: #26333750;

  --text: #ECF3F4;
  --text-muted: #9CB0B6;
  --text-faint: #6C8189;

  --primary-50: #10373B;
  --primary-100: #12474C;
  --secondary-50: #123527;
  --success-50: #10362A;
  --warning-50: #3A2C10;
  --danger-50: #3A1416;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.30);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
}

/* ------------------------------- إعادة ضبط -------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }
ul { margin: 0; padding: 0; list-style: none; }

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 0;
  color: var(--text);
  letter-spacing: -0.01em;
}

.num { font-family: var(--font-display); font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* --------------------------------- الأيقونات -------------------------------- */
.icon { width: 20px; height: 20px; stroke-width: 2; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 26px; height: 26px; }

/* ------------------------------- هيكل الصفحة -------------------------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* الشريط الجانبي (سطح المكتب) */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 19px;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.nav-section-label {
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 16px 12px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-link:hover { background: var(--primary-50); color: var(--primary-dark); }
.nav-link.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-glow); }
.nav-link .icon { opacity: 0.9; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
}

/* الشريط العلوي */
.topbar {
  height: var(--topbar-h);
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  border-bottom: 1px solid var(--border-soft);
}
.topbar-title { font-size: 18px; font-weight: 700; font-family: var(--font-display); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: all var(--dur-fast) var(--ease);
  position: relative;
}
.icon-btn:hover { background: var(--primary-50); color: var(--primary-dark); border-color: var(--primary-100); }

.badge-dot {
  position: absolute; top: 6px; left: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--surface);
}

.avatar {
  width: 38px; height: 38px; border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary-light), var(--secondary-light));
  color: #fff; font-family: var(--font-display); font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
  overflow: hidden;
}

.avatar img {
  width: 100%; height: 100%; object-fit: cover; border-radius: inherit;
}

/* المحتوى الرئيسي */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 24px 22px calc(var(--bottomnav-h) + 30px);
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
}

/* شريط التنقل السفلي (هاتف) */
.bottom-nav {
  position: fixed;
  bottom: 0; inset-inline: 0;
  height: var(--bottomnav-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border-top: 1px solid var(--border-soft);
  display: none;
  z-index: 40;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-inner { display: flex; height: 100%; }
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-faint); font-size: 10.5px; font-weight: 700;
}
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item .icon { width: 22px; height: 22px; }
.bottom-nav-fab {
  width: 52px; height: 52px; border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff; display: flex; align-items: center; justify-content: center;
  margin-top: -26px; box-shadow: var(--shadow-glow);
}

@media (max-width: 980px) {
  .sidebar { display: none; }
  .bottom-nav { display: block; }
  .main-content { padding: 18px 14px calc(var(--bottomnav-h) + 22px); }
  .topbar { padding: 0 14px; }
}

/* --------------------------------- البطاقات --------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-flush { padding: 0; overflow: hidden; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 10px;
}
.card-title { font-size: 15px; font-weight: 700; font-family: var(--font-display); }
.card-subtitle { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

/* ------------------------------ حلقات التقدم -------------------------------- */
/* هذا هو العنصر البصري المميّز للتطبيق: حلقات تقدم زجاجية ناعمة */
.ring {
  position: relative;
  width: var(--ring-size, 96px);
  height: var(--ring-size, 96px);
  display: flex; align-items: center; justify-content: center;
}
.ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.ring circle { fill: none; stroke-width: 9; }
.ring .ring-track { stroke: var(--border-soft); }
.ring .ring-fill {
  stroke: var(--ring-color, var(--primary));
  stroke-linecap: round;
  transition: stroke-dashoffset 900ms var(--ease);
}
.ring-label {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.ring-label .value { font-family: var(--font-display); font-weight: 800; font-size: 20px; }
.ring-label .unit { font-size: 10px; color: var(--text-muted); font-weight: 600; }

/* -------------------------------- الأزرار ----------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-weight: 700; font-size: 14px;
  border: 1px solid transparent;
  transition: all var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-glow); }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { filter: brightness(0.92); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-50); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-sm { padding: 7px 14px; font-size: 12.5px; border-radius: 9px; }
.btn-lg { padding: 14px 26px; font-size: 15px; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-icon { padding: 10px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* -------------------------------- الحقول ------------------------------------ */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 13px; font-weight: 700; margin-bottom: 7px; color: var(--text);
}
.field .hint { font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }

.input, select.input, textarea.input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input:focus, select.input:focus, textarea.input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-50);
  background: var(--surface);
}
textarea.input { resize: vertical; min-height: 80px; }

.input-group { display: flex; gap: 10px; }
.input-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }

.checkbox-row { display: flex; align-items: center; gap: 10px; }
.switch {
  position: relative; width: 44px; height: 26px; flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track {
  position: absolute; inset: 0; background: var(--border); border-radius: var(--radius-full);
  transition: background var(--dur) var(--ease); cursor: pointer;
}
.switch .thumb {
  position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; transition: inset-inline-start var(--dur) var(--ease);
  box-shadow: var(--shadow-sm);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track .thumb { inset-inline-start: 21px; }
.switch input:checked ~ .thumb { inset-inline-start: 21px; }

/* ------------------------------- الشارات (Badges) --------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 11.5px; font-weight: 700;
}
.badge-primary { background: var(--primary-50); color: var(--primary-dark); }
.badge-secondary { background: var(--secondary-50); color: var(--secondary); }
.badge-success { background: var(--success-50); color: var(--success); }
.badge-warning { background: var(--warning-50); color: var(--warning); }
.badge-danger { background: var(--danger-50); color: var(--danger); }
.badge-neutral { background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }

/* -------------------------------- شرائط التقدم ------------------------------- */
.progress {
  height: 10px; border-radius: var(--radius-full); background: var(--border-soft);
  overflow: hidden; position: relative;
}
.progress-bar {
  height: 100%; border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  transition: width 700ms var(--ease);
}
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* --------------------------------- الجداول ---------------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border-soft); }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.table th {
  text-align: start; padding: 12px 16px; background: var(--surface-alt);
  color: var(--text-muted); font-weight: 700; font-size: 12px; border-bottom: 1px solid var(--border-soft);
}
table.table td { padding: 12px 16px; border-bottom: 1px solid var(--border-soft); }
table.table tr:last-child td { border-bottom: none; }
table.table tbody tr:hover { background: var(--surface-alt); }

/* --------------------------------- التنبيهات --------------------------------- */
.flash-stack {
  position: fixed; top: 16px; inset-inline: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.flash {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-radius: var(--radius-sm);
  background: var(--surface); box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-soft);
  font-size: 13.5px; font-weight: 600;
  max-width: 92vw;
  animation: flash-in 260ms var(--ease);
}
.flash-success { border-inline-start: 4px solid var(--success); }
.flash-danger { border-inline-start: 4px solid var(--danger); }
.flash-warning { border-inline-start: 4px solid var(--warning); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

.alert {
  padding: 14px 16px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
  display: flex; gap: 10px; align-items: flex-start;
}
.alert-info { background: var(--primary-50); color: var(--primary-dark); }
.alert-warning { background: var(--warning-50); color: #8a5a10; }

/* ------------------------------- حالة فارغة ---------------------------------- */
.empty-state {
  text-align: center; padding: 46px 20px; color: var(--text-muted);
}
.empty-state .icon-lg { margin: 0 auto 14px; color: var(--text-faint); width: 44px; height: 44px; }
.empty-state h4 { margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 13.5px; margin: 0 0 16px; }

/* -------------------------------- تبويبات ------------------------------------ */
.tabs { display: flex; gap: 6px; background: var(--surface-alt); padding: 5px; border-radius: var(--radius-sm); width: fit-content; }
.tab {
  padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 700; color: var(--text-muted);
  transition: all var(--dur-fast) var(--ease);
}
.tab.active { background: var(--surface); color: var(--primary-dark); box-shadow: var(--shadow-sm); }

/* -------------------------------- القوائم المنسدلة --------------------------- */
.dropdown-menu {
  position: absolute;
  inset-inline-start: 0;
  top: 48px;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: none;
  overflow: hidden;
}
.dropdown-menu.open { display: block; animation: modal-in 160ms var(--ease); }
.dropdown-head {
  padding: 14px 16px; border-bottom: 1px solid var(--border-soft); font-weight: 700; font-size: 13.5px;
  display: flex; justify-content: space-between; align-items: center;
}
.dropdown-body { max-height: 320px; overflow-y: auto; }
.dropdown-item { padding: 12px 16px; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.dropdown-item:last-child { border-bottom: none; }
.dropdown-empty { padding: 24px 16px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* --------------------------------- نافذة منبثقة ------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 20, 24, 0.45);
  backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 90; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); padding: 24px;
  width: 100%; max-width: 480px; box-shadow: var(--shadow-lg);
  max-height: 88vh; overflow-y: auto;
  animation: modal-in 200ms var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

/* ----------------------------------- عام ------------------------------------- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 6px; } .gap-2 { gap: 10px; } .gap-3 { gap: 16px; } .gap-4 { gap: 22px; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 10px; } .mt-3 { margin-top: 16px; } .mt-4 { margin-top: 24px; }
.mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 10px; } .mb-3 { margin-bottom: 16px; } .mb-4 { margin-bottom: 24px; }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-sm { font-size: 12.5px; }
.text-center { text-align: center; }
.w-full { width: 100%; }
.divider { height: 1px; background: var(--border-soft); border: none; margin: 16px 0; }
.section-title { font-size: 20px; margin-bottom: 4px; }
.page-head { margin-bottom: 22px; }
.hidden { display: none !important; }

/* شريط التمرير */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* -------------------------------- صفحات الدخول -------------------------------- */
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background:
    radial-gradient(circle at 15% 10%, var(--primary-50), transparent 45%),
    radial-gradient(circle at 85% 90%, var(--secondary-50), transparent 45%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 34px 30px;
  border: 1px solid var(--border-soft);
}
.auth-logo { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 22px; font-family: var(--font-display); font-weight: 800; font-size: 20px; }

/* -------------------------------- أونبوردينج ---------------------------------- */
.onboard-shell { max-width: 640px; margin: 0 auto; padding: 30px 18px 60px; }
.onboard-progress { display: flex; gap: 6px; margin-bottom: 24px; }
.onboard-progress span { flex: 1; height: 5px; border-radius: var(--radius-full); background: var(--border-soft); }
.onboard-progress span.done { background: var(--primary); }

/* عناصر مساعدة للتمرين التنفيذي */
.set-row {
  display: grid; grid-template-columns: 34px 1fr 1fr 44px; gap: 10px; align-items: center; margin-bottom: 8px;
}
.set-row .set-num {
  width: 34px; height: 34px; border-radius: 50%; background: var(--surface-alt);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12.5px; color: var(--text-muted);
}
.set-row.completed .set-num { background: var(--success); color: #fff; }

.timer-display {
  font-family: var(--font-display); font-weight: 900; font-size: 42px; text-align: center;
  color: var(--primary-dark);
}

.exercise-card.done { border-color: var(--success); box-shadow: 0 0 0 3px var(--success-50); }
