/* ===== RESPONSIVE ENHANCEMENTS & MOBILE PERFECTION ===== */
/* Perfect experience for both desktop and mobile devices */

/* ===== MOBILE-FIRST TOUCH TARGETS ===== */
/* Ensure all interactive elements are at least 44x44px for easy touch */
@media (max-width: 768px) {
  button,
  .btn-primary,
  .btn-secondary,
  .btn-outline,
  .nav-link,
  a[role="button"] {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem 1.25rem;
  }

  /* Larger touch targets for icons */
  .btn-notifications,
  .btn-user-avatar {
    min-height: 48px;
    min-width: 48px;
  }
}

/* ===== MOBILE NAVIGATION IMPROVEMENTS ===== */
@media (max-width: 1024px) {
  .nav-container {
    padding: 0 1rem;
    height: auto;
    min-height: 70px;
    flex-direction: column;
    gap: 1rem;
    padding-top: 1rem;
    padding-bottom: 1rem;
  }

  .nav-logo {
    width: 100%;
    justify-content: center;
  }

  .nav-links {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }

  .nav-actions {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }

  /* Ensure icons are properly aligned on mobile */
  .nav-icon,
  .points-icon,
  .notification-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Hide nav link text on very small screens, show only icons */
  @media (max-width: 480px) {
    .nav-link span:not(.nav-icon) {
      display: none;
    }

    .nav-link {
      min-width: 48px;
      padding: 0.75rem;
    }
  }
}

/* ===== MOBILE TYPOGRAPHY OPTIMIZATION ===== */
@media (max-width: 768px) {
  :root {
    /* Adjust font sizes for better mobile readability */
    --mobile-scale: 0.9;
  }

  h1 {
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    line-height: 1.2;
  }

  h2 {
    font-size: clamp(1.5rem, 4vw, 2rem);
    line-height: 1.3;
  }

  h3 {
    font-size: clamp(1.25rem, 3.5vw, 1.75rem);
    line-height: 1.4;
  }

  p {
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    line-height: 1.6;
  }

  /* Improve text spacing for mobile */
  .user-greeting h1 {
    font-size: clamp(1.75rem, 6vw, 2.5rem);
    margin-bottom: 0.5rem;
  }

  .giveaways-hero h1 {
    font-size: clamp(1.75rem, 6vw, 2.6rem);
  }
}

/* ===== MOBILE SPACING & LAYOUT ===== */
@media (max-width: 768px) {
  .main-grid {
    padding: 1rem 1rem 3rem;
  }

  .dashboard-container {
    padding: 1rem;
  }

  .welcome-section,
  .giveaways-hero {
    padding: 1.25rem;
    gap: 1rem;
  }

  .dashboard-card .card-header,
  .dashboard-card .card-body {
    padding: 1rem;
  }

  /* Stack elements vertically on mobile */
  .welcome-content,
  .giveaways-hero {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }

  .quick-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .giveaways-metrics {
    justify-content: center;
    width: 100%;
  }
}

/* ===== MOBILE CARDS & COMPONENTS ===== */
@media (max-width: 640px) {
  .giveaways-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .giveaway-card {
    max-width: 100%;
  }

  .dashboard-grid {
    gap: 1rem;
  }

  .quick-stats {
    grid-template-columns: 1fr;
  }

  .quick-stat {
    padding: 0.875rem;
  }

  .stat-icon {
    width: 44px;
    height: 44px;
    font-size: 1.75rem;
  }
}

/* ===== MOBILE FORM IMPROVEMENTS ===== */
@media (max-width: 768px) {
  .form-input,
  .form-textarea,
  .form-select {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
  }

  .form-group {
    gap: 0.625rem;
  }

  .profile-form,
  .form-row {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* ===== ENHANCED TOUCH INTERACTIONS ===== */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch devices */
  .btn-primary:hover::before {
    display: none;
  }

  /* Add active states for better touch feedback */
  button:active,
  .btn-primary:active,
  .btn-secondary:active,
  .btn-outline:active {
    transform: scale(0.97);
    transition: transform 0.1s ease;
  }

  .giveaway-card:active,
  .dashboard-card:active,
  .list-item:active {
    transform: scale(0.99);
  }

  /* Increase tap target areas */
  .nav-link,
  .filter-btn {
    padding: 0.75rem 1.25rem;
  }
}

/* ===== MOBILE NOTIFICATIONS & DROPDOWNS ===== */
@media (max-width: 768px) {
  .notifications-dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 70vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(0);
  }

  .notifications-list {
    max-height: calc(70vh - 120px);
  }

  .toast-container {
    top: 1rem;
    right: 1rem;
    left: 1rem;
  }

  .toast {
    min-width: auto;
    width: 100%;
  }
}

