/* =====================================================================
   FDA Small-Molecule Atlas (/atlas)
   Built on the site tokens in web.css — no new colours, no second
   typeface. The one local idea is --ac, the therapeutic-area colour,
   set per tile and per badge from the dataset.
   ===================================================================== */

/* ---------- hero counters ---------- */
.at-stats {
  list-style: none;
  margin: 26px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 14px 38px;
}
.at-stats li { display: flex; flex-direction: column; gap: 3px; }
.at-stat-n {
  font-size: 1.55rem;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.at-stat-n.at-stat-ok { color: var(--success); }
.at-stat-l { font-size: var(--fs-xs); color: var(--muted); }

/* ---------- the "structures are being checked" panel ---------- */
.at-pending {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: var(--warn-tint);
  border: 1px solid #f0dcb4;
  border-radius: var(--r-lg);
  padding: 20px 22px;
}
.at-pending > i { flex: none; width: 24px; height: 24px; color: var(--warn); margin-top: 2px; }
.at-pending h2 { margin: 0 0 8px; font-size: var(--fs-lg); color: #6b4208; }
.at-pending p { margin: 0 0 10px; color: #6b4208; font-size: var(--fs-sm); line-height: 1.6; }
.at-pending p:last-child { margin-bottom: 0; }

/* ---------- section headings ---------- */
.at-h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 6px;
  font-size: var(--fs-xl);
}
.at-h2 i { width: 20px; height: 20px; color: var(--teal-deep); }
.at-h3 { margin: 4px 0 6px; font-size: var(--fs-lg); }
.at-sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: var(--fs-sm);
  max-width: 68ch;
  line-height: 1.6;
}

/* ---------- therapeutic-area tiles ---------- */
.at-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 11px;
}
.at-tile {
  position: relative;
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  padding: 14px 15px 13px;
  border-radius: 15px;
  border: 1px solid color-mix(in srgb, var(--ac) 30%, transparent);
  background:
    linear-gradient(150deg,
      color-mix(in srgb, var(--ac) 15%, var(--surface)),
      color-mix(in srgb, var(--ac) 4%, var(--surface)) 65%,
      var(--surface));
  transition: transform 0.12s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.at-tile:hover {
  transform: translateY(-2px);
  border-color: var(--ac);
  box-shadow: 0 10px 24px -12px var(--ac);
}
.at-tile:focus-visible { outline: none; box-shadow: var(--focus); }
.at-tile[aria-pressed="true"] {
  border-color: var(--ac);
  box-shadow: inset 0 0 0 2px var(--ac), 0 8px 22px -14px var(--ac);
}
.at-tile-pct {
  position: absolute;
  top: 13px;
  right: 14px;
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.at-tile-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 33px;
  height: 33px;
  margin-bottom: 11px;
  border-radius: 11px;
  background: var(--ac);
  box-shadow: 0 5px 13px -5px var(--ac);
}
.at-tile-ico svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #fff;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.at-tile-name {
  display: block;
  font-weight: 600;
  font-size: 0.82rem;
  line-height: 1.25;
  min-height: 2.5em;
  color: var(--ink);
}
.at-tile-count {
  display: block;
  margin-top: 4px;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ac);
  font-variant-numeric: tabular-nums;
}
.at-tile-bar {
  display: block;
  height: 5px;
  margin-top: 9px;
  border-radius: 5px;
  background: rgba(11, 27, 63, 0.07);
  overflow: hidden;
}
.at-tile-bar i { display: block; height: 100%; border-radius: 5px; background: var(--ac); }

/* ---------- tabs ---------- */
.at-tabs {
  display: flex;
  gap: 4px;
  margin: 34px 0 18px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.at-tabs::-webkit-scrollbar { display: none; }
.at-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  margin-bottom: -1px;
  cursor: pointer;
  white-space: nowrap;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: 0;
  border-bottom: 2.5px solid transparent;
}
.at-tab i { width: 17px; height: 17px; }
.at-tab:hover { color: var(--ink); }
.at-tab.is-on { color: var(--brand-ink); border-bottom-color: var(--brand); }
.at-tab:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px 8px 0 0; }

