/*
 * This is a manifest file that'll be compiled into application.css.
 */

/* ============================================================
   Design tokens
   ============================================================ */
:root {
  --color-bg:           #f8f9fa;
  --color-surface:      #ffffff;
  --color-accent:       #4361ee;
  --color-accent-hover: #3451d1;
  --color-text:         #111827;
  --color-text-muted:   #6b7280;
  --color-border:       #e5e7eb;
  --color-border-light: #f3f4f6;
  --color-success-bg:   #f0fdf4;
  --color-success-text: #166534;
  --color-warning-bg:   #fffbeb;
  --color-warning-text: #92400e;
  --color-error-bg:     #fef2f2;
  --color-error-text:   #991b1b;
  --radius:             8px;
  --shadow-sm:          0 1px 3px rgba(0,0,0,0.07);
  --shadow-md:          0 4px 16px rgba(0,0,0,0.08);
}

/* ============================================================
   Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  margin: 0;
  padding: 0;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; font-weight: 700; color: var(--color-text); margin: 0 0 0.5rem; }
h2 { font-size: 1.2rem;  font-weight: 600; color: var(--color-text); margin: 1.5rem 0 0.75rem; }
h3 { font-size: 1rem;    font-weight: 600; color: var(--color-text); margin: 0 0 0.5rem; }
h4 { font-size: 0.875rem; font-weight: 600; color: var(--color-text); }

/* ============================================================
   Navbar
   ============================================================ */
.navbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.navbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 2rem;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.navbar-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-text);
  letter-spacing: 0.02em;
}

.navbar-brand:hover { text-decoration: none; color: var(--color-accent); }

.navbar-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.navbar-links a { color: var(--color-text-muted); font-size: 0.9rem; }
.navbar-links a:hover { color: var(--color-text); text-decoration: none; }
.navbar-links .btn-primary { color: #fff; }
.navbar-links .btn-primary:hover { color: #fff; }

.navbar-user {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* ============================================================
   Layout
   ============================================================ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--color-border);
  flex-wrap: wrap;
}

.page-header h1 { margin: 0; }

.competitors-list {
  margin: 0.25rem 0 0;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

main, .main-content {
  padding: 1.5rem 2rem;
  max-width: 1600px;
  margin: 0 auto;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-header-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.credit-balance { font-size: 0.85rem; color: var(--color-text-muted); }
.credit-balance--empty { color: #c0392b; font-weight: 500; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-block;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  transition: background 0.15s;
  text-decoration: none;
}

.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:hover { background: var(--color-accent-hover); text-decoration: none; color: #fff; }
.btn-secondary { background: var(--color-border); color: var(--color-text); }
.btn-secondary:hover { background: #d1d5db; text-decoration: none; color: var(--color-text); }
.btn-large { padding: 0.65rem 1.5rem; font-size: 1rem; }
.btn-disabled { background: #a0aec0; color: #fff; cursor: not-allowed; opacity: 0.65; }

/* ============================================================
   Status badges
   ============================================================ */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: capitalize;
}

.status-pending    { background: var(--color-border-light); color: var(--color-text-muted); }
.status-processing { background: var(--color-warning-bg);   color: var(--color-warning-text); }
.status-completed  { background: var(--color-success-bg);   color: var(--color-success-text); }
.status-failed     { background: var(--color-error-bg);     color: var(--color-error-text); }

/* ============================================================
   Spinner
   ============================================================ */
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

.cell-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  color: #aaa;
}

/* ============================================================
   Index page
   ============================================================ */
.empty-state {
  padding: 3rem;
  text-align: center;
  color: var(--color-text-muted);
}

.analyses-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.analyses-table th,
.analyses-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border-light);
}

.analyses-table th {
  background: var(--color-bg);
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.analyses-table tr:last-child td { border-bottom: none; }
.analyses-table tr:hover td { background: #fafcff; }

/* ============================================================
   Notices (flash + inline warnings)
   ============================================================ */
.notice {
  border-left: 4px solid transparent;
  border-radius: 6px;
  padding: 0.75rem 1.25rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.notice p { margin: 0; }
.notice p + p { margin-top: 0.25rem; }

.notice--warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
  border-left-color: #f59e0b;
}

.notice--success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border-left-color: #22c55e;
}

.notice--error {
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border-left-color: #ef4444;
}

/* ============================================================
   Form
   ============================================================ */
.analysis-form {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 640px;
  box-shadow: var(--shadow-md);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--color-text);
}

.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  color: var(--color-text);
  background: var(--color-surface);
}

.form-control:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(67,97,238,0.1);
}

