:root {
  --ink: #0b1c2c;
  --ink-soft: #1a3348;
  --mist: #e6eef4;
  --paper: #f3f7fa;
  --line: #c5d4e0;
  --teal: #1a6b5c;
  --teal-soft: #d7efe9;
  --amber: #c45c26;
  --amber-soft: #f8e6dc;
  --slate: #5a7184;
  --high: #9b2c2c;
  --med: #a15c12;
  --low: #3d5a6c;
  --font-display: "Anuphan", "Sarabun", sans-serif;
  --font-body: "Sarabun", "Anuphan", sans-serif;
  --radius: 6px;
  --shadow: 0 12px 40px rgba(11, 28, 44, 0.08);
  --max: 1080px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.65;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(26, 107, 92, 0.12), transparent 55%),
    radial-gradient(900px 420px at 95% 0%, rgba(196, 92, 38, 0.1), transparent 50%),
    linear-gradient(180deg, #d9e6ef 0%, var(--paper) 28%, var(--mist) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(11, 28, 44, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(11, 28, 44, 0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  z-index: 0;
}

.wrap,
.site-header,
.site-footer {
  position: relative;
  z-index: 1;
}

.wrap {
  width: min(100% - 2rem, var(--max));
  margin-inline: auto;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 0.5rem 1rem;
  z-index: 10;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Header */
.site-header {
  border-bottom: 1px solid rgba(11, 28, 44, 0.08);
  background: rgba(243, 247, 250, 0.82);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  background:
    conic-gradient(from 210deg, var(--teal), var(--ink-soft), var(--amber), var(--teal));
  box-shadow: inset 0 0 0 3px var(--paper);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.brand-text strong {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-text span {
  font-size: 0.85rem;
  color: var(--slate);
}

.header-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-end;
}

.stat-pill {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(11, 28, 44, 0.08);
  color: var(--ink-soft);
}

.top-tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.85rem 0 0;
  border-bottom: 1px solid rgba(11, 28, 44, 0.08);
  margin-bottom: 0.25rem;
}

.top-tab {
  font: inherit;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  border: 0;
  background: transparent;
  color: var(--slate);
  padding: 0.65rem 1rem 0.75rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.top-tab:hover {
  color: var(--ink);
}

.top-tab.is-active {
  color: var(--teal);
  border-bottom-color: var(--teal);
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0.5rem 0 1.25rem;
  animation: rise 0.55s ease both;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
}

.filter-label {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
}

.filter.labeled {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.filter.labeled > span {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.topic-filter select {
  min-width: 18rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip-btn {
  font: inherit;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chip-btn:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.chip-btn.is-active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.date-picker select,
.filter select,
.range-picker select,
.search input {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  min-width: 10rem;
}

.range-picker {
  flex: 0 0 auto;
}

.range-picker select {
  min-width: 8.5rem;
  font-family: var(--font-display);
  font-weight: 600;
}

.search {
  flex: 1;
  min-width: 12rem;
}

.search input {
  width: 100%;
  min-width: 0;
}

.toolbar-row .filter,
.toolbar-row .search {
  display: flex;
}

.hero-compact {
  padding-top: 2rem;
  padding-bottom: 1.25rem;
}

.hero-compact h1 {
  max-width: none;
}

/* Hero */
.hero {
  padding: clamp(2.5rem, 7vw, 4.5rem) 0 2rem;
  animation: rise 0.7s ease both;
}

.hero-kicker {
  margin: 0 0 0.6rem;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--teal);
}

.hero h1 {
  margin: 0 0 0.8rem;
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 4.5vw, 3rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.03em;
  max-width: 16ch;
}

.hero-lead {
  margin: 0;
  max-width: 42rem;
  color: var(--ink-soft);
  font-size: 1.12rem;
}

.hero-lead code {
  font-size: 0.92em;
  background: rgba(11, 28, 44, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.hero-meta {
  margin: 1rem 0 0;
  color: var(--slate);
  font-size: 0.95rem;
}

/* KPI */
.kpi {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  animation: rise 0.7s ease 0.08s both;
}

.kpi-item {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(11, 28, 44, 0.06);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}

.kpi-item .label {
  display: block;
  font-size: 0.82rem;
  color: var(--slate);
  margin-bottom: 0.25rem;
}

.kpi-item .value {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

/* Panels */
.panel {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(11, 28, 44, 0.06);
  border-radius: calc(var(--radius) + 2px);
  padding: 1.25rem 1.35rem 1.4rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  animation: rise 0.65s ease both;
}

.panel h2 {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 0;
}

.grid-two .panel {
  margin-bottom: 1.25rem;
}

.muted {
  color: var(--slate);
  font-size: 0.95rem;
}

/* Bars */
.bars {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.35rem 0.75rem;
  align-items: center;
}

.bar-row .name {
  font-size: 0.95rem;
}

.bar-row .count {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.bar-track {
  grid-column: 1 / -1;
  height: 8px;
  background: rgba(11, 28, 44, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--teal), var(--ink-soft));
  border-radius: inherit;
  transition: width 0.7s ease;
}

.bar-fill.surge {
  background: linear-gradient(90deg, var(--amber), #8b3a14);
}

.delta {
  font-size: 0.85rem;
  font-weight: 600;
}

.delta.up {
  color: var(--amber);
}

.delta.down {
  color: var(--teal);
}

/* Alerts */
.alerts-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.alert-item {
  border-left: 3px solid var(--amber);
  padding: 0.55rem 0 0.55rem 0.9rem;
  background: var(--amber-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.alert-item strong {
  display: block;
  font-family: var(--font-display);
  margin-bottom: 0.25rem;
}

.alert-item ul {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
}

/* Posts */
.posts-panel {
  border: 1px solid rgba(26, 107, 92, 0.18);
  box-shadow: 0 14px 44px rgba(11, 28, 44, 0.1);
}

.posts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.posts-head h2 {
  margin: 0;
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.post-list li {
  border-top: 1px solid rgba(11, 28, 44, 0.08);
  padding-top: 0.85rem;
}

.post-list li:first-child {
  border-top: 0;
  padding-top: 0.25rem;
}

.post-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

.post-link:hover .post-title,
.post-link:focus-visible .post-title {
  color: var(--teal);
}

.post-title {
  font-family: var(--font-display);
  font-size: 1.08rem;
  font-weight: 700;
  margin: 0 0 0.35rem;
  letter-spacing: -0.015em;
  transition: color 0.15s ease;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--font-display);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: rgba(11, 28, 44, 0.06);
  color: var(--ink-soft);
}

.chip.sev-high {
  background: #f8d7d7;
  color: var(--high);
}

.chip.sev-medium {
  background: #f6e5c8;
  color: var(--med);
}

.chip.sev-low {
  background: #d9e4ec;
  color: var(--low);
}

.chip.alert {
  background: var(--amber-soft);
  color: var(--amber);
}

.chip.ok {
  background: var(--teal-soft);
  color: var(--teal);
}

.post-agency {
  margin: 0;
  color: var(--slate);
  font-size: 0.92rem;
}

/* Detail */
.post-detail h1 {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  line-height: 1.3;
  margin: 0.5rem 0 0.75rem;
}

.post-detail .content {
  white-space: pre-wrap;
  margin: 1rem 0;
}

.post-detail .analysis-block,
.post-detail .fact-card {
  margin: 1.1rem 0;
  padding-top: 0.4rem;
  border-top: 1px solid var(--line, #d5ddd8);
}

.post-detail .analysis-block h2,
.post-detail .fact-card h2 {
  font-size: 1.05rem;
  margin: 0.4rem 0;
}

.post-detail .story-graph-block .story-ego-wrap {
  margin: 0.75rem 0 0.5rem;
  padding: 0.5rem;
  background: #eef3f7;
  border: 1px solid var(--line, #d5ddd8);
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

.post-detail .story-ego-svg,
.post-detail .story-ego-img,
.post-detail .story-ego-canvas {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  margin: 0 auto;
}

.post-detail .story-ego-canvas {
  height: 640px;
  min-height: 640px;
  background: #f7fafc;
  border-radius: 8px;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  cursor: grab;
}

.post-detail .story-rel-heading {
  font-size: 0.95rem;
  margin: 0.85rem 0 0.35rem;
}

.post-detail .story-rel-list {
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.2rem;
}

.post-detail .story-rel-list code,
.post-detail .story-rel-label {
  font-size: 0.82em;
  background: #10211e;
  color: #f7fffc;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-weight: 600;
  font-family: var(--font-body);
}

.post-detail .story-graph-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.35rem 0 0.55rem;
}

a.story-open-graph {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.post-detail .story-graph-link {
  margin-top: 0.5rem;
}

.post-detail .pre {
  white-space: pre-wrap;
}

.post-detail .fact-card dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.6rem 1rem;
  margin: 0;
}

.post-detail .fact-card dt {
  font-size: 0.78rem;
  color: var(--slate);
}

.post-detail .fact-card dd {
  margin: 0.15rem 0 0;
}

.post-detail .actions {
  background: var(--mist);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin: 1rem 0;
}

.post-detail .back {
  display: inline-block;
  margin-bottom: 0.5rem;
  color: var(--teal);
  font-weight: 600;
  text-decoration: none;
}

.post-detail .back:hover {
  text-decoration: underline;
}

.source-link {
  color: var(--teal);
  font-weight: 600;
}

.source-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.source-chip {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--teal);
  text-decoration: none;
  background: var(--teal-soft);
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
}

.source-chip:hover {
  text-decoration: underline;
}

.sources-block {
  margin-top: 1.25rem;
  padding: 0.9rem 1rem;
  background: var(--mist);
  border-radius: var(--radius);
}

.sources-block strong {
  display: block;
  font-family: var(--font-display);
  margin-bottom: 0.45rem;
}

.source-list {
  margin: 0;
  padding-left: 1.15rem;
}

.source-list li {
  margin: 0.25rem 0;
}

.download-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.download-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  border-top: 1px solid rgba(11, 28, 44, 0.08);
}

.download-item:first-child {
  border-top: 0;
  padding-top: 0.25rem;
}

.download-item .muted {
  margin: 0.2rem 0 0;
  word-break: break-all;
}

.download-btn {
  flex-shrink: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
  color: #fff;
  background: var(--teal);
  padding: 0.55rem 0.95rem;
  border-radius: var(--radius);
}

.download-btn:hover {
  background: var(--ink-soft);
}

.downloads-toolbar {
  margin-bottom: 1rem;
}

.status {
  display: block;
  text-align: center;
  color: var(--slate);
  padding: 1rem 0 2.5rem;
  font-size: 0.95rem;
}

.site-footer {
  border-top: 1px solid rgba(11, 28, 44, 0.08);
  padding: 1.5rem 0 2rem;
  background: rgba(255, 255, 255, 0.45);
}

.site-footer p {
  margin: 0 0 0.4rem;
  max-width: 40rem;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .toolbar,
  .hero,
  .kpi,
  .panel {
    animation: none;
  }
}

/* ข้อมูลกราฟ — full-bleed horizontal workspace */
body.is-brain .site-footer {
  display: none;
}

#main.main-brain.wrap {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

.view-brain {
  width: 100%;
}

.brain-shell {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 0.85rem 0.85rem;
  min-height: calc(100vh - 7.5rem);
  box-sizing: border-box;
}

.brain-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.75rem 1.25rem;
  width: 100%;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.62);
}

.brain-topbar-title {
  min-width: 12rem;
}

.brain-kicker {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 600;
}

.brain-topbar-title h1 {
  margin: 0.1rem 0;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 2vw, 1.75rem);
  line-height: 1.2;
}

.brain-status-line {
  margin: 0;
  font-size: 0.88rem;
  color: var(--slate);
}

.brain-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  font-size: 0.9rem;
  color: var(--ink-soft);
  flex: 1 1 auto;
}

.brain-stats strong {
  color: var(--ink);
  font-weight: 700;
}

.brain-help-box {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.7);
  padding: 0.35rem 0.65rem;
  margin-left: auto;
}

.brain-help-box summary {
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink-soft);
  list-style: none;
}

.brain-help-box summary::-webkit-details-marker {
  display: none;
}

.brain-help {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  z-index: 20;
  width: min(420px, 92vw);
  max-height: 50vh;
  overflow: auto;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.brain-help h3 {
  margin: 0.65rem 0 0.3rem;
  font-size: 0.95rem;
  font-family: var(--font-display);
  color: var(--ink);
}

.brain-help h3:first-child {
  margin-top: 0;
}

.brain-help ul {
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.1rem;
}

.brain-help-colors {
  list-style: none;
  padding-left: 0;
}

.brain-help-colors li {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  margin-bottom: 0.4rem;
}

.brain-help-colors i {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  margin-top: 0.35rem;
  flex: 0 0 auto;
}

.brain-filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.55rem 0.7rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.7);
}

.brain-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--slate);
  margin: 0;
}

.brain-field-search {
  flex: 1 1 14rem;
  min-width: 12rem;
}

#brain-relation {
  max-width: 16rem;
}

.brain-field-narrow {
  width: 5.5rem;
}

.brain-field input,
.brain-field select {
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.38rem 0.5rem;
  background: #fff;
  min-height: 2.15rem;
}

.brain-fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0;
  padding: 0.2rem 0.5rem 0.35rem;
}