/* ===== MOBILE LEADERBOARD ===== */
@media (max-width: 768px) {
  .leaderboard-hero {
    flex-direction: column;
    padding: 1.25rem;
    gap: 1rem;
  }

  .leaderboard-hero h1 {
    font-size: 1.5rem;
  }

  .leaderboard-controls {
    width: 100%;
  }

  .leaderboard-stats-card {
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
  }

  .lb-stat {
    flex-direction: row;
    justify-content: space-between;
    width: 100%;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
  }

  .lb-stat:last-child {
    border-bottom: none;
  }

  .leaderboard-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1rem;
    padding: 0 1rem;
  }

  .leaderboard-table {
    font-size: 0.875rem;
    min-width: 500px;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 0.75rem 0.5rem;
  }

  /* Hide less important columns on mobile */
  .leaderboard-table th:nth-child(3),
  .leaderboard-table td:nth-child(3),
  .leaderboard-table th:nth-child(6),
  .leaderboard-table td:nth-child(6) {
    display: none;
  }

  .leaderboard-pagination {
    flex-direction: column;
    gap: 0.75rem;
    align-items: stretch;
  }

  .leaderboard-pagination button {
    width: 100%;
  }

  .leaderboard-user-card {
    padding: 1rem;
  }

  .leaderboard-user-stats {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .lb-user-pill {
    flex: 1 1 45%;
    min-width: 0;
    padding: 0.5rem;
    font-size: 0.85rem;
  }

  .rank-badge {
    width: 32px;
    height: 32px;
    font-size: 0.875rem;
  }

  .user-avatar {
    width: 36px;
    height: 36px;
  }

  .leaderboard-avatar {
    width: 36px;
    height: 36px;
  }
}

/* ===== SMOOTH SCROLLING ===== */
html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent horizontal scroll on mobile */
body {
  overflow-x: hidden;
}

/* ===== MOBILE SAFE AREAS (iOS NOTCH) ===== */
@supports (padding: env(safe-area-inset-top)) {
  .navbar {
    padding-top: env(safe-area-inset-top);
  }

  .discord-float-btn {
    bottom: calc(20px + env(safe-area-inset-bottom));
    right: calc(20px + env(safe-area-inset-right));
  }

  .notifications-dropdown {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ===== DESKTOP ENHANCEMENTS (1200px+) ===== */
@media (min-width: 1200px) {
  .main-grid {
    padding: 2.5rem 2rem 4rem;
  }

  .dashboard-container {
    grid-template-columns: 1fr 350px;
    gap: 2rem;
  }

  .giveaways-grid {
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 2rem;
  }

  .welcome-section,
  .giveaways-hero {
    padding: 2.5rem 3rem;
  }

  /* Larger hover effects on desktop */
  .giveaway-card:hover {
    transform: translateY(-6px);
  }

  .dashboard-card:hover {
    transform: translateY(-3px);
  }
}

/* ===== ULTRA-WIDE DESKTOP (1600px+) ===== */
@media (min-width: 1600px) {
  .main-grid {
    max-width: 1600px;
  }

  .giveaways-grid {
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  }

  .dashboard-container {
    grid-template-columns: 1fr 400px;
  }
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .border-flow,
  .pulse-glow,
  .discord-pulse {
    animation: none !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border: rgba(0, 102, 255, 0.4);
    --border-hover: rgba(0, 102, 255, 0.6);
  }

  .btn-primary,
  .btn-secondary,
  .btn-outline {
    border-width: 2px;
  }
}

/* ===== DARK MODE ENHANCEMENTS (Already dark, but deeper on preference) ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #0f1420;
    --bg-card: #141824;
  }
}

/* ===== LANDSCAPE MOBILE OPTIMIZATION ===== */
@media (max-width: 900px) and (orientation: landscape) {
  .welcome-section,
  .giveaways-hero {
    flex-direction: row;
    padding: 1.5rem;
  }

  .quick-stats {
    grid-template-columns: repeat(4, 1fr);
  }

  .navbar {
    position: sticky;
  }
}

/* ===== TABLET OPTIMIZATION (768px - 1024px) ===== */
@media (min-width: 768px) and (max-width: 1024px) {
  .giveaways-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .quick-stats {
    grid-template-columns: repeat(4, 1fr);
  }

  .welcome-section,
  .giveaways-hero {
    padding: 2rem;
  }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

/*
 * Note: will-change removed to prevent memory overhead.
 * GPU acceleration via translateZ(0) is applied only where truly needed.
 * For animated elements, will-change should be added via JS just before
 * animation starts and removed after completion.
 */

/* Optimize repaints for frequently updated elements */
.notification-badge,
.discord-float-btn {
  transform: translateZ(0);
}

/* ===== PRINT STYLES ===== */
@media print {
  .navbar,
  .nav-actions,
  .discord-float-btn,
  .notifications-dropdown,
  .toast-container {
    display: none !important;
  }

  .dashboard-card,
  .giveaway-card {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body {
    background: white;
    color: black;
  }
}
