/* DokTor — Custom Styles
   Excellence. Always. */

/* Three-panel grid layout */
.dt-grid {
  display: grid;
  grid-template-columns: 280px 1fr 0;
  height: calc(100vh - 3.5rem); /* viewport minus navbar */
}

.dt-grid.chat-open {
  grid-template-columns: 280px 1fr var(--dt-chat-width, 520px);
}

/* Chat panel resize handle */
.dt-chat-resize {
  width: 8px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.15s;
  flex-shrink: 0;
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 10;
}
/* U+00B7 MIDDLE DOT — drag-handle grip indicator */
.dt-chat-resize::after {
  content: "\00B7\00B7\00B7";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
  font-size: 12px;
  color: oklch(var(--bc) / 0.2);
  pointer-events: none;
  letter-spacing: 2px;
}
.dt-chat-resize:hover,
.dt-chat-resize.active {
  background: oklch(var(--p) / 0.4);
}
.dt-chat-resize:hover::after,
.dt-chat-resize.active::after {
  color: oklch(var(--bc) / 0.6);
}

/* Nav panel */
.dt-nav {
  overflow-y: auto;
  scrollbar-width: thin;
}

/* Main content area */
.dt-main {
  overflow-y: auto;
  scrollbar-width: thin;
}

/* Content + TOC side by side */
.dt-content-area {
  display: grid;
  grid-template-columns: 1fr 220px;
  min-height: 0;
}

/* TOC sidebar */
.dt-toc {
  overflow-y: auto;
  scrollbar-width: thin;
  max-height: calc(100vh - 7rem);
  position: sticky;
  top: 0;
}

/* Chat panel */
.dt-chat {
  overflow-y: auto;
  scrollbar-width: thin;
}

/* Doc content area */
.dt-doc {
  min-width: 0; /* prevent overflow */
}

/* TOC styling */
.dt-toc-content nav.toc ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.dt-toc-content nav.toc li {
  margin: 0;
  padding: 0;
}

.dt-toc-content nav.toc a {
  display: block;
  padding: 0.2rem 0 0.2rem 0.5rem;
  color: oklch(var(--bc) / 0.5);
  text-decoration: none;
  border-left: 2px solid transparent;
  font-size: 0.8125rem;
  line-height: 1.4;
  transition: all 0.15s;
}

.dt-toc-content nav.toc a:hover,
.dt-toc-content nav.toc a.toc-active {
  color: oklch(var(--bc) / 0.9);
  border-left-color: oklch(var(--p));
}

.dt-toc-content nav.toc a.toc-active {
  font-weight: 500;
}

.dt-toc-content nav.toc li.toc-level-2 a {
  padding-left: 0.5rem;
}

.dt-toc-content nav.toc li.toc-level-3 a {
  padding-left: 1rem;
}

.dt-toc-content nav.toc li.toc-level-4 a {
  padding-left: 1.5rem;
}

/* Nav tree children container */
.dt-nav-children {
  min-height: 0;
}

/* HTMX loading indicator */
.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
  position: sticky;
  top: 0;
  z-index: 10;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

/* Admonition alert boxes */
.dt-doc .alert {
  margin: 1rem 0;
}

/* Code block styling */
.dt-doc pre {
  position: relative;
  border-radius: 0.5rem;
}

.dt-doc pre code {
  font-size: 0.8125rem;
}

/* Graphviz diagrams */
.dt-doc .graphviz {
  margin: 1rem 0;
  text-align: center;
}

.dt-doc .graphviz svg {
  max-width: 100%;
  height: auto;
}

/* Prose overrides for DaisyUI compatibility */
.dt-doc h1 { margin-top: 1.5rem; }
.dt-doc h2 { margin-top: 1.25rem; }
.dt-doc h3 { margin-top: 1rem; }

/* Table styling */
.dt-table-wrapper {
  overflow-x: auto;
  margin: 1rem 0;
}
.dt-doc table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.dt-doc table th {
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid oklch(var(--bc) / 0.2);
  padding: 0.5rem 0.75rem;
}
.dt-doc table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid oklch(var(--bc) / 0.1);
}
.dt-doc table tbody tr:hover {
  background: oklch(var(--bc) / 0.03);
}

/* Diagram toggle containers */
.dt-diagram {
  position: relative;
  margin: 1rem 0;
}
.dt-diagram-toolbar {
  display: flex;
  gap: 0.25rem;
  justify-content: flex-end;
  margin-bottom: 0.25rem;
}
.dt-diagram-toolbar button {
  font-size: 0.75rem;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.dt-diagram-toolbar button:hover {
  opacity: 1;
}
.dt-diagram-source.hidden {
  display: none;
}
.dt-diagram-render.hidden {
  display: none;
}

/* Heading anchor links — inline after heading text */
.dt-anchor {
  opacity: 0;
  margin-left: 0.35em;
  color: oklch(var(--p));
  text-decoration: none;
  font-weight: 400;
  transition: opacity 0.15s;
}
.group:hover .dt-anchor,
.dt-anchor:focus {
  opacity: 0.6;
}
.dt-anchor:hover {
  opacity: 1;
}

.dt-doc img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
}

/* Code file viewer */
.dt-code-viewer {
  padding: 0.5rem 0;
}
.dt-code-highlight pre {
  margin: 0;
  padding: 1rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  line-height: 1.5;
}
.dt-code-highlight code {
  font-size: 0.8125rem;
}

