/* ============================================================
   AGRICOLA – World-Class Mobile UX Layer
   Bottom nav, skeleton loading, touch states, micro-animations
   ============================================================ */

/* ── Safe-area body adjustment for bottom nav ──────────────── */
@media (max-width: 900px) {
  body {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }
  /* vehicles page: float FAB above bottom nav */
  .filter-fab {
    bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* ── Bottom Navigation Bar ─────────────────────────────────── */
#bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 990;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--color-bg-glass);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
}

@media (max-width: 900px) {
  #bottom-nav {
    display: flex;
  }
}

.bottom-nav-inner {
  display: flex;
  align-items: stretch;
  width: 100%;
  height: 64px;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--color-text-dim);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  text-decoration: none;
  position: relative;
  transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding: 4px 0;
}

.bottom-nav-item:active {
  opacity: 0.7;
}

.bottom-nav-item i {
  font-size: 1.25rem;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.2s ease;
}

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

.bottom-nav-item.active i {
  transform: translateY(-2px) scale(1.08);
}

/* Active indicator pill */
.bottom-nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 3px;
  background: var(--color-primary-light);
  border-radius: 0 0 3px 3px;
}

/* Donate tab accent */
.bottom-nav-item.nav-donate-tab {
  color: var(--color-accent);
}

.bottom-nav-item.nav-donate-tab.active {
  color: var(--color-accent);
}

.bottom-nav-item.nav-donate-tab.active::before {
  background: var(--color-accent);
}

/* ── Skeleton Loading (Vehicle Grid) ───────────────────────── */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  pointer-events: none;
}

.skeleton-photo {
  height: 200px;
  background: linear-gradient(
    90deg,
    var(--color-surface) 0%,
    var(--color-surface-light) 25%,
    var(--color-surface) 50%,
    var(--color-surface-light) 75%,
    var(--color-surface) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
}

.skeleton-body {
  padding: var(--space-lg);
}

.skeleton-line {
  height: 12px;
  border-radius: 6px;
  margin-bottom: 10px;
  background: linear-gradient(
    90deg,
    var(--color-surface) 0%,
    var(--color-surface-light) 25%,
    var(--color-surface) 50%,
    var(--color-surface-light) 75%,
    var(--color-surface) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
}

.skeleton-line.line-short  { width: 40%; }
.skeleton-line.line-medium { width: 65%; }
.skeleton-line.line-wide   { width: 85%; }
.skeleton-line.line-full   { width: 100%; }
.skeleton-line.line-title  { height: 18px; width: 75%; margin-bottom: 14px; }

.skeleton-chips {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.skeleton-chip {
  height: 26px;
  width: 68px;
  border-radius: 99px;
  background: linear-gradient(
    90deg,
    var(--color-surface) 0%,
    var(--color-surface-light) 25%,
    var(--color-surface) 50%,
    var(--color-surface-light) 75%,
    var(--color-surface) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
  flex-shrink: 0;
}

.skeleton-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--color-border);
}

.skeleton-footer .skeleton-line {
  margin-bottom: 0;
}

/* Stagger animation delays */
.skeleton-card:nth-child(2) .skeleton-photo,
.skeleton-card:nth-child(2) .skeleton-line,
.skeleton-card:nth-child(2) .skeleton-chip { animation-delay: 0.1s; }

.skeleton-card:nth-child(3) .skeleton-photo,
.skeleton-card:nth-child(3) .skeleton-line,
.skeleton-card:nth-child(3) .skeleton-chip { animation-delay: 0.2s; }

.skeleton-card:nth-child(4) .skeleton-photo,
.skeleton-card:nth-child(4) .skeleton-line,
.skeleton-card:nth-child(4) .skeleton-chip { animation-delay: 0.3s; }

.skeleton-card:nth-child(5) .skeleton-photo,
.skeleton-card:nth-child(5) .skeleton-line,
.skeleton-card:nth-child(5) .skeleton-chip { animation-delay: 0.15s; }

.skeleton-card:nth-child(6) .skeleton-photo,
.skeleton-card:nth-child(6) .skeleton-line,
.skeleton-card:nth-child(6) .skeleton-chip { animation-delay: 0.25s; }

/* ── Vehicle Card Touch & Hover Polish ─────────────────────── */
.vehicle-item {
  transform: translateZ(0);
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.vehicle-item:active {
  transform: scale(0.975) translateY(1px) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4) !important;
  border-color: rgba(74, 158, 74, 0.3) !important;
  transition: transform 0.1s ease, box-shadow 0.1s ease !important;
}

@media (hover: hover) {
  .vehicle-item:hover {
    transform: translateY(-5px) scale(1.01);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(74, 158, 74, 0.25);
    border-color: rgba(74, 158, 74, 0.4);
  }
}

.vehicle-item-photo img {
  transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
  will-change: transform;
}

@media (hover: hover) {
  .vehicle-item:hover .vehicle-item-photo img {
    transform: scale(1.05);
  }
}

/* Card appear animation */
@keyframes cardAppear {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.vehicle-item {
  animation: cardAppear 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.vehicle-item:nth-child(1)  { animation-delay: 0.00s; }
.vehicle-item:nth-child(2)  { animation-delay: 0.04s; }
.vehicle-item:nth-child(3)  { animation-delay: 0.08s; }
.vehicle-item:nth-child(4)  { animation-delay: 0.12s; }
.vehicle-item:nth-child(5)  { animation-delay: 0.16s; }
.vehicle-item:nth-child(6)  { animation-delay: 0.20s; }
.vehicle-item:nth-child(7)  { animation-delay: 0.24s; }
.vehicle-item:nth-child(8)  { animation-delay: 0.28s; }
.vehicle-item:nth-child(9)  { animation-delay: 0.32s; }
.vehicle-item:nth-child(10) { animation-delay: 0.36s; }
.vehicle-item:nth-child(n+11) { animation-delay: 0.4s; }

/* ── Filter Drawer — Spring Physics ────────────────────────── */
.filter-drawer {
  transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1) !important;
  will-change: transform;
}

.filter-drawer.open {
  transition: transform 0.38s cubic-bezier(0.34, 1.2, 0.64, 1) !important;
}

.filter-drawer-handle {
  width: 48px !important;
  height: 5px !important;
  background: rgba(255, 255, 255, 0.2) !important;
  border-radius: 3px !important;
  margin: 0 auto var(--space-lg) !important;
  cursor: grab;
  transition: width 0.2s ease, background 0.2s ease;
}

.filter-drawer-handle:active {
  cursor: grabbing;
  width: 64px !important;
  background: rgba(255, 255, 255, 0.35) !important;
}

/* ── Mobile Typography Scaling ─────────────────────────────── */
@media (max-width: 420px) {
  h1 { font-size: clamp(1.75rem, 7vw, 2.25rem); }
  h2 { font-size: clamp(1.4rem, 6vw, 1.8rem); }
}

/* ── Button Touch States ───────────────────────────────────── */
.btn,
button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.96) !important;
  transition: transform 0.08s ease !important;
}

@media (max-width: 640px) {
  .btn-primary {
    box-shadow: 0 4px 24px rgba(45, 106, 45, 0.4);
  }
}

/* ── Filter FAB Enhanced ───────────────────────────────────── */
.filter-fab {
  box-shadow: 0 8px 32px rgba(45, 106, 45, 0.55),
              0 2px 8px rgba(0, 0, 0, 0.4) !important;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.filter-fab:active {
  transform: translateX(-50%) scale(0.95) !important;
  box-shadow: 0 4px 16px rgba(45, 106, 45, 0.4) !important;
}

@keyframes fabEntrance {
  from { opacity: 0; transform: translateX(-50%) translateY(20px) scale(0.9); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

@media (max-width: 900px) {
  .filter-fab {
    animation: fabEntrance 0.4s 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }
}

/* ── Nav Hamburger Press Feedback ──────────────────────────── */
.nav-hamburger {
  position: relative;
  overflow: hidden;
}

.nav-hamburger::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(74, 158, 74, 0.3) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
  border-radius: inherit;
}

.nav-hamburger:active::after {
  opacity: 1;
}

/* ── Mobile Menu Active Indicator ──────────────────────────── */
#mobile-menu a {
  position: relative;
  overflow: hidden;
}

#mobile-menu a::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--color-primary-light);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.2s ease;
  border-radius: 2px;
}

#mobile-menu a.active::before {
  transform: scaleX(1);
}

