/*
 * Centralized Sidebar Layout System v2
 * Espresso sidebar with amber accents
 * Used by: Chat, PO Builder, Packages
 */

/* ============================================
   HUB EMBED MODE — Reduce padding when loaded inside hub iframe
   ============================================ */

body.hub-embed-mode {
  padding-top: 0 !important;
  margin-top: 0 !important;
}

body.hub-embed-mode > .mx-auto {
  padding-top: 4px !important;
}

/* Embed mode: the parent (`packages.html`) already provides
   horizontal page padding via its own `.mx-auto px-2 md:px-4`
   wrapper. Repeating that inside the iframe wastes ~16 px each side
   on phones and makes the box content read as a narrow column with
   visible white margins. Drop the iframe's horizontal padding on
   phones so the inner panels use the full iframe width. */
@media (max-width: 768px) {
  body.hub-embed-mode > .mx-auto {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }
}

/* Hide header and sidebar when embedded inside parent module iframe */
.hub-embed-mode [id$="ModuleHeader"],
.hub-embed-mode #packageModuleHeader {
  display: none !important;
}

.hub-embed-mode .module-sidebar,
.hub-embed-mode .sidebar-fab,
.hub-embed-mode .sidebar-overlay {
  display: none !important;
}

.hub-embed-mode .module-main-content {
  margin-left: 0 !important;
}

/* Let the main content fill full width when sidebar is hidden */
.hub-embed-mode .module-main-content [data-action="toggle-sidebar"] {
  display: none !important;
}

/* ============================================
   SIDEBAR - Collapsible left panel
   ============================================ */

.module-sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--sidebar, var(--oc-navy, #011638));
  color: rgba(255,255,255,0.8);
  display: flex;
  flex-direction: column;
  border-radius: var(--radius, 5px);
  box-shadow: var(--shadow-md);
  height: 100%;
  overflow: hidden;
  transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease, visibility 0.3s ease;
  position: relative;
}

/* Collapsed state - completely hide sidebar */
.module-sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  opacity: 0;
  overflow: hidden;
  visibility: hidden;
  flex-shrink: 0;
}

.module-sidebar.collapsed > div {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  overflow: hidden;
}

.sidebar-text {
  transition: opacity 0.2s ease;
}

.module-sidebar.collapsed .sidebar-text {
  opacity: 0;
}

/* ============================================
   TOGGLE ARROW ICON ROTATION
   ============================================ */

.sidebar-toggle-icon {
  transition: transform 0.3s ease;
}

/* ============================================
   SIDEBAR CONTROLS — drag-to-resize + header collapse + reopen pill
   (2026-07-07 redesign, round 2. Round 1's full-height click-to-collapse
   edge rail squatted the boundary users naturally try to DRAG — resizing
   and collapsing interfered. Concerns are now separated, VS Code-style:
     • .sidebar-drag-handle  — the boundary is a PURE resize handle
       (drag 260–560px, snap-collapse when dragged tiny, dbl-click reset);
     • .sidebar-header-collapse — small chevron button in the sidebar
       header does the explicit hide;
     • .sidebar-reopen-pill — compact navy pill pinned top-left of the
       content area while collapsed.
   All injected/wired by static/js/shared-sidebar-resize.js, which
   forwards to each page's legacy .sidebar-collapse-toggle handler.
   The legacy button itself is hidden but kept for the JS contract.)
   ============================================ */
.sidebar-collapse-toggle { display: none !important; } /* legacy control — JS forwards to it */

