:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --surface: #ffffff;
  --surface-strong: #eef2ee;
  --ink: #18201d;
  --muted: #637169;
  --line: #dce3dc;
  --accent: #2f6f5e;
  --accent-dark: #1d5144;
  --warn: #a66221;
  --danger: #a43b3b;
  --blue: #315f8d;
  --shadow: 0 18px 50px rgba(24, 32, 29, 0.08);

  /* Aliases used by inline styles in index.html */
  --text-primary: var(--ink);
  --text-secondary: var(--muted);
  --border: var(--line);
  --surface-alt: var(--surface-strong);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  background: #17221e;
  color: #f7fbf8;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand,
.model-card {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: #e0b85e;
  color: #17221e;
  font-weight: 800;
  border-radius: 8px;
}

.brand h1,
.topbar h2,
.section-heading h3,
.panel h4 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p,
.model-card p,
.section-heading p,
.metric p {
  margin: 4px 0 0;
  color: var(--muted);
}

.sidebar .brand p,
.sidebar .eyebrow {
  color: #b8c7bf;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #dce8e2;
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  color: #e0b85e;
}

.matter-switcher,
.panel,
.module-card,
.metric,
.chat-panel,
.work-status {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.matter-switcher {
  padding: 14px;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
}

.matter-switcher label,
.panel label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin: 12px 0 6px;
}

.sidebar select,
.sidebar button {
  width: 100%;
}

.model-card {
  margin-top: auto;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #6bd19e;
  box-shadow: 0 0 0 6px rgba(107, 209, 158, 0.12);
}

main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 28px;
}

.topbar h2 {
  font-size: clamp(24px, 3vw, 34px);
}

.topbar-actions,
.filter-row,
.form-row,
.panel-heading,
.panel-actions,
.section-heading,
.segmented,
.progress-heading,
.progress-meta,
.setting-title,
.conversation-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.query-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.query-form textarea {
  width: 100%;
  min-height: 80px;
}

