/* ===== إعادة الضبط والتخطيط الأساسي ===== */
/* خط Cairo محلي - بديل عن Google Fonts لتجنب مشاكل CSP والـ SW */
@font-face {
  font-family: 'Cairo';
  src: url('/static/fonts/Cairo-Light.ttf') format('truetype');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('/static/fonts/Cairo-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('/static/fonts/Cairo-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('/static/fonts/Cairo-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('/static/fonts/Cairo-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('/static/fonts/Cairo-ExtraBold.ttf') format('truetype');
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  color: var(--text-primary);
  background-color: var(--bg-body);
  direction: rtl;
  min-height: 100vh;
  min-height: 100dvh; /* دعم viewport الديناميكي على iOS */
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--text-link);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

ul, ol { list-style: none; }

button { cursor: pointer; font-family: var(--font-family); }

input, select, textarea {
  font-family: var(--font-family);
  font-size: var(--font-size-md);
}

/* ===== حاوية التطبيق ===== */
#app {
  min-height: 100vh;
  position: relative;
  background: var(--bg-body);
}

/* ===== المحتوى الرئيسي ===== */
#main-content {
  /* padding-top يعتمد ارتفاع الهيدر + safe-area-inset-top على الموبايل */
  padding-top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  /* padding-bottom يعتمد ارتفاع الشريط السفلي + safe-area-inset-bottom */
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + var(--space-md));
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===== شريط التحميل ===== */
#loading-bar {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  background: var(--color-accent);
  z-index: 9999;
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.3s ease;
}
#loading-bar.active { transform: scaleX(1); }

/* ===== Tablet (481px - 768px) ===== */
@media (min-width: 481px) and (max-width: 768px) {
  #app { /* max-width: 720px; */ }
}

/* ===== Desktop (≥769px) ===== */
@media (min-width: 769px) {
  #app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr;
    grid-template-areas:
      "sidebar header"
      "sidebar main";
  }

  #app-header {
    grid-area: header;
  }

  .sidebar {
    grid-area: sidebar;
    display: flex !important;
  }

  /* حاوية المحتوى - توسيط مع حد أقصى للعرض */
  #main-content {
    grid-area: main;
    overflow-y: auto;
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-md) var(--space-lg);
    width: 100%;
    box-sizing: border-box;
  }

  #bottom-nav {
    display: none !important;
  }

  /* إخفاء pull-to-refresh على سطح المكتب */
  #ptr-wrapper { display: none !important; }
}

/* شاشات أكبر - عرض أوسع */
@media (min-width: 1400px) {
  #main-content {
    max-width: 1400px;
  }
}