/* ---------- toolbar ---------- */
.at-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
  margin-bottom: 12px;
}
.at-field {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.at-field:focus-within { border-color: var(--brand); box-shadow: var(--focus); }
.at-field > i { flex: none; width: 17px; height: 17px; color: var(--muted); }
.at-field input,
.at-field select {
  min-width: 0;
  border: 0;
  outline: none;
  background: none;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--ink);
  /* Not height:100%. Forcing a control to the field's inner height makes the browser
     clip its text box, which shaves the descenders — "All years" reads as "All vears".
     Letting the control size to its own line box and centring it in the flex row keeps
     the glyphs whole. */
  height: auto;
  line-height: 1.5;
  padding: 1px 0;
}
.at-field select {
  cursor: pointer;
  padding-right: 2px;
  /* A native select adds its own vertical padding on top of the line box; without room
     for it the same clipping comes back on Windows and Android. */
  padding-block: 2px;
  max-width: 100%;
  text-overflow: ellipsis;
}
.at-field-grow { flex: 1 1 240px; }
.at-field-grow input { width: 100%; }
.at-field-mw input { width: 78px; }
.at-field-pre { font-size: var(--fs-sm); color: var(--muted); white-space: nowrap; }
.at-csv { margin-left: auto; }
.at-field.is-set { border-color: var(--brand); background: var(--brand-soft); }

.at-count {
  margin: 0 0 10px;
  font-size: var(--fs-sm);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.at-count b { color: var(--ink); }

/* ---------- the table ---------- */
.at-table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: auto;
  max-height: 78vh;
}
.at-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.at-table th,
.at-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
  font-size: var(--fs-sm);
}
.at-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0;
  background: var(--wash);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.at-table thead th button,
.at-table thead th { font-size: var(--fs-xs); font-weight: 650; color: var(--muted); }
.at-table thead th button {
  display: block;
  width: 100%;
  padding: 11px 14px;
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
}
.at-table thead th:not(:has(button)) { padding: 11px 14px; }
.at-table thead th button:hover { color: var(--brand); }
.at-table thead th button[aria-sort]::after { content: " \25B2"; font-size: 0.6em; }
.at-table thead th button[aria-sort="descending"]::after { content: " \25BC"; }
.at-table tbody tr:hover td { background: var(--wash); }
.at-table .at-td-num,
.at-table .at-td-mw { color: var(--muted); font-variant-numeric: tabular-nums; }
.at-table .at-td-yr { font-variant-numeric: tabular-nums; white-space: nowrap; }
.at-td-name a { font-weight: 600; color: var(--brand-ink); text-decoration: none; }
.at-td-name a:hover { text-decoration: underline; }
.at-links { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.at-links a {
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 0.68rem;
  color: var(--muted);
  text-decoration: none;
}
.at-links a:hover { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); }
.at-smiles {
  min-width: 220px;
  max-width: 330px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  word-break: break-all;
  color: var(--ink-2);
}
.at-formula { white-space: nowrap; color: var(--ink-2); }
.at-copy {
  display: inline-flex;
  margin-left: 5px;
  padding: 2px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  vertical-align: middle;
}
.at-copy i { width: 14px; height: 14px; }
.at-copy:hover { color: var(--brand); background: var(--brand-soft); }
.at-cid { margin-left: 5px; font-size: 0.68rem; color: var(--muted); text-decoration: none; }
.at-cid:hover { color: var(--brand); }

.at-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 7px;
  border-radius: 20px;
  white-space: nowrap;
  cursor: pointer;
  border: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ac);
  background: color-mix(in srgb, var(--ac) 14%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ac) 28%, transparent);
}
.at-badge svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.at-badge:hover { background: color-mix(in srgb, var(--ac) 22%, transparent); }

.at-loading td,
.at-empty td { padding: 36px 14px; text-align: center; color: var(--muted); }
.at-empty b { display: block; color: var(--ink); margin-bottom: 3px; }

