/* MPDrexel Knowledge Explorer Styles - 3-Panel Layout */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --secondary: #64748b;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f8fafc;
  --bg-dark: #1e293b;
  --bg-elevated: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.15);
  --radius: 8px;
  --radius-sm: 4px;

  /* Layout dimensions */
  --top-nav-height: 56px;
  --sidebar-width: 280px;
  --chat-panel-width: 420px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* =============================================================================
   APP CONTAINER
   ============================================================================= */

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* =============================================================================
   TOP NAVIGATION
   ============================================================================= */

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--top-nav-height);
  padding: 0 1rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-nav-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-light);
  transition: all 0.2s;
}

.sidebar-toggle:hover {
  background: var(--bg);
  color: var(--text);
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

.logo-sub {
  font-weight: 400;
  color: var(--text-light);
  font-size: 0.875rem;
}

.top-nav-center {
  display: flex;
  gap: 0.25rem;
  background: var(--bg);
  padding: 0.25rem;
  border-radius: var(--radius);
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-light);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.nav-btn:hover {
  color: var(--text);
}

.nav-btn.active {
  background: var(--bg-elevated);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.top-nav-right {
  display: flex;
  align-items: center;
}

.chat-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--primary);
  background: transparent;
  color: var(--primary);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

.chat-toggle:hover {
  background: var(--primary);
  color: white;
}

.chat-label {
  display: none;
}

@media (min-width: 640px) {
  .chat-label {
    display: inline;
  }
}

/* =============================================================================
   MAIN LAYOUT
   ============================================================================= */

.main-layout {
  display: flex;
  flex: 1;
  position: relative;
}

/* =============================================================================
   LEFT SIDEBAR
   ============================================================================= */

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: var(--top-nav-height);
  height: calc(100vh - var(--top-nav-height));
  overflow-y: auto;
  transition: margin-left 0.3s ease, width 0.3s ease;
}

.sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-search {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  background: var(--bg);
}

.sidebar-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

/* Navigation sections */
.nav-section {
  margin-bottom: 0.25rem;
}

.nav-section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
  font-size: 0.875rem;
  transition: background 0.15s;
  user-select: none;
}

.nav-section-header:hover {
  background: var(--bg);
}

.nav-section-icon {
  font-size: 1rem;
}

.nav-section-label {
  flex: 1;
}

.nav-section-chevron {
  color: var(--text-muted);
  transition: transform 0.2s;
}

.nav-section.expanded .nav-section-chevron {
  transform: rotate(90deg);
}

.nav-section-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
}

.nav-section-children {
  display: none;
  padding-left: 0.5rem;
}

.nav-section.expanded > .nav-section-children {
  display: block;
}

/* Admin-only sections - hidden by default, shown when body has .is-admin */
.nav-section.admin-only {
  display: none;
}

body.is-admin .nav-section.admin-only {
  display: block;
}

/* Navigation items */
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem 0.5rem 2rem;
  color: var(--text-light);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s;
  border-left: 2px solid transparent;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}

/* Nested sections (subsections) */
.nav-subsection {
  margin: 0.125rem 0;
}

.nav-subsection-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem 0.5rem 1.5rem;
  cursor: pointer;
  color: var(--text-light);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all 0.15s;
  user-select: none;
}

.nav-subsection-header:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-subsection-header .nav-toggle {
  color: var(--text-muted);
  font-size: 0.625rem;
  width: 1rem;
  text-align: center;
  flex-shrink: 0;
}

.nav-subsection-content {
  display: none;
  margin-left: 0.5rem;
}

.nav-subsection.expanded > .nav-subsection-content {
  display: block;
}

.nav-subsection-content .nav-item {
  padding-left: 2rem;
  font-size: 0.8125rem;
}

/* Deeply nested subsections */
.nav-subsection .nav-subsection .nav-subsection-header {
  padding-left: 2.5rem;
}

.nav-subsection .nav-subsection .nav-subsection-content .nav-item {
  padding-left: 3rem;
}

