:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --panel: #fbfcfa;
  --panel-strong: #ffffff;
  --ink: #20251f;
  --muted: #697368;
  --line: #d8ded5;
  --line-strong: #bac5b7;
  --accent: #2f6f69;
  --accent-dark: #244f4b;
  --accent-soft: #dceae7;
  --video: #a44d42;
  --civil: #5d6f91;
  --criminal: #2f6f69;
  --archive: #7c695a;
  --remote: #9a7b36;
  --shadow: 0 22px 55px -38px rgba(35, 48, 39, 0.45);
  --mono: "SFMono-Regular", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(32, 37, 31, 0.035) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(0deg, rgba(32, 37, 31, 0.025) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

a {
  color: var(--accent-dark);
}

.shell {
  width: min(1760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding: 10px 0 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font: 700 11px/1.3 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 780px;
  margin-bottom: 0;
  font-size: clamp(34px, 5vw, 68px);
  line-height: 0.94;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.2;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(86px, 1fr));
  gap: 8px;
  min-width: min(620px, 100%);
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.stat strong {
  display: block;
  font: 700 20px/1 var(--mono);
}

.stat span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(460px, 1fr) minmax(380px, 520px);
  gap: 14px;
  align-items: start;
}

.controls,
.timeline-panel,
.results-panel,
.detail-pane {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 252, 250, 0.94);
  box-shadow: var(--shadow);
}

.controls {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 16px;
  padding: 16px;
}

.field {
  display: grid;
  gap: 7px;
}

label,
.switch span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input[type="search"],
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input[type="search"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 105, 0.14);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.segment,
.plain-button,
.video-tab,
.resource-card,
.entity-chip,
.timeline-node {
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1), border-color 180ms ease, background 180ms ease, color 180ms ease;
}

