/* ==========================================================================
   SIDEBAR NAVIGATION + SEARCH OVERLAY
   ========================================================================== */

/* --------------------------------------------------------------------------
   SIDEBAR - collapsed 68px, expands 260px on hover
   -------------------------------------------------------------------------- */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 68px;
  height: 100vh;
  background: #0f172a;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  z-index: 210;
  overflow: visible;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar:hover {
  width: 360px;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
}

/* Clip inner content so it doesn't bleed */
.sidebar-top,
.sidebar-bottom {
  overflow: hidden;
}

.sidebar-nav {
  overflow: hidden;
}

/* Show labels when a sub-menu is open */
.sidebar:has(.nav-item-group.open) .nav-item span,
.sidebar:has(.nav-item-group.open) .sub-arrow {
  opacity: 1;
}

.sidebar:has(.nav-item-group.open) .sidebar-logo-full {
  opacity: 1;
}

.sidebar:has(.nav-item-group.open) .sidebar-logo-icon {
  opacity: 0;
  width: 0;
  margin: 0;
}

/* Allow sidebar-nav to scroll when expanded */
.sidebar:has(.nav-item-group.open) .sidebar-nav {
  overflow-y: auto;
  overflow-x: hidden;
}

/* Push page content right — only when sidebar exists (not on auth pages) */
body:has(.sidebar) {
  padding-left: 68px;
  transition: padding-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --------------------------------------------------------------------------
   SIDEBAR BRAND
   -------------------------------------------------------------------------- */

.sidebar-top {
  padding: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 52px;
  text-decoration: none;
  overflow: hidden;
}

.sidebar-logo-icon {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 0.5rem;
  transition: opacity 0.2s;
}

.sidebar-logo-full {
  height: 40px;
  width: 0;
  margin-left: 0;
  flex-shrink: 0;
  opacity: 0;
  overflow: hidden;
  transition: opacity 0.2s 0.05s, width 0.2s, margin 0.2s;
}

.sidebar:hover .sidebar-logo-full {
  opacity: 1;
  width: auto;
  margin-left: 0.75rem;
}

.sidebar:hover .sidebar-logo-icon {
  opacity: 0;
  width: 0;
  margin: 0;
  overflow: hidden;
}

.sidebar-brand:hover {
  opacity: 0.85;
}

/* --------------------------------------------------------------------------
   NAV ITEMS
   -------------------------------------------------------------------------- */

.sidebar-nav {
  flex: 1;
  padding: 0.5rem;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-bottom {
  padding: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  color: #94a3b8;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  border: none;
  background: transparent;
  border-radius: 0.5rem;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}

.nav-item:hover {
  color: #f1f5f9;
  background: rgba(255, 255, 255, 0.06);
}

.nav-item i:first-child {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.nav-item span {
  opacity: 0;
  transition: opacity 0.15s;
}

.sidebar:hover .nav-item span {
  opacity: 1;
}

/* Sub-menu arrow */
.sub-arrow {
  margin-left: auto;
  font-size: 0.6rem;
  transition: transform 0.2s;
  opacity: 0;
}

.sidebar:hover .sub-arrow {
  opacity: 1;
}

.nav-item-group.open .sub-arrow {
  transform: rotate(90deg);
}

/* Sidebar badge (cart count) - always visible */
.sidebar-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: #ef4444;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1 !important;
  flex-shrink: 0;
}

/* When collapsed, position badge as overlay on the icon */
.sidebar:not(:hover) .sidebar-badge {
  position: absolute;
  top: 0.25rem;
  left: 1.85rem;
}

/* --------------------------------------------------------------------------
   SUB-MENUS (inline expand when sidebar is open)
   -------------------------------------------------------------------------- */

.sub-menu {
  display: none;
  padding-left: 0.5rem;
  margin-top: 0.15rem;
}

/* Sub-menus only show when clicked open AND sidebar is wide enough */
.sidebar:hover .nav-item-group.open .sub-menu:not(.cart-flyout),
.sidebar:has(.nav-item-group.open) .nav-item-group.open .sub-menu:not(.cart-flyout) {
  display: block;
}

.sidebar:hover .cart-group.open .cart-flyout,
.sidebar:has(.cart-group.open) .cart-group.open .cart-flyout {
  display: flex;
}

.sub-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.75rem 0.45rem 2.5rem;
  color: #64748b;
  font-size: 0.8rem;
  text-decoration: none;
  border-radius: 0.375rem;
  transition: all 0.15s;
  white-space: nowrap;
}

.sub-item:hover {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.04);
}

