/**
 * ConfidenceTalk — Responsive App Shell (mobile)
 *
 * Mobile app-shell navigation (Batches 5a + 5b):
 *   - Fixed bottom tab bar with the primary sections + "More"
 *   - The existing sidebar slides in as a drawer from the left
 *   - Backdrop + safe-area support
 *
 * Surfaces:
 *   - Frontend user dashboard        → body.ct-dashboard-active
 *   - Frontend admin panel           → body.ct-admin-panel-active
 *   - wp-admin Gold Series panel     → body.toplevel_page_confidence-talk
 *
 * Applies at <=768px (bp-md). Desktop/tablet layouts are untouched.
 * Loaded after gold-series.css / frontend.css so overrides win.
 *
 * @package ConfidenceTalk
 */

/* ============================================================
   MOBILE APP SHELL — DASHBOARD + ADMIN PANELS
   ============================================================ */
@media screen and (max-width: 768px) {

  /* Layout: stack (the drawer is fixed, so the content flows normally) */
  body.ct-dashboard-active .ct-main-layout,
  body.ct-admin-panel-active .ct-main-layout,
  body.toplevel_page_confidence-talk .ct-main-layout {
    display: block;
  }

  /* Drawer: fixed slide-in panel replacing the stacked sidebar */
  body.ct-dashboard-active .ct-sidebar,
  body.ct-admin-panel-active .ct-sidebar,
  body.toplevel_page_confidence-talk .ct-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 85vw);
    min-width: 0;
    z-index: 1002;
    transform: translateX(-105%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--color-secondary-gradient, #2C5F6E) !important;
    border-radius: 0 16px 16px 0;
    padding: calc(env(safe-area-inset-top, 0px) + 16px) 0 16px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  }

  body.ct-dashboard-active .ct-sidebar.ct-drawer-open,
  body.ct-admin-panel-active .ct-sidebar.ct-drawer-open,
  body.toplevel_page_confidence-talk .ct-sidebar.ct-drawer-open {
    transform: translateX(0);
  }

  /* Backdrop */
  .ct-drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s ease, visibility 0.28s ease;
  }

  .ct-drawer-backdrop.ct-drawer-visible {
    opacity: 1;
    visibility: visible;
  }

  /* Content + site footer clear the fixed bottom tab bar */
  body.ct-dashboard-active .ct-content,
  body.ct-admin-panel-active .ct-content,
  body.toplevel_page_confidence-talk .ct-content {
    padding: 16px 12px calc(64px + env(safe-area-inset-bottom, 0px));
    min-height: auto; /* let the chat fill the viewport without extra scroll */
  }

  body.ct-dashboard-active .ct-site-content,
  body.ct-admin-panel-active .ct-site-content {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  /* Bottom tab bar */
  .ct-bottom-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1001;
    display: flex;
    align-items: stretch;
    background: var(--color-primary, #2c3e50);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.35);
  }

  .ct-bottom-tabs .ct-nav-item {
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    height: auto;
    min-height: 56px;
    margin: 0;
    padding: 6px 4px;
    border-radius: 0;
    background: transparent;
    text-align: center;
    font-size: 10px;
    line-height: 1.2;
  }

  .ct-bottom-tabs .ct-nav-item .ct-nav-icon {
    font-size: 19px;
    width: auto;
  }

  .ct-bottom-tabs .ct-nav-item.active {
    background: var(--color-secondary-gradient, #2C5F6E);
    box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.25);
  }

  .ct-bottom-tabs .ct-bottom-tabs-more {
    font-family: inherit;
    cursor: pointer;
  }
}

/* ============================================================
   BACKEND DATA TABLES — MOBILE (Batch 6)
   Wide admin/dashboard tables (CRM, Safety, Analytics, coupons,
   dashboard stats) become self-scrolling on phones instead of
   being crushed into the column layout. `display:block` turns the
   table into its own horizontal scroll box; `white-space:nowrap`
   keeps columns readable. Matches the existing .ct-table-wrapper
   scroll pattern in gold-series.css.
   ============================================================ */
@media screen and (max-width: 768px) {
  body.ct-dashboard-active .ct-content table,
  body.ct-admin-panel-active .ct-content table,
  body.ct-admin-panel-active #ct-crm-modal-overlay table,
  body.toplevel_page_confidence-talk .ct-content table,
  body.toplevel_page_confidence-talk #ct-crm-modal-overlay table {
    display: block;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
}

/* Safety log → stacked cards on small phones (data-label + ::before).
   Inline cell styles are overridden with !important. */
@media screen and (max-width: 480px) {
  .ct-safety-table,
  .ct-safety-table tbody,
  .ct-safety-table tr,
  .ct-safety-table td {
    display: block !important;
    width: 100% !important;
  }

  .ct-safety-table thead {
    display: none !important;
  }

  .ct-safety-table tr {
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-radius: 10px !important;
    margin-bottom: 10px !important;
    padding: 6px 8px !important;
  }

  .ct-safety-table td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: baseline !important;
    gap: 12px !important;
    padding: 6px 2px !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
    text-align: right !important;
    white-space: normal !important;
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  .ct-safety-table td:last-child {
    border-bottom: none !important;
  }

  .ct-safety-table td::before {
    content: attr(data-label);
    flex-shrink: 0;
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: rgba(255, 255, 255, 0.45);
    text-align: left;
  }
}


/* MOBILE TOUCH TARGET — vertical/drawer nav items (was 38px) */
@media (max-width: 768px) {
  .ct-nav-item,
  .nav-item {
    min-height: 44px;
  }
}

/* ============================================================
   CHAT BACK BUTTON — hidden by default, shown only in the
   immersive mobile chat (body.ct-chat-immersive).
   ============================================================ */
.ct-chat-back {
  display: none;
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  z-index: 3;
}

.ct-chat-back:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* ============================================================
   IMMERSIVE FULL-SCREEN CHAT (mobile) — when a conversation is
   open on a phone the chat owns the viewport. Hide the marketing
   header / footer + the fixed bottom tab bar, drop the guest-trial
   banner, and let #ct-chat-container fill the screen with the back
   button in the header. Loaded after frontend.css so it wins.
   ============================================================ */
@media screen and (max-width: 768px) {
  body.ct-dashboard-active.ct-chat-immersive .ct-site-header,
  body.ct-dashboard-active.ct-chat-immersive .ct-site-footer,
  body.ct-dashboard-active.ct-chat-immersive .ct-bottom-tabs,
  body.ct-dashboard-active.ct-chat-immersive .ct-guest-trial-banner {
    display: none !important;
  }

  body.ct-dashboard-active.ct-chat-immersive .ct-content {
    padding: 0 !important;
    min-height: 0 !important;
  }

  body.ct-dashboard-active.ct-chat-immersive .ct-gold-series {
    margin: 0 !important;
    max-width: none !important;
  }

  body.ct-dashboard-active.ct-chat-immersive #ct-tab-content {
    margin: 0 !important;
  }

  body.ct-dashboard-active.ct-chat-immersive .ct-chat-header {
    position: relative;
    padding-left: 52px;
  }

  body.ct-dashboard-active.ct-chat-immersive .ct-chat-back {
    display: flex;
  }

  body.ct-dashboard-active.ct-chat-immersive #ct-chat-container {
    height: 100vh;          /* fallback */
    height: 100dvh;         /* dynamic viewport (URL bar / keyboard aware) */
    min-height: 0;
    border-radius: 0;
    margin: 0;
    border: none;
    box-shadow: none;
  }
}