.conversation-tools select {
  max-width: 280px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-matter-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-matter-controls select {
  min-width: 220px;
  max-width: 32vw;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 18px;
}

.section-heading p {
  max-width: 760px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 12px;
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.primary-button,
.secondary-button,
.text-button,
.icon-button,
.segmented button {
  border-radius: 8px;
  border: 1px solid transparent;
  min-height: 40px;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  padding: 0 14px;
}

.text-button {
  background: transparent;
  color: var(--accent);
  padding: 0 8px;
}

.icon-button {
  width: 42px;
  background: var(--surface);
  border-color: var(--line);
  font-size: 15px;
  font-weight: 800;
}

.info-button {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef2ee;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

.work-status {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.85fr);
  gap: 16px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.work-progress h4 {
  margin: 0;
  font-size: 17px;
}

.work-progress p {
  margin: 4px 0 0;
  color: var(--muted);
}

.progress-heading,
.progress-meta,
.panel-heading,
.setting-title,
.conversation-tools {
  justify-content: space-between;
}

.progress-heading > span {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent-dark);
}

.progress-track {
  width: 100%;
  height: 10px;
  background: #e5ece8;
  border-radius: 999px;
  overflow: hidden;
  margin: 14px 0 9px;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  border-radius: inherit;
  transition: width 180ms ease;
}

.progress-meta {
  color: var(--muted);
  font-size: 13px;
}

.system-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.system-strip div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf7;
}

.system-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.system-strip strong {
  display: block;
  margin-top: 3px;
  font-size: 13px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric {
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  font-size: 32px;
  margin-top: 6px;
}

.two-column,
.ingest-layout,
.settings-grid,
.case-theory-grid,
.module-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.settings-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.case-theory-grid {
  align-items: start;
}

.module-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.module-card {
  padding: 18px;
  box-shadow: var(--shadow);
}

.module-card p {
  color: var(--muted);
  line-height: 1.5;
}

.panel {
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel-heading {
  margin-bottom: 12px;
}

.panel-actions {
  flex-wrap: wrap;
}

.field-help {
  margin: 8px 0 0;
  padding: 10px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  background: #f4f7f4;
  border-radius: 0 8px 8px 0;
  line-height: 1.45;
}

.index-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0;
}

.index-list {
  display: grid;
  gap: 8px;
  margin: 8px 0 14px;
}

.index-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.index-row strong,
.index-row small {
  display: block;
}

.index-row small {
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.35;
}

.index-row.active-index {
  border-color: var(--accent);
  background: #edf6ee;
}

.folder-picker {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin: 10px 0;
}

.full-button {
  width: 100%;
  margin-top: 12px;
}

.suggestion-panel {
  display: grid;
  gap: 10px;
}

.suggestion-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf7;
}

.suggestion-card p {
  color: var(--muted);
  line-height: 1.45;
}

.source-note {
  font-size: 13px;
  color: var(--accent-dark) !important;
}

.action-row {
  align-items: stretch;
}

.stack-list {
  display: grid;
  gap: 10px;
}

.list-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.list-item strong {
  display: block;
}

.list-item p {
  margin: 6px 0 0;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: #e5ece8;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}

.pill.warn {
  background: #f5e7d7;
  color: var(--warn);
}

.pill.danger {
  background: #f4dddd;
  color: var(--danger);
}

.drop-zone {
  min-height: 260px;
  border: 2px dashed #9bb0a6;
  border-radius: 8px;
  background: #fff;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  padding: 28px;
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: #eef7f3;
}

.drop-symbol {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e5ece8;
  color: var(--accent);
  font-size: 30px;
}

.drop-zone h4 {
  margin: 14px 0 4px;
  font-size: 20px;
}

.drop-zone p {
  margin: 0 0 18px;
  color: var(--muted);
  max-width: 440px;
}

.checkbox-line {
  display: flex !important;
  align-items: center;
  gap: 8px;
}

.checkbox-line input {
  width: auto;
}

.pipeline {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.pipeline-step {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 112px;
  background: #fff;
}

.pipeline-step.complete {
  border-color: #95c7b1;
  background: #eef8f3;
}

.pipeline-step.running {
  border-color: #e0b85e;
  background: #fff8e8;
}

.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 1460px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #f3f6f3;
}

tr:last-child td {
  border-bottom: 0;
}

.document-title {
  font-weight: 700;
}

.document-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.description-cell {
  min-width: 260px;
  max-width: 360px;
  color: #394640;
  line-height: 1.4;
}

.doc-link {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.doc-link:hover {
  text-decoration: underline;
}

.tag-cell {
  min-width: 190px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin: 0 5px 6px 0;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--accent-dark);
  font-size: 12px;
}

.tag-chip.active {
  background: #e5ece8;
  border-color: #b9cbc1;
  font-weight: 800;
}

.mini-button {
  display: block;
  width: 100%;
  min-height: 30px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.mini-button:disabled {
  cursor: default;
  color: var(--muted);
  background: #eef2ee;
}

.review-actions {
  min-width: 130px;
}

.checkbox-line.compact {
  margin: 0;
  white-space: nowrap;
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 18px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.timeline-date {
  color: var(--blue);
  font-weight: 800;
}

.source-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

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

.segmented {
  padding: 4px;
  background: #e5ece8;
  border-radius: 8px;
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 0 12px;
}

.segmented button.active {
  background: #fff;
  box-shadow: 0 4px 14px rgba(24, 32, 29, 0.08);
}

.chat-panel {
  min-height: 620px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.conversation-tools {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #f7faf7;
}

.conversation-tools input {
  max-width: 440px;
}

.chat-messages {
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 14px;
  overflow: auto;
}

.message {
  max-width: 860px;
  padding: 14px;
  border-radius: 8px;
  background: #f1f5f2;
}

.message.user {
  justify-self: end;
  background: #e5eef8;
}

.message strong {
  display: block;
  margin-bottom: 6px;
}

.citation-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.citation-list li {
  padding: 8px;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.query-form {
  border-top: 1px solid var(--line);
  padding: 14px;
  align-items: stretch;
}

.query-form button {
  min-width: 98px;
}

.help-panel {
  margin-top: 16px;
}

.help-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(23, 34, 30, 0.46);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: min(560px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-form {
  display: grid;
  gap: 10px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  background: #17221e;
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  transition: opacity 160ms ease, transform 160ms ease;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ── Worker pool panel ──────────────────────────────────────── */
.worker-pool-panel,
.tag-manager-panel,
.matter-manager-panel,
.backup-panel,
.pipeline-tuning-panel,
.help-panel {
  margin-top: 16px;
}

.worker-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 8px;
}

.worker-row.active {
  border-color: #95c7b1;
  background: #f0faf5;
}

.worker-row.idle {
  opacity: 0.8;
}

.worker-row.offline {
  opacity: 0.55;
  border-style: dashed;
}

.worker-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.worker-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 2px;
}

.worker-list {
  display: grid;
  gap: 8px;
}

/* ── File stage meter ───────────────────────────────────────── */
.file-stage-meter {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.file-stage-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #f7faf7;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.file-stage-list {
  padding: 8px 12px;
  display: grid;
  gap: 6px;
}

.file-stage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.file-stage-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Queue and backup panels ────────────────────────────────── */
.queue-job {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 6px;
}

.queue-job-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.queue-job-actions {
  display: flex;
  gap: 6px;
}

.queue-files {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.queue-file {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

.queue-stage-list {
  display: grid;
  gap: 4px;
  margin-top: 6px;
}

.backup-list {
  display: grid;
  gap: 8px;
}

.backup-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}

/* ── Bound list (cross-references) ─────────────────────────── */
.bound-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.bound-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7faf7;
  font-size: 13px;
}

/* ── Research panel ─────────────────────────────────────────── */
.research-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.canlii-answer {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  line-height: 1.55;
}

.answer-text {
  color: var(--ink);
  line-height: 1.55;
}

/* ── Matter manager ─────────────────────────────────────────── */
.matter-manager-list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.matter-manager-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.matter-manager-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

/* ── Model inventory ────────────────────────────────────────── */
.model-inventory {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.model-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}

/* ── Custom tag chip ────────────────────────────────────────── */
.custom-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #e5ece8;
  color: var(--accent-dark);
  font-size: 12px;
}

/* ── Tag editor ─────────────────────────────────────────────── */
.tag-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.tag-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

/* ── Parent context label ───────────────────────────────────── */
.parent-context-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
  display: block;
}

.child-trigger {
  display: none;
}

.child-trigger:checked + .child-trigger-label ~ * {
  display: block;
}

.child-trigger-label {
  cursor: pointer;
  font-size: 12px;
  color: var(--accent);
}

/* ── Tuning grid ────────────────────────────────────────────── */
.tuning-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 10px;
}

/* ── Danger text ────────────────────────────────────────────── */
.danger-text {
  color: var(--danger);
}

/* ── Button row ─────────────────────────────────────────────── */
.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: 1fr;
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .matter-switcher,
  .model-card {
    display: none;
  }

  .metric-grid,
  .two-column,
  .ingest-layout,
  .settings-grid,
  .case-theory-grid,
  .module-grid,
  .pipeline,
  .work-status {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  main {
    padding: 18px;
  }

  .topbar,
  .section-heading,
  .filter-row,
  .query-form,
  .conversation-tools,
  .progress-heading,
  .progress-meta {
    align-items: stretch;
    flex-direction: column;
  }

  .conversation-tools input {
    max-width: none;
  }

  .topbar-actions,
  .header-matter-controls {
    width: 100%;
  }

  .header-matter-controls select {
    flex: 1;
    max-width: none;
    min-width: 0;
  }

  .folder-picker {
    grid-template-columns: 1fr;
  }

  .system-strip {
    grid-template-columns: 1fr;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .timeline-item {
    grid-template-columns: 1fr;
  }
}
