/*!
 * @fileoverview Styles for the Molecule view (js/molecule-view.js, docs/ledger-design.md
 *   section 8.1): the condition x phase matrix with a one-hue heat ramp, the
 *   industry / investigator split bar, classification chips (shape glyph plus
 *   label), signal cards and the per-condition timeline strip.
 *   Colour: the heat ramp is the validated sequential blue (steps 250 to 650 on
 *   light; flipped to 600 to 200 on dark so the low end recedes into the
 *   surface), each step at least 2:1 against the surface and monotone in
 *   lightness (validate_palette.js --ordinal passes in both modes). The split
 *   uses categorical slots 1 (blue, industry) and 2 (orange, investigator) on a
 *   surface-coloured track so they never sit directly on the heat fill. Text is
 *   never coloured with a series colour. Reuses tokens from css/app.css and
 *   css/timeline.css; load after css/views.css.
 * @module css/molecule
 */

.tt-mol {
  --mol-heat-1: #86b6ef;
  --mol-heat-2: #5598e7;
  --mol-heat-3: #2a78d6;
  --mol-heat-4: #1c5cab;
  --mol-heat-5: #104281;
  --mol-heat-ink-1: #0b0b0b;
  --mol-heat-ink-2: #0b0b0b;
  --mol-heat-ink-3: #ffffff;
  --mol-heat-ink-4: #ffffff;
  --mol-heat-ink-5: #ffffff;
  --mol-industry: #2a78d6;
  --mol-investigator: #eb6834;
  --mol-zero: var(--tt-surface-2);
  --mol-strip: #5598e7;
  --mol-strip-track: var(--tt-grid);
  display: grid;
  gap: var(--tt-sp-4);
  min-width: 0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .tt-mol {
    --mol-heat-1: #184f95;
    --mol-heat-2: #256abf;
    --mol-heat-3: #3987e5;
    --mol-heat-4: #6da7ec;
    --mol-heat-5: #9ec5f4;
    --mol-heat-ink-1: #ffffff;
    --mol-heat-ink-2: #ffffff;
    --mol-heat-ink-3: #0b0b0b;
    --mol-heat-ink-4: #0b0b0b;
    --mol-heat-ink-5: #0b0b0b;
    --mol-industry: #3987e5;
    --mol-investigator: #d95926;
    --mol-strip: #6da7ec;
  }
}
:root[data-theme='dark'] .tt-mol {
  --mol-heat-1: #184f95;
  --mol-heat-2: #256abf;
  --mol-heat-3: #3987e5;
  --mol-heat-4: #6da7ec;
  --mol-heat-5: #9ec5f4;
  --mol-heat-ink-1: #ffffff;
  --mol-heat-ink-2: #ffffff;
  --mol-heat-ink-3: #0b0b0b;
  --mol-heat-ink-4: #0b0b0b;
  --mol-heat-ink-5: #0b0b0b;
  --mol-industry: #3987e5;
  --mol-investigator: #d95926;
  --mol-strip: #6da7ec;
}

.tt-mol-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- header: search, alias chips, ask chips ---- */
.tt-mol-head { display: grid; gap: var(--tt-sp-3); }
.tt-mol-form { display: flex; gap: var(--tt-sp-2); flex-wrap: wrap; }
.tt-mol-search { flex: 1 1 260px; width: auto; max-width: 420px; }
.tt-mol-aliasrow,
.tt-mol-askrow { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.tt-mol-label {
  font-size: var(--tt-fs-12);
  font-weight: 600;
  color: var(--tt-ink-secondary);
  margin-right: 2px;
}
.tt-mol-alias {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--tt-fs-12);
  color: var(--tt-ink-secondary);
  background: var(--tt-surface);
  border: 1px solid var(--tt-border-strong);
  border-radius: 999px;
  padding: 3px 10px;
}
.tt-mol-alias.is-primary { color: var(--tt-ink); font-weight: 600; background: var(--tt-surface-2); }
.tt-mol-alias-x {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-right: -6px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  cursor: pointer;
}
.tt-mol-alias-x:hover { background: var(--tt-border); }
.tt-mol-addalias { display: inline-flex; gap: 6px; align-items: center; }
.tt-mol-alias-input { width: 140px; padding: 4px 10px; font-size: var(--tt-fs-12); }