.at-more { margin-top: 14px; text-align: center; }

.at-note {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin: 16px 0 0;
  font-size: var(--fs-xs);
  line-height: 1.65;
  color: var(--muted);
  max-width: 82ch;
}
.at-note i { flex: none; width: 15px; height: 15px; margin-top: 2px; }
.at-note a { color: var(--brand); }

/* ---------- substructure search ---------- */
.at-frag-picker { display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.at-frag-group > h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: var(--fs-xs);
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.at-frag-group > h4 span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--ac);
}
.at-frag-group > h4 svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.at-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.at-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 20px;
  cursor: pointer;
  font-size: var(--fs-xs);
  color: var(--ink-2);
  background: color-mix(in srgb, var(--ac) 5%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--ac) 28%, transparent);
}
.at-chip:hover { border-color: var(--ac); }
.at-chip:focus-visible { outline: none; box-shadow: var(--focus); }
.at-chip.is-on { color: #fff; background: var(--ac); border-color: var(--ac); }
.at-chip .at-chip-n { font-variant-numeric: tabular-nums; opacity: 0.65; font-size: 0.68rem; }

.at-chosen { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.at-chosen:empty { margin-bottom: 0; }
.at-tag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 7px 5px 11px;
  border-radius: 20px;
  font-size: var(--fs-xs);
  color: var(--brand-ink);
  background: var(--brand-tint);
}
.at-tag code { font-size: 0.68rem; opacity: 0.75; }
.at-tag button {
  display: inline-flex;
  padding: 2px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  cursor: pointer;
}
.at-tag button i { width: 13px; height: 13px; }
.at-tag button:hover { background: rgba(26, 77, 216, 0.16); }

.at-frag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(208px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.at-fcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
}
.at-fcard .at-struct {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 150px;
  border-radius: 10px;
  background: var(--wash);
  color: var(--muted);
  font-size: var(--fs-xs);
}
.at-fcard .at-struct svg { max-width: 100%; height: auto; }
.at-fcard-name { margin-top: 9px; font-size: var(--fs-sm); font-weight: 600; }
.at-fcard-name a { color: var(--brand-ink); text-decoration: none; }
.at-fcard-name a:hover { text-decoration: underline; }
.at-fcard-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 6px; }
.at-fcard-sub { font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.at-frag-empty {
  grid-column: 1 / -1;
  padding: 36px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-2);
  border-radius: 14px;
}
.at-frag-empty b { display: block; color: var(--ink); margin-bottom: 4px; }

.at-spin {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 7px;
  vertical-align: -1px;
  border: 2px solid var(--line-2);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: at-spin 0.7s linear infinite;
}
@keyframes at-spin { to { transform: rotate(360deg); } }

/* ---------- key reactions ---------- */
.at-rxn-list { display: flex; flex-direction: column; gap: 14px; }
.at-rxn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px 20px;
}
.at-rxn-top { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.at-rxn-num {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--brand-tint);
  color: var(--brand-ink);
  font-size: var(--fs-xs);
  font-weight: 700;
}
.at-rxn-top h4 { margin: 0; font-size: var(--fs-lg); }
.at-rxn-forms {
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--teal-tint);
  color: var(--teal-deep);
  font-size: var(--fs-xs);
  font-weight: 600;
}
.at-rxn-blurb { margin: 10px 0 0; font-size: var(--fs-sm); line-height: 1.65; color: var(--ink-2); }
.at-rxn-note {
  margin: 9px 0 0;
  padding: 8px 11px;
  border-radius: 9px;
  background: var(--warn-tint);
  color: var(--warn);
  font-size: var(--fs-xs);
  line-height: 1.55;
}
.at-rxn-refs { margin: 10px 0 0; font-size: var(--fs-xs); color: var(--muted); line-height: 1.7; }
.at-rxn-refs span {
  display: inline-block;
  margin-right: 7px;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--wash-2);
  font-weight: 650;
}
.at-rxn-refs a { color: var(--brand); text-decoration: none; margin-right: 10px; }
.at-rxn-refs a:hover { text-decoration: underline; }
.at-rxn-examples {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.at-rxn-ex { margin: 0; }
.at-rxn-struct {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--wash);
  color: var(--muted);
  font-size: 0.7rem;
}
.at-rxn-struct svg { max-width: 100%; height: auto; }
.at-rxn-ex figcaption { margin-top: 6px; text-align: center; font-size: var(--fs-xs); }
.at-rxn-ex figcaption a { color: var(--brand-ink); text-decoration: none; }
.at-rxn-ex figcaption a:hover { text-decoration: underline; }

