/**
 * TalentTuner Surgical Resume Optimizer
 * 2025 Redesign - Three-Column Interactive Layout
 */

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  background: rgba(13, 18, 32, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  min-width: 300px;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: slideInRight 0.3s ease;
  display: flex;
  align-items: start;
  gap: 0.75rem;
}

.toast.success {
  border-left: 3px solid var(--accent-success);
}

.toast.error {
  border-left: 3px solid var(--accent-danger);
}

.toast.warning {
  border-left: 3px solid var(--accent-warning);
}

.toast.info {
  border-left: 3px solid var(--accent-primary);
}

.toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.toast-content {
  flex: 1;
}

.toast-message {
  color: var(--text-primary);
  font-size: 0.9rem;
  margin: 0;
  line-height: 1.4;
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition: color 0.2s ease;
}

.toast-close:hover {
  color: var(--text-primary);
}

@keyframes slideInRight {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(400px);
    opacity: 0;
  }
}

.toast.hiding {
  animation: slideOutRight 0.3s ease forwards;
}

/* ============================================================================
   CSS VARIABLES & THEME
   ============================================================================ */
:root {
  /* Dark theme colors */
  --bg-primary: #0b0e14;
  --bg-secondary: #0f1420;
  --bg-card: #141c2e;
  --bg-hover: #1a2338;

  /* Borders & dividers */
  --border-color: #232a3b;
  --border-hover: #344166;

  /* Text colors */
  --text-primary: #e9eefc;
  --text-secondary: #b9c3df;
  --text-muted: #7d8ba8;

  /* Accent colors */
  --accent-primary: #7aa2ff;
  --accent-success: #79f0c6;
  --accent-danger: #ff7a9b;
  --accent-warning: #f7d774;

  /* Edit category colors */
  --color-keyword: #82aaff;
  --color-action: #a7f3d0;
  --color-metric: #c5a3ff;
  --color-clarity: #ffd493;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.35);

  /* Border radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* Spacing */
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* Typography */
  --font-sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* ============================================================================
   BASE STYLES
   ============================================================================ */
.optimize-page {
  background: linear-gradient(180deg, var(--bg-primary) 0%, #0d1220 100%);
  min-height: 100vh;
  color: var(--text-primary);
  font-family: var(--font-sans);
  overflow-x: hidden; /* Critical: prevent horizontal scroll at page level */
  max-width: 100vw; /* Ensure page respects viewport width */
  box-sizing: border-box; /* Include padding in width calculations */
}

/* Hide feedback button and power plan on optimize pages */
.optimize-page #feedback-widget,
.optimize-page #crisp-chatbox,
.optimize-page .intercom-launcher,
.optimize-page [class*="feedback"],
.optimize-page [class*="power-plan"],
.optimize-page [id*="power-plan"] {
  display: none !important;
}

.optimize-page-container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 var(--space-md);
  /* overflow-x: hidden removed - breaks position: sticky for score bar */
  width: 100%; /* Ensure container respects viewport */
  box-sizing: border-box; /* Include padding in width */
}

/* Hidden utility */
.hidden {
  display: none !important;
}

/* ============================================================================
   SCORE BAR (Sticky Header)
   ============================================================================ */
.score-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(13, 18, 32, 0.85);
  backdrop-filter: saturate(1.2) blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  margin: var(--space-md) 0;
  padding: var(--space-md);
}

.score-bar-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-md);
}

.scores-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.score-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.score-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.score-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.score-original .score-value {
  color: #9fb4ff;
}

.score-optimized .score-value {
  color: var(--accent-success);
}

.score-arrow {
  color: var(--text-muted);
  font-size: 20px;
}

.score-delta {
  padding: 6px 12px;
  border: 1px dashed var(--border-color);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-secondary);
}

.score-actions {
  display: flex;
  gap: var(--space-sm);
}

