/* public/app.css
 *
 * Shared styles for the main pipeline pages:
 *   index.html                    1. Find cluster
 *   retrosynth.html               2. Choose scaffolds + search settings
 *   retrosynthesis_paths.html     3. Strategies
 * Legacy pages (analysis.html, clusters.html) keep style.css.
 */

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #cbd5e1;
  --text: #1f2937;
  --muted: #667085;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eef4ff;
  --success: #15803d;
  --danger: #b42318;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 12px rgba(16, 24, 40, 0.04);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 650; }
a { color: var(--accent); }

/* ---------------- Header ---------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
}

.steps {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.88rem;
  color: var(--muted);
}

.step {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
}

.step b {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  font-size: 0.78rem;
}

.step.is-current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.step.is-current b { background: var(--accent); color: #fff; }
.step.is-done b { background: var(--success); color: #fff; }
.step-sep { color: var(--border-strong); }

/* ---------------- Layout ---------------- */
.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-head p { margin: 6px 0 0; color: var(--muted); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.layout-sidebar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}

@media (max-width: 900px) {
  .layout-sidebar { grid-template-columns: 1fr; }
}

.sticky { position: sticky; top: 76px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card + .card { margin-top: 16px; }

.section { margin-top: 28px; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--mono); font-size: 0.8rem; overflow-wrap: anywhere; }

.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.error-state {
  padding: 16px;
  color: var(--danger);
  background: #fef3f2;
  border: 1px solid #fecdca;
  border-radius: var(--radius-sm);
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:disabled, .btn.disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); border-color: transparent; }

.btn-lg { padding: 12px 22px; font-size: 1rem; }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }
.btn-block { width: 100%; }

/* ---------------- Forms ---------------- */
.search-bar { display: flex; gap: 10px; flex-wrap: wrap; }

.input {
  flex: 1 1 320px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.95rem;
}

.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.options { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 14px; }

/* Structure editor ("Draw structure") on the start page */
.draw-panel {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.draw-editor { width: 100%; min-height: 360px; background: var(--surface); }

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.check input { margin-top: 3px; accent-color: var(--accent); }
.check small { display: block; color: var(--muted); font-size: 0.8rem; }

.field { margin-top: 14px; }
.field:first-child { margin-top: 0; }

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

.field-value {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 8px;
  border-radius: 999px;
}

.field-help { margin: 4px 0 0; color: var(--muted); font-size: 0.8rem; line-height: 1.4; }

.field input[type="range"] { width: 100%; margin-top: 6px; accent-color: var(--accent); }

.field input[type="number"] {
  width: 90px;
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font: inherit;
}

.settings-group + .settings-group {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.settings-group h3 {
  margin-bottom: 12px;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.8rem;
  color: var(--muted);
}

button.chip { cursor: pointer; font-family: var(--mono); }
button.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------------- Molecule tiles ---------------- */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

.mol-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.mol-tile.is-selectable { cursor: pointer; }
.mol-tile.is-selectable:hover { border-color: var(--border-strong); }
.mol-tile.is-selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.mol-art {
  display: grid;
  place-items: center;
  height: 150px;
  padding: 6px;
  background: #fff;
}

.mol-art svg { width: 100%; height: 100%; }

.mol-meta {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.mol-meta .mono { color: var(--muted); }

.tile-check {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* ---------------- Search results (search.js markup) ---------------- */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.result-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.result-card:hover { border-color: var(--border-strong); }
.result-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.result-card > div:first-child,
.result-card .thumb {
  display: grid;
  place-items: center;
  height: 140px;
  padding: 6px;
}

.result-card svg { width: 100%; height: 100%; }

.result-card .caption {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  overflow-wrap: anywhere;
  max-height: 4.6em;
  overflow: hidden;
}

.thumb.spinner::after {
  content: "";
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.thumb.error { color: var(--danger); font-size: 0.85rem; }

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

.hint {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.error { color: var(--danger); }

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.pager > div { margin-right: auto; color: var(--muted); font-size: 0.9rem; }

.pager button, .cluster-pager button, .load-more-button, .analysis-button {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.pager button:disabled, .analysis-button:disabled { opacity: 0.45; cursor: not-allowed; }

.cluster-pager { margin-top: 12px; display: flex; gap: 8px; align-items: center; color: var(--muted); }

/* ---------------- Legacy tools ---------------- */
.legacy {
  margin-top: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.legacy > summary {
  padding: 14px 20px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}

.legacy[open] > summary { border-bottom: 1px solid var(--border); }
.legacy-body { padding: 20px; }
.legacy-body > * + * { margin-top: 14px; }

/* ---------------- Strategies ---------------- */
.strategy {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}

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

.strategy-title { display: flex; align-items: center; gap: 10px; font-weight: 650; }

.rank {
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
}

.path {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.molecule-card {
  width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.molecule-card .mol-thumb {
  display: grid;
  place-items: center;
  height: 120px;
  padding: 4px;
  background: #fff;
}

.molecule-card .mol-thumb svg { width: 100%; height: 100%; }

.molecule-smiles {
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.arrow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 96px;
  text-align: center;
  color: var(--accent);
}

.arrow-glyph { font-size: 26px; line-height: 1; }
.arrow-label { font-size: 0.72rem; line-height: 1.25; color: var(--muted); }

.branches { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.branches:empty { display: none; }

.branch {
  margin-left: 24px;
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-2);
}

.branch-head { font-size: 0.85rem; color: var(--muted); margin-bottom: 10px; }
.branch-note { font-size: 0.85rem; color: var(--muted); margin-top: 8px; }
.branch-actions { margin-top: 10px; }
.branch-actions:empty { display: none; }

.np-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.np-title {
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.np-list { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }

.np-card {
  width: 130px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.np-card .mol-thumb { display: grid; place-items: center; height: 100px; padding: 4px; }
.np-card .mol-thumb svg { width: 100%; height: 100%; }
.np-empty { font-size: 0.88rem; color: var(--muted); }
.np-progress { width: 100%; }

/* Buttons created by the strategies script */
.explore-btn {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.explore-btn:hover { background: var(--accent-soft); }
.explore-btn:disabled { opacity: 0.55; cursor: default; }

/* ---------------- Progress panel (progress.js) ---------------- */
.pp-panel { --pp-max-width: none; }
#progressHost:empty { display: none; }
#progressHost { margin-bottom: 16px; }

@media (max-width: 640px) {
  .app-header { padding: 10px 16px; }
  .page { padding: 20px 16px 48px; }
  .steps .step span { display: none; }
  .molecule-card { width: 132px; }
  .arrow { width: 72px; }
  .branch { margin-left: 8px; }
}

/* search.js fills #searchPageInfo once there are results */
.pager:has(#searchPageInfo:empty) { display: none; }
