/**
 * Responsive Mobile-First CSS for Instagram Unfollower Tracker
 * Optimized for mobile devices with proper tab handling and layout
 */

/* ============================================
   MOBILE RESPONSIVE STYLES (up to 768px)
   ============================================ */

@media (max-width: 768px) {
  /* Container padding for mobile */
  .container {
    max-width: 100%;
    margin: 20px auto;
    padding: 0 12px;
  }
  
  /* Header - stack on mobile */
  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
  }
  
  h1 {
    font-size: 22px;
  }
  
  /* Stats grid - 2 columns on mobile */
  .stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 12px 0 10px;
  }
  
  .stat-card {
    padding: 12px;
  }
  
  .stat-value {
    font-size: 18px;
  }
  
  .stat-label {
    font-size: 11px;
  }
  
  /* Status badge - smaller */
  .status-badge {
    font-size: 11px;
    padding: 5px 8px;
  }
  
  /* Controls - stack on mobile */
  .controls {
    flex-direction: column;
    gap: 8px;
    margin: 10px 0 16px;
  }
  
  .btn {
    width: 100%;
    justify-content: center;
    padding: 12px 14px;
    font-size: 15px;
  }
  
  /* Unfollowers section */
  .unfollowers-section {
    padding: 12px;
    border-radius: 12px;
  }
  
  /* Tab navigation - horizontal scroll with NO wrapping */
  .tab-navigation {
    display: flex;
    flex-wrap: nowrap; /* CRITICAL: No wrapping on mobile */
    gap: 6px;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(107, 139, 255, 0.3) transparent;
    padding-bottom: 2px; /* Space for scrollbar */
  }
  
  /* Hide scrollbar for cleaner look */
  .tab-navigation::-webkit-scrollbar {
    height: 3px;
  }
  
  .tab-navigation::-webkit-scrollbar-track {
    background: transparent;
  }
  
  .tab-navigation::-webkit-scrollbar-thumb {
    background: rgba(107, 139, 255, 0.3);
    border-radius: 999px;
  }
  
  .tab-btn {
    padding: 8px 12px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0; /* CRITICAL: Prevent tabs from shrinking */
    flex-grow: 0;
    min-width: fit-content;
    text-align: center;
  }
  
  .tab-badge {
    padding: 2px 6px;
    font-size: 11px;
    min-width: 20px;
    text-align: center;
  }
  
  /* Section header - stack search box */
  .section-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin: 10px 0;
  }
  
  .section-header h2 {
    font-size: 16px !important;
  }
  
  .search-box {
    min-width: 100%;
    width: 100%;
    padding: 10px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  /* Unfollower items - touch-friendly */
  .unfollower-item {
    padding: 10px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  
  .unfollower-info {
    width: 100%;
  }
  
  .avatar {
    width: 40px;
    height: 40px;
    font-size: 14px;
  }
  
  .user-details h3 {
    font-size: 14px;
  }
  
  .user-details p {
    font-size: 11px;
  }
  
  .btn-small {
    width: 100%;
    padding: 10px;
    text-align: center;
  }
  
  /* Notifications - adjust for mobile */
  .notification-container {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
  
  .notification {
    padding: 12px;
  }
  
  .notification-icon {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
  
  .notification-title {
    font-size: 13px;
  }
  
  .notification-message {
    font-size: 12px;
  }
  
  /* Pagination - stack on mobile */
  .pagination-container {
    flex-direction: column;
    gap: 8px;
  }
  
  .pagination-btn {
    padding: 10px 16px;
    font-size: 14px;
  }
  
  .pagination-info {
    order: -1;
    margin-bottom: 4px;
  }
  
  /* Profile section */
  .profile-section {
    gap: 8px;
  }
  
  .profile-avatar {
    width: 36px;
    height: 36px;
  }
  
  .profile-name {
    font-size: 14px;
  }
  
  .logout-btn {
    padding: 6px 10px;
    font-size: 12px;
  }
}

/* ============================================
   SMALL MOBILE (up to 375px)
   ============================================ */

@media (max-width: 375px) {
  .container {
    padding: 0 10px;
    margin: 15px auto;
  }
  
  h1 {
    font-size: 20px;
  }
  
  .stats {
    gap: 8px;
  }
  
  .stat-card {
    padding: 10px;
    border-radius: 10px;
  }
  
  .stat-value {
    font-size: 16px;
  }
  
  .stat-label {
    font-size: 10px;
  }
  
  /* Slightly smaller tabs on tiny screens */
  .tab-btn {
    padding: 6px 10px;
    font-size: 12px;
  }
  
  .tab-badge {
    padding: 2px 5px;
    font-size: 10px;
    min-width: 18px;
  }
  
  .notification {
    padding: 10px;
  }
  
  .btn {
    padding: 11px 12px;
    font-size: 14px;
  }
}

/* ============================================
   TABLET PORTRAIT (769px - 1024px)
   ============================================ */

@media (min-width: 769px) and (max-width: 1024px) {
  .container {
    max-width: 720px;
    padding: 0 16px;
  }
  
  /* Stats - 4 columns on tablet */
  .stats {
    grid-template-columns: repeat(4, 1fr);
  }
  
  /* Section header - keep side by side */
  .section-header {
    flex-direction: row;
  }
  
  .search-box {
    min-width: 280px;
  }
  
  /* Tabs should not wrap on tablet - allow scroll if needed */
  .tab-navigation {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
  }
  
  .tab-btn {
    flex: 0 0 auto;
  }
}

/* ============================================
   LANDSCAPE MOBILE
   ============================================ */

@media (max-height: 600px) and (orientation: landscape) {
  .container {
    margin: 10px auto;
  }
  
  .stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 8px 0;
  }
  
  .stat-card {
    padding: 8px;
  }
  
  .stat-value {
    font-size: 16px;
  }
  
  .controls {
    flex-direction: row;
    margin: 8px 0 12px;
  }
  
  .btn {
    width: auto;
    padding: 8px 12px;
  }
  
  .unfollowers-section {
    padding: 10px;
  }
  
  .tab-btn {
    padding: 6px 10px;
  }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */

@media (hover: none) and (pointer: coarse) {
  /* Increase touch targets */
  .btn {
    min-height: 44px; /* iOS recommended touch target */
  }
  
  .tab-btn {
    min-height: 40px;
  }
  
  .unfollower-item {
    min-height: 64px;
  }
  
  .notification {
    min-height: 60px;
  }
  
  /* Remove hover effects on touch devices */
  .btn:hover,
  .tab-btn:hover,
  .unfollower-item:hover {
    transform: none;
  }
  
  /* Add active states for touch feedback */
  .btn:active {
    transform: scale(0.98);
    opacity: 0.9;
  }
  
  .tab-btn:active {
    opacity: 0.8;
  }
}

/* ============================================
   PWA-SPECIFIC STYLES
   ============================================ */

/* Installed as PWA - remove unnecessary browser chrome */
@media (display-mode: standalone) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  .container {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  
  /* Hide logout button when installed as app */
  .logout-btn {
    display: none;
  }
}

/* iOS notch support */
@supports (padding: max(0px)) {
  .header {
    padding-top: max(12px, env(safe-area-inset-top));
  }
  
  .notification-container {
    top: max(10px, env(safe-area-inset-top));
  }
}

/* ============================================
   LOADING STATES & ANIMATIONS
   ============================================ */

.loading-state {
  text-align: center;
  padding: 40px 20px;
}

.loading-text {
  font-size: 16px;
  margin-bottom: 20px;
  color: var(--text);
}

.loading-bar-container {
  width: 100%;
  max-width: 300px;
  height: 4px;
  background: #1a1f47;
  border-radius: 999px;
  overflow: hidden;
  margin: 0 auto 16px;
}

.loading-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
  0% {
    transform: translateX(-100%);
  }
  50% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(100%);
  }
}

.loading-subtext {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 24px;
}

.scan-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 300px;
  margin: 0 auto;
}

