/* ==========================================================================
   DOCS PAGE
   Documentation page specific styles.
   ========================================================================== */

/* -------------------------------------------------------------------------
   Container
   ------------------------------------------------------------------------- */
.docs-container {
  padding: var(--space-2) var(--space-4) var(--space-4) var(--space-4);
}

/* -------------------------------------------------------------------------
   Sidebar Navigation
   ------------------------------------------------------------------------- */
.docs-sidebar {
  align-self: flex-start;
  border-end: 0;
  max-width: 320px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
}

#docs-sections {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
  padding-right: var(--space-1);
}

#docs-sections::-webkit-scrollbar {
  width: 4px;
}

#docs-sections::-webkit-scrollbar-track {
  background: transparent;
}

#docs-sections::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

#docs-sections::-webkit-scrollbar-thumb:hover {
  background: var(--color-fg-subtle);
}


.docs-sidebar .docs-section-header {
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: border-color var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
}

.docs-sidebar .docs-section-header.active {
  background: linear-gradient(135deg, rgba(23, 64, 146, 0.1), rgba(23, 64, 146, 0.04));
  border-color: rgba(23, 64, 146, 0.26);
  color: var(--color-fg);
  font-weight: var(--font-semibold);
}

.docs-sidebar .docs-section-header:hover {
  background-color: var(--color-bg-subtle);
  border-color: var(--color-border);
}

.docs-sidebar .docs-section-link {
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  color: var(--color-fg);
  text-decoration: none;
}

.docs-sidebar .docs-section-link:hover {
  text-decoration: underline;
}

.docs-sidebar .docs-toggle {
  color: var(--color-fg-muted);
}

.docs-sidebar .docs-toggle:focus {
  box-shadow: none;
}

.docs-sidebar .chevron {
  transition: transform var(--transition-fast);
}

.docs-sidebar .chevron.rotate {
  transform: rotate(90deg);
}

/* -------------------------------------------------------------------------
   Sidebar Subitems
   ------------------------------------------------------------------------- */
.docs-sidebar .docs-subitems {
  margin-bottom: var(--space-2);
}

.docs-sidebar .docs-subitems .list-group-item {
  padding: var(--space-2) var(--space-4) var(--space-2) var(--space-6);
  font-size: var(--text-sm);
  border: 0;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
}

.docs-sidebar .docs-subitems .list-group-item.active {
  background: linear-gradient(135deg, rgba(23, 64, 146, 0.13), rgba(23, 64, 146, 0.06));
  color: var(--color-primary);
  font-weight: var(--font-semibold);
}

.docs-sidebar .docs-subitems .list-group .list-group-item:first-child {
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: var(--radius-md);
}

.docs-sidebar .docs-subitems .list-group .list-group-item:last-child {
  border-bottom-left-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

/* Optional increased indent by level */
.docs-sidebar .docs-subitems .level-3 {
  padding-left: 2.25rem;
}

.docs-sidebar .docs-subitems .level-4 {
  padding-left: 2.75rem;
}

.docs-sidebar .docs-subitems .level-5 {
  padding-left: 3.25rem;
}

/* -------------------------------------------------------------------------
   Repo Button (Next to 'Back to Map')
   ------------------------------------------------------------------------- */
.repo-btn,
.download-btn {
  border-radius: var(--radius-sm) !important;
  font-weight: var(--font-semibold, 600);
  transition: all var(--transition-fast);
}

.repo-btn:hover,
.download-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1)) !important;
}

.repo-btn i,
.download-btn i {
  color: inherit !important;
}


/* -------------------------------------------------------------------------
   Content Area
   ------------------------------------------------------------------------- */
