/* Mobile Optimization for Trading System
   This file contains responsive styles for mobile devices
   to complement the existing CSS files:
   - trades.css
   - pets.css
   - mutationsSelection.css
   - activeAd.css
   - extras.css
*/

/* Apply these styles for screens smaller than 768px */
@media (max-width: 768px) {
    /* General Layout Adjustments */
    body {
      font-size: 14px;
    }
  
    .container {
      padding: 0 0.75rem;
      margin: 1rem auto;
    }
  
    /* Header Section */
    .header-section {
      margin-top: 70px;
      flex-direction: column;
      align-items: stretch;
    }
  
    .create-trade-btn {
      width: 100%;
      justify-content: center;
      margin-bottom: 1rem;
    }
  
    .trade-filters {
      flex-direction: column;
      width: 100%;
    }
  
    .filter-select, 
    .trade-search {
      width: 100%;
      min-width: unset;
    }
  
    /* Modal Adjustments */
    .modal {
      width: 95%;
      padding: 1rem;
      max-height: 85vh;
    }
  
    .modal-header {
      padding-bottom: 0.75rem;
      margin-bottom: 1rem;
    }
  
    .modal-header h2 {
      font-size: 1.25rem;
    }
  
    /* Step Indicators */
    .step-indicators::before {
      top: 15px;
      height: 1px;
    }
  
    .step-indicator {
      flex-direction: column;
    }
  
    .step-number {
      width: 24px;
      height: 24px;
      font-size: 0.8rem;
    }
  
    .step-text {
      font-size: 0.7rem;
      margin-top: 0.25rem;
    }
  
    /* Items Grid */
    .items-grid {
      grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
      gap: 0.8rem;
      max-height: 350px;
      padding: 0.75rem;
    }
  
    .item-box {
      min-height: 90px;
      padding: 0.5rem;
    }
  
    .item-box .item-image-container {
      height: 50px;
    }
  
    .item-box .item-name {
      font-size: 0.8rem;
    }
  
    /* Selected Items Display */
    .selected-items-display {
      flex-direction: column;
      gap: 1rem;
    }
  
    .offering-preview, 
    .wanting-preview {
      width: 100%;
    }
  
    .selected-items-grid {
      grid-template-columns: repeat(3, 1fr);
      gap: 0.6rem;
    }
  
    .selected-item {
      min-height: 80px;
      padding: 6px;
    }
  
    .selected-item img {
      height: 50px;
      margin-top: 10px;
      margin-bottom: 2px;
    }
  
    .selected-item .item-name {
      font-size: 0.7rem;
    }
  
    .remove-item-btn {
      width: 18px;
      height: 18px;
      font-size: 12px;
    }
  
    /* Trade Actions */
    .trade-actions {
      flex-direction: column;
      gap: 0.8rem;
    }
  
    .edit-trade-btn,
    .create-trade-submit {
      width: 100%;
      padding: 0.8rem;
    }
  
    /* Message Modal */
    .message-content {
      width: 95%;
      padding: 1rem;
    }
  
    /* Item Info Modal */
    .info-modal-content {
      padding: 1rem;
    }
  
    .modal-grid {
      grid-template-columns: 1fr;
    }
  
    .modal-left {
      border-right: none;
      border-bottom: 1px solid rgba(255, 255, 255, 0.1);
      padding-right: 0;
      padding-bottom: 1rem;
      margin-bottom: 1rem;
    }
  
    .info-image-container {
      width: 150px;
      height: 150px;
    }
  
    .info-title h3 {
      font-size: 1.5rem;
    }
  
    .value-history {
      min-height: 300px;
    }
  
    /* Message Dialog */
    .message-dialog-content {
      width: 95%;
      max-height: 90vh;
    }
  
    .message-dialog-header {
      padding: 15px;
    }
  
    .recipient-avatar {
      width: 40px;
      height: 40px;
    }
  
    .recipient-details h3 {
      font-size: 16px;
    }
  
    .message-dialog-body {
      padding: 15px;
    }
  
    .message-templates {
      flex-wrap: wrap;
    }
  
    .template-btn {
      font-size: 12px;
      padding: 6px 12px;
    }
  
    #messageContent {
      min-height: 100px;
    }
  
    .message-dialog-footer {
      padding: 15px;
    }
  
    .send-controls {
      flex-direction: column;
      gap: 10px;
    }
  
    .cancel-btn,
    .send-message-btn {
      width: 100%;
      padding: 10px;
    }
  
    /* Trade Preview in Message Dialog */
    .preview-items {
      grid-template-columns: repeat(3, 1fr);
    }
  
    .trade-preview-grid .trade-item .item-name {
      font-size: 0.6rem;
    }
  
    /* Item Tooltips */
    .item-tooltip {
      left: 50%;
      top: -100%;
      transform: translateX(-50%);
      margin-left: 0;
      margin-top: -10px;
      min-width: 180px;
    }
    
    .item-tooltip::after {
      top: auto;
      bottom: -6px;
      left: 50%;
      transform: translateX(-50%) rotate(45deg);
      border: none;
      border-right: 1px solid rgba(255, 255, 255, 0.1);
      border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
  
    /* Pet Selection Modal */
    .pet-selection-modal .modal-content {
      width: 95%;
      max-height: 85vh;
    }
  
    .pet-types-grid {
      grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
      gap: 10px;
    }
  
    .pet-type-box {
      padding: 8px;
    }
  
    .pet-image-container {
      height: 60px;
    }
  
    .pet-name {
      font-size: 12px;
    }
  
    .pet-preview img {
      width: 100px;
      height: 100px;
    }
  
    .customization-group {
      padding: 12px;
    }
  
    .age-slider-container,
    .weight-control-row {
      flex-direction: column;
      gap: 8px;
      align-items: stretch;
    }
  
    .age-text-input,
    .weight-text-input {
      width: 100%;
    }
  
    /* Mutations Selection */
    .item-customization-popup {
      padding: 0.5rem;
    }
  
    .popup-content {
      width: 95%;
      max-width: 100%;
    }
  
    .popup-header {
      padding: 0.75rem 1rem;
    }
  
    .popup-body {
      padding: 1rem;
      gap: 1rem;
    }
  
    .item-preview {
      flex-direction: column;
      align-items: center;
      padding: 1rem;
      gap: 0.75rem;
    }
  
    .item-image-container {
      width: 80px;
      height: 80px;
    }
  
    .item-stats {
      grid-template-columns: 1fr 1fr;
    }
  
    .mutations-checkbox-group {
      grid-template-columns: 1fr;
      gap: 8px;
      padding: 12px;
    }
  
    .mutation-checkbox {
      padding: 8px 10px;
    }
  
    .mutation-checkbox label {
      font-size: 0.85rem;
      padding-left: 28px;
    }
  
    .weight-input-container {
      margin-top: 6px;
    }
  
    .weight-control-row {
      flex-direction: column;
      gap: 10px;
    }
  
    .weight-text-input {
      width: 100%;
    }
  
    /* Active Trade Cards */
    .trade-card {
      padding: 0.75rem;
    }
  
    .trader-info {
      grid-template-columns: auto 1fr;
      grid-template-areas: 
        "avatar name"
        "avatar timer"
        "message message";
      gap: 0.5rem;
      padding-bottom: 0.75rem;
      margin-bottom: 0.75rem;
    }
  
    .trader-avatar {
      width: 40px;
      height: 40px;
    }
  
    .trader-name {
      font-size: 1rem;
    }
  
    .message-trader-btn {
      margin-top: 0.5rem;
      width: 100%;
      justify-content: center;
      padding: 0.5rem;
      font-size: 0.85rem;
    }
  
    .trade-items {
      grid-template-columns: 1fr;
      gap: 0.75rem;
    }
  
    .offering-items,
    .wanting-items {
      padding: 0.75rem;
    }
  
    .items-display {
      grid-template-columns: repeat(3, 1fr);
      gap: 0.5rem;
      padding: 0.25rem;
    }
  
    .trade-item {
      padding: 0.5rem;
      border-radius: 12px;
    }
  
    .item-image-container {
      height: 60px;
      margin-bottom: 0.25rem;
    }
  
    /* Tag Selection Modal */
    .tag-selection-modal .modal-content {
      width: 95%;
      max-height: 85vh;
    }
  
    .tags-grid {
      grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
      gap: 0.75rem;
      padding: 0.75rem;
    }
  
    .tag-box {
      padding: 0.75rem;
    }
  
    .tag-image {
      width: 50px;
      height: 50px;
    }
  
    .tag-name {
      font-size: 0.8rem;
    }
  
    .selected-tags {
      grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
      gap: 0.6rem;
    }
  
    .selected-tag .tag-icon {
      width: 50px;
      height: 50px;
    }
  
    .selected-tag .tag-text {
      font-size: 0.7rem;
    }
  
    .add-tag-btn,
    .add-pet-btn {
      padding: 5px 10px;
      font-size: 12px;
    }
    
    /* Pagination adjustments */
    .pagination-controls {
      flex-wrap: wrap;
      justify-content: center;
    }
    
    .page-link {
      min-width: 32px;
      height: 32px;
      font-size: 0.9rem;
    }
    
    .pagination-info {
      text-align: center;
      width: 100%;
      margin-top: 0.5rem;
    }
    
    /* Mutation indicators and tags */
    .mutation-indicator {
      top: 5px;
      right: 5px;
      min-width: 18px;
      height: 18px;
      font-size: 0.65rem;
    }
    
    .mutation-tag {
      padding: 1px 4px;
      font-size: 0.65rem;
    }
    
    .item-mutations {
      gap: 2px;
    }
  }
  
  /* Apply these styles for very small screens (less than 480px) */
  @media (max-width: 480px) {
    /* Further reduce sizes for very small screens */
    .items-grid {
      grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
      gap: 0.6rem;
    }
  
    .selected-items-grid {
      grid-template-columns: repeat(2, 1fr);
    }
  
    .items-display {
      grid-template-columns: repeat(2, 1fr);
    }
  
    .preview-items {
      grid-template-columns: repeat(2, 1fr);
    }
  
    .pet-types-grid,
    .tags-grid {
      grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }
  
    /* Adjust modal headers */
    .modal-header h2,
    .popup-header h3,
    .tag-selection-modal .modal-header h3 {
      font-size: 1.1rem;
    }
  
    /* Simplify item tooltips */
    .item-tooltip {
      width: 160px;
      padding: 8px;
    }
    
    .tooltip-title {
      font-size: 0.8rem;
      margin-bottom: 6px;
    }
    
    .tooltip-stats .stat-row {
      padding: 4px;
    }
    
    .tooltip-stats .stat-label,
    .tooltip-stats .stat-value {
      font-size: 0.75rem;
    }
  
    /* Hide some elements to save space */
    .trade-preview-grid .item-value {
      display: none;
    }
  
    /* Adjust buttons for better touch targets */
    button, 
    .create-trade-btn,
    .confirm-step,
    .edit-trade-btn,
    .create-trade-submit,
    .message-close,
    .cancel-btn,
    .send-message-btn,
    .add-tag-btn,
    .add-pet-btn {
      min-height: 44px; /* Minimum touch target size */
    }
    
    /* Further simplify trade items */
    .trade-item {
      border-radius: 8px;
    }
    
    .item-image-container {
      height: 50px;
    }
    
    /* Reduce padding to fit more content */
    .modal-header,
    .popup-header,
    .message-dialog-header,
    .tag-selection-modal .modal-header {
      padding: 10px;
    }
    
    .popup-body,
    .message-dialog-body {
      padding: 10px;
    }
    
  /* Simplify step indicators */
  .step-indicators {
    margin-bottom: 1rem;
  }
  
  .step-number {
    width: 20px;
    height: 20px;
    font-size: 0.7rem;
  }
  
  .step-text {
    font-size: 0.65rem;
  }
  
  /* Compact item info modal */
  .info-image-container {
    width: 120px;
    height: 120px;
  }
  
  .info-title h3 {
    font-size: 1.3rem;
  }
  
  .info-subtitle {
    font-size: 1rem;
  }
  
  .info-stats {
    padding: 15px;
  }
  
  .stat-row {
    padding: 8px 0;
  }
  
  .value-history {
    min-height: 250px;
    padding: 15px;
  }
  
  .history-filters button {
    padding: 4px 8px;
    font-size: 0.8rem;
  }
  
  /* Compact message dialog */
  .recipient-avatar {
    width: 36px;
    height: 36px;
  }
  
  .recipient-details h3 {
    font-size: 14px;
  }
  
  .recipient-status {
    font-size: 12px;
  }
  
  .template-btn {
    padding: 5px 10px;
    font-size: 11px;
  }
  
  /* Adjust trade preview in message dialog */
  .trade-preview-grid .trade-item {
    padding: 4px;
  }
  
  .trade-preview-grid .trade-item img {
    height: 50%;
  }
  
  .trade-preview-grid .trade-item .item-name {
    font-size: 0.55rem;
  }
  
  .trade-preview-grid .trade-item .item-weight {
    font-size: 0.55rem;
  }
}

