/* ==========================================================================
   Responsive CSS & Mobile Bottom Navigation Bar for Devomize
   ========================================================================== */

/* Universal Reset for overflow prevention without breaking sticky headers */
html {
  max-width: 100%;
}
body {
  max-width: 100%;
  overflow-x: clip;
}

/* Modals (Universal for Desktop & Mobile) */
.app-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.app-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px;
  box-shadow: var(--shadow-lg);
  position: relative;
  animation: modalPop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.95) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 12px;
}

.modal-close-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-main);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: var(--transition);
}

.modal-close-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

[data-theme="light"] .app-modal {
  background: #ffffff;
  border-color: #e2e8f0;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .modal-close-btn {
  background: #f1f5f9;
  color: #334155;
}

/* Desktop default states */
.mobile-bottom-nav {
  display: none;
}
.mobile-brand-banner {
  display: none !important;
}
.mobile-products-list {
  display: none;
}
.mobile-orders-list {
  display: none;
}
.desktop-table-view {
  display: block;
}

@media (max-width: 1024px) {
  :root {
    --sidebar-width: 240px;
  }
  .grid-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .app-sidebar {
    transform: translateX(-100%);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.9);
  }

  .app-sidebar.open {
    transform: translateX(0);
  }

  .app-main {
    margin-left: 0 !important;
    max-width: 100vw;
    min-width: 0;
    overflow-x: clip;
  }

  .app-container {
    max-width: 100vw;
    overflow-x: clip;
  }

  .mobile-toggle {
    display: inline-flex;
  }

  .grid-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .grid-stats .stat-card:last-child:nth-child(odd) {
    grid-column: span 2;
  }

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

  .stat-icon {
    width: 38px !important;
    height: 38px !important;
  }

  .stat-value {
    font-size: 1.3rem !important;
  }

  .desktop-chart-switch {
    display: none !important;
  }

  .mobile-chart-select-wrapper {
    display: block !important;
    width: 100%;
  }

  .chart-canvas-wrapper {
    height: 230px !important;
  }

  .dashboard-filter-bar {
    padding: 12px 14px !important;
    gap: 10px !important;
  }

  .dashboard-site-select {
    width: 100% !important;
    min-width: 0 !important;
  }

  .dashboard-main-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    width: 100% !important;
  }

  .page-content {
    padding: 14px 12px;
    padding-bottom: 96px !important; /* Space for Mobile Bottom Nav so content never gets covered */
    max-width: 100vw;
    overflow-x: clip;
  }

  .card {
    max-width: 100%;
    margin-bottom: 16px;
  }

  /* Impersonation Bar on Mobile: Compact & single-line */
  .impersonation-bar {
    padding: 6px 12px !important;
    font-size: 0.74rem !important;
    height: 36px !important;
  }

  .impersonation-bar-email {
    display: none !important;
  }

  /* Header on Mobile: Frozen / Sticky at top */
  .app-header {
    height: 56px;
    min-height: 56px;
    padding: 0 12px;
    justify-content: center !important;
    position: sticky;
    top: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-subtle);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }

  body.has-impersonation .app-header {
    top: 36px !important;
  }

  [data-theme="light"] .app-header {
    background: rgba(255, 255, 255, 0.96) !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  }

  .desktop-only-header {
    display: none !important;
  }

  .mobile-brand-banner {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
  }

  .mobile-brand-banner img,
  .mobile-header-brand-img {
    max-height: 42px;
    max-width: 230px;
    object-fit: contain;
    transition: var(--transition);
  }

  /* Pitch Black Theme: Add bright white glow shadow behind transparent PNG */
  [data-theme="dark"] .mobile-header-brand-img,
  :root:not([data-theme="light"]) .mobile-header-brand-img {
    filter: drop-shadow(0 0 1px #ffffff) drop-shadow(0 0 7px rgba(255, 255, 255, 0.85)) drop-shadow(0 0 16px rgba(255, 255, 255, 0.45));
  }

  /* Pure White Theme: No shadow as requested */
  [data-theme="light"] .mobile-header-brand-img {
    filter: none !important;
  }

  /* Fixed Mobile Bottom Navigation Bar */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-subtle);
    z-index: 999;
    align-items: center;
    justify-content: space-around;
    padding: 0 6px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-dim);
    font-size: 0.7rem;
    font-weight: 600;
    text-decoration: none;
    transition: var(--transition);
    padding: 6px 0;
    text-align: center;
  }

  .bottom-nav-item svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
    transition: var(--transition);
  }

  .bottom-nav-item:hover,
  .bottom-nav-item.active {
    color: var(--primary);
  }

  .bottom-nav-item.active svg {
    stroke: var(--primary);
    transform: translateY(-2px);
  }

  /* Elevated Circular FAB (+) in the center of the mobile bottom nav */
  .bottom-nav-fab-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 56px;
    height: 100%;
    flex-shrink: 0;
  }

  .bottom-nav-fab {
    position: absolute;
    top: -18px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: #ffffff;
    border: 3.5px solid var(--bg-surface);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 1001;
  }

  .bottom-nav-fab:active {
    transform: scale(0.92);
  }

  [data-theme="light"] .mobile-bottom-nav {
    background: rgba(255, 255, 255, 0.95);
    border-top-color: #e2e8f0;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.05);
  }

  [data-theme="light"] .bottom-nav-fab {
    border-color: #ffffff;
    box-shadow: 0 6px 18px rgba(79, 70, 229, 0.4);
  }

  /* Products & Orders on Mobile: Hide table, show compact cards */
  .desktop-table-view {
    display: none !important;
  }

  .mobile-products-list,
  .mobile-orders-list {
    display: flex !important;
    flex-direction: column;
    gap: 10px;
    width: 100%;
  }

  /* Mobile Product Card (Image + Name only) */
  .mobile-prod-row {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: var(--transition);
  }

  .mobile-prod-row:hover,
  .mobile-prod-row:active {
    border-color: var(--border-focus);
    background: var(--bg-card-hover);
  }

  .mobile-prod-thumb {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
  }

  .mobile-prod-thumb.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
  }

  .mobile-prod-content {
    flex: 1;
    min-width: 0;
  }

  .mobile-prod-title {
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-prod-subtitle {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
  }

  .mobile-prod-arrow {
    color: var(--text-dim);
    font-size: 1rem;
    padding-left: 4px;
  }

  /* Mobile Order Card */
  .mobile-order-row {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    cursor: pointer;
    transition: var(--transition);
  }

  .mobile-order-row:hover,
  .mobile-order-row:active {
    border-color: var(--border-focus);
    background: var(--bg-card-hover);
  }
}

/* Mobile backdrop when sidebar is open */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 45;
}

.sidebar-backdrop.active {
  display: block;
}

/* Hide Install Buttons Automatically in Native Standalone App Mode */
@media all and (display-mode: standalone) {
  .btn-pwa-install,
  #pwaInstallBtn,
  .install-native-app-btn,
  .pwa-install-wrapper {
    display: none !important;
  }
}
