/* Stem Cell Industry Intelligence: styles.
   Styling rule from the requirements: simple color and type only.
   One typeface (system stack), five sizes, two weights; neutral base; one accent for anything clickable;
   red reserved for FDA and legal flags. Category colors appear only inside the map and charts, always labeled. */

:root {
  --bg: #FFFFFF;
  --surface: #F4F6F8;
  --text: #1E242B;
  --text-2: #5A6470;
  --rule: #DCE1E6;
  --rule-strong: #C3CAD2;
  --accent: #2D5F8F;
  --accent-weak: #E7EEF5;
  --flag: #B0413E;
  --flag-weak: #F8EBEA;
  --group: #4A5561;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-1: 12px;
  --fs-2: 13px;
  --fs-3: 15px;
  --fs-4: 18px;
  --fs-5: 24px;
  --w-reg: 400;
  --w-bold: 600;

  --nav-w: 212px;
  --top-h: 56px;
  --radius: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); font-size: var(--fs-3); font-weight: var(--w-reg); line-height: 1.45;
  color: var(--text); background: var(--bg);
  padding-top: env(safe-area-inset-top, 0px);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
.skip { position: absolute; left: -999px; top: 0; background: var(--bg); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
.muted { color: var(--text-2); }
.small { font-size: var(--fs-1); }
.flag-text { color: var(--flag); }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ header */
.top {
  position: fixed; top: 0; left: 0; right: 0; height: var(--top-h); z-index: 30;
  display: flex; align-items: center; gap: 20px; padding: 0 20px;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--bg); border-bottom: 1px solid var(--rule);
}
.brand { font-size: var(--fs-3); font-weight: var(--w-bold); color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav-toggle { display: none; background: none; border: 0; padding: 6px; cursor: pointer; }
.search { position: relative; flex: 1 1 auto; max-width: 560px; }
.search input {
  width: 100%; height: 36px; padding: 0 12px; font: inherit; font-size: var(--fs-2);
  border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--bg); color: var(--text);
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-weak); }
.search-results {
  position: absolute; top: 40px; left: 0; right: 0; max-height: 70vh; overflow: auto; z-index: 40;
  background: var(--bg); border: 1px solid var(--rule-strong); border-radius: var(--radius);
}
.sr-group { padding: 6px 0; border-bottom: 1px solid var(--rule); }
.sr-group:last-child { border-bottom: 0; }
.sr-head { font-size: var(--fs-1); color: var(--text-2); padding: 4px 12px; }
.sr-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 6px 12px; cursor: pointer; font-size: var(--fs-2); }
.sr-item .muted { font-size: var(--fs-1); }
.sr-item[aria-selected="true"], .sr-item:hover { background: var(--accent-weak); }
.sr-empty { padding: 12px; font-size: var(--fs-2); color: var(--text-2); }
.top-right { display: flex; align-items: center; gap: 16px; margin-left: auto; font-size: var(--fs-2); white-space: nowrap; }
.lens { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.lens select { font: inherit; font-size: var(--fs-2); padding: 4px 6px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); color: var(--text-2); }
.asof { color: var(--text-2); }
.btn-quiet { background: none; border: 1px solid var(--rule-strong); border-radius: var(--radius); padding: 6px 10px; cursor: pointer; font-size: var(--fs-2); color: var(--accent); }
.btn-quiet:hover { background: var(--accent-weak); }
.watch-menu { position: relative; }
.watch-pop { position: absolute; right: 0; top: 40px; width: 280px; background: var(--bg); border: 1px solid var(--rule-strong); border-radius: var(--radius); padding: 8px 0; z-index: 40; white-space: normal; }
.watch-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 6px 12px; cursor: pointer; color: var(--accent); font-size: var(--fs-2); }
.watch-pop button:hover { background: var(--accent-weak); }
.watch-pop p { padding: 6px 12px; font-size: var(--fs-2); color: var(--text-2); }

