/*
  Henoyo Agent Factory: Chaupal look.
  Tokens follow henoyo-design/theme/tokens.css (CLASSIC) and Chaupal's board.css.
  Fixed light theme: there is no dark variant.
  The Content-Security-Policy allows no web fonts, so the families below use the installed
  Source Serif 4, Inter and JetBrains Mono when present and fall back to system faces.
*/

/* ---- Tokens ---- */
:root {
  color-scheme: light;
  --bg: #F8F6F1;
  --surface: #FFFEFB;
  --surface2: #EFEBE3;
  --ink: #1A1F1C;
  --muted: #666666;
  --line: #E5DFD2;
  --control-line: #8C8576; /* form controls and buttons: 3.5:1 on the card surface */
  --primary: #2B4A35;
  --primary-hover: #1F3827;
  --on-primary: #FFFEFB;
  --accent: #4FA776;
  --soft: #E9EFEB;
  --focus: #2B4A35;
  --amber: #92400E;
  --amber-bg: #FEF3C7;
  --red: #9F1239;
  --red-bg: #FEE2E2;
  --font-display: "Source Serif 4", Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --card-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

/* ---- Base ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14.5px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, textarea, select { outline-offset: 2px; }
:focus-visible { outline: 2px solid var(--focus); }
[tabindex="-1"]:focus-visible { outline: none; }
a { color: var(--primary); }
h1, h2, h3 { font-family: var(--font-display); color: var(--ink); }
h1 { font-size: 26px; line-height: 1.3; margin: 3px 0 6px; font-weight: 600; letter-spacing: -0.2px; }
h2 { font-size: 18px; margin: 0; font-weight: 600; }
h3 { font-size: 15px; margin: 0; font-weight: 600; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.fine { font-size: 12px; color: var(--muted); margin-top: 12px; }
.eyebrow { font-size: 10px; font-weight: 600; letter-spacing: 1.25px; color: var(--muted); }
.skip { position: absolute; top: -60px; left: 16px; background: var(--surface); padding: 10px; z-index: 20; }
.skip:focus { top: 8px; }

/* ---- Buttons ---- */
button {
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--control-line);
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 500;
  min-height: 36px;
}
button:hover { background: var(--surface2); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); padding: 8px 16px; }
button.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
button.quiet { border-color: transparent; background: transparent; }
button.quiet:hover { background: var(--surface2); }
.danger { color: var(--red); }

/* ---- Form controls ---- */
input, textarea, select {
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--surface);
  padding: 9px 12px;
  min-height: 40px;
}
textarea { width: 100%; resize: vertical; }
label { font-weight: 500; }