/* ── Toast positioning with bottom nav ─────────────────────── */
@media (max-width: 900px) {
  #toast-container {
    bottom: calc(72px + env(safe-area-inset-bottom, 0px) + var(--space-md)) !important;
  }
}

/* ── Section spacing on tiny screens ───────────────────────── */
@media (max-width: 420px) {
  .section {
    padding: var(--space-2xl) 0;
  }
}

/* ── Footer with bottom nav ─────────────────────────────────── */
@media (max-width: 900px) {
  #footer {
    padding-bottom: var(--space-xl);
  }
}

/* ── Overscroll contain for filter drawer ───────────────────── */
@supports (overscroll-behavior: contain) {
  .filter-drawer {
    overscroll-behavior: contain;
  }
}

/* ── Vehicle Detail — Carousel Mobile Polish ───────────────── */
@media (max-width: 640px) {
  .carousel-arrow {
    width: 36px !important;
    height: 36px !important;
    font-size: 0.85rem !important;
  }
}

/* ── Form Inputs — Better Mobile UX ───────────────────────── */
@media (max-width: 640px) {
  input[type=text],
  input[type=email],
  input[type=tel],
  input[type=number],
  input[type=password],
  textarea,
  select {
    font-size: 16px !important; /* prevents iOS zoom-on-focus */
    min-height: 52px;
  }

  textarea {
    min-height: 120px;
  }

  /* Sticky submit button on contact/donate forms */
  .form-submit-sticky {
    position: sticky;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px) + 12px);
    z-index: 50;
    padding: 12px;
    margin: 0 -12px;
    background: linear-gradient(to top, var(--color-bg) 70%, transparent);
    border-radius: var(--radius-md);
  }
}

/* ── Section heading micro-animation ──────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.section-label,
.page-hero-breadcrumb {
  animation: fadeUp 0.5s 0.1s ease both;
}

/* ── Image lazy-load fade in ─────────────────────────────── */
img {
  transition: opacity 0.3s ease;
}

img[loading=lazy] {
  opacity: 0;
}

img[loading=lazy].loaded {
  opacity: 1;
}

/* ── Smooth scrollbar (webkit) ──────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-surface-light);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-dim);
}

/* ── Focus ring — premium accessible ─────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-primary-light);
  outline-offset: 3px;
  border-radius: 4px;
}