.btn-finalize {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, #67b3ff 100%);
  color: var(--bg-primary);
  font-weight: 700;
  font-size: 14px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 12px rgba(122, 162, 255, 0.3);
}

.btn-finalize:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(122, 162, 255, 0.4);
}

.btn-finalize:active:not(:disabled) {
  transform: translateY(0);
}

.btn-finalize:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-icon {
  flex-shrink: 0;
}

/* ============================================================================
   THREE-COLUMN WORKSPACE
   ============================================================================ */
.optimize-workspace {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr; /* Fluid columns - no minmax to prevent overflow */
  gap: var(--space-md);
  margin: var(--space-md) 0;
  align-items: stretch;
  max-width: 100%; /* Prevent overflow */
  overflow-x: hidden; /* Safety net */
}

.column {
  background: linear-gradient(180deg, var(--bg-secondary) 0%, #0f172a 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  min-height: 600px;
  max-height: 80vh;
  min-width: 0; /* Allow flex children to shrink below content size */
  overflow-x: auto; /* Individual column scroll if needed */
}

.column-header {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.column-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: #d9e3ff;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.header-icon {
  color: var(--accent-primary);
}

.column-content {
  flex: 1;
  padding: var(--space-md);
  overflow-y: auto;
  overflow-x: auto; /* Allow horizontal scroll within column if content is too wide */
  max-width: 100%; /* Respect column width */
  box-sizing: border-box; /* Include padding in width */
}

/* Resume text display */
.resume-text {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
}

.resume-line {
  margin-bottom: 0; /* No margin by default */
  white-space: pre-wrap; /* Preserve spaces and wrapping */
  word-wrap: break-word;
}

/* Add spacing only for paragraph breaks (when line has content) */
.resume-line + .resume-line {
  margin-top: 2px; /* Minimal spacing between consecutive lines */
}

/* Paragraph spacing: when preceded by empty line marker */
.resume-paragraph-break {
  height: 1em; /* Single line height for paragraph breaks */
  display: block;
}

/* Custom scrollbar */
.column-content::-webkit-scrollbar {
  width: 10px;
}

.column-content::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.column-content::-webkit-scrollbar-thumb {
  background: #2a3550;
  border-radius: var(--radius-sm);
}

.column-content::-webkit-scrollbar-thumb:hover {
  background: #344166;
}

/* ============================================================================
   LEGEND (Category Filter Pills)
   ============================================================================ */
.legend {
  display: flex;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
  flex-wrap: wrap;
}

.legend-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.legend-keyword {
  border-bottom: 3px solid var(--color-keyword);
}

.legend-action {
  border-bottom: 3px solid var(--color-action);
}

.legend-metric {
  border-bottom: 3px solid var(--color-metric);
}

.legend-clarity {
  border-bottom: 3px solid var(--color-clarity);
}

.legend-pill:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.legend-pill.active {
  background: var(--bg-hover);
}

.pill-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: rgba(122, 162, 255, 0.2);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-primary);
}

/* ============================================================================
   DORMANT STATE (Before Generation)
   ============================================================================ */
.dormant-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-xl);
  gap: var(--space-lg);
  min-height: 400px;
}

.dormant-icon {
  color: var(--accent-primary);
  opacity: 0.8;
}

.dormant-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.dormant-description {
  max-width: 480px;
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.btn-generate {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, #67b3ff 100%);
  color: var(--bg-primary);
  font-weight: 800;
  font-size: 16px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 6px 20px rgba(122, 162, 255, 0.35);
}

.btn-generate:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(122, 162, 255, 0.45);
}

.btn-generate:active {
  transform: translateY(0);
}

/* ============================================================================
   BUILDING STATE (AI Processing)
   ============================================================================ */
.building-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
  gap: var(--space-lg);
  min-height: 400px;
}