/* Apply these styles for extra small screens (less than 360px) */
@media (max-width: 360px) {
  /* Extremely compact layout for very small devices */
  .items-grid {
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 0.5rem;
  }
  
  .selected-items-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }
  
  .items-display {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
  }
  
  .item-box {
    min-height: 80px;
    padding: 0.4rem;
  }
  
  .item-box .item-image-container {
    height: 40px;
  }
  
  .item-box .item-name {
    font-size: 0.7rem;
  }
  
  .selected-item {
    min-height: 70px;
  }
  
  .selected-item img {
    height: 40px;
  }
  
  .selected-item .item-name {
    font-size: 0.65rem;
  }
  
  /* Hide more elements to save space */
  .step-text {
    display: none;
  }
  
  .item-value-display {
    display: none;
  }
  
  /* Simplify modals further */
  .modal-header h2,
  .popup-header h3,
  .tag-selection-modal .modal-header h3 {
    font-size: 1rem;
  }
  
  .close-modal,
  .close-popup,
  .close-mutation-modal {
    font-size: 1.2rem;
  }
  
  /* Adjust pet and tag selection */
  .pet-types-grid,
  .tags-grid {
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  }
  
  .pet-image-container,
  .tag-image {
    height: 50px;
    width: 50px;
  }
}

