/* ALEX CV Engine — Main Stylesheet */
/* Mobile-first, no frameworks */

:root {
  --c-bg: #f5f5f3;
  --c-surface: #ffffff;
  --c-border: #e0e0dc;
  --c-primary: #1a1a1a;
  --c-accent: #2563eb;
  --c-accent-hover: #1d4ed8;
  --c-success: #16a34a;
  --c-warning: #d97706;
  --c-danger: #dc2626;
  --c-muted: #6b7280;
  --c-covered: #dcfce7;
  --c-covered-text: #15803d;
  --c-bridgeable: #fef9c3;
  --c-bridgeable-text: #854d0e;
  --c-gap: #fee2e2;
  --c-gap-text: #991b1b;
  --radius: 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);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Courier New', Courier, monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ---- HEADER ---- */
.app-header {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  color: var(--c-primary);
}
.nav-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--c-muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
  margin-left: 4px;
}
.nav-btn:hover { background: var(--c-bg); color: var(--c-primary); }

/* ---- PROGRESS BAR ---- */
.progress-bar {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  padding: 8px 16px;
}
.progress-steps {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.step {
  font-size: 0.75rem;
  color: var(--c-muted);
  padding: 3px 8px;
  border-radius: 999px;
  transition: background 0.2s, color 0.2s;
}
.step.active {
  background: var(--c-accent);
  color: #fff;
  font-weight: 600;
}
.step.done {
  background: var(--c-covered);
  color: var(--c-covered-text);
}
.step-sep { color: var(--c-border); font-size: 0.85rem; }

/* ---- LOADING OVERLAY ---- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(245,245,243,0.85);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 32px 48px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-message { color: var(--c-muted); font-size: 0.875rem; }

/* ---- ERROR BANNER ---- */
.error-banner {
  background: var(--c-gap);
  border-bottom: 1px solid #fca5a5;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.875rem;
  color: var(--c-danger);
}
.error-banner button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--c-danger);
  padding: 0 4px;
}

/* ---- VIEWS ---- */
.view { display: none; padding: 28px 0 60px; }
.view.active { display: block; }

/* ---- CONTAINER ---- */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---- PHASE HEADERS ---- */
.phase-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.phase-desc {
  color: var(--c-muted);
  font-size: 0.875rem;
  margin-bottom: 24px;
  max-width: 640px;
}

/* ---- HOME CARD ---- */
.home-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  max-width: 680px;
  margin: 0 auto;
}
.home-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.subtitle {
  color: var(--c-muted);
  font-size: 0.875rem;
  margin-bottom: 24px;
}
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
textarea {
  width: 100%;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  resize: vertical;
  background: var(--c-bg);
  color: var(--c-primary);
  transition: border 0.15s;
}
textarea:focus { outline: none; border-color: var(--c-accent); }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn-lg { padding: 12px 28px; font-size: 0.95rem; }
.btn-primary { background: var(--c-accent); color: #fff; border-color: var(--c-accent); }
.btn-primary:hover { background: var(--c-accent-hover); border-color: var(--c-accent-hover); }
.btn-outline {
  background: var(--c-surface);
  color: var(--c-primary);
  border-color: var(--c-border);
}
.btn-outline:hover { border-color: var(--c-muted); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- RESULT GRID (Phase 1) ---- */
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.result-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px;
}
.result-card label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.result-card.full-width { grid-column: 1 / -1; }
.badge-row { display: flex; gap: 8px; flex-wrap: wrap; }
.badge-toggle {
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid var(--c-border);
  background: var(--c-bg);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
}
.badge-toggle.active {
  background: var(--c-accent);
  color: #fff;
  border-color: var(--c-accent);
}
.field-select, .field-input {
  width: 100%;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 0.875rem;
  background: var(--c-bg);
  color: var(--c-primary);
}
.field-select:focus, .field-input:focus { outline: none; border-color: var(--c-accent); }
.label-warning { color: var(--c-warning) !important; }
.text-warning { color: var(--c-warning); font-size: 0.875rem; }
.text-muted { color: var(--c-muted); font-size: 0.875rem; }

/* ---- ACTION ROW ---- */
.action-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 24px;
  flex-wrap: wrap;
}
.action-note { font-size: 0.8rem; color: var(--c-muted); }

