/**
 * Shippy Global Companion Shell Stylesheet
 * 
 * Implements:
 * - Minimized launcher positioning (never blocks controls)
 * - Peek panel styling (small, temporary)
 * - Expanded drawer styling (desktop docking, mobile bottom sheet)
 * - Safe zone rules (nav, filters, buttons, modals protected)
 * - Responsive behavior (<768px = mobile)
 */

/* Container for Shippy elements */
:root {
  --shippy-topbar-offset: 0px;
  --shippy-desktop-panel-width: clamp(320px, 32vw, 380px);
  --shippy-mobile-sheet-height: min(65vh, calc(100dvh - 96px));
}

#shippy-global-container {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 10;
  font-family: system-ui, -apple-system, sans-serif;
  color-scheme: dark;
  pointer-events: none;
}

/* ========================================
   MINIMIZED LAUNCHER (Small persistent pill)
   ======================================== */

.shippy-launcher {
  /* Position: bottom-right corner, persistent */
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 10100;
  
  /* Size: small pill, 50px */
  width: 50px;
  height: 50px;
  border-radius: 50%;
  
  /* Styling */
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.8);
  color: #e2e8f0;
  cursor: pointer;
  
  /* Typography */
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  
  /* Effects */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 200ms ease-out;
  
  /* Accessibility */
  border: none;
  outline-offset: 2px;
  pointer-events: auto;
}

.shippy-launcher:hover:not([disabled]) {
  background: rgba(15, 23, 42, 0.95);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  transform: scale(1.05);
}

.shippy-launcher:focus-visible {
  outline: 2px solid #60a5fa;
}

.shippy-launcher[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.shippy-launcher__icon {
  display: block;
  line-height: 1;
}

.shippy-launcher__badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ef4444;
  color: white;
  font-size: 11px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(15, 23, 42, 0.9);
}

/* ========================================
   PANELS (Peek and Expanded)
   ======================================== */

.shippy-panel {
  position: fixed;
  z-index: 10000;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  color: #e2e8f0;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  pointer-events: auto;
}

/* ========================================
   PEEK PANEL (Small temporary readout)
   ======================================== */

.shippy-panel--peek {
  bottom: 70px;
  right: 16px;
  width: 320px;
  max-height: 400px;
  animation: slideUp 200ms ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
   EXPANDED DRAWER (Full companion panel)
   ======================================== */

.shippy-panel--expanded {
  animation: slideIn 250ms ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Desktop: Docked to right side, reserves space */
.shippy-panel--expanded.shippy-panel--desktop {
  bottom: 0;
  right: 0;
  top: var(--shippy-topbar-offset);
  width: var(--shippy-desktop-panel-width);
  height: calc(100dvh - var(--shippy-topbar-offset));
  max-height: calc(100dvh - var(--shippy-topbar-offset));
  max-width: none;
  border-radius: 0;
  border-left: 1px solid rgba(148, 163, 184, 0.2);
  
  /* Flexbox for proper layout */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10099;
  position: fixed;
}

/* Mobile: Bottom sheet, 60-70% height */
.shippy-panel--expanded.shippy-panel--mobile {
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-height: var(--shippy-mobile-sheet-height);
  max-width: none;
  border-radius: 12px 12px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUpMobile 250ms ease-out;
  z-index: 10099;
  position: fixed;
}

@keyframes slideUpMobile {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile drag handle */
.shippy-panel--mobile::before {
  content: '';
  display: block;
  height: 4px;
  background: rgba(148, 163, 184, 0.4);
  border-radius: 2px;
  margin: 8px auto;
  width: 40px;
}

/* ========================================
   PANEL HEADER
   ======================================== */

.shippy-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  gap: 8px;
  
  /* Sticky header for expanded state */
  position: sticky;
  top: 0;
  background: rgba(15, 23, 42, 0.95);
  z-index: 10500;
  flex-shrink: 0;
  pointer-events: auto;
}

.shippy-panel__title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #e2e8f0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.shippy-panel__controls {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.shippy-panel__btn-minimize,
.shippy-panel__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 6px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  font-size: 16px;
  transition: all 150ms ease-out;
}

.shippy-panel__btn-minimize:hover,
.shippy-panel__close:hover {
  background: rgba(148, 163, 184, 0.1);
  color: #e2e8f0;
}

.shippy-panel__btn-minimize:focus-visible,
.shippy-panel__close:focus-visible {
  outline: 2px solid #60a5fa;
}

/* ========================================
   PANEL CONTENT
   ======================================== */

.shippy-panel__content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  min-height: 0;
  
  /* Smooth scrolling */
  scroll-behavior: smooth;
}

.shippy-panel--peek .shippy-panel__content {
  padding: 12px 16px;
  max-height: 350px;
  overflow-y: auto;
}

.shippy-panel__summary {
  margin: 0 0 12px;
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.5;
}

.shippy-panel__section {
  margin-bottom: 16px;
}

.shippy-panel__section:last-child {
  margin-bottom: 0;
}