.building-animation {
  width: 100%;
  max-width: 500px;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: var(--space-md);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-success));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.building-message {
  text-align: center;
  font-size: 15px;
  color: var(--text-secondary);
  margin: 0 0 var(--space-lg) 0;
}

.building-steps {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: 100%;
}

.building-step {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  opacity: 0.4;
  transition: opacity 0.3s ease;
}

.building-step.active {
  opacity: 1;
  border-color: var(--accent-primary);
}

.step-icon {
  font-size: 20px;
}

.step-text {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ============================================================================
   EDIT HIGHLIGHTING & TOOLTIPS
   ============================================================================ */
.edit-highlight {
  position: relative;
  display: inline;
  cursor: pointer;
  padding-bottom: 2px;
  transition: background-color 0.2s ease;
}

.edit-highlight.edit-keyword {
  box-shadow: inset 0 -3px 0 var(--color-keyword);
}

.edit-highlight.edit-action {
  box-shadow: inset 0 -3px 0 var(--color-action);
}

.edit-highlight.edit-metric {
  box-shadow: inset 0 -3px 0 var(--color-metric);
}

.edit-highlight.edit-clarity {
  box-shadow: inset 0 -3px 0 var(--color-clarity);
}

.edit-highlight.rejected {
  box-shadow: none;
  opacity: 0.6;
  text-decoration: line-through;
  text-decoration-color: var(--accent-danger);
}

/* Tooltip */
.edit-tooltip {
  position: fixed; /* Changed from absolute to prevent clipping */
  left: 0; /* Will be set by JavaScript */
  top: 0; /* Will be set by JavaScript */
  transform: translateX(-50%);
  width: 320px;
  max-width: 90vw;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-lg);
  z-index: 10000; /* Higher than modal */
  display: none;
  pointer-events: all;
  opacity: 0;
  transition: opacity 0.15s ease;
}

/* JavaScript-controlled visibility */
.edit-tooltip.visible {
  display: block;
  opacity: 1;
}

/* Highlight hover effect - but don't show tooltip */
.edit-highlight:hover {
  cursor: pointer;
  opacity: 0.9;
}

/* Tooltip arrow */
.edit-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--border-color);
}

.tooltip-original {
  font-family: var(--font-mono);
  font-size: 12px;
  color: #9fb4ff;
  margin-bottom: var(--space-sm);
  padding: var(--space-xs);
  background: rgba(159, 180, 255, 0.1);
  border-radius: var(--radius-sm);
}

.tooltip-original s {
  opacity: 0.7;
}

