/* Phone-specific styles for guest.html - Only applies to phones ≤480px */
/* Tablets and desktop designs remain completely untouched */

/* Ensure tablets (481px - 768px) use desktop styles */
@media only screen and (min-width: 481px) and (max-width: 768px) {
  /* Tablets use desktop layout - no mobile overrides */
  .status-overlay {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    left: auto !important;
    transform: none !important;
    width: auto !important;
    min-width: 320px !important;
    max-width: 380px !important;
  }
  
  .scanner-overlay {
    display: block !important;
  }
  
  .barn-switcher {
    position: fixed !important;
    top: 90px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    right: auto !important;
    padding: 10px 20px !important;
    flex-direction: row !important;
  }
  
  .barn-switcher-label {
    display: block !important;
  }
  
  .mobile-scanner-btn {
    display: none !important;
  }
}

@media only screen and (max-width: 480px) {
  /* =================== MOBILE FAB BUTTONS =================== */
  .mobile-fab-button {
    position: fixed;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    font-size: 18px;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    color: white;
  }

  #mobile-fab-checkout {
    bottom: 120px;
    background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
    box-shadow: 0 6px 20px rgba(220,53,69,0.3);
  }

  #mobile-fab-checkin {
    bottom: 50px;
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    box-shadow: 0 6px 20px rgba(16,185,129,0.3);
  }

  #mobile-fab-passport {
    bottom: 190px;
    background: #1E3676;
    box-shadow: 0 6px 20px rgba(30,54,118,0.3);
  }

  .mobile-fab-button i {
    color: white !important;
  }

  /* =================== MOBILE BUTTON IMPROVEMENTS =================== */

  /* Fix modal button styling - be specific to avoid affecting other buttons */
  .modal-actions button {
    border-radius: 12px !important;
    border: none !important;
    padding: 12px 24px !important;
    font-weight: 600 !important;
    transition: none !important;
    transform: none !important;
  }

  /* Restore borders for scanner buttons */
  .scan-btn,
  .omnimax-btn,
  .mobile-scanner-btn {
    border: 2px solid #203775 !important;
    border-radius: 8px !important;
    background: white !important;
    color: #203775 !important;
  }

  .scan-btn:disabled,
  .omnimax-btn:disabled,
  .mobile-scanner-btn:disabled {
    border: 2px solid #ccc !important;
    background: #f8f9fa !important;
    color: #6c757d !important;
    opacity: 0.6 !important;
  }

  .modal-actions button.primary,
  .modal-content button.primary {
    background: linear-gradient(135deg, #203775 0%, #2E4A8B 100%) !important;
    color: white !important;
  }

  .modal-actions button.cancel,
  .modal-content button.cancel {
    background: #f8f9fa !important;
    color: #6c757d !important;
    border: 1px solid #dee2e6 !important;
  }

  /* Fix modal actions spacing */
  .modal-actions {
    margin-top: auto !important;
    padding: 20px !important;
    background: white !important;
    border-top: 1px solid #E5E7EB !important;
    display: flex !important;
    gap: 10px !important;
    justify-content: space-between !important;
    flex-shrink: 0 !important;
  }

  /* Fix modal content to prevent white space */
  #checkin-modal .modal-content > * {
    flex-shrink: 0;
  }

  #checkin-modal .tab-content {
    flex-grow: 1 !important;
    overflow-y: auto !important;
    padding: 20px !important;
  }

  /* Better mobile keyboard support for Transport tab */
  #transport-tab .transport-scrollable {
    padding-bottom: 120px !important; /* Only enough space for keyboard */
  }

  /* Add space after final destination only */
  #transport-tab .form-group:last-child {
    margin-bottom: 80px !important;
  }

  /* Hide the bottom checkout button on mobile since we have FABs */
  .choice-button.checkout-bottom {
    display: none !important;
  }

  /* =================== LANDING PAGE MOBILE =================== */
  .landing-content {
    padding: 20px;
    padding-bottom: 140px; /* More space for bottom checkout button */
  }

  .welcome-title {
    font-size: 32px !important;
    margin-bottom: 15px !important;
  }

  .welcome-subtitle {
    font-size: 18px !important;
    margin-bottom: 30px !important;
  }

  .choice-buttons {
    flex-direction: column;
    width: 100%;
    max-width: 320px;
    gap: 15px;
  }

  .choice-button {
    width: 100%;
    min-width: unset !important;
    padding: 18px 30px !important;
    font-size: 17px !important;
  }

  .choice-button.checkout-bottom {
    min-width: 200px !important;
    width: calc(100% - 40px);
    max-width: 320px;
    left: 20px;
    right: 20px;
    transform: none;
    bottom: 30px; /* Moved up a bit */
    animation: none !important;
    transition: none !important;
  }

  /* Remove all animations from choice buttons on mobile */
  .choice-button {
    animation: none !important;
    transition: none !important;
  }

  .choice-buttons {
    animation: none !important;
  }

  /* Executive Panel button - visible only on mobile */
  .choice-button.executive-panel {
    display: block !important;
  }

  /* Animated blobs - smaller on mobile */
  .gradient-blob {
    filter: blur(60px);
  }

  .blob-1 {
    width: 300px;
    height: 300px;
  }

  .blob-2 {
    width: 250px;
    height: 250px;
  }

  .blob-3 {
    width: 200px;
    height: 200px;
  }

  .blob-4 {
    width: 150px;
    height: 150px;
  }

  /* =================== HEADER MOBILE =================== */
  .header {
    height: 60px;
    padding: 0 15px;
  }

  .header img {
    max-height: 40px;
  }

  /* =================== MAIN APPLICATION MOBILE =================== */
  .container {
    top: 60px; /* Adjusted for smaller header */
  }

  /* Back button mobile - keep in top-right */
  .back-button {
    top: 10px !important;
    right: 15px !important;
    left: auto !important;
    padding: 8px 15px;
    font-size: 14px;
  }

  /* =================== BARN SWITCHER MOBILE =================== */
  .barn-switcher {
    position: fixed;
    top: 65px !important;
    left: auto !important;
    right: 10px !important;
    transform: none !important;
    background: rgba(255, 255, 255, 0.9);
    padding: 6px 10px !important;
    border-radius: 10px !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px !important;
    flex-direction: row !important;
  }

  .barn-switcher-label {
    display: none !important; /* Hide label on mobile */
  }

  .barn-tabs {
    display: flex;
    gap: 6px !important;
    width: auto !important;
    flex-wrap: nowrap !important;
  }

  .barn-tab {
    padding: 6px 12px !important;
    border: 1.5px solid #1E88E5 !important;
    background: white;
    color: #1E88E5;
    border-radius: 8px !important;
    font-weight: 600;
    font-size: 12px !important;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: unset !important;
    flex: unset !important;
  }

  .barn-tab.active {
    background: #1E88E5 !important;
    color: white !important;
    border-color: #1E88E5 !important;
  }

  /* =================== STATUS OVERLAY MOBILE =================== */
  /* Convert to bottom sheet on mobile */
  .status-overlay {
    position: fixed;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: none !important;
    min-width: unset !important;
    border-radius: 20px 20px 0 0 !important;
    padding: 20px !important;
    transform: translateY(calc(100% - 80px)) !important; /* Show only header by default */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    max-height: 50vh !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1) !important;
  }

  /* Add pull handle */
  .status-overlay::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: #D1D5DB;
    border-radius: 2px;
  }

  /* Expanded state */
  .status-overlay.expanded {
    transform: translateY(0) !important;
  }

  /* Collapsed view shows just the legend */
  .color-legend {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 15px;
    font-size: 12px;
  }

  .legend-item {
    padding: 5px;
    font-size: 12px;
  }

  .legend-color {
    width: 14px;
    height: 14px;
    margin-right: 6px;
  }

  /* Controls in mobile */
  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 15px;
  }

  .controls button {
    width: 100%;
    min-height: 44px; /* iOS touch target */
    font-size: 13px;
    padding: 10px 12px;
  }

  /* OMNIMAX Scanner button in status overlay - mobile only */
  .mobile-scanner-btn {
    display: block !important;
    grid-column: span 2; /* Full width */
    background: linear-gradient(135deg, #8B5CF6 0%, #7C3AED 100%);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }

  .mobile-scanner-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
  }

  .mobile-scanner-btn i {
    font-size: 16px;
  }

  /* Hide scanner button on iOS devices */
  .mobile-scanner-btn.ios-hidden {
    display: none !important;
  }

  .mobile-scanner-status {
    font-size: 11px;
    margin-left: 8px;
    padding: 2px 6px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.2);
  }

  /* =================== SCANNER OVERLAY MOBILE =================== */
  /* Hide the separate scanner overlay on mobile - it will be in status overlay */
  .scanner-overlay {
    display: none !important;
  }

  /* =================== MODALS MOBILE =================== */
  /* General modal content on phones */
  .modal-content {
    width: calc(100% - 20px) !important;
    max-width: none !important;
    margin: 10px !important;
    max-height: calc(100vh - 20px) !important;
    border-radius: 15px !important;
  }

  /* Check-in Modal Mobile */
  #checkin-modal {
    animation: none !important;
  }

  #checkin-modal .modal-content {
    width: 90%;
    height: auto;
    max-height: 80vh;
    border-radius: 15px;
    display: flex;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    flex-direction: column;
    padding: 0;
    margin: auto;
    animation: none !important;
    overflow: hidden;
  }
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
  }

  #checkin-modal h2 {
    padding: 15px 20px;
    margin: 0;
    font-size: 20px;
    background: var(--primary-blue);
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  /* Tab group mobile */
  .tab-group {
    display: flex;
    background: #F8FAFC;
    border-bottom: 1px solid #E5E7EB;
    position: sticky;
    top: 51px; /* Below header */
    z-index: 9;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab {
    flex: 1;
    min-width: 100px;
    padding: 12px 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  .tab i {
    display: block;
    margin-bottom: 4px;
    font-size: 16px;
  }

  /* Tab content mobile */
  .tab-content {
    padding: 20px !important;
    overflow-y: auto !important;
    flex: 1;
    -webkit-overflow-scrolling: touch;
  }

  /* Form groups mobile */
  .form-group {
    margin-bottom: 20px;
  }

  .form-group label {
    font-size: 14px;
    margin-bottom: 8px;
  }

  .form-group input,
  .form-group select {
    min-height: 44px; /* iOS touch target */
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 12px;
  }

  /* Chip input with scanner buttons */
  .chip-input-container {
    display: flex;
    gap: 8px;
  }

  .scan-buttons {
    display: flex;
    gap: 8px;
  }

  .scan-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Modal actions mobile - stacked vertically */
  .modal-actions {
    position: sticky;
    bottom: 0;
    background: white;
    padding: 15px 20px;
    border-top: 1px solid #E5E7EB;
    display: flex;
    flex-direction: column !important; /* Stack vertically */
    gap: 8px;
    margin: 0;
  }

  .modal-actions button {
    width: 100%;
    min-height: 48px; /* Slightly taller for better touch */
    font-size: 16px;
    padding: 12px 20px;
    border-radius: 10px;
  }
  
  /* Ensure proper order: Submit/Next at top, Previous in middle, Cancel at bottom */
  .modal-actions {
    flex-direction: column-reverse !important;
  }
  
  .modal-actions .cancel {
    order: 3;
  }
  
  .modal-actions #prev-tab {
    order: 2;
  }
  
  .modal-actions #next-tab,
  .modal-actions #submit-checkin {
    order: 1;
  }

  /* Scanner Setup Modal Mobile */
  .scanner-setup-content {
    width: calc(100% - 20px);
    max-width: none;
    height: auto;
    max-height: 90vh;
    border-radius: 15px;
    margin: 10px;
    display: flex;
    flex-direction: column;
  }

  .scanner-setup-header {
    padding: 12px 15px;
    font-size: 16px;
  }

  .scanner-setup-body {
    padding: 15px;
    overflow-y: auto;
    flex: 1;
    max-height: 50vh;
  }

  .instructions-section {
    margin-bottom: 15px;
  }

  .instructions-section h4 {
    font-size: 14px;
    margin-bottom: 10px;
  }

  .instructions-section ol {
    padding-left: 20px;
    font-size: 12px;
    line-height: 1.5;
  }

  .connect-scanner-btn,
  .test-scan-btn {
    width: 100%;
    min-height: 40px;
    font-size: 14px;
    padding: 10px;
  }

  /* Scanner terminal mobile - much smaller */
  .scanner-terminal {
    max-height: 100px;
    border-radius: 0 0 15px 15px;
  }

  .scanner-terminal-header {
    padding: 8px 12px;
    font-size: 12px;
  }

  .scanner-terminal-output {
    height: 80px;
    padding: 8px;
    font-size: 10px;
    line-height: 1.3;
  }

  /* Barcode Scanner Modal Mobile */
  .scanner-content {
    width: 100%;
    height: 100vh;
    border-radius: 0;
    padding: 0;
  }

  .scanner-header {
    padding: 15px 20px;
    font-size: 18px;
    background: var(--primary-blue);
    color: white;
  }

  .scanner-body {
    padding: 20px;
  }

  .scanner-body p {
    font-size: 14px;
    margin-bottom: 15px;
  }

  .camera-container {
    width: 100%;
    height: 300px;
    margin: 15px 0;
  }

  .scanner-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .scanner-actions button {
    width: 100%;
    min-height: 44px;
    font-size: 15px;
  }

  /* =================== 3D VIEWER MOBILE =================== */
  /* Add touch gesture hints */
  #smplr-container::after {
    content: 'Pinch to zoom • Drag to rotate';
    position: absolute;
    bottom: 100px; /* Above status overlay */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    z-index: 100;
    animation: fadeInOut 5s ease-in-out;
    pointer-events: none;
  }

  @keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    20%, 80% { opacity: 1; }
  }

  /* =================== PROFILE PANELS MOBILE =================== */
  .horse-profile-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    max-height: 70vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    padding: 20px;
  }

  .horse-profile-panel.show {
    transform: translateY(0);
  }

  .horse-profile-header h2 {
    font-size: 22px;
  }

  .profile-field {
    margin-bottom: 15px;
  }

  .profile-field label {
    font-size: 11px;
  }

  .profile-field .value {
    font-size: 16px;
  }

  /* Profile actions mobile */
  .profile-actions {
    padding: 15px;
    gap: 10px;
  }

  .profile-btn {
    min-height: 44px;
    font-size: 14px;
    padding: 12px 15px;
  }

  /* Two buttons per row on mobile */
  .profile-actions-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  /* =================== CHECKOUT MODAL MOBILE =================== */
  #checkout-modal .modal-content {
    width: 90%;
    height: auto;
    max-height: 80vh;
    border-radius: 15px;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  /* =================== CONFIRMATION GADGETS MOBILE =================== */
  .confirmation-content {
    width: calc(100% - 40px);
    max-width: none;
    min-width: unset;
    margin: 20px;
    padding: 20px;
  }

  .confirmation-datetime {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  /* =================== SUCCESS ANIMATIONS MOBILE =================== */
  .success-icon {
    width: 80px;
    height: 80px;
  }

  .success-icon i {
    font-size: 40px;
  }

  .success-content h2 {
    font-size: 24px;
  }

  /* Transfer animation mobile */
  .stable-icons {
    gap: 80px;
  }

  .stable-icon {
    font-size: 14px;
  }

  .stable-icon i {
    font-size: 32px;
  }

  .arrow {
    font-size: 20px;
  }

  /* =================== EDIT MODAL MOBILE =================== */
  .edit-modal-content {
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    margin: 0;
  }

  .edit-modal-header {
    padding: 15px 20px;
  }

  .edit-modal-header h2 {
    font-size: 20px;
  }

  .edit-tab-group {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .edit-tab {
    padding: 15px 12px;
    font-size: 13px;
    min-width: 100px;
  }

  .edit-tab-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
  }

  .edit-form-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .edit-modal-actions {
    position: sticky;
    bottom: 0;
    padding: 15px 20px;
  }

  /* =================== LICENSE PLATE MOBILE =================== */
  .license-plate {
    width: 100%;
    max-width: 350px;
    height: 60px;
  }

  .country-section {
    width: 60px;
  }

  .country-code-input {
    font-size: 16px;
  }

  .plate-number-input {
    font-size: 22px;
    letter-spacing: 2px;
  }

  /* =================== SCROLLBAR STYLING MOBILE =================== */
  /* Make scrollbars more touch-friendly */
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }

  ::-webkit-scrollbar-track {
    background: transparent;
  }

  ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
  }

  /* =================== TOUCH OPTIMIZATIONS =================== */
  /* Prevent double-tap zoom on buttons */
  button, .choice-button, .tab, .scan-btn {
    touch-action: manipulation;
  }

  /* Improve tap targets */
  button, input, select, textarea {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  }

  /* Prevent text selection on UI elements */
  .tab, .legend-item, .controls button {
    user-select: none;
    -webkit-user-select: none;
  }

  /* Smooth scrolling */
  .tab-content, .scanner-terminal-output, .horse-profile-panel {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
}

