:root {
  color-scheme: light dark;
}

body {
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.module-link {
  width: 100%;
  text-align: left;
}

.module-link.is-active {
  background-color: rgba(24, 144, 255, 0.12);
  color: rgb(37, 99, 235);
}

.dark .module-link.is-active {
  background-color: rgba(24, 144, 255, 0.2);
  color: rgb(191, 219, 254);
}

.loader,
.loader::after {
  border-radius: 9999px;
}

.loader {
  width: 3rem;
  height: 3rem;
  border: 0.35rem solid rgba(148, 163, 184, 0.35);
  border-left-color: rgb(24, 144, 255);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

[data-content-area] {
  min-height: calc(100vh - 4rem);
}

.login-screen {
  min-height: 100vh;
  background: radial-gradient(circle at top, rgba(24, 144, 255, 0.15), transparent 55%),
    linear-gradient(135deg, rgba(24, 144, 255, 0.08), rgba(14, 165, 233, 0.05));
}

/* Brighten FTI logo in dark mode */
.dark img[alt="FTI Consulting"] {
  filter: brightness(0) invert(1);
}

/* Nav link transitions */
.nav-link {
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* Hide login screen initially to prevent flash */
#login-screen {
  display: none;
}

/* Details/summary arrow override */
details summary::-webkit-details-marker {
  display: none;
}

details summary {
  list-style: none;
}

/* ── AI Chat: Rich Markdown Rendering ── */
.ai-chat-content h1,
.ai-chat-content h2,
.ai-chat-content h3 {
  font-weight: 700;
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
  line-height: 1.3;
}
.ai-chat-content h1 { font-size: 1.1rem; }
.ai-chat-content h2 { font-size: 1rem; }
.ai-chat-content h3 { font-size: 0.9rem; }
.ai-chat-content p { margin-bottom: 0.5rem; }
.ai-chat-content ul,
.ai-chat-content ol {
  padding-left: 1.25rem;
  margin-bottom: 0.5rem;
}
.ai-chat-content ul { list-style-type: disc; }
.ai-chat-content ol { list-style-type: decimal; }
.ai-chat-content li { margin-bottom: 0.15rem; }
.ai-chat-content code:not(pre code) {
  background: rgba(0,0,0,0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.85em;
}
.dark .ai-chat-content code:not(pre code) {
  background: rgba(255,255,255,0.1);
}

/* Tables */
.ai-table-wrap {
  overflow-x: auto;
  margin: 0.5rem 0;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}
.dark .ai-table-wrap {
  border-color: rgba(255,255,255,0.12);
}
.ai-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  line-height: 1.4;
}
.ai-table thead th {
  background: #f3f4f6;
  font-weight: 600;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid #d1d5db;
  white-space: nowrap;
}
.dark .ai-table thead th {
  background: rgba(255,255,255,0.06);
  border-bottom-color: rgba(255,255,255,0.15);
}
.ai-table tbody td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
}
.dark .ai-table tbody td {
  border-bottom-color: rgba(255,255,255,0.08);
}
.ai-table tbody tr:last-child td {
  border-bottom: none;
}
.ai-table tbody tr:nth-child(even) {
  background: rgba(0,0,0,0.02);
}
.dark .ai-table tbody tr:nth-child(even) {
  background: rgba(255,255,255,0.03);
}
.ai-table tbody tr:hover {
  background: rgba(24,144,255,0.05);
}

/* Mermaid diagrams */
.ai-mermaid-block svg {
  max-width: 100%;
  height: auto;
}

/* Chart blocks */
.ai-chart-block canvas {
  max-width: 100%;
}
.ai-chart-block,
.ai-mermaid-block,
.ai-plotly-block {
  position: relative;
}

/* Plotly blocks */
.ai-plotly-block {
  margin-left: -0.75rem;
  margin-right: -0.75rem;
  border-radius: 8px;
}
.ai-plotly-block .js-plotly-plot {
  width: 100% !important;
}
/* Chart blocks also get negative margin for breathing room */
.ai-chart-block {
  margin-left: -0.75rem;
  margin-right: -0.75rem;
  border-radius: 8px;
}

/* Expand button on charts and diagrams */
.ai-chart-expand-btn {
  position: absolute;
  top: 4px;
  right: 16px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: rgba(255,255,255,0.85);
  border: 1px solid #e5e7eb;
  color: #637588;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.ai-chart-block:hover .ai-chart-expand-btn,
.ai-mermaid-block:hover .ai-chart-expand-btn,
.ai-plotly-block:hover .ai-chart-expand-btn {
  opacity: 1;
}
.ai-chart-expand-btn:hover {
  background: #fff;
  color: #1890ff;
  border-color: #1890ff;
}

/* Viewer Modal Overlay */
.ai-viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0);
  backdrop-filter: blur(0);
  transition: background 0.2s ease, backdrop-filter 0.2s ease;
}
.ai-viewer-overlay.visible {
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
}
.ai-viewer-modal {
  width: 92vw;
  max-width: 1100px;
  max-height: 88vh;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2), 0 0 0 1px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.ai-viewer-overlay.visible .ai-viewer-modal {
  transform: scale(1);
  opacity: 1;
}
.ai-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}
.ai-viewer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #637588;
  cursor: pointer;
  transition: background 0.15s ease;
}
.ai-viewer-close:hover {
  background: #f3f4f6;
  color: #111418;
}
.ai-viewer-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.ai-viewer-body canvas {
  max-width: 100%;
}
.ai-viewer-body svg {
  max-width: 100%;
  height: auto;
}
.ai-viewer-zoom-wrap svg {
  max-width: none !important;
  height: unset !important;
}

