:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #d8dce2;
  --text: #23272f;
  --text-dim: #656d78;
  --accent: #1f6f5c;
  --accent-dim: #dcefe9;
  --hit: #b8433a;
  --link: #2d6cad;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

mark { background: none; color: var(--hit); font-weight: 700; }

[hidden] { display: none !important; }

.load-error {
  max-width: 520px;
  margin: 80px auto;
  padding: 24px;
  text-align: center;
  color: var(--text);
}
.load-error code {
  background: #eef0f3;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--mono);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

/* ---------- Title bar ---------- */
.titlebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border-bottom: 1px solid #14493c;
}
.titlebar .logo {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: #fff;
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.titlebar h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}
.titlebar .subtitle {
  font-size: 12px;
  opacity: 0.85;
  margin-left: 4px;
}
.titlebar .badge {
  margin-left: auto;
  font-size: 11px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  padding: 3px 8px;
  border-radius: 999px;
}

/* ---------- Body layout ---------- */
.body {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 0;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px 14px 24px;
}
.sidebar h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 18px 0 6px;
}
.sidebar h2:first-child { margin-top: 0; }
.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  padding: 2px 0;
}
.stat-row span:first-child { color: var(--text-dim); }
.filter-btn {
  width: 100%;
  padding: 6px 8px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  background: #fafbfc;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.filter-btn:hover { background: var(--accent-dim); }
.filter-btn #filter-toggle-count {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 10.5px;
  padding: 1px 6px;
  margin-left: 6px;
}
.filter-btn #filter-toggle-count:empty { display: none; }
.filter-pill {
  display: inline-block;
  font-size: 11.5px;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 8px;
  margin: 6px 4px 0 0;
}
.filter-pill button {
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
  margin-left: 4px;
  padding: 0;
  font-size: 12px;
  line-height: 1;
}
.filter-panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafbfc;
  padding: 8px;
  margin-top: 6px;
}
.filter-group + .filter-group { margin-top: 10px; }
.filter-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.filter-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  padding: 2px 0;
  cursor: pointer;
}
.filter-option input { margin: 0; cursor: pointer; }
.filter-option .fo-count { margin-left: auto; color: var(--text-dim); font-size: 11.5px; }
.filter-clear {
  width: 100%;
  margin-top: 10px;
  padding: 5px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-dim);
}
.filter-clear:hover { background: var(--accent-dim); color: var(--accent); }
.file-list {
  list-style: none;
  margin: 0; padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
}
.file-list li {
  padding: 5px 8px;
  font-family: var(--mono);
  font-size: 12px;
  border-bottom: 1px solid #edeff2;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
}
.file-list li:last-child { border-bottom: none; }
.file-list li:hover { background: var(--accent-dim); }
.file-list li.active { background: var(--accent); color: #fff; }
.file-list li .count { color: var(--text-dim); font-family: var(--sans); }
.file-list li.active .count { color: #dff0ea; }
.ref-note {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  background: #fafbfc;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 8px;
}

/* ---------- Main ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  padding: 0 8px;
  overflow-x: auto;
}
.tab {
  padding: 10px 16px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.panel {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: none;
}
.panel.active { display: block; }

/* ---------- KWIC table ---------- */
.results-meta {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
table.kwic {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  font-size: 13px;
}
table.kwic th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  position: sticky;
  top: 0;
  background: var(--panel);
}
table.kwic td {
  padding: 8px 10px;
  border-bottom: 1px solid #eef0f3;
  vertical-align: top;
}
table.kwic tr { cursor: pointer; }
table.kwic tr:hover td { background: var(--accent-dim); }
table.kwic td.left { text-align: right; font-family: var(--mono); color: var(--text-dim); }
table.kwic td.right { font-family: var(--mono); color: var(--text-dim); }
table.kwic td.hit { font-family: var(--mono); font-weight: 700; color: var(--hit); text-align: center; }
table.kwic td.file { font-family: var(--mono); font-size: 12px; color: var(--link); }
.status-pill {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.status-pill.verified { background: var(--accent-dim); color: var(--accent); }
.status-pill.pending { background: #fbe9d6; color: #97591a; }

/* ---------- Utterance detail ---------- */
.detail-empty {
  color: var(--text-dim);
  font-size: 13px;
  padding: 40px 10px;
  text-align: center;
}
.detail-card {
  max-width: 880px;
  margin: 0 auto;
}
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.detail-head h3 {
  margin: 0;
  font-size: 16px;
  font-family: var(--mono);
}
.detail-sub {
  color: var(--text-dim);
  font-size: 12.5px;
  margin-bottom: 16px;
}
.fabricated-banner {
  background: #fbe9d6;
  color: #97591a;
  border: 1px solid #f0c896;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 12.5px;
  line-height: 1.5;
}

.audio-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.play-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}
.play-btn:hover { background: #17564a; }
.audio-note { font-size: 11.5px; color: var(--text-dim); }

.viz-box {
  background: #12181c;
  border-radius: 8px;
  padding: 10px 12px 4px;
  margin-bottom: 16px;
}
.viz-label {
  color: #8fd6c4;
  font-size: 11px;
  font-family: var(--mono);
  margin-bottom: 4px;
}
.viz-empty {
  color: #8fd6c4;
  font-size: 12.5px;
  padding: 16px 0;
  text-align: center;
}

.field-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.field-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.conversation { display: flex; flex-direction: column; gap: 10px; }
.turn {
  padding: 8px 12px;
  border-left: 3px solid var(--border);
  background: #fafbfc;
  border-radius: 0 6px 6px 0;
}
.turn-head {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12.5px;
}
.turn-head .turn-meta {
  font-weight: 400;
  color: var(--text-dim);
  font-size: 11.5px;
}
.turn-text {
  font-family: var(--mono);
  font-size: 14.5px;
  margin-top: 2px;
}
.turn-text mark {
  background: none;
  color: var(--hit);
  font-weight: 700;
}
.turn-translation {
  font-size: 13px;
  font-style: italic;
  color: #3a4048;
  margin-top: 2px;
}
.turn-target {
  border-left-color: var(--accent);
  background: var(--accent-dim);
}
.field-pragmatic { font-size: 13.5px; line-height: 1.55; }
.verify-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}

/* ---------- Wordcloud ---------- */
.wordcloud {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 14px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.wordcloud span {
  font-family: var(--mono);
  color: var(--accent);
  cursor: pointer;
}
.wordcloud span:hover { color: var(--hit); }

/* ---------- About ---------- */
.about { max-width: 980px; margin: 0 auto; }
.about p { line-height: 1.6; }
.about ul { line-height: 1.7; padding-left: 20px; margin: 4px 0; }
.about-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 0 24px;
}
.about-hero-logo {
  width: 52px; height: 52px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 24px;
  flex-shrink: 0;
}
.about-hero h2 { margin: 0 0 2px; font-size: 22px; }
.about-tagline { margin: 0; color: var(--text-dim); font-size: 13.5px; }

.about-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 14px;
}
.about-section h3 { margin: 0 0 12px; font-size: 15px; }
.about-section .lang-divider { color: var(--text-dim); font-weight: 400; font-size: 13px; }

.bilingual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 720px) {
  .bilingual-grid { grid-template-columns: 1fr; }
}
.lang-col p, .lang-col ul { font-size: 13.5px; }
.lang-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 4px;
  padding: 1px 6px;
  margin-bottom: 6px;
}

