:root {
  --bg: #5805bc;
  --surface: #f7f4ed;
  --text: #fff;
  --text-strong: rgba(28, 28, 28, 0.83);
  --text-muted: #fff;


    --bg-900: #0B1020;
    --bg-850: #0E1428;
    --bg-800: #121A33;
    --bg-750: #16203C;
    --bg-700: #1B2747;
    --bg-600: #233158;
    --bg-500: #2E3D6A;
    --line: #2C3A63;
    --line-soft: #1F2A4A;
    --tx-hi: #F3F6FF;
    --tx-mid: #A8B4D4;
    --tx-lo: #6B78A0;
    --tx-dim: #48547A;
    --accent: #FFC531;
    --accent-dim: #C89A1F;
    --accent-glow: rgba(255, 197, 49, 0.16);
    --accent-ink: #0B1020;
    --accent-2: #48C6E8;
    --accent-2-dim: #2E9BBB;
    --accent-2-glow: rgba(72, 198, 232, 0.14);
    --kind-manual-bg: rgba(255, 197, 49, 0.14);
    --kind-manual-fg: #FFC531;
    --kind-standard-bg: rgba(72, 198, 232, 0.16);
    --kind-standard-fg: #6FD0EC;
    --kind-capture-bg: rgba(74, 222, 128, 0.14);
    --kind-capture-fg: #4ADE80;
    --kind-product-bg: rgba(72, 198, 232, 0.14);
    --kind-product-fg: #48C6E8;




  --border: linear-gradient(180deg, var(--bg-700), var(--bg-800));
  --border-interactive: rgba(28, 28, 28, 0.4);
  --tint-04: rgba(28, 28, 28, 0.04);
  --tint-03: rgba(28, 28, 28, 0.03);
  --on-dark: #fcfbf8;
  --ring: rgba(59, 130, 246, 0.5);
  --focus-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px;
  --btn-inset: rgba(255, 255, 255, 0.2) 0px 0.5px 0px 0px inset, rgba(0, 0, 0, 0.2) 0px 0px 0px 0.5px inset,
    rgba(0, 0, 0, 0.05) 0px 1px 2px 0px;

  /* Citation states are a correctness signal, not decoration, so they keep
     enough saturation to stay legible -- muted/earthy to sit inside the warm
     palette rather than the bright red/amber/green a dark-UI would use. */
  --success: #3f7d4f;
  --success-bg: rgba(63, 125, 79, 0.1);
  --success-border: rgba(63, 125, 79, 0.35);
  --warn: #a15c0a;
  --warn-bg: rgba(161, 92, 10, 0.1);
  --warn-border: rgba(161, 92, 10, 0.32);
  --danger: #a5402c;
  --danger-bg: rgba(165, 64, 44, 0.1);
  --danger-border: rgba(165, 64, 44, 0.32);

  --radius-sm: 4px;
  --radius: 6px;
  --radius-md: 8px;
  --radius-card: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;

  --font: "Camera Plain Variable", ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg-900);
  color: var(--text);
  line-height: 1.5;
  font-weight: 400;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.header {
  margin-bottom: 2rem;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  position: relative;
}

.lang-switch {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 0.15rem;
  gap: 0.15rem;
}

.lang-btn {
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.78rem;
  padding: 0.25rem 0.7rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.lang-btn:hover {
  color: var(--text);
}

.lang-btn.active {
  background: var(--text);
  color: var(--on-dark);
}

.logo {
  font-size: 2.25rem;
  font-weight: 600;
  letter-spacing: -0.9px;
  color: var(--text);
}

.tag {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.subtitle {
  margin: 0.6rem 0 0;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.5;
  max-width: 640px;
}

.query-panel {
  background: linear-gradient(180deg, var(--bg-700), var(--bg-800));
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 1.25rem 1.5rem;
}

.query-panel label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.query-row {
  display: flex;
  gap: 0.75rem;
}

#query-input {
  flex: 1;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-900);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
}

#query-input::placeholder {
  color: var(--text-muted);
}

#query-input:focus {
  outline: none;
  border-color: var(--border-interactive);
  box-shadow: 0 0 0 2px var(--ring);
}

#submit-btn {
  padding: 0.7rem 1.35rem;
  border: none;
  border-radius: var(--radius);
  background: var(--bg-900);
  color: var(--on-dark);
  font-family: var(--font);
  font-weight: 400;
  font-size: 1rem;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--btn-inset);
}

#submit-btn:hover:not(:disabled) {
  opacity: 0.9;
}

#submit-btn:active:not(:disabled) {
  opacity: 0.8;
}

#submit-btn:focus-visible {
  box-shadow: var(--btn-inset), var(--focus-shadow);
}

#submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.samples {
  margin-top: 0.9rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  border: 1px solid var(--border);
  background: var(--bg-900);
  color: var(--text);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-pill);
  font-family: var(--font);
  font-size: 0.82rem;
  cursor: pointer;
}

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

.chip:active {
  opacity: 0.8;
}

.status {
  margin-top: 1rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--tint-03);
}

.status.error {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.results {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: linear-gradient(180deg, var(--bg-700), var(--bg-800));
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 1.25rem 1.5rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text);
}

