/**
 * Markdown Viewer & Toolkit — Markdown Formatter CSS
 * Specialized dual-pane layout, syntax highlighting theme tokens, and diff metrics.
 */

/* Main Formatter Dual-Pane Workspace */
.formatter-workspace-panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 580px;
  background-color: var(--bg-surface);
}

/* Secondary Toolbar: Presets & Action Trigger */
.formatter-settings-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
}

.formatter-presets-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Primary Format Action Button */
.btn-format-primary {
  background-color: var(--brand-primary);
  color: #ffffff !important;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  border: 1px solid var(--brand-primary);
  transition: all var(--transition);
}

.btn-format-primary:hover {
  background-color: var(--brand-primary-hover);
  box-shadow: var(--shadow-md);
}

/* Formatted Output Viewer Pane */
.pane-formatted {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--bg-surface);
  position: relative;
}

/* Tab Switcher for Formatted View (Source vs Rendered Preview) */
.view-tabs-control {
  display: inline-flex;
  background-color: var(--bg-surface-alt);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: calc(var(--radius-sm) - 1px);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.tab-btn:hover {
  color: var(--text-main);
}

.tab-btn.active {
  background-color: var(--bg-surface);
  color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

/* Formatted Code Block Container */
.formatted-code-container {
  flex: 1;
  position: relative;
  overflow: auto;
  max-height: 680px;
  background-color: var(--bg-page);
}

.formatted-code-pre {
  margin: 0;
  padding: 1.25rem 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre;
  word-break: normal;
  overflow-x: auto;
  color: var(--text-main);
  background-color: transparent;
  border: none;
  border-radius: 0;
  box-sizing: border-box;
  tab-size: 2;
}

/* Diff / Formatting Changes Metrics Bar */
.formatter-diff-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25rem;
  padding: 0.45rem 1rem;
  background-color: var(--bg-surface-alt);
  border-top: 1px solid var(--border-light);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.diff-stat-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.diff-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.7rem;
}

.diff-badge.clean {
  background-color: rgba(22, 163, 74, 0.1);
  color: var(--color-success);
}

.diff-badge.notice {
  background-color: var(--brand-accent-subtle);
  color: var(--brand-primary);
}

/* =====================================================================
   Markdown Syntax Highlighting Theme Tokens
   ===================================================================== */
.tok-hash {
  color: var(--brand-primary);
  font-weight: 700;
}
.tok-heading {
  font-weight: 700;
  color: var(--text-main);
}
.tok-bold {
  font-weight: 700;
}
.tok-italic {
  font-style: italic;
}
.tok-bold-italic {
  font-weight: 700;
  font-style: italic;
}
.tok-strike {
  text-decoration: line-through;
  opacity: 0.75;
}
.tok-link {
  color: var(--brand-primary);
}
.tok-img {
  color: #b45309;
}
.tok-url {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.tok-inline-code {
  font-family: var(--font-mono);
  background-color: var(--code-bg);
  border: 1px solid var(--code-border);
  color: var(--brand-primary);
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-xs);
}
.tok-fence {
  color: var(--text-subtle);
  font-weight: 600;
}
.tok-code-block {
  color: #15803d;
}
.tok-quote {
  color: var(--text-muted);
  font-style: italic;
}
.tok-bullet {
  color: var(--brand-primary);
  font-weight: 700;
}
.tok-table {
  color: var(--text-main);
}
.tok-table-sep {
  color: var(--border-medium);
  font-weight: 500;
}
.tok-yaml-delim {
  color: #b45309;
  font-weight: 700;
}

/* Dark theme syntax token overrides */
[data-theme="dark"] .tok-hash {
  color: var(--brand-primary);
}
[data-theme="dark"] .tok-link {
  color: var(--brand-primary);
}
[data-theme="dark"] .tok-img {
  color: #f59e0b;
}
[data-theme="dark"] .tok-url {
  color: var(--text-muted);
}
[data-theme="dark"] .tok-inline-code {
  background-color: var(--code-bg);
  border: 1px solid var(--code-border);
  color: var(--brand-accent);
}
[data-theme="dark"] .tok-fence {
  color: var(--text-subtle);
}
[data-theme="dark"] .tok-code-block {
  color: #4ade80;
}
[data-theme="dark"] .tok-quote {
  color: var(--text-muted);
}
[data-theme="dark"] .tok-bullet {
  color: var(--brand-accent);
}
[data-theme="dark"] .tok-table {
  color: var(--text-main);
}
[data-theme="dark"] .tok-table-sep {
  color: var(--border-medium);
}
[data-theme="dark"] .tok-yaml-delim {
  color: #fbbf24;
}

/* Responsive Stacking for Small Devices */
@media (max-width: 860px) {
  .formatter-workspace-panes {
    grid-template-columns: 1fr;
  }
  
  .pane-editor {
    border-right: none;
    border-bottom: 1px solid var(--border-light);
    min-height: 320px;
  }

  .formatted-code-container {
    max-height: 480px;
  }

  .formatter-settings-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .formatter-presets-group {
    justify-content: space-between;
  }
}
