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

:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --surface2:  #21262d;
  --border:    #30363d;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --accent:    #58a6ff;
  --accent-dk: #1f6feb;
  --green:     #3fb950;
  --yellow:    #d29922;
  --red:       #f85149;
  --orange:    #e3b341;
  --radius:    8px;
  --tr:        150ms ease;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Top bar ───────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 20px;
  z-index: 100;
}

.topbar-brand {
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  white-space: nowrap;
}

.brand-icon {
  width: 28px; height: 28px;
  background: var(--accent-dk);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.topbar-nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  padding: 6px 14px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  transition: color var(--tr), background var(--tr);
}
.nav-btn:hover { color: var(--text); background: var(--surface2); }
.nav-btn.active { color: var(--text); background: var(--surface2); }

.topbar-auth {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ── WS status dot ─────────────────────────────────────── */
.ws-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  cursor: default;
}
.ws-dot.connected    { background: var(--green); }
.ws-dot.connecting   { background: var(--yellow); animation: pulse 1s infinite; }
.ws-dot.disconnected { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

/* ── Gmail auth area ───────────────────────────────────── */
.gmail-user {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px 4px 10px;
  font-size: 13px;
  color: var(--muted);
}

/* ── Main content ──────────────────────────────────────── */
.content {
  margin-top: 56px;
  padding: 32px 24px;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Pages ─────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ── Page header ───────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
}

.sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

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

/* ── Buttons ───────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: var(--accent-dk);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--tr);
}
.btn-primary:hover    { background: #388bfd; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color var(--tr), background var(--tr);
}
.btn-secondary:hover { border-color: var(--accent); background: var(--surface); }

.btn-ghost {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color var(--tr);
}
.btn-ghost:hover { color: var(--text); }

.btn-send {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: #1a7f37;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--tr);
}
.btn-send:hover    { background: #2da44e; }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

.back-btn { margin-bottom: 4px; }

/* ── Forms ─────────────────────────────────────────────── */
.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.form-section-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 16px;
}

details.form-section > summary.form-section-title {
  margin-bottom: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.full { grid-column: 1 / -1; }

label {
  font-size: 13px;
  font-weight: 500;
}

.req { color: var(--red); }

input[type="text"],
input[type="number"],
input[type="email"],
textarea,
select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 8px 12px;
  transition: border-color var(--tr);
  resize: vertical;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
}

.error-msg { color: var(--red); font-size: 13px; }

