/* ============================================================================
   public/src/components/download-quiz-modal/download-quiz-modal.css
   Shared styles for the Download Quiz format-picker
   popup across all pages. Styles the markup built by showDownloadModal() in
   download-quiz-modal.js. Relies on the page's own generic .modal-overlay /
   .modal-card / .modal-header / .close-btn primitives for the outer shell.
   ============================================================================ */

.dl-modal-card {
  max-width: 520px;
  width: 95vw;
  padding: 0;
  overflow: hidden;
  text-align: initial;
  max-height: min(85vh, 640px);
  display: flex;
  flex-direction: column;
}

.dl-modal-card .modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.lesson-dl-modal-card .modal-header h2 {
  display: flex;
  align-items: center;
  gap: 9px;
}

.lesson-dl-modal-card .modal-header h2 svg {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
  color: var(--color-primary);
}

.lesson-dl-grid .export-card {
  min-height: 142px;
  justify-content: center;
  border-radius: 14px;
}

.lesson-dl-grid .export-card[data-format="html"] .export-icon img {
  border-radius: 10px;
}

.lesson-dl-grid .export-card[data-format="json"] .export-icon svg {
  color: #e4a84b;
}

/* ── Download-button loading spinner ──
   Used by withDownloadLoading() (download-quiz-modal.js) — a small,
   dependency-free spinner (no Lucide/icon-font required, unlike the
   previous <i data-lucide> approach, which silently failed to render on
   pages that never load the Lucide JS library, e.g. index.html). Sized
   to sit comfortably inside a normal button without widening it, so no
   accompanying loading text is needed. */
.dl-btn-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  opacity: 0.85;
  animation: dl-btn-spin 0.7s linear infinite;
}

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

/* ── Export cards with split download / copy actions ── */

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px 24px 24px;
  overflow-y: auto;
}

.export-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  direction: ltr;
  gap: 5px;
  padding: 16px 8px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--color-border);
  background: var(--color-background);
  color: var(--color-text-primary);
  cursor: pointer;
  transition:
    border-color 0.18s,
    background 0.18s,
    transform 0.18s,
    box-shadow 0.18s;
  font-family: inherit;
}

.export-card:hover,
.export-card:focus-visible {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: var(--shadow-md);
}

/* Fix #flicker: the hover "lift" must move the CONTENT, not the card box.
   When `transform: translateY(-3px)` was applied to .export-card itself,
   the whole bounding box jumped 3px up on hover, so a cursor close to the
   bottom edge left the box → :hover dropped → the card slid back down →
   :hover re-engaged — the reported "flickers when the mouse crosses the
   hover/normal boundary". Moving the transform to the pointer-events:none
   content child (which contributes no hit area) preserves the lift while
   keeping the card's hit box stationary. */
.export-card:hover .export-card-content,
.export-card:focus-visible .export-card-content {
  transform: translateY(-3px);
}

.export-card:active .export-card-content {
  transform: translateY(0);
}

.export-card-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  pointer-events: none;
  transition: transform 0.18s;
}

.export-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
}

.export-icon img,
.export-icon svg {
  display: block;
  width: 48px;
  height: 48px;
  max-width: 48px;
  max-height: 48px;
  object-fit: contain;
  border-radius: 8px;
}

.export-label {
  font-weight: 600;
  font-size: 0.82rem;
  text-align: center;
  color: var(--color-text-primary);
}

.export-extension {
  font-size: 0.7rem;
  color: var(--color-text-tertiary);
  text-align: center;
  margin-top: -3px;
}

.mode-copy-btn {
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-background);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition:
    border-color 0.15s,
    color 0.15s,
    background 0.15s;
  z-index: 2;
}

