:root {
  /* Palette matched to the COSSEE brand (cossee.org): sage/teal greens,
     steel blue, and warm neutrals drawn from the COSSEE logo. */
  --bg: #f4f7f4;
  --surface: #ffffff;
  --ink: #1b2733;
  --muted: #5c6e68;
  --accent: #1f7a63;       /* COSSEE teal-green */
  --accent-dark: #155c4a;
  --accent-soft: #e3f1ec;
  --blue: #7aa7c6;         /* COSSEE steel blue (lightened for green/blue CVD separation) */
  --border: #e0e8e3;
  --sidebar-bg: #16352d;   /* deep forest-teal */
  --sidebar-ink: #d6e2db;
  --sidebar-muted: #8aa399;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --sidebar-w: 280px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
a { color: var(--accent); }

.layout { display: flex; min-height: 100vh; }

/* ============================ SIDEBAR ============================ */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.sidebar-close { display: none; }   /* mobile only (see media query) */
.sidebar-backdrop { display: none; }
.brand .leaf { font-size: 1.5rem; }
.brand strong { display: block; font-size: 0.98rem; color: #fff; }
.brand-sub { font-size: 0.72rem; color: var(--sidebar-muted); letter-spacing: .04em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: var(--sidebar-ink); text-decoration: none; font-size: 0.9rem;
  padding: 8px 12px; border-radius: 8px; border-left: 3px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: rgba(31,122,99,.22); border-left-color: var(--accent); color: #fff; }

.filters { border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; }
.filters h3 { margin: 0 0 12px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--sidebar-muted); }
.f-label { display: block; font-size: 0.82rem; margin-bottom: 14px; color: var(--sidebar-ink); }
.f-label select, .f-range select {
  width: 100%; margin-top: 5px; padding: 7px 8px; border-radius: 7px;
  border: 1px solid rgba(255,255,255,.14); background: #1d2c39; color: #fff; font-size: 0.85rem;
}
.f-range { display: flex; align-items: center; gap: 6px; }
.f-range select { margin-top: 5px; }
.f-range span { color: var(--sidebar-muted); }

/* Tom Select searchable multi-selects — themed for the dark sidebar */
.filters .ts-wrapper { margin-top: 5px; }
.filters .ts-control {
  background: #1f4a3e; border: 1px solid rgba(255,255,255,.14); border-radius: 7px;
  color: #fff; padding: 4px 8px; min-height: 34px; gap: 4px; box-shadow: none;
}
.filters .ts-control > input, .filters .ts-control > input::placeholder { color: #fff; font-size: 0.85rem; }
.filters .ts-control > input::placeholder { color: var(--sidebar-muted); }
.filters .ts-wrapper.focus .ts-control { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(31,122,99,.4); }
.filters .ts-control .item {
  background: var(--accent); color: #fff; border-radius: 5px; padding: 1px 4px 1px 7px; font-size: 0.8rem;
}
.filters .ts-control .item .remove { border-left-color: rgba(255,255,255,.3); }
.filters .ts-control .item .remove:hover { background: rgba(255,255,255,.18); }
.ts-dropdown {
  background: #1d3a32; color: var(--sidebar-ink); border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px; box-shadow: 0 10px 28px rgba(0,0,0,.4); margin-top: 4px;
}
.ts-dropdown .option { padding: 6px 10px; font-size: 0.84rem; }
.ts-dropdown .option.active { background: rgba(255,255,255,.10); color: #fff; }
.ts-dropdown .no-results { padding: 6px 10px; color: var(--sidebar-muted); }
.ts-dropdown input[type=checkbox] { accent-color: var(--accent); }

.f-group { border: none; padding: 0; margin: 0 0 14px; }
.f-group legend { font-size: 0.82rem; padding: 0; margin-bottom: 6px; }
.mr-prec { opacity: 0.75; white-space: nowrap; }
.f-note { font-size: 0.72rem; opacity: 0.8; margin: 4px 0 0; line-height: 1.35; }
.f-group label { display: flex; align-items: center; gap: 7px; font-size: 0.82rem; padding: 3px 0; cursor: pointer; }
.f-group input { accent-color: var(--accent); }

.f-check { display: flex; align-items: center; gap: 7px; font-size: 0.82rem; margin-bottom: 14px; cursor: pointer; }
.f-check input { accent-color: var(--accent); }

.btn-reset {
  width: 100%; padding: 8px; border-radius: 8px; cursor: pointer;
  background: transparent; color: var(--sidebar-ink); border: 1px solid rgba(255,255,255,.18); font-size: 0.82rem;
}
.btn-reset:hover { background: rgba(255,255,255,.06); }

.sidebar-actions { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; }
.match-count { font-size: 0.85rem; color: var(--sidebar-muted); margin-bottom: 8px; }
.match-count b { color: #fff; }
.btn-download {
  width: 100%; padding: 10px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.85rem;
  background: var(--accent); color: #fff; border: none;
}
.btn-download:hover { background: var(--accent-dark); }
.repo-link { color: var(--sidebar-muted); font-size: 0.8rem; text-decoration: none; }
.repo-link:hover { color: #fff; }

/* ============================ MAIN ============================ */
.main-col { flex: 1 1 auto; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  background: linear-gradient(135deg, #ffffff 0%, #eef5f0 100%);
  border-bottom: 3px solid var(--accent); padding: 14px 32px;
}
.topbar h1 { margin: 0 0 3px; font-size: 1.4rem; }
.subtitle { margin: 0; color: var(--muted); font-size: 0.86rem; max-width: 620px; }
.credit { margin: 5px 0 0; color: var(--muted); font-size: 0.8rem; max-width: 560px; }
.topbar-logo { display: inline-flex; }
.topbar-logo img { height: 46px; width: auto; display: block; }
.topbar-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; white-space: nowrap; }
.lang-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.lang-toggle button {
  border: none; background: transparent; padding: 6px 12px; font-size: 0.8rem; font-weight: 700;
  color: var(--muted); cursor: pointer; letter-spacing: .03em;
}
.lang-toggle button:hover { background: var(--accent-soft); }
.lang-toggle button.active { background: var(--accent); color: #fff; }

.gh-button {
  display: inline-flex; align-items: center; gap: 7px; text-decoration: none;
  background: #16352d; color: #fff; padding: 7px 13px; border-radius: 8px; font-size: 0.85rem; font-weight: 600;
}
.gh-button:hover { background: #234c40; }
.pilot-badge {
  font-size: 0.68rem; font-weight: 700; letter-spacing: .06em; color: var(--accent);
  background: var(--accent-soft); padding: 4px 10px; border-radius: 999px;
}

.filters-toggle { display: none; }

/* Desktop sidebar collapse toggle (lives in the view-tabs row; hidden on mobile) */
.nav-collapse {
  margin-left: auto; align-self: center; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; font-size: 0.82rem; font-weight: 600;
}
.nav-collapse:hover { background: var(--accent-soft); color: var(--ink); }
@media (max-width: 900px) { .nav-collapse { display: none; } }  /* mobile uses .filters-toggle */

/* Collapsed: hand the sidebar's width back to the content */
.layout.nav-collapsed .sidebar { display: none; }
.layout.nav-collapsed .content { max-width: 1400px; }

.content { padding: 18px 32px 56px; max-width: 1180px; }
#loading { color: var(--muted); }

.section { margin-bottom: 40px; scroll-margin-top: 16px; }
.section-title { font-size: 1.15rem; margin: 0 0 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .value { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.kpi .label { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.kpi.kpi-prec { border-left: 4px solid var(--accent); }
.kpi-note { color: var(--muted); font-size: 0.86rem; max-width: 760px; margin: -6px 0 20px; }

.card-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card h3 { margin: 0 0 4px; font-size: 1.02rem; }
.card-desc { margin: 0 0 14px; color: var(--muted); font-size: 0.84rem; }
.card > canvas { max-height: 330px; }
.card > canvas.compact { height: 158px; max-height: 158px; }
/* Align the two open-access bar charts: equal-height cards with the canvas pinned
   to the bottom, so their plot baselines line up despite different description lengths. */
#outputs .card-grid .card { display: flex; flex-direction: column; }
#outputs .card-grid .card > canvas.compact { margin-top: auto; }

.network-canvas { height: 560px; width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #fbfcfd; }
.map-canvas { height: 560px; width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #eef2f5; z-index: 0; }
.map-canvas .leaflet-container { border-radius: 10px; font: inherit; }
.network-canvas canvas { max-height: none !important; }
.net-legend { margin-left: 6px; white-space: nowrap; }
.net-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 4px 0 12px; vertical-align: middle; }
.net-legend .dot.ca { background: var(--accent); }
.net-legend .dot.intl { background: var(--blue); }
/* Triangle swatch — matches the international (international = triangle) node shape */
.net-legend .tri {
  display: inline-block; width: 0; height: 0; margin: 0 4px 0 12px; vertical-align: middle;
  border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-bottom: 11px solid var(--blue);
}

.muted { color: var(--muted); font-size: 0.84rem; }
code { background: var(--bg); padding: 2px 6px; border-radius: 6px; font-size: 0.8rem; word-break: break-all; }

/* ---- View tabs (Dashboard / Records) ---- */
.view-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.view-tabs button {
  border: none; background: transparent; padding: 10px 20px; font-size: 0.95rem; font-weight: 600;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.view-tabs button:hover { color: var(--ink); }
.view-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

#dash.view-records .section:not(#records-view) { display: none; }
#dash:not(.view-records) #records-view { display: none; }

/* ---- Records table ---- */
.table-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.table-perpage { font-size: 0.82rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.table-perpage select { padding: 4px 7px; border-radius: 6px; border: 1px solid var(--border); }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; max-height: 70vh; overflow-y: auto; }
.rec-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.rec-table th, .rec-table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.rec-table th {
  position: sticky; top: 0; background: var(--surface); cursor: pointer; user-select: none; z-index: 1;
  font-size: 0.74rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
}
.rec-table th:hover { color: var(--ink); }
.rec-table th.sorted { color: var(--accent); }
.rec-table th.num, .rec-table td.num { text-align: right; }
.rec-table tbody tr:hover { background: var(--bg); }
.rec-table td:first-child { white-space: normal; min-width: 280px; max-width: 440px; }
.oa-pill {
  display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 0.74rem; color: #1b2733;
  background: color-mix(in srgb, var(--oa) 20%, white); border: 1px solid color-mix(in srgb, var(--oa) 45%, white);
}
.table-pager { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 14px; }
.btn-page { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 15px; cursor: pointer; font-size: 0.85rem; }
.btn-page:hover:not(:disabled) { background: var(--bg); }
.btn-page:disabled { opacity: .45; cursor: default; }

/* ---- Metaresearch report ---- */
.report-intro { color: var(--muted); font-size: 0.9rem; max-width: 760px; margin: 0 0 20px; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.finding {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 15px; box-shadow: var(--shadow); border-top: 3px solid var(--accent);
  display: flex; flex-direction: column;
}
.finding-q { margin: 0 0 4px; font-size: 0.82rem; font-weight: 600; color: var(--ink); }
.finding-stat { font-size: 1.6rem; font-weight: 700; color: var(--accent); line-height: 1.1; margin: 1px 0 5px; }
.finding-text { margin: 0; color: var(--muted); font-size: 0.78rem; }

/* ---- Search string & validation ---- */
#validation .card h3 { margin: 22px 0 8px; font-size: 0.98rem; }
#validation .card h3:first-of-type { margin-top: 8px; }
.query-box { display: flex; gap: 10px; align-items: flex-start; background: #16352d; border-radius: 10px; padding: 12px 14px; }
.query-box code { background: transparent; color: #d7e3ee; flex: 1; font-size: 0.82rem; line-height: 1.5; }
.btn-copy { flex: 0 0 auto; background: rgba(255,255,255,.1); color: #fff; border: none; border-radius: 7px; padding: 6px 12px; font-size: 0.8rem; cursor: pointer; }
.btn-copy:hover { background: rgba(255,255,255,.2); }
.val-links { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 10px; font-size: 0.85rem; font-weight: 600; }
.concept-list { list-style: none; padding: 0; margin: 0; font-size: 0.86rem; }
.concept-list li { padding: 5px 0; border-bottom: 1px solid var(--border); }
.concept-list li.concept-head { border: none; color: var(--muted); padding-top: 12px; font-weight: 600; }
.concept-list li.concept-line { color: var(--ink); }
.btn-action { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 9px 16px; font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.btn-action:hover { background: var(--accent-dark); }
.val-result { margin-top: 12px; }
.val-result .ok { color: #1f7a45; font-weight: 600; }
.val-result .warn { color: #b3641a; font-weight: 600; }
.verify-grid { display: flex; gap: 28px; margin-bottom: 6px; }
.verify-grid .vlabel { display: block; color: var(--muted); font-size: 0.78rem; }
.verify-grid b { font-size: 1.5rem; color: var(--accent); }
.sample-list { margin: 6px 0 0; padding-left: 22px; font-size: 0.88rem; }
.sample-list li { padding: 4px 0; }
#validation #sensChart { max-height: 200px; margin-top: 6px; }
.sens-table { width: 100%; border-collapse: collapse; margin: 12px 0 4px; font-size: 0.86rem; }
.sens-table th, .sens-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
.sens-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: .03em; }
.sens-table td:nth-child(2), .sens-table th:nth-child(2),
.sens-table td:nth-child(3), .sens-table th:nth-child(3) { text-align: right; white-space: nowrap; }
.sens-table tbody tr:first-child td { font-weight: 600; }
.planned { border-left: 3px solid var(--blue); padding-left: 10px; font-style: italic; }

/* ============================ RESPONSIVE ============================ */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 50; height: 100vh; transform: translateX(-100%);
    transition: transform .25s ease; box-shadow: 2px 0 16px rgba(0,0,0,.25);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close {
    display: inline-flex; align-items: center; justify-content: center; margin-left: auto;
    width: 32px; height: 32px; flex: 0 0 auto; border: none; border-radius: 8px; cursor: pointer;
    background: rgba(255,255,255,.08); color: var(--sidebar-ink); font-size: 0.95rem;
  }
  .sidebar-close:hover { background: rgba(255,255,255,.18); color: #fff; }
  .sidebar.open ~ .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45);
  }
  .filters-toggle {
    display: inline-block; margin: 14px 0 0 20px; padding: 9px 14px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 0.9rem;
  }
  .content { padding: 18px 20px 48px; }
  .topbar { padding: 18px 20px; }
  .card-grid { grid-template-columns: 1fr; }
  .card.wide { grid-column: auto; }
}

/* Community validation */
.vote-list { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 20px; }
.vote-row { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(120px, 2fr) 104px; gap: 14px; align-items: center; font-size: 0.86rem; }
.vote-bar { display: block; height: 14px; background: var(--accent-soft); border-radius: 7px; overflow: hidden; }
.vote-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 7px; }
.vote-val { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.comm-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 6px 0 14px; }
.comm-col { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; }
.comm-col h4 { margin: 0 0 8px; font-size: 0.9rem; color: var(--accent-dark); }
.comm-col ul { margin: 0; padding-left: 18px; font-size: 0.84rem; line-height: 1.45; }
.comm-col li + li { margin-top: 5px; }
@media (max-width: 900px) {
  .comm-grid { grid-template-columns: 1fr; }
  .vote-row { grid-template-columns: 1fr 88px; }
  .vote-row > span:first-child { grid-column: 1 / -1; }
}