/* Fix for iOS Safari 100vh issue */
@supports (-webkit-touch-callout: none) {
  .modal-overlay,
  .message-modal,
  .item-info-modal,
  .message-dialog,
  .pet-selection-modal,
  .item-customization-popup,
  .tag-selection-modal,
  .mutation-selection-modal {
    height: -webkit-fill-available;
  }
}

/* Improve touch targets for interactive elements */
.item-box,
.selected-item,
.trade-item,
.pet-type-box,
.tag-box,
.mutation-checkbox,
.page-link,
.template-btn {
  min-height: 44px; /* Minimum recommended touch target size */
}

/* Fix for fixed position elements when keyboard is open on mobile */
@media (max-height: 500px) {
  .modal-overlay,
  .message-modal,
  .item-info-modal,
  .message-dialog,
  .pet-selection-modal,
  .item-customization-popup,
  .tag-selection-modal,
  .mutation-selection-modal {
    position: absolute;
  }
}

/* Prevent text size adjustment on orientation change */
html {
  -webkit-text-size-adjust: 100%;
}

/* Add smooth scrolling for better mobile experience */
.items-grid,
.popup-body,
.modal,
.pet-selection-steps,
.info-modal-content,
.message-dialog-content,
.tag-selection-modal .modal-content {
  -webkit-overflow-scrolling: touch;
}