.scan-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: #161b3e;
  border-radius: 8px;
  opacity: 0.5;
  transition: opacity 0.3s;
}

.scan-step.active {
  opacity: 1;
}

.scan-step-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.scan-step-text {
  font-size: 13px;
  color: var(--text);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
   EMPTY STATE
   ============================================ */

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 14px;
  line-height: 1.6;
}

@media (max-width: 768px) {
  .empty-state {
    padding: 40px 16px;
  }
  
  .empty-state-icon {
    font-size: 40px;
  }
  
  .empty-state p {
    font-size: 13px;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Hide on mobile */
.hide-mobile {
  display: none !important;
}

@media (min-width: 769px) {
  .hide-mobile {
    display: block !important;
  }
}

/* Hide on desktop */
.hide-desktop {
  display: block !important;
}

@media (min-width: 769px) {
  .hide-desktop {
    display: none !important;
  }
}

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

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .controls,
  .notification-container,
  .status-badge,
  .btn,
  .logout-btn {
    display: none !important;
  }
  
  .container {
    max-width: 100%;
  }
  
  .unfollowers-section {
    border: 1px solid #ddd;
  }
  
  .tab-navigation {
    display: none !important;
  }
  
  .list-container {
    display: block !important;
    page-break-inside: avoid;
  }
}

/* ============================================
   HIGH DPI DISPLAYS
   ============================================ */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .avatar img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}