/* ---- title and stats ---- */
.tt-mol-title { display: flex; align-items: baseline; gap: var(--tt-sp-3); flex-wrap: wrap; }
.tt-mol-h { margin: 0; font-size: var(--tt-fs-20); font-weight: 650; letter-spacing: -0.01em; }
.tt-mol-stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--tt-sp-3);
}
.tt-mol-stat {
  background: var(--tt-surface);
  border: 1px solid var(--tt-border);
  border-radius: var(--tt-radius);
  padding: var(--tt-sp-3) var(--tt-sp-4);
  min-width: 0;
}
.tt-mol-stat-value { font-size: var(--tt-fs-28); font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.tt-mol-stat-label { font-size: var(--tt-fs-12); color: var(--tt-ink-secondary); margin-top: 2px; }

/* ---- sample / status banner ---- */
.tt-mol-banner {
  display: flex;
  align-items: center;
  gap: var(--tt-sp-3);
  padding: var(--tt-sp-3) var(--tt-sp-4);
  border: 1px solid var(--tt-border-strong);
  border-radius: var(--tt-radius);
  background: var(--tt-surface-2);
  font-size: var(--tt-fs-13);
  color: var(--tt-ink-secondary);
}
.tt-mol-banner strong { color: var(--tt-ink); }
.tt-mol-banner-text { flex: 1 1 auto; min-width: 0; }
.tt-mol-banner .tt-empty-cmd { display: inline-block; margin-left: 6px; }
.tt-mol-banner-icon { display: inline-grid; place-items: center; color: var(--tt-ink-secondary); }

/* ---- matrix card ---- */
.tt-mol-matrix-card { display: grid; gap: var(--tt-sp-3); }
.tt-mol-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--tt-sp-3); flex-wrap: wrap; }
.tt-mol-filters,
.tt-mol-viewtoggle { display: flex; flex-wrap: wrap; gap: 6px; }

.tt-mol-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tt-sp-2) var(--tt-sp-6);
  font-size: var(--tt-fs-12);
  color: var(--tt-ink-secondary);
}
.tt-mol-legend-group { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
.tt-mol-legend-title { font-weight: 600; color: var(--tt-ink); }
.tt-mol-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.tt-mol-swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; }
.tt-swatch-bar { height: 4px; border-radius: 2px; width: 20px; background: var(--mol-strip); }
.tt-swatch-diamond { width: 9px; height: 9px; border-radius: 1px; transform: rotate(45deg); background: var(--tt-ink); }

.tt-heat-1 { background: var(--mol-heat-1); color: var(--mol-heat-ink-1); }
.tt-heat-2 { background: var(--mol-heat-2); color: var(--mol-heat-ink-2); }
.tt-heat-3 { background: var(--mol-heat-3); color: var(--mol-heat-ink-3); }
.tt-heat-4 { background: var(--mol-heat-4); color: var(--mol-heat-ink-4); }
.tt-heat-5 { background: var(--mol-heat-5); color: var(--mol-heat-ink-5); }
.tt-heat-0 { background: var(--mol-zero); color: var(--tt-ink-muted); }
.tt-split-industry { background: var(--mol-industry); }
.tt-split-investigator { background: var(--mol-investigator); }

.tt-mol-matrix-wrap { display: grid; gap: var(--tt-sp-3); min-width: 0; }
.tt-mol-matrix { display: grid; gap: 2px; min-width: 0; }
.tt-mol-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.6fr) repeat(3, minmax(76px, 0.7fr)) minmax(150px, 1.3fr) 140px;
  gap: 2px;
  align-items: stretch;
}
.tt-mol-row > * { min-width: 0; }
.tt-mol-row-head {
  font-size: var(--tt-fs-12);
  font-weight: 600;
  color: var(--tt-ink-secondary);
  align-items: end;
  padding-bottom: 2px;
}
.tt-mol-col-phase { text-align: center; }
.tt-mol-col-cond { padding: 6px 10px 6px 0; display: grid; gap: 4px; align-content: center; }
.tt-mol-cond-name { font-size: var(--tt-fs-14); font-weight: 600; overflow-wrap: anywhere; }
.tt-mol-cond-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; font-size: var(--tt-fs-12); color: var(--tt-ink-secondary); }
.tt-mol-kinds { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.tt-mol-kind {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--tt-fs-12);
  font-weight: 500;
  color: var(--tt-ink-secondary);
  border: 1px solid var(--tt-border-strong);
  border-radius: 999px;
  padding: 1px 8px 1px 6px;
  white-space: nowrap;
}
.tt-mol-shape { display: inline-block; width: 9px; height: 9px; flex: none; background: var(--tt-ink-secondary); }
.tt-mol-shape.is-circle { border-radius: 50%; }
.tt-mol-shape.is-triangle { background: none; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 9px solid var(--tt-ink-secondary); }
.tt-mol-shape.is-diamond { transform: rotate(45deg) scale(0.85); border-radius: 1px; }
.tt-mol-shape.is-ring { border-radius: 50%; background: none; border: 1.5px solid var(--tt-ink-secondary); }
.tt-mol-shape.is-bolt { clip-path: polygon(55% 0, 15% 55%, 45% 55%, 35% 100%, 85% 40%, 55% 40%); }

.tt-mol-cell {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  min-height: 48px;
  padding: 6px 8px;
  border-radius: 4px;
}
.tt-mol-cell-n { font-size: var(--tt-fs-16); font-weight: 650; line-height: 1; }
.tt-mol-cell-n.is-zero { font-weight: 400; }
.tt-mol-splitbar {
  display: flex;
  gap: 2px;
  width: 100%;
  max-width: 64px;
  height: 8px;
  padding: 2px;
  box-sizing: border-box;
  background: var(--tt-surface);
  border-radius: 3px;
  overflow: hidden;
}
.tt-mol-seg { display: block; height: 100%; min-width: 2px; border-radius: 1px; }