/* Improve form elements for mobile */
input, 
select, 
textarea {
  font-size: 16px; /* Prevents iOS zoom on focus */
  max-width: 100%;
}

/* Prevent content overflow */
img {
  max-width: 100%;
}

/* Improve scrolling performance */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Fix for sticky hover states on mobile */
@media (hover: none) {
  .item-box:hover,
  .trade-item:hover,
  .selected-item:hover,
  .pet-type-box:hover,
  .tag-box:hover,
  .mutation-checkbox:hover,
  .create-trade-btn:hover,
  .edit-trade-btn:hover,
  .create-trade-submit:hover,
  .confirm-step:hover,
  .message-close:hover,
  .page-btn:hover,
  .message-trader-btn:hover,
  .add-tag-btn:hover,
  .add-pet-btn:hover,
  .template-btn:hover,
  .cancel-btn:hover,
  .send-message-btn:hover,
  .mutation-option:hover {
    transform: none;
    box-shadow: none;
  }
  
  /* Disable hover effects that show hidden elements */
  .item-box:hover .item-value-display,
  .item-box:hover .item-info-btn,
  .trade-item:hover .item-tooltip,
  .trade-item:hover .item-hover-card {
    opacity: 0;
    visibility: hidden;
  }
  
  /* Use active state instead for mobile */
  .item-box:active,
  .trade-item:active,
  .selected-item:active,
  .pet-type-box:active,
  .tag-box:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
}

/* Improve modal scrolling on iOS */
.modal,
.popup-body,
.info-modal-content,
.message-dialog-content,
.pet-selection-steps,
.tag-selection-modal .modal-content {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: 85vh;
}

/* Fix for position:fixed elements when keyboard is open */
@media (max-height: 450px) {
  .modal-overlay,
  .message-modal,
  .item-info-modal,
  .message-dialog,
  .pet-selection-modal,
  .item-customization-popup,
  .tag-selection-modal,
  .mutation-selection-modal {
    position: absolute;
    height: 100%;
  }
}

