/* ─── Design Tokens ────────────────────────────────────────────────────────── */
:root {
  --primary:       #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success:       #059669;
  --success-light: #ecfdf5;
  --warning:       #d97706;
  --warning-light: #fffbeb;
  --error:         #dc2626;
  --error-light:   #fef2f2;
  --text:          #0f172a;
  --text-muted:    #64748b;
  --border:        #e2e8f0;
  --surface:       #ffffff;
  --bg:            #f8fafc;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:     0 4px 12px rgba(0,0,0,0.10);
}

/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

code { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.85em; }

/* ─── Layout ───────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.app-title {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Step indicators */
#step-indicators {
  display: flex;
  align-items: center;
  gap: 0;
}

.step-pip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.pip-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.pip-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.step-pip.active .pip-num {
  background: var(--primary);
  color: white;
  box-shadow: 0 0 0 3px var(--primary-light);
}

.step-pip.active .pip-label { color: var(--primary); font-weight: 600; }

.step-pip.done .pip-num {
  background: var(--success);
  color: white;
}

.step-pip.done .pip-label { color: var(--success); }

.pip-connector {
  width: 24px;
  height: 2px;
  background: var(--border);
  margin-bottom: 14px;
  flex-shrink: 0;
}

/* Main wizard body */
#wizard-body {
  flex: 1;
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
  padding: 2rem 1.5rem 7rem;
  transition: max-width 0.2s ease;
}

#wizard-body.output-expanded {
  max-width: 100%;
  padding-left: 1rem;
  padding-right: 1rem;
}

/* Footer nav */
footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.footer-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

#error-banner {
  flex: 1;
  color: var(--error);
  font-size: 0.88rem;
  font-weight: 500;
}

.nav-btns {
  display: flex;
  gap: 0.625rem;
  margin-left: auto;
}

/* ─── Step ─────────────────────────────────────────────────────────────────── */
.step-header {
  margin-bottom: 2rem;
}

.step-header h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.375rem;
}

.step-header p {
  color: var(--text-muted);
  font-size: 0.925rem;
}

/* ─── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1.5rem;
}

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.text-input,
.select-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.text-input:focus,
.select-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.key-input-wrap {
  position: relative;
  display: flex;
}

.key-input-wrap .text-input {
  padding-right: 2.75rem;
}

.btn-icon {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.375rem;
  font-size: 1rem;
  opacity: 0.55;
  transition: opacity 0.15s;
}

.btn-icon:hover { opacity: 1; }

.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* ─── Provider Cards ───────────────────────────────────────────────────────── */
.provider-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.provider-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

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

.provider-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.provider-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.provider-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* ─── Field Cards ──────────────────────────────────────────────────────────── */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 0.875rem;
  margin-bottom: 2rem;
}

.field-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  padding: 1.25rem 0.875rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  user-select: none;
}

.field-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.field-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.field-card:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.field-icon { font-size: 2rem; }
.field-label { font-weight: 700; font-size: 0.9rem; }
.field-desc { font-size: 0.75rem; color: var(--text-muted); line-height: 1.4; }

/* ─── Specialization Chips ─────────────────────────────────────────────────── */
.hidden { display: none !important; }

.spec-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.875rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.spec-chip {
  padding: 0.4rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

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

.spec-chip.selected {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

/* ─── Drop Zones ───────────────────────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.dropzone:hover,
.dropzone:focus-within {
  border-color: var(--primary);
  background: var(--primary-light);
}

.dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
  border-style: solid;
}

.dropzone.has-content {
  border-color: var(--success);
  background: var(--success-light);
}

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

.drop-icon { font-size: 2.25rem; }
.dropzone p { color: var(--text-muted); font-size: 0.9rem; margin: 0; }

.btn-browse {
  padding: 0.4rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 0.25rem;
}

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

.parse-status {
  margin-top: 0.5rem;
  padding: 0.5rem 0.875rem;
  border-radius: 6px;
  font-size: 0.85rem;
  min-height: 2rem;
}

.parse-status.loading {
  background: #fef9c3;
  color: var(--warning);
}

.parse-status.ok {
  background: var(--success-light);
  color: var(--success);
  font-weight: 500;
}

.parse-status.error {
  background: var(--error-light);
  color: var(--error);
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.text-area {
  width: 100%;
  padding: 0.75rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1.65;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  min-height: 180px;
  outline: none;
  transition: border-color 0.15s;
}

.text-area:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.file-loaded {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--success);
  font-weight: 500;
}

.badge-optional {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #e0f2fe;
  color: #0369a1;
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  vertical-align: middle;
  margin-left: 0.4rem;
}

/* ─── Detection Banner ─────────────────────────────────────────────────────── */
.detection-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: #1e40af;
  margin-bottom: 1.5rem;
}

/* ─── Custom Spec Input ────────────────────────────────────────────────────── */
.spec-hint {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
}

.custom-spec-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.875rem;
}

.custom-spec-row .text-input {
  flex: 1;
}

.custom-chip {
  position: relative;
  padding-right: 1.75rem; /* room for × */
}

.chip-remove {
  position: absolute;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.6;
  pointer-events: auto;
}

.chip-remove:hover {
  opacity: 1;
}

/* ─── Source Preview (resume / JD collapsible) ─────────────────────────────── */
.source-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 0.75rem;
  background: var(--surface);
}

.source-preview summary {
  padding: 0.625rem 1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.source-preview summary::-webkit-details-marker { display: none; }
.source-preview summary::before {
  content: '▶';
  font-size: 0.65rem;
  color: var(--text-muted);
  transition: transform 0.15s;
}
.source-preview[open] summary::before { transform: rotate(90deg); }

.preview-meta {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-left: auto;
}

.preview-text {
  margin: 0;
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--border);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.78rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg);
}

/* ─── Review Card ──────────────────────────────────────────────────────────── */
.review-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.review-row {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.review-row:last-child { border-bottom: none; }

.rv-label {
  min-width: 140px;
  color: var(--text-muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.rv-val { font-weight: 500; }
.rv-ok { color: var(--success); }
.rv-optional { color: var(--text-muted); font-style: italic; font-weight: 400; }
.rv-missing { color: var(--error); }
.rv-warn { color: var(--warning); }

/* ─── Progress Panel ───────────────────────────────────────────────────────── */
.progress-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.progress-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 1.25rem;
}

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

.progress-log {
  min-height: 4rem;
  margin-bottom: 1.25rem;
}

.progress-log p {
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 0.2rem 0;
  opacity: 0;
  animation: fadein 0.4s ease forwards;
}

@keyframes fadein { to { opacity: 1; } }

.progress-track-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.progress-track {
  flex: 1;
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  border-radius: 999px;
  width: 0%;
  transition: width 0.6s ease;
}

.progress-pct {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary);
  min-width: 2.75rem;
  text-align: right;
}

.progress-chars {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.progress-time {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.25rem;
  min-height: 1.2em;
}

/* ─── Auth Loading Overlay ─────────────────────────────────────────────────── */
.auth-loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.925rem;
}

.user-btn-wrap {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* ─── Output Panel ─────────────────────────────────────────────────────────── */
.output-panel {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.output-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
}

.output-frame {
  width: 100%;
  height: 80vh;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-outline:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-muted);
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .field-grid { grid-template-columns: 1fr 1fr; }
  .provider-row { grid-template-columns: repeat(3, 1fr); }
  .output-actions { flex-direction: column; }
  .output-frame { height: 70vh; }
  .rv-label { min-width: 100px; }
  .pip-label { display: none; }
}
