:root {
  /* Common Colors */
  --primary: #287F71;
  --crepe-color-primary: var(--primary);
  --primary-rgb: 40, 127, 113;
  --secondary: #963b68;
  --success: #2786f1;
  --info: #73bbe2;
  --warning: #f59440;
  --danger: #ec344c;
  --font-family: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --sidebar-width: 280px;
  --toc-width: 260px;
}

/* Light Theme Variables */
[data-theme="light"] {
  --bg-body: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --text-main: #172b4d;
  /* Confluence dark blue text */
  --text-muted: #6b778c;
  --border: #dfe1e6;
  --code-bg: #f4f5f7;
  --pre-bg: #1e293b;
  --header-bg: rgba(255, 255, 255, 0.95);
  --shadow: 0 1px 1px rgba(9, 30, 66, 0.25), 0 0 1px rgba(9, 30, 66, 0.31);
}

.user-avatar-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Dark Theme Variables */
[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-card: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: rgba(255, 255, 255, 0.1);
  --code-bg: rgba(255, 255, 255, 0.05);
  --pre-bg: #000000;
  --header-bg: rgba(15, 23, 42, 0.8);
  --shadow: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}

/* Milkdown Dynamic Theme Mapping */
[data-theme="dark"] .milkdown {
  --crepe-color-background: transparent;
  --crepe-color-on-background: var(--text-main);
  --crepe-color-surface: var(--bg-card);
  --crepe-color-surface-low: var(--bg-sidebar);
  --crepe-color-on-surface: var(--text-main);
  --crepe-color-on-surface-variant: var(--text-muted);
  --crepe-color-outline: rgba(255, 255, 255, 0.2);
  --crepe-color-primary: var(--primary);
  --crepe-color-secondary: rgba(255, 255, 255, 0.1);
  --crepe-color-on-secondary: var(--text-main);
  --crepe-color-inverse: var(--text-main);
  --crepe-color-on-inverse: var(--bg-body);
  --crepe-color-inline-code: #fca5a5;
  --crepe-color-error: #fca5a5;
  --crepe-color-hover: rgba(255, 255, 255, 0.05);
  --crepe-color-selected: rgba(255, 255, 255, 0.1);
  --crepe-color-inline-area: var(--code-bg);
}

/* Hide interactive image controls in read/view mode */
.milkdown .ProseMirror[contenteditable="false"] .milkdown-image-block>.image-wrapper .operation,
.milkdown .ProseMirror[contenteditable="false"] .milkdown-image-block>.image-wrapper>.image-resize-handle,
.milkdown .ProseMirror[contenteditable="false"] .milkdown-image-block>.caption-input,
.milkdown .ProseMirror[contenteditable="false"] .milkdown-image-block>.image-edit,
.milkdown .ProseMirror[contenteditable="false"] .milkdown-image-inline>.empty-image-inline {
  display: none !important;
}

[data-theme="dark"] .text-muted {
  color: var(--text-muted) !important;
}

[data-theme="dark"] .form-label {
  color: var(--text-muted) !important;
}

[data-theme="dark"] .table {
  --bs-table-bg: transparent !important;
  --bs-table-color: var(--text-main) !important;
  --bs-table-hover-bg: rgba(255, 255, 255, 0.05) !important;
  --bs-table-hover-color: var(--text-main) !important;
  color: var(--text-main) !important;
  border-color: var(--border) !important;
}

[data-theme="dark"] .table td,
[data-theme="dark"] .table th {
  background-color: transparent !important;
  color: inherit !important;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-body) !important;
  color: var(--text-main);
  line-height: 1.6;
  transition: background-color 0.3s, color 0.3s;
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Slim Scrollbar */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Layout Grid */
.docs-container {
  display: flex;
  min-height: 100vh;
}

.docs-container.no-sidebar .main-wrapper {
  margin-left: 0 !important;
  width: 100% !important;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: sticky;
  top: 0;
  padding: 1.5rem 0.75rem;
  overflow-y: auto;
  z-index: 101;
  flex-shrink: 0;
}

.offcanvas.sidebar {
  width: 300px;
  background: var(--bg-sidebar);
  color: var(--text-main);
  border-right: 1px solid var(--border);
  z-index: 1045;
}

.offcanvas-header {
  border-bottom: 1px solid var(--border);
  /*padding: 1.5rem;*/
}

.btn-close {
  filter: var(--bs-theme-filter, invert(1));
}

