/* ==========================================================================
   Mawid (موعد) - Core Design Tokens & Theme Stylesheet
   Modern, Ultra-responsive & Mobile-First
   ========================================================================== */

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

:root {
  /* Brand Palette - Modern Emerald & Teal with Amber Gold accents */
  --primary-50: #f0fdfa;
  --primary-100: #ccfbf1;
  --primary-200: #99f6e4;
  --primary-300: #5eead4;
  --primary-400: #2dd4bf;
  --primary-500: #14b8a6;
  --primary-600: #0d9488;
  --primary-700: #0f766e;
  --primary-800: #115e59;
  --primary-900: #134e4a;
  
  --accent-gold: #f59e0b;
  --accent-gold-light: #fef3c7;
  --accent-rose: #f43f5e;
  --accent-rose-light: #ffe4e6;
  --accent-blue: #3b82f6;
  --accent-blue-light: #eff6ff;
  --accent-purple: #8b5cf6;
  --accent-purple-light: #f5f3ff;

  /* Typography */
  --font-family: 'Cairo', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Default Light Theme Tokens */
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --bg-muted: #f1f5f9;
  --bg-input: #f8fafc;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  --text-inverted: #ffffff;

  --border-subtle: #e2e8f0;
  --border-focus: #0d9488;

  --primary: #0d9488;
  --primary-hover: #0f766e;
  --primary-light: #ccfbf1;
  --primary-text: #0f766e;

  /* Glassmorphism & Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 30px -10px rgba(0, 0, 0, 0.12);
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.6);

  /* Layout */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-full: 9999px;
  --header-height: 70px;
  --bottom-nav-height: 68px;
  --max-app-width: 480px; /* Mobile frame width on desktop */
}

/* Dark Theme Overrides */
[data-theme="dark"] {
  --bg-app: #090d16;
  --bg-surface: #111827;
  --bg-surface-elevated: #1e293b;
  --bg-surface-hover: #1e293b;
  --bg-muted: #1e293b;
  --bg-input: #1e293b;

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-tertiary: #64748b;
  --text-inverted: #090d16;

  --border-subtle: #1e293b;
  --border-focus: #14b8a6;

  --primary: #14b8a6;
  --primary-hover: #2dd4bf;
  --primary-light: rgba(20, 184, 166, 0.15);
  --primary-text: #2dd4bf;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 10px 0 rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 25px -4px rgba(0, 0, 0, 0.6);
  --shadow-xl: 0 24px 35px -8px rgba(0, 0, 0, 0.8);
  --glass-bg: rgba(17, 24, 39, 0.85);
  --glass-border: rgba(255, 255, 255, 0.08);
}

/* Reset & Base Rules */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-family: var(--font-family);
  direction: rtl;
  text-align: right;
  font-size: 16px;
  background-color: var(--bg-app);
  color: var(--text-primary);
  scroll-behavior: smooth;
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-app);
  color: var(--text-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow: hidden; /* Prevents outer window scrolling so navigation bar stays completely fixed */
}

/* App Shell (Mobile First Preview Container) */
.app-container {
  width: 100%;
  max-width: var(--max-app-width);
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg-surface);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Keeps navigation bar and all content tightly contained */
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.08);
}

@media (min-width: 540px) {
  body {
    padding: 0;
    background: radial-gradient(circle at 50% 10%, rgba(13, 148, 136, 0.08), transparent 70%), var(--bg-app);
  }
  .app-container {
    border-radius: 36px;
    border: 8px solid var(--bg-surface-elevated);
    box-shadow: var(--shadow-xl), 0 0 0 1px var(--border-subtle);
    height: calc(100vh - 40px);
    max-height: 900px;
  }
}

/* Device Mode Switcher (Visible on desktop to toggle frame mode vs responsive) */
.desktop-banner {
  display: none;
}
@media (min-width: 860px) {
  .desktop-banner {
    display: flex;
    position: fixed;
    top: 20px;
    right: 24px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    padding: 10px 16px;
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-md);
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    z-index: 100;
  }
  .desktop-banner .badge {
    background: var(--primary-light);
    color: var(--primary-text);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-weight: 700;
  }
}

/* Top App Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  padding: calc(env(safe-area-inset-top, 12px) + 8px) 18px 12px;
  transition: all 0.25s ease;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.avatar-wrapper {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  padding: 2px;
  background: linear-gradient(135deg, var(--primary), var(--accent-gold));
  flex-shrink: 0;
}

.avatar-img {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full);
  object-fit: cover;
  background: var(--bg-muted);
}

.avatar-status-dot {
  position: absolute;
  bottom: 1px;
  left: 1px;
  width: 11px;
  height: 11px;
  background: #22c55e;
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-greeting {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.user-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--primary-400);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.notif-badge {
  position: absolute;
  top: 7px;
  left: 7px;
  width: 8px;
  height: 8px;
  background: var(--accent-rose);
  border-radius: 50%;
  border: 1.5px solid var(--bg-surface);
}

/* Global Search Bar */
.search-container {
  margin-top: 12px;
  position: relative;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  right: 14px;
  width: 18px;
  height: 18px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 10px 42px 10px 14px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s ease;
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: var(--bg-surface);
}

.search-input::placeholder {
  color: var(--text-tertiary);
}

/* Main Content Views */
.main-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 18px calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 24px) + 36px);
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle) transparent;
}

.screen-view {
  display: none;
  animation: fadeIn 0.25s ease forwards;
}

.screen-view.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Bottom Navigation Bar (Fixed across all pages & scrolling) */
.bottom-nav {
  position: fixed !important;
  bottom: 0 !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  width: 100% !important;
  max-width: var(--max-app-width) !important;
  height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 12px)) !important;
  background: var(--bg-surface) !important;
  backdrop-filter: blur(24px) !important;
  -webkit-backdrop-filter: blur(24px) !important;
  border-top: 1px solid var(--border-subtle) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-around !important;
  padding: 0 10px env(safe-area-inset-bottom, 12px) !important;
  z-index: 150 !important;
  box-shadow: 0 -4px 25px rgba(0, 0, 0, 0.08) !important;
  flex-shrink: 0 !important;
  pointer-events: auto !important;
  box-sizing: border-box !important;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 8px 4px;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
  position: relative;
  flex: 1;
}

.nav-item svg {
  width: 22px;
  height: 22px;
  margin-bottom: 3px;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nav-label {
  font-size: 0.72rem;
  font-weight: 600;
  font-family: inherit;
}

.nav-item.active {
  color: var(--primary);
}

.nav-item.active svg {
  transform: translateY(-2px);
}

.nav-item.active::after {
  content: '';
  position: absolute;
  top: 4px;
  width: 4px;
  height: 4px;
  background: var(--primary);
  border-radius: 50%;
}

/* Elevated Center Action Button (حجز حضوري) */
.nav-item-center {
  padding: 0 4px 6px;
  overflow: visible;
}

.nav-center-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #0f172a);
  color: #ffffff;
  border: 4px solid var(--bg-surface);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -26px;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nav-item-center:active .nav-center-circle {
  transform: scale(0.94);
}

.nav-item-center .nav-center-circle svg {
  width: 24px;
  height: 24px;
  stroke: #ffffff;
  margin-bottom: 0;
}

.nav-item-center .nav-label {
  color: var(--primary);
  font-weight: 800;
  font-size: 0.68rem;
  margin-top: 2px;
  white-space: nowrap;
}

/* Typography Helpers */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  margin-top: 20px;
}

.section-header:first-of-type {
  margin-top: 0;
}

.section-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-link {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
}