/* =================== LANDSCAPE PHONE ADJUSTMENTS =================== */
@media only screen and (max-width: 900px) and (max-height: 480px) and (orientation: landscape) {
  .header {
    height: 50px;
  }

  .header img {
    max-height: 35px;
  }

  .container {
    top: 50px;
  }

  .status-overlay {
    max-height: 40vh !important;
  }

  .horse-profile-panel {
    max-height: 80vh;
  }

  #checkin-modal .modal-content {
    max-height: 90vh;
  }

  .welcome-title {
    font-size: 28px !important;
  }

  .welcome-subtitle {
    font-size: 16px !important;
  }
}

/* =================== SMALL PHONE ADJUSTMENTS =================== */
@media only screen and (max-width: 380px) {
  .welcome-title {
    font-size: 28px !important;
  }

  .welcome-subtitle {
    font-size: 16px !important;
  }

  .choice-button {
    padding: 16px 24px !important;
    font-size: 15px !important;
  }

  .tab {
    padding: 10px 8px;
    font-size: 12px;
    min-width: 85px;
  }

  .profile-field .value {
    font-size: 14px;
  }

  .controls button {
    font-size: 13px;
    padding: 10px 15px;
  }

  /* Even smaller modals for tiny phones */
  .modal-content {
    width: calc(100% - 10px) !important;
    margin: 5px !important;
    max-height: calc(100vh - 10px) !important;
  }

  .scanner-setup-content {
    width: calc(100% - 10px) !important;
    margin: 5px !important;
  }

  .scanner-terminal-output {
    height: 60px !important;
    font-size: 9px !important;
  }

  .scanner-setup-body {
    padding: 12px !important;
  }

  .instructions-section ol {
    font-size: 11px !important;
  }
  
  /* Keep modal actions vertical on small phones */
  .modal-actions {
    padding: 12px 15px !important;
    gap: 6px !important;
  }
  
  .modal-actions button {
    min-height: 44px !important;
    font-size: 14px !important;
    padding: 10px 15px !important;
  }
}

/* =================== IPHONE NOTCH SUPPORT =================== */
@supports (padding-top: env(safe-area-inset-top)) {
  @media only screen and (max-width: 480px) {
    .header {
      padding-top: env(safe-area-inset-top);
      height: calc(60px + env(safe-area-inset-top));
    }

    .container {
      top: calc(60px + env(safe-area-inset-top));
    }

    .back-button {
      top: calc(10px + env(safe-area-inset-top)) !important;
    }

    .scanner-overlay {
      top: calc(70px + env(safe-area-inset-top)) !important;
    }

    .modal-actions {
      padding-bottom: calc(15px + env(safe-area-inset-bottom));
    }

    .status-overlay {
      padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
  }
}