/* ---------- phones: the table becomes a list of cards ---------- */
@media (max-width: 760px) {
  .at-tiles { grid-template-columns: repeat(auto-fill, minmax(144px, 1fr)); }
  .at-csv { margin-left: 0; }
  .at-table-wrap { max-height: none; border: 0; background: none; overflow: visible; }
  .at-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .at-table,
  .at-table tbody,
  .at-table tr,
  .at-table td { display: block; width: 100%; }
  .at-table tr {
    margin-bottom: 10px;
    padding: 13px 15px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
  }
  .at-table td { padding: 3px 0; border: 0; }
  .at-table tbody tr:hover td { background: none; }
  .at-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 1px;
    font-size: 0.66rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
  }
  .at-table .at-td-num { display: none; }
  .at-smiles { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  .at-tile { transition: none; }
  .at-tile:hover { transform: none; }
  .at-spin { animation-duration: 2s; }
}

/* ---------- draft structures ----------
   An unchecked structure is shown, never hidden, but it is never allowed to look settled. */
.at-smiles-text.is-draft {
  text-decoration: underline dotted var(--warn);
  text-underline-offset: 3px;
}
.at-cid-draft { color: var(--warn); font-weight: 600; }
.at-cid-draft:hover { color: var(--warn); text-decoration: underline; }
.at-frag-warn {
  padding: 9px 12px;
  margin-bottom: 12px;
  border-radius: 10px;
  background: var(--warn-tint);
  color: #6b4208;
}
.at-frag-warn i { color: var(--warn); }
.at-frag-warn code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(107, 66, 8, 0.1);
  font-size: 0.95em;
}

/* An open-access reference is marked, so a reader knows which links lead to a free copy
   and which stop at a paywall before they click. */
.at-oa {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 20px;
  background: var(--teal-tint);
  color: var(--teal-deep);
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- property space ---------- */
.at-plot-wrap {
  position: relative;
  height: min(62vh, 520px);
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}
#at-plot { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.at-plot-tip {
  position: absolute;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-width: 220px;
  padding: 7px 10px;
  pointer-events: none;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: var(--fs-xs);
  line-height: 1.45;
  box-shadow: 0 8px 20px -8px rgba(11, 27, 63, 0.5);
}
.at-plot-tip b { font-size: var(--fs-sm); }
.at-plot-tip span { opacity: 0.82; font-variant-numeric: tabular-nums; }

.at-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.at-stat-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
}
.at-stat-k {
  font-size: var(--fs-xs);
  font-weight: 650;
  line-height: 1.25;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  /* "Median weight" is one line and "Breaking 2+ rules of five" is two, so without a
     reserved two lines the big numbers underneath sit at different heights across the
     row. Reserving the space lines them up whatever the label's length. */
  min-height: 2.5em;
}
.at-stat-v {
  margin-bottom: 2px;
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--brand-ink);
  font-variant-numeric: tabular-nums;
}
.at-stat-note {
  /* Pushed to the bottom so the notes share a baseline too, rather than floating at
     whatever height the number above them happens to end. */
  margin-top: auto;
  padding-top: 6px;
  font-size: var(--fs-xs);
  line-height: 1.5;
  color: var(--muted);
}

@media (max-width: 760px) {
  .at-plot-wrap { height: 68vh; }
  .at-stats { grid-template-columns: 1fr 1fr; }
}