.docs-content img {
  max-width: 100%;
  height: auto;
  margin: var(--space-4) 0;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.docs-content p {
  margin-bottom: 1.25rem;
  line-height: var(--leading-relaxed, 1.6);
}

.docs-content p:last-child {
  margin-bottom: 0;
}

.docs-content pre {
  background: var(--color-bg-subtle);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  overflow: auto;
  font-size: var(--text-sm);
}

.docs-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

.docs-content th,
.docs-content td {
  border: var(--border-width) solid var(--color-border);
  padding: var(--space-2) var(--space-3);
}

.docs-content thead th {
  background-color: var(--color-bg-subtle);
  font-weight: var(--font-semibold);
}

.docs-content tbody tr:nth-child(odd) {
  background-color: var(--color-bg);
}

.docs-content tbody tr:nth-child(even) {
  background-color: var(--color-bg-subtle);
}

/* -------------------------------------------------------------------------
   Prev/Next Navigation Buttons
   ------------------------------------------------------------------------- */
.docs-nav {
  gap: var(--space-3);
}

.docs-nav-btn {
  border-radius: var(--radius-md);
  border: var(--border-width) solid var(--color-border);
  background: var(--color-bg);
  padding: var(--space-3) var(--space-4);
  transition: background-color var(--transition-fast);
}

.docs-nav-btn:hover {
  background: var(--color-bg-subtle);
  text-decoration: none;
}

.docs-nav-btn .nav-label {
  font-weight: var(--font-bold);
  font-size: var(--text-base);
}

.docs-nav-btn .nav-title {
  font-size: var(--text-sm);
  color: var(--color-fg-muted);
}

/* -------------------------------------------------------------------------
   Dynamic Statistics Styling
   ------------------------------------------------------------------------- */
.dynamic-stat {
  font-weight: var(--font-semibold);
  color: var(--color-accent);
  background: var(--color-bg-subtle);
  padding: 0 var(--space-1);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.dynamic-stat.stat-unavailable {
  color: var(--color-fg-muted);
  font-style: italic;
}

/* Tooltip for dynamic stats */
.dynamic-stat[title] {
  cursor: help;
  border-bottom: 1px dotted var(--color-border);
}

/* -------------------------------------------------------------------------
   Mermaid Diagrams
   ------------------------------------------------------------------------- */
.mermaid {
  margin: var(--space-4) 0;
  padding: var(--space-4);
  background: var(--color-bg);
  border-radius: var(--radius-md);
  border: var(--border-width) solid var(--color-border);
  overflow-x: auto;
}

.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* Center mermaid diagrams */
.docs-content .mermaid {
  display: flex;
  justify-content: center;
}

/* Apply rounded corners to Mermaid diagram elements */
.mermaid .node rect,
.mermaid .node polygon,
.mermaid .cluster rect {
  rx: var(--radius-sm) !important;
  ry: var(--radius-sm) !important;
}

.mermaid .edgeLabel rect {
  rx: var(--radius-sm) !important;
  ry: var(--radius-sm) !important;
}

/* -------------------------------------------------------------------------
   Operator Normalizations Page
   ------------------------------------------------------------------------- */
.normalizations-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-4);
}

.normalizations-header {
  margin-bottom: var(--space-6);
}