.tt-mol-col-strip { display: grid; align-content: center; padding: 0 6px; }
.tt-mol-axis { position: relative; height: 16px; }
.tt-mol-tick { position: absolute; top: 0; transform: translateX(-50%); font-size: 11px; font-weight: 400; color: var(--tt-ink-muted); }
.tt-mol-strip {
  position: relative;
  height: 16px;
  border-radius: 2px;
  background: linear-gradient(var(--mol-strip-track), var(--mol-strip-track)) center / 100% 1px no-repeat;
}
.tt-mol-strip-bar { position: absolute; top: 6px; height: 4px; border-radius: 2px; background: var(--mol-strip); }
.tt-mol-strip-cat {
  position: absolute;
  top: 3px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  transform: rotate(45deg) scale(0.8);
  border-radius: 1px;
  background: var(--tt-ink);
  outline: 2px solid var(--tt-surface);
}
.tt-mol-strip-today { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--tt-axis); }
.tt-mol-strip-na { position: absolute; left: 0; top: 0; font-size: 11px; color: var(--tt-ink-muted); background: var(--tt-surface); padding-right: 4px; }
.tt-mol-col-act { display: flex; align-items: center; justify-content: flex-end; }
.tt-mol-more { justify-self: start; }

/* ---- table twin ---- */
.tt-mol-table-wrap { overflow-x: auto; border: 1px solid var(--tt-border); border-radius: var(--tt-radius-sm); }
.tt-mol-table { width: 100%; border-collapse: collapse; font-size: var(--tt-fs-13); }
.tt-mol-table th,
.tt-mol-table td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--tt-border); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tt-mol-table th:first-child,
.tt-mol-table td:first-child,
.tt-mol-table th:nth-child(2),
.tt-mol-table td:nth-child(2) { text-align: left; }
.tt-mol-table thead th { position: sticky; top: 0; background: var(--tt-surface); font-size: var(--tt-fs-12); color: var(--tt-ink-secondary); }
.tt-mol-table tbody th { font-weight: 600; white-space: normal; min-width: 180px; }

/* ---- signal cards ---- */
.tt-mol-signals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--tt-sp-4); }
.tt-mol-signal .tt-card-title { display: inline-flex; align-items: center; gap: 8px; }
.tt-mol-signal-sub { margin: -6px 0 var(--tt-sp-2); }
.tt-mol-signal-list { list-style: none; margin: 0; padding: 0; display: grid; }
.tt-mol-signal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--tt-sp-3);
  padding: 8px 0;
  border-top: 1px solid var(--tt-border);
}
.tt-mol-signal-item:first-child { border-top: 0; }
.tt-mol-signal-main { min-width: 0; }
.tt-mol-signal-name { font-size: var(--tt-fs-14); font-weight: 600; overflow-wrap: anywhere; }
.tt-mol-foot { margin: 0; max-width: 80ch; }

/* ---- narrow viewports: rows stack ---- */
@media (max-width: 1023px) {
  .tt-mol-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tt-mol-signals { grid-template-columns: minmax(0, 1fr); }
  .tt-mol-row { grid-template-columns: minmax(150px, 1.4fr) repeat(3, minmax(56px, 0.6fr)); }
  .tt-mol-row .tt-mol-col-strip { grid-column: 1 / 4; }
  .tt-mol-row .tt-mol-col-act { grid-column: 4; }
  .tt-mol-row-head .tt-mol-col-strip,
  .tt-mol-row-head .tt-mol-col-act { display: none; }
}
@media (max-width: 560px) {
  .tt-mol-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tt-mol-stat-value { font-size: var(--tt-fs-20); }
  .tt-mol-row { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 4px; padding-bottom: var(--tt-sp-3); border-bottom: 1px solid var(--tt-border); }
  .tt-mol-row-head { display: none; }
  .tt-mol-row .tt-mol-col-cond { grid-column: 1 / -1; padding-bottom: 0; }
  .tt-mol-row .tt-mol-col-strip { grid-column: 1 / 3; padding: 0; }
  .tt-mol-row .tt-mol-col-act { grid-column: 3; }
  .tt-mol-row .tt-mol-col-act .tt-btn { padding: 4px 6px; }
  .tt-mol-cell::before { content: attr(data-phase); font-size: 10px; opacity: 0.8; }
  .tt-mol-search { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  .tt-mol * { transition: none !important; }
}

.tt-mol-askrow .tt-chip,
.tt-mol-filters .tt-chip { display: inline-flex; align-items: center; gap: 6px; }

/* World mini-map card (js/world-view.js mountMini, mounted by js/app.js): a compact map, not a full-width banner. */
.tt-mol-world-card { display: grid; gap: var(--tt-sp-3); }
.tt-mol-world-host { max-width: 720px; }
.tt-company-world { max-width: 420px; }