/* Active nav item - enhanced visibility */
.nav-item.active {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
  border-left: 3px solid var(--primary);
  font-weight: 500;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: var(--text-light);
  text-decoration: none;
  font-size: 0.8125rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.sidebar-link:hover {
  background: var(--bg);
  color: var(--text);
}

/* =============================================================================
   MAIN CONTENT AREA
   ============================================================================= */

.content {
  flex: 1;
  background: var(--bg);
  min-width: 0; /* Prevent flex overflow */
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* =============================================================================
   READER VIEW
   ============================================================================= */

.reader-view {
  display: none;
}

.reader-view.active {
  display: block;
}

.document-container {
  padding: 2rem;
  min-width: 0;
}

/* On large screens, use side-by-side layout */
@media (min-width: 1200px) {
  .reader-view.active {
    display: flex;
    flex-direction: row;
  }

  .document-container {
    flex: 1;
  }
}

.document-welcome {
  max-width: 600px;
  margin: 4rem auto;
  text-align: center;
}

.document-welcome h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: var(--text);
}

.document-welcome p {
  color: var(--text-light);
  margin-bottom: 2rem;
}

.quick-start {
  text-align: left;
  background: var(--bg-elevated);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.quick-start h3 {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-light);
  margin-bottom: 1rem;
}

.quick-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.quick-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text);
  transition: all 0.15s;
  text-align: left;
}

.quick-link:hover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.04);
}

/* Document content */
.document-content {
  max-width: 800px;
  margin: 0 auto;
  background: var(--bg-elevated);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.document-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.document-header h1 {
  font-size: 1.75rem;
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

.document-header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-light);
}

.source-link {
  margin-top: 0.75rem;
}

.source-link a {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  text-decoration: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.2s;
}

.source-link a:hover {
  background: var(--primary-dark);
}

.document-body {
  font-size: 1rem;
  line-height: 1.75;
}

/* Markdown content styling */
.document-body h1 { font-size: 1.75rem; margin: 2rem 0 1rem; }
.document-body h2 { font-size: 1.5rem; margin: 1.75rem 0 0.875rem; }
.document-body h3 { font-size: 1.25rem; margin: 1.5rem 0 0.75rem; }
.document-body h4 { font-size: 1.125rem; margin: 1.25rem 0 0.625rem; }
.document-body h5, .document-body h6 { font-size: 1rem; margin: 1rem 0 0.5rem; }

.document-body p { margin-bottom: 1rem; }

.document-body ul, .document-body ol {
  margin: 0 0 1rem 1.5rem;
}

.document-body li {
  margin-bottom: 0.25rem;
}

.document-body blockquote {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--primary);
  background: var(--bg);
  color: var(--text-light);
  font-style: italic;
}

.document-body code {
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 0.875em;
  background: var(--bg);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
}

.document-body pre {
  margin: 1rem 0;
  padding: 1rem;
  background: var(--bg-dark);
  color: #e2e8f0;
  border-radius: var(--radius);
  overflow-x: auto;
}

.document-body pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.document-body a {
  color: var(--primary);
  text-decoration: none;
}

.document-body a:hover {
  text-decoration: underline;
}

/* Wiki-style internal links */
.document-body .wiki-link {
  color: var(--primary);
  background: rgba(37, 99, 235, 0.08);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s;
}

.document-body .wiki-link:hover {
  background: rgba(37, 99, 235, 0.15);
  text-decoration: none;
}

/* Broken/missing wiki links */
.document-body .wiki-link.broken {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.08);
}

.document-body .wiki-link.broken:hover {
  background: rgba(239, 68, 68, 0.15);
}

.document-body table {
  width: 100%;
  margin: 1rem 0;
  border-collapse: collapse;
}

.document-body th, .document-body td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
}

.document-body th {
  background: var(--bg);
  font-weight: 600;
}

/* Related documents at bottom of page */
.document-related {
  margin-top: 3rem;
  padding-top: 2rem;
}

.document-related .related-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.document-related h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
}

.document-related .related-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 768px) {
  .document-related .related-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.document-related .related-section {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.document-related .related-section h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-light);
  margin-bottom: 0.75rem;
}