.brain-fieldset-inline {
  display: flex;
  flex-direction: column;
}

.brain-fieldset legend {
  font-size: 0.78rem;
  color: var(--slate);
  padding: 0 0.2rem;
}

.brain-checks-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.7rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.brain-checks label,
.brain-check {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  white-space: nowrap;
}

.brain-check {
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin: 0 0 0.15rem;
  min-height: 2.15rem;
}

.brain-filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
  margin-left: auto;
}

.btn-ghost {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 0.92rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 2.15rem;
}

.btn-ghost:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.brain-legend-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 1rem;
  width: 100%;
  padding: 0 0.15rem;
}

.brain-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.brain-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.45);
  color: var(--ink-soft);
  font-size: 0.85rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-body);
}

.brain-legend-item i {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  display: inline-block;
}

.brain-legend-item span {
  color: var(--slate);
}

.brain-legend-item.is-active {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.brain-hint {
  margin: 0;
  font-size: 0.84rem;
}

.brain-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 0.75rem;
  align-items: stretch;
  height: calc(100vh - 15rem);
  min-height: 640px;
}

.brain-workspace .brain-stage {
  min-height: 0;
  height: 100%;
}

.brain-workspace #brain-canvas {
  height: 100%;
  min-height: 0;
}

.brain-chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(248, 251, 255, 0.96);
  overflow: hidden;
}