/* ── Run brief (collapsible on running page) ───────────── */
.run-brief-details {
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.run-brief-summary {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.run-brief-content {
  margin: 0;
  padding: 8px 16px 14px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  max-height: 200px;
  overflow-y: auto;
}
.run-context-grid {
  padding: 6px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.run-ctx-item {
  display: flex;
  gap: 12px;
  align-items: baseline;
}
.run-ctx-label {
  flex-shrink: 0;
  width: 110px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.run-ctx-value {
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}
.run-ctx-row-inline {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.run-ctx-tag {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--surface2);
  color: var(--muted);
}

/* ── Running page layout ───────────────────────────────── */
.running-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}

/* ── Prospect grid ─────────────────────────────────────── */
.prospect-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

/* ── Prospect card ─────────────────────────────────────── */
.prospect-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color var(--tr), transform var(--tr);
}
.prospect-card.clickable {
  cursor: pointer;
}
.prospect-card.clickable:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.prospect-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.prospect-name {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
}

.prospect-url {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

/* ── Fit score badges ──────────────────────────────────── */
.fit-badge {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}
.fit-badge.high   { background: rgba(63,185,80,0.15);  color: var(--green);  border: 1.5px solid var(--green); }
.fit-badge.medium { background: rgba(210,153,34,0.15); color: var(--yellow); border: 1.5px solid var(--yellow); }
.fit-badge.low    { background: rgba(248,81,73,0.15);  color: var(--red);    border: 1.5px solid var(--red); }
.fit-badge.none   { background: var(--surface2);       color: var(--muted);  border: 1.5px solid var(--border); }

.fit-badge-lg {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  flex-shrink: 0;
}
.fit-badge-lg.high   { background: rgba(63,185,80,0.15);  color: var(--green);  border: 2px solid var(--green); }
.fit-badge-lg.medium { background: rgba(210,153,34,0.15); color: var(--yellow); border: 2px solid var(--yellow); }
.fit-badge-lg.low    { background: rgba(248,81,73,0.15);  color: var(--red);    border: 2px solid var(--red); }
.fit-badge-lg.none   { background: var(--surface2);       color: var(--muted);  border: 2px solid var(--border); }

/* ── Stage progress (inside running cards) ─────────────── */
.card-stages { margin-top: 8px; }

.stage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding: 2px 0;
}
.stage-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.stage-dot.done    { background: var(--green); }
.stage-dot.active  { background: var(--yellow); animation: pulse 0.8s infinite; }
.stage-dot.pending { background: transparent; border: 1px solid var(--border); }

.card-score { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ── Status badges ─────────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  text-transform: capitalize;
}
.status-badge.complete,
.status-badge.completed  { background: rgba(63,185,80,0.15);  color: var(--green); }
.status-badge.error,
.status-badge.failed     { background: rgba(248,81,73,0.15);  color: var(--red); }
.status-badge.running    { background: rgba(88,166,255,0.15); color: var(--accent); }
.status-badge.scored     { background: rgba(210,153,34,0.15); color: var(--yellow); }
.status-badge.researched,
.status-badge.researching { background: rgba(88,166,255,0.1); color: var(--accent); }
.status-badge.pending    { background: var(--surface2); color: var(--muted); }

/* ── Event log ─────────────────────────────────────────── */
.event-log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: sticky;
  top: 72px;
}

.event-log-header {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.event-log-entries {
  overflow-y: auto;
  flex: 1;
  padding: 4px 0;
}

.event-entry {
  padding: 5px 14px;
  font-size: 11.5px;
  font-family: SFMono-Regular, Consolas, "Liberation Mono", monospace;
  color: var(--muted);
  border-bottom: 1px solid rgba(48,54,61,0.5);
  word-break: break-word;
  line-height: 1.5;
}
.event-entry .ev-type    { color: var(--accent); font-weight: 600; margin-right: 6px; }
.event-entry .ev-company { color: var(--text); }
.event-entry .ev-stage   { color: var(--yellow); }
.event-entry .ev-error   { color: var(--red); }
.event-entry .ev-query {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  margin: 2px 3px;
  font-size: 11px;
  color: var(--text);
}

/* ── Runs table ────────────────────────────────────────── */
.runs-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.runs-table th,
.runs-table td {
  padding: 11px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.runs-table th {
  background: var(--surface2);
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.4px;
}

.runs-table tr:last-child td { border-bottom: none; }

.runs-table tbody tr {
  background: var(--surface);
  cursor: pointer;
  transition: background var(--tr);
}
.runs-table tbody tr:hover { background: var(--surface2); }

.query-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Prospect detail grid ──────────────────────────────── */
.prospect-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.detail-card.full { grid-column: 1 / -1; }

.detail-card > h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.report-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.75;
  white-space: pre-wrap;
  max-height: 420px;
  overflow-y: auto;
  font-family: inherit;
}

/* ── Draft cards ───────────────────────────────────────── */
.draft-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 12px;
}

.draft-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.draft-subject {
  font-weight: 600;
  font-size: 14px;
}

.draft-to {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.draft-no-email {
  color: var(--red);
}

.draft-body {
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.65;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 4px;
}

/* ── Refinement log ────────────────────────────────────── */
.ref-entry {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.ref-entry:last-child { border-bottom: none; }

.ref-stage {
  font-family: SFMono-Regular, Consolas, monospace;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 4px;
}

.ref-text {
  color: var(--muted);
  white-space: pre-wrap;
  line-height: 1.5;
}

/* ── Refinement feedback ───────────────────────────────── */
.refine-textarea {
  width: 100%;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  transition: border-color var(--tr);
}
.refine-textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.refine-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.refine-status {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.refine-status.hidden { display: none; }
.refine-status .spinner-inline {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* ── Send email modal ──────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay.hidden { display: none !important; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 600px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 600; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Toast notifications ───────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
}

.toast {
  padding: 12px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
  animation: slideIn 200ms ease;
  max-width: 340px;
}
.toast.success { background: #1a7f37; color: #fff; }
.toast.error   { background: #6e1a1a; color: #fca5a5; border: 1px solid #f85149; }
.toast.info    { background: var(--accent-dk); color: #fff; }

@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Empty state ───────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state h3 { font-size: 16px; margin-bottom: 8px; color: var(--text); }

/* ── File upload area ──────────────────────────────────── */
.upload-area {
  position: relative;
  border: 1.5px dashed var(--border);
  border-radius: 6px;
  background: var(--surface2);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--tr), background var(--tr);
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--accent);
  background: rgba(88,166,255,0.06);
}
.upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  background: none;
}
#upload-label {
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
}
.upload-filename {
  font-size: 12px;
  color: var(--green);
  font-weight: 500;
}

/* ── Spinner ───────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scrollbars ────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Login splash ──────────────────────────────────────── */
.login-splash {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.login-splash.hidden { display: none !important; }
.login-splash-card {
  text-align: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  max-width: 380px;
  width: 100%;
}

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

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 860px) {
  .running-layout          { grid-template-columns: 1fr; }
  .form-grid               { grid-template-columns: 1fr; }
  .form-group.full         { grid-column: 1; }
  .prospect-detail-grid    { grid-template-columns: 1fr; }
  .detail-card.full        { grid-column: 1; }
  .topbar-brand span       { display: none; }
}

@media (max-width: 560px) {
  .content { padding: 20px 14px; }
  .topbar  { padding: 0 14px; }
}

/* ── Disclaimer box ────────────────────────────────────── */
.disclaimer-box {
  background: rgba(210,153,34,0.08);
  border: 1px solid rgba(210,153,34,0.25);
  border-radius: var(--radius);
  padding: 20px;
}