/* Responsive: collapse nav on small screens */
@media (max-width: 1024px) {
  .dt-grid {
    grid-template-columns: 1fr;
  }

  .dt-grid.chat-open {
    grid-template-columns: 1fr;
  }

  .dt-nav {
    display: none;
  }

  .dt-content-area {
    grid-template-columns: 1fr;
  }

  .dt-toc {
    display: none;
  }

  .dt-chat {
    display: none;
  }
}

/* Scrollbar styling for dark theme */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: oklch(var(--bc) / 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: oklch(var(--bc) / 0.3);
}

/* =========================================
   Chat panel styles
   ========================================= */

/* Chat message container */
.dt-chat-msg {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid oklch(var(--bc) / 0.05);
}

.dt-chat-msg:last-child {
  border-bottom: none;
}

/* Chat message header with role indicator */
.dt-chat-msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.375rem;
}

.dt-chat-msg-role {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  color: oklch(var(--bc) / 0.5);
}

.dt-chat-msg-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dt-chat-msg-dot-user {
  background: oklch(var(--p));
}

.dt-chat-msg-dot-assistant {
  background: #8b5cf6;
}

.dt-chat-msg-dot-tool {
  background: #22c55e;
}

/* Chat message body — markdown content */
.dt-chat-msg-body {
  font-size: 0.875rem;
  line-height: 1.75;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Prose styling for rendered assistant messages */
.dt-chat-msg-body.dt-chat-prose h1,
.dt-chat-msg-body.dt-chat-prose h2,
.dt-chat-msg-body.dt-chat-prose h3,
.dt-chat-msg-body.dt-chat-prose h4 {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
  line-height: 1.3;
}

.dt-chat-msg-body.dt-chat-prose h1 { font-size: 1.25rem; }
.dt-chat-msg-body.dt-chat-prose h2 { font-size: 1.125rem; }
.dt-chat-msg-body.dt-chat-prose h3 { font-size: 1rem; }
.dt-chat-msg-body.dt-chat-prose h4 { font-size: 0.875rem; }

.dt-chat-msg-body.dt-chat-prose p {
  margin: 0.5rem 0;
}

.dt-chat-msg-body.dt-chat-prose p:first-child {
  margin-top: 0;
}

.dt-chat-msg-body.dt-chat-prose ul,
.dt-chat-msg-body.dt-chat-prose ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.dt-chat-msg-body.dt-chat-prose li {
  margin: 0.25rem 0;
}

.dt-chat-msg-body.dt-chat-prose blockquote {
  border-left: 3px solid oklch(var(--bc) / 0.2);
  padding-left: 0.75rem;
  margin: 0.5rem 0;
  color: oklch(var(--bc) / 0.7);
}

.dt-chat-msg-body.dt-chat-prose a {
  color: oklch(var(--p));
  text-decoration: underline;
  text-underline-offset: 2px;
}

.dt-chat-msg-body.dt-chat-prose a:hover {
  opacity: 0.8;
}

/* Inline code in chat */
.dt-chat-msg-body code {
  background: oklch(var(--b2));
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.8125rem;
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

/* Code blocks in chat */
.dt-chat-msg-body pre {
  background: oklch(var(--b2));
  border: 1px solid oklch(var(--b3));
  border-radius: 0.5rem;
  padding: 0.75rem;
  overflow-x: auto;
  margin: 0.5rem 0;
  position: relative;
}

.dt-chat-msg-body pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.8125rem;
  line-height: 1.5;
  white-space: pre;
}

/* Table styling in chat */
.dt-chat-msg-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  margin: 0.5rem 0;
}

.dt-chat-msg-body table th {
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid oklch(var(--bc) / 0.2);
  padding: 0.375rem 0.5rem;
}

.dt-chat-msg-body table td {
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid oklch(var(--bc) / 0.1);
}

/* Chat message footer (metadata) */
.dt-chat-msg-footer {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.375rem;
  font-size: 0.6875rem;
  color: oklch(var(--bc) / 0.35);
}

/* Chat message actions (copy button) */
.dt-chat-msg-actions {
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.dt-chat-msg:hover .dt-chat-msg-actions {
  opacity: 1;
}

/* Typing indicator */
.dt-chat-typing {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
}

.dt-chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: oklch(var(--bc) / 0.3);
  animation: dt-chat-bounce 1.4s ease-in-out infinite;
}

.dt-chat-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.dt-chat-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dt-chat-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-4px); }
}

/* Chat tool call display */
.dt-chat-tool {
  margin: 0.375rem 0;
  border-radius: 0.375rem;
  border: 1px solid oklch(var(--bc) / 0.1);
  overflow: hidden;
}

.dt-chat-tool summary {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  background: oklch(var(--b2));
  color: oklch(var(--bc) / 0.6);
}

.dt-chat-tool summary:hover {
  background: oklch(var(--b3));
}

.dt-chat-tool pre {
  margin: 0;
  border: none;
  border-radius: 0;
  border-top: 1px solid oklch(var(--bc) / 0.1);
}

/* Code copy button inside chat messages */
.dt-chat-code-copy {
  position: absolute;
  top: 0.375rem;
  right: 0.375rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.dt-chat-msg-body pre:hover .dt-chat-code-copy {
  opacity: 1;
}

/* User message body styling */
.dt-chat-msg-user .dt-chat-msg-body {
  white-space: pre-wrap;
}

/* Streaming cursor — blinking caret during live rendering */
.dt-chat-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: oklch(var(--p));
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: dt-cursor-blink 0.8s step-end infinite;
}
@keyframes dt-cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Internal links in chat messages */
.dt-chat-msg-body a[data-internal] {
  cursor: pointer;
}
.dt-chat-msg-body a[data-internal]::after {
  content: " \2197";
  font-size: 0.7em;
  opacity: 0.5;
}
