/* Comprehensive Responsive Design for TextMyStocks */

/* Base responsive breakpoints */
:root {
  --mobile-max: 576px;
  --tablet-max: 768px;
  --desktop-min: 992px;
  --large-desktop-min: 1200px;
}

/* Global responsive utilities */
* {
  box-sizing: border-box;
}

/* Ensure images are responsive by default */
img {
  max-width: 100%;
  height: auto;
}

/* Container responsive adjustments */
.container {
  width: 100%;
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

@media (min-width: 576px) {
  .container {
    max-width: 540px;
  }
}

@media (min-width: 768px) {
  .container {
    max-width: 720px;
  }
}

@media (min-width: 992px) {
  .container {
    max-width: 960px;
  }
}

@media (min-width: 1200px) {
  .container {
    max-width: 1140px;
  }
}

/* Mobile-first navigation improvements */
.navbar {
  padding: 0.5rem 0;
  position: relative;
}

.navbar .container {
  position: relative;
}

.navbar-toggler {
  border: none;
  padding: 0.25rem 0.5rem;
  font-size: 1.25rem;
  background: transparent;
  z-index: 1001;
}

.navbar-toggler:focus {
  box-shadow: none;
  outline: none;
}

.navbar-brand {
  font-size: 1.25rem;
  font-weight: 700;
}

/* Mobile navigation */
@media (max-width: 767px) {
  .navbar-brand {
    font-size: 1.1rem;
  }
  
  .navbar-collapse {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border-radius: 8px;
    margin-top: 0.5rem;
    padding: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
  }
  
  .navbar-collapse.collapsing {
    transition: height 0.3s ease;
  }
  
  .navbar-nav {
    text-align: center;
  }
  
  .navbar-nav .nav-item {
    margin: 0.25rem 0;
  }
  
  .navbar-nav .nav-link {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    display: block;
    width: 100%;
  }
  
  .navbar-nav .nav-link:hover,
  .navbar-nav .nav-link:focus {
    background-color: rgba(59, 130, 246, 0.1);
  }
}

/* Dashboard sidebar responsive behavior */
.sidebar {
  transition: transform 0.3s ease-in-out;
}

/* Mobile sidebar - hidden by default */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: 1050;
    transform: translateX(-100%);
    background: white;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  }
  
  .sidebar.show {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0;
    padding: 1rem;
    width: 100%;
  }
  
  /* Mobile menu button */
  .mobile-menu-btn {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1060;
    background: var(--primary-blue, #3b82f6);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 1.25rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: block;
  }
  
  .mobile-menu-btn:hover {
    background: var(--primary-blue-dark, #2563eb);
  }
  
  /* Overlay for mobile sidebar */
  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
  }
  
  .sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
  }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 991px) {
  .sidebar {
    width: 200px;
  }
  
  .main-content {
    margin-left: 200px;
    padding: 1.5rem;
  }
  
  .mobile-menu-btn {
    display: none;
  }
}

/* Desktop - hide mobile menu button */
@media (min-width: 992px) {
  .mobile-menu-btn {
    display: none;
  }
}