.document-related .related-section ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.document-related .related-section li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.875rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.document-related .related-section li:last-child {
  border-bottom: none;
}

.document-related .related-section li a {
  color: var(--text);
  text-decoration: none;
  flex: 1;
  transition: color 0.15s;
}

.document-related .related-section li a:hover {
  color: var(--primary);
}

.document-related .relation-type {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

/* =============================================================================
   FOOTNOTES
   ============================================================================= */

.footnotes {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-light);
  line-height: 1.7;
}

.footnotes p {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
  text-indent: -1.5rem;
}

.footnotes sup {
  color: var(--primary);
  font-weight: 600;
  margin-right: 0.25rem;
}

.footnotes a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.footnotes a:hover {
  text-decoration: underline;
}

/* Inline superscript citation styling */
.document-body sup {
  font-size: 0.7em;
  vertical-align: super;
  line-height: 0;
}

.document-body sup a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.document-body sup a:hover {
  text-decoration: underline;
}

/* =============================================================================
   GRAPH VIEW
   ============================================================================= */

.graph-view.active {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--top-nav-height));
}

.graph-controls {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.graph-search, .graph-filter {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.graph-search {
  flex: 1;
  max-width: 300px;
}

.btn-small {
  padding: 0.5rem 1rem;
  background: var(--secondary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-small:hover {
  opacity: 0.9;
}

#graph-container {
  flex: 1;
  background: var(--bg-elevated);
}

.graph-details {
  position: absolute;
  right: 1rem;
  top: 1rem;
  width: 360px;
  max-height: calc(100% - 2rem);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  overflow-y: auto;
  z-index: 50;
}

.graph-details.hidden {
  display: none;
}

/* =============================================================================
   SEARCH VIEW
   ============================================================================= */

.search-view.active {
  display: flex;
  flex-direction: column;
  padding: 2rem;
  min-height: calc(100vh - var(--top-nav-height));
}

.search-container {
  max-width: 600px;
  margin: 0 auto 2rem;
  width: 100%;
}

.global-search {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color 0.15s;
}

.global-search:focus {
  outline: none;
  border-color: var(--primary);
}

.search-filters {
  display: flex;
  gap: 1rem;
  margin-top: 0.75rem;
  justify-content: center;
}

.search-filters label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  color: var(--text-light);
  cursor: pointer;
}

.search-results {
  flex: 1;
  overflow-y: auto;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.search-hint {
  text-align: center;
  color: var(--text-light);
  padding: 2rem;
}

.search-result {
  background: var(--bg-elevated);
  padding: 1rem;
  margin-bottom: 0.75rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.15s;
}

.search-result:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.search-result h3 {
  font-size: 1rem;
  margin-bottom: 0.375rem;
}

.search-result-meta {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-bottom: 0.5rem;
}

.search-result-snippet {
  font-size: 0.875rem;
  color: var(--text-light);
}

.search-result-snippet mark {
  background: #fef3c7;
  color: inherit;
  padding: 0 0.125rem;
}

/* =============================================================================
   RIGHT CHAT PANEL
   ============================================================================= */

.chat-panel {
  position: fixed;
  right: 0;
  top: var(--top-nav-height);
  width: var(--chat-panel-width);
  height: calc(100vh - var(--top-nav-height));
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 200;
}

.chat-panel.open {
  transform: translateX(0);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.chat-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.chat-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-light);
  transition: all 0.15s;
}

.chat-close:hover {
  background: var(--bg);
  color: var(--text);
}

/* Minimize button - hidden on desktop, shown on mobile via media query */
.chat-minimize {
  display: none;
}

.chat-context {
  padding: 0.75rem 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-light);
  display: none;
}

.chat-context.has-context {
  display: block;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.chat-message {
  margin-bottom: 1rem;
  max-width: 90%;
}

.chat-message.user {
  margin-left: auto;
}

.chat-message.user p {
  background: var(--primary);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
}

.chat-message.assistant p {
  background: var(--bg);
  padding: 0.75rem 1rem;
  border-radius: var(--radius) var(--radius) var(--radius) 4px;
}

/* Markdown styling in chat messages */
.chat-message.assistant p strong {
  font-weight: 600;
  color: var(--text);
}

.chat-message.assistant p em {
  font-style: italic;
  color: var(--text-light);
}

.chat-message.assistant p ul,
.chat-message.assistant p ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.chat-message.assistant p li {
  margin-bottom: 0.35rem;
  line-height: 1.5;
}

.chat-message.assistant p code {
  background: var(--bg-elevated);
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  font-size: 0.875em;
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}

/* Document ID links in chat */
.chat-message.assistant p a.doc-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  background: rgba(59, 130, 246, 0.1);
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  transition: all 0.15s;
}

.chat-message.assistant p a.doc-link:hover {
  background: rgba(59, 130, 246, 0.2);
  text-decoration: underline;
}

.chat-message .feedback {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding-left: 0.25rem;
}

.chat-message .feedback button {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

.chat-message .feedback button:hover {
  background: var(--bg);
}

.chat-message .feedback button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.chat-input-area {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
}

#chat-input {
  flex: 1;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  resize: none;
  font-family: inherit;
}

#chat-input:focus {
  outline: none;
  border-color: var(--primary);
}

.chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.chat-send-btn:hover {
  background: var(--primary-dark);
}

.chat-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.chat-action {
  flex: 1;
  padding: 0.5rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.15s;
}

.chat-action:hover {
  background: var(--bg);
  color: var(--text);
}

/* =============================================================================
   BADGES
   ============================================================================= */

.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 500;
}

.badge-entity { background: #dbeafe; color: #1d4ed8; }
.badge-strategy { background: #dcfce7; color: #16a34a; }
.badge-reference { background: #fef3c7; color: #d97706; }
.badge-thesis { background: #f3e8ff; color: #7c3aed; }
.badge-architecture { background: #fce7f3; color: #be185d; }
.badge-research { background: #e0f2fe; color: #0369a1; }
.badge-active { background: #dcfce7; color: #16a34a; }
.badge-draft { background: #fef3c7; color: #d97706; }
.badge-deprecated { background: #fee2e2; color: #dc2626; }

/* =============================================================================
   UTILITY CLASSES
   ============================================================================= */

.hidden {
  display: none !important;
}

/* =============================================================================
   RESPONSIVE
   ============================================================================= */

@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
    --chat-panel-width: 100%;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--top-nav-height);
    height: calc(100vh - var(--top-nav-height));
    z-index: 150;
    box-shadow: var(--shadow-lg);
    /* Hidden by default on mobile */
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  /* Show sidebar when .open class is added */
  .sidebar.open {
    transform: translateX(0);
  }

  /* Legacy support for .collapsed logic (hide when explicitly collapsed) */
  .sidebar.collapsed {
    transform: translateX(-100%);
  }

  .logo-sub {
    display: none;
  }

  .nav-btn span {
    display: none;
  }

  .document-container {
    padding: 1rem;
  }

  .document-content {
    padding: 1.5rem;
  }

  .graph-controls {
    flex-wrap: wrap;
  }

  .graph-search {
    max-width: none;
    width: 100%;
  }

  .graph-details {
    width: calc(100% - 2rem);
    left: 1rem;
    right: 1rem;
  }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--top-nav-height);
  background: rgba(0, 0, 0, 0.3);
  z-index: 140;
}

.sidebar-overlay.visible {
  display: block;
}

/* =============================================================================
   AUTHENTICATION UI
   ============================================================================= */

/* Auth container in top nav */
.auth-container {
  position: relative;
  margin-right: 0.5rem;
}

.auth-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.15s;
}

.auth-button:hover {
  background: var(--border-light);
  border-color: var(--text-muted);
}

.auth-label {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* User menu dropdown */
.user-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 1000;
}

.user-menu.hidden {
  display: none;
}

.user-info {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.user-name {
  display: block;
  font-size: 0.875rem;
  color: var(--text-light);
  margin-bottom: 0.25rem;
}

.user-role {
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
}

.user-role.badge-admin {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.user-role.badge-commenter {
  background: rgba(34, 197, 94, 0.1);
  color: var(--success);
}

.user-role.badge-viewer {
  background: rgba(100, 116, 139, 0.1);
  color: var(--secondary);
}

.user-menu-item {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.15s;
}

.user-menu-item:hover {
  background: var(--border-light);
}

/* Modal styles */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: var(--bg-elevated);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal h2 {
  margin-bottom: 0.5rem;
}

.modal-subtitle {
  color: var(--text-light);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
}

.modal hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.modal-footer-text {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-light);
}

/* Form styles */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-weight: 500;
  font-size: 0.875rem;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-message {
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-top: 1rem;
}

.form-message.success {
  background: rgba(34, 197, 94, 0.1);
  color: var(--success);
}

.form-message.error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.form-message.hidden {
  display: none;
}

/* Buttons */
.btn {
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
}

.link-button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: inherit;
  text-decoration: underline;
}

.link-button:hover {
  color: var(--primary-dark);
}

body.modal-open {
  overflow: hidden;
}

/* Hide admin link by default (shown via JS for admins) */
.sidebar-footer .sidebar-link[href="/admin"] {
  display: none;
}

@media (max-width: 768px) {
  .auth-label {
    display: none;
  }

  .modal-content {
    padding: 1.5rem;
  }
}

/* =============================================================================
   Learning Path Navigation
   ============================================================================= */

/* Path start buttons in Learning Paths document */
.path-start-btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background: var(--primary);
  color: white !important;
  text-decoration: none !important;
  border-radius: var(--radius);
  font-weight: 600;
  margin: 0.5rem 0 1rem 0;
  transition: all 0.15s;
}

.path-start-btn:hover {
  background: var(--primary-dark);
  transform: translateX(4px);
}

/* Path navigation sidebar */
.path-nav {
  padding: 1rem;
}

.path-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.path-icon {
  font-size: 1.5rem;
}

.path-info {
  flex: 1;
}

.path-label {
  font-weight: 600;
  color: var(--text);
  font-size: 0.9375rem;
}

.path-duration {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.path-exit {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.15s;
}

.path-exit:hover {
  background: var(--bg);
  color: var(--text);
}

/* Progress bar */
.path-progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.path-progress-bar {
  height: 100%;
  background: var(--success);
  transition: width 0.3s ease;
}

.path-progress-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 1rem;
}

/* Path steps list */
.path-steps {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.path-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.75rem 0.5rem 0.25rem 0.5rem;
  margin-top: 0.5rem;
}

.path-section-label:first-child {
  margin-top: 0;
}

.path-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: all 0.15s;
}

.path-step-indicator {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.path-step-label {
  flex: 1;
  font-size: 0.8125rem;
  line-height: 1.3;
}

.path-step-duration {
  font-size: 0.6875rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Step states */
.path-step-complete {
  color: var(--text-light);
}

.path-step-complete .path-step-indicator {
  background: var(--success);
  color: white;
}

.path-step-complete:hover {
  background: var(--bg);
}

.path-step-current {
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
}

.path-step-current .path-step-indicator {
  background: var(--primary);
  color: white;
}

.path-step-upcoming {
  color: var(--text-muted);
}

.path-step-upcoming .path-step-indicator {
  background: var(--border);
  color: var(--text-muted);
}

.path-step-upcoming:hover {
  background: var(--bg);
  color: var(--text-light);
}

/* Prev/Next buttons */
.path-nav-buttons {
  display: flex;
  justify-content: space-between;
  padding: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

.path-nav-btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s;
}

.path-prev {
  color: var(--text-light);
  background: var(--bg);
}

.path-prev:hover {
  background: var(--border);
  color: var(--text);
}

.path-next {
  background: var(--primary);
  color: white;
}

.path-next:hover {
  background: var(--primary-dark);
}

.path-complete {
  background: var(--success);
  color: white;
}

.path-complete:hover {
  background: #16a34a;
}

/* Hide sidebar footer in path mode */
body.path-mode .sidebar-footer {
  display: none;
}

/* =============================================================================
   MOBILE CHAT - Minimized Pill & Full-Screen Mode
   ============================================================================= */

/* Floating chat pill (shown when chat is minimized on mobile) */
.chat-pill {
  display: none;
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  right: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
  z-index: 250;
  transition: all 0.2s ease;
  animation: pill-pulse 2s ease-in-out infinite;
}

.chat-pill:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.5);
}

.chat-pill:active {
  transform: scale(0.98);
}

.chat-pill-icon {
  margin-right: 0.5rem;
}

.chat-pill-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  background: white;
  color: var(--primary);
  font-size: 0.6875rem;
  font-weight: 700;
  border-radius: 999px;
  margin-left: 0.5rem;
  padding: 0 0.25rem;
}

@keyframes pill-pulse {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
  }
  50% {
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.6);
  }
}

