:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --accent-soft: #e6eefb;
  --test: #8a4b00;
  --test-soft: #fdf0dd;
  --done: #1f7a43;
  --done-soft: #e3f4ea;
  --danger: #b42318;
  --meter-low: #9aa6b4;
  --meter-mid: #d08a00;
  --meter-high: #c0362c;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Bengali",
          "Nirmala UI", Vrinda, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --text: #e5e9ef;
    --muted: #9aa5b3;
    --border: #2d3540;
    --accent: #6ea3f0;
    --accent-text: #0d1726;
    --accent-soft: #1d2b40;
    --test: #f0b45e;
    --test-soft: #3a2a14;
    --done: #6fcf97;
    --done-soft: #183126;
    --danger: #f2877e;
    --meter-low: #5e6b7a;
    --meter-mid: #e0a030;
    --meter-high: #f07167;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}

a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
code { font-size: 0.9em; background: var(--accent-soft); padding: 0.1em 0.35em; border-radius: 4px; }
kbd {
  font: 0.75rem var(--font);
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 0 0.3em;
  margin-left: 0.4em;
  opacity: 0.7;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.error { color: var(--danger); font-weight: 600; }

/* layout */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: var(--muted); text-decoration: none; padding: 0.2rem 0; border-bottom: 2px solid transparent; }
.topbar nav a.active { color: var(--text); border-bottom-color: var(--accent); }
.logout { display: flex; align-items: center; gap: 0.75rem; }

main { max-width: 880px; margin: 1.5rem auto; padding: 0 1rem; }
main.narrow { max-width: 420px; margin-top: 10vh; }
main.wide { max-width: 1100px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.center { text-align: center; }
.row-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.row-head h1 { margin: 0; }

/* forms and buttons */
label { display: block; margin-bottom: 0.9rem; font-weight: 500; }
input:not([type=checkbox]), textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button, .button {
  display: inline-flex;
  align-items: center;
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.subtle { color: var(--muted); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 500; }
.login button { width: 100%; justify-content: center; margin-top: 0.5rem; }

/* review page */
.context { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
.badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-right: 0.25rem;
}
.badge.subtle { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.badge.test { background: var(--test-soft); color: var(--test); }
.badge.done { background: var(--done-soft); color: var(--done); }
.badge.run { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--test-soft); color: var(--danger); }

.sms { white-space: pre-wrap; overflow-wrap: anywhere; }
.message .sms { font-size: 1.25rem; line-height: 1.6; margin: 0; }
.message details { margin-top: 1rem; }
.examples { margin: 0.5rem 0 0; padding-left: 1.2rem; color: var(--muted); }
.examples li { margin-bottom: 0.35rem; }
summary { cursor: pointer; color: var(--muted); }

fieldset { border: 0; margin: 0; padding: 0; }
legend { font-weight: 600; margin-bottom: 0.6rem; }
legend .muted { font-weight: 400; }

.toggle {
  display: grid;
  grid-template-columns: auto auto 6.5rem 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.8rem;
  margin: 0 0 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 400;
}
.toggle:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.toggle input { width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--accent); }
.toggle .key {
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 1.4rem;
  text-align: center;
}
.toggle .name { font-weight: 600; }
.toggle .desc { color: var(--muted); font-size: 0.9rem; }
.toggle .score { font-size: 0.8rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

meter { width: 4.5rem; height: 0.55rem; vertical-align: middle; }
meter::-webkit-meter-bar { background: var(--border); border: 0; border-radius: 99px; }
meter::-webkit-meter-optimum-value { background: var(--meter-low); border-radius: 99px; }
meter::-webkit-meter-suboptimum-value { background: var(--meter-mid); border-radius: 99px; }
meter::-webkit-meter-even-less-good-value { background: var(--meter-high); border-radius: 99px; }
meter::-moz-meter-bar { border-radius: 99px; }

progress {
  width: 100%;
  max-width: 10rem;
  height: 0.55rem;
  vertical-align: middle;
  appearance: none;
  border: 0;
  border-radius: 99px;
  background: var(--border);
  overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--border); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

.evidence { margin: 0.75rem 0 1rem; }
.evidence ul { margin: 0.5rem 0; padding-left: 1.2rem; font-size: 0.9rem; }
.evidence p { margin: 0; font-size: 0.8rem; }
.note { margin-top: 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }

/* template browser */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; }
.filters label { margin: 0; }
.filters .grow { flex: 1 1 16rem; }
.filters button { margin-bottom: 1px; }
select {
  display: block;
  margin-top: 0.3rem;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.templates td.clip2 a {
  color: var(--text);
  text-decoration: none;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.templates td.clip2 a:hover { color: var(--accent); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 0.75rem; }
.examples-head { font-size: 0.9rem; color: var(--muted); margin: 1rem 0 0.25rem; }

/* flash messages */
.flash { padding: 0.7rem 1rem; border-radius: 8px; margin: 0 0 1rem; font-weight: 500; }
.flash.ok { background: var(--done-soft); color: var(--done); }
.flash.error { background: var(--test-soft); color: var(--danger); }
.flash.info { background: var(--accent-soft); color: var(--accent); }

/* pipeline page */
.job .row-head { margin-bottom: 0.25rem; }
.job h2 { margin: 0; }
.job-actions { margin-top: 0.75rem; }
.job-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; }
.job-form label { margin: 0; }
.job-form input[type=number] { width: 8rem; }
.job-form .check { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; }
.job-form .check input { width: auto; margin: 0; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.log { margin-top: 0.75rem; }
.log pre {
  max-height: 18rem;
  overflow: auto;
  font-size: 0.8rem;
  line-height: 1.4;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  margin: 0.5rem 0 0;
}

table.compact th, table.compact td { padding: 0.35rem 0.5rem; font-size: 0.9rem; }
.model { border-top: 1px solid var(--border); padding-top: 0.75rem; margin-top: 0.75rem; }
.model.active { border-left: 3px solid var(--done); padding-left: 0.75rem; }
.model h3 { margin: 0; }

/* evaluate page */
.label-head { margin: 1.5rem 0 0.25rem; }
h4 { font-size: 0.9rem; margin: 0.5rem 0; color: var(--muted); font-weight: 600; }

/* dashboard */
h3 { font-size: 1rem; margin: 0 0 0.25rem; }
.metric-views { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 1.5rem; margin-bottom: 0.75rem; }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); gap: 0 1rem; }
.pipeline td { vertical-align: middle; }

/* tables */
.card { overflow-x: auto; }  /* a wide table scrolls inside its card, never the page */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.history .clip { max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 640px) {
  .toggle { grid-template-columns: auto auto 1fr; }
  .toggle .desc { grid-column: 1 / -1; }
  .toggle .score { grid-column: 1 / -1; }
  .history .clip { max-width: 10rem; }
  .row-head { flex-direction: column; align-items: flex-start; }
}