.competitors-fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.competitors-fieldset legend {
  font-weight: 600;
  padding: 0 0.5rem;
  color: var(--color-text);
}

.hint { font-weight: 400; color: var(--color-text-muted); font-size: 0.85rem; }
.required { color: #e74c3c; }

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 1.5rem;
}

/* Auth card (sign in / sign up / password reset) */
.auth-card {
  max-width: 420px;
  margin: 5rem auto;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem;
}

.auth-card h1 {
  font-size: 1.4rem;
  margin-bottom: 1.5rem;
}

.auth-card .form-actions { margin-top: 1.25rem; }

.auth-footer {
  margin-top: 1.25rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-align: center;
}

/* Admin form-section panel */
.form-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}

.form-section h2 { margin-top: 0; }

/* ============================================================
   Analysis type selector (new form)
   ============================================================ */
.type-selector {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.type-option {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.type-option:has(input:checked) {
  border-color: var(--color-accent);
  background: #f0f3ff;
}

.type-option input[type="radio"] { margin-top: 0.2rem; flex-shrink: 0; }

.type-option-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
}

.type-option-desc {
  display: block;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-top: 0.1rem;
}

/* ============================================================
   Results grid
   ============================================================ */
.loading-message {
  text-align: center;
  color: var(--color-text-muted);
  padding: 1rem;
}

.results-grid-wrapper {
  overflow-x: auto;
  margin-top: 1.5rem;
}

.results-grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.results-grid th,
.results-grid td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border-light);
  border-right: 1px solid var(--color-border-light);
  vertical-align: top;
}

.results-grid th:last-child,
.results-grid td:last-child { border-right: none; }

.results-grid tr:last-child td { border-bottom: none; }

.results-grid th {
  background: var(--color-bg);
  text-align: left;
}

.subject-col { width: 140px; min-width: 120px; }
.provider-col { min-width: 300px; }

.provider-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

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

.subject-name {
  font-weight: 600;
  vertical-align: top;
  padding-top: 1rem;
}

.primary-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.4rem;
  background: var(--color-accent);
  color: #fff;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  vertical-align: middle;
}

/* ============================================================
   Result cell
   ============================================================ */
.result-cell { font-size: 0.85rem; }

.result-section { margin-bottom: 1.25rem; }
.result-section:last-child { margin-bottom: 0; }

.result-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-accent);
  border-bottom: 1px solid #eef0ff;
  padding-bottom: 0.25rem;
}

.result-section p { margin: 0 0 0.5rem; }

.persona-card {
  background: #f8f9ff;
  border-left: 3px solid var(--color-accent);
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.6rem;
}

.persona-card--inappropriate {
  border-left-color: #e74c3c;
  background: #fff8f8;
}