/* Show pill when chat is minimized (mobile only) */
@media (max-width: 768px) {
  .chat-pill.visible {
    display: flex;
    align-items: center;
  }
}

/* =============================================================================
   MOBILE-SPECIFIC OVERRIDES
   ============================================================================= */

@media (max-width: 768px) {
  /* Chat panel - full screen on mobile */
  .chat-panel {
    width: 100%;
    height: 100%;
    top: 0;
    border-radius: 0;
    border-left: none;
  }

  .chat-panel.open {
    transform: translateX(0);
  }

  /* Better chat header on mobile */
  .chat-header {
    padding: 0.875rem 1rem;
    padding-top: calc(0.875rem + env(safe-area-inset-top, 0px));
    background: var(--bg-elevated);
  }

  .chat-header h3 {
    font-size: 1.125rem;
  }

  /* Minimize button (only on mobile) */
  .chat-minimize {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-light);
    margin-right: 0.5rem;
    transition: all 0.15s;
    font-size: 1.25rem;
    font-weight: bold;
  }

  .chat-minimize:hover {
    background: var(--border);
    color: var(--text);
  }

  /* Chat messages area with better scroll */
  .chat-messages {
    padding: 1rem;
    padding-bottom: 0.5rem;
    -webkit-overflow-scrolling: touch;
  }

  /* Larger touch targets for messages */
  .chat-message {
    margin-bottom: 1.25rem;
  }

  .chat-message.assistant p,
  .chat-message.user p {
    padding: 0.875rem 1rem;
    font-size: 0.9375rem;
    line-height: 1.6;
  }

  /* Chat input area with safe area padding */
  .chat-input-area {
    padding: 0.75rem 1rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    gap: 0.75rem;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
  }

  #chat-input {
    font-size: 1rem;
    padding: 0.75rem 1rem;
    min-height: 44px;
  }

  .chat-send-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
  }

  /* Chat actions with safe area */
  .chat-actions {
    padding: 0.5rem 1rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
  }

  /* Document links in chat - larger touch target */
  .chat-message.assistant p a.doc-link {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    margin: 0.125rem 0;
  }

  /* Top nav adjustments for mobile */
  .top-nav {
    padding: 0 0.75rem;
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--top-nav-height) + env(safe-area-inset-top, 0px));
  }

  /* Sidebar adjustments for mobile */
  .sidebar {
    top: calc(var(--top-nav-height) + env(safe-area-inset-top, 0px));
    height: calc(100vh - var(--top-nav-height) - env(safe-area-inset-top, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* Document content safe areas */
  .document-container {
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  /* Larger nav items for touch */
  .nav-item {
    padding: 0.75rem 1rem 0.75rem 2rem;
    min-height: 44px;
  }

  .nav-section-header {
    padding: 0.75rem 1rem;
    min-height: 48px;
  }

  .nav-subsection-header {
    padding: 0.625rem 1rem 0.625rem 1.5rem;
    min-height: 44px;
  }
}

/* Very small screens (iPhone SE, etc.) */
@media (max-width: 375px) {
  .chat-pill {
    padding: 0.625rem 1rem;
    font-size: 0.8125rem;
  }

  .logo {
    font-size: 1.125rem;
  }

  .chat-toggle {
    padding: 0.5rem 0.75rem;
  }
}
