/* ============================================================================
   CONVERT SECTION CONTAINER - LAYOUT
   ============================================================================ */

.mathpix-convert-section {
  margin-top: 1.5rem;
  padding: 1.25rem;
  border-radius: 4px;
}

.mathpix-download-buttons a {
  border-radius: 4px;
  vertical-align: middle;
  padding: 0.5rem 1rem 0.5rem 1rem;
  font-size: 1.2rem;
  text-align: center;
  margin: 0.5rem 0.3rem 0.5rem 0rem;
  text-decoration: none;
}

.mathpix-convert-section h3 {
  margin: 0 0 1rem 0;
  font-size: 1.15rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mathpix-convert-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ============================================================================
   FORMAT SELECTION FIELDSET - LAYOUT
   ============================================================================ */

.mathpix-convert-format-selection {
  border: none;
  padding: 0;
  margin: 0;
}

.mathpix-convert-format-selection legend {
  margin-bottom: 0.75rem;
}

.mathpix-convert-format-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.5rem;
}

.mathpix-convert-format-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  min-height: 44px;
  min-width: 44px;
}

.mathpix-convert-format-option:has(input:focus-visible) {
  outline-offset: 2px;
}

.mathpix-convert-format-option input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
  cursor: pointer;
  position: relative;
}

.mathpix-convert-format-option input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
}

.mathpix-convert-format-label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.9rem;
  font-weight: 500;
}

/* ============================================================================
   CONVERT ACTIONS - LAYOUT
   ============================================================================ */

.mathpix-convert-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.mathpix-convert-status {
  font-size: 0.9rem;
}

.mathpix-btn,
.mathpix-convert-download-btn {
  font-size: 0.8rem;
}

/* ============================================================================
   PROGRESS SECTION - LAYOUT
   ============================================================================ */

.mathpix-convert-progress {
  padding: 1rem;
  border-radius: 4px;
}

.mathpix-convert-progress-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mathpix-progress-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
}

.mathpix-progress-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

/* Processing state - spin the icon */
.mathpix-progress-item[data-status="processing"] .mathpix-progress-icon .icon {
  animation: spin 1s linear infinite;
}

.mathpix-progress-label {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
}

.mathpix-progress-status {
  font-size: 0.85rem;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* ============================================================================
   DOWNLOADS SECTION - LAYOUT
   ============================================================================ */

.mathpix-convert-downloads {
  padding: 1rem;
  border-radius: 4px;
}

.mathpix-convert-downloads h4 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mathpix-download-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ============================================================================
   ERRORS SECTION - LAYOUT
   ============================================================================ */

.mathpix-convert-errors {
  padding: 1rem;
  border-radius: 4px;
}

.mathpix-convert-errors h4 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mathpix-convert-error-list {
  margin: 0;
  padding-left: 1.5rem;
  font-size: 0.9rem;
}

.mathpix-convert-error-list li {
  margin-bottom: 0.25rem;
}

/* Downloads header with Download All button */
.mathpix-convert-downloads-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.mathpix-convert-downloads-header h4 {
  margin: 0;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 600px) {
  .mathpix-convert-section {
    padding: 1rem;
  }

  .mathpix-convert-format-grid {
    grid-template-columns: 1fr;
  }

  .mathpix-convert-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .mathpix-convert-status {
    text-align: center;
  }
}

/* ============================================================================
   REDUCED MOTION SUPPORT
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  .mathpix-convert-format-option,
  .mathpix-btn,
  .mathpix-convert-download-btn {
    transition: none;
  }

  @keyframes spin {
    from {
      transform: rotate(0deg);
    }
    to {
      transform: rotate(0deg);
    }
  }
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
  .mathpix-convert-section {
    display: none;
  }
}

/* ============================================================================
   PHASE 6.4: SPLIT VIEW LAYOUT
   ============================================================================ */

/* --------------------------------------------------------------------------
   Preview Section Container
   -------------------------------------------------------------------------- */

.convert-preview-section {
  margin-top: 1.5rem;
}

.convert-preview-title {
  margin: 0 0 1rem 0;
  font-size: 1.15rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* --------------------------------------------------------------------------
   Split View Container - Side by Side Layout
   -------------------------------------------------------------------------- */

.convert-split-view {
  display: flex;
  gap: 1rem;
  min-height: 350px;
}

/* --------------------------------------------------------------------------
   Pane Styling - Source and Preview
   -------------------------------------------------------------------------- */

.convert-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid currentColor;
  border-radius: 4px;
  overflow: hidden;
  min-width: 0; /* Prevent flex item overflow */
}

.convert-source-pane {
  max-width: 50%;
}

.convert-preview-pane {
  max-width: 50%;
}

/* --------------------------------------------------------------------------
   Pane Header
   -------------------------------------------------------------------------- */

.convert-pane-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid currentColor;
  flex-shrink: 0;
  min-height: 82px; /* 44px button + padding for equal height */
  box-sizing: border-box;
}

