/**
 * @file
 * NodeHive Admin Sidebar - Modern SaaS-style navigation.
 *
 * Uses Gin theme CSS variables directly (no intermediate custom properties)
 * so dark mode and accent changes propagate automatically.
 */

/* ==========================================================================
   CSS Custom Properties (layout only — colors use Gin vars directly)
   ========================================================================== */

:root {
  --nh-sidebar-width: 200px;
}

@media (min-width: 1440px) {
  :root {
    --nh-sidebar-width: 240px;
  }
}

@media (min-width: 1920px) {
  :root {
    --nh-sidebar-width: 280px;
  }
}

/* ==========================================================================
   Toolbar Integration — Work alongside Drupal toolbar
   ========================================================================== */

body.nodehive-admin-page.toolbar-horizontal.toolbar-fixed .nh-sidebar {
  top: var(--gin-toolbar-height, 39px);
  height: calc(100vh - var(--gin-toolbar-height, 39px));
}

body.nodehive-admin-page.toolbar-horizontal.toolbar-fixed.gin--secondary-toolbar-frontend .nh-sidebar {
  top: calc(var(--gin-toolbar-height, 39px) + var(--gin-toolbar-secondary-height, 48px));
  height: calc(100vh - var(--gin-toolbar-height, 39px) - var(--gin-toolbar-secondary-height, 48px));
}

/* Disable Gin's vertical toolbar when our sidebar is active */
body.nodehive-admin-page.toolbar-vertical.toolbar-fixed {
  padding-left: 0 !important;
}

body.nodehive-admin-page.toolbar-vertical .toolbar-tray-vertical {
  display: none !important;
}

/* ==========================================================================
   Page Layout Adjustment
   ========================================================================== */

body.nodehive-admin-page .dialog-off-canvas-main-canvas {
  margin-left: var(--nh-sidebar-width) !important;
}

/* ==========================================================================
   Sidebar Container
   ========================================================================== */