.sub-item.active {
  color: #3b82f6;
}

.sub-item i {
  width: 16px;
  text-align: center;
  font-size: 0.75rem;
  color: #475569;
}

.sub-item:hover i {
  color: #3b82f6;
}

.sub-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.04);
  margin: 0.375rem 1rem 0.375rem 2.5rem;
}

/* Language label */
.lang-label {
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* Theme toggle icons */
.theme-label {
  font-weight: 500;
}

[data-theme-icon="light"] {
  display: inline;
}
[data-theme-icon="dark"] {
  display: none;
}
html[data-theme="light"] [data-theme-icon="light"] {
  display: none;
}
html[data-theme="light"] [data-theme-icon="dark"] {
  display: inline;
}

/* --------------------------------------------------------------------------
   CART FLYOUT DROPDOWN
   -------------------------------------------------------------------------- */

.cart-flyout {
  max-height: 400px;
  flex-direction: column;
  padding-left: 0 !important;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: 0.25rem;
}

/* When cart sub-menu is shown, use flex instead of block */
.cart-group.open .cart-flyout {
  display: flex;
}

.cart-flyout #cartItems {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  max-height: 300px;
}

.cart-flyout-footer {
  padding: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* Cart items */
.cart-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: 0.5rem;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.cart-item:last-child {
  border-bottom: none;
}

.cart-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.cart-item-image {
  width: 44px;
  height: 44px;
  border-radius: 0.375rem;
  object-fit: cover;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.cart-item-details {
  flex: 1;
  min-width: 0;
}

.cart-item-details .item-name {
  font-size: 0.78rem;
  font-weight: 500;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.2rem;
}

.cart-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.cart-item-details .item-price {
  font-size: 0.78rem;
  color: #3b82f6;
  font-weight: 600;
}

/* Quantity controls */
.cart-qty-controls {
  display: flex;
  align-items: center;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.375rem;
  overflow: hidden;
}

.cart-qty-controls .qty-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.cart-qty-controls .qty-btn:hover {
  background: #3b82f6;
  color: #fff;
}

.cart-qty-controls .qty-value {
  min-width: 24px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #e2e8f0;
}

.cart-remove-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  background: transparent;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.cart-remove-btn:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.cart-empty {
  text-align: center;
  padding: 1.5rem 1rem;
  color: #64748b;
  font-size: 0.85rem;
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: #e2e8f0;
}

.cart-total-amount {
  font-weight: 700;
  color: #f1f5f9;
  font-size: 1.05rem;
}

.cart-checkout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 1rem;
  background: #3b82f6;
  color: #fff;
  text-align: center;
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: 0.5rem;
  transition: background 0.2s;
  text-decoration: none;
}

.cart-checkout-btn:hover {
  background: #2563eb;
  color: #fff;
}

/* Cart quantity input (legacy) */
.cart-item-quantity {
  width: 50px;
  padding: 0.25rem 0.375rem;
  margin-top: 0.25rem;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.25rem;
  color: #e2e8f0;
  font-size: 0.75rem;
  text-align: center;
  -moz-appearance: textfield;
}

.cart-item-quantity::-webkit-outer-spin-button,
.cart-item-quantity::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.cart-item-quantity:focus {
  outline: none;
  border-color: #3b82f6;
}

/* --------------------------------------------------------------------------
   SEARCH OVERLAY
   -------------------------------------------------------------------------- */

.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 18vh;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

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

.search-overlay-inner {
  width: 100%;
  max-width: 640px;
  padding: 0 1.5rem;
}

.search-overlay-form {
  display: flex;
  align-items: center;
  background: #1e293b;
  border: 2px solid rgba(59, 130, 246, 0.4);
  border-radius: 1rem;
  padding: 0 1.25rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transition: border-color 0.2s;
}

.search-overlay-form:focus-within {
  border-color: #3b82f6;
}

.search-overlay-icon {
  color: #64748b;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.search-overlay-input {
  flex: 1;
  padding: 1rem 1rem;
  background: transparent;
  border: none;
  font-size: 1.15rem;
  color: #f1f5f9;
  font-family: inherit;
}

.search-overlay-input::placeholder {
  color: #475569;
}

.search-overlay-input:focus {
  outline: none;
}

.search-overlay-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.06);
  border: none;
  border-radius: 0.375rem;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.search-overlay-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
}

