/* Sidebar Component Styles */
.sidebar-toggle-btn {
  color: white;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0.375rem;
  transition: all 0.2s ease;
  font-size: 1.125rem;
}

.sidebar-toggle-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
}

.sidebar-overlay {
  position: fixed;
  top: 4rem; /* Start below header */
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 30;
  display: none;
}

.sidebar-overlay.active {
  display: block;
}

.sidebar {
  position: fixed;
  left: 0;
  top: 4rem; /* Start below header */
  width: 16rem;
  height: calc(100vh - 4rem); /* Account for header height */
  background-color: white;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  z-index: 40;
  transform: translateX(-100%);
  transition: transform 0.3s ease-in-out, width 0.3s ease-in-out;
  overflow: hidden;
}

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

/* Smooth text animations */
.sidebar-nav-text,
.sidebar-brand-text {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease-in-out 0.15s, visibility 0.2s ease-in-out 0.15s, transform 0.2s ease-in-out 0.15s;
  transform: translateX(0);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-nav-link {
  transition: all 0.2s ease, padding 0.3s ease-in-out;
  white-space: nowrap;
}

.sidebar-nav-icon {
  transition: margin-right 0.3s ease-in-out;
  flex-shrink: 0;
}

/* Collapsed sidebar - only on desktop */
@media (min-width: 769px) {
  body.sidebar-collapsed .sidebar {
    width: 4rem;
    transform: translateX(0);
    top: 4rem; /* Start below header */
    height: calc(100vh - 4rem);
  }

  body.sidebar-collapsed .sidebar-nav-text,
  body.sidebar-collapsed .sidebar-brand-text {
    opacity: 0;
    visibility: hidden;
    transform: translateX(-10px);
    transition: opacity 0.15s ease-in-out, visibility 0.15s ease-in-out, transform 0.15s ease-in-out;
  }

  body.sidebar-collapsed .sidebar-nav-link {
    justify-content: center;
    padding: 0.75rem 0.5rem;
    transition: all 0.2s ease, padding 0.3s ease-in-out;
  }

  body.sidebar-collapsed .sidebar-nav-icon {
    margin-right: 0;
    transition: margin-right 0.3s ease-in-out;
  }

  body.sidebar-collapsed .sidebar-header {
    justify-content: center;
  }

  body.sidebar-collapsed .sidebar-brand {
    justify-content: center;
  }
}

/* Unified layout shift (desktop). Margin adjustments only apply ≥769px so mobile overlay is unaffected */
@media (min-width: 769px) {
  main.main-content { transition: margin-left 0.3s ease-in-out; }
  body.sidebar-collapsed main.main-content { margin-left: 4rem; }
  body.sidebar-open main.main-content { margin-left: 16rem; }
}

/* Mobile: content always full width; sidebar overlays */
@media (max-width: 768px) {
  body.sidebar-open main.main-content { margin-left: 0; }
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  font-size: 1.125rem;
  font-weight: 600;
  color: #111827;
  text-decoration: none;
  transition: color 0.2s ease;
}

.sidebar-brand:hover {
  color: #3b82f6;
}

.sidebar-brand-text {
  margin-left: 0.5rem;
}

.sidebar-nav {
  padding: 1rem 0;
}

.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav-item {
  display: block;
  margin-bottom: 0.25rem;
  list-style: none;
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  color: #6b7280;
  text-decoration: none;
  transition: all 0.2s ease;
  border-radius: 0.375rem;
  margin: 0 0.5rem;
  position: relative;
}

.sidebar-nav-link:hover {
  background-color: #f3f4f6;
  color: #111827;
}

.sidebar-nav-link.active {
  background-color: var(--brand-primary);
  color: white;
  opacity: 0.9;
}

.sidebar-nav-icon {
  margin-right: 0.75rem;
  font-size: 1.125rem;
  width: 1.25rem;
  text-align: center;
}

.sidebar-nav-text {
  font-size: 0.875rem;
  font-weight: 500;
  flex: 1;
}

.sidebar-tooltip {
  display: none;
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  background-color: #1f2937;
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  white-space: nowrap;
  z-index: 1000;
  margin-left: 0.5rem;
  pointer-events: none;
}

.sidebar-tooltip::before {
  content: '';
  position: absolute;
  top: 50%;
  left: -4px;
  transform: translateY(-50%);
  border: 4px solid transparent;
  border-right-color: #1f2937;
}

/* Show tooltip on hover when collapsed */
body.sidebar-collapsed .sidebar-nav-link:hover .sidebar-tooltip {
  display: block;
}

.nav-item {
  display: block;
  margin-bottom: 0.25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  color: #6b7280;
  text-decoration: none;
  transition: all 0.2s ease;
  border-radius: 0;
  margin: 0 0.5rem;
}

.nav-link:hover {
  background-color: #f3f4f6;
  color: #111827;
}

.nav-link.active {
  background-color: #dbeafe;
  color: #1d4ed8;
}

.nav-link .icon {
  margin-right: 0.75rem;
  font-size: 1.25rem;
}

.nav-label {
  font-size: 0.875rem;
  font-weight: 500;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .sidebar {
    width: 16rem;
    transform: translateX(-100%);
    top: 4rem; /* Start below header on mobile too */
    height: calc(100vh - 4rem);
  }

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

  body.sidebar-open {
    margin-left: 0;
  }

  body.sidebar-open .main-content {
    margin-left: 0;
  }

  .sidebar-overlay {
    display: block;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    top: 4rem; /* Start below header */
    height: calc(100vh - 4rem);
  }

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

/* Wider document container for readability beyond Tailwind's max-w-6xl (1152px) */
.document-container-wide {
  max-width: 1400px; /* Increase from ~1152px */
}

@media (min-width: 1536px) { /* 2xl and above */
  .document-container-wide {
    max-width: 1600px; /* Allow a bit more on very large screens */
  }
}

/* Optional narrower text blocks inside wide layout */
.document-container-wide .document-content {
  max-width: 1000px; /* Keep paragraphs readable */
}

/* Document viewer modal sizing */
.modal-document-viewer {
  display: flex;
  flex-direction: column;
  height: 80vh; /* Target ~80% of viewport height */
  max-height: 80vh;
}

.modal-document-viewer .modal-pdf-frame,
.modal-document-viewer .modal-pdf-image {
  height: calc(80vh - 140px); /* subtract approximate header+footer padding */
  max-height: calc(80vh - 140px);
}

@media (max-height: 700px) {
  .modal-document-viewer { height: 75vh; max-height: 75vh; }
  .modal-document-viewer .modal-pdf-frame,
  .modal-document-viewer .modal-pdf-image { height: calc(75vh - 140px); max-height: calc(75vh - 140px); }
}