/* Boundary drag handle — thin, cursor tells the story, gold on hover/drag */
.sidebar-drag-handle {
  position: absolute;
  left: -8px;
  top: 0;
  bottom: 0;
  width: 12px;
  cursor: col-resize;
  z-index: 30;
  background: transparent;
}
.sidebar-drag-handle::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  transform: translateX(-50%);
  background: transparent;
  transition: background 0.15s ease;
}
.sidebar-drag-handle:hover::before { background: var(--oc-gold, #C6904D); }
body.sidebar-resizing { cursor: col-resize; user-select: none; }
body.sidebar-resizing .sidebar-drag-handle::before { background: var(--oc-gold, #C6904D); }
/* Suspend the width transition while dragging so the sidebar tracks the pointer */
.module-sidebar.resizing { transition: none; }
/* No drag handle while collapsed (nothing to resize) */
.module-sidebar.collapsed ~ .module-main-content .sidebar-drag-handle { display: none; }

/* Header collapse button — small, quiet, top-right of the sidebar header */
.sidebar-header-collapse {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.65);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-header-collapse:hover { background: var(--oc-gold, #C6904D); color: #fff; }
.module-sidebar-header { position: relative; }

/* Reopen pill — appears straddling the content's left edge only while
   collapsed (half-outside via the container's overflow-clip-margin, so it
   never overlaps page headings/toolbars at the content's top-left). */
.sidebar-reopen-pill {
  display: none;
  position: absolute;
  left: -15px;
  top: 14px;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--oc-navy, #011638);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 11px;
  z-index: 30;
  box-shadow: 0 2px 8px rgba(1, 22, 56, 0.30);
  transition: background 0.15s ease;
}
.sidebar-reopen-pill:hover { background: var(--oc-gold, #C6904D); }
.module-sidebar.collapsed ~ .module-main-content .sidebar-reopen-pill { display: flex; }

@media (max-width: 768px) {
  .sidebar-drag-handle, .sidebar-header-collapse, .sidebar-reopen-pill { display: none !important; }
}

/* ============================================
   MAIN CONTENT - Expands when sidebar collapses
   ============================================ */

.module-main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--white, #FFFFFF);
  border-radius: var(--radius, 5px);
  box-shadow: var(--shadow-sm);
  /* overflow: clip (not hidden) + a small clip-margin lets the sidebar toggle
     circle hang ~13px off the left edge (macOS straddle) while content beyond
     the margin is still clipped; the inner scroll container clips content too. */
  overflow: clip;
  overflow-clip-margin: 18px;
  min-width: 0;
  transition: all 0.3s ease;
  position: relative;
}

/* ============================================
   MOBILE BEHAVIOR - Sidebar overlays
   ============================================ */

@media (max-width: 768px) {
  /* Mobile sidebar is now a true full-height drawer — previously it
     started 60 px below the top so the page header peeked out above
     and there was a confusing dead band at the top of the overlay
     ("doesn't reach top"). The drawer now covers the full viewport
     and provides its own close button at top-right. */
  .module-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    min-width: 320px;
    max-width: 88vw;
    height: 100vh;
    height: 100dvh;
    z-index: 200;
    transform: translateX(-100%);
    border-radius: 0;
    transition: transform 0.3s ease;
    /* Respect iOS safe-area inset so the close button doesn't sit
       under the camera notch in landscape / split view. */
    padding-top: env(safe-area-inset-top, 0);
  }

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

  /* Don't collapse on mobile - just hide/show */
  .module-sidebar.collapsed {
    width: 320px;
    min-width: 320px;
    transform: translateX(-100%);
  }

  .module-sidebar.collapsed > div {
    opacity: 1;
    pointer-events: all;
  }

  /* Mobile overlay covers the entire viewport now that the sidebar
     covers the header — tapping anywhere outside the drawer closes
     it, including the previously-peeking header band. */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
  }

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

  .module-main-content {
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }
  /* Mobile-first: drop the rounded "card-in-a-page" framing so the
     main content goes edge-to-edge against the viewport. The shadow
     + 5 px radius read as visible gray gutters on phones, making the
     page feel narrow and boxed in. Restore on desktop where the
     framing is desirable. */
  .module-main-content {
    border-radius: 0 !important;
    box-shadow: none !important;
  }
}

/* ============================================
   FLOATING SIDEBAR TRIGGER (FAB)
   Shared button used by every module that has a collapsible sidebar.
   Renders only ≤768 px — desktop sidebars are always visible.
   Modules previously each shipped their own copy of this style; this
   single definition supersedes them so the FAB looks identical
   everywhere. Override colours per-page only if absolutely needed.
   ============================================ */

.sidebar-fab {
  display: none;
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom, 16px));
  left: 12px;
  min-width: 48px;
  min-height: 48px;
  padding: 0 14px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--brand-navy, var(--oc-navy, #011638));
  color: white;
  border: none;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: 99;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, background 0.15s ease;
}
.sidebar-fab:hover { background: var(--brand-gold, #C9905A); }
.sidebar-fab:active { transform: scale(0.93); }
.sidebar-fab i { font-size: 16px; pointer-events: none; }
/* Icon-only variant (no text label) — collapse to a circle. */
.sidebar-fab:not(:has(span)) { padding: 0; width: 48px; }

@media (max-width: 768px) {
  .sidebar-fab { display: inline-flex; }
}

/* ============================================
   RIGHT PANELS (Customer/Draft Order)
   ============================================ */

.module-right-panel {
  position: fixed;
  top: var(--header-height, 60px);
  right: 0;
  bottom: 0;
  width: 90%;
  max-width: 400px;
  z-index: 50;
  background: var(--white, #FFFFFF);
  border-left: 1px solid var(--border, #E7E7E7);
  box-shadow: var(--shadow-xl);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.module-right-panel.open {
  transform: translateX(0);
}

/* ============================================
   OVERLAY for mobile panels
   ============================================ */

.module-overlay {
  position: fixed;
  top: var(--header-height, 60px);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.module-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* ============================================
   SIDEBAR ITEMS & STYLING
   ============================================ */

.module-sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.module-sidebar-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: white;
  margin-bottom: 0.25rem;
}

.module-sidebar-subtitle {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
}

.module-sidebar-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.75rem;
}

.module-sidebar-item {
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
  background: rgba(255, 255, 255, 0.05);
  border-left: 3px solid transparent;
}

.module-sidebar-item:hover {
  background: rgba(255, 255, 255, 0.06);
  border-left-color: var(--amber, #C9905A);
}

.module-sidebar-item.active {
  background: var(--sidebar-active, rgba(201,144,90,0.18));
  border-left-color: var(--amber, #C9905A);
}

/* ============================================
   RESPONSIVE UTILITIES
   ============================================ */

@media (max-width: 640px) {
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 641px) {
  .hide-desktop {
    display: none !important;
  }
}
