/* ==========================================================================
   DebtFlow - Shared Global Sticky Navbar & Base System Styles
   ========================================================================== */

/* Universal Reset & Overflow Protection */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Fluid Responsive Container */
.container,
main,
section {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Standardized Responsive Table Container */
.table-responsive {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
}

/* Accessible Touch Targets Baseline */
input,
select,
textarea,
button,
.btn,
[role="button"] {
  min-height: 44px;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid #e2e8f0;
  width: 100%;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 4.25rem;
  height: auto;
  padding: 0.5rem 0;
  gap: 1rem;
  flex-wrap: nowrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex-shrink: 1;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: #0f172a;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.logo-icon {
  width: 2.25rem;
  height: 2.25rem;
  background: linear-gradient(135deg, #4f46e5 0%, #10b981 100%);
  border-radius: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
  flex-shrink: 0;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.65rem;
  background: #eef2ff;
  border: 1px solid #e0e7ff;
  color: #4338ca;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  white-space: nowrap;
}

.brand-badge-dot {
  width: 0.45rem;
  height: 0.45rem;
  background: #10b981;
  border-radius: 50%;
}

.site-nav {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  gap: 0.5rem;
  list-style: none;
  align-items: center;
  margin: 0;
  padding: 0;
  flex-wrap: nowrap;
}

.nav-link {
  text-decoration: none;
  color: #475569;
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.4rem 0.75rem;
  border-radius: 0.5rem;
  transition: all 0.15s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
}

.nav-link:hover {
  color: #1e293b;
  background: #f1f5f9;
}

.nav-link.active {
  color: #4338ca;
  background: #eef2ff;
  font-weight: 600;
}

/* Polished Multi-Column Dropdown */
.nav-dropdown {
  position: relative;
  display: inline-block;
}

.nav-dropdown-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  background: #4f46e5;
  border: 1px solid #4338ca;
  border-radius: 0.5rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.25);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.nav-dropdown-btn:hover {
  background: #4338ca;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.35);
}

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  width: 520px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  padding: 1rem;
  z-index: 1001;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
  display: block;
}

.dropdown-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.dropdown-sector {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.dropdown-sector-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  padding: 0.2rem 0.5rem;
  border-bottom: 1px solid #f1f5f9;
  margin-bottom: 0.25rem;
}

.dropdown-item {
  display: block;
  padding: 0.35rem 0.5rem;
  font-size: 0.825rem;
  color: #334155;
  text-decoration: none;
  border-radius: 0.375rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.dropdown-item:hover {
  background: #f8fafc;
  color: #4f46e5;
  font-weight: 500;
}

.dropdown-item.active {
  font-weight: 600;
  color: #4338ca;
  background: #eef2ff;
}

@media (max-width: 992px) {
  .brand-badge {
    display: none;
  }
}

@media (max-width: 768px) {
  .nav-dropdown-menu {
    width: min(320px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    right: 0;
  }

  .dropdown-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .nav-link:not(.active) {
    display: none;
  }
}

@media (max-width: 480px) {
  .header-inner {
    gap: 0.5rem;
    padding: 0.4rem 0;
    min-height: 3.75rem;
  }

  .brand-logo {
    font-size: 1.15rem;
    gap: 0.5rem;
  }

  .logo-icon {
    width: 2rem;
    height: 2rem;
  }

  .nav-links {
    gap: 0.25rem;
  }

  .nav-link {
    display: none !important;
  }

  .nav-dropdown-btn {
    padding: 0.4rem 0.65rem;
    font-size: 0.8rem;
    min-height: 40px;
  }
}


/* إصلاح انزياح كروت الموبايل نهائياً */
@media (max-width: 768px) {

  /* ضبط حاوية القائمة المنسدلة على الموبايل */
  .nav-dropdown-menu {
    width: min(330px, calc(100vw - 20px)) !important;
    max-width: calc(100vw - 20px) !important;
    right: 0 !important;
    left: auto !important;
    max-height: 70vh !important;
    /* لا تتجاوز 70% من ارتفاع شاشة الهاتف */
    overflow-y: auto !important;
    /* تمرير داخلي سلس جداً */
    -webkit-overflow-scrolling: touch !important;
    padding: 0.75rem !important;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2) !important;
  }

  /* جعل الأدوات تظهر في عمودين أنيقين بدلاً من عمود واحد طويل */
  .dropdown-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem !important;
  }

  .dropdown-sector {
    gap: 0.15rem !important;
  }

  .dropdown-sector-title {
    font-size: 0.65rem !important;
    padding: 0.15rem 0.35rem !important;
    margin-bottom: 0.2rem !important;
  }

  .dropdown-item {
    padding: 0.35rem 0.45rem !important;
    font-size: 0.75rem !important;
    line-height: 1.25 !important;
    white-space: normal !important;
    /* يسمح للنص بالالتفاف داخل الصندوق بأناقة */
    border-radius: 0.3rem !important;
  }
}

@media (max-width: 640px) {
  .nav-link:not(.active) {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .header-inner {
    gap: 0.5rem;
    padding: 0.4rem 0;
    min-height: 3.75rem;
  }

  .brand-logo {
    font-size: 1.15rem;
    gap: 0.5rem;
  }

  .logo-icon {
    width: 2rem;
    height: 2rem;
  }

  .nav-links {
    gap: 0.25rem;
  }

  .nav-link {
    display: none !important;
  }

  .nav-dropdown-btn {
    padding: 0.4rem 0.65rem;
    font-size: 0.8rem;
    min-height: 40px;
  }
}

/* إصلاح انزياح كروت الموبايل نهائياً */
@media screen and (max-width: 768px) {

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

  .presets,
  [class*="preset"],
  .btn-group {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    width: 100% !important;
  }

  .container,
  main,
  section,
  .calc-layout,
  .calculator-grid,
  [class*="grid"],
  [class*="wrapper"] {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .card,
  [class*="card"],
  .calc-card,
  .results-card {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin: 0 0 16px 0 !important;
  }
}

html,
body {
  overflow-x: hidden !important;
  width: 100% !important;
  position: relative !important;
}

@media (max-width: 768px) {

  /* 1. جعل الترويسة في صف واحد مريح */
  .site-header .container {
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 0.75rem 1rem !important;
    position: relative !important;
  }

  /* 2. ضبط زر القائمة ليبقى بحجم متناسق */
  .tools-menu-btn,
  .btn-all-tools {
    padding: 0.45rem 0.85rem !important;
    font-size: 0.825rem !important;
    white-space: nowrap !important;
  }

  /* 3. حل مشكلة انقطاع القائمة المنسدلة */
  .dropdown-menu,
  .tools-dropdown {
    position: fixed !important;
    top: 65px !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    max-width: calc(100vw - 24px) !important;
    max-height: 80vh !important;
    overflow-y: auto !important;
    box-shadow: 0 20px 30px rgba(0, 0, 0, 0.25) !important;
    border-radius: 14px !important;
    z-index: 99999 !important;
  }

  /* ترتيب روابط القائمة لتبدو أنيقة وواضحة */
  .dropdown-menu a,
  .tools-dropdown a {
    padding: 0.65rem 0.85rem !important;
    font-size: 0.85rem !important;
  }
}