.search-hint {
  text-align: center;
  margin-top: 0.75rem;
  color: #475569;
  font-size: 0.8rem;
}

/* --------------------------------------------------------------------------
   MOBILE BOTTOM BAR
   -------------------------------------------------------------------------- */

.mobile-bar {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* --------------------------------------------------------------------------
   RESPONSIVE
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }

  .sidebar:hover {
    width: 280px;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.5);
  }

  .sidebar.mobile-open .nav-item span {
    opacity: 1;
  }

  .sidebar.mobile-open .sub-arrow {
    opacity: 1;
  }

  .sidebar.mobile-open .sidebar-logo-full {
    opacity: 1;
  }

  .sidebar.mobile-open .sidebar-logo-icon {
    opacity: 0;
    width: 0;
    margin: 0;
  }

  /* Show sub-menus in mobile open state */
  .sidebar.mobile-open .nav-item-group.open .sub-menu {
    display: block !important;
  }

  body:has(.sidebar) {
    padding-left: 0;
    padding-bottom: 60px;
  }

  .mobile-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: #0f172a;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 200;
    align-items: center;
    justify-content: space-around;
    padding: 0 0.5rem;
  }

  .mobile-bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.4rem 0.5rem;
    color: #64748b;
    font-size: 0.65rem;
    font-weight: 500;
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    position: relative;
    transition: color 0.15s;
  }

  .mobile-bar-item:hover,
  .mobile-bar-item:active {
    color: #3b82f6;
  }

  .mobile-bar-item i {
    font-size: 1.15rem;
  }

  .mobile-bar-item span {
    max-width: 56px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-badge {
    position: absolute;
    top: 0;
    right: 0.15rem;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: #ef4444;
    color: #fff;
    font-size: 0.55rem;
    font-weight: 700;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .cart-flyout {
    width: 100%;
  }

  .search-overlay {
    padding-top: 12vh;
  }

  .search-overlay-inner {
    padding: 0 1rem;
  }
}

/* --------------------------------------------------------------------------
   LIGHT THEME overrides
   -------------------------------------------------------------------------- */

/* Sidebar stays navy in both themes */

html[data-theme="light"] .search-overlay {
  background: rgba(255, 255, 255, 0.8);
}

html[data-theme="light"] .search-overlay-form {
  background: #fff;
  border-color: #3b82f6;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

html[data-theme="light"] .search-overlay-input {
  color: #1e293b;
}

html[data-theme="light"] .search-overlay-input::placeholder {
  color: #94a3b8;
}

html[data-theme="light"] .search-overlay-close {
  background: #f1f5f9;
  color: #64748b;
}

html[data-theme="light"] .search-overlay-close:hover {
  background: #e2e8f0;
  color: #1e293b;
}

html[data-theme="light"] .search-hint {
  color: #94a3b8;
}

/* Mobile bar light mode */
html[data-theme="light"] .mobile-bar {
  background: #fff;
  border-top-color: #e2e8f0;
}

html[data-theme="light"] .mobile-bar-item {
  color: #94a3b8;
}

html[data-theme="light"] .mobile-bar-item:hover,
html[data-theme="light"] .mobile-bar-item:active {
  color: #3b82f6;
}