.convert-pane-title {
  font-size: 0.9rem;
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Copy Button
   -------------------------------------------------------------------------- */

.convert-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  transition: opacity 0.15s ease;
}

.convert-copy-btn:hover {
  opacity: 0.8;
}

.convert-copy-btn:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Pane Content Area
   -------------------------------------------------------------------------- */

.convert-pane-content {
  flex: 1;
  overflow: auto;
  padding: 1rem;
}

/* Code block within source pane */
.convert-source-pane .convert-pane-content {
  padding: 0;
}

.convert-source-pane .code-block-wrapper {
  height: 100%;
}

.convert-source-pane .code-block-wrapper pre {
  margin: 0;
  padding: 1rem;
  height: 100%;
  overflow: auto;
  border-radius: 0;
}

.convert-source-pane .code-block-wrapper pre code {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Prevent MathJax overflow in preview pane */
.convert-preview-pane .mathpix-rendered-content {
  overflow-x: auto;
}

.convert-preview-pane mjx-container {
  max-width: 100%;
  overflow-x: auto;
}

.convert-preview-pane mjx-container[jax="CHTML"][display="true"] {
  margin: 1em 0;
}

/* Rendered content within preview pane */
.convert-preview-pane .mathpix-rendered-content {
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   Responsive: Stack on Mobile (<768px)
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  .convert-split-view {
    flex-direction: column;
    min-height: auto;
  }

  .convert-source-pane,
  .convert-preview-pane {
    max-width: 100%;
    min-height: 250px;
  }

  .convert-pane-content {
    max-height: 300px;
  }
}

/* --------------------------------------------------------------------------
   Reduced Motion Support
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .convert-copy-btn {
    transition: none;
  }
}

/* --------------------------------------------------------------------------
   Print Styles - Hide Preview Section
   -------------------------------------------------------------------------- */

@media print {
  .convert-preview-section {
    display: none;
  }
}
/* ============================================================================
   PHASE 6.4: EDITOR TOOLBAR & EDIT MODE
   ============================================================================ */

/* --------------------------------------------------------------------------
   Editor Toolbar Container
   -------------------------------------------------------------------------- */

.convert-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-top: 1rem;
  border: 1px solid currentColor;
  border-radius: 4px;
}

/* --------------------------------------------------------------------------
   Toolbar Groups
   -------------------------------------------------------------------------- */

.convert-toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.convert-toolbar-edit-group {
  padding-right: 0.75rem;
  border-right: 1px solid currentColor;
}

.convert-toolbar-file-group {
  padding-left: 0;
}

/* --------------------------------------------------------------------------
   Toolbar Buttons
   -------------------------------------------------------------------------- */

.convert-toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
}

/* Edit button active state */
.convert-toolbar-btn[aria-pressed="true"] {
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Upload Label (styled as button)
   -------------------------------------------------------------------------- */

.convert-upload-label {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 500;

  border-radius: 4px;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  transition: opacity 0.15s ease;
}

.convert-upload-label:focus-within {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.convert-toolbar-btn .icon {
  width: 24px;
  height: 24px;
}

/* --------------------------------------------------------------------------
   Editor Status
   -------------------------------------------------------------------------- */

.convert-editor-status {
  margin-left: auto;
  font-size: 0.8rem;
  font-style: italic;
}

/* --------------------------------------------------------------------------
   Edit Mode Overlay - Inline (Default)
   -------------------------------------------------------------------------- */

.convert-edit-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 0;
}

.convert-edit-textarea {
  width: 100%;
  height: 100%;
  padding: 1rem;
  font-family: "Consolas", "Monaco", "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  border: 2px solid transparent;
  border-radius: 0;
  resize: none;
  box-sizing: border-box;
}

.convert-edit-textarea:focus {
  border-color: currentColor;
  box-shadow: inset 0 0 0 2px currentColor;
}

.convert-edit-textarea:focus-visible {
  outline: 3px solid currentColor;
  outline-offset: -3px;
}

/* Source pane content needs relative positioning for overlay */
.convert-source-pane .convert-pane-content {
  position: relative;
}

/* --------------------------------------------------------------------------
   Source Pane - Fullscreen Mode
   -------------------------------------------------------------------------- */

.convert-source-pane.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  max-width: 100%;
  min-height: 100vh;
  border-radius: 0;
}

