/* ========== DESIGN SYSTEM ========== */
/* 8px grid · WCAG AA · semantic colour only · no transitions */

:root {
  /* Role-based readable font size — overridden at runtime by app-settings.js */
  --role-font: 16px;

  /* Brand */
  --primary-dark: #1e3a8a;
  --primary: #3b82f6;
  --primary-accent: #0369a1;

  /* Semantic states */
  --success: #166534;
  --warning: #92400e;
  --danger: #991b1b;

  /* Detection flag colours */
  --flag-high: #b91c1c;
  --flag-medium: #d97706;
  --flag-caution: #ca8a04;
  --flag-low: #15803d;

  /* Backgrounds */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;

  /* Text */
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-tertiary: #64748b;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  /* Borders */
  --border-light: #e2e8f0;
  --border-base: #cbd5e0;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* ========== GLOBAL ========== */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ========== TYPOGRAPHY ========== */

h1 {
  font-size: 32px;
  font-weight: 700;
  margin: 0 0 8px 0;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 16px 0 8px 0;
  color: var(--text-primary);
  line-height: 1.3;
}

h3 {
  font-size: 20px;
  font-weight: 600;
  margin: 16px 0 8px 0;
  color: var(--text-primary);
  line-height: 1.3;
}

p {
  margin: 0;
  line-height: 1.4;
}

small {
  font-size: 12px;
}

/* ========== BUTTONS ========== */

button {
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  padding: 12px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  outline: none;
  min-height: 44px;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Primary */
button:not(.secondary):not(.icon-only) {
  background: var(--primary);
  color: white;
}

button:not(.secondary):not(.icon-only):hover:not(:disabled) {
  background: var(--primary-dark);
}

/* Secondary */
button.secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

button.secondary:hover:not(:disabled) {
  background: var(--bg-tertiary);
}

/* Success */
button.success {
  background: var(--success);
  color: white;
}

button.success:hover:not(:disabled) {
  background: #15803d;
}

/* ========== FORM ELEMENTS ========== */

label {
  display: block;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

textarea {
  width: 100%;
  min-height: 160px;
  padding: 16px;
  font-size: 16px;
  line-height: 1.4;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  resize: vertical;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ========== CONTROLS ========== */

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 8px 0;
}

.note {
  color: var(--text-tertiary);
  font-size: 12px;
  margin: 8px 0 0 0;
  line-height: 1.4;
}

/* ========== PHASE MANAGEMENT ========== */

.analysis-tab {
  display: none;
}

.analysis-tab.active {
  display: block;
}

.phase {
  display: block;
}

.phase.hidden {
  display: none;
}

/* ========== FLAG LEGEND ========== */

.flag-legend {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 8px;
}

.flag-legend strong {
  display: block;
  color: var(--text-primary);
  font-size: 12px;
  margin-bottom: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.flag-legend > div:nth-child(2) {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  font-size: 12px;
  line-height: 1.4;
}

.flag-legend > div:nth-child(2) div {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

/* ========== FLAG SUMMARY ========== */

#flagSummary {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

/* ========== FLAGGED TEXT DISPLAY ========== */

.flagged-text-display {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 8px;
}

.flagged-text-display label {
  margin-bottom: 8px;
}

.flagged-text-content {
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  color: var(--text-primary);
  max-height: 256px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
}

/* ========== FLAG HIGHLIGHTING ========== */

.flag-high {
  background: var(--flag-high);
  color: white;
  padding: 2px 4px;
  border-radius: 3px;
  font-weight: 600;
  margin: 0 2px;
  cursor: help;
  display: inline-block;
}

.flag-medium {
  background: var(--flag-medium);
  color: white;
  padding: 2px 4px;
  border-radius: 3px;
  font-weight: 600;
  margin: 0 2px;
  cursor: help;
  display: inline-block;
}

.flag-low {
  background: var(--flag-low);
  color: white;
  padding: 2px 4px;
  border-radius: 3px;
  font-weight: 600;
  margin: 0 2px;
  cursor: help;
  display: inline-block;
}

.flagged-word {
  position: relative;
  cursor: text; /* hints that double-click will open inline editing */
}

/* Tooltips are rendered via JavaScript (position:fixed on document.body)
   to escape overflow:auto clipping on the output container. */

/* ========== OUTPUT VIEWER ========== */

.output-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.output-text-viewer {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 16px;
  min-height: 160px;
  max-height: 352px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  color: var(--text-primary);
}

.output-text-viewer:empty::before {
  content: 'Output will appear here';
  color: var(--text-tertiary);
  font-style: italic;
  font-size: 12px;
}

.output-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.copy-button {
  background: var(--success);
  color: white;
  font-weight: 600;
  font-size: 16px;
  padding: 12px 16px;
  border-radius: 6px;
  min-height: 44px;
}

.copy-button:hover:not(:disabled) {
  background: #15803d;
}

.copy-feedback {
  font-size: 12px;
  color: var(--success);
  font-weight: 600;
}

/* ========== STATUS ========== */

#status {
  font-size: 12px;
  color: var(--text-tertiary);
  padding: 4px 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ========== MODALS ========== */

.comment-modal,
.section-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}

.comment-modal.active,
.section-modal.active {
  display: flex;
}

.comment-box,
.section-box {
  background: var(--bg-primary);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  width: 90%;
  padding: 16px;
}

.comment-header {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-primary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.comment-text {
  font-size: 16px;
  line-height: 1.4;
  color: var(--text-primary);
  margin-bottom: 8px;
  min-height: 48px;
}

.comment-counter {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.section-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.section-buttons button {
  padding: 12px 16px;
  font-size: 12px;
}

.section-preview {
  background: var(--bg-secondary);
  padding: 8px;
  border-radius: 4px;
  margin: 8px 0;
  font-size: 12px;
  line-height: 1.4;
  max-height: 144px;
  overflow-y: auto;
  border: 1px solid var(--border-light);
}

/* ========== OUTPUT DISPLAY (Linear Flow) ========== */

.output-display-container {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
}

.output-display-locked {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 16px;
  overflow-x: hidden; /* prevent edit-mode inputs from triggering a horizontal scroll */
}

.output-display {
  font-size: var(--role-font, 16px);
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  color: var(--text-primary);
  max-height: 352px;
  overflow-y: auto;
  min-height: 96px;
  padding: 8px 0;
}

.output-display:empty::before {
  content: 'Analyzing…';
  color: var(--text-tertiary);
  font-style: italic;
  font-size: 12px;
}

/* Highlight classes — saturated solid colours with white text for maximum contrast */
.highlight-spike {
  background: #dc2626;
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

.highlight-spike:hover {
  background: #b91c1c;
}

.highlight-syntax {
  background: #ea580c;
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

.highlight-syntax:hover {
  background: #c2410c;
}

.highlight-formal {
  background: #b45309;
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

.highlight-formal:hover {
  background: #92400e;
}

.highlight-human {
  background: #15803d;
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

.highlight-human:hover {
  background: #166534;
}

.highlight-minor {
  background: #15803d;
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

.highlight-template {
  background: #7e22ce;
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

.highlight-template:hover {
  background: #6b21a8;
}

.highlight-fronted {
  background: #3730a3;
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

.highlight-fronted:hover {
  background: #312e81;
}

.highlight-forensic {
  background: #1d4ed8;
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

.highlight-forensic:hover {
  background: #1e40af;
}

.highlight-rhetoric {
  background: #c026d3;
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

.highlight-rhetoric:hover {
  background: #a21caf;
}

.highlight-puff {
  background: #be185d;
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

.highlight-puff:hover {
  background: #9d1650;
}

.highlight-formula {
  background: #65a30d;
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

.highlight-formula:hover {
  background: #4d7c0f;
}

.highlight-multi {
  color: white;
  padding: 1px 3px;
  border-radius: 2px;
  position: relative;
  cursor: help;
}

/* ── Simple mode — traffic-light colour overrides ── */
.simple-mode .highlight-spike,
.simple-mode .highlight-template,
.simple-mode .highlight-forensic,
.simple-mode .highlight-formula {
  background: #dc2626 !important;
  color: white !important;
}

.simple-mode .highlight-syntax,
.simple-mode .highlight-formal,
.simple-mode .highlight-fronted,
.simple-mode .highlight-rhetoric,
.simple-mode .highlight-puff {
  background: #d97706 !important;
  color: white !important;
}

.simple-mode .highlight-human {
  background: #15803d !important;
  color: white !important;
}

/* ========== MODULE LEGEND ========== */

.module-legend {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
}

.module-legend > div {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  font-size: 12px;
  line-height: 1.4;
}

.module-legend > div div {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ========== UTILITIES ========== */

.no-select {
  user-select: none;
  -webkit-user-select: none;
}

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

@media (max-width: 768px) {
  main {
    padding: 16px;
  }

  h1 {
    font-size: 24px;
    margin-bottom: 8px;
  }

  h2 {
    font-size: 20px;
    margin: 16px 0 8px 0;
  }

  button {
    font-size: 16px;
    padding: 12px 16px;
  }

  textarea {
    min-height: 144px;
    font-size: 16px;
  }

  .controls {
    margin: 8px 0;
    gap: 8px;
  }

  .flagged-text-content {
    max-height: 224px;
    font-size: 12px;
  }

  .output-text-viewer {
    max-height: 288px;
    font-size: 12px;
  }

  .flag-legend {
    padding: 16px;
  }

  .flag-legend > div:nth-child(2) {
    grid-template-columns: 1fr;
    gap: 8px;
    font-size: 12px;
  }

  .note {
    font-size: 12px;
  }

  .copy-button {
    font-size: 16px;
    padding: 12px 16px;
  }

  .header-tagline {
    display: none;
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
    padding-bottom: 8px;
  }

  .app-header h1 {
    margin-bottom: 0;
  }

  .app-controls {
    gap: 4px;
    width: 100%;
    flex-wrap: wrap;
  }
}

/* ========== QUOTA BAR ========== */

.quota-bar-container {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 8px 16px;
  margin-bottom: 8px;
}

.quota-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.quota-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

.quota-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  min-width: 64px;
  text-align: right;
}

.buy-credits-btn {
  padding: 8px 16px;
  min-height: 44px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.buy-credits-btn:hover {
  background: var(--primary-accent);
}

.quota-bar-background {
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0 0 0;
}

.quota-bar-fill {
  height: 100%;
  background: var(--flag-low);
  border-radius: 4px;
}

.quota-bar-text {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  pointer-events: none;
}

.quota-warning {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: var(--warning);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  margin-top: 8px;
}

/* ========== PRICING MODAL ========== */

.pricing-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.pricing-modal {
  background: var(--bg-primary);
  border-radius: 8px;
  padding: 32px;
  max-width: 600px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-secondary);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.modal-close:hover {
  background: var(--bg-tertiary);
}

.pricing-modal h2 {
  text-align: center;
  margin-bottom: 24px;
}

.pricing-tiers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.tier {
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  position: relative;
}

.tier:hover {
  border-color: var(--primary);
}

.tier.featured {
  border: 2px solid var(--primary);
  background: #f0f9ff;
}

.badge {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
}

.tier h3 {
  font-size: 16px;
  margin: 0 0 8px 0;
  color: var(--text-primary);
}

.tier .price {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  margin: 8px 0 4px 0;
}

.tier .cvt {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 4px 0;
}

.select-btn {
  width: 100%;
  padding: 12px 16px;
  min-height: 44px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  font-family: inherit;
}

.select-btn:hover {
  background: var(--primary-accent);
}

/* ========== DARK MODE ========== */

html.dark {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e0;
  --text-tertiary: #94a3b8;
  --text-muted: #64748b;
  --border-light: #334155;
  --border-base: #475569;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4);
}

html.dark body {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

html.dark textarea,
html.dark input[type="text"],
html.dark input[type="email"],
html.dark select {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-color: var(--border-base);
}

html.dark .output-display-locked,
html.dark .output-display {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-color: var(--border-base);
}

html.dark button.secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-base);
}

html.dark button.secondary:hover {
  background: var(--border-base);
}

html.dark #cvtBtn {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-base);
}

html.dark #cvtBtn:hover {
  background: var(--border-base);
}

html.dark .header-dropdown {
  background: var(--bg-primary);
  border-color: var(--border-base);
}

html.dark .header-dropdown button {
  color: var(--text-primary);
}

html.dark .header-dropdown button:hover {
  background: var(--bg-tertiary);
}

html.dark .module-legend {
  background: var(--bg-primary);
  border-color: var(--border-base);
  color: var(--text-primary);
}

/* All-resolved green border (student inline editing) */
.output-display-locked.all-resolved {
  border: 2px solid #16a34a;
  border-radius: 8px;
}

/* Copy Result active state */
#copyBtn.copy-result-active {
  background: #16a34a;
  color: white;
  font-weight: 700;
}

/* Copy Result disabled while in edit mode */
#copyBtn:disabled,
#copyBtn.copy-edit-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--bg-secondary);
  color: var(--text-tertiary);
}

/* ── Dark mode: pricing modal ── */

html.dark .pricing-modal {
  background: var(--bg-primary);
  color: var(--text-primary);
}

html.dark .pricing-modal h2,
html.dark .pricing-modal label {
  color: var(--text-primary);
}

/* Fix low-contrast preselected option in dark mode */
html.dark .purchase-option {
  color: var(--text-secondary);
  border-color: var(--border-base);
  background: var(--bg-secondary);
}

html.dark .purchase-option.active {
  background: var(--primary-dark);
  color: #ffffff;
  border-color: var(--primary);
}

html.dark .recipient-section input {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border-base);
}

html.dark .tier {
  background: var(--bg-secondary);
  border-color: var(--border-base);
  color: var(--text-primary);
}

html.dark .tier h3 { color: var(--text-primary); }

html.dark .tier:hover,
html.dark .tier.featured {
  border-color: var(--primary);
  background: #1e3a5f;
}

html.dark .tier .price { color: var(--primary); }
html.dark .tier .cvt   { color: var(--text-secondary); }

html.dark .recipient-feedback.ok  { color: #4ade80; }
html.dark .recipient-feedback.err { color: #f87171; }

/* ── Dark mode: JS-created help/history modals (override hardcoded inline #f9fafb) ── */

html.dark #helpModal table tr[style*="#f9fafb"],
html.dark #helpModal table tr:nth-child(even) {
  background: var(--bg-tertiary) !important;
}

html.dark #helpModal table th,
html.dark #helpModal table td {
  border-color: var(--border-base) !important;
  color: var(--text-secondary) !important;
}

html.dark #helpModal p[style*="color:#6b7280"] {
  color: var(--text-tertiary) !important;
}

/* ── Quickstart tutorial overlay ── */

#qs-overlay {
  pointer-events: none;
}

#qs-callout {
  pointer-events: all;
}

/* ── Role-aware font size for modals ── */
/* --role-font is set by app-settings.js updateRoleFeatures() */
.pricing-modal,
.pricing-modal p,
.pricing-modal .tier h3,
.pricing-modal .purchase-option {
  font-size: var(--role-font, 16px);
}

/* ═══════════════════════════════════════════════════════════════════
   EDITOR ENHANCED — mode toggle, sidebar, editor panel, undo badge
   ═══════════════════════════════════════════════════════════════════ */

/* ── Mode toggle button ─────────────────────────────────────────── */
.mode-toggle-btn {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0 12px;
  min-height: 30px;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.08s;
  white-space: nowrap;
}
.mode-toggle-btn:active { transform: scale(0.97); }
.mode-toggle-btn.mode-academic {
  background: var(--primary, #3b82f6);
  color: #fff;
}
.mode-toggle-btn.mode-academic:hover { background: #2563eb; }
.mode-toggle-btn.mode-standard {
  background: #d97706;
  color: #fff;
}
.mode-toggle-btn.mode-standard:hover { background: #b45309; }

/* ── Workspace / sidebar layout ─────────────────────────────────── */
#mainWorkspace.sidebar-open {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}
#mainWorkspace.sidebar-open #phaseWrapper {
  flex: 1;
  min-width: 0;
}
body.sidebar-open main {
  max-width: 1200px;
}
@media (max-width: 768px) {
  #mainWorkspace.sidebar-open { display: block !important; }
  body.sidebar-open main      { max-width: 900px; }
  #flagSidebar                { display: none !important; }
}

/* ── Flag sidebar ───────────────────────────────────────────────── */
#flagSidebar {
  width: 268px;
  flex-shrink: 0;
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
}
.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
}
.sidebar-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sidebar-progress {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
}
.sidebar-filter-row {
  margin-bottom: 10px;
}
.sidebar-filter-row select {
  width: 100%;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border-base);
  border-radius: 4px;
  background: var(--bg-primary);
  color: var(--text-primary);
}
.flag-list { display: flex; flex-direction: column; gap: 3px; }
.flag-item {
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.1s;
}
.flag-item:hover  { background: var(--bg-tertiary); }
.flag-item.active { border-color: var(--primary); background: rgba(59,130,246,0.06); }
.flag-item.dimmed { opacity: 0.35; pointer-events: none; }
.flag-item-header {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 3px;
}
.flag-item-num   { font-size: 10px; color: var(--text-tertiary); flex-shrink: 0; }
.flag-tag {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}
.flag-item-snippet {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Status dot */
.flag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-left: auto;
}
.flag-dot.pending  { background: #94a3b8; }
.flag-dot.accepted { background: #16a34a; }
.flag-dot.skipped  { background: #f59e0b; }
.flag-dot.custom   { background: #7e22ce; }

/* Filtered output */
#outputDisplay.filtered .flagged-word               { opacity: 0.25; transition: opacity 0.1s; }
#outputDisplay.filtered .flagged-word.filter-match  { opacity: 1; }

/* Accepted/skipped spans */
.flagged-word[data-status="skipped"] {
  text-decoration: line-through;
  opacity: 0.55;
}

/* ── Editor panel (floating suggestion/edit popup) ──────────────── */
#editorPanel {
  position: fixed;
  z-index: 1900;
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border-base, #cbd5e0);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.18);
  padding: 14px 16px;
  min-width: 240px;
  max-width: 320px;
  font-size: 13px;
  color: var(--text-primary);
  display: none;
}
html.dark #editorPanel { border-color: var(--border-base); }
.ep-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.ep-close {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--text-tertiary);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
  align-self: flex-start;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ep-close:hover { color: var(--text-primary); }
.ep-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.ep-original {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}
.ep-original em { font-style: italic; color: var(--text-secondary); }
.ep-reason {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-bottom: 10px;
}
.ep-loading {
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
  padding: 6px 0;
  margin-bottom: 8px;
}
.ep-suggestions { display: flex; flex-direction: column; gap: 5px; margin-bottom: 8px; }
.ep-suggestion-btn {
  text-align: left;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 12px;
  line-height: 1.35;
  transition: border-color 0.1s, background 0.1s;
}
.ep-suggestion-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--primary);
}
.ep-suggestion-btn .ep-num {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-right: 5px;
  font-weight: 600;
}
/* ArchaicAuthor style label badge inside suggestion buttons */
.ep-style-label {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--primary, #3b82f6);
  background: var(--bg-tertiary, #f1f5f9);
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 6px;
  white-space: nowrap;
}
/* Context highlight wrapper for ArchaicAuthor 3-sentence window */
.archaic-author-context {
  transition: background 0.2s;
}
.ep-action-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.ep-skip-btn {
  font-size: 12px;
  color: var(--text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
.ep-skip-btn:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.ep-custom-toggle {
  font-size: 12px;
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
.ep-custom-toggle:hover { background: var(--bg-tertiary); }
.ep-custom-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.ep-custom-input {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border-base);
  border-radius: 6px;
  font-size: 13px;
  min-width: 0;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: inherit;
}
.ep-confirm-btn {
  padding: 6px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.ep-confirm-btn:hover { background: #2563eb; }

/* ── Undo badge ─────────────────────────────────────────────────── */
#undoBadge {
  position: fixed;
  bottom: 70px;
  right: 22px;
  font-size: 11px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  padding: 3px 9px;
  border-radius: 10px;
  color: var(--text-secondary);
  z-index: 200;
  display: none;
  cursor: pointer;
  user-select: none;
}
#undoBadge:hover { background: var(--bg-secondary); }