.shippy-panel__section-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: #94a3b8;
  letter-spacing: 0.5px;
}

.shippy-panel__text {
  margin: 0;
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.5;
}

.shippy-panel__bullets {
  margin: 0;
  padding-left: 20px;
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.6;
}

.shippy-panel__bullets li {
  margin-bottom: 6px;
}

.shippy-panel__bullets li:last-child {
  margin-bottom: 0;
}

/* ========================================
   PANEL FOOTER / BUTTONS
   ======================================== */

.shippy-panel__footer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  background: rgba(15, 23, 42, 0.5);
}

.shippy-panel__btn {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 6px;
  background: transparent;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all 150ms ease-out;
  outline-offset: 2px;
}

.shippy-panel__btn:hover {
  background: rgba(148, 163, 184, 0.1);
  border-color: rgba(148, 163, 184, 0.5);
  color: #e2e8f0;
}

.shippy-panel__btn--primary {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.4);
  color: #60a5fa;
}

.shippy-panel__btn--primary:hover {
  background: rgba(59, 130, 246, 0.3);
  border-color: rgba(59, 130, 246, 0.6);
  color: #93c5fd;
}

.shippy-panel__btn:focus-visible {
  outline: 2px solid #60a5fa;
}

/* ========================================
   INPUT / INTERACTION AREA (sticky at bottom)
   ======================================== */

.shippy-panel__section:has(.shippy-panel__input) {
  position: sticky;
  bottom: 0;
  background: rgba(15, 23, 42, 0.95);
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  margin-bottom: 0;
  z-index: 99;
}

.shippy-panel__input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 6px;
  background: rgba(30, 41, 59, 0.6);
  color: #e2e8f0;
  font-size: 13px;
  font-family: inherit;
  transition: all 150ms ease-out;
}

.shippy-panel__input::placeholder {
  color: rgba(148, 163, 184, 0.5);
}

.shippy-panel__input:focus {
  outline: none;
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(59, 130, 246, 0.5);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.shippy-panel__btn-ask {
  padding: 8px 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 6px;
  background: rgba(148, 163, 184, 0.1);
  color: #94a3b8;
  cursor: pointer;
  font-size: 14px;
  transition: all 150ms ease-out;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
}

.shippy-panel__btn-ask:hover {
  background: rgba(148, 163, 184, 0.15);
  color: #cbd5e1;
}

.shippy-panel__btn-ask:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

.shippy-panel__btn-ask:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========================================
   SAFE ZONES (Never covered by Shippy)
   ======================================== */

/* When Shippy expanded on desktop, reserve space on right */
body.shippy-shell-expanded-desktop #app.content {
  padding-right: calc(var(--shippy-desktop-panel-width) + 24px);
}

body.shippy-shell-expanded-desktop .topbar {
  padding-right: 16px;
}

body.shippy-shell-expanded-mobile #app.content {
  padding-bottom: calc(var(--shippy-mobile-sheet-height) + 24px);
}

/* Modal-safe: Ensure modals stay on top */
[role="dialog"][open],
.modal[open],
.bol-detail-panel {
  z-index: 10050; /* Above Shippy but visible */
}

/* Protect nav */
.topbar {
  z-index: 10200; /* Above Shippy launcher */
}

/* Protect filters and controls */
.track-filters,
.search-box,
[data-search],
[data-filter] {
  z-index: 10150;
}

/* ========================================
   MOBILE OPTIMIZATIONS (<768px)
   ======================================== */

@media (max-width: 768px) {
  .shippy-launcher {
    bottom: 12px;
    right: 12px;
    width: 48px;
    height: 48px;
    font-size: 22px;
  }
  
  .shippy-panel--peek {
    bottom: 64px;
    right: 12px;
    width: 100vw;
    max-width: calc(100vw - 24px);
    left: 12px;
    right: auto;
  }
  
  .shippy-panel--expanded.shippy-panel--desktop {
    /* Switch to mobile behavior */
    display: none;
  }
  
  .shippy-panel--mobile {
    display: flex;
  }
  
  .shippy-panel__content {
    padding: 12px 16px;
  }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

.shippy-panel {
  /* Ensure text is readable */
  color: #e2e8f0;
}

.shippy-panel__title,
.shippy-panel__section-title {
  color: #cbd5e1;
}

/* Focus visible for keyboard navigation */
.shippy-launcher:focus-visible,
.shippy-panel__btn:focus-visible,
.shippy-panel__close:focus-visible,
.shippy-panel__btn-minimize:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .shippy-launcher,
  .shippy-panel,
  .shippy-panel__btn {
    animation: none !important;
    transition: none !important;
  }
}

/* ========================================
   SCROLLBAR STYLING
   ======================================== */

.shippy-panel__content::-webkit-scrollbar {
  width: 6px;
}

.shippy-panel__content::-webkit-scrollbar-track {
  background: transparent;
}

.shippy-panel__content::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: 3px;
}

.shippy-panel__content::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.5);
}
