/* ============================================
   🎨 PharmaWeb Responsive Enhancements v1.0
   ✨ Additional responsive improvements for all pages
   📱 Mobile-First | Touch Optimized | Accessibility Ready
   ============================================ */

/* === Critical Resets === */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

/* === Container Improvements === */
.container,
.container-fluid {
  width: 100%;
  max-width: 100vw;
}

@media (max-width: 576px) {
  .container,
  .container-fluid {
    padding-left: 10px;
    padding-right: 10px;
  }
}

/* === Touch Friendly Elements === */
@media (hover: none) and (pointer: coarse) {
  /* Minimum touch target size - only for specific elements */
  .btn,
  input[type="submit"],
  input[type="button"] {
    min-height: 44px;
  }
  
  /* Better touch feedback */
  .btn:active {
    opacity: 0.9;
    transform: scale(0.98);
  }
  
  /* Disable sticky hover states on touch */
  a:hover,
  button:hover {
    transition-duration: 0s;
  }
}

/* === Tap Highlight & Selection === */
a, button, [role="button"], input[type="submit"] {
  -webkit-tap-highlight-color: rgba(0, 140, 105, 0.12);
}

/* === Momentum Scrolling === */
.container, .container-fluid {
  -webkit-overflow-scrolling: touch;
}

/* === Prevent text overflow breaking mobile layouts === */
@media (max-width: 576px) {
  h1, h2, h3, h4, h5, h6, p, span, a, li, td, th, label, div {
    overflow-wrap: break-word;
    word-wrap: break-word;
  }
}

/* === Safe Area Support for iPhone X+ === */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .navbar,
  .site-header {
    padding-top: env(safe-area-inset-top);
  }
  
  footer,
  .site-footer {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }
  
  /* Fixed bottom elements */
  .fixed-bottom,
  .sticky-bottom {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* === Improved Form Elements === */
input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]), 
textarea, 
select {
  font-size: 16px !important; /* Prevents iOS zoom on focus */
}

input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(0, 140, 105, 0.5);
  outline-offset: 2px;
}

/* === Better Scrolling === */
.scroll-container {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Hide scrollbar but keep functionality */
.hide-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.hide-scrollbar::-webkit-scrollbar {
  display: none;
}

/* === Image Improvements === */
img {
  max-width: 100%;
  height: auto;
}

/* Lazy loading placeholder */
img[data-src],
img[loading="lazy"] {
  background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: img-shimmer 1.5s infinite;
}

@keyframes img-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* === Responsive Typography === */
html {
  font-size: 16px;
}

@media (max-width: 768px) {
  html {
    font-size: 15px;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 14px;
  }
}

h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.5rem, 3.5vw, 2rem); }
h3 { font-size: clamp(1.25rem, 3vw, 1.5rem); }
h4 { font-size: clamp(1.1rem, 2.5vw, 1.25rem); }

/* === RTL/LTR Improvements === */
[dir="rtl"] {
  text-align: right;
}

[dir="rtl"] .me-2 { margin-left: 0.5rem !important; margin-right: 0 !important; }
[dir="rtl"] .ms-2 { margin-right: 0.5rem !important; margin-left: 0 !important; }
[dir="rtl"] .me-3 { margin-left: 1rem !important; margin-right: 0 !important; }
[dir="rtl"] .ms-3 { margin-right: 1rem !important; margin-left: 0 !important; }

/* === Loading States === */
.loading {
  position: relative;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 3px solid rgba(0, 140, 105, 0.2);
  border-top-color: #008c69;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* === Better Buttons === */
.btn {
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease;
}

.btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.3s, height 0.3s;
}

.btn:active::after {
  width: 200%;
  height: 200%;
}

/* === Focus States for Accessibility === */
*:focus-visible {
  outline: 3px solid rgba(0, 140, 105, 0.5);
  outline-offset: 2px;
}

/* Remove outline for mouse users */
*:focus:not(:focus-visible) {
  outline: none;
}

/* === Card Improvements === */
.card {
  border-radius: 16px;
  border: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

@media (max-width: 576px) {
  .card {
    border-radius: 12px;
  }
}

/* === Table Responsiveness === */
.table-responsive {
  -webkit-overflow-scrolling: touch;
}

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

/* === Modal Improvements === */
.modal-dialog {
  margin: 0.5rem;
}

@media (min-width: 576px) {
  .modal-dialog {
    margin: 1.75rem auto;
  }
}

/* === Alert Improvements === */
.alert {
  border: none;
  border-radius: 12px;
  padding: 1rem 1.25rem;
}

/* === Dropdown Improvements === */
.dropdown-menu {
  border: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  padding: 0.5rem;
  background: hsl(35, 25%, 92%);
  z-index: 1050;
}

.dropdown-item {
  border-radius: 8px;
  padding: 0.5rem 1rem;
  color: #333;
}

.dropdown-item:hover {
  background: hsla(160, 100%, 27%, 0.12);
  color: #008c69;
}

/* === Navbar Mobile Improvements === */
/* Note: navbar-collapse styles are defined in base.html to avoid conflicts */

/* === Print Styles === */
@media print {
  .navbar,
  .site-header,
  footer,
  .site-footer,
  .chat-widget,
  .toast-container,
  .modal {
    display: none !important;
  }
  
  * {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
  }
}

/* === High Contrast Mode === */
@media (prefers-contrast: high) {
  * {
    border-color: currentColor !important;
  }
  
  .btn {
    border: 2px solid currentColor;
  }
}

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

/* === Dark Mode Support (if implemented) === */
@media (prefers-color-scheme: dark) {
  /* Uncomment if dark mode is implemented */
  /*
  :root {
    --bg-color: #1a1a2e;
    --text-color: #ffffff;
    --card-bg: #16213e;
  }
  */
}

/* === Mobile Bottom Nav Spacing === */
/* Handled by .pharma-mobile-nav in pharma-components.css */
/* body { padding-bottom: calc(68px + env(safe-area-inset-bottom)) } */

/* === Long Text Overflow Protection === */
.text-break-all {
  word-break: break-all;
}

.crypto-address,
[data-address],
.wallet-address {
  word-break: break-all;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
}

/* === Scroll Offset for Sticky Navbar === */
html {
  scroll-padding-top: 80px;
}

@media (max-width: 991px) {
  /* On mobile, navbar hides on scroll, so reduce scroll padding */
  html {
    scroll-padding-top: 16px;
  }
}

/* === Order Detail Responsive Fixes === */
@media (max-width: 576px) {
  .order-detail-header {
    padding: 1.25rem !important;
    border-radius: 14px !important;
  }
  
  .status-badge-large {
    padding: 8px 16px !important;
    font-size: 0.85rem !important;
  }
}

/* === Payment Page Responsive === */
@media (max-width: 576px) {
  .wallet-panel {
    padding: 1rem !important;
  }
  
  .wallet-panel img[alt*="QR"],
  .wallet-panel canvas {
    max-width: 180px;
    height: auto;
  }
}

/* === Profile Page Quick Amount Buttons === */
.q-btn {
  min-width: 56px;
  min-height: 44px;
}

@media (max-width: 400px) {
  .q-btn {
    min-width: 48px;
    font-size: 0.85rem;
  }
}