/* ---- KEYWORD TABS (Phase 2) ---- */
.keyword-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 20px;
}
.tab-btn {
  padding: 8px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--c-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn.active { color: var(--c-accent); border-bottom-color: var(--c-accent); font-weight: 600; }
.count-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  font-size: 0.7rem;
  font-weight: 700;
}
.count-badge.alert { background: var(--c-gap); color: var(--c-danger); border-color: #fca5a5; }

/* ---- KEYWORD LIST ---- */
.keyword-list { display: flex; flex-direction: column; gap: 10px; }
.keyword-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
}
.keyword-card.covered { border-left: 3px solid var(--c-success); }
.keyword-card.bridgeable { border-left: 3px solid var(--c-warning); }
.keyword-card.gap { border-left: 3px solid var(--c-danger); }
.keyword-info { flex: 1; min-width: 180px; }
.keyword-text { font-weight: 600; font-size: 0.9rem; margin-bottom: 2px; }
.keyword-source { font-size: 0.75rem; color: var(--c-muted); }
.keyword-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.kw-badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.kw-badge.covered { background: var(--c-covered); color: var(--c-covered-text); }
.kw-badge.bridgeable { background: var(--c-bridgeable); color: var(--c-bridgeable-text); }
.kw-badge.gap { background: var(--c-gap); color: var(--c-gap-text); }
.resolution-btn {
  padding: 4px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  background: var(--c-bg);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 500;
  transition: all 0.15s;
}
.resolution-btn.selected-bridge { background: var(--c-accent); color: #fff; border-color: var(--c-accent); }
.resolution-btn.selected-suppress { background: var(--c-muted); color: #fff; border-color: var(--c-muted); }
.resolution-btn.selected-expose { background: var(--c-warning); color: #fff; border-color: var(--c-warning); }
.anchor-chip {
  display: inline-block;
  padding: 2px 8px;
  background: var(--c-covered);
  color: var(--c-covered-text);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  margin-left: 4px;
}

/* ---- PIVOT TABLE (Phase 3) ---- */
.pivot-table-wrap { overflow-x: auto; margin-bottom: 16px; }
.pivot-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.pivot-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-bg);
}
.pivot-table td {
  padding: 12px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: top;
}
.pivot-table tr:last-child td { border-bottom: none; }
.pivot-toggle {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  position: relative;
  background: var(--c-border);
  transition: background 0.2s;
}
.pivot-toggle::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.pivot-toggle.on { background: var(--c-success); }
.pivot-toggle.on::after { transform: translateX(18px); }
.pivot-narrative { color: var(--c-muted); font-size: 0.8rem; max-width: 320px; }
.anchor-tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--c-covered);
  color: var(--c-covered-text);
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ---- DOCUMENT PREVIEW (Phases 4 & 5) ---- */
.doc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.doc-meta { font-size: 0.8rem; color: var(--c-muted); }
.doc-preview {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 28px 32px;
  min-height: 400px;
  font-size: 0.875rem;
  line-height: 1.7;
  white-space: pre-wrap;
  font-family: var(--font);
  box-shadow: var(--shadow);
}
.doc-preview h1 { font-size: 1.3rem; margin-bottom: 2px; }
.doc-preview h2 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--c-border);
  padding-bottom: 4px;
  margin: 18px 0 8px;
  color: var(--c-muted);
}
.doc-preview h3 { font-size: 0.9rem; font-weight: 700; margin-bottom: 2px; }
.doc-preview ul { padding-left: 18px; margin: 6px 0; }
.doc-preview li { margin-bottom: 3px; }
.doc-preview p { margin-bottom: 8px; }
.doc-preview strong { font-weight: 600; }

/* ---- SESSION LOCKED ---- */
.locked-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.locked-badge {
  background: var(--c-covered);
  color: var(--c-covered-text);
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}
.locked-meta { font-size: 0.85rem; color: var(--c-muted); }
.doc-actions-row { display: flex; gap: 10px; margin-bottom: 28px; flex-wrap: wrap; }

/* ---- Q&A CHAT ---- */
.qa-section h3 { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.chat-window {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 220px;
  max-height: 420px;
  overflow-y: auto;
  margin: 16px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}
.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-msg.assistant { align-self: flex-start; }
.chat-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
}
.chat-msg.user .chat-bubble { background: var(--c-accent); color: #fff; border-radius: 12px 12px 2px 12px; }
.chat-msg.assistant .chat-bubble { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 12px 12px 12px 2px; }
.chat-input-row { display: flex; gap: 10px; align-items: flex-end; }
.chat-input-row textarea { flex: 1; }
.chat-input-row .btn { flex-shrink: 0; }

/* ---- HISTORY LIST ---- */
.history-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.history-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  flex-wrap: wrap;
  gap: 10px;
}
.history-card:hover { border-color: var(--c-accent); box-shadow: var(--shadow-md); }
.history-info { flex: 1; min-width: 200px; }
.history-title { font-weight: 600; font-size: 0.9rem; margin-bottom: 2px; }
.history-meta { font-size: 0.75rem; color: var(--c-muted); }
.history-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.history-badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  color: var(--c-muted);
}

/* ---- ANCHOR MODAL ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-md);
}
.modal-card h3 { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.anchor-options { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.anchor-option-btn {
  padding: 12px 16px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-bg);
  cursor: pointer;
  text-align: left;
  font-size: 0.85rem;
  transition: all 0.15s;
}
.anchor-option-btn:hover { border-color: var(--c-accent); background: #eff6ff; }
.anchor-option-btn strong { display: block; margin-bottom: 2px; }
.anchor-option-btn span { color: var(--c-muted); font-size: 0.78rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- RESPONSIVE ---- */
@media (max-width: 600px) {
  .result-grid { grid-template-columns: 1fr; }
  .home-card { padding: 20px; }
  .doc-preview { padding: 16px; }
  .pivot-table { font-size: 0.78rem; }
  .header-inner { padding: 0 12px; }
}
