/**
 * DTC BTS - Mobile Mode & PWA Installation Modal Styling
 */

/* Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  z-index: 1040;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.mobile-bottom-nav-inner {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: space-around;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: #64748b;
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
  gap: 2px;
  padding: 6px 0;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease;
}

.mobile-nav-item i {
  font-size: 1.15rem;
  transition: transform 0.15s ease;
}

.mobile-nav-item.active {
  color: #1e3a8a;
}

.mobile-nav-item.active i {
  transform: translateY(-2px);
}

.mobile-nav-item .badge {
  position: absolute;
  top: 4px;
  right: 25%;
  font-size: 0.68rem;
  padding: 2px 4px;
}

/* PWA App Install Modal / Sheet */
#pwaInstallModal .modal-dialog {
  max-width: 440px;
  margin: auto;
}

.pwa-app-card {
  background: linear-gradient(145deg, #1e3a8a, #0f172a);
  color: white;
  border-radius: 16px;
  padding: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.2);
}

.pwa-app-card::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.2) 0%, transparent 70%);
  pointer-events: none;
}

.pwa-icon-box {
  width: 68px;
  height: 68px;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  overflow: hidden;
  flex-shrink: 0;
  background: white;
  padding: 4px;
}

.pwa-icon-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.pwa-feature-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.pwa-feature-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #e0f2fe;
  color: #0284c7;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.95rem;
}

/* Floating Install Banner for Mobile */
#mobileInstallBanner {
  position: fixed;
  top: 10px;
  left: 12px;
  right: 12px;
  background: #ffffff;
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: 0 4px 20px rgba(30, 58, 138, 0.15);
  z-index: 1055;
  display: none;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.3s ease;
}

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

/* Media Queries for Mobile & Tablet Experience */
html,
body {
  max-width: 100vw !important;
  overflow-x: hidden !important;
}

.app-layout,
.main-wrapper,
#main-content,
.content-area {
  min-width: 0 !important;
  max-width: 100vw !important;
}

.table-container,
.table-responsive,
.rbac-table-wrap,
#urgentTableScrollWrapper,
.nearest-table-scroll {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  max-width: 100% !important;
  min-width: 0 !important;
}

@media (max-width: 992px) {
  #sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    height: 100dvh !important;
    width: min(260px, 82vw) !important;
    max-width: 82vw !important;
    z-index: 1050 !important;
    transform: translateX(-105%) !important;
    margin-left: 0 !important;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }

  #sidebar.show {
    transform: translateX(0) !important;
  }
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    display: block;
  }

  body.app-layout,
  .app-layout {
    overflow: hidden !important;
    max-width: 100vw !important;
  }

  .main-wrapper {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    overflow-x: hidden !important;
  }

  #main-content,
  .main-content,
  .content-area {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 8px 10px calc(68px + env(safe-area-inset-bottom, 0px)) !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  #top-header,
  .top-bar,
  .top-navbar {
    width: calc(100% - 16px) !important;
    max-width: calc(100% - 16px) !important;
    margin: 6px 8px 0 8px !important;
    box-sizing: border-box !important;
    overflow: visible !important;
    position: relative !important;
    z-index: 1030 !important;
    padding: 6px 10px !important;
    gap: 6px !important;
  }

  /* Thẻ KPI & Khối Flex/Grid co giãn mượt, chống tràn chữ */
  .kpi-card,
  .card,
  .card-body,
  .card-header {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .kpi-card {
    padding: 10px 12px !important;
    gap: 8px !important;
  }

  .kpi-card > div {
    min-width: 0 !important;
  }

  .kpi-title,
  .kpi-value,
  .kpi-sub {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    max-width: 100% !important;
  }

  .table-toolbar {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px;
  }

  .table-container {
    max-height: calc(100vh - 250px) !important;
  }

  #btnInstallAppHeader {
    display: inline-flex !important;
  }

  /* Popup bản đồ Leaflet co giãn theo màn hình điện thoại */
  .leaflet-popup-content-wrapper {
    max-width: min(320px, 88vw) !important;
  }

  .leaflet-popup-content {
    min-width: 220px !important;
    max-width: min(300px, 82vw) !important;
    margin: 10px 12px !important;
    word-break: break-word !important;
  }

  /* Modal co giãn gọn trên mobile */
  .modal-dialog {
    margin: 10px !important;
    max-width: calc(100vw - 20px) !important;
  }
}

@media (max-width: 576px) {
  .login-card {
    padding: 24px 18px 20px !important;
    border-radius: 16px !important;
  }

  .card-header {
    padding: 8px 12px !important;
  }

  .card-body {
    padding: 10px 12px !important;
  }
}

/* Standalone / PWA Mode */
@media all and (display-mode: standalone) {
  #mobileInstallBanner,
  #btnInstallAppHeader,
  #sidebarInstallBtn {
    display: none !important;
  }
}
