/**
 * Sidebar Layout Component
 * Features: collapsible, nested navigation, user section
 * Theming: matches concreteinfo.in light sidebar style
 *
 * @author Amit Haridas, ConcreteInfo
 */

/* ============================================
   SIDEBAR BASE — light theme
   ============================================ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width, 264px);
  height: 100vh;
  background-color: var(--bg-primary, #ffffff);
  border-right: 1px solid var(--border-subtle, #e3e3e3);
  display: flex;
  flex-direction: column;
  z-index: var(--z-fixed, 1030);
  transition: transform var(--transition-normal, 250ms ease);
  overflow: hidden;
}

/* ============================================
   SIDEBAR HEADER
   ============================================ */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-4, 1rem) var(--spacing-5, 1.25rem);
  min-height: var(--header-height, 64px);
  border-bottom: 1px solid var(--border-subtle, #e3e3e3);
  background-color: var(--bg-primary, #ffffff);
}

.sidebar-logo {
  height: 2.5rem;
  width: auto;
}

.sidebar-close {
  display: none;
  padding: var(--spacing-2, 0.5rem);
  border-radius: var(--radius-md, 0.5rem);
  color: var(--color-gray-500, #6b7280);
  background: var(--bg-tertiary, #f3f4f6);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast, 150ms);
}

.sidebar-close:hover {
  background-color: var(--bg-secondary, #e5e7eb);
  color: var(--text-primary, #1f2937);
}

/* ============================================
   SIDEBAR USER
   ============================================ */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--spacing-3, 0.75rem);
  padding: var(--spacing-4, 1rem) var(--spacing-5, 1.25rem);
  border-bottom: 1px solid var(--border-subtle, #f0f0f0);
  background-color: var(--bg-secondary, #fafafa);
  color: var(--color-gray-500, #6b7280);
}

.sidebar-user i {
  color: var(--color-brand);
  font-size: 1.5rem;
}

.sidebar-user .fw-semibold {
  color: var(--text-primary, #1f2937);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm, 0.875rem);
}

.sidebar-user small {
  color: var(--text-tertiary, #9a9696);
  font-size: var(--font-size-xs, 0.75rem);
}

.sidebar-user .ms-2 {
  margin-left: 0.5rem;
}

/* ============================================
   SIDEBAR NAVIGATION
   ============================================ */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-3, 0.75rem) 0;
  display: flex;
  flex-direction: column;
}

/* Custom scrollbar — orange thumb matching concreteinfo.in */
.sidebar-nav::-webkit-scrollbar {
  width: 0.25rem;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: var(--bg-tertiary, #f3f4f6);
  border-radius: 9999px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--color-brand);
  border-radius: 9999px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: var(--color-brand-dark);
}

/* Firefox scrollbar */
.sidebar-nav {
  scrollbar-width: thin;
  scrollbar-color: var(--color-brand) var(--bg-tertiary, #f3f4f6);
}

/* Navigation Section */
.sidebar-section {
  margin-bottom: 0;
}

.sidebar-section-title {
  display: flex;
  align-items: center;
  gap: var(--spacing-2, 0.5rem);
  padding: var(--spacing-3, 0.75rem) var(--spacing-5, 1.25rem) var(--spacing-2, 0.5rem);
  font-size: 0.6875rem;
  font-weight: var(--font-weight-semibold);
  color: var(--text-tertiary, #9a9696);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-top: 1px solid var(--border-subtle, #e3e3e3);
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast, 150ms);
}

.sidebar-section-title:hover {
  color: var(--color-brand);
}

.sidebar-section:first-of-type .sidebar-section-title {
  border-top: none;
  padding-top: var(--spacing-2, 0.5rem);
}

.sidebar-section-title > i:first-child {
  font-size: 0.75rem;
  color: var(--color-brand);
  flex-shrink: 0;
}

/* Chevron indicator */
.sidebar-section-chevron {
  margin-left: auto;
  font-size: 0.65rem;
  color: var(--text-tertiary, #9a9696);
  transition: transform 260ms cubic-bezier(0.4, 0, 0.2, 1),
              color var(--transition-fast, 150ms);
  flex-shrink: 0;
}

.sidebar-section.open .sidebar-section-chevron {
  transform: rotate(180deg);
  color: var(--color-brand);
}

.sidebar-section-title:hover .sidebar-section-chevron {
  color: var(--color-brand);
}

/* Collapsible body */
.sidebar-section-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 280ms cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-section.open .sidebar-section-body {
  max-height: 1200px;
}

/* Navigation Link */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--spacing-3, 0.75rem);
  padding: 0.55rem var(--spacing-5, 1.25rem);
  margin: 0.125rem 0;
  border-left: 3px solid transparent;
  color: var(--color-gray-500, #6b7280);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: var(--font-weight-medium);
  transition: all var(--transition-fast, 150ms);
  position: relative;
}

.sidebar-link:hover {
  background-color: var(--color-brand-50, #fef2f2);
  color: var(--color-brand);
  border-left-color: var(--color-brand-200, #fcd5cc);
}

.sidebar-link.active {
  background-color: var(--color-brand-50, #fef2f2);
  color: var(--color-brand);
  border-left-color: var(--color-brand);
  font-weight: var(--font-weight-semibold);
}

.sidebar-link i {
  width: 1.25rem;
  text-align: center;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.sidebar-link span {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-link.text-danger {
  color: #dc2626 !important;
}

.sidebar-link.text-danger:hover {
  background-color: #fef2f2 !important;
  color: #b91c1c !important;
  border-left-color: #fca5a5 !important;
}

/* ============================================
   SIDEBAR OVERLAY (Mobile)
   ============================================ */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1040;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal, 250ms);
  pointer-events: none;
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ============================================
   TOPBAR
   ============================================ */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width, 264px);
  right: 0;
  height: var(--header-height, 64px);
  background-color: var(--bg-primary, #ffffff);
  border-bottom: 1px solid var(--border-subtle, #e3e3e3);
  display: flex;
  align-items: center;
  padding: 0 var(--spacing-6, 1.5rem);
  z-index: calc(var(--z-fixed, 1030) - 2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.sidebar-toggle {
  display: none;
  padding: var(--spacing-2, 0.5rem);
  border-radius: var(--radius-md, 0.5rem);
  color: var(--color-gray-500, #6b7280);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast, 150ms);
  margin-right: var(--spacing-3, 0.75rem);
}

.sidebar-toggle:hover {
  background-color: var(--bg-tertiary, #f3f4f6);
  color: var(--text-primary, #1f2937);
}

.topbar-brand {
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary, #1f2937);
  font-family: var(--font-family-heading, -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--spacing-3, 0.75rem);
}

.topbar-actions button[data-theme-toggle] {
  padding: var(--spacing-2, 0.5rem);
  border-radius: var(--radius-lg, 0.75rem);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast, 150ms);
}

.topbar-actions button[data-theme-toggle]:hover {
  background-color: var(--bg-tertiary, #f3f4f6);
}

/* ============================================
   CONTENT WRAPPER
   ============================================ */
.content-wrapper {
  margin-left: var(--sidebar-width, 264px);
  min-height: 100vh;
  background-color: var(--bg-primary, #f5f5f5);
}

.main-content {
  padding: var(--spacing-6, 1.5rem);
}

/* ============================================
   RESPONSIVE SIDEBAR
   ============================================ */
@media (max-width: 1023.98px) {
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    z-index: var(--z-modal, 1050);
  }

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

  .sidebar-close {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .topbar {
    left: 0;
  }

  .content-wrapper {
    margin-left: 0;
  }

  .main-content {
    padding-top: var(--spacing-4, 1rem);
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.text-muted {
  color: var(--text-secondary, #6b7280) !important;
}

.ms-2 {
  margin-left: 0.5rem !important;
}

.mr-1 {
  margin-right: 0.25rem !important;
}

.mr-2 {
  margin-right: 0.5rem !important;
}

.mt-auto {
  margin-top: auto !important;
}

.fw-semibold {
  font-weight: var(--font-weight-semibold) !important;
}

.hidden {
  display: none !important;
}

/* ============================================
   FOCUS RINGS (keyboard navigation)
   ============================================ */
.sidebar-link:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: -2px;
  border-radius: 2px;
}

.sidebar-section-title:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: -2px;
}

/* ============================================
   FOOTER SECTION (Profile / Logout)
   ============================================ */
.sidebar-section--footer {
  margin-top: auto;
  padding-top: var(--spacing-2, 0.5rem);
  border-top: 1px solid var(--border-subtle, #e3e3e3);
}

/* ============================================
   SIDEBAR SEARCH
   ============================================ */

/* Container — matches sidebar-user section rhythm */
.sidebar-search {
  padding: var(--spacing-2, 0.5rem) var(--spacing-5, 1.25rem) var(--spacing-3, 0.75rem);
  background-color: var(--bg-secondary, #ffffff);
  border-bottom: 1px solid var(--border-subtle, #e3e3e3);
  flex-shrink: 0;
}

.dark .sidebar-search {
  background-color: var(--bg-secondary);
  border-bottom-color: var(--border-subtle);
}

.sidebar-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

/* Search icon */
.sidebar-search-wrap .search-icon {
  position: absolute;
  left: 0.65rem;
  color: var(--text-tertiary, #9a9696);
  font-size: 0.675rem;
  pointer-events: none;
  z-index: 1;
  transition: color 150ms;
}

.sidebar-search-input:focus ~ .search-icon,
.sidebar-search-wrap:focus-within .search-icon {
  color: var(--color-brand, #16668b);
}

/* Input — pill shape, tertiary bg so it looks embedded */
.sidebar-search-input {
  width: 100%;
  padding: 0.4375rem 4rem 0.4375rem 2rem;
  border: 1px solid var(--border-subtle, #e3e3e3);
  border-radius: var(--radius-full, 9999px);
  background-color: var(--bg-tertiary, #f5f5f5);
  color: var(--text-primary, #1f2937);
  font-size: 0.8125rem;
  font-family: inherit;
  outline: none;
  box-shadow: var(--shadow-xs);
  transition: border-color 150ms, box-shadow 150ms, background-color 150ms;
  -webkit-appearance: none;
  appearance: none;
}

.sidebar-search-input::-webkit-search-cancel-button {
  display: none;
}

.sidebar-search-input::placeholder {
  color: var(--text-tertiary, #9a9696);
}

.sidebar-search-input:hover:not(:focus) {
  border-color: var(--border-default, #d1d1d1);
  background-color: var(--bg-secondary, #ffffff);
  box-shadow: var(--shadow-sm);
}

.sidebar-search-input:focus {
  border-color: var(--color-brand, #16668b);
  box-shadow: 0 0 0 3px var(--color-brand-100, hsl(199, 73%, 95%)), var(--shadow-sm);
  background-color: var(--bg-secondary, #ffffff);
}

/* ⌘K / Ctrl+K shortcut badge — visible when input is idle and empty */
.sidebar-search-kbd {
  position: absolute;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.125rem;
  pointer-events: none;
  transition: opacity 150ms;
}

.sidebar-search-kbd kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.1rem 0.3rem;
  font-size: 0.625rem;
  font-family: inherit;
  font-weight: 600;
  line-height: 1;
  color: var(--text-tertiary, #9a9696);
  background: var(--bg-secondary, #ffffff);
  border: 1px solid var(--border-default, #d1d1d1);
  border-radius: var(--radius-sm, 0.25rem);
  box-shadow: 0 1px 0 var(--border-default, #d1d1d1);
  white-space: nowrap;
}

.sidebar-search-kbd.hidden {
  display: none;
}

/* Clear button — shown only when input has value */
.sidebar-search-clear {
  position: absolute;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  background: var(--bg-tertiary, #f5f5f5);
  border: 1px solid var(--border-subtle, #e3e3e3);
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-tertiary, #9a9696);
  font-size: 0.6rem;
  line-height: 1;
  padding: 0;
  transition: background-color 150ms, color 150ms, border-color 150ms;
}

.sidebar-search-clear:hover {
  background: var(--border-subtle, #e3e3e3);
  border-color: var(--border-default, #d1d1d1);
  color: var(--text-primary, #1f2937);
}

/* ─── Results panel inside the nav ──────────────────────────────────────── */
.sidebar-search-results-panel {
  display: none;
  padding: 0.25rem 0 0.5rem;
}

.sidebar-nav.search-active .sidebar-search-results-panel {
  display: block;
}

.sidebar-nav.search-active > .sidebar-link,
.sidebar-nav.search-active > .sidebar-section {
  display: none;
}

/* Results count header — matches sidebar-section-title style */
.search-results-header {
  padding: var(--spacing-2, 0.5rem) var(--spacing-5, 1.25rem) var(--spacing-1, 0.25rem);
  font-size: 0.6875rem;
  font-weight: var(--font-weight-semibold, 600);
  color: var(--text-tertiary, #9a9696);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* ─── Individual result item — mirrors .sidebar-link exactly ───────────── */
.sidebar-search-result-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-3, 0.75rem);
  padding: 0.55rem var(--spacing-5, 1.25rem);
  margin: 0.125rem 0;
  font-size: 0.85rem;
  font-weight: var(--font-weight-medium, 500);
  color: var(--color-gray-500, #6b7280);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background-color 150ms, color 150ms, border-left-color 150ms;
  cursor: pointer;
}

.sidebar-search-result-item:hover {
  background-color: var(--color-brand-50);
  color: var(--color-brand, #16668b);
  border-left-color: var(--color-brand-200);
}

.sidebar-search-result-item.highlighted {
  background-color: var(--color-brand-50);
  color: var(--color-brand, #16668b);
  border-left-color: var(--color-brand, #16668b);
}

.sidebar-search-result-item i {
  width: 1.25rem;
  text-align: center;
  font-size: 0.8rem;
  flex-shrink: 0;
  color: inherit;
}

.sidebar-search-result-item .result-text {
  flex: 1;
  min-width: 0;
}

.sidebar-search-result-item .result-label {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-search-result-item .result-section {
  display: block;
  font-size: 0.6875rem;
  color: var(--text-tertiary, #9a9696);
  margin-top: 0.1rem;
}

.sidebar-search-result-item:hover .result-section,
.sidebar-search-result-item.highlighted .result-section {
  color: var(--color-brand-light, hsl(199, 73%, 60%));
}

/* Empty state */
.sidebar-search-empty {
  padding: 1.25rem var(--spacing-5, 1.25rem);
  font-size: 0.8125rem;
  color: var(--text-tertiary, #9a9696);
  text-align: center;
  line-height: 1.5;
}

.sidebar-search-empty .empty-icon {
  display: block;
  font-size: 1.25rem;
  margin-bottom: 0.4rem;
  opacity: 0.35;
}

/* Highlighted match — brand teal, not orange */
mark.search-highlight {
  background: var(--color-brand-100, hsl(199, 73%, 95%));
  color: var(--color-brand, #16668b);
  border-radius: 2px;
  padding: 0 1px;
  font-style: normal;
  font-weight: 600;
}

/* ─── Dark mode ─────────────────────────────────────────────────────────── */
.dark .sidebar-search-wrap .search-icon {
  color: rgba(255, 255, 255, 0.3);
}

.dark .sidebar-search-wrap:focus-within .search-icon {
  color: var(--color-brand-light);
}

.dark .sidebar-search-input {
  background-color: var(--bg-tertiary);
  border-color: var(--border-subtle);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}

.dark .sidebar-search-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.dark .sidebar-search-input:hover:not(:focus) {
  border-color: rgba(255, 255, 255, 0.18);
  background-color: rgba(255, 255, 255, 0.06);
  box-shadow: var(--shadow-sm);
}

.dark .sidebar-search-input:focus {
  background-color: var(--bg-secondary);
  border-color: var(--color-brand-light);
  box-shadow: 0 0 0 3px rgba(22, 104, 139, 0.25), var(--shadow-sm);
}

.dark .sidebar-search-kbd kbd {
  background: var(--bg-tertiary);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.3);
}

.dark .sidebar-search-clear {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.4);
}

.dark .sidebar-search-clear:hover {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
}

.dark .sidebar-search-result-item {
  color: var(--text-tertiary);
}

.dark .sidebar-search-result-item:hover {
  background-color: rgba(22, 104, 139, 0.12);
  color: var(--color-brand-light);
  border-left-color: rgba(22, 104, 139, 0.35);
}

.dark .sidebar-search-result-item.highlighted {
  background-color: rgba(22, 104, 139, 0.18);
  color: var(--color-brand-light);
  border-left-color: var(--color-brand-light);
}

.dark .sidebar-search-result-item .result-section {
  color: rgba(255, 255, 255, 0.3);
}

.dark .sidebar-search-result-item:hover .result-section,
.dark .sidebar-search-result-item.highlighted .result-section {
  color: var(--color-brand-light);
  opacity: 0.65;
}

.dark mark.search-highlight {
  background: rgba(22, 104, 139, 0.22);
  color: var(--color-brand-light);
}

.dark .search-results-header {
  color: rgba(255, 255, 255, 0.3);
}

/* ============================================
   MOBILE FAB TOGGLE (topbar removed)
   ============================================ */
.sidebar-toggle-fab {
  display: none;
  position: fixed;
  top: var(--spacing-3, 0.75rem);
  left: var(--spacing-3, 0.75rem);
  z-index: calc(var(--z-modal, 1050) - 10);
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-lg, 0.75rem);
  background: var(--color-brand);
  color: #fff;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0,0,0,.15));
  transition: transform var(--transition-fast, 150ms);
}
.sidebar-toggle-fab:hover { transform: scale(1.05); }

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

/* ============================================
   SIDEBAR USER CARD (footer identity)
   ============================================ */
.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: var(--spacing-2, 0.5rem);
  padding: var(--spacing-2, 0.5rem) var(--spacing-3, 0.75rem);
  margin-bottom: var(--spacing-2, 0.5rem);
  border-radius: var(--radius-md, 0.5rem);
  background: var(--bg-secondary, #f3f4f6);
}
.sidebar-user-card__main {
  display: flex;
  align-items: center;
  gap: var(--spacing-2, 0.5rem);
  flex: 1;
  min-width: 0;
  text-decoration: none;
}
.sidebar-user-card__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9999px;
  background: var(--color-brand);
  color: #fff;
  font-size: 0.75rem;
  flex-shrink: 0;
}
.sidebar-user-card__info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}
.sidebar-user-card__name {
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: var(--font-weight-semibold, 600);
  color: var(--text-primary, #1f2937);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-card__plan {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-gray-400, #9ca3af);
}
.sidebar-user-card__plan i { color: var(--color-brand); }
.sidebar-user-card__theme {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-md, 0.5rem);
  background: transparent;
  color: var(--color-gray-500, #6b7280);
  cursor: pointer;
  transition: background var(--transition-fast, 150ms);
}
.sidebar-user-card__theme:hover {
  background: var(--bg-tertiary, #e5e7eb);
}
.dark .sidebar-user-card { background: rgba(255,255,255,0.05); }
.dark .sidebar-user-card__theme:hover { background: rgba(255,255,255,0.1); }