/* ------------------------------------------------------------ navigation */
.side {
  position: fixed; top: var(--top-h); bottom: 0; left: 0; width: var(--nav-w); z-index: 20;
  padding: 16px 12px; border-right: 1px solid var(--rule); background: var(--bg); overflow: auto;
}
.nav-group { margin-bottom: 18px; }
.nav-head { font-size: var(--fs-1); color: var(--text-2); padding: 0 8px 4px; }
.side a { display: block; padding: 6px 8px; border-radius: var(--radius); color: var(--text); font-size: var(--fs-2); }
.side a:hover { background: var(--surface); text-decoration: none; }
.side a.on { background: var(--accent-weak); color: var(--accent); font-weight: var(--w-bold); }
.build-note { font-size: var(--fs-1); color: var(--text-2); padding: 12px 8px 0; border-top: 1px solid var(--rule); }

/* ------------------------------------------------------------ main */
main { margin-left: var(--nav-w); padding: calc(var(--top-h) + 16px) 20px 40px; min-height: 100vh; outline: none; }
.page-title { font-size: var(--fs-5); font-weight: var(--w-bold); margin-bottom: 4px; }
.page-sub { color: var(--text-2); font-size: var(--fs-2); margin-bottom: 16px; }

/* catch-up bar */
.catchup {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 10px 14px; margin-bottom: 14px;
  border: 1px solid var(--rule); border-radius: var(--radius); font-size: var(--fs-2);
}
.catchup strong { font-weight: var(--w-bold); }
.catchup button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: var(--fs-2); }
.catchup button:hover { text-decoration: underline; }

/* headline figures */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat {
  text-align: left; background: var(--bg); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer;
}
.stat:hover { border-color: var(--accent); }
.stat[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-weak); }
.stat .num { display: block; font-size: var(--fs-5); font-weight: var(--w-bold); line-height: 1.15; }
.stat .num.flag-text { color: var(--flag); }
.stat .lbl { display: block; font-size: var(--fs-2); }
.stat .hint { display: block; font-size: var(--fs-1); color: var(--text-2); margin-top: 2px; }

/* map block + feed */
.mapzone { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; margin-bottom: 14px; }
.mapcard { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--bg); display: flex; flex-direction: column; min-width: 0; }
.mapcard:fullscreen { border-radius: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--rule); font-size: var(--fs-2); }
.filters label { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.filters input[type="text"], .filters select {
  font: inherit; font-size: var(--fs-2); color: var(--text); height: 30px; padding: 0 8px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--bg);
}
.filters input[type="text"] { width: 190px; }
.filters select:disabled { background: var(--surface); color: var(--text-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--rule); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-1); padding: 3px 9px; cursor: pointer;
  border: 1px solid var(--rule-strong); border-radius: 999px; background: var(--bg); color: var(--text);
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chip[aria-pressed="false"] { color: var(--text-2); background: var(--surface); border-color: var(--rule); }
.chip[aria-pressed="false"] .dot { opacity: 0.35; }
.chip.all { color: var(--accent); }
.mapbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--rule); }
.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { background: var(--bg); border: 0; border-right: 1px solid var(--rule-strong); padding: 5px 10px; font-size: var(--fs-2); cursor: pointer; color: var(--text); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-weak); color: var(--accent); font-weight: var(--w-bold); }
.seg-label { font-size: var(--fs-1); color: var(--text-2); margin-right: 6px; }
.mapbody { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); min-height: 520px; }
.mapbody.split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.map { position: relative; min-height: 520px; }
.mapbody.listonly .map { display: none; }
.mapbody:not(.split):not(.listonly) .listpane { display: none; }
.mapcard:fullscreen .mapbody, .mapcard:fullscreen .map { min-height: 0; flex: 1 1 auto; }
.mapcard:fullscreen { display: flex; flex-direction: column; height: 100%; }
.notice {
  position: absolute; left: 12px; top: 12px; right: 12px; z-index: 5; max-width: 520px;
  background: var(--bg); border: 1px solid var(--rule-strong); border-radius: var(--radius); padding: 10px 12px; font-size: var(--fs-2);
}
.notice strong { font-weight: var(--w-bold); }
.notice button { margin-top: 6px; }
.nomap { display: flex; align-items: center; justify-content: center; height: 100%; min-height: 520px; padding: 24px; text-align: center; color: var(--text-2); font-size: var(--fs-2); background: var(--surface); }
.nomap div { max-width: 420px; }
.nomap strong { color: var(--text); display: block; font-size: var(--fs-3); margin-bottom: 6px; }