.segment {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.segment:hover,
.plain-button:hover,
.video-tab:hover,
.entity-chip:hover,
.resource-card:hover {
  transform: translateY(-1px);
}

.segment:active,
.plain-button:active,
.video-tab:active,
.entity-chip:active,
.resource-card:active,
.timeline-node:active {
  transform: translateY(1px) scale(0.99);
}

.segment.is-active {
  border-color: rgba(47, 111, 105, 0.34);
  background: var(--accent);
  color: #ffffff;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.plain-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 0 10px;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.entity-panel,
.source-note {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.source-note p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.source-note strong {
  color: var(--ink);
}

.source-note a {
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.entity-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  max-height: 230px;
  overflow: auto;
  padding-right: 4px;
}

.entity-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 6px 9px;
  cursor: pointer;
  color: var(--ink);
  font-size: 12px;
  line-height: 1;
}

.entity-chip.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.stage {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.timeline-panel {
  padding: 16px;
  overflow: hidden;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend i {
  width: 14px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
}

.legend-video {
  background: var(--video);
}

.legend-local {
  background: var(--accent);
}

.legend-remote {
  background: var(--remote);
}

.timeline {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.timeline-lane {
  min-width: 0;
}

.lane-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.lane-head span {
  color: var(--muted);
  font: 700 11px/1.2 var(--mono);
}

.month-scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 2px 12px;
  scrollbar-color: var(--line-strong) transparent;
}

.month-block {
  flex: 0 0 auto;
  min-width: 94px;
  border-left: 1px solid var(--line);
  padding-left: 8px;
}

.month-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font: 700 11px/1 var(--mono);
  text-transform: uppercase;
}

.node-row {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  min-height: 58px;
}

.timeline-node {
  position: relative;
  width: 12px;
  height: 58px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.timeline-node::before {
  content: "";
  position: absolute;
  left: 2px;
  right: 2px;
  bottom: 0;
  height: var(--node-height, 24px);
  min-height: 9px;
  border-radius: 4px 4px 2px 2px;
  background: var(--accent);
}

.timeline-node[data-trial="civil"]::before {
  background: var(--civil);
}

.timeline-node[data-kind="remote"]::before {
  background: var(--remote);
}

.timeline-node.has-video::after {
  content: "";
  position: absolute;
  left: 2px;
  right: 2px;
  top: 0;
  height: 8px;
  border-radius: 4px;
  background: var(--video);
}

.timeline-node.is-selected {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.results-panel {
  padding: 16px;
}

.resource-list {
  display: grid;
  gap: 8px;
  max-height: calc(100dvh - 390px);
  min-height: 360px;
  overflow: auto;
  margin-top: 14px;
  padding-right: 4px;
}

.resource-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.resource-card.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.date-tile {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(244, 246, 243, 0.72);
  color: var(--muted);
  font: 700 11px/1.1 var(--mono);
  text-transform: uppercase;
}

.date-tile strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
}

.resource-main {
  min-width: 0;
}

.resource-title {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.resource-meta,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--muted);
  padding: 0 7px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.pill.video {
  border-color: rgba(164, 77, 66, 0.28);
  color: var(--video);
}

.pill.text-hit {
  border-color: rgba(45, 90, 132, 0.26);
  color: #2d5a84;
}

.pill.remote {
  border-color: rgba(154, 123, 54, 0.34);
  color: var(--remote);
}

.pill.criminal {
  border-color: rgba(47, 111, 105, 0.26);
  color: var(--criminal);
}

.pill.civil {
  border-color: rgba(93, 111, 145, 0.28);
  color: var(--civil);
}

.resource-hit {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.detail {
  position: sticky;
  top: 16px;
  min-width: 0;
}

.detail-pane {
  max-height: calc(100dvh - 32px);
  overflow: auto;
}

.detail-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.detail-header h2 {
  margin-top: 8px;
  font-size: 22px;
  line-height: 1.08;
}

.summary {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.action-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  padding: 0 10px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.button-link {
  cursor: pointer;
}

.media-panel {
  border-bottom: 1px solid var(--line);
  background: #eef2ee;
}

.video-poster {
  position: relative;
  min-height: 268px;
  overflow: hidden;
  background: #1e241f;
}

.video-poster > img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 268px;
  object-fit: cover;
  filter: saturate(0.92) contrast(0.98);
}

.poster-overlay {
  position: absolute;
  inset: auto 0 0;
  display: grid;
  gap: 8px;
  padding: 18px;
  background: linear-gradient(0deg, rgba(30, 36, 31, 0.92), rgba(30, 36, 31, 0.18));
  color: #ffffff;
}

.poster-overlay strong {
  font-size: 15px;
  line-height: 1.25;
}

.poster-overlay span {
  color: rgba(255, 255, 255, 0.78);
  font: 700 11px/1 var(--mono);
}

.poster-overlay .action-link {
  border-color: rgba(255, 255, 255, 0.32);
}

.video-embed-message .poster-overlay {
  inset: 0;
  align-content: center;
  background: linear-gradient(135deg, rgba(30, 36, 31, 0.96), rgba(58, 71, 60, 0.94));
}

.video-embed-message .poster-overlay span {
  max-width: 62ch;
  font: 700 12px/1.5 var(--sans);
}

.video-frame-wrap {
  aspect-ratio: 16 / 9;
  background: #1e241f;
}

.video-frame-wrap iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.video-tabs {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.video-tab {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 7px;
  text-align: left;
  cursor: pointer;
}

.video-tab.is-active {
  border-color: var(--video);
}

.video-tab img {
  width: 92px;
  aspect-ratio: 16 / 9;
  border-radius: 5px;
  object-fit: cover;
  background: #d8ded5;
}

.video-tab strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.video-tab span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font: 700 11px/1 var(--mono);
}

.detail-section {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.detail-section:last-child {
  border-bottom: 0;
}

.transcript-tools {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 12px 0;
}

.transcript-tools input {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
}

.transcript-box {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
  white-space: pre-wrap;
  color: #273027;
  font: 12px/1.55 var(--mono);
}

.snippet-list {
  display: grid;
  gap: 7px;
  margin-bottom: 10px;
}

.search-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.snippet {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 9px;
  width: 100%;
  border-left: 3px solid var(--accent);
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  background: rgba(47, 111, 105, 0.08);
  padding: 8px 10px;
  color: #354138;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.45;
  text-align: left;
}

.snippet.is-active {
  background: rgba(47, 111, 105, 0.16);
}

.snippet-index {
  color: var(--accent-dark);
  font: 800 11px/1.45 var(--mono);
}

.transcript-box mark {
  border-radius: 3px;
  background: #f0d36a;
  color: #1e241f;
  padding: 0 2px;
}

.related-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.related-item {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  color: inherit;
  text-decoration: none;
}

.related-item strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
}

.related-item span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.empty,
.error {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.error {
  border-color: rgba(164, 77, 66, 0.38);
  background: rgba(164, 77, 66, 0.07);
  color: #7a352d;
}

.loading-block {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.loading-block span {
  height: 20px;
  border-radius: 6px;
  background: linear-gradient(90deg, #e3e8e1, #f7f8f6, #e3e8e1);
  background-size: 220% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.loading-block span:nth-child(2) {
  width: 82%;
}

.loading-block span:nth-child(3) {
  width: 64%;
}

@keyframes shimmer {
  from {
    background-position: 120% 0;
  }
  to {
    background-position: -120% 0;
  }
}

@media (max-width: 1160px) {
  .workspace {
    grid-template-columns: 260px minmax(420px, 1fr);
  }

  .detail {
    position: static;
    grid-column: 1 / -1;
  }

  .detail-pane {
    max-height: none;
  }
}

@media (max-width: 860px) {
  .shell {
    width: min(100% - 20px, 760px);
    padding-top: 14px;
  }

  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .stat-row {
    min-width: 0;
    grid-template-columns: repeat(2, 1fr);
  }

  .controls,
  .detail {
    position: static;
  }

  .resource-list {
    max-height: 520px;
  }
}

@media (max-width: 520px) {
  .stat-row,
  .resource-card,
  .video-tab,
  .transcript-tools {
    grid-template-columns: 1fr;
  }

  .date-tile {
    min-height: 46px;
    justify-items: start;
    padding: 8px;
  }

  .video-tab img {
    width: 100%;
  }
}