[data-theme="light"] .btn-close {
  filter: none;
}

.logo-link {
  text-decoration: none;
  display: block;
  margin-bottom: 1.5rem;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--primary);
}

.logo-text-group {
  display: flex;
  flex-direction: column;
}

.logo-main {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 0.9;
}

.logo-sub {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 2px;
  opacity: 0.8;
}

/* Sidebar specifically uses corner-align */
.sidebar .logo-sub {
  align-self: flex-end;
}

/* Center-aligned variant for splash screens */
.logo-centered {
  text-align: center;
}

.logo-centered .logo-sub {
  align-self: center;
}

/* Sidebar Search */
.sidebar-search {
  margin-bottom: 1rem;
  position: relative;
  display: flex;
  align-items: center;
}

.sidebar-search input {
  width: 100%;
  padding: 0.6rem 0.8rem 0.6rem 2.5rem;
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 0.85rem;
  outline: none;
  transition: all 0.2s;
}

.sidebar-search i,
.sidebar-search svg {
  position: absolute;
  left: 12px;
  top: 50% !important;
  transform: translateY(-50%) !important;
  color: var(--text-muted);
  width: 16px !important;
  height: 16px !important;
  pointer-events: none;
  margin: 0 !important;
}

* {
  box-sizing: border-box;
}

/* Main Wrapper */
.main-wrapper {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-width: 0;
  min-height: 100vh;
  background-color: var(--bg-body);
}

/* Top Bar */
.top-bar {
  height: 64px;
  flex-shrink: 0;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1030;
  gap: 1.5rem;
}

.global-search {
  position: relative;
  width: 100%;
  max-width: 450px;
  display: flex;
  align-items: center;
}

@media (max-width: 768px) {
  .top-bar {
    height: auto !important;
    padding: 0 !important;
    gap: 0 !important;
    display: grid !important;
    grid-template-columns: 1fr auto;
  }

  .top-bar>.d-flex:first-child {
    grid-column: 1;
    grid-row: 1;
    padding-left: 1.5rem;
    height: 64px;
    margin: 0;
  }

  .top-bar>.top-actions {
    grid-column: 2;
    grid-row: 1;
    padding-right: 1.5rem;
    height: 64px;
    margin: 0 !important;
    gap: 0.25rem;
  }

  .global-search {
    grid-column: 1 / -1;
    grid-row: 2;
    position: relative;
    left: 0;
    transform: none;
    max-width: none;
    margin: 0;
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    display: none;
  }

  .global-search.mobile-open {
    display: flex;
    animation: slideDownSearch 0.2s ease-out;
  }

  @keyframes slideDownSearch {
    from {
      opacity: 0;
      transform: translateY(-10px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .global-search i,
  .global-search svg {
    left: calc(1.5rem + 14px) !important;
  }
}

.global-search input {
  width: 100%;
  padding: 0.45rem 1.2rem 0.45rem 3rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-main);
  outline: none;
  font-size: 0.9rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05);
}

.global-search input:focus {
  background: var(--bg-sidebar);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 15%, transparent), var(--shadow);
}

.global-search i,
.global-search svg {
  position: absolute;
  left: 14px;
  top: 50% !important;
  transform: translateY(-50%) !important;
  color: var(--text-muted);
  width: 18px !important;
  height: 18px !important;
  pointer-events: none;
  margin: 0 !important;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  max-height: 450px;
  overflow-y: auto;
  display: none;
  z-index: 1000;
  padding: 8px;
}

.search-result-item {
  padding: 12px 16px;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
  display: block;
  text-decoration: none;
  color: inherit;
  margin-bottom: 4px;
}

.search-result-item:hover,
.search-result-item.selected {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
  transform: translateX(4px);
}

.search-result-title {
  font-weight: 600;
  color: var(--primary);
  font-size: 0.95rem;
  display: block;
  margin-bottom: 2px;
}

.search-result-context {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  margin-bottom: 4px;
  display: block;
}

.search-result-snippet {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.search-no-results {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-left: auto;
}

.version-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--code-bg);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.theme-toggle {
  background: none;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Navigation */
.nav-section {
  margin-bottom: 2rem;
}

.nav-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}

.nav-link {
  display: block;
  padding: 0.5rem 0.8rem;
  color: var(--text-main);
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  margin-bottom: 2px;
}

.nav-link:hover {
  color: var(--primary);
}

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

