/* ═══════════════════════════════════════════════
   BASE STYLES — Reset, Typography, Layout
   Adapted from Stitch Design System
   ═══════════════════════════════════════════════ */

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: var(--font-primary);
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
  line-height: var(--lh-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Comprehensive RTL Support ── */
[dir="rtl"] {
  font-family: 'Noto Sans Arabic', 'Cairo', 'Segoe UI', Tahoma, system-ui, -apple-system, sans-serif;
  line-height: var(--lh-normal);
}

[dir="rtl"],
[dir="rtl"] * {
  letter-spacing: 0 !important;
}

[dir="rtl"] .text-ellipsis {
  text-align: start;
}

/* Ensure proper font sizing and line heights for Arabic text */
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] h4, [dir="rtl"] h5, [dir="rtl"] h6 {
  line-height: 1.4;
}

[dir="rtl"] p, [dir="rtl"] span, [dir="rtl"] label, [dir="rtl"] input, [dir="rtl"] button {
  line-height: 1.5;
}

/* Navigation chevrons flip in RTL */
[dir="rtl"] .material-icons-round.chevron-icon,
[dir="rtl"] .arrow-flip {
  transform: scaleX(-1);
}

/* ── Links ── */
a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-in-out);
}
a:hover { color: var(--color-primary-hover); }

/* ── Images ── */
img, video {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ── Lists ── */
ul, ol { list-style: none; }

/* ── Buttons ── */
button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  outline: none;
}

/* ── Inputs ── */
input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  outline: none;
  border: none;
  background: none;
}

input::placeholder, textarea::placeholder {
  color: var(--color-text-tertiary);
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--color-text-disabled);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-tertiary);
}

/* ── Selection ── */
::selection {
  background: var(--color-primary);
  color: white;
}

/* ══════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════ */

#app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  overflow-x: hidden;
}

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  position: relative;
  overflow: hidden;
}

/* ── Top App Bar (Glassmorphic) ── */
.app-bar {
  position: sticky;
  top: 0;
  z-index: var(--z-app-bar);
  display: flex;
  align-items: center;
  height: var(--app-bar-height);
  padding: 0 var(--sp-4);
  background: rgba(22, 27, 34, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--color-divider);
  gap: var(--sp-2);
  transition: background var(--duration-normal) ease;
  flex-shrink: 0;
}
[data-theme="light"] .app-bar {
  background: rgba(255, 255, 255, 0.88);
}
.app-bar.hidden { display: none !important; }
#app-bar-back-btn.hidden { display: none !important; }
[dir="rtl"] #app-bar-back-btn span {
  transform: rotate(180deg);
}
.app-bar-title {
  flex: 1;
  text-align: center;
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  letter-spacing: -0.015em;
  color: var(--color-text);
}
.app-bar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}
[dir="rtl"] .app-bar-actions {
  margin-left: 0;
  margin-right: auto;
}

/* ── Page Container ── */
.page-container {
  flex: 1;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.page-container.has-bottom-nav {
  padding-bottom: calc(var(--bottom-nav-height) + 16px + env(safe-area-inset-bottom, 0px));
}

/* ── Drawer ── */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-drawer);
  pointer-events: none;
}
.drawer.open { pointer-events: auto; }

.drawer-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-in-out);
  z-index: var(--z-drawer-overlay);
}
.drawer.open .drawer-overlay { opacity: 1; }

.drawer-content {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--drawer-width);
  height: 100%;
  background: var(--color-surface);
  transform: translateX(-100%);
  transition: transform var(--duration-normal) var(--ease-out);
  overflow-y: auto;
  z-index: var(--z-drawer);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-modal);
}
.drawer.open .drawer-content { transform: translateX(0); }

[dir="rtl"] .drawer-content {
  left: auto;
  right: 0;
  transform: translateX(100%);
}
[dir="rtl"] .drawer.open .drawer-content { transform: translateX(0); }

/* Hide pin drawer button on mobile by default */
#btn-toggle-pin-drawer {
  display: none !important;
}

/* ── Modern Floating Bottom Navigation (matches Flutter ModernBottomNav) ── */
.bottom-nav {
  position: fixed;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  left: 16px;
  right: 16px;
  max-width: 520px;
  margin: 0 auto;
  z-index: var(--z-bottom-nav);
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 64px;
  background: rgba(22, 27, 34, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--color-border);
  border-radius: 32px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  padding: 0 var(--sp-2);
  transition: all var(--duration-normal) ease;
}
[data-theme="light"] .bottom-nav {
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 24px rgba(11, 28, 48, 0.12);
}
.bottom-nav.hidden { display: none !important; }

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px;
  color: var(--color-text-secondary);
  font-size: 11px;
  font-weight: var(--fw-medium);
  transition: all var(--duration-fast) var(--ease-in-out);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.bottom-nav-icon-wrapper {
  width: 38px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  transition: background var(--duration-fast) ease, transform var(--duration-fast) ease;
}
.bottom-nav-item .material-icons-round { font-size: 22px; }
.bottom-nav-item.active {
  color: var(--color-primary);
  font-weight: var(--fw-bold);
}
.bottom-nav-item.active .bottom-nav-icon-wrapper {
  background: var(--color-primary-dim);
  transform: translateY(-2px);
}

/* ── Drawer Hidden Rule ── */
.drawer.hidden {
  display: none !important;
}

