:root {
  --ink: #17212b;
  --muted: #5d6975;
  --line: #d8dde2;
  --paper: #f7f4ed;
  --surface: #fffdf8;
  --teal: #0e7c7b;
  --teal-dark: #075f60;
  --brick: #a63d40;
  --gold: #b98518;
  --violet: #58508d;
  --shadow: 0 20px 55px rgba(23, 33, 43, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
  max-width: 100vw;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  color: #f8fafc;
  background:
    linear-gradient(140deg, rgba(166, 61, 64, 0.22), transparent 36%),
    linear-gradient(180deg, #15212d 0%, #0d1823 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 8px;
  color: #0d1823;
  background: #f2c36b;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 2px;
  color: rgba(248, 250, 252, 0.66);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: rgba(248, 250, 252, 0.78);
  background: transparent;
  text-align: left;
  padding: 0 12px;
}

.nav-item:hover,
.nav-item.active {
  border-color: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.source-policy {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.source-policy p {
  margin: 8px 0 0;
  color: rgba(248, 250, 252, 0.72);
  font-size: 13px;
  line-height: 1.5;
}

.status-dot {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #54d6a1;
  box-shadow: 0 0 0 6px rgba(84, 214, 161, 0.15);
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  overflow: hidden;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  min-width: 0;
}

.topbar > div {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  max-width: 980px;
  margin: 0;
  font-size: clamp(30px, 4.5vw, 62px);
  line-height: 0.98;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

body:not([data-active-view="research"]) h1 {
  max-width: 780px;
  font-size: clamp(28px, 3vw, 44px);
  line-height: 1.05;
}

body:not([data-active-view="research"]) .status-grid,
body:not([data-active-view="research"]) .query-band,
body:not([data-active-view="research"]) .process-rail {
  display: none;
}

body:not([data-active-view="research"]) .section-heading {
  display: grid;
  justify-content: stretch;
  align-items: start;
  gap: 4px;
}

body:not([data-active-view="research"]) .section-heading strong {
  text-align: left;
  overflow-wrap: anywhere;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
}

.icon-button,
.primary-button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.icon-button {
  width: 42px;
  color: var(--ink);
  background: #e4e8ec;
}

.primary-button {
  padding: 0 16px;
  color: #ffffff;
  background: var(--teal);
}

.primary-button:hover {
  background: var(--teal-dark);
}

.query-band,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.query-band {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(220px, 360px) auto;
  gap: 16px;
  align-items: end;
  padding: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid #cdd3d9;
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  padding: 10px 12px;
  outline: none;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(14, 124, 123, 0.16);
}

.control-grid {
  display: grid;
  gap: 10px;
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 10px;
  text-transform: none;
}

.toggle-line input {
  width: 18px;
}

.run-button {
  min-width: 168px;
}

.view {
  display: none;
  min-height: 0;
}

.active-view {
  display: block;
}

.main-grid,
.channel-layout,
.creator-layout {
  display: grid;
  grid-template-columns: minmax(330px, 0.95fr) minmax(420px, 1.25fr);
  gap: 18px;
}

.panel {
  min-width: 0;
  padding: 16px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.section-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.section-heading strong {
  text-align: right;
}

.section-heading.wide {
  margin-top: 4px;
}

.answer-output {
  display: grid;
  gap: 12px;
}

.answer-block {
  border-left: 4px solid var(--teal);
  padding: 10px 12px;
  background: #eef7f6;
}

.answer-block.interpretation {
  border-left-color: var(--gold);
  background: #fff5df;
}

.answer-block.speculation {
  border-left-color: var(--brick);
  background: #fff0ef;
}

.answer-block h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.answer-block p {
  margin: 0;
  color: #33414f;
  line-height: 1.55;
}

.citation {
  display: inline-block;
  margin-top: 8px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
}

.graph-panel {
  display: flex;
  flex-direction: column;
}

canvas {
  width: 100%;
  aspect-ratio: 3 / 2;
  border: 1px solid #d9dee3;
  border-radius: 8px;
  background: #fbfaf6;
}

.node-detail {
  min-height: 46px;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.45;
}

.strip-grid,
.library-grid,
.lens-grid,
.format-grid,
.hunter-list {
  display: grid;
  gap: 12px;
}

.strip-grid {
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  margin-top: 18px;
}

.mini-card,
.library-card,
.lens-card,
.format-card,
.hunter-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.mini-card strong,
.library-card strong,
.lens-card strong,
.format-card strong,
.hunter-card strong {
  display: block;
  margin-bottom: 6px;
}

.mini-card p,
.library-card p,
.lens-card p,
.format-card p,
.hunter-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.library-grid {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}

.lens-grid {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.pill {
  border-radius: 999px;
  color: #26313d;
  background: #ece8dd;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
}

.channel-layout .panel:first-child,
.creator-layout .panel:first-child {
  align-self: start;
}

.channel-status {
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.55;
}

.format-grid {
  grid-template-columns: repeat(2, minmax(160px, 1fr));
}

.format-card {
  text-align: left;
}

.format-card.active {
  border-color: var(--teal);
  box-shadow: inset 0 0 0 2px rgba(14, 124, 123, 0.18);
}

pre {
  min-height: 420px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  color: #24303b;
  background: #f3f0e7;
  border-radius: 8px;
  padding: 16px;
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  transform: translateY(20px);
  opacity: 0;
  max-width: 320px;
  border-radius: 8px;
  color: #ffffff;
  background: #17212b;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transition: 180ms ease;
  pointer-events: none;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(130px, 1fr));
    overflow-x: auto;
  }

  .source-policy {
    display: none;
  }

  .query-band,
  .main-grid,
  .channel-layout,
  .creator-layout {
    grid-template-columns: 1fr;
  }

  .strip-grid,
  .library-grid,
  .lens-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }
}

@media (max-width: 680px) {
  .workspace,
  .sidebar {
    padding: 16px;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    width: 100%;
  }

  .primary-button {
    flex: 1;
  }

  .strip-grid,
  .library-grid,
  .lens-grid,
  .format-grid {
    grid-template-columns: 1fr;
  }

  .nav-list {
    grid-template-columns: 1fr;
  }

  h1 {
    width: 100%;
    max-width: 340px;
    font-size: 28px;
    line-height: 1.08;
  }

  body:not([data-active-view="research"]) h1 {
    max-width: 340px;
    font-size: 24px;
  }

  .eyebrow {
    font-size: 11px;
    overflow-wrap: anywhere;
  }
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
}

.status-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.78);
  padding: 12px 14px;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.status-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 14px;
}

.secondary-button {
  min-height: 40px;
  border: 1px solid #cdd3d9;
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  padding: 0 14px;
  font-weight: 800;
}

.secondary-button:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.process-rail {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.process-step {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.74);
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 800;
}

.process-step span {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: #ffffff;
  background: #75818c;
}

.process-step.active {
  color: var(--ink);
  border-color: rgba(14, 124, 123, 0.42);
}

.process-step.active span {
  background: var(--teal);
}

.packet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.research-lower {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(300px, 0.55fr);
  gap: 18px;
  margin-top: 18px;
}

.research-lower .strip-grid {
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  margin-top: 0;
}

.citation-list {
  display: grid;
  gap: 12px;
}

.citation-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.citation-card strong {
  display: block;
  margin-bottom: 6px;
}

.citation-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.empty-state {
  border: 1px dashed #c8ced4;
  border-radius: 8px;
  padding: 12px;
  background: #fbfaf6;
}

@media (max-width: 1180px) {
  .research-lower {
    grid-template-columns: 1fr;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }
}

@media (max-width: 680px) {
  .status-grid,
  .process-rail,
  .research-lower .strip-grid {
    grid-template-columns: 1fr;
  }

  .secondary-button {
    flex: 1;
  }

  .process-step {
    min-height: 38px;
  }

  .query-band {
    padding: 12px;
  }

  .section-heading {
    display: grid;
    justify-content: stretch;
    align-items: start;
    gap: 4px;
  }

  .section-heading strong {
    text-align: left;
    overflow-wrap: anywhere;
  }

  canvas {
    min-height: 280px;
  }
}