.mode-copy-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.mode-copy-btn.copied {
  border-color: var(--color-success, #16a34a);
  color: var(--color-success, #16a34a);
}

.mode-btn {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: 10px;
  border: 1.5px solid var(--color-border);
  background: var(--color-background);
  color: var(--color-text-primary);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  transition:
    border-color 0.18s,
    background 0.18s;
}

.mode-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.mode-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.download-source-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.download-source-actions .mode-btn {
  grid-column: auto;
  min-width: 0;
  text-decoration: none;
}

[data-theme="dark"] .export-card,
[data-theme="dark-slate"] .export-card,
[data-theme="dark"] .mode-btn,
[data-theme="dark-slate"] .mode-btn,
[data-theme="dark"] .mode-copy-btn,
[data-theme="dark-slate"] .mode-copy-btn {
  background: var(--color-surface, var(--color-background));
}

[data-theme="dark"] .export-card:hover,
[data-theme="dark-slate"] .export-card:hover,
[data-theme="dark"] .mode-btn:hover,
[data-theme="dark-slate"] .mode-btn:hover {
  background: var(--color-primary-light);
}

/* Phones: this modal may share the page with a fixed bottom-nav bar —
     pull the card height in further and pad its scrollable grid so the last
     row clears the nav instead of sitting underneath it. */
@media (max-width: 640px) {
  .dl-modal-card {
    width: 94vw;
    max-height: min(80vh, 80dvh);
  }

  .mode-grid {
    grid-template-columns: repeat(3, 1fr);
    padding: 12px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .dl-modal-card .modal-header {
    padding: 16px 16px 12px;
  }

  .lesson-dl-grid .export-card {
    min-height: 126px;
  }

  .download-source-actions {
    grid-template-columns: 1fr;
  }
}

/* ── Generation progress panel (PPTX/Word) ──────────────────────────────
   Shown in place of the format grid while a chunked, cancellable export
   (see export-to-pptx.js / export-to-word.js) is running. */
.dl-progress-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px 24px 28px;
  text-align: center;
}

.dl-progress-icon {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.dl-progress-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

.dl-progress-track {
  width: 100%;
  max-width: 320px;
  height: 10px;
  border-radius: 999px;
  background: var(--color-border-light, var(--color-border));
  overflow: hidden;
}

.dl-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--color-primary);
  transition: width 0.2s ease-out;
}

.dl-progress-pct {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}

.dl-progress-cancel {
  margin-top: 4px;
  padding: 8px 20px;
  border-radius: 8px;
  border: 1.5px solid var(--color-border);
  background: var(--color-background);
  color: var(--color-text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    border-color 0.15s,
    color 0.15s,
    background 0.15s;
}

.dl-progress-cancel:hover {
  border-color: var(--color-error, #ef4444);
  color: var(--color-error, #ef4444);
}

.dl-progress-cancelling {
  opacity: 0.6;
  pointer-events: none;
}

/* ── Settings panel (Step 5: answers/explanations/placement/background) ──
   Shown in place of the format grid, right after a pdf/pptx/docx/md card
   is clicked and before generation actually starts. */
.dl-settings-host {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.dl-settings-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 24px 20px;
}

.dl-settings-heading {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text-secondary);
  padding: 12px 4px 4px;
}

.dl-settings-rows {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.dl-settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--color-border);
}

/* Fix #separator: the previous `:last-child` rule only ever matched the
   row that happened to be last in DOM order, which — because rows with
   conditional visibility (the placement row, hidden until answers are
   toggled on) still count as "last" even while display:none — didn't
   reliably strip the border from whichever row is *visually* last.
   Explicit per-format overrides below cover the two real "last visible
   row" cases instead of relying on DOM-order luck. */
.dl-settings-row:last-child {
  border-bottom: none;
}

/* When the placement row is visible (answers included), it's the true
   last visible row and should carry no separator regardless of what
   comes after it in the DOM. */
.dl-settings-placement[style*="flex"] {
  border-bottom: none;
}

.dl-settings-row-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.dl-settings-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.dl-settings-row-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

.dl-settings-row-sub {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  line-height: 1.4;
}

/* "Include answers" is deliberately a confirm-gated button, not a
   toggle — flipping it on is a one-way reveal decision the user should
   consciously make, per explicit product feedback. */
.dl-settings-answers-btn {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1.5px solid var(--color-border);
  background: var(--color-background);
  color: var(--color-text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition:
    border-color 0.15s,
    background 0.15s,
    color 0.15s;
}

.dl-settings-answers-btn:hover {
  border-color: var(--color-primary);
}

.dl-settings-answers-btn.active {
  border-color: var(--color-success, #16a34a);
  background: rgba(34, 197, 94, 0.12);
  color: var(--color-success, #16a34a);
}

/* Generic on/off switch, used for the ordinary toggle rows
   (user's answers / explanations) — kept visually distinct from the
   answers-reveal button above. */
.dl-switch {
  flex-shrink: 0;
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  border: none;
  background: var(--color-border-light, var(--color-border));
  cursor: pointer;
  padding: 0;
  transition: background 0.18s;
}

.dl-switch.on {
  background: var(--color-primary);
}

.dl-switch-knob {
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: inset-inline-start 0.18s;
}

.dl-switch.on .dl-switch-knob {
  inset-inline-start: 21px;
}

/* Two-way segmented control (answer placement / pdf background) */
.dl-settings-segmented {
  display: flex;
  gap: 6px;
}

.dl-segmented-btn {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1.5px solid var(--color-border);
  background: var(--color-background);
  color: var(--color-text-secondary);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s,
    color 0.15s;
}

.dl-segmented-btn:hover {
  border-color: var(--color-primary);
}

.dl-segmented-btn.active {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.dl-settings-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--color-border);
}

.dl-settings-back,
.dl-settings-continue {
  flex: 1;
  padding: 10px 16px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s,
    opacity 0.15s;
}

.dl-settings-back {
  border: 1.5px solid var(--color-border);
  background: var(--color-background);
  color: var(--color-text-primary);
}

.dl-settings-back:hover {
  border-color: var(--color-text-secondary);
}

.dl-settings-continue {
  border: 1.5px solid var(--color-primary);
  background: var(--color-primary);
  color: #fff;
}

.dl-settings-continue:hover {
  opacity: 0.92;
}

@media (max-width: 640px) {
  .dl-settings-panel {
    padding: 4px 16px 16px;
  }
}