/**
 * mobile.css - Comprehensive Mobile App Enhancements for RKA KWEZI
 * Optimizes the web application for a smooth native-like mobile experience.
 */

:root {
  --mobile-tab-height: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* Touch optimizations */
html, body {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Safe area support for iOS notches, Dynamic Island, and Android gesture bars */
body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* Standalone / App Mode enhancements */
@media all and (display-mode: standalone), (display-mode: fullscreen) {
  body {
    user-select: none;
    -webkit-user-select: none;
  }
  input, textarea, select, [contenteditable="true"] {
    user-select: auto;
    -webkit-user-select: auto;
  }
  .app-shell .topbar {
    padding-top: calc(8px + var(--safe-top));
  }
}

/* Mobile Topbar Adjustments */
@media (max-width: 768px) {
  .app-shell .topbar {
    padding-left: 12px;
    padding-right: 12px;
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar-titles {
    max-width: calc(100% - 150px);
  }
  .page-title {
    font-size: 1.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .page-sub {
    font-size: 0.75rem;
    display: none; /* Hide subtitle on tiny screens to save vertical space */
  }
  .topbar-actions {
    gap: 6px;
  }
  .topbar-actions .icon-btn {
    width: 38px;
    height: 38px;
  }

  /* Main content padding to avoid being covered by mobile bottom tab bar */
  .main-wrap {
    padding-bottom: calc(var(--mobile-tab-height) + var(--safe-bottom) + 20px) !important;
  }

  /* Prevent side-scrolling jitter */
  .content {
    padding: 12px 10px !important;
    overflow-x: hidden;
  }

  /* Touch-friendly buttons and controls */
  .btn, .form-control, .form-select {
    min-height: 42px;
  }
  .btn-sm {
    min-height: 34px;
  }

  /* Cards styling for mobile */
  .card {
    border-radius: 12px !important;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  }
  .card-body {
    padding: 14px !important;
  }

  /* Responsive tables with smooth inertial scroll */
  .table-responsive {
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    overflow-x: auto;
  }
  .table-responsive table {
    white-space: nowrap;
    font-size: 0.88rem;
  }
  .table-responsive table td, 
  .table-responsive table th {
    padding: 10px 8px;
  }

  /* Metric cards grid for mobile */
  .stat-card {
    padding: 12px !important;
  }
}

/* ==========================================================================
   Mobile Bottom Tab Bar (App Dock)
   ========================================================================== */
.mobile-bottom-dock {
  display: none;
}

@media (max-width: 768px) {
  .mobile-bottom-dock {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--mobile-tab-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid #E2E8F0;
    z-index: 1030;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  }

  /* Dark mode support */
  [data-theme="dark"] .mobile-bottom-dock,
  [data-bs-theme="dark"] .mobile-bottom-dock {
    background: rgba(18, 24, 38, 0.95);
    border-top: 1px solid #2D3748;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.35);
  }

  .dock-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #64748B;
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 500;
    position: relative;
    transition: color 0.15s ease, transform 0.1s ease;
    padding-top: 4px;
    cursor: pointer;
    background: none;
    border: none;
  }

  .dock-item:active {
    transform: scale(0.92);
  }

  .dock-item i {
    font-size: 1.28rem;
    margin-bottom: 2px;
    line-height: 1;
    transition: transform 0.15s ease;
  }

  .dock-item.active {
    color: var(--brand, #0072BC);
    font-weight: 600;
  }

  .dock-item.active i {
    transform: translateY(-1px);
  }

  .dock-item .dock-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 18px);
    font-size: 0.62rem;
    padding: 2px 5px;
    border-radius: 10px;
    background-color: #EF4444;
    color: #FFF;
    font-weight: 700;
  }
}

/* ==========================================================================
   PWA / Mobile Install Prompt Banner & Modal
   ========================================================================== */
.mobile-install-banner,
#rkaInstallBanner {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

[data-theme="dark"] .mobile-install-banner,
[data-bs-theme="dark"] .mobile-install-banner {
  background: #1E293B;
  border-color: #334155;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

@keyframes slideUpBanner {
  from {
    transform: translateY(100px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.mobile-install-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.mobile-install-banner-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: contain;
  background: #F8FAFC;
  padding: 4px;
  border: 1px solid #E2E8F0;
}

.mobile-install-banner-text h6 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
}

.mobile-install-banner-text p {
  margin: 2px 0 0;
  font-size: 0.74rem;
  color: #64748B;
  line-height: 1.2;
}

.mobile-install-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* iOS Installation Instruction Bottom Sheet Modal */
.ios-install-sheet {
  border-radius: 24px 24px 0 0;
}

.ios-step {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}

.ios-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand, #0072BC);
  color: #FFF;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ios-step-text {
  font-size: 0.92rem;
  color: #334155;
  line-height: 1.4;
}

[data-theme="dark"] .ios-step-text,
[data-bs-theme="dark"] .ios-step-text {
  color: #CBD5E1;
}

/* Global Offline Modal & Overlay - Hidden per user requirement (no offline indication) */
.rka-offline-overlay,
.rka-offline-pill {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ==========================================================================
   OS Selection Dialog & Hero Button
   ========================================================================== */
.mobile-app-cta-btn {
  background-color: #FFFFFF !important;
  color: #0072BC !important;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: none;
}
.mobile-app-cta-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25) !important;
  color: #005a96 !important;
}
.mobile-app-cta-btn:active {
  transform: translateY(0);
}

.os-card {
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  background: #FFFFFF;
  border: 2px solid #E2E8F0 !important;
  position: relative;
}
.os-card:hover {
  transform: translateY(-3px);
  border-color: #0072BC !important;
  box-shadow: 0 10px 24px rgba(0, 114, 188, 0.12);
}
.os-card.active {
  border-color: #0072BC !important;
  background: rgba(0, 114, 188, 0.04) !important;
  box-shadow: 0 10px 25px rgba(0, 114, 188, 0.16);
}
.os-card.active::after {
  content: "✓";
  position: absolute;
  top: 10px;
  right: 12px;
  background: #0072BC;
  color: #FFF;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

[data-theme="dark"] .os-card,
[data-bs-theme="dark"] .os-card {
  background: #1E293B;
  border-color: #334155 !important;
}
[data-theme="dark"] .os-card.active,
[data-bs-theme="dark"] .os-card.active {
  background: rgba(0, 114, 188, 0.15) !important;
  border-color: #38BDF8 !important;
}

/* ==========================================================================
   Real-Time Mobile Sync & Pull-to-Refresh Indicator
   ========================================================================== */
.ptr-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translate(-50%, -100%);
  z-index: 1060;
  background: #FFFFFF;
  border-radius: 24px;
  padding: 6px 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #1E293B;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.15s ease-out;
  border: 1px solid #E2E8F0;
  opacity: 0;
}

[data-theme="dark"] .ptr-indicator,
[data-bs-theme="dark"] .ptr-indicator {
  background: #1E293B;
  color: #F8FAFC;
  border-color: #334155;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.ptr-indicator .ptr-icon {
  font-size: 1.1rem;
}

.mobile-sync-toast {
  position: fixed;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translate(-50%, -50px);
  z-index: 1070;
  background: rgba(0, 114, 188, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #FFFFFF;
  padding: 7px 18px;
  border-radius: 30px;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 114, 188, 0.35);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.mobile-sync-toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.sync-pending-pill {
  position: fixed;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translate(-50%, 0);
  z-index: 1070;
  background: #0F172A;
  color: #FFFFFF;
  padding: 6px 14px;
  border-radius: 30px;
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  animation: fadeInDown 0.3s ease;
}

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

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

.spin {
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