.persona-name { display: block; font-size: 0.85rem; margin-bottom: 0.2rem; }
.persona-desc { color: var(--color-text-muted); margin: 0 0 0.3rem; }
.persona-reason { color: #e74c3c; margin: 0; font-size: 0.82rem; }

.jtbd-list {
  margin: 0.3rem 0 0;
  padding-left: 1.2rem;
  color: var(--color-text);
}

.jtbd-list li { margin-bottom: 0.2rem; }

.sample-prompts {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.6;
}

.sample-prompts li { margin-bottom: 0.2rem; }

.result-section--references h4 { color: var(--color-text-muted); }

.disclaimer {
  font-weight: 400;
  font-size: 0.75rem;
  color: #e67e22;
  text-transform: none;
  letter-spacing: 0;
}

.references-list {
  margin: 0;
  padding-left: 1.2rem;
}

.references-list li { margin-bottom: 0.3rem; }

/* ============================================================
   Persona fit heatmap
   ============================================================ */
.provider-section { margin-bottom: 2.5rem; }

.provider-heading {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.heatmap-wrapper { overflow-x: auto; }

.heatmap-table {
  border-collapse: collapse;
  width: 100%;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.heatmap-table th,
.heatmap-table td {
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border-light);
  vertical-align: top;
}

.heatmap-table th {
  background: var(--color-bg);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.persona-col { min-width: 200px; background: var(--color-bg); }
.persona-col strong { display: block; margin-bottom: 0.2rem; font-size: 0.88rem; }
.persona-col p { margin: 0; font-size: 0.8rem; color: var(--color-text-muted); }

.heatmap-cell { text-align: center; min-width: 130px; }
.score-badge { display: block; font-size: 1.5rem; font-weight: 700; margin-bottom: 0.35rem; }
.score-reasoning { font-size: 0.78rem; color: var(--color-text); text-align: left; margin: 0; line-height: 1.4; }

.heatmap-loading { height: 60px; gap: 0.5rem; font-size: 0.9rem; color: var(--color-text-muted); }

.heatmap-cell[data-score="1"]  { background: #fde8e8; }
.heatmap-cell[data-score="2"]  { background: #fdd0d0; }
.heatmap-cell[data-score="3"]  { background: #f9a8a8; }
.heatmap-cell[data-score="4"]  { background: #fde6c0; }
.heatmap-cell[data-score="5"]  { background: #fdf0c0; }
.heatmap-cell[data-score="6"]  { background: #fdf8c0; }
.heatmap-cell[data-score="7"]  { background: #d4f0c0; }
.heatmap-cell[data-score="8"]  { background: #b8e8a0; }
.heatmap-cell[data-score="9"]  { background: #90d870; }
.heatmap-cell[data-score="10"] { background: #6cc840; }

/* ============================================================
   Error states
   ============================================================ */
.query-status-wrap { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 0.2rem; }

.error-reason {
  font-size: 0.75rem;
  color: var(--color-error-text);
  background: var(--color-error-bg);
  border: 1px solid #fecaca;
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  max-width: 300px;
  word-break: break-word;
}

.cell-error {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 1rem;
  color: var(--color-error-text);
  font-size: 0.85rem;
}

.cell-error-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-error-bg);
  border: 1px solid #fecaca;
  font-weight: 700;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.heatmap-error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  color: var(--color-error-text);
  font-size: 0.9rem;
  background: var(--color-error-bg);
  border-radius: var(--radius);
  border: 1px solid #fecaca;
}

.heatmap-error .error-reason { margin-top: 0.25rem; width: 100%; }

/* ============================================================
   Analysis type badge
   ============================================================ */
.analysis-type-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  background: var(--color-border-light);
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  .navbar-inner { padding: 0 1rem; flex-wrap: wrap; gap: 0.5rem; }
  .navbar-links { gap: 0.5rem; font-size: 0.82rem; }
  main, .main-content { padding: 1rem; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .analysis-form { padding: 1.25rem; }
  .auth-card { margin: 2rem 1rem; padding: 1.5rem; }
  .results-grid-wrapper { overflow-x: auto; }
}

/* ============================================================
   Print / Export to PDF
   ============================================================ */
@media print {
  .navbar,
  .header-actions,
  .notice,
  .loading-message,
  .cell-spinner,
  .heatmap-loading,
  .cell-error,
  .heatmap-error { display: none !important; }

  body { font-size: 11px; color: #000; background: #fff; }

  main, .main-content { padding: 0.5rem; max-width: 100%; }

  .results-grid,
  .heatmap-table { box-shadow: none; }

  .persona-card { box-shadow: none; }

  .results-grid tr,
  .heatmap-table tr { page-break-inside: avoid; }

  .provider-section { page-break-before: auto; }

  a { color: #000; text-decoration: none; }

  .references-list a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.75em;
    color: #555;
  }

  .heatmap-cell,
  .persona-card,
  .persona-card--inappropriate,
  .status-badge,
  .primary-badge,
  .score-badge {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