.normalizations-table {
  background: var(--color-bg);
  border-radius: var(--radius-md);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.normalizations-table table {
  width: 100%;
  margin: 0;
}

.normalizations-table th {
  background-color: var(--color-primary-subtle);
  color: var(--color-primary);
  font-weight: var(--font-semibold);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 10;
}

.normalizations-table td {
  padding: var(--space-2) var(--space-4);
  border-bottom: var(--border-width) solid var(--color-border);
}

.normalizations-table tr:last-child td {
  border-bottom: none;
}

.normalizations-table tbody tr:hover {
  background-color: var(--color-bg-subtle);
}

.badge-count {
  background-color: var(--color-primary-subtle);
  color: var(--color-primary);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
}

.info-box {
  background-color: var(--color-primary-subtle);
  border-start: 4px solid var(--color-primary);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  border-radius: var(--radius-sm);
}

.info-box i {
  color: var(--color-primary);
  margin-right: var(--space-2);
}

/* -------------------------------------------------------------------------
   GitHub-style Alerts
   Styled blockquote alerts like [!NOTE], [!IMPORTANT], etc.
   ------------------------------------------------------------------------- */
.github-alert {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border-start: 4px solid;
}

.github-alert .alert-title {
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.github-alert .alert-title i {
  font-size: var(--text-base);
}

.github-alert .alert-content {
  font-size: var(--text-sm);
}

.github-alert .alert-content p {
  margin: 0;
}

.github-alert .alert-content p+p {
  margin-top: var(--space-2);
}

/* Note - Blue/Info */
.github-alert.alert-note {
  background-color: rgba(23, 64, 146, 0.1);
  border-start-color: var(--color-primary);
}

.github-alert.alert-note .alert-title {
  color: var(--color-primary);
}

/* Tip - Green */
.github-alert.alert-tip {
  background-color: rgba(76, 175, 80, 0.1);
  border-start-color: var(--color-success, #4caf50);
}

.github-alert.alert-tip .alert-title {
  color: var(--color-success, #4caf50);
}

/* Important - Red (matches app danger color) */
.github-alert.alert-important {
  background-color: var(--color-danger-subtle, rgba(220, 53, 69, 0.1));
  border-start-color: var(--color-danger, #dc3545);
}

.github-alert.alert-important .alert-title {
  color: var(--color-danger, #dc3545);
}

/* Warning - Yellow/Orange */
.github-alert.alert-warning {
  background-color: rgba(240, 173, 78, 0.1);
  border-start-color: var(--color-warning, #f0ad4e);
}

.github-alert.alert-warning .alert-title {
  color: var(--color-warning, #f0ad4e);
}

/* Caution - Red */
.github-alert.alert-caution {
  background-color: var(--color-danger-subtle, rgba(220, 53, 69, 0.1));
  border-start-color: var(--color-danger, #dc3545);
}

.github-alert.alert-caution .alert-title {
  color: var(--color-danger, #dc3545);
}

/* -------------------------------------------------------------------------
   Expandable Content Sections
   Used for embedded tables (e.g. operator normalizations)
   ------------------------------------------------------------------------- */
.doc-expandable-section {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: box-shadow var(--transition-fast);
}

.doc-expandable-section:hover {
  box-shadow: var(--shadow-sm);
}

.doc-expandable-section[open] {
  box-shadow: var(--shadow-md);
  border-color: rgba(23, 64, 146, 0.3);
}

.doc-expandable-summary {
  padding: var(--space-3) var(--space-4);
  background: linear-gradient(to right, var(--color-primary-subtle, rgba(23, 64, 146, 0.05)), transparent);
  color: var(--color-primary);
  font-weight: var(--font-semibold);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.doc-expandable-summary::-webkit-details-marker {
  display: none;
}

.doc-expandable-summary::before {
  content: '\f078';
  font-family: 'Font Awesome 5 Free';
  font-weight: 900;
  font-size: 0.8em;
  transition: transform var(--transition-fast);
}

.doc-expandable-section[open] .doc-expandable-summary::before {
  transform: rotate(180deg);
}

.doc-expandable-content {
  padding: var(--space-4);
  border-top: 1px solid var(--color-border-subtle, #f0f0f0);
}

/* -------------------------------------------------------------------------
   Canonical Palette Grid
   Beautiful grid of color cards for the brand palette
   ------------------------------------------------------------------------- */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-6);
}

.palette-card {
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base);
  height: 100%;
}

.palette-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-primary-muted);
}

.palette-swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  border: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.palette-details {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.palette-name {
  font-weight: var(--font-bold);
  font-size: var(--text-base);
  color: var(--color-fg);
}

.palette-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.palette-hex, 
.palette-token {
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  color: var(--color-fg-muted);
}

.palette-token {
  color: var(--color-primary);
  border-color: var(--color-primary-subtle);
}

.palette-desc {
  font-size: var(--text-xs);
  color: var(--color-fg-muted);
  line-height: var(--leading-normal);
  margin-top: var(--space-2);
}

/* -------------------------------------------------------------------------
   Mobile Responsiveness
   ------------------------------------------------------------------------- */

/* Floating toggle button for mobile */
.mobile-sidebar-toggle {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 1050;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  display: flex !important;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
  padding: 0;
  background-color: var(--color-primary) !important;
  color: white !important;
  border: none !important;
  box-shadow: var(--shadow-lg) !important;
}

.mobile-sidebar-toggle:active {
  transform: scale(0.9);
}

.mobile-sidebar-toggle i {
  font-size: 1.25rem;
}

@media (max-width: 767.98px) {
  .docs-container {
    padding: var(--space-2);
  }

  .docs-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    z-index: 1060;
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    border-radius: 0;
    border: none;
    border-end: 1px solid var(--color-border);
    box-shadow: var(--shadow-xl);
    overflow-y: auto;
    background: var(--color-bg);
    margin: 0 !important;
    display: flex !important;
    flex-direction: column;
  }

  .docs-sidebar.mobile-expanded {
    transform: translateX(0);
  }

  /* Content area adjustments */
  .docs-sidebar.pe-0 {
    padding-right: var(--space-2) !important;
  }

  .docs-content {
    width: 100%;
    margin-top: var(--space-2);
  }

  /* Overlay when sidebar is open */
  .docs-sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1055;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
  }

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

  /* Sidebar header on mobile */
  .mobile-sidebar-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-4);
  }

  .mobile-sidebar-header h5 {
    margin: 0;
    font-weight: var(--font-bold);
  }

  /* Ensure the buttons at the bottom are also visible and spaced correctly */
  .docs-sidebar .text-center.px-2 {
    margin-top: auto !important;
    padding-bottom: var(--space-6);
  }
}

@media (min-width: 768px) {
  /* Sticky behavior only on desktop */
  .docs-sidebar {
    position: sticky;
    top: calc(var(--navbar-height) + var(--space-4));
    height: calc(100vh - var(--navbar-height) - var(--space-8));
    overflow: hidden; /* prevents sidebar itself from scrolling, child #docs-sections will scroll */
  }

  .mobile-sidebar-toggle,
  .mobile-sidebar-header,
  .docs-sidebar-backdrop {
    display: none !important;
  }
}