.brain-chat-log {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.85rem 0.9rem 1rem;
}

.brain-chat-empty {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.brain-chat-empty[hidden] {
  display: none;
}

.brain-ask-examples {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.brain-example {
  white-space: normal;
  text-align: left;
  line-height: 1.45;
  height: auto;
}

.chat-turn {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.chat-bubble {
  border-radius: var(--radius);
  padding: 0.7rem 0.8rem;
}

.chat-user {
  align-self: flex-end;
  max-width: 95%;
  background: var(--teal-soft);
  color: var(--ink);
}

.chat-assistant {
  align-self: stretch;
  background: #fff;
  border: 1px solid var(--line);
}

.brain-chat-form {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  padding: 0.7rem;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.brain-chat-form input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem 0.6rem;
  background: #fff;
  min-height: 2.4rem;
}

.rag-holder {
  margin: 0.35rem 0;
  font-size: 1.02rem;
}

.rag-holder strong {
  font-family: var(--font-display);
}

.rag-answer h3,
.rag-answer h4,
.rag-narration h3,
.rag-qty-group h4 {
  font-family: var(--font-display);
  line-height: 1.35;
}

.rag-answer h3 {
  margin: 0.15rem 0 0.4rem;
  font-size: 1.12rem;
}

.rag-answer h4,
.rag-qty-group h4,
.rag-narration h3 {
  margin: 0.85rem 0 0.3rem;
  font-size: 0.98rem;
}

.rag-count {
  margin: 0.35rem 0 0.15rem;
  font-size: 1.05rem;
}

.rag-count strong {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--teal);
  margin-right: 0.25rem;
}

.rag-warn {
  margin: 0.35rem 0;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius);
  background: var(--amber-soft);
  color: var(--ink);
  font-size: 0.92rem;
}

.rag-cases,
.rag-qty-group ul,
.rag-answer section ul {
  margin: 0.25rem 0 0.4rem;
  padding-left: 1.15rem;
}

.rag-cases li,
.rag-answer li {
  margin: 0.45rem 0;
}

.rag-cases a,
.rag-answer a {
  color: var(--teal);
}

.rag-qty {
  font-weight: 700;
}

.rag-files {
  margin: 0.15rem 0 0;
  font-size: 0.88rem;
}

.rag-narration {
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
}

.rag-narration-body {
  white-space: normal;
  overflow: visible;
  max-height: none;
}

.rag-narration-body p,
.rag-narration-body h4 {
  margin: 0.45rem 0;
}

.rag-narration-body h4 {
  font-family: var(--font-display);
  font-size: 1rem;
}

.rag-narration-body ul,
.rag-narration-body ol {
  margin: 0.3rem 0 0.65rem;
  padding-left: 1.2rem;
}

.rag-narration-body li {
  margin: 0.28rem 0;
}

.rag-llm {
  margin-top: 0.75rem;
  padding: 0.75rem 0.8rem;
  border: 1px solid var(--teal);
  border-radius: var(--radius);
  background: #fff;
  overflow: visible;
  max-height: none;
}

.rag-evidence {
  margin-top: 0.7rem;
}

.rag-evidence summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--teal);
}