.convert-source-pane.fullscreen .convert-pane-header {
  padding: 1rem 1.5rem;
  border-radius: 0;
}

.convert-source-pane.fullscreen .convert-pane-content {
  height: calc(100vh - 60px);
  max-height: none;
}

.convert-source-pane.fullscreen .convert-edit-textarea {
  padding: 1.5rem;
  font-size: 1rem;
  line-height: 1.6;
  min-height: calc(100vh - 80px);
}

/* Hide preview pane when source is fullscreen */
.convert-source-pane.fullscreen ~ .convert-preview-pane {
  display: none;
}

/* --------------------------------------------------------------------------
   Pane Header Button (Fullscreen Toggle)
   -------------------------------------------------------------------------- */

.convert-pane-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
  border-radius: 4px;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  transition: opacity 0.15s ease;
}

/* --------------------------------------------------------------------------
   Responsive: Stack toolbar on mobile
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  .convert-editor-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .convert-toolbar-edit-group {
    padding-right: 0;
    padding-bottom: 0.75rem;
    border-right: none;
    border-bottom: 1px solid currentColor;
  }

  .convert-toolbar-file-group {
    padding-left: 0;
    padding-top: 0.75rem;
  }

  .convert-toolbar-group {
    justify-content: center;
  }

  .convert-editor-status {
    margin-left: 0;
    text-align: center;
    margin-top: 0.5rem;
  }
}

/* --------------------------------------------------------------------------
   Reduced Motion Support
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .convert-toolbar-btn,
  .convert-upload-label {
    transition: none;
  }
}

/* --------------------------------------------------------------------------
   Print Styles - Hide Editor Toolbar
   -------------------------------------------------------------------------- */

@media print {
  .convert-editor-toolbar,
  .convert-edit-overlay {
    display: none;
  }
}

/* ============================================================================
   PHASE 6.5: SIMPLIFIED ALWAYS-ON EDITOR
   ============================================================================ */

/* --------------------------------------------------------------------------
   Editor Introduction Text
   -------------------------------------------------------------------------- */

.convert-editor-intro {
  margin: 0 0 1rem 0;
  font-size: 0.95rem;
  line-height: 1.5;
}

/* --------------------------------------------------------------------------
   Always-On Edit Mode (no overlay needed)
   -------------------------------------------------------------------------- */

.convert-edit-always-on {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 300px;
}

/* Drag-over state for file drops */
.convert-edit-textarea.drag-over {
  border-color: currentColor;
  box-shadow: inset 0 0 0 3px currentColor;
}

/* Remove the code block wrapper when in always-on mode */
.convert-source-pane .code-block-wrapper {
  display: none;
}

/* Ensure pane content fills space */
.convert-source-pane .convert-pane-content {
  display: flex;
  flex-direction: column;
}

/* --------------------------------------------------------------------------
   Toolbar Adjustments for Always-On Mode
   -------------------------------------------------------------------------- */

.convert-editor-toolbar {
  margin-top: 0.75rem;
}

/* Remove the border between edit and file groups since Edit button is gone */
.convert-toolbar-edit-group {
  padding-right: 0.75rem;
  border-right: 1px solid currentColor;
}
/* ============================================================================
   SVG ICON STYLES
   ============================================================================ */

/**
 * Base icon styling for inline SVG icons
 * Icons inherit colour from parent text (currentColor)
 */
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  flex-shrink: 0;
}

/* Icon in buttons - slightly larger for touch targets */
.mathpix-convert-download-btn .icon,
.mathpix-btn .icon {
  width: 1.2em;
  height: 1.2em;
  vertical-align: -0.2em;
}

/* Icon alignment in format labels */
.mathpix-convert-format-label .icon {
  width: 1.1em;
  height: 1.1em;
}

.mathpix-download-all-btn[hidden] {
  display: none;
}
