/* Mobile Enhancements CSS */

/* Safe Area Support for Notched Devices */
:root {
  --safe-area-top: 0;
  --safe-area-bottom: 0;
  --safe-area-left: 0;
  --safe-area-right: 0;
  --mobile-tap-size: 44px;
  --mobile-spacing: 16px;
}

/* Mobile-First Base Styles */
body {
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  overscroll-behavior: none;
}

/* Touch-Optimized Button Size */
button,
.btn,
a[role="button"],
input[type="button"],
input[type="submit"] {
  min-height: var(--mobile-tap-size);
  min-width: var(--mobile-tap-size);
  padding: 12px 16px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

button:active,
.btn:active,
a[role="button"]:active {
  transform: scale(0.98);
  opacity: 0.9;
}

/* Mobile Toast Notifications */
.mobile-toast-container {
  position: fixed;
  bottom: var(--safe-area-bottom, 16px);
  left: var(--safe-area-left, 16px);
  right: var(--safe-area-right, 16px);
  z-index: 9999;
  pointer-events: none;
}

.mobile-toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  margin-top: 8px;
  border-radius: 8px;
  background: #1a1a1a;
  color: #fff;
  font-size: 0.9rem;
  border-left: 4px solid #ff6b6b;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  pointer-events: auto;
  animation: slideUp 0.3s ease;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
}

.mobile-toast.show {
  transform: translateY(0);
  opacity: 1;
}

.mobile-toast.mobile-toast-success {
  border-left-color: #6bff6b;
}

.mobile-toast.mobile-toast-error {
  border-left-color: #ff6b6b;
}

.mobile-toast.mobile-toast-warning {
  border-left-color: #ffb86b;
}

.mobile-toast.mobile-toast-info {
  border-left-color: #6bbfff;
}

.mobile-toast.mobile-toast-top {
  top: var(--safe-area-top, 16px);
  bottom: auto;
  animation: slideDown 0.3s ease;
  transform: translateY(-100px);
}

.mobile-toast.mobile-toast-top.show {
  transform: translateY(0);
}

.toast-message {
  flex: 1;
  line-height: 1.4;
}

.toast-action {
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 4px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.toast-action:active {
  background: rgba(255, 255, 255, 0.3);
}

/* Mobile Loader */
.mobile-loader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 26, 0.95);
  z-index: 9998;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease;
}

.mobile-loader.fade-out {
  animation: fadeOut 0.3s ease;
}

.loader-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 107, 107, 0.2);
  border-top-color: #ff6b6b;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loader-text {
  margin-top: 16px;
  color: #fff;
  font-size: 0.95rem;
  text-align: center;
}

/* Mobile Bottom Sheet Modal */
.mobile-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 9996;
  transition: background-color 0.3s ease;
  cursor: pointer;
}

.mobile-modal-overlay.show {
  background: rgba(0, 0, 0, 0.5);
}

.mobile-modal-overlay.closing {
  background: rgba(0, 0, 0, 0);
}

.mobile-bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 90vh;
  background: #fff;
  border-radius: 16px 16px 0 0;
  z-index: 9997;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
  max-width: 600px;
  margin: 0 auto;
  left: 0;
  right: 0;
}

.mobile-bottom-sheet.show {
  transform: translateY(0);
}

.mobile-bottom-sheet.closing {
  transform: translateY(100%);
}

.bottom-sheet-header {
  padding: 16px var(--safe-area-left, 16px) 16px var(--safe-area-right, 16px);
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.bottom-sheet-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #666;
  padding: 4px 8px;
}

.bottom-sheet-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  color: #333;
}

.bottom-sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border-top: 1px solid #e0e0e0;
  padding-bottom: calc(16px + var(--safe-area-bottom, 0));
}

.action-btn {
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn.action-primary {
  background: #ff6b6b;
  color: #fff;
}

.action-btn.action-primary:active {
  background: #ff5252;
}

.action-btn.action-secondary {
  background: #f0f0f0;
  color: #333;
}

.action-btn.action-secondary:active {
  background: #e0e0e0;
}

.action-btn.action-danger {
  background: #ff4757;
  color: #fff;
}

.action-btn.action-danger:active {
  background: #ff3838;
}

/* Mobile Prompt Input */
.mobile-prompt-input {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.mobile-prompt-input:focus {
  outline: none;
  border-color: #ff6b6b;
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.1);
}

/* Keyboard Visible Adjustments */
body.keyboard-visible {
  height: 100vh;
  overflow: hidden;
}

body.keyboard-visible .mobile-toast-container {
  bottom: auto;
  top: 16px;
}

/* Touch-Friendly Input Fields */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
textarea,
select {
  font-size: 16px; /* Prevents iOS zoom on focus */
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #ddd;
  transition: border-color 0.2s ease;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="tel"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #ff6b6b;
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.1);
}

/* Mobile-Optimized Select */
select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 1.5em;
  padding-right: 40px;
}

/* Pull-to-Refresh Indicator */
.pull-to-refresh-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, rgba(255, 107, 107, 0.1) 0%, transparent 100%);
  transform: translateY(-100%);
  transition: all 0.3s ease;
  z-index: 100;
}

.pull-to-refresh-indicator.pulling {
  transform: translateY(0);
}

.pull-refresh-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid rgba(255, 107, 107, 0.2);
  border-top-color: #ff6b6b;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Animations */
@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideDown {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

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

/* Mobile-Specific Scrolling */
.mobile-scroll-container {
  -webkit-overflow-scrolling: touch;
  overflow-y: scroll;
}

/* Hide scrollbars on mobile while keeping functionality */
.mobile-scroll-container::-webkit-scrollbar {
  display: none;
}

.mobile-scroll-container {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Responsive Typography */
@media (max-width: 480px) {
  :root {
    --mobile-spacing: 12px;
  }

  button,
  .btn {
    font-size: 0.95rem;
    padding: 10px 14px;
  }

  .mobile-toast {
    font-size: 0.85rem;
    padding: 12px;
  }

  .bottom-sheet-header h2 {
    font-size: 1.1rem;
  }

  .action-btn {
    font-size: 0.9rem;
    padding: 10px 14px;
  }
}

/* Landscape Mode Adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .mobile-toast-container {
    bottom: 8px;
  }

  .mobile-toast {
    margin-top: 4px;
    padding: 10px 12px;
    font-size: 0.8rem;
  }

  .mobile-bottom-sheet {
    max-height: 95vh;
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  textarea,
  select {
    padding: 8px;
    font-size: 14px;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .mobile-bottom-sheet {
    background: #2d2d2d;
    color: #fff;
  }

  .bottom-sheet-header {
    border-bottom-color: #444;
  }

  .bottom-sheet-header h2 {
    color: #fff;
  }

  .close-btn {
    color: #aaa;
  }

  .bottom-sheet-content {
    color: #ddd;
  }

  .bottom-sheet-actions {
    border-top-color: #444;
  }

  .action-btn.action-secondary {
    background: #444;
    color: #fff;
  }

  .action-btn.action-secondary:active {
    background: #555;
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  textarea,
  select {
    background: #333;
    color: #fff;
    border-color: #555;
  }

  input[type="text"]:focus,
  input[type="email"]:focus,
  input[type="password"]:focus,
  input[type="number"]:focus,
  input[type="tel"]:focus,
  textarea:focus,
  select:focus {
    border-color: #ff6b6b;
  }
}