.listpane { overflow: auto; max-height: 640px; border-left: 1px solid var(--rule); }
.mapbody.listonly .listpane { border-left: 0; }
table.list { width: 100%; border-collapse: collapse; font-size: var(--fs-2); }
table.list th { position: sticky; top: 0; background: var(--bg); text-align: left; font-weight: var(--w-bold); font-size: var(--fs-1); color: var(--text-2); padding: 8px 10px; border-bottom: 1px solid var(--rule-strong); cursor: pointer; white-space: nowrap; }
table.list td { padding: 8px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.list td.num, table.list th.num { text-align: right; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: var(--surface); }
.list-head { padding: 8px 10px; font-size: var(--fs-1); color: var(--text-2); border-bottom: 1px solid var(--rule); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 8px 12px; border-top: 1px solid var(--rule); font-size: var(--fs-1); color: var(--text-2); align-items: center; }
.legend .item { display: inline-flex; align-items: center; gap: 5px; }
.legend .sym { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.legend .sym.hq { border-radius: 1px; transform: rotate(45deg); width: 9px; height: 9px; }
.legend .sym.group { background: var(--group); width: 12px; height: 12px; }
.legend .sym.ring { background: transparent; border: 2px solid var(--flag); width: 12px; height: 12px; }

/* side panel over the map */
.panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 360px; max-width: 100%; z-index: 6;
  background: var(--bg); border-left: 1px solid var(--rule-strong); overflow: auto; padding: 14px 16px 20px;
}
.panel-close { position: absolute; top: 8px; right: 8px; background: none; border: 0; cursor: pointer; padding: 6px; color: var(--text-2); }
.panel h2 { font-size: var(--fs-4); font-weight: var(--w-bold); padding-right: 28px; }
.panel h3 { font-size: var(--fs-2); font-weight: var(--w-bold); margin: 14px 0 4px; }
.panel p, .panel li { font-size: var(--fs-2); }
.panel ul { margin: 0; padding-left: 18px; }
.panel .meta { font-size: var(--fs-1); color: var(--text-2); margin-top: 2px; }
.panel .seglist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.panel .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.btn { background: var(--bg); border: 1px solid var(--rule-strong); border-radius: var(--radius); padding: 6px 10px; cursor: pointer; font-size: var(--fs-2); color: var(--accent); }
.btn:hover { background: var(--accent-weak); }
.btn[aria-pressed="true"] { background: var(--accent-weak); border-color: var(--accent); }
.btn:disabled { color: var(--text-2); cursor: not-allowed; background: var(--surface); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { background: var(--surface); color: var(--text-2); border-color: var(--rule-strong); filter: none; }
.ftoggle { display: none; margin: 10px 12px 0; align-self: flex-start; }
.mapbody.split table.list .c-treat, .mapbody.split table.list .c-hq { display: none; }
.flagline { display: block; padding: 6px 8px; border-radius: var(--radius); margin-top: 6px; font-size: var(--fs-2); }
.flagline.open { background: var(--flag-weak); color: var(--flag); }
.flagline.closed { background: var(--surface); color: var(--text); }
.src { font-size: var(--fs-1); }
.src a { white-space: nowrap; }
.approx { font-size: var(--fs-1); color: var(--text-2); }
.ringres { margin-top: 8px; font-size: var(--fs-2); }
.ringres button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: var(--fs-2); text-align: left; }
.memberlist button { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--rule); padding: 8px 0; cursor: pointer; }
.memberlist button:hover { color: var(--accent); }
.gap { color: var(--text-2); font-size: var(--fs-1); }

/* lens extras */
.lenscard { border-top: 1px solid var(--rule); padding: 10px 12px; font-size: var(--fs-2); }
.timebar { display: flex; align-items: center; gap: 12px; }
.timebar input[type="range"] { flex: 1 1 auto; accent-color: var(--accent); }
.timebar output { min-width: 80px; font-weight: var(--w-bold); }
.spark { width: 100%; height: auto; display: block; margin-top: 8px; }

