/* ============================================================
   BOX101 — Mobile-First Enhancement Layer  (mobile.css)
   Load AFTER style.css / portal.css / admin.css on every page.
   Purely ADDITIVE: enhances small screens, leaves desktop intact.
   ============================================================ */

/* ---- Global guards (all viewports) ------------------------- */
* { -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* clip (not hidden) so it doesn't create a scroll container that breaks position:sticky */
html, body { overflow-x: clip; }
img, svg, video, canvas { max-width: 100%; }
/* Let flex/grid children shrink instead of forcing overflow */
.portal-body *, .portal-header * { min-width: 0; }

/* Smooth, momentum scrolling for any horizontal scroll area */
.table-wrap, .schedule-wrap, [data-scroll-x] {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* ============================================================
   TABLET / MOBILE  (<= 900px)
   ============================================================ */
@media (max-width: 900px) {
  /* --- Kill the #1 overflow culprit: fixed-width search boxes --- */
  .search-bar { width: 100%; }
  .search-bar input,
  #adminCustomerSearch {
    min-width: 0 !important;
    width: 100% !important;
    flex: 1 1 auto;
  }
  #adminCustomerSearchResults {
    min-width: 0 !important;
    left: 0; right: 0;
    width: 100%;
  }
  /* Admin header search wrapper injected by admin-layout.js */
  .portal-header > div:last-child { width: 100%; }

  /* --- Comfortable tap targets (Apple HIG = 44px) --- */
  .btn, .filter-tab, .sidebar-nav a, .bottom-nav-item,
  button:not(.icon-btn), select, .form-input, .form-control input, input[type="submit"] {
    min-height: 44px;
  }
  .btn-sm { min-height: 38px; }

  /* --- Generic safe table fallback: horizontal scroll, never overflow page --- */
  .portal-body .table:not(.cards-on-mobile),
  .portal-body table:not(.cards-on-mobile):not(.schedule-table) {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  /* --- Stat / generic card grids collapse --- */
  .stat-cards { grid-template-columns: 1fr 1fr !important; }

  /* --- Bottom-nav clearance so content isn't hidden behind the bar --- */
  body.has-bottom-nav .portal-body { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
}

/* ============================================================
   PHONE  (<= 640px)
   ============================================================ */
@media (max-width: 640px) {
  .stat-cards { grid-template-columns: 1fr !important; }

  /* Generic multi-column inline grids → single column.
     Scoped to portal-body so we don't disturb the public landing page. */
  .portal-body [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Buttons in headers/toolbars go full width for easy tapping */
  .portal-header .btn,
  .admin-content-header .btn { width: 100%; justify-content: center; }

  /* --- Opt-in: turn a wide table into stacked cards ---
     Add class="cards-on-mobile" to a <table> and data-label="Col" on each <td>. */
  table.cards-on-mobile { width: 100%; }
  table.cards-on-mobile thead { display: none; }
  table.cards-on-mobile tr {
    display: block;
    background: var(--bg-card, #141414);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm, 12px);
    padding: 0.85rem 1rem;
    margin-bottom: 0.85rem;
  }
  table.cards-on-mobile td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    padding: 0.4rem 0;
    border: none;
    text-align: right;
    white-space: normal;
  }
  table.cards-on-mobile td::before {
    content: attr(data-label);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted, #888);
    font-weight: 700;
    text-align: left;
    flex: 0 0 auto;
  }
  table.cards-on-mobile td[data-label=""]::before { content: ""; }
  /* Loading / empty rows that span all columns */
  table.cards-on-mobile td.cards-full {
    justify-content: center;
    text-align: center;
    color: var(--text-muted, #888);
  }

  /* Modals: full-width sheets with safe-area */
  .modal, .booking-modal-box {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 1.25rem 1.25rem 0 0;
  }
}

/* ============================================================
   BOTTOM TAB BAR (customer portal, mobile only)
   ============================================================ */
.bottom-nav { display: none; }

@media (max-width: 900px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 150;
    background: rgba(12,12,12,0.92);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 0.4rem 0.25rem calc(0.4rem + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 28px rgba(0,0,0,0.45);
  }
  .bottom-nav-item {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0.4rem 0;
    color: var(--text-muted, #8a8a8a);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    text-decoration: none;
    border-radius: 12px;
    transition: color 0.2s ease, transform 0.15s ease;
  }
  .bottom-nav-item i { font-size: 1.45rem; line-height: 1; transition: transform 0.2s ease; }
  .bottom-nav-item:active { transform: scale(0.92); }
  .bottom-nav-item.active { color: var(--red-bright, #ff2a38); }
  .bottom-nav-item.active i { transform: translateY(-2px); }
  .bottom-nav-item.active::after {
    content: '';
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--red, #E8000E);
    box-shadow: 0 0 10px var(--red, #E8000E);
    margin-top: 1px;
  }

  /* When bottom nav is present, the floating hamburger would collide —
     move it to the right and shrink, or hide if drawer rarely needed. */
  body.has-bottom-nav .sidebar-toggle { top: max(0.9rem, env(safe-area-inset-top)); }
}

/* ============================================================
   STICKY MOBILE PORTAL HEADER
   ============================================================ */
@media (max-width: 900px) {
  .portal-header {
    position: sticky;
    top: 0;
    z-index: 90;
    background: rgba(10,10,10,0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }
}

/* ============================================================
   REFINED MOTION  (gated behind prefers-reduced-motion)
   ============================================================ */
@media (prefers-reduced-motion: no-preference) {
  /* Entrance: cards/sections fade-rise as they mount */
  .anim-rise { animation: bx-rise 0.5s cubic-bezier(0.22,1,0.36,1) both; }
  .anim-rise-1 { animation-delay: 0.05s; }
  .anim-rise-2 { animation-delay: 0.10s; }
  .anim-rise-3 { animation-delay: 0.15s; }
  .anim-rise-4 { animation-delay: 0.20s; }
  .anim-rise-5 { animation-delay: 0.25s; }
  @keyframes bx-rise {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  /* Press feedback on primary tappables */
  .btn:active, .plan-card:active, .stat-card:active, .card.tappable:active {
    transform: scale(0.985);
  }

  /* Page content settle on load */
  .portal-body > * { animation: bx-fade 0.45s ease both; }
  @keyframes bx-fade { from { opacity: 0; } to { opacity: 1; } }
}

/* Skeleton shimmer (works regardless of motion pref, but subtle) */
.skeleton {
  background: linear-gradient(100deg, rgba(255,255,255,0.04) 30%, rgba(255,255,255,0.10) 50%, rgba(255,255,255,0.04) 70%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm, 12px);
}
@media (prefers-reduced-motion: no-preference) {
  .skeleton { animation: bx-shimmer 1.4s infinite linear; }
  @keyframes bx-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
}

/* Respect reduced motion globally for our additions */
@media (prefers-reduced-motion: reduce) {
  .anim-rise, .portal-body > * { animation: none !important; }
}

/* ============================================================
   NOTIFICATIONS — bell, badge, panel (all viewports)
   ============================================================ */
.notif-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1.5px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: var(--text-primary, #fff);
  font-size: 1.4rem;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}
.notif-bell:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.18); }
.notif-bell:active { transform: scale(0.94); }
.notif-bell.has-unread i { color: var(--red-bright, #ff2a38); }
@media (prefers-reduced-motion: no-preference) {
  .notif-bell.has-unread i { animation: notif-swing 2.4s ease-in-out infinite; transform-origin: top center; }
  @keyframes notif-swing {
    0%, 88%, 100% { transform: rotate(0); }
    90% { transform: rotate(12deg); }
    94% { transform: rotate(-10deg); }
    97% { transform: rotate(6deg); }
  }
}
.notif-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 18px; height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--red, #E8000E);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 2px var(--bg-base, #0a0a0a);
}

.notif-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(3px);
  display: none;
}
.notif-overlay.open { display: block; }
.notif-panel {
  position: absolute;
  top: 4.5rem; right: 1.5rem;
  width: min(380px, calc(100vw - 2rem));
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-card, #141414);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 1rem;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
  overflow: hidden;
}
@media (prefers-reduced-motion: no-preference) {
  .notif-overlay.open .notif-panel { animation: notif-pop 0.22s cubic-bezier(0.22,1,0.36,1) both; }
  @keyframes notif-pop { from { opacity: 0; transform: translateY(-8px) scale(0.98); } to { opacity: 1; transform: none; } }
}
.notif-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.notif-markall {
  background: none; border: none; color: var(--text-muted, #9ca3af);
  font-size: 0.78rem; font-weight: 600; cursor: pointer;
}
.notif-markall:hover { color: var(--red-bright, #ff2a38); }
.notif-close {
  background: none; border: none; color: var(--text-primary, #fff);
  font-size: 1.2rem; cursor: pointer; line-height: 1; padding: 0.2rem;
}
.notif-list { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.notif-item {
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  position: relative;
}
.notif-item.unread { background: rgba(232,0,14,0.06); }
.notif-item.unread::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--red, #E8000E);
}
.notif-item-top { display: flex; justify-content: space-between; gap: 0.75rem; align-items: baseline; }
.notif-item-top strong { font-size: 0.92rem; }
.notif-time { font-size: 0.72rem; color: var(--text-muted, #9ca3af); white-space: nowrap; flex: 0 0 auto; }
.notif-body { margin: 0.35rem 0 0; font-size: 0.85rem; color: var(--text-secondary, #cbd5e1); line-height: 1.5; }
.notif-link {
  display: inline-flex; align-items: center; gap: 0.3rem;
  margin-top: 0.6rem; font-size: 0.82rem; font-weight: 700;
  color: var(--red-bright, #ff2a38);
}
.notif-empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted, #9ca3af); }
.notif-empty i { font-size: 2rem; display: block; margin-bottom: 0.5rem; opacity: 0.6; }

/* Mobile: panel becomes a bottom sheet */
@media (max-width: 640px) {
  .notif-panel {
    top: auto; right: 0; left: 0; bottom: 0;
    width: 100%;
    max-height: 80vh;
    border-radius: 1.25rem 1.25rem 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  @media (prefers-reduced-motion: no-preference) {
    .notif-overlay.open .notif-panel { animation: notif-sheet 0.28s cubic-bezier(0.22,1,0.36,1) both; }
    @keyframes notif-sheet { from { transform: translateY(100%); } to { transform: none; } }
  }
}

/* ============================================================
   CHAT — message threads (customer + admin)
   ============================================================ */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  background: rgba(0,0,0,0.25);
  border-radius: var(--radius-sm, 12px);
}
.chat-row { display: flex; }
.chat-row.mine { justify-content: flex-end; }
.chat-row.theirs { justify-content: flex-start; }
.chat-bubble {
  max-width: 78%;
  padding: 0.6rem 0.85rem 1.15rem;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.45;
  position: relative;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-row.theirs .chat-bubble {
  background: var(--bg-surface-2, #1e1e1e);
  border: 1px solid rgba(255,255,255,0.08);
  border-bottom-left-radius: 4px;
  color: var(--text-primary, #fff);
}
.chat-row.mine .chat-bubble {
  background: linear-gradient(135deg, var(--red, #E8000E) 0%, var(--red-dark, #b3000b) 100%);
  border-bottom-right-radius: 4px;
  color: #fff;
}
.chat-meta {
  position: absolute;
  right: 0.7rem; bottom: 0.35rem;
  font-size: 0.62rem;
  opacity: 0.7;
}
.chat-empty { text-align: center; color: var(--text-muted, #9ca3af); padding: 2.5rem 1rem; margin: auto; }
.chat-empty i { font-size: 2.2rem; display: block; margin-bottom: 0.5rem; opacity: 0.6; }

.chat-composer {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  padding-top: 0.75rem;
}
.chat-composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  min-height: 44px;
}
.chat-send-btn {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--red, #E8000E);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease, background 0.2s ease;
}
.chat-send-btn:hover { background: var(--red-bright, #ff2a38); }
.chat-send-btn:active { transform: scale(0.9); }
.chat-send-btn:disabled { opacity: 0.5; cursor: default; }

/* Admin inbox conversation list */
.conv-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  text-align: left;
  padding: 0.85rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  color: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
}
.conv-item:hover, .conv-item.active { background: rgba(255,255,255,0.04); }
.conv-avatar {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(232,0,14,0.15);
  color: var(--red-bright, #ff2a38);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
}
.conv-main { flex: 1; min-width: 0; }
.conv-name { font-weight: 700; font-size: 0.9rem; display: flex; justify-content: space-between; gap: 0.5rem; }
.conv-name span.time { font-weight: 500; font-size: 0.7rem; color: var(--text-muted, #9ca3af); }
.conv-preview { font-size: 0.82rem; color: var(--text-muted, #9ca3af); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-unread {
  flex: 0 0 auto;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px;
  background: var(--red, #E8000E); color: #fff;
  font-size: 0.7rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}

/* Sidebar nav unread pill (chat) */
.nav-unread {
  margin-left: auto;
  background: var(--red, #E8000E); color: #fff;
  border-radius: 10px; padding: 0 6px;
  font-size: 0.72rem; font-weight: 800;
}

/* ============================================================
   PWA INSTALL BANNER
   ============================================================ */
.pwa-install-banner {
  position: fixed;
  left: 0.75rem; right: 0.75rem;
  bottom: calc(0.75rem + env(safe-area-inset-bottom));
  z-index: 400;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  background: rgba(20,20,20,0.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  box-shadow: 0 16px 44px rgba(0,0,0,0.55);
}
/* Sit above the customer bottom tab bar when present */
body.has-bottom-nav .pwa-install-banner { bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
.pwa-install-logo { width: 38px; height: 38px; border-radius: 9px; flex: 0 0 auto; object-fit: contain; }
.pwa-install-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.pwa-install-text strong { font-size: 0.92rem; }
.pwa-install-text span { font-size: 0.76rem; color: var(--text-muted, #9ca3af); }
.pwa-install-go {
  flex: 0 0 auto;
  background: var(--red, #E8000E); color: #fff;
  border: none; border-radius: 10px;
  padding: 0.55rem 1.1rem; font-weight: 800; font-size: 0.85rem;
  cursor: pointer; min-height: 40px;
}
.pwa-install-go:active { transform: scale(0.95); }
.pwa-install-ios { flex: 0 0 auto; font-size: 0.78rem; color: var(--text-secondary, #cbd5e1); max-width: 150px; }
.pwa-install-ios i { color: #0a84ff; vertical-align: middle; }
.pwa-install-close {
  flex: 0 0 auto;
  background: none; border: none; color: var(--text-muted, #9ca3af);
  font-size: 1.1rem; cursor: pointer; padding: 0.2rem; line-height: 1;
}

/* ============================================================
   HOMEPAGE SCHEDULE — mobile day cards (replaces wide table)
   ============================================================ */
.schedule-mobile { display: none; }

@media (max-width: 768px) {
  .schedule-wrap { display: none; }          /* hide the scrolling table */
  .schedule-mobile {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 560px;
    margin: 0 auto;
  }
  .sched-m-day {
    background: var(--bg-surface, #141414);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius, 16px);
    overflow: hidden;
    box-shadow: var(--shadow-sm, 0 4px 14px rgba(0,0,0,0.3));
  }
  .sched-m-day-head {
    background: linear-gradient(135deg, rgba(232,0,14,0.18) 0%, rgba(232,0,14,0.06) 100%);
    border-bottom: 1px solid rgba(232,0,14,0.25);
    padding: 0.7rem 1rem;
    font-family: var(--font-heading, inherit);
    font-weight: 800;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.45rem;
  }
  .sched-m-day-head i { color: var(--red-bright, #ff2a38); }
  .sched-m-row {
    display: flex;
    gap: 0.85rem;
    padding: 0.85rem 1rem;
    align-items: flex-start;
  }
  .sched-m-row + .sched-m-row { border-top: 1px solid rgba(255,255,255,0.05); }
  .sched-m-time {
    flex: 0 0 auto;
    min-width: 92px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-secondary, #cbd5e1);
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 10px;
    padding: 0.4rem 0.5rem;
    text-align: center;
    line-height: 1.25;
  }
  .sched-m-body { flex: 1; min-width: 0; }
  .sched-m-body > div { margin-bottom: 0 !important; }
  .sched-m-body .class-pill { white-space: normal; }
  .sched-m-body .sched-book-pill { margin-top: 0.4rem; }
}