.hint {
  margin: -0.35rem 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.media-item {
  background: linear-gradient(180deg, var(--bg-700), var(--bg-800));
  border-radius: var(--radius-card);
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.media-thumb {
  aspect-ratio: 16 / 9;
  background: var(--tint-04);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-thumb .placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1rem;
  text-align: center;
}

/* PDF page renders are portrait -- "cover" (used for 16:9 video keyframes)
   would crop most of a tall page's text away, so this gets its own fit. */
.media-thumb img.pdf-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: top;
  background: var(--tint-03);
}

.media-body {
  padding: 0.85rem 1rem 1.1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.media-title {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
}

.media-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.source-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.1rem;
  padding: 0.12rem 0.5rem;
  border-radius: var(--radius-pill);
  background: var(--tint-04);
  border: 1px solid var(--border);
  color: var(--text-strong);
  font-size: 0.76rem;
  font-weight: 600;
}

.time-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.12rem 0.5rem;
  border-radius: var(--radius-pill);
  background: var(--tint-04);
  border: 1px solid var(--border);
  color: var(--text-strong);
  font-size: 0.72rem;
}

.media-snippet {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.media-item video {
  width: 100%;
  max-height: 200px;
  background: #000;
}

.pdf-placeholder {
  font-weight: 600;
  color: var(--text-strong);
}

.pdf-preview {
  width: 100%;
  height: 220px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--tint-03);
  margin-top: 0.35rem;
}

.pdf-preview-img {
  width: 100%;
  max-height: 480px;
  object-fit: contain;
  object-position: top;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--tint-03);
}

.pdf-open-link {
  align-self: flex-start;
  font-size: 0.82rem;
  color: var(--text);
}

.cause {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}

.cause:last-child {
  margin-bottom: 0;
}

.cause h3 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.likelihood {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.16rem 0.5rem;
  border-radius: var(--radius-pill);
  margin-left: 0.5rem;
  vertical-align: middle;
  border: 1px solid transparent;
}

.likelihood.high {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}

.likelihood.medium {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn);
}

.likelihood.low {
  background: var(--tint-04);
  border-color: var(--border);
  color: var(--text-muted);
}

.cause p {
  margin: 0.4rem 0;
  font-size: 0.92rem;
  color: var(--text);
}

.cause ol {
  margin: 0.6rem 0 0;
  padding-left: 1.25rem;
  font-size: 0.9rem;
}

.cause ol li {
  margin-bottom: 0.4rem;
  color: var(--text);
}

.safety {
  color: var(--warn);
  font-size: 0.82rem;
}

.evidence-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.evidence-row {
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--bg-700), var(--bg-800));
}

.evidence-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
}

.evidence-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.evidence-row p {
  margin: 0.45rem 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.toggle {
  background: none;
  border: none;
  color: var(--text);
  text-decoration: underline;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.88rem;
  padding: 0;
}

.raw-json {
  margin-top: 0.75rem;
  padding: 1rem;
  background: var(--tint-03);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: auto;
  font-size: 0.75rem;
  max-height: 360px;
  color: var(--text-strong);
}

/* --- citation chips: functional 3-state signal, kept as pill "action" tags --- */

.cite-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 0.05rem 0.55rem;
  margin: 0 0.15rem;
  font-size: 0.76rem;
  font-weight: 600;
  font-family: var(--font);
  line-height: 1.6;
  cursor: pointer;
  vertical-align: baseline;
}

.cite-chip.cite-green {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}

.cite-chip.cite-yellow {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn);
}

.cite-chip.cite-red {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
  text-decoration: line-through;
}

.cite-chip:hover {
  box-shadow: var(--focus-shadow);
}

.cite-popover {
  position: absolute;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.7rem;
  font-size: 0.78rem;
  color: var(--text-strong);
  box-shadow: var(--focus-shadow);
  z-index: 50;
  pointer-events: none;
}

/* --- validation bar --- */

.validation-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0.9rem 0 1.1rem;
  padding: 0.65rem 0.95rem;
  border-radius: var(--radius-md);
  background: var(--tint-03);
  border: 1px solid var(--border);
  font-size: 0.82rem;
}

.vstat {
  color: var(--text-muted);
}

.vstat-ok {
  color: var(--success);
  font-weight: 600;
}

.vstat-warn {
  color: var(--danger);
  font-weight: 600;
}

.vstat-note {
  color: var(--warn);
}

/* --- evidence-focus: deduped-by-source cards (video / manual / procedure) --- */

.evidence-focus {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.focus-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.focus-card.focus-video {
  border-color: var(--border-interactive);
}

.focus-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.focus-title {
  font-weight: 600;
  color: var(--text);
}

.focus-tag {
  font-size: 0.72rem;
  padding: 0.14rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success);
}

.focus-tag.degraded {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn);
}

.focus-card video {
  width: 100%;
  max-height: 240px;
  background: #000;
  border-radius: var(--radius-md);
}

.evidence-bar {
  position: relative;
  height: 8px;
  border-radius: var(--radius-sm);
  background: var(--tint-04);
  overflow: hidden;
}

.evidence-seg {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-sm);
}

.evidence-seg.active {
  background: rgba(59, 130, 246, 0.85);
}

.focus-caption {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.replay-btn {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border-interactive);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.4rem 0.85rem;
  font-family: var(--font);
  font-size: 0.78rem;
  cursor: pointer;
}

.replay-btn:hover {
  box-shadow: var(--focus-shadow);
}

.replay-btn:active {
  opacity: 0.8;
}

.focus-degraded .placeholder {
  aspect-ratio: 16 / 9;
  background: var(--tint-04);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.focus-degraded .placeholder img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.focus-snippet-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.focus-snippet-highlight {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-strong);
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
}

@media (max-width: 600px) {
  .query-row {
    flex-direction: column;
  }
}