/* feed */
.feed { border: 1px solid var(--rule); border-radius: var(--radius); display: flex; flex-direction: column; min-width: 0; max-height: 760px; }
.feed-head { padding: 12px 14px 8px; border-bottom: 1px solid var(--rule); }
.feed-head h2 { font-size: var(--fs-3); font-weight: var(--w-bold); }
.feed-head p { font-size: var(--fs-1); color: var(--text-2); }
.feed-list { overflow: auto; flex: 1 1 auto; }
.fitem { padding: 10px 14px; border-bottom: 1px solid var(--rule); cursor: pointer; }
.fitem:hover { background: var(--surface); }
.fitem .fmeta { font-size: var(--fs-1); color: var(--text-2); }
.fitem .fco { font-size: var(--fs-2); font-weight: var(--w-bold); color: var(--text); }
.fitem .fsum { font-size: var(--fs-2); margin-top: 2px; }
.fitem.watched .fco::after { content: " (watching)"; font-weight: var(--w-reg); color: var(--text-2); font-size: var(--fs-1); }
.fitem.fda .ftype { color: var(--flag); }
.feed-more { padding: 10px 14px; }

/* modules */
.modules { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.module { border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; min-width: 0; }
.module h2 { font-size: var(--fs-3); font-weight: var(--w-bold); }
.module .sub { font-size: var(--fs-1); color: var(--text-2); margin-bottom: 8px; }
.module ul { list-style: none; margin: 0; padding: 0; flex: 1 1 auto; }
.module li { font-size: var(--fs-2); padding: 6px 0; border-top: 1px solid var(--rule); }
.module li:first-child { border-top: 0; }
.module li button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-align: left; }
.module .more { margin-top: 10px; font-size: var(--fs-2); }
.foot { margin-top: 24px; font-size: var(--fs-1); color: var(--text-2); max-width: 820px; }
.foot p { margin-bottom: 6px; }

/* placeholder pages */
.placeholder { max-width: 720px; border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px 20px; }
.placeholder h2 { font-size: var(--fs-4); font-weight: var(--w-bold); margin-bottom: 6px; }
.placeholder p { margin-bottom: 10px; font-size: var(--fs-3); }
.placeholder ul { margin: 0 0 10px; padding-left: 20px; }
.placeholder li { margin-bottom: 4px; }

/* Mapbox popup */
.mapboxgl-popup-content { font-family: var(--font); font-size: var(--fs-2); padding: 8px 10px; border-radius: var(--radius); }
.mapboxgl-popup-content strong { font-weight: var(--w-bold); }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1280px) {
  .mapzone { grid-template-columns: minmax(0, 1fr); }
  .feed { max-height: 460px; }
  .modules { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lens span { display: none; }
}
@media (max-width: 900px) {
  :root { --nav-w: 0px; }
  .nav-toggle { display: inline-flex; }
  .side { width: 240px; transform: translateX(-100%); transition: transform 0.15s ease; }
  .side.open { transform: none; }
  .top { gap: 10px; padding: 0 12px; }
  .brand { display: none; }
  .lens, .asof { display: none; }
  main { padding: calc(var(--top-h) + 12px) 12px 32px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modules { grid-template-columns: minmax(0, 1fr); }
  .mapbody.split { grid-template-columns: minmax(0, 1fr); }
  .mapbody.split .listpane { border-left: 0; border-top: 1px solid var(--rule); }
  .map, .mapbody { min-height: 440px; }
  .panel { top: auto; left: 0; width: 100%; max-height: 70%; border-left: 0; border-top: 1px solid var(--rule-strong); border-radius: 12px 12px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
  .filters input[type="text"] { width: 150px; }
  .ftoggle { display: inline-block; }
  .mapcard:not(.fopen) .filters, .mapcard:not(.fopen) .chips { display: none; }
  .mapcard.fopen .chips { border-top: 0; }
  .feed { order: 2; }
}
@media (prefers-reduced-motion: reduce) {
  .side { transition: none; }
}