/* ── Desktop & Laptop View: Responsive Sidebar with Pinned & Hover Modes ── */
@media (min-width: 1024px) {
  /* Viewport container — clips overflow so sidebar doesn't scroll with page */
  #app {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
  }

  #btn-toggle-pin-drawer {
    display: flex !important;
  }

  /* Page UI fully expands across screen */
  .page {
    max-width: 100% !important;
    width: 100% !important;
    padding: var(--sp-6) var(--sp-8);
    padding-bottom: var(--sp-12);
    margin: 0 !important;
    box-sizing: border-box;
  }

  /* Main wrapper scrolls independently — sidebar never moves */
  .main-wrapper {
    flex: 1;
    min-width: 0;
    width: 100%;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: margin var(--duration-normal) var(--ease-out);
  }

  /* ── UNPINNED (Overlay Auto-Hover Mode) ── */
  .drawer:not(.hidden):not(.pinned) {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    z-index: var(--z-drawer);
    pointer-events: none;
    display: block;
  }

  .drawer:not(.pinned) .drawer-content {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width, 270px);
    transform: translateX(-100%);
    transition: transform var(--duration-normal) var(--ease-out), box-shadow var(--duration-normal) ease;
    overflow-x: hidden;
    overflow-y: auto;
    z-index: var(--z-drawer);
    pointer-events: auto;
    box-shadow: none;
  }

  .drawer:not(.pinned):hover .drawer-content,
  .drawer:not(.pinned).open .drawer-content,
  .drawer:not(.pinned).hover-open .drawer-content {
    transform: translateX(0);
    box-shadow: var(--shadow-modal);
  }

  [dir="rtl"] .drawer:not(.pinned) .drawer-content {
    left: auto;
    right: 0;
    transform: translateX(100%);
  }
  [dir="rtl"] .drawer:not(.pinned):hover .drawer-content,
  [dir="rtl"] .drawer:not(.pinned).open .drawer-content,
  [dir="rtl"] .drawer:not(.pinned).hover-open .drawer-content {
    transform: translateX(0);
  }

  /* ── PINNED MODE (Expands into page & content naturally shrinks) ── */
  /* ── PINNED MODE: Fixed sidebar, content scrolls independently ── */
  .drawer:not(.hidden).pinned {
    position: relative;
    width: var(--sidebar-width, 270px);
    min-width: var(--sidebar-width, 270px);
    height: 100vh;
    flex-shrink: 0;
    z-index: 50;
    pointer-events: auto;
    display: flex;
    transition: width var(--duration-normal) var(--ease-out), min-width var(--duration-normal) var(--ease-out);
  }

  .drawer.pinned .drawer-overlay {
    display: none !important;
  }

  /* Sidebar itself scrolls internally — never moves with page scroll */
  .drawer.pinned .drawer-content {
    position: sticky;
    top: 0;
    left: 0;
    width: var(--sidebar-width, 270px);
    height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transform: none !important;
    border-right: 1px solid var(--color-divider);
    box-shadow: none;
    pointer-events: auto;
    flex-shrink: 0;
  }

  [dir="rtl"] .drawer.pinned .drawer-content {
    border-right: none;
    border-left: 1px solid var(--color-divider);
    left: auto;
    right: 0;
    transform: none !important;
  }

  /* ── RESIZE HANDLE (Mouse Dragging) ── */
  .drawer-resizer {
    position: absolute;
    top: 0;
    right: -4px;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    z-index: 100;
    user-select: none;
    transition: background 0.15s ease;
  }
  .drawer-resizer:hover,
  .drawer-resizer.dragging {
    background: var(--color-primary);
  }
  [dir="rtl"] .drawer-resizer {
    right: auto;
    left: -4px;
  }

  /* Hover trigger zone at the screen edge (only for unpinned mode) */
  .drawer-edge-trigger {
    position: fixed;
    top: 0;
    left: 0;
    width: 20px;
    height: 100%;
    z-index: calc(var(--z-drawer) - 1);
    pointer-events: auto;
    background: transparent;
  }
  .drawer.pinned .drawer-edge-trigger {
    display: none !important;
  }
  [dir="rtl"] .drawer-edge-trigger {
    left: auto;
    right: 0;
  }

  .bottom-nav { display: none !important; }
  #menu-btn { display: inline-flex; }
  .drawer.pinned ~ .main-wrapper #menu-btn {
    display: none !important;
  }
  #app-bar-back-btn:not(.hidden) { display: inline-flex; }
  .app-bar-title { 
    display: block;
    text-align: start; 
  }
}

/* ── Utility Classes ── */
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
.text-center { text-align: center; }
.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .hide-on-mobile { display: none !important; }
}

/* ── Icon Button ── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  color: var(--color-text);
  transition: background var(--duration-fast) var(--ease-in-out), transform var(--duration-fast) ease;
}
.icon-btn:hover {
  background: var(--color-surface-hover);
  transform: scale(1.05);
}
.icon-btn:active {
  transform: scale(0.95);
}

/* ── Page Container ── */
.page {
  padding: var(--sp-4);
  padding-bottom: 96px;
  max-width: var(--max-content-width);
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  animation: fadeSlideIn var(--duration-page) var(--ease-out) both;
}

@media (min-width: 1024px) {
  .page {
    padding: var(--sp-6) var(--sp-8);
    padding-bottom: var(--sp-12);
  }
}

.page-full {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  animation: fadeIn var(--duration-page) var(--ease-out) both;
}