.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.team-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fafbfc;
}
.team-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.team-name { font-weight: 700; font-size: 14px; }
.team-role { color: var(--text-dim); font-size: 12.5px; margin-bottom: 6px; }
.team-links { display: flex; flex-direction: column; gap: 2px; }
.team-links a {
  color: var(--link);
  font-size: 12.5px;
  text-decoration: none;
}
.team-links a:hover { text-decoration: underline; }

/* ---------- Search bar ---------- */
.searchbar {
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.searchbar .opt {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 4px;
}
.searchbar input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 13px;
}
.searchbar button.start {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.searchbar button.start:hover { background: #17564a; }
.searchbar .count {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ---------- Chart ---------- */
.chart-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 12.5px;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch {
  width: 11px; height: 11px;
  border-radius: 3px;
  display: inline-block;
}
.chart-row {
  display: grid;
  grid-template-columns: 70px 1fr 40px;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}
.chart-label { font-family: var(--mono); font-weight: 700; color: var(--hit); font-size: 13px; }
.chart-bar-track {
  background: #eef0f3;
  border-radius: 4px;
  overflow: hidden;
  height: 20px;
}
.chart-bar { display: flex; height: 100%; min-width: 2px; }
.chart-seg { display: block; height: 100%; }
.chart-total { font-size: 12.5px; color: var(--text-dim); text-align: right; }

/* ---------- Collocate / Cluster node selector ---------- */
#collocate-node-select, #cluster-node-select {
  font-family: var(--mono);
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
}

.cluster-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.cluster-col {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.cluster-col-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.cluster-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 13px;
  padding: 3px 0;
  border-bottom: 1px solid #eef0f3;
}
.cluster-row:last-child { border-bottom: none; }
.cluster-count { color: var(--text-dim); }
.cluster-empty { color: var(--text-dim); font-size: 12.5px; font-style: italic; }

/* ---------- N-Gram toggle ---------- */
.ngram-toggle { margin-left: 10px; }
.ngram-btn {
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: #fafbfc;
  cursor: pointer;
  color: var(--text-dim);
}
.ngram-btn:first-child { border-radius: 6px 0 0 6px; }
.ngram-btn:last-child { border-radius: 0 6px 6px 0; border-left: none; }
.ngram-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
