/* Enhanced Bottom Navigation Bar Styles with Better Accessibility */
.bottom-navbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--ds-surface);
  border-top: 1px solid var(--ds-line-2);
  box-shadow: 0 -4px 20px rgba(var(--ds-shadow-rgb), 0.08);
  z-index: 999;
  display: none; /* Hidden by default, shown on mobile */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-height: 70px; /* Minimum touch target size */
  /* Isolate so absolute children (the FAB) don't escape on Safari ≤16. */
  isolation: isolate;
}

.bottom-nav-container {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 12px 8px max(12px, env(safe-area-inset-bottom));
  max-width: 100vw;
  margin: 0 auto;
  direction: rtl;
  min-height: 70px; /* Ensure adequate touch targets */
}

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 56px;
  padding: 8px 6px;
  text-decoration: none;
  color: var(--ds-muted, #7D8B94);
  transition: color 200ms cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 14px;
  position: relative;
  cursor: pointer;
  background: transparent;
  border: 0;
  outline: none;
  flex: 1;
  max-width: 88px;
}

/* Accent bar that animates in on the active item — runs across the top
   of the item. Subtle but unambiguous. */
.bottom-nav-item::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 28px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--ds-brand, #00A693);
  transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center;
}
.bottom-nav-item.active::before { transform: translateX(-50%) scaleX(1); }

