/* Mobile-First Responsive Styles for WeShare PWA */

/* Prevent text size adjustment on iOS */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Touch-friendly tap targets - minimum 44x44px */
@media (max-width: 768px) {
  
  /* Navigation and buttons */
  .btn, button, a.btn {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 20px;
    font-size: 16px; /* Prevent iOS zoom on input focus */
    touch-action: manipulation; /* Disable double-tap zoom */
  }
  
  /* Form inputs */
  input, textarea, select {
    min-height: 44px;
    font-size: 16px; /* Prevent iOS zoom */
    padding: 10px 15px;
  }
  
  /* Navigation links */
  .navbar .nav > li > a {
    min-height: 44px;
    padding: 12px 15px;
    line-height: 20px;
  }
  
  /* Hamburger menu icon (show on mobile) */
  .navbar .btn-navbar {
    display: block;
    min-height: 44px;
    min-width: 44px;
    padding: 12px 15px;
  }
  
  /* Container padding for mobile */
  .container {
    padding-left: 15px;
    padding-right: 15px;
  }
  
  /* Full width on mobile */
  .span8, .span4 {
    width: 100%;
    margin-left: 0;
  }
  
  /* Stack columns vertically */
  .row-fluid [class*="span"] {
    width: 100%;
    margin-left: 0;
    float: none;
  }
  
  /* Tables - make scrollable */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Larger touch targets for icons */
  i.icon-white, i[class^="icon-"] {
    font-size: 20px;
    padding: 2px;
  }
  
  /* File upload area */
  #drop-zone {
    min-height: 150px;
    padding: 30px 15px;
  }
  
  /* Cards and panels */
  .well, .alert {
    padding: 15px;
    margin-bottom: 15px;
  }
  
  /* Typography adjustments */
  h1 { font-size: 28px; }
  h2 { font-size: 24px; }
  h3 { font-size: 20px; }
  h4 { font-size: 18px; }
  
  p, li, td, th {
    font-size: 16px;
    line-height: 1.5;
  }
  
  /* Improve readability */
  body {
    font-size: 16px;
    line-height: 1.6;
  }
  
  /* Better spacing for touch */
  ul li, ol li {
    margin-bottom: 12px;
  }
  
  /* Modal adjustments */
  .modal {
    width: 95%;
    margin-left: -47.5%;
  }
  
  /* Image responsiveness */
  img {
    max-width: 100%;
    height: auto;
  }
}

/* Extra small devices (phones, less than 480px) */
@media (max-width: 480px) {
  
  /* Even larger touch targets for small screens */
  .btn, button, a.btn {
    display: block;
    width: 100%;
    margin-bottom: 10px;
  }
  
  /* Stack navbar brand and menu */
  .navbar .brand {
    font-size: 18px;
    padding: 12px 15px;
  }
  
  /* Full width inputs */
  input, textarea, select {
    width: 100%;
    box-sizing: border-box;
  }
  
  /* Reduce padding for very small screens */
  .container {
    padding-left: 10px;
    padding-right: 10px;
  }
  
  /* Smaller modals */
  .modal {
    width: 98%;
    margin-left: -49%;
  }
}

/* Landscape orientation optimizations */
@media (max-width: 768px) and (orientation: landscape) {
  
  /* Reduce vertical spacing in landscape */
  .navbar {
    min-height: 40px;
  }
  
  .navbar .nav > li > a {
    padding: 10px 12px;
  }
  
  h1, h2, h3 {
    margin-top: 10px;
    margin-bottom: 10px;
  }
}

/* PWA Install Banner (mobile-specific) */
#pwa-install-banner {
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translate(-50%, 100px);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

/* Touch feedback - add subtle highlight on tap */
@media (hover: none) {
  button:active, a:active, .btn:active {
    background-color: rgba(0, 0, 0, 0.1);
    transition: background-color 0.1s;
  }
}

/* Safe area for notched devices (iPhone X, etc.) */
@supports (padding-top: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  
  .navbar-fixed-top {
    padding-top: env(safe-area-inset-top);
  }
}

/* Improved scrolling on iOS */
.scroll-container {
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
}

/* Disable pull-to-refresh interference */
body {
  overscroll-behavior-y: contain;
}

/* Chart responsiveness for Bullish dashboard */
@media (max-width: 768px) {
  canvas {
    max-width: 100%;
    height: auto !important;
  }
  
  #chart-container {
    position: relative;
    height: 300px;
    width: 100%;
  }
}

/* File list improvements */
@media (max-width: 768px) {
  .file-item {
    padding: 15px;
    border-bottom: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  
  .file-item a {
    word-break: break-all;
    font-size: 16px;
  }
  
  .file-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
  }
  
  .file-actions .btn {
    flex: 1;
    min-width: 100px;
  }
}

/* Accessibility - focus indicators for keyboard/switch access */
a:focus, button:focus, input:focus, textarea:focus, select:focus {
  outline: 3px solid #0d6efd;
  outline-offset: 2px;
}

/* Dark mode support (if user prefers) */
@media (prefers-color-scheme: dark) {
  body {
    background-color: #1a1a1a;
    color: #e0e0e0;
  }
  
  .navbar-inverse {
    background-color: #0a0a0a;
  }
  
  .well, .alert {
    background-color: #2a2a2a;
    border-color: #3a3a3a;
  }
  
  input, textarea, select {
    background-color: #2a2a2a;
    color: #e0e0e0;
    border-color: #3a3a3a;
  }
}

/* Loading states - improve perceived performance */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #0d6efd;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Offline indicator */
body.offline::before {
  content: 'Offline Mode';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #ff9800;
  color: white;
  text-align: center;
  padding: 5px;
  font-size: 14px;
  z-index: 10000;
}