.brain-stage {
  position: relative;
  display: block;
  width: 100%;
  flex: 1 1 auto;
  min-height: calc(100vh - 12rem);
}

#brain-canvas {
  display: block;
  position: relative;
  z-index: 1;
  width: 100%;
  height: calc(100vh - 12rem);
  min-height: 640px;
  border: 1px solid rgba(80, 96, 118, 0.55);
  border-radius: var(--radius);
  /* Obsidian-like dark graph plane */
  background:
    radial-gradient(ellipse at 28% 18%, rgba(125, 211, 192, 0.07), transparent 42%),
    radial-gradient(ellipse at 78% 72%, rgba(110, 168, 216, 0.06), transparent 40%),
    radial-gradient(circle at 50% 50%, #252b36 0%, #1a1f28 62%, #141820 100%);
  touch-action: none;
  pointer-events: auto;
  cursor: grab;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

#brain-canvas:active {
  cursor: grabbing;
}

.brain-detail {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: min(340px, 34vw);
  max-height: calc(100% - 1.5rem);
  border: 1px solid rgba(120, 140, 165, 0.35);
  border-radius: var(--radius);
  background: rgba(248, 251, 255, 0.94);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  padding: 0.95rem 1.05rem;
  overflow: auto;
  z-index: 5;
}

