/**
 * @component Workspace Viewer Markdown Preview
 * @description Rich markdown preview with inline images, cards, tables, players
 * @category Components
 * @darkmode true
 */

/* ============================================================
   Preview container
   ============================================================ */

.ws-viewer-preview {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  display: none;
}

.md-preview-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 24px;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary, #c9d1d9);
}

/* ============================================================
   Typography
   ============================================================ */

.md-preview-content h1,
.md-preview-content h2,
.md-preview-content h3,
.md-preview-content h4,
.md-preview-content h5,
.md-preview-content h6 {
  margin: 1.2em 0 0.5em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary, #c9d1d9);
}

.md-preview-content h1 {
  font-size: 1.5em;
  border-bottom: 1px solid var(--border-default, #30363d);
  padding-bottom: 0.3em;
}
.md-preview-content h2 {
  font-size: 1.3em;
  border-bottom: 1px solid var(--border-default, #30363d);
  padding-bottom: 0.2em;
}
.md-preview-content h3 {
  font-size: 1.15em;
}
.md-preview-content h4 {
  font-size: 1em;
}

.md-preview-content p {
  margin: 0.5em 0;
}

.md-preview-content a {
  color: var(--accent-primary, #58a6ff);
  text-decoration: none;
}

.md-preview-content a:hover {
  text-decoration: underline;
}

.md-preview-content strong {
  font-weight: 600;
}

.md-preview-content hr {
  border: none;
  border-top: 1px solid var(--border-default, #30363d);
  margin: 1.5em 0;
}

/* ============================================================
   Inline code & code blocks
   ============================================================ */

.md-inline-code {
  background: var(--bg-tertiary, #21262d);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  font-size: 0.9em;
  font-family: "JetBrains Mono", "Monaco", "Menlo", monospace;
}

.md-code-block {
  position: relative;
  margin: 0.8em 0;
  background: var(--bg-tertiary, #161b22);
  border: 1px solid var(--border-default, #30363d);
  border-radius: 6px;
  overflow: hidden;
}

.md-code-block pre {
  margin: 0;
  padding: 12px 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}

.md-code-block code {
  font-family: "JetBrains Mono", "Monaco", "Menlo", monospace;
}

.md-code-lang {
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 11px;
  color: var(--text-muted, #8b949e);
  opacity: 0.7;
}

/* ============================================================
   Tables
   ============================================================ */

.md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.8em 0;
  font-size: 13px;
}

.md-table th,
.md-table td {
  padding: 6px 12px;
  border: 1px solid var(--border-default, #30363d);
  text-align: left;
}

.md-table th {
  background: var(--bg-tertiary, #21262d);
  font-weight: 600;
}

.md-table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

/* ============================================================
   Images
   ============================================================ */

.md-image {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 0.5em 0;
  border: 1px solid var(--border-default, #30363d);
}

/* ============================================================
   Audio & Video players
   ============================================================ */

.md-player {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0.5em 0;
  padding: 8px 12px;
  background: var(--bg-tertiary, #161b22);
  border: 1px solid var(--border-default, #30363d);
  border-radius: 6px;
}

.md-player audio {
  width: 100%;
  height: 36px;
}

.md-player video {
  max-width: 100%;
  border-radius: 4px;
}

.md-player-label {
  font-size: 12px;
  color: var(--text-muted, #8b949e);
}

/* ============================================================
   Expandable cards (<details>)
   ============================================================ */

.md-preview-content details {
  margin: 0.8em 0;
  border: 1px solid var(--border-default, #30363d);
  border-radius: 6px;
  overflow: hidden;
}

.md-preview-content summary {
  padding: 8px 12px;
  background: var(--bg-tertiary, #21262d);
  cursor: pointer;
  font-weight: 500;
  user-select: none;
  list-style: none;
}

.md-preview-content summary::-webkit-details-marker {
  display: none;
}

.md-preview-content summary::before {
  content: "\25B6";
  display: inline-block;
  margin-right: 8px;
  font-size: 0.7em;
  transition: transform 0.2s ease;
}

.md-preview-content details[open] > summary::before {
  transform: rotate(90deg);
}

.md-preview-content details > :not(summary) {
  padding: 0 12px;
}

/* ============================================================
   Blockquotes
   ============================================================ */

.md-blockquote {
  margin: 0.5em 0;
  padding: 4px 12px;
  border-left: 3px solid var(--accent-primary, #3b82f6);
  color: var(--text-secondary, #8b949e);
}

/* ============================================================
   Lists
   ============================================================ */

.md-list-item {
  margin: 0.2em 0;
  padding-left: 4px;
}

/* ============================================================
   View mode toggle buttons
   ============================================================ */

.ws-viewer-mode-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted, #8b949e);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
  margin-left: auto;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.15s ease;
}

.ws-viewer-mode-toggle-btn:hover {
  opacity: 1;
  color: var(--text-primary, #d4e1e8);
}

/* ============================================================
   Light mode overrides
   ============================================================ */

[data-theme="light"] .md-preview-content {
  color: var(--text-primary, #1f2328);
}

[data-theme="light"] .md-code-block {
  background: var(--bg-tertiary, #f6f8fa);
}

[data-theme="light"] .md-inline-code {
  background: var(--bg-tertiary, #f6f8fa);
}

[data-theme="light"] .md-player {
  background: var(--bg-tertiary, #f6f8fa);
}
