/**
 * SeymourOS Dashboard - Sidebar Styles
 * Consolidated from sidebar-tablet.css and inline styles
 */

/* Sidebar variables */
:root {
  --sidebar-width: 260px;
}

/* Sidebar base styles */
.dashboard-sidebar {
  --sidebar-width: 260px;
  position: fixed;
  top: 56px;
  left: 0;
  width: 260px;
  height: calc(100vh - 56px);
  background: var(--color-bg-secondary);
  border-right: 1px solid var(--color-border);
  z-index: 90;
  transition: transform 400ms cubic-bezier(0.4, 0, 0.2, 1), width 400ms cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  padding: var(--space-4);
}

/* Sidebar collapsed */
.sidebar-collapsed .dashboard-sidebar {
  transform: translateX(-100%);
}

/* Sidebar right */
.sidebar-right .dashboard-sidebar {
  left: auto;
  right: 0;
  border-right: none;
  border-left: 1px solid var(--color-border);
}

.sidebar-right.sidebar-collapsed .dashboard-sidebar {
  transform: translateX(100%);
}

/* Main content margins when sidebar is shown/hidden */
.sidebar-collapsed .dashboard-main {
  margin-left: 0;
  margin-right: 0;
}

.sidebar-right .dashboard-main {
  margin-left: 0;
  margin-right: 260px;
}