/* Sub-navigation */
.nav-sub-list {
  padding-left: 1.5rem;
  margin-top: 4px;
  border-left: 1px solid var(--border);
  margin-left: 0.8rem;
}

.sub-link {
  font-size: 0.85rem !important;
  color: var(--text-muted) !important;
  padding: 0.4rem 0.8rem !important;
}

.sub-link:hover {
  color: var(--primary) !important;
  border-left: 1px solid var(--primary);
}

.sub-link.active {
  background: none !important;
  color: var(--primary) !important;
  font-weight: 600;
}

/* Main Content */
.main-content {
  padding: 0;
  max-width: 100%;
  margin-left: 0;
  width: 100%;
  flex: 1;
}

/* Table of Contents */
.toc-sidebar {
  width: var(--toc-width);
  padding: 2rem 1.5rem;
  height: calc(100vh - 72px);
  position: sticky;
  top: 72px;
  border-left: 1px solid var(--border);
  flex-shrink: 0;
}

.toc-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.toc-link {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
  display: block;
  margin-bottom: 0.5rem;
}

.toc-link:hover {
  color: var(--primary);
}

.ms-3 {
  margin-left: 1rem;
}

/* Markdown Styling */
.markdown-content h1 {
  font-size: 2.5rem;
  margin-bottom: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
}

.markdown-content h2 {
  font-size: 1.8rem;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.markdown-content h3 {
  font-size: 1.3rem;
  margin-top: 2rem;
  margin-bottom: 0.8rem;
}

.markdown-content p {
  margin-bottom: 1.2rem;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.markdown-content code {
  background: var(--code-bg);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-family: monospace;
  color: var(--secondary);
}

.markdown-content pre {
  background: var(--pre-bg);
  padding: 1.5rem;
  border-radius: 12px;
  overflow-x: auto;
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  color: #e2e8f0;
}

/* Image Alignment Options */
.milkdown-image-block:has(img[src*="align=left"]),
.markdown-content img[src*="align=left"] {
  float: left;
  margin: 0.5rem 1.5rem 0.5rem 0 !important;
  max-width: 50%;
  clear: none;
}

.milkdown-image-block:has(img[src*="align=right"]),
.markdown-content img[src*="align-right"] {
  float: right;
  margin: 0.5rem 0 0.5rem 1.5rem !important;
  max-width: 50%;
  clear: none;
}

.milkdown-image-block:has(img[src*="align-center"]),
.markdown-content img[src*="align-center"] {
  display: block;
  margin: 1rem auto !important;
  max-width: 80%;
  float: none;
}

.milkdown-image-block:has(img[src*="align=full"]),
.markdown-content img[src*="align=full"] {
  display: block;
  width: 100% !important;
  max-width: 100%;
  margin: 1rem 0 !important;
  float: none;
}

/* Float clearing for paragraphs around floats */
.markdown-content::after,
.milkdown .ProseMirror::after {
  content: "";
  display: table;
  clear: both;
}

/* Alert Boxes */
.alert-secondary {
  border-radius: 12px;
  padding: 1.5rem;
  margin: 2rem 0;
}

/* Mobile Adjustments */
@media (max-width: 991px) {
  .main-content {
    padding: 2rem;
  }

  .top-bar {
    padding: 0 1.5rem;
  }
}

/* Dropdown Global Overrides */
.dropdown-item {
  transition: all 0.2s ease;
}

.dropdown-item:hover,
.dropdown-item:focus {
  background-color: color-mix(in srgb, var(--primary) 8%, transparent) !important;
  color: var(--primary) !important;
}

.dropdown-item.active,
.dropdown-item:active {
  background-color: var(--primary) !important;
  color: #fff !important;
}

.dropdown-item.text-danger:hover {
  background-color: color-mix(in srgb, var(--danger) 10%, transparent) !important;
  color: var(--danger) !important;
}


/* Outline Primary Button Global Overrides */
.btn-outline-primary {
  color: var(--primary) !important;
  border-color: var(--primary) !important;
}

.btn-outline-primary:hover,
.btn-outline-primary:active,
.btn-outline-primary:focus,
.btn-outline-primary.active {
  background-color: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
}


/* Form Input Global Overrides */
.form-check-input:checked {
  background-color: var(--primary) !important;
  border-color: var(--primary) !important;
}

.form-control:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 0.25rem color-mix(in srgb, var(--primary) 25%, transparent) !important;
}