.directive-typst .preview-container {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 120px;
  overflow: hidden;
  border: 1px solid var(--color-spacer);
  border-radius: 8px;
  background-color: var(--color-background);
}

/* The document scrolls below the header. */
.directive-typst .typst-preview {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* Without the editor: the document and its downloads, one above the other
   at any width. */
.directive-typst.preview-only {
  flex-direction: column;
  gap: 0;
  height: auto;
}

.directive-typst.preview-only .preview-container {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.directive-typst.preview-only .download-pdf {
  border-right: none;
}

.directive-typst .typst-preview svg {
  max-width: 100%;
  height: auto;
  background-color: white;
}

.directive-typst .typst-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  gap: 12px;
  color: var(--color-text);
}

.directive-typst .typst-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-spacer);
  border-top-color: var(--color-brand, #3b82f6);
  border-radius: 50%;
  animation: typst-spin 1s linear infinite;
}

@keyframes typst-spin {
  to {
    transform: rotate(360deg);
  }
}

.directive-typst .typst-error {
  color: #dc2626;
  padding: 16px;
  background-color: #fef2f2;
  border-radius: 4px;
  font-family: monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.directive-typst .typst-error-overlay {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  z-index: 100;
  animation: typst-error-slide-in 0.3s ease-out;
}

@keyframes typst-error-slide-in {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.directive-typst .typst-error-content {
  background-color: #fef2f2;
  border: 2px solid #dc2626;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.directive-typst .typst-error-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background-color: #dc2626;
  color: white;
}

.directive-typst .typst-error-title {
  font-weight: 600;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.directive-typst .typst-error-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0;
  margin: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s;
  flex: none;
}

.directive-typst .typst-error-close:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.directive-typst .typst-error-message {
  padding: 16px;
  color: #dc2626;
  font-family: monospace;
  font-size: 0.8125rem;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

.directive-typst .buttons-container {
  display: flex;
  justify-content: center;
  width: 100%;
}

.directive-typst .buttons-container button {
  flex: none;
  border: 1px solid var(--color-spacer);
  border-radius: 8px;
  padding: 8px 24px;
}

.directive-typst .hidden {
  display: none !important;
}

.directive-typst:fullscreen.preview-only {
  height: 100dvh !important;
}