/* Grid system responsive adjustments */
.usage-stats {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* Mobile: single column */
@media (max-width: 576px) {
  .usage-stats {
    grid-template-columns: 1fr;
  }
  
  .payg-options {
    grid-template-columns: 1fr !important;
  }
  
  .billing-frequency {
    grid-template-columns: 1fr !important;
  }
  
  /* Plan selector adjustments */
  .plan-selector-container {
    grid-template-columns: 1fr !important;
  }
}

/* Tablet: two columns */
@media (min-width: 577px) and (max-width: 768px) {
  .usage-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .payg-options {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  .plan-selector-container {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* Desktop: three columns */
@media (min-width: 769px) {
  .usage-stats {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .payg-options {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  
  .plan-selector-container {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* Typography responsive scaling */
@media (max-width: 576px) {
  .page-title {
    font-size: 1.5rem !important;
  }
  
  .section-title {
    font-size: 1.25rem !important;
  }
  
  .hero h1 {
    font-size: 2rem !important;
  }
  
  .hero .lead {
    font-size: 1rem !important;
  }
  
  .usage-stat-value {
    font-size: 1.5rem !important;
  }
}

@media (min-width: 577px) and (max-width: 768px) {
  .page-title {
    font-size: 1.75rem !important;
  }
  
  .section-title {
    font-size: 1.375rem !important;
  }
  
  .hero h1 {
    font-size: 2.5rem !important;
  }
}

/* Button responsive adjustments */
@media (max-width: 576px) {
  .btn-primary,
  .btn-secondary,
  .btn-outline {
    width: 100%;
    margin-bottom: 0.5rem;
    margin-right: 0 !important;
  }
  
  .hero-buttons {
    flex-direction: column;
    align-items: stretch;
  }
  
  .hero-buttons .btn {
    margin-bottom: 0.75rem;
    margin-right: 0 !important;
  }
}

/* Table responsive improvements */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
  .table {
    font-size: 0.875rem;
  }
  
  .table th,
  .table td {
    padding: 0.5rem;
    white-space: nowrap;
  }
}

/* Form responsive adjustments */
@media (max-width: 576px) {
  .form-control,
  .form-select,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  textarea {
    font-size: 16px !important; /* Prevents zoom on iOS */
  }
  
  .referral-link-box {
    flex-direction: column;
  }
  
  .referral-link-box .btn {
    margin-top: 0.5rem;
    margin-left: 0 !important;
  }
  
  /* Ensure form containers are properly sized */
  .form-container,
  .register-container,
  .login-container {
    padding: 1rem !important;
    margin: 0.5rem !important;
  }
  
  /* Phone input prefix adjustment for mobile */
  .phone-prefix {
    font-size: 14px !important;
    padding: 0.5rem !important;
  }
  
  #phone {
    padding-left: 65px !important;
  }
}

/* Hero section responsive improvements */
.hero {
  padding: 2rem 0;
  min-height: auto;
}

@media (max-width: 768px) {
  .hero {
    padding: 1.5rem 0;
    text-align: center;
  }
  
  .hero-content {
    padding: 0 1rem;
  }
  
  .phone-mockup {
    width: 200px !important;
    height: 400px !important;
    margin: 2rem auto 0;
  }
  
  .welcome-message {
    flex-direction: column;
    text-align: center;
  }
  
  .welcome-icon {
    margin: 0 auto 1rem;
  }
}

/* Card and content section responsive adjustments */
.content-section {
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 576px) {
  .content-section {
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 8px;
  }
}

/* Admin dashboard responsive adjustments */
@media (max-width: 767px) {
  .stats-cards {
    grid-template-columns: 1fr;
  }
  
  .stats-cards .card {
    margin-bottom: 1rem;
  }
}

@media (min-width: 768px) and (max-width: 991px) {
  .stats-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Utility classes for responsive display */
.d-mobile-none {
  display: block;
}

.d-mobile-block {
  display: none;
}

@media (max-width: 768px) {
  .d-mobile-none {
    display: none !important;
  }
  
  .d-mobile-block {
    display: block !important;
  }
}

/* Spacing adjustments for mobile */
@media (max-width: 576px) {
  .mb-4 {
    margin-bottom: 1.5rem !important;
  }
  
  .mb-3 {
    margin-bottom: 1rem !important;
  }
  
  .p-4 {
    padding: 1.5rem !important;
  }
  
  .p-3 {
    padding: 1rem !important;
  }
}

/* Ensure proper touch targets on mobile */
@media (max-width: 768px) {
  .btn,
  .nav-link,
  .plan-selector,
  .payg-option-card {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Fix for iOS Safari viewport units */
@supports (-webkit-touch-callout: none) {
  .hero {
    min-height: -webkit-fill-available;
  }
}

/* Print styles */
@media print {
  .sidebar,
  .mobile-menu-btn,
  .navbar {
    display: none !important;
  }
  
  .main-content {
    margin-left: 0 !important;
  }
  
  .content-section {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn-primary {
    border: 2px solid currentColor;
  }
  
  .card,
  .content-section {
    border: 2px solid currentColor;
  }
}

/* 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;
  }
}