.bottom-nav-item:focus-visible {
  outline: 2px solid var(--ds-brand, #00A693);
  outline-offset: 2px;
}

.bottom-nav-item:hover { color: var(--ds-brand, #00A693); }
.bottom-nav-item.active { color: var(--ds-brand-800, #005B5D); font-weight: 700; }

.nav-icon-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  transition: background 200ms cubic-bezier(0.4, 0, 0.2, 1), transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
  margin-bottom: 2px;
}

.bottom-nav-item:hover .nav-icon-wrapper { background: var(--ds-brand-50, #E6F7F4); }
.bottom-nav-item.active .nav-icon-wrapper {
  background: var(--ds-brand-50, #E6F7F4);
  color: var(--ds-brand, #00A693);
}
.bottom-nav-item:active .nav-icon-wrapper { transform: scale(0.94); }

/* Search Item Special Styling (Middle Icon) */
.bottom-nav-item.search-item .nav-icon-wrapper {
  background: var(--primary-brand, #00A693);
  width: 48px;
  height: 48px;
  box-shadow: 0 4px 16px rgba(0, 166, 147, 0.3);
  margin-bottom: 2px;
}

.bottom-nav-item.search-item .nav-icon-wrapper:hover {
  background: var(--brand-dark, #005B5D);
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 166, 147, 0.4);
}

.search-icon-wrapper {
  background: linear-gradient(135deg, var(--primary-brand, #00A693), var(--brand-dark, #005B5D)) !important;
}

.nav-icon {
  font-size: 1.05rem;
  transition: color 200ms cubic-bezier(0.4, 0, 0.2, 1);
}
.bottom-nav-item.active .nav-icon { color: var(--ds-brand, #00A693); }

.search-nav-icon {
  color: white !important;
  font-size: 20px;
  font-weight: 900;
}

.bottom-nav-item.search-item {
  color: var(--primary-brand, #00A693);
  font-weight: 600;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 64px;
  transition: color 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.bottom-nav-item.search-item .nav-label {
  font-weight: 600;
  color: var(--primary-brand, #00A693);
}

/* Notification Badge */
.notification-badge {
  position: absolute;
  top: -2px;
  inset-inline-end: -2px;
  background: var(--ds-action-danger);
  color: #ffffff;
  border-radius: 50%;
  min-width: 16px;
  height: 16px;
  font-size: var(--ds-text-xs);
  font-weight: var(--ds-weight-bold);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.32);
  border: 2px solid var(--ds-surface);
  z-index: 1;
}

/* Search Modal Styles */
.search-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: none;
  opacity: 0;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.search-modal.active {
  opacity: 1;
}

.search-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.search-modal-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--primary-bg, #FFFFFF);
  border-radius: 20px 20px 0 0;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  direction: rtl;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
}

.search-modal.active .search-modal-content {
  transform: translateY(0);
}

.search-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-color, #E5E7EB);
  position: sticky;
  top: 0;
  background: var(--primary-bg, #FFFFFF);
  z-index: 1;
}

.search-modal-header h3 {
  font-size: var(--ds-text-lg);
  font-weight: 700;
  color: var(--primary-text, #333333);
  margin: 0;
}

.close-search-btn {
  background: none;
  border: none;
  padding: 8px;
  border-radius: 50%;
  color: var(--secondary-text, #7D8B94);
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}

.close-search-btn:hover {
  background: var(--hover-bg, #F9FAFB);
  color: var(--primary-text, #333333);
}

.search-modal-body {
  padding: 24px;
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.search-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-field label {
  font-size: var(--ds-text-sm);
  font-weight: 600;
  color: var(--primary-text, #333333);
  text-align: right;
}

.search-select,
.search-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border-color, #E5E7EB);
  border-radius: 12px;
  font-size: var(--ds-text-base);
  color: var(--primary-text, #333333);
  background: var(--primary-bg, #FFFFFF);
  transition: all 0.3s ease;
  text-align: right;
  direction: rtl;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.search-select:focus,
.search-input:focus {
  outline: none;
  border-color: var(--primary-brand, #00A693);
  box-shadow: 0 0 0 3px rgba(0, 166, 147, 0.1);
}

.search-input-container {
  position: relative;
}

.search-input-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--secondary-text, #7D8B94);
  font-size: var(--ds-text-base);
  pointer-events: none;
}

.search-input {
  padding-left: 48px;
}

/* Enhanced Fieldset and Radio Group Styles */
.transaction-fieldset {
  border: none;
  margin: 0;
  padding: 0;
}

.transaction-legend {
  font-size: var(--ds-text-sm);
  font-weight: 600;
  color: var(--primary-text, #333333);
  text-align: right;
  margin-bottom: 8px;
  padding: 0;
}

.radio-group {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: var(--ds-text-sm);
  color: var(--primary-text, #333333);
  position: relative;
  padding: 8px 0;
}

.radio-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.radio-custom {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-color, #E5E7EB);
  border-radius: 50%;
  position: relative;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.radio-custom::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary-brand, #00A693);
  transition: transform 0.3s ease;
}

.radio-option input[type="radio"]:checked + .radio-custom {
  border-color: var(--primary-brand, #00A693);
}

.radio-option input[type="radio"]:checked + .radio-custom::after {
  transform: translate(-50%, -50%) scale(1);
}

/* Submit Button */
.search-submit-btn {
  background: var(--primary-brand, #00A693);
  color: white;
  border: none;
  padding: 16px 24px;
  border-radius: 12px;
  font-size: var(--ds-text-base);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  box-shadow: 0 4px 16px rgba(0, 166, 147, 0.2);
}

.search-submit-btn:hover {
  background: var(--brand-dark, #005B5D);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 166, 147, 0.3);
}

.search-submit-btn:active {
  transform: translateY(0);
}

/* Enhanced Icon Styles for Better Visibility */
.nav-icon {
  font-family: "Font Awesome 6 Free", "Font Awesome 5 Free", "FontAwesome" !important;
  font-weight: 900 !important;
  font-style: normal !important;
  display: inline-block !important;
  line-height: 1 !important;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Specific icon adjustments for better visual balance */
.bottom-nav-item[data-page="buy"] .nav-icon {
  font-size: 17px; /* Slightly smaller for fa-building */
}

.bottom-nav-item[data-page="rent"] .nav-icon {
  font-size: var(--ds-text-base); /* Smaller for fa-handshake to balance visual weight */
}

.bottom-nav-item[data-page="profile"] .nav-icon {
  font-size: 19px; /* Slightly larger for fa-user-circle */
}

/* Search icon specific styling */
.search-nav-icon {
  font-size: 20px !important;
  font-weight: 900 !important;
}

/* Enhanced Mobile Responsive Styles */
@media (max-width: 768px) {
  .bottom-navbar {
    display: block;
  }

  /* Body padding = nav height + FAB protrusion (22px) + safe-area
     + a 12px breathing room. The FAB rises 22px above the nav, so
     content scrolled to the bottom needs that extra clearance or it
     sits under the FAB. */
  body {
    padding-bottom: calc(var(--ds-bottom-nav-h) + 22px + var(--ds-safe-bottom) + 12px);
  }
  
  /* Adjust navbar container padding for smaller screens while maintaining accessibility */
  .bottom-nav-container {
    padding: 10px 4px max(10px, env(safe-area-inset-bottom));
    min-height: 76px; /* Adequate touch targets */
  }
  
  .bottom-nav-item {
    min-width: 56px; /* Maintain minimum touch target */
    min-height: 60px; /* Ensure adequate height */
    padding: 6px 3px;
  }
  
  .nav-icon-wrapper {
    width: 40px; /* Slightly reduced but still accessible */
    height: 40px;
    margin-bottom: 2px;
  }
  
  .bottom-nav-item.search-item .nav-icon-wrapper {
    width: 48px; /* Keep search prominent */
    height: 48px;
  }
  
  .nav-icon {
    font-size: var(--ds-text-lg); /* Slightly larger for visibility */
  }
  
  .search-nav-icon {
    font-size: 20px; /* Keep search icon prominent */
  }
  
  .nav-label {
    font-size: var(--ds-text-xs); /* Slightly larger for readability */
    font-weight: 500;
  }
}

@media (max-width: 480px) {
  .bottom-nav-container {
    padding: 8px 2px max(8px, env(safe-area-inset-bottom));
    min-height: 72px; /* Maintain minimum height */
  }
  
  .bottom-nav-item {
    min-width: 52px; /* Still accessible touch target */
    min-height: 56px; /* Maintain WCAG compliance */
    padding: 4px 2px;
  }
  
  .nav-icon-wrapper {
    width: 36px; /* Reduced but still usable */
    height: 36px;
    margin-bottom: 1px;
  }
  
  .bottom-nav-item.search-item .nav-icon-wrapper {
    width: 44px; /* Keep search prominent */
    height: 44px;
  }
  
  .nav-icon {
    font-size: var(--ds-text-base); /* Maintain visibility */
  }
  
  .search-nav-icon {
    font-size: var(--ds-text-lg); /* Keep search visible */
  }
  
  .nav-label {
    font-size: var(--ds-text-xs); /* Maintain readability */
    font-weight: 500;
  }
  
  .notification-badge {
    min-width: 16px;
    height: 16px;
    font-size: var(--ds-text-xs);
    top: -2px;
    right: -2px;
  }
  /* body padding-bottom inherited from the 768px breakpoint. */
}

/* Hide on desktop */
@media (min-width: 769px) {
  .bottom-navbar {
    display: none !important;
  }
  
  body {
    padding-bottom: 0;
  }
}

/* Safe area support for devices with notches */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav-container {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

/* Active state management */
body.home-page .bottom-nav-item[data-page="home"],
body.properties-page .bottom-nav-item[data-page="buy"],
body.properties-page .bottom-nav-item[data-page="rent"],
body.profile-page .bottom-nav-item[data-page="profile"],
body.login-page .bottom-nav-item[data-page="login"] {
  color: var(--primary-brand, #00A693) !important;
}

body.home-page .bottom-nav-item[data-page="home"] .nav-icon-wrapper,
body.properties-page .bottom-nav-item[data-page="buy"] .nav-icon-wrapper,
body.properties-page .bottom-nav-item[data-page="rent"] .nav-icon-wrapper,
body.profile-page .bottom-nav-item[data-page="profile"] .nav-icon-wrapper,
body.login-page .bottom-nav-item[data-page="login"] .nav-icon-wrapper {
  background: rgba(0, 166, 147, 0.1);
  transform: scale(1.05);
}

/* Accessibility improvements */
.bottom-nav-item:focus-visible {
  outline: 2px solid var(--primary-brand, #00A693);
  outline-offset: 2px;
}

.search-submit-btn:focus-visible,
.close-search-btn:focus-visible {
  outline: 2px solid var(--primary-brand, #00A693);
  outline-offset: 2px;
}

/* Animation for modal */
@keyframes modalSlideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes modalSlideDown {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(100%);
  }
}

.search-modal.closing .search-modal-content {
  animation: modalSlideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* =========================================================
   Centered FAB — "ثبت آگهی" primary action on mobile nav
   ========================================================= */
.bottom-nav-fab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 72px;
  /* Padding has to clear the absolutely-positioned button. The button rises
     22 px above the bar and is 48 px tall ⇒ its bottom edge sits at
     -22 + 48 = 26 px from the container top. We need the label below that. */
  padding-top: 34px;
  color: var(--ds-brand-800, #005B5D);
  text-decoration: none;
  flex: 0 0 auto;
}

.bottom-nav-fab__btn {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--ds-brand, #00A693);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--ds-text-lg);
  box-shadow:
    0 8px 20px rgba(0, 166, 147, 0.32),
    0 3px 8px rgba(0, 0, 0, 0.14),
    0 0 0 3px #fff;             /* cut-out ring to lift above the nav bar */
  transition: transform var(--ds-fast, 150ms cubic-bezier(.4,0,.2,1)),
              background var(--ds-fast, 150ms cubic-bezier(.4,0,.2,1)),
              box-shadow var(--ds-fast, 150ms cubic-bezier(.4,0,.2,1));
}

.bottom-nav-fab:hover .bottom-nav-fab__btn,
.bottom-nav-fab:focus-visible .bottom-nav-fab__btn {
  background: var(--ds-brand-700, #007B6E);
  transform: translateX(-50%) scale(1.06);
  box-shadow:
    0 12px 24px rgba(0, 166, 147, 0.42),
    0 0 0 3px #fff;
}

.bottom-nav-fab:active .bottom-nav-fab__btn {
  transform: translateX(-50%) scale(0.98);
}

.bottom-nav-fab .nav-label {
  font-size: var(--ds-text-xs);
  font-weight: 700;
  color: var(--ds-brand-800, #005B5D);
  margin-top: 2px;
  line-height: 1;
}

/* Safe-area extra padding below the nav so the FAB isn't cut off on notched devices */
.bottom-navbar {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