/* Optimize for landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .modal,
  .info-modal-content,
  .message-dialog-content,
  .pet-selection-modal .modal-content,
  .tag-selection-modal .modal-content,
  .popup-content {
    max-height: 80vh;
  }
  
  .items-grid {
    max-height: 200px;
  }
  
  .modal-grid {
    grid-template-columns: 250px 1fr;
  }
  
  .modal-left {
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: none;
    padding-right: 1rem;
    padding-bottom: 0;
    margin-bottom: 0;
  }
  
  .pet-types-grid,
  .tags-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
  
  .trade-items {
    grid-template-columns: 1fr 1fr;
  }
  
  .items-display {
    grid-template-columns: repeat(4, 1fr);
  }
  
  /* Adjust pet customization for landscape */
  .pet-customization {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
  }
  
  /* Adjust message dialog for landscape */
  .message-dialog-body {
    max-height: 50vh;
  }
  
  .trade-preview-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Optimize loading states for mobile */
#loadingOverlay.active {
  z-index: 2000; /* Ensure it's above all other elements */
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border-width: 4px;
}

/* Improve mobile accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Ensure buttons have proper spacing for touch */
button {
  margin: 0;
  padding: 8px 16px;
}

/* Fix for iOS input styling */
input[type="text"],
input[type="search"],
input[type="number"],
select,
textarea {
  -webkit-appearance: none;
  border-radius: 4px;
}

/* Improve focus states for accessibility */
button:focus,
input:focus,
select:focus,
textarea:focus,
.item-box:focus,
.selected-item:focus,
.trade-item:focus,
.pet-type-box:focus,
.tag-box:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* Improve focus states for accessibility */
button:focus,
input:focus,
select:focus,
textarea:focus,
.item-box:focus,
.selected-item:focus,
.trade-item:focus,
.pet-type-box:focus,
.tag-box:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* Ensure proper z-index stacking for modals */
.modal-overlay {
  z-index: 1000;
}

.message-modal {
  z-index: 1200;
}

.item-info-modal {
  z-index: 1000;
}

.message-dialog {
  z-index: 1200;
}

.pet-selection-modal {
  z-index: 1100;
}

.item-customization-popup {
  z-index: 1000;
}

.tag-selection-modal {
  z-index: 1000;
}

.mutation-selection-modal {
  z-index: 1100;
}

#loadingOverlay {
  z-index: 2000;
}

/* Fix for iOS button styling */
button {
  -webkit-appearance: none;
}

/* Improve tap highlight for interactive elements */
.item-box,
.selected-item,
.trade-item,
.pet-type-box,
.tag-box,
.mutation-checkbox,
.page-link,
.template-btn,
button {
  -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
}

/* Ensure proper spacing for form elements */
.filter-select, 
.trade-search,
.search-bar input,
.weight-text-input,
.age-text-input,
#messageContent {
  margin-bottom: 10px;
}

/* Fix for iOS Safari border radius issues */
.item-box,
.selected-item,
.trade-item,
.pet-type-box,
.tag-box,
.modal,
.message-content,
.info-modal-content,
.message-dialog-content,
.pet-selection-modal .modal-content,
.tag-selection-modal .modal-content,
.popup-content {
  -webkit-mask-image: -webkit-radial-gradient(white, black);
}

/* Ensure proper spacing for message dialog */
.message-dialog-content {
  margin: 10px;
}

/* Fix for iOS Safari scrolling issues */
.items-grid,
.popup-body,
.modal,
.pet-selection-steps,
.info-modal-content,
.message-dialog-content,
.tag-selection-modal .modal-content {
  -webkit-transform: translateZ(0);
}

/* Ensure proper spacing for buttons in modals */
.popup-footer,
.modal-footer,
.message-dialog-footer {
  padding-bottom: env(safe-area-inset-bottom, 10px);
}

/* Add safe area insets for notched devices */
.modal-overlay,
.message-modal,
.item-info-modal,
.message-dialog,
.pet-selection-modal,
.item-customization-popup,
.tag-selection-modal,
.mutation-selection-modal {
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

/* Ensure proper spacing for container */
.container {
  padding-left: max(env(safe-area-inset-left, 0), 0.75rem);
  padding-right: max(env(safe-area-inset-right, 0), 0.75rem);
}

/* Fix for iOS Safari bottom bar */
body {
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Ensure proper spacing for fixed elements */
.header-section {
  padding-top: env(safe-area-inset-top, 0);
}

/* Fix for iOS Safari input zoom */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  select,
  textarea,
  input[type="text"],
  input[type="search"],
  input[type="number"] {
    font-size: 16px;
  }
}