/* Smooth transition for main content margins */
.dashboard-main {
  transition: margin-left 400ms cubic-bezier(0.4, 0, 0.2, 1), 
              margin-right 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Slower transition during auto-fit */
.sidebar-auto-fitting ~ .dashboard-main,
.dashboard-container:has(.sidebar-auto-fitting) .dashboard-main {
  transition: margin-left 800ms cubic-bezier(0.16, 1, 0.3, 1), 
              margin-right 800ms cubic-bezier(0.16, 1, 0.3, 1) !important;
}

/* Sidebar nav */
.sidebar-nav {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav-item {
  margin-bottom: var(--space-2);
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  color: var(--color-text);
  text-decoration: none;
  transition: all 200ms ease;
  position: relative;
}

.sidebar-nav-link:hover {
  background: var(--color-bg-tertiary);
}

.sidebar-nav-link.active {
  background: var(--color-primary);
  color: var(--color-primary-text);
}

.sidebar-nav-icon {
  font-size: 20px;
  flex-shrink: 0;
}

/* Sidebar footer */
.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

/* Hamburger toggle button */
.sidebar-toggle {
  position: fixed !important;
  top: calc(56px + 25px) !important;
  width: 48px !important;
  height: 48px !important;
  border-radius: 50% !important;
  background: var(--color-bg-secondary) !important;
  border: 1px solid var(--color-border) !important;
  box-shadow: var(--shadow-md) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  z-index: 1000 !important;
  transition: left 400ms cubic-bezier(0.4, 0, 0.2, 1), 
              right 400ms cubic-bezier(0.4, 0, 0.2, 1),
              background-color 200ms ease,
              transform 200ms ease !important;
  transform: none !important;
  left: calc(var(--sidebar-width, 260px) - 24px) !important;
  right: auto !important;
}

/* Toggle button hover */
.sidebar-toggle:hover {
  background: var(--color-primary) !important;
  color: var(--color-primary-text) !important;
  transform: none !important;
}

/* Toggle button smooth slide during auto-fit */
.dashboard-container:has(.sidebar-auto-fitting) .sidebar-toggle {
  transition: left 800ms cubic-bezier(0.16, 1, 0.3, 1), 
              right 800ms cubic-bezier(0.16, 1, 0.3, 1) !important;
}

/* Position when sidebar is open - LEFT */
.dashboard-container:not(.sidebar-right):not(.sidebar-collapsed) ~ .sidebar-toggle,
.dashboard-container:not(.sidebar-right):not(.sidebar-collapsed) .sidebar-toggle {
  left: calc(var(--sidebar-width, 260px) - 24px) !important;
  right: auto !important;
}

/* Position when sidebar is open - RIGHT */
.dashboard-container.sidebar-right:not(.sidebar-collapsed) ~ .sidebar-toggle,
.dashboard-container.sidebar-right:not(.sidebar-collapsed) .sidebar-toggle {
  left: auto !important;
  right: calc(var(--sidebar-width, 260px) - 24px) !important;
}

/* Position when sidebar is collapsed - LEFT */
.dashboard-container.sidebar-collapsed:not(.sidebar-right) ~ .sidebar-toggle,
.dashboard-container.sidebar-collapsed:not(.sidebar-right) .sidebar-toggle {
  left: 10px !important;
  right: auto !important;
}

/* Position when sidebar is collapsed - RIGHT */
.dashboard-container.sidebar-right.sidebar-collapsed ~ .sidebar-toggle,
.dashboard-container.sidebar-right.sidebar-collapsed .sidebar-toggle {
  left: auto !important;
  right: 10px !important;
}

/* Resize grip */
.sidebar-resize-grip {
  position: fixed !important;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--color-text-secondary);
  background-color: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 6px 4px;
  z-index: 1000;
  cursor: col-resize;
  box-shadow: var(--shadow-md);
  width: 16px;
  text-align: center;
  user-select: none;
  transition: opacity 200ms;
  box-sizing: border-box !important;
  margin: 0 !important;
  touch-action: none;
}

/* Hide grip when collapsed */
.sidebar-collapsed .sidebar-resize-grip {
  opacity: 0;
  pointer-events: none;
}

.sidebar-resize-grip:hover,
.sidebar-resize-grip.active {
  background-color: var(--color-primary);
  color: var(--color-primary-text);
}

/* Double-click pulse effect */
@keyframes gripPulse {
  0% { 
    transform: translateY(-50%) scale(1);
    box-shadow: var(--shadow-md);
  }
  50% { 
    transform: translateY(-50%) scale(1.2);
    box-shadow: 0 0 20px rgba(var(--color-primary-rgb), 0.4);
    background-color: var(--color-primary);
    color: var(--color-primary-text);
  }
  100% { 
    transform: translateY(-50%) scale(1);
    box-shadow: var(--shadow-md);
  }
}

.sidebar-resize-grip:active {
  animation: gripPulse 0.3s ease;
}

/* Magical glow during auto-fit */
.sidebar-auto-fitting {
  box-shadow: 0 0 30px rgba(var(--color-primary-rgb), 0.3);
  /* Include BOTH transitions for smooth animation */
  transition: width 1000ms cubic-bezier(0.16, 1, 0.3, 1), 
              box-shadow 800ms cubic-bezier(0.16, 1, 0.3, 1),
              transform 1000ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Disable transitions during resize for instant feedback */
.dashboard-container.resizing .sidebar-toggle {
  transition: none !important;
}

.dashboard-container.resizing .sidebar-resize-grip {
  transition: none !important;
}

/* Conveyor belt animation for sidebar swap */
@keyframes conveyorLeftToRight {
  0% {
    left: 0;
    opacity: 1;
  }
  49% {
    left: calc(var(--sidebar-width, 260px) * -1);
    opacity: 0;
  }
  51% {
    left: auto;
    right: calc(var(--sidebar-width, 260px) * -1);
    opacity: 0;
  }
  100% {
    left: auto;
    right: 0;
    opacity: 1;
  }
}

@keyframes conveyorRightToLeft {
  0% {
    right: 0;
    left: auto;
    opacity: 1;
  }
  49% {
    right: calc(var(--sidebar-width, 260px) * -1);
    left: auto;
    opacity: 0;
  }
  51% {
    right: auto;
    left: calc(var(--sidebar-width, 260px) * -1);
    opacity: 0;
  }
  100% {
    right: auto;
    left: 0;
    opacity: 1;
  }
}

/* Apply conveyor belt animation during swap */
.dashboard-container.sidebar-swapping .dashboard-sidebar {
  animation-duration: 800ms;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  animation-fill-mode: both;
  overflow: hidden;
  pointer-events: none;
}

.dashboard-container.conveyor-left-to-right .dashboard-sidebar {
  animation-name: conveyorLeftToRight;
}

.dashboard-container.conveyor-right-to-left .dashboard-sidebar {
  animation-name: conveyorRightToLeft;
}

.dashboard-container.sidebar-swapping .dashboard-main {
  transition: margin 800ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Mobile sidebar overrides (≤ 768px) ----------
 * On narrow viewports the sidebar behaves like a slide-in drawer rather
 * than a fixed column. dashboard-sidebar.js now defaults the container
 * to .sidebar-collapsed at mobile widths so content uses the full width
 * by default; the user opens the drawer via the existing toggle button.
 */
@media (max-width: 768px) {
  /* Hide the resize grip on mobile — pointer-precision UX, not touch. */
  .sidebar-resize-grip { display: none !important; }

  /* Set the drawer width up front (open AND collapsed) so only transform
   * animates during the slide. Width-change-during-transform was causing
   * the "jumping" effect — the sidebar visually grew from 260px to 320px
   * at the same time as it slid in. Sliding-only reads as smooth.
   *
   * Force the transform transition explicitly on mobile in case any other
   * rule (e.g. .sidebar-animating, swap conveyor) overrides it. Without
   * this !important the slide silently fell back to instant on iPhone.
   *
   * Reserve ~50px of top padding so the floating X close button (top: 10px,
   * height: 36px) doesn't collide with the first row of sidebar content
   * (search input + Clear button). */
  .dashboard-sidebar {
    width: min(85vw, 320px) !important;
    transition: transform 400ms cubic-bezier(0.4, 0, 0.2, 1) !important;
    padding-top: 56px !important;
  }
  body.sidebar-drawer-open .dashboard-sidebar {
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.4);
  }

  /* Pin the toggle button to a predictable corner regardless of sidebar
   * state — none of the desktop "position toggle based on sidebar width"
   * math works once the sidebar is a transient drawer. The 70px offset
   * accounts for the admin navbar's actual height (overridden inline to
   * 70px on admin pages) plus its drop shadow; +20px gap below it. */
  .sidebar-toggle {
    left: 10px !important;
    right: auto !important;
    top: calc(70px + 20px) !important;
    width: 40px !important;
    height: 40px !important;
  }
  .dashboard-container.sidebar-right .sidebar-toggle {
    left: auto !important;
    right: 10px !important;
  }

  /* In-drawer close button — appended by dashboard-sidebar.js. Sits top-
   * right inside the sidebar and dismisses the drawer with the same slide
   * animation as the toggle. Desktop hides it (the X is mobile-only since
   * desktop already has the persistent toggle button outside the sidebar). */
  .sidebar-drawer-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 2;
  }
  .sidebar-drawer-close:hover { background: var(--color-primary); color: var(--color-primary-text); }
}
@media (min-width: 769px) {
  .sidebar-drawer-close { display: none; }
}