.brain-detail-placeholder h3 {
  margin: 0.2rem 0;
}

.brain-detail h3 {
  margin: 0.15rem 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  line-height: 1.35;
}

.brain-kind {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 600;
}

.brain-help-inline {
  margin: 0 0 0.4rem;
  font-size: 0.88rem;
  color: var(--slate);
}

.brain-path {
  font-size: 0.82rem;
  word-break: break-all;
}

.brain-dl {
  display: grid;
  gap: 0.35rem;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}

.brain-dl div {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0.35rem;
}

.brain-dl dt {
  margin: 0;
  color: var(--slate);
}

.brain-dl dd {
  margin: 0;
}

.brain-excerpt {
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.brain-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.brain-tags span {
  background: var(--mist);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  font-size: 0.8rem;
}

.brain-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.65rem 0;
}

.brain-links {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.brain-links ul {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
}

.brain-links button {
  border: 0;
  background: none;
  color: var(--teal);
  text-align: left;
  padding: 0.15rem 0;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (max-width: 900px) {
  .brain-filter-actions {
    margin-left: 0;
    width: 100%;
  }

  .brain-workspace {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .brain-stage {
    min-height: 72vh;
  }

  .brain-workspace #brain-canvas,
  #brain-canvas {
    height: 72vh;
    min-height: 480px;
  }

  .brain-chat {
    height: auto;
    min-height: 70vh;
  }

  .brain-chat-log {
    min-height: 52vh;
  }

  .brain-detail {
    position: static;
    width: 100%;
    max-height: 40vh;
    margin-top: 0.65rem;
  }
}

@media (max-width: 860px) {
  .kpi {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-two {
    grid-template-columns: 1fr;
  }

  .header-inner {
    flex-wrap: wrap;
  }

  .header-stats {
    width: 100%;
    justify-content: flex-start;
  }

  .hero h1 {
    max-width: none;
  }

  .download-item {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 480px) {
  .kpi {
    grid-template-columns: 1fr;
  }

  .posts-head {
    flex-direction: column;
    align-items: stretch;
  }
}
