/* Mobile-specific enhancements for Home Safe Caregiver PWA */

/* PWA-specific styles */
.pwa-mode {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.pwa-mode .navbar {
  padding-top: calc(env(safe-area-inset-top) + 0.5rem);
}

/* iOS Safari PWA background fix */
@media (display-mode: standalone) {
  html, body {
    background-color: #f8f9fa !important;
  }
  
  body {
    min-height: 100vh;
    background-color: #f8f9fa !important;
  }
}

/* iOS specific PWA fixes */
@supports (-webkit-appearance: none) {
  @media (display-mode: standalone) {
    html {
      background: #f8f9fa !important;
    }
    
    body {
      background: #f8f9fa !important;
      background-color: #f8f9fa !important;
    }
    
    .navbar-dark.bg-primary {
      background-color: #527a5b !important;
    }
  }
}

/* Offline indicator */
.offline-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #ffc107;
  color: #000;
  text-align: center;
  padding: 0.5rem;
  z-index: 9999;
  font-size: 0.875rem;
}

.offline .offline-indicator {
  display: block;
}

/* Enhanced touch targets */
.touch-target {
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}

/* Better button styling for mobile */
@media (max-width: 768px) {
  .btn {
    min-height: 44px;
    font-size: 1rem;
    padding: 0.75rem 1rem;
  }
  
  .btn-group .btn {
    min-width: 60px;
  }
  
  .room-selection .card {
    margin-bottom: 1rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
  }
  
  .room-selection .card:active {
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  }
  
  .screening-form .form-group {
    margin-bottom: 1.5rem;
  }
  
  .screening-form .form-control {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.75rem;
    border-radius: 8px;
  }
  
  .screening-form textarea.form-control {
    min-height: 120px;
  }
  
  .answer-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
    margin: 1rem 0;
  }
  
  .answer-btn {
    min-width: 80px;
    min-height: 44px;
    border-radius: 22px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    border: 2px solid transparent;
  }
  
  .answer-btn:active {
    transform: scale(0.95);
  }
  
  .answer-btn.btn-success {
    background: #28a745;
    border-color: #28a745;
  }
  
  .answer-btn.btn-danger {
    background: #dc3545;
    border-color: #dc3545;
  }
  
  .answer-btn.btn-secondary {
    background: #6c757d;
    border-color: #6c757d;
  }
  
  .answer-btn.btn-info {
    background: #0081cc;
    border-color: #0081cc;
  }
  
  .answer-btn.btn-warning {
    background: #ffc107;
    border-color: #ffc107;
    color: #000;
  }
  
  .answer-btn.selected {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    border-color: #fff;
  }
  
  /* Photo capture enhancements */
  .photo-capture {
    margin: 1rem 0;
  }
  
  .photo-preview {
    max-width: 100%;
    border-radius: 8px;
    margin: 0.5rem 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  }
  
  .photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
  }
  
  .photo-item {
    position: relative;
    background: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
  }
  
  .photo-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
  }
  
  .photo-item .photo-caption {
    padding: 0.5rem;
    font-size: 0.875rem;
    color: #6c757d;
    background: white;
  }
  
  .photo-item .delete-photo {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(220, 53, 69, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
  }
  
  /* Progress indicators */
  .progress-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: #e9ecef;
    z-index: 9998;
  }
  
  .progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #527a5b, #527a52);
    transition: width 0.3s ease;
  }
  
  /* Sticky action buttons */
  .sticky-actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #dee2e6;
    padding: 1rem;
    z-index: 1000;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
  }
  
  .sticky-actions .btn {
    width: 100%;
    margin: 0.25rem 0;
  }
  
  .sticky-actions.dual-action {
    display: flex;
    gap: 1rem;
  }
  
  .sticky-actions.dual-action .btn {
    flex: 1;
  }
  
  /* Gesture indicators */
  .gesture-hint {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
  }
  
  .gesture-hint.show {
    opacity: 1;
  }
  
  /* Improved form layouts */
  .screening-question {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 1rem;
    margin: 1rem 0;
    border: 1px solid #e9ecef;
  }
  
  .screening-question.concerning {
    border-color: #ffc107;
    background: #fff3cd;
  }
  
  .screening-question .question-text {
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: #333;
  }
  
  .screening-question .guidance-text {
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 0.75rem;
    line-height: 1.4;
  }
  
  .screening-question .notes-section {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e9ecef;
  }
  
  .notes-section textarea {
    background: white;
    border: 1px solid #ced4da;
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 0.9rem;
    resize: vertical;
    min-height: 80px;
  }
  
  .notes-section textarea:focus {
    border-color: #527a5b;
    box-shadow: 0 0 0 0.2rem rgba(82, 122, 91, 0.25);
  }
  
  /* Room navigation */
  .room-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: white;
    border-bottom: 1px solid #e9ecef;
    position: sticky;
    top: 0;
    z-index: 100;
  }
  
  .room-nav .room-title {
    font-weight: 600;
    color: #333;
    margin: 0;
  }
  
  .room-nav .room-progress {
    font-size: 0.875rem;
    color: #6c757d;
  }
  
  /* Loading states */
  .loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
  }
  
  .loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #527a5b;
    border-radius: 50%;
    animation: spin 1s linear infinite;
  }
  
  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }
  
  /* Fix "What to look for" button to match other button animations and size */
  .btn-outline-info:hover {
    background-color: var(--info-color) !important;
    border-color: var(--info-color) !important;
    color: white !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,129,204,0.3);
  }
  
  .btn-outline-info:active,
  .btn-outline-info.active {
    color: white !important;
  }

  /* Make "What to look for" button same height as answer buttons */
  .btn-sm.btn-outline-info[data-bs-toggle="collapse"] {
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    min-height: 38px;
  }

  /* Fix answer buttons to behave consistently - override btn-outline-info for answer buttons */
  /* Use maximum specificity to override style.min.css */
  .question-item .answer-options .btn-group .btn-outline-info:hover,
  .question-item .answer-options .btn-group .btn-outline-success:hover,
  .question-item .answer-options .btn-group .btn-outline-danger:hover,
  .question-item .answer-options .btn-group .btn-outline-secondary:hover,
  .question-item .answer-options .btn-group .btn-outline-warning:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
    color: white !important;
  }

  /* Info button (help available) specific hover styling */
  .question-item .answer-options .btn-group .btn-outline-info:hover {
    background-color: var(--info-color) !important;
    border-color: var(--info-color) !important;
  }

  .question-item .answer-options .btn-group .btn-outline-info:active,
  .question-item .answer-options .btn-group .btn-outline-success:active,
  .question-item .answer-options .btn-group .btn-outline-danger:active,
  .question-item .answer-options .btn-group .btn-outline-secondary:active,
  .question-item .answer-options .btn-group .btn-outline-warning:active {
    transform: scale(0.95) !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1) !important;
  }

  /* Ensure success buttons use correct colors */
  .question-item .answer-options .btn-group .btn-outline-success:hover {
    background-color: var(--success-color) !important;
    border-color: var(--success-color) !important;
  }

  /* Ensure danger buttons use correct colors */  
  .question-item .answer-options .btn-group .btn-outline-danger:hover {
    background-color: var(--danger-color) !important;
    border-color: var(--danger-color) !important;
  }

  /* Ensure secondary buttons use correct colors */
  .question-item .answer-options .btn-group .btn-outline-secondary:hover {
    background-color: var(--muted-color) !important;
    border-color: var(--muted-color) !important;
  }

  /* Ensure warning buttons use correct colors */
  .question-item .answer-options .btn-group .btn-outline-warning:hover {
    background-color: var(--warning-color) !important;
    border-color: var(--warning-color) !important;
    color: #000 !important;
  }

  /* Reduce "Back to Screening" button vertical size by 30% from bottom */
  .row .col-12 .d-flex.justify-content-between .btn.btn-outline-secondary.me-2,
  .d-flex.justify-content-between.align-items-center .btn.btn-outline-secondary.me-2,
  a.btn.btn-outline-secondary.me-2[href*="screening_detail"] {
    padding-top: 0.375rem !important;
    padding-bottom: 0.2625rem !important; /* 30% reduction from standard 0.375rem */
    min-height: auto !important;
  }

  /* Safe areas for notched devices */
  @supports (padding: max(0px)) {
    .safe-area-top {
      padding-top: max(1rem, env(safe-area-inset-top));
    }
    
    .safe-area-bottom {
      padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
  }
}