.tooltip-rationale {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.tooltip-actions {
  display: flex;
  gap: var(--space-xs);
}

.tooltip-btn {
  flex: 1;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tooltip-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.tooltip-btn.btn-accept {
  border-color: rgba(121, 240, 198, 0.3);
  background: rgba(121, 240, 198, 0.1);
  color: var(--accent-success);
}

.tooltip-btn.btn-reject {
  border-color: rgba(255, 122, 155, 0.3);
  background: rgba(255, 122, 155, 0.1);
  color: var(--accent-danger);
}

/* Active state - show which action is current */
.tooltip-btn.active {
  font-weight: 700;
  box-shadow: 0 0 0 2px currentColor;
  opacity: 1;
}

.tooltip-btn:not(.active) {
  opacity: 0.5;
}

.tooltip-btn:not(.active):hover {
  opacity: 0.8;
}

/* ============================================================================
   OPTIMIZATION PANEL (Right Column)
   ============================================================================ */
.panel-content {
  padding: 0;
}

.panel-dormant {
  padding: var(--space-xl);
  text-align: center;
}

.panel-empty-message {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.panel-actions {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.panel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.panel-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.btn-accept-all {
  background: rgba(121, 240, 198, 0.1);
  border-color: rgba(121, 240, 198, 0.3);
  color: var(--accent-success);
}

.btn-reject-all {
  background: rgba(255, 122, 155, 0.1);
  border-color: rgba(255, 122, 155, 0.3);
  color: var(--accent-danger);
}

.panel-select {
  padding: 8px 12px;
  font-size: 13px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
}

.panel-edits {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.edit-category {
  margin-bottom: var(--space-md);
}

.category-header {
  margin: 0 0 var(--space-sm) 0;
  font-size: 13px;
  font-weight: 700;
  color: #cfd9ff;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
}

.category-header:hover {
  background: var(--bg-hover);
}

.category-header-content {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex: 1;
}

.category-collapse-icon {
  margin-left: auto;
  transition: transform 0.3s ease;
  color: var(--text-muted);
}

.category-collapse-icon.collapsed {
  transform: rotate(-90deg);
}

.category-count {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.category-edits {
  display: grid;
  gap: var(--space-sm);
  overflow: hidden;
  transition: all 0.3s ease;
}

.category-edits.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

.edit-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}

.edit-chip:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.chip-content {
  flex: 1;
  min-width: 0;
}

.chip-title {
  font-size: 13px;
  color: #e3eafe;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.chip-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.chip-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.chip-btn {
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.chip-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ============================================================================
   LOADING & SKELETON STATES
   ============================================================================ */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  gap: var(--space-md);
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  font-size: 14px;
  color: var(--text-secondary);
}

.loading-skeleton {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.skeleton-line {
  height: 12px;
  background: linear-gradient(90deg, var(--bg-card), #1a2338, var(--bg-card));
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.5s infinite;
}

.skeleton-line.short {
  width: 75%;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ============================================================================
   FINALIZE MODAL
   ============================================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 20, 0.75);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.modal-container {
  width: min(920px, 95vw);
  max-height: 90vh;
  background: linear-gradient(180deg, var(--bg-secondary), #0d1426);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  padding: var(--space-xs);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-overlay .modal-content {
  flex: 1;
  width: 100%; /* Ensure it fills container width */
  max-width: none; /* Override any inherited max-width from dashboard CSS */
  padding: var(--space-lg);
  overflow-y: auto;
  box-sizing: border-box; /* Include padding in width calculation */
  background: transparent; /* Explicitly set to show modal-container gradient (no dashboard CSS bleeding) */
}

.modal-description {
  margin: 0 0 var(--space-lg) 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.modal-section {
  margin-bottom: var(--space-xl);
}

.modal-section-title {
  margin: 0 0 var(--space-md) 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md);
}

.template-card {
  padding: var(--space-md);
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}

.template-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.template-card.selected {
  border-color: var(--accent-primary);
  background: rgba(122, 162, 255, 0.05);
  box-shadow: 0 2px 8px rgba(122, 162, 255, 0.2);
}

.template-card.selected:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(122, 162, 255, 0.3);
}

.template-preview {
  height: 140px;
  background: linear-gradient(180deg, var(--bg-secondary), #0b1222);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
}

/* Ensure text inside template preview (white background) doesn't inherit dark theme colors */
.template-preview * {
  /* Reset any inherited color - inline styles will override this */
  color: initial;
}

.template-preview div[style*="color"] {
  /* Let inline color styles work properly */
  color: inherit;
}

.template-name {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.template-desc {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.format-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-md);
}

.format-card {
  padding: var(--space-lg);
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.format-card:hover {
  border-color: var(--border-hover);
}

.format-card.selected {
  border-color: var(--accent-primary);
  background: rgba(122, 162, 255, 0.05);
}

.format-icon {
  color: var(--accent-primary);
  margin-bottom: var(--space-sm);
}

.format-name {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.format-desc {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.modal-footer {
  padding: var(--space-lg);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

.modal-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-cancel {
  background: transparent;
  color: var(--text-secondary);
}

.btn-cancel:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-download {
  background: linear-gradient(135deg, var(--accent-success) 0%, #3cd4a7 100%);
  color: var(--bg-primary);
  border-color: transparent;
}

.btn-download:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(121, 240, 198, 0.3);
}

/* ============================================================================
   AUTH REQUIRED STATE
   ============================================================================ */
.auth-required-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: var(--space-xl);
}

.auth-required-card {
  max-width: 400px;
  padding: var(--space-xl);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  text-align: center;
}

.auth-icon {
  color: var(--accent-primary);
  margin-bottom: var(--space-lg);
}

.auth-title {
  margin: 0 0 var(--space-sm) 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.auth-message {
  margin: 0 0 var(--space-lg) 0;
  font-size: 15px;
  color: var(--text-secondary);
}

.btn-auth {
  display: inline-block;
  padding: 12px 24px;
  background: var(--accent-primary);
  color: var(--bg-primary);
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.btn-auth:hover {
  background: #67b3ff;
  transform: translateY(-1px);
}

/* ============================================================================
   REPORT SELECTOR
   ============================================================================ */
#report-selector {
  padding: var(--space-xxl) var(--space-lg);
  max-width: 1200px;
  margin: 0 auto;
}

.selector-container {
  width: 100%;
}

.selector-header {
  text-align: center;
  margin-bottom: var(--space-xxl);
}

.selector-title {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.selector-description {
  font-size: 16px;
  color: var(--text-secondary);
}

.reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-lg);
}

.report-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.report-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(122, 162, 255, 0.15);
}

.report-score {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent-primary);
  line-height: 1;
}

.report-details {
  flex: 1;
}

.report-job {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
  line-height: 1.3;
}

.report-date {
  font-size: 14px;
  color: var(--text-secondary);
}

.report-btn {
  width: 100%;
  padding: 10px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, #67b3ff 100%);
  color: var(--bg-primary);
  border: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.report-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(122, 162, 255, 0.3);
}

.no-reports {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--space-xxl);
  color: var(--text-secondary);
}

.no-reports a {
  color: var(--accent-primary);
  text-decoration: underline;
}

/* ============================================================================
   OPTIMIZE HEADER (Collapsible on Mobile)
   ============================================================================ */
.optimize-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 1.5rem 2rem;
  text-align: center;
  color: white;
  margin-bottom: 1rem;
}

.optimize-header-content {
  max-width: 900px;
  margin: 0 auto;
}

.header-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.header-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-collapse-btn {
  display: none; /* Hidden on desktop, shown on mobile */
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  padding: 0.25rem;
  margin-left: auto;
  transition: transform 0.3s ease;
}

.header-collapse-btn svg {
  display: block;
}

.header-collapse-btn.collapsed {
  transform: rotate(180deg);
}

.header-details {
  transition: all 0.3s ease;
  overflow: hidden;
}

.header-description {
  margin: 0;
  font-size: 1rem;
  opacity: 0.95;
  max-width: 800px;
  margin: 0 auto;
}

.header-features {
  margin: 0.75rem 0 0 0;
  font-size: 0.9rem;
  opacity: 0.85;
}

/* ============================================================================
   SCROLL-TO-TOP FAB BUTTON
   ============================================================================ */
.scroll-to-top-fab {
  position: fixed;
  bottom: 100px; /* Above mobile bottom bar */
  right: 16px;
  z-index: 90;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary) 0%, #67b3ff 100%);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(122, 162, 255, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.3s ease;
  pointer-events: none;
}

.scroll-to-top-fab.visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: all;
}

.scroll-to-top-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(122, 162, 255, 0.5);
}

.scroll-to-top-fab:active {
  transform: scale(0.95);
}

/* ============================================================================
   MOBILE TAB NAVIGATION (Mobile Only <640px)
   ============================================================================ */
.mobile-tabs {
  display: none; /* Hidden on desktop */
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px;
  margin: var(--space-md) 0;
  gap: 6px;
}

.mobile-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mobile-tab svg {
  flex-shrink: 0;
}

.mobile-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.mobile-tab.active {
  background: var(--accent-primary);
  color: var(--bg-primary);
  box-shadow: 0 2px 8px rgba(122, 162, 255, 0.3);
}

/* ============================================================================
   MOBILE BOTTOM ACTION BAR (Mobile Only <640px)
   ============================================================================ */
.mobile-bottom-bar {
  display: none; /* Hidden on desktop */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10000; /* Above everything including footer, feedback widgets */
  background: rgba(13, 18, 32, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  padding: 12px 16px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
}

.mobile-finalize-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, #67b3ff 100%);
  color: var(--bg-primary);
  font-weight: 700;
  font-size: 15px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 12px rgba(122, 162, 255, 0.4);
}

.mobile-finalize-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(122, 162, 255, 0.5);
}

.mobile-finalize-btn:active:not(:disabled) {
  transform: translateY(0);
}

.mobile-finalize-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.mobile-finalize-btn svg {
  flex-shrink: 0;
}

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

/* Large desktop: Default 3-column layout (defined above at line 303) */

/* Tablets and smaller desktops: 2 columns + right panel below */
@media (max-width: 1280px) {
  .optimize-workspace {
    grid-template-columns: 1fr 1fr;
  }

  .column-right {
    grid-column: 1 / -1;
    max-height: 500px;
  }
}

/* Tablets: Stack score bar vertically, adjust layout */
@media (max-width: 768px) {
  /* Single column layout */
  .optimize-workspace {
    grid-template-columns: 1fr;
  }

  .column {
    max-height: none;
  }

  /* Score bar: more compact but still readable */
  .score-bar {
    padding: var(--space-sm);
    margin: var(--space-sm) 0;
  }

  .score-bar-content {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-sm);
  }

  .scores-group {
    flex-direction: row; /* Keep horizontal on tablet for space efficiency */
    align-items: center;
    gap: var(--space-xs);
    flex-wrap: wrap;
  }

  .score-item {
    flex: 1;
    min-width: 120px;
    padding: 8px 10px;
  }

  .score-label {
    font-size: 11px;
  }

  .score-value {
    font-size: 18px;
  }

  .score-arrow {
    font-size: 16px;
  }

  .score-delta {
    padding: 4px 10px;
    font-size: 12px;
  }

  .score-actions {
    width: 100%;
  }

  .btn-finalize {
    width: 100%;
    justify-content: center;
    padding: 8px 14px;
    font-size: 13px;
  }

  /* Template grid: 2 columns on tablet */
  .template-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Format grid: single column */
  .format-grid {
    grid-template-columns: 1fr;
  }

  /* Modal adjustments */
  .modal-container {
    width: min(920px, 98vw);
  }

  .modal-header {
    padding: var(--space-md);
  }

  .modal-content {
    padding: var(--space-md);
  }

  .modal-footer {
    padding: var(--space-md);
    flex-direction: column;
  }

  .modal-btn {
    width: 100%;
  }
}

/* Mobile: Tabbed layout with internal scrolling, ULTRA COMPACT */
@media (max-width: 640px) {
  /* ========================================
     HEADER: Collapsible on mobile
     ======================================== */
  .optimize-header {
    padding: 1rem;
    margin-bottom: 0.5rem;
  }

  .header-title-row {
    margin-bottom: 0;
  }

  .header-title {
    font-size: 1.25rem !important; /* 30% smaller */
  }

  .header-collapse-btn {
    display: block; /* Show collapse button on mobile */
  }

  .header-details {
    max-height: 200px; /* Allow expanding */
    opacity: 1;
  }

  .header-details.collapsed {
    max-height: 0;
    opacity: 0;
    margin: 0;
  }

  .header-description {
    font-size: 0.85rem !important;
    padding-top: 0.75rem;
  }

  .header-features {
    font-size: 0.75rem !important;
    margin-top: 0.5rem !important;
  }

  /* ========================================
     MOBILE TABS: Show on mobile
     ======================================== */
  .mobile-tabs {
    display: flex; /* Show on mobile */
  }

  /* ========================================
     MOBILE BOTTOM BAR: Show on mobile
     ======================================== */
  .mobile-bottom-bar {
    display: block; /* Show on mobile */
  }

  .mobile-bottom-bar:not(.hidden) {
    display: block !important;
  }

  /* Hide desktop finalize button on mobile */
  .score-bar .btn-finalize {
    display: none;
  }

  /* Add padding to page container to account for bottom bar */
  .optimize-page-container {
    padding: 0 8px 80px 8px; /* 80px bottom padding for action bar */
  }

  /* ========================================
     TABBED COLUMN LAYOUT: One visible at a time
     ======================================== */
  .optimize-workspace {
    grid-template-columns: 1fr; /* Single column */
    margin: 8px 0;
    gap: 0; /* No gap between columns since only one visible */
  }

  /* Hide all columns by default on mobile */
  .column {
    display: none;
    min-height: unset; /* Remove min-height */
    max-height: calc(100vh - 320px); /* Viewport height - header - score bar - tabs - bottom bar */
    overflow-y: auto; /* Enable internal scrolling */
  }

  /* Show only the active column */
  .column.mobile-active {
    display: flex;
  }

  .column-content {
    padding: 10px;
  }

  .column-header {
    padding: 10px;
  }

  /* Smaller text */
  .column-title {
    font-size: 12px;
  }

  /* ========================================
     TOUCH TARGETS: Larger for mobile
     ======================================== */
  .tooltip-btn {
    padding: 10px 16px; /* Was 6px 12px - now 44px height */
    font-size: 13px;
  }

  .legend-pill {
    padding: 8px 14px; /* Was 6px 12px */
    font-size: 13px;
  }

  .chip-btn {
    padding: 8px 12px; /* Was 4px 8px */
    font-size: 12px;
  }

  .panel-btn {
    padding: 10px 14px; /* Was 8px 12px */
    font-size: 14px;
  }

  /* ========================================
     SCORE BAR: Sleek horizontal layout on mobile
     ======================================== */
  .score-bar {
    padding: 12px;
    margin: 8px 0;
    position: sticky;
    top: 0;
  }

  .score-bar-content {
    flex-direction: column;
    gap: 12px;
  }

  .scores-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: nowrap;
  }

  .score-item {
    flex: 1;
    max-width: 160px;
    padding: 12px 16px;
    flex-direction: row; /* Label and value side by side */
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(100, 116, 139, 0.3);
  }

  .score-label {
    font-size: 11px;
    margin: 0;
    text-transform: none;
    letter-spacing: 0;
    opacity: 0.8;
    font-weight: 500;
    white-space: nowrap;
  }

  .score-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
  }

  .score-original .score-value {
    color: #a5b4fc; /* Lighter blue */
  }

  .score-optimized .score-value {
    color: #4ade80; /* Bright green */
  }

  .score-arrow {
    display: block;
    font-size: 20px;
    color: var(--accent-primary);
    flex-shrink: 0;
  }

  .score-delta {
    padding: 8px 12px;
    font-size: 11px;
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    font-weight: 400;
  }

  /* ========================================
     MODAL: Compact on mobile
     ======================================== */
  .modal-container {
    width: 100%;
    max-height: 95vh;
  }

  .modal-title {
    font-size: 18px;
  }

  /* Single column for templates */
  .template-grid {
    grid-template-columns: 1fr;
  }

  /* Smaller template previews */
  .template-preview {
    height: 100px; /* Was 120px */
  }

  /* ========================================
     TOAST NOTIFICATIONS: Full width
     ======================================== */
  .toast-container {
    right: 10px;
    left: 10px;
    top: 60px; /* Below header */
  }

  .toast {
    min-width: auto;
    max-width: none;
  }
}