/* Viewer Zoom Controls */
.ai-viewer-zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-right: 8px;
  padding: 2px 4px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
}
.ai-viewer-zoom-controls button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #637588;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.ai-viewer-zoom-controls button:hover {
  background: #e5e7eb;
  color: #111418;
}
.ai-viewer-zoom-wrap {
  transform-origin: 0 0;
  will-change: transform;
  display: inline-block;
}

/* Export Modal Cards */
.ai-export-card {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
  width: 100%;
}
.ai-export-card:hover {
  border-color: #1890ff;
  box-shadow: 0 2px 8px rgba(24,144,255,0.12);
  transform: translateY(-1px);
}
.ai-export-card:active {
  transform: translateY(0);
}
.ai-export-card:disabled {
  opacity: 0.5;
  pointer-events: none;
}
.ai-export-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
}

/* Dark mode overrides for modal */
@media (prefers-color-scheme: dark) {
  .ai-viewer-modal { background: #1f2937; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
  .ai-viewer-header { border-bottom-color: rgba(255,255,255,0.1); }
  .ai-viewer-close:hover { background: rgba(255,255,255,0.1); color: #fff; }
  .ai-chart-expand-btn { background: rgba(31,41,55,0.85); border-color: rgba(255,255,255,0.15); color: #9ca3af; }
  .ai-chart-expand-btn:hover { background: #1f2937; color: #1890ff; border-color: #1890ff; }
  .ai-export-card { background: #1f2937; border-color: rgba(255,255,255,0.1); }
  .ai-export-card:hover { border-color: #1890ff; box-shadow: 0 2px 8px rgba(24,144,255,0.2); }
  .ai-viewer-zoom-controls { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.1); }
  .ai-viewer-zoom-controls button { color: #9ca3af; }
  .ai-viewer-zoom-controls button:hover { background: rgba(255,255,255,0.1); color: #fff; }
}

/* AI Panel Resize Handle */
.ai-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  z-index: 30;
  background: transparent;
  transition: background 0.15s ease;
}
.ai-resize-handle:hover,
.ai-resize-handle.active {
  background: rgba(24,144,255,0.35);
}
.ai-resize-handle::before {
  content: '';
  position: absolute;
  left: 1px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 32px;
  border-radius: 2px;
  background: rgba(0,0,0,0.12);
  transition: background 0.15s ease;
}
.ai-resize-handle:hover::before,
.ai-resize-handle.active::before {
  background: rgba(24,144,255,0.7);
}