/* ---- Identifiers and code ---- */
.mono, code, pre {
  font: 12px/1.65 var(--font-mono);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* ---- Brand and header ---- */
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.brand-mark { width: 28px; height: 28px; flex: none; color: var(--primary); }
.brand-text { min-width: 0; line-height: 1; white-space: nowrap; }
.wordmark {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.01em;
  line-height: 1;
  color: var(--ink);
}
.wordmark .mark { color: var(--accent); font-style: normal; }
.brand-by {
  margin-left: 6px;
  vertical-align: middle;
  font-style: normal;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.section-label {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  padding-left: 14px;
  border-left: 1px solid var(--line);
  line-height: 1.2;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  min-height: 56px;
  padding: 10px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.pilot-label {
  font-size: 10px;
  letter-spacing: 1px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 7px;
  color: var(--muted);
}
.topbar-end { display: flex; gap: 16px; align-items: center; margin-left: auto; font-size: 13px; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.back-link::before { content: "←"; color: var(--primary); }
.back-link:hover { background: var(--surface2); }
.fine .back-link { font-size: 13px; }

/* ---- Shell and sidebar ---- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 56px); }
.sidebar { padding: 32px 16px; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.sidebar > .eyebrow { padding-left: 12px; margin-bottom: 14px; }
.sidebar nav { display: grid; gap: 5px; }
.nav { width: 100%; text-align: left; display: flex; align-items: center; gap: 12px; border: 0; background: transparent; font-weight: 500; }
.nav.active { background: var(--soft); color: var(--primary); }
.nav > span:first-child { font-size: 18px; }
.nav-count { margin-left: auto; background: var(--surface); font-size: 11px; padding: 0 6px; border-radius: 5px; }
.sidebar-foot { margin-top: auto; padding: 40px 12px 0; font-size: 12px; color: var(--muted); }
.sidebar-foot p { margin-top: 12px; font-size: 11px; }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 4px; }

/* ---- Page ---- */
main { padding: 32px; min-width: 0; max-width: 1800px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.page-heading .muted { font-size: 13px; }

/* ---- Toolbar ---- */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.search { display: flex; align-items: center; gap: 7px; background: var(--surface); border: 1px solid var(--control-line); border-radius: 8px; padding-left: 12px; width: 320px; }
.search span { font-size: 22px; color: var(--muted); }
.search input { border: 0; background: transparent; width: 100%; min-width: 0; }
.toolbar select { font-size: 12px; }
.toolbar #run-count { margin-left: auto; font-size: 12px; }

[hidden] { display: none !important; }

/* ---- Console list ---- */
.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.toggle input { min-height: initial; }
.run-list { display: grid; gap: 24px; }
.group-head, .group > summary { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 0 0 10px; }
.group > summary { cursor: pointer; }
.group-body { display: grid; gap: 8px; }
.empty-line { color: var(--muted); font-size: 13px; margin: 0; padding: 4px 2px; }
.run-card {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--card-shadow);
}
.run-card:hover { border-color: var(--accent); background: var(--surface); }
.row-main { min-width: 0; }
.run-card h3 { font-family: var(--font-ui); font-size: 14.5px; line-height: 1.4; overflow-wrap: anywhere; }
.row-status { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.row-status.warn { color: var(--amber); }
.row-side { display: flex; align-items: center; gap: 12px; font-size: 12px; white-space: nowrap; }
.row-open { color: var(--primary); font-weight: 600; }
.collapsed { margin-bottom: 16px; }
.collapsed > summary { cursor: pointer; font-weight: 600; color: var(--primary); padding: 4px 0; }
.wanted { font-size: 14.5px; }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  line-height: 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
  background: var(--surface2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.live, .badge.good { background: var(--soft); border-color: var(--accent); color: var(--primary); }
.badge.warn { background: var(--amber-bg); border-color: var(--amber); color: var(--amber); }
.badge.bad { background: var(--red-bg); border-color: var(--red); color: var(--red); }

/* ---- Notices ---- */
.empty { color: var(--muted); font-size: 12px; padding: 24px 12px; text-align: center; line-height: 1.7; }
.notice, .callout { padding: 12px 16px; border-radius: 8px; background: var(--soft); border: 1px solid var(--line); font-size: 13px; margin-bottom: 20px; }
.notice.error, .error { color: var(--red); }

/* ---- Sign-in ---- */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(var(--soft), var(--bg)); padding: 24px; }
.login-card { max-width: 400px; text-align: center; }
.brand-tile {
  background: var(--primary);
  color: var(--on-primary);
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  margin: 0 auto 20px;
  box-shadow: 0 12px 36px -10px rgba(43, 74, 53, 0.4);
}
.brand-tile .brand-mark { width: 36px; height: 36px; color: var(--on-primary); }
.login-brand { display: flex; align-items: baseline; justify-content: center; }
.login .wordmark { font-size: 30px; }
.login .section-label { border: 0; padding: 0; margin: 8px 0 0; font-size: 17px; }
.login .eyebrow { margin-top: 12px; }
.login h1 { margin: 22px 0 12px; }
.login label { display: block; text-align: left; margin: 24px 0 6px; }
.login input, .login .primary { width: 100%; }
.login .primary { margin-top: 12px; }
.login .error { margin-top: 12px; }

/* ---- Dialogs ---- */
dialog {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  max-width: 600px;
  width: calc(100% - 32px);
  padding: 24px;
  box-shadow: 0 8px 24px -12px rgba(26, 26, 26, 0.18), 0 18px 70px rgba(26, 31, 28, 0.15);
  max-height: 90vh;
}
dialog::backdrop { background: rgba(26, 31, 28, 0.45); }
dialog label { display: block; margin: 18px 0 6px; }
dialog select { width: 100%; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; border-top: 1px solid var(--line); padding-top: 16px; }
.detail-dialog { max-width: 920px; }

/* ---- Run detail ---- */
.detail-requirement { white-space: pre-wrap; font-size: 16px; line-height: 1.65; margin: 12px 0 20px; }
.detail-tags, .detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-section { border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; min-width: 0; }
.detail-section h3 { margin-bottom: 12px; }
.facts { display: grid; grid-template-columns: 130px 1fr; gap: 8px; font-size: 12.5px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.event { border-left: 2px solid var(--line); padding: 0 0 14px 14px; margin-left: 3px; }
.event time { font-size: 11px; color: var(--muted); }
.event p { margin: 2px 0; font-size: 12.5px; }
.evidence { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.evidence:last-child { border: 0; }
.evidence summary { cursor: pointer; font-weight: 500; }
.evidence pre { max-height: 240px; overflow: auto; background: var(--bg); padding: 10px; border-radius: 6px; }
.approval-digest { display: block; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px; margin: 10px 0; }
.approval-check { display: flex !important; gap: 8px; align-items: flex-start; font-size: 12.5px; margin-bottom: 12px !important; }
.approval-check input { min-height: initial; }

/* ---- Focused page (the one page a Chaupal button opens) ---- */
.focus-view { max-width: 760px; margin: 0 auto; padding: 32px 24px 64px; }
.focus-title { font-size: 28px; line-height: 1.25; margin: 0 0 6px; overflow-wrap: anywhere; }
.focus-status { margin: 0 0 18px; font-size: 13px; }
.focus-ask { font-size: 16px; line-height: 1.55; }
.focus-done { font-size: 18px; margin: 20px 0; }
.focus-section { margin: 0 0 22px; }
.focus-section h2, .focus-section h3 { font-size: 17px; margin: 0 0 8px; }
.focus-summary { white-space: pre-wrap; margin: 0 0 10px; font-size: 15px; line-height: 1.6; }
.focus-view .detail-section { margin-bottom: 22px; }
.checked { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.checked li { display: flex; gap: 10px; align-items: baseline; }
.checked .mark { width: 16px; flex: none; text-align: center; font-weight: 700; }
.checked .ok .mark { color: var(--primary); }
.checked .bad { color: var(--amber); }
.checked .bad .mark { color: var(--red); }
.checked .none { color: var(--muted); }
.focus-actions, .focus-back { display: flex; gap: 12px; align-items: center; margin: 18px 0; }

/* ---- Health ---- */
.health-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.health-card { padding: 20px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; box-shadow: var(--card-shadow); }
.health-card p { font-size: 13px; margin-top: 8px; }
.health-card .badge { margin-top: 12px; }

/* ---- Responsive ---- */
@media (max-width: 1200px) {
  .shell { grid-template-columns: 190px 1fr; }
  main { padding: 24px; }
}
@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { padding: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar > .eyebrow, .sidebar-foot { display: none; }
  .sidebar nav { display: flex; }
  .nav { width: auto; font-size: 12px; gap: 6px; }
  .nav > span:first-child { display: none; }
  .topbar { padding: 8px 16px; flex-wrap: wrap; gap: 8px 12px; }
  .topbar-end { gap: 8px; font-size: 11px; flex-wrap: wrap; }
  .pilot-label, .brand-by { display: none; }
  main { padding: 20px 16px; }
  .page-heading { align-items: flex-start; flex-direction: column; margin-bottom: 20px; }
  .toolbar { flex-wrap: wrap; }
  .search { width: 100%; flex: 1 1 180px; }
  .toolbar #run-count { margin-left: 0; }
  .run-card { grid-template-columns: 1fr; gap: 6px; }
  .row-side { justify-content: space-between; }
  .detail-grid, .health-grid { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 100px 1fr; }
}
@media (prefers-reduced-motion: no-preference) {
  button, .back-link { transition: background 0.12s, border-color 0.12s; }
}