.nh-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 501;
  display: flex;
  flex-direction: column;
  width: var(--nh-sidebar-width);
  height: 100vh;
  background: var(--gin-bg-layer, #fff);
  border-right: 1px solid var(--gin-border-color-layer, #d4d4d8);
  overflow: hidden;
}

/* ==========================================================================
   Space Header (preview + stats — replaces the old space dropdown)
   ========================================================================== */

.nh-sidebar__space-header {
  padding: 12px;
  border-bottom: 1px solid var(--gin-border-color-layer, #d4d4d8);
  flex-shrink: 0;
}

.nh-sidebar__space-preview {
  display: block;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 8px;
  border: 1px solid var(--gin-border-color-layer, #d4d4d8);
  aspect-ratio: 16 / 9;
  background: var(--gin-bg-layer2, #f8f8f8);
  position: relative;
}

.nh-sidebar__space-preview::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, var(--gin-bg-layer2, #f0f0f0) 25%, var(--gin-bg-layer, #fafafa) 50%, var(--gin-bg-layer2, #f0f0f0) 75%);
  background-size: 200% 100%;
  animation: nh-shimmer 1.5s ease-in-out infinite;
  z-index: 1;
  transition: opacity 300ms ease;
}

.nh-sidebar__space-preview.is-loaded::before {
  opacity: 0;
  pointer-events: none;
}

@keyframes nh-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.nh-sidebar__space-screenshot {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 300ms ease;
}

.nh-sidebar__space-preview.is-loaded .nh-sidebar__space-screenshot {
  opacity: 1;
}

.nh-sidebar__space-meta {
  padding: 0 8px;
}

.nh-sidebar__space-name {
  display: block;
  font-size: var(--gin-font-size-s, 14px);
  font-weight: 600;
  color: var(--gin-color-text, #2e2e2e);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nh-sidebar__space-name:hover {
  color: var(--gin-color-primary, #003cc5);
}

.nh-sidebar__space-domain {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--gin-color-text-light, #5d5d5d);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}

a.nh-sidebar__space-domain:hover {
  color: var(--gin-color-primary, #003cc5);
}

.nh-sidebar__external-icon {
  flex-shrink: 0;
  opacity: 0.6;
}

a.nh-sidebar__space-domain:hover .nh-sidebar__external-icon {
  opacity: 1;
}

.nh-sidebar__space-stats {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px 0;
  font-size: 11px;
  color: var(--gin-color-text-light, #5d5d5d);
}

.nh-sidebar__space-stat-sep {
  opacity: 0.5;
}

/* ==========================================================================
   Space Tabs (Experience | Content | Settings)
   ========================================================================== */

.nh-sidebar__space-tabs {
  padding: 8px;
  border-bottom: 1px solid var(--gin-border-color-layer, #d4d4d8);
  flex-shrink: 0;
}

/* ==========================================================================
   Navigation Area
   ========================================================================== */

.nh-sidebar__nav {
  flex: 1;
  margin: 0;
  padding: 12px 8px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--gin-border-color-layer, #d4d4d8) transparent;
}

.nh-sidebar__nav::-webkit-scrollbar {
  width: 4px;
}

.nh-sidebar__nav::-webkit-scrollbar-track {
  background: transparent;
}

.nh-sidebar__nav::-webkit-scrollbar-thumb {
  background: var(--gin-border-color-layer, #d4d4d8);
  border-radius: 2px;
}

/* ==========================================================================
   Navigation Sections
   ========================================================================== */

.nh-sidebar__section {
  margin-bottom: 2px;
}

.nh-sidebar__section + .nh-sidebar__section {
  margin-top: 12px;
}

.nh-sidebar__section-header {
  padding: 8px 12px 4px;
}

.nh-sidebar__section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gin-color-text-light, #5d5d5d);
  opacity: 0.7;
}

.nh-sidebar__section-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nh-sidebar__item {
  margin-bottom: 2px;
}

/* ==========================================================================
   Navigation Links
   ========================================================================== */

.nh-sidebar__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--gin-border-radius, 8px);
  color: var(--gin-color-text-light, #5d5d5d);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  transition: all 150ms ease;
}

.nh-sidebar__link:hover {
  color: var(--gin-color-text, #2e2e2e);
  background: var(--gin-bg-item-hover, rgba(0, 0, 0, 0.04));
}

/* Active link — uses Gin primary color with stronger background */
.nh-sidebar__link.is-active {
  color: var(--gin-color-primary, #003cc5);
  background: var(--gin-color-primary-light, rgba(0, 60, 197, 0.08));
  font-weight: 600;
}

.nh-sidebar__link.is-active .nh-sidebar__icon {
  color: var(--gin-color-primary, #003cc5);
}

/* Active indicator bar — Gin primary accent */
.nh-sidebar__link.is-active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 24px;
  background: var(--gin-color-primary, #003cc5);
  border-radius: 0 2px 2px 0;
}

/* ==========================================================================
   Icons and Labels
   ========================================================================== */

.nh-sidebar__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: inherit;
}

.nh-sidebar__icon svg {
  width: 20px;
  height: 20px;
}

.nh-sidebar__label {
  opacity: 1;
}

/* ==========================================================================
   Sidebar Footer
   ========================================================================== */

.nh-sidebar__footer {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 8px;
  border-top: 1px solid var(--gin-border-color-layer, #d4d4d8);
  flex-shrink: 0;
}

.nh-sidebar__settings {
  margin-bottom: 4px;
}

/* ==========================================================================
   User Avatar
   ========================================================================== */

.nh-sidebar__user {
  margin-bottom: 4px;
}

.nh-sidebar__user-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: var(--gin-bg-item-hover, rgba(0, 0, 0, 0.04));
}

.nh-sidebar__user-avatar svg {
  width: 16px;
  height: 16px;
}

.nh-sidebar__user-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ==========================================================================
   Dark Mode Support (via Gin)
   ========================================================================== */

/* All colors reference Gin CSS variables directly (--gin-*), which Gin
   redefines when dark mode is active. No overrides needed here. */

/* ==========================================================================
   Smooth Page Transitions
   ========================================================================== */

body.nodehive-admin-page .region-content {
  animation: fadeIn 200ms ease;
}

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