/* =========================================================================
   Helm — design system stylesheet
   Source of truth: docs/design/helm-design-system.md (+ reference HTML
   palettes under docs/design/reference/).
   Tenets: retro instrumentation · JetBrains Mono · hard ink borders · square
   corners · offset shadows · signal-orange accent used sparingly.
   ========================================================================= */

/* --- Tokens ---------------------------------------------------------- */

:root {
  color-scheme: light;
  /* Cream / parchment (light, default) */
  --bg:        #ECE4D0;
  --bg-2:      #E1D8C1;
  --surface:   #F4EEDC;
  --surface-2: #EFE8D3;
  --ink:       #15130F;
  --ink-2:     #4A443A;
  --ink-3:     #8A8270;
  --accent:    #C0381A;
  --accent-fg: #FFF7E8;
  --ok:        #2E6B3D;
  --warn:      #B97400;
  --bad:       #9B1C1C;
  --rule:      #15130F;
  --rule-soft: #15130F33;

  --border:      1.5px solid var(--ink);
  --border-thin: 1px solid var(--ink);
  --border-soft: 1px solid var(--rule-soft);

  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, "Cascadia Mono", monospace;
  --font-crt:  "VT323", "JetBrains Mono", ui-monospace, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  /* Graphite (dark) — same token names, different values */
  --bg:        #14110C;
  --bg-2:      #1C1814;
  --surface:   #1A1612;
  --surface-2: #221D17;
  --ink:       #EDE4CD;
  --ink-2:     #B6AC95;
  --ink-3:     #7A7160;
  --accent:    #E9582A;
  --accent-fg: #14110C;
  --ok:        #6AB06F;
  --warn:      #E0A23A;
  --bad:       #E26464;
  --rule:      #EDE4CD;
  --rule-soft: #EDE4CD33;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "tnum" 1, "ss01" 1;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 32px;
  /* parchment dot texture */
  background-image:
    radial-gradient(rgba(0,0,0,0.025) 1px, transparent 1px),
    radial-gradient(rgba(0,0,0,0.018) 1px, transparent 1px);
  background-size: 3px 3px, 7px 7px;
  background-position: 0 0, 1px 2px;
}

body[data-theme="dark"] {
  background-image:
    repeating-linear-gradient(0deg,
      rgba(237,228,205,0.025) 0px,
      rgba(237,228,205,0.025) 1px,
      transparent 1px,
      transparent 3px);
}

/* --- Link defaults --------------------------------------------------- */
/* Bare <a> tags get the signal-orange accent. Without an explicit
   :visited rule the browser falls back to its default purple, which
   reads as dead chrome on parchment — keep visited == link. */

a,
a:link,
a:visited {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover,
a:focus {
  color: var(--accent);
  text-decoration: underline;
}

/* Styled anchors below set their own color, but :visited has higher
   specificity than a bare class — restate the intended color so the
   browser default doesn't override these. */

.brand:visited,
.footer a:visited { color: var(--bg); }

.button-link:visited,
.helm-btn:visited,
.primary-nav a:visited { color: var(--ink); }

.button-link.primary-link:visited,
.button-link.primary:visited,
.helm-btn-primary:visited { color: var(--accent-fg); }

.helm-btn-ghost:visited { color: var(--ink); }

.button-link.danger:visited { color: var(--bad); }

.object-title:visited { color: var(--ink); }

.tag:visited { color: var(--ink-2); }

/* --- Sheet wrapper --------------------------------------------------- */
/* The whole app shell (stamp → body → footer) sits inside one sheet. */

.sheet {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  background: var(--surface);
  border: var(--border);
  box-shadow: 8px 8px 0 var(--ink);
}

/* --- Systemic overflow containment ----------------------------------
   One base guard so long unbroken strings (JSON blobs, URLs, tokens,
   file paths) can never force the layout wider than the parchment sheet.
   Supersedes per-page overflow patches — see docs/design §08.

   Flex/grid items default to min-width:auto and refuse to shrink below
   their content, which is the classic cause of a child escaping its
   container. Let the layout chain shrink so inner content wraps (or
   scrolls within its own panel) instead of pushing the page sideways. */
.sheet,
.topbar,
.stamp,
.container,
.footer,
.sec,
.sec-body,
.card { min-width: 0; }

/* Body copy and content panels break unbreakable strings hard rather
   than overflowing. Normal prose still wraps at spaces as usual. */
.container,
.sec-body,
.card { overflow-wrap: anywhere; }

/* Replaced / embedded elements never exceed their column. */
img,
svg,
video,
canvas,
iframe { max-width: 100%; height: auto; }

/* Utility: wrap a table (or any wide block) that must keep its width in
   this so the panel scrolls horizontally — never the whole page. */
.table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

/* Any preformatted block stays within its panel. Prose-style blocks use
   .code-block (white-space: pre-wrap; see below) to wrap; code snippets
   that must preserve line shape scroll horizontally inside their own box
   rather than widening the sheet. */
pre { max-width: 100%; }
pre:not(.code-block) { overflow-x: auto; }

/* --- Stamp (top bar) ------------------------------------------------- */

.topbar,
.stamp {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 24px;
  padding: 14px 22px;
  background: var(--ink);
  color: var(--bg);
  border-bottom: var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--bg);
  text-decoration: none;
}

.brand-mark {
  display: block;
  width: 48px;
  height: 48px;
  /* The PNG is white on transparent, sitting on var(--ink). */
  image-rendering: -webkit-optimize-contrast;
  transform-origin: 50% 50%;
  transition: transform 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.brand:hover .brand-mark,
.brand:focus-visible .brand-mark {
  transform: rotate(25deg);
}

@media (prefers-reduced-motion: reduce) {
  .brand-mark { transition: none; }
  .brand:hover .brand-mark,
  .brand:focus-visible .brand-mark { transform: none; }
}

.brand-text {
  font-weight: 800;
  font-size: 24px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

/* Legacy ".brand" (without inner spans) — keep usable as-is */
.brand:not(:has(.brand-text)) {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.version,
.stamp-meta {
  font-size: 12px;
  letter-spacing: 0.18em;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* --- Primary nav ----------------------------------------------------- */

.topbar-left {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

/* Hamburger toggle + logout — instrumentation buttons on the ink bar. */
.nav-toggle,
.logout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  background: transparent;
  color: var(--bg);
  border: 1.5px solid var(--bg);
  font-family: var(--font-mono);
  line-height: 1;
  cursor: pointer;
}

/* Hamburger is a fixed icon square; logout is a tracked text button. */
.nav-toggle {
  width: 34px;
  padding: 0;
  font-size: 16px;
}

.logout-btn {
  padding: 0 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.nav-toggle:hover,
.nav-toggle:focus-visible,
.logout-btn:hover,
.logout-btn:focus-visible {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  outline: none;
}

.theme-switcher {
  display: inline-flex;
  align-items: center;
  margin: 0;
  border: 1.5px solid var(--bg);
}

.theme-switcher label {
  margin: 0;
  display: inline-flex;
  align-items: center;
  height: 31px;
  color: var(--bg);
  letter-spacing: 0.14em;
  border-right: 1.5px solid var(--bg);
  cursor: pointer;
}

.theme-switcher label:last-of-type {
  border-right: none;
}

.theme-switcher input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.theme-switcher span {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 10px;
}

.theme-switcher label:hover span,
.theme-switcher label:focus-within span,
.theme-switcher input:checked + span {
  background: var(--accent);
  color: var(--accent-fg);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Primary nav is a flyout panel that drops from the topbar's right edge.
   Closed by default; the toggle adds .open. Lifted surface, so it carries
   the offset (never blurred) drop shadow per the design system. */
.primary-nav {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 60;
  flex-direction: column;
  min-width: 200px;
  background: var(--surface);
  color: var(--ink);
  border: var(--border);
  box-shadow: 8px 8px 0 var(--ink);
}

.primary-nav.open {
  display: flex;
}

.primary-nav a {
  display: block;
  padding: 11px 18px;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  border-bottom: var(--border-soft);
}

.primary-nav a:last-child {
  border-bottom: none;
}

.primary-nav a:hover,
.primary-nav a:focus-visible,
.primary-nav a.active {
  background: var(--accent);
  color: var(--accent-fg);
  outline: none;
}

/* --- Topbar right (nav toggle / flyout anchor) ----------------------- */

.topbar-right {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: flex-end;
}

/* --- Main container -------------------------------------------------- */

.container {
  flex: 1;
  width: 100%;
  margin: 0;
  padding: 28px 28px;
  background: var(--surface);
}

.container.wide {
  max-width: none;
}

/* --- Footer (inverted strip) ----------------------------------------- */

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 22px;
  background: var(--ink);
  color: var(--bg);
  border-top: var(--border);
  text-align: left;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.footer small {
  font-size: inherit;
  color: var(--bg);
}

.footer-mark { color: var(--accent); margin-right: 6px; }
.footer-meta { color: var(--ink-3); }
.footer .accent { color: var(--accent); }

/* --- Cards / panels -------------------------------------------------- */

.card {
  background: var(--surface);
  border: var(--border-thin);
  padding: 22px 24px;
  box-shadow: none;
}

.card + .card { margin-top: 18px; }

/* --- Headings -------------------------------------------------------- */

h1 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink);
  line-height: 1.1;
}

h2 {
  margin: 22px 0 8px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink);
}

h3 {
  margin: 18px 0 6px;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-2);
}

h4 {
  margin: 14px 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
}

p { margin: 6px 0 12px; color: var(--ink); }

hr {
  border: none;
  border-top: 1.5px solid var(--ink);
  margin: 20px 0;
}

/* --- Muted / helpers ------------------------------------------------- */

.muted { color: var(--ink-2); }

.small { font-size: 12.5px; }

.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.row.gap { gap: 10px; }

/* --- Lists ----------------------------------------------------------- */

ul { padding-left: 1.25rem; }
li { margin: 4px 0; }

/* --- Forms ----------------------------------------------------------- */

label {
  display: block;
  margin: 16px 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-2);
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="search"],
input[type="url"],
input[type="number"],
input[type="date"],
textarea,
select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: var(--border-thin);
  border-radius: 0;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
}

textarea {
  white-space: pre-wrap;
  word-wrap: break-word;
  min-height: 160px;
}

/* Preformatted blocks (e.g. project/client instructions). Wrap rather than
   overflow the panel — long unbroken strings break anywhere. */
.code-block {
  display: block;
  margin: 0;
  padding: 12px 14px;
  background: var(--bg-2);
  border: var(--border-thin);
  border-radius: 0;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Inline previews on the project file view (image / PDF / audio-video). */
.file-image-preview {
  display: block;
  max-width: 100%;
  height: auto;
  border: var(--border-thin);
  background: var(--bg-2);
}

.file-pdf-preview {
  display: block;
  width: 100%;
  height: 80vh;
  border: var(--border-thin);
  background: var(--bg-2);
}

.file-av-preview {
  display: block;
  max-width: 100%;
  margin-top: 4px;
}
video.file-av-preview { height: auto; }

/* CSV/TSV rendered as a table. Horizontal scroll for wide sheets; sticky
   monospace header on the design-system ink rules. */
.file-table-wrap {
  overflow-x: auto;
  border: var(--border-thin);
}

.file-table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 13px;
}

.file-table th,
.file-table td {
  padding: 5px 10px;
  border-bottom: var(--border-soft);
  border-right: var(--border-soft);
  text-align: left;
  white-space: pre;
  vertical-align: top;
}

.file-table th {
  position: sticky;
  top: 0;
  background: var(--bg-2);
  color: var(--ink);
  font-weight: 700;
  border-bottom: var(--border-thin);
}

.file-table tbody tr:nth-child(even) { background: var(--bg-2); }
.file-table th:last-child,
.file-table td:last-child { border-right: none; }

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

/* --- Buttons --------------------------------------------------------- */

button,
.button-link {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 7px 14px;
  background: var(--surface);
  color: var(--ink);
  border: var(--border-thin);
  border-radius: 0;
  text-decoration: none;
  display: inline-block;
  line-height: 1.2;
}

button:hover,
.button-link:hover {
  background: var(--bg-2);
  color: var(--ink);
}

button.primary,
.button-link.primary-link,
.helm-btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

button.primary { margin-top: 20px; width: 100%; }

button.primary:hover,
.button-link.primary-link:hover,
.helm-btn-primary:hover {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

button.ghost,
.helm-btn-ghost {
  background: transparent;
  color: var(--ink);
  border: var(--border-thin);
}

button.ghost:hover,
.helm-btn-ghost:hover {
  background: var(--bg-2);
  color: var(--ink);
}

button.ghost.danger,
.button-link.danger,
.helm-btn.danger {
  color: var(--bad);
  border-color: var(--bad);
}

button.ghost.danger:hover,
.helm-btn.danger:hover {
  background: var(--bad);
  color: var(--bg);
  border-color: var(--bad);
}

/* Small variant */
.helm-btn-sm,
button.sm,
.button-link.sm {
  padding: 4px 10px;
  font-size: 11px;
}

/* Helm-native button class (forward-compatible with design system) */
.helm-btn {
  appearance: none;
  background: var(--surface);
  color: var(--ink);
  border: var(--border-thin);
  border-radius: 0;
  padding: 7px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.2;
}

.helm-btn:hover { background: var(--bg-2); color: var(--ink); }

.logout-form { margin: 0; }
.inline-form { display: inline-block; margin: 0; }

/* --- Alerts ---------------------------------------------------------- */

.alert {
  margin: 12px 0;
  padding: 10px 12px;
  background: var(--bad);
  color: var(--bg);
  border: var(--border-thin);
  border-color: var(--bad);
  border-radius: 0;
  font-size: 13px;
  font-weight: 600;
}

.alert.ok {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--bg);
}

.alert.warn {
  background: var(--warn);
  border-color: var(--warn);
  color: var(--bg);
}

/* --- Inline code ----------------------------------------------------- */

code {
  background: var(--bg-2);
  border: var(--border-soft);
  padding: 1px 5px;
  border-radius: 0;
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--ink);
  /* A long token / URL in inline code wraps instead of widening the row. */
  overflow-wrap: anywhere;
}

/* --- Block code (helm-code) ----------------------------------------- */

pre.helm-code {
  font-family: var(--font-mono);
  background: var(--bg);
  border: var(--border-thin);
  border-radius: 0;
  padding: 12px 14px;
  margin: 12px 0;
  overflow: auto;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
}

pre.helm-code code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

/* --- KV / dl --------------------------------------------------------- */

dl.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 16px;
  row-gap: 6px;
  margin: 0;
  font-size: 13.5px;
}

dl.kv dt {
  color: var(--ink-3);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 700;
}

dl.kv dd { margin: 0; color: var(--ink); }

/* --- Activity / event lists ----------------------------------------- */

ul.events { list-style: none; padding: 0; margin: 0; }

ul.events li {
  padding: 8px 0;
  border-bottom: var(--border-soft);
  font-size: 13px;
  color: var(--ink);
}

ul.events li:last-child { border-bottom: none; }

.event-type {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.hint { margin-top: 12px; font-size: 12.5px; color: var(--ink-2); }

/* --- Object list (notes, tasks, resources, etc.) -------------------- */

.object-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  border-top: var(--border-thin);
  border-bottom: var(--border-thin);
}

.object-list li {
  padding: 12px 14px;
  border-bottom: var(--border-soft);
  background: var(--surface);
  margin: 0;
}

.object-list li:last-child { border-bottom: none; }

.object-title {
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: 0.01em;
}

.object-title:hover { color: var(--accent); }

.ticket-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
}

.ticket-card {
  min-width: 0;
  margin: 0;
  padding: 14px;
  background: var(--surface-2);
  border: var(--border-thin);
}

.ticket-card.is-muted {
  color: var(--ink-2);
  background: var(--bg-2);
}

.ticket-card .helm-tag {
  margin-top: 8px;
}

.pinned {
  color: var(--accent);
  margin-right: 4px;
}

/* --- Tags (legacy class) -------------------------------------------- */

.tags {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-block;
  padding: 2px 7px;
  font-size: 12px;
  letter-spacing: 0.04em;
  font-weight: 600;
  border: var(--border-soft);
  background: var(--bg-2);
  color: var(--ink-2);
  text-decoration: none;
  border-radius: 0;
}

.tag::before {
  content: "● ";
  color: var(--ink-3);
}

.tag:hover {
  background: var(--surface-2);
  color: var(--ink);
}

/* --- Status pills (legacy class) ------------------------------------ */

.status {
  display: inline-block;
  padding: 2px 7px;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  border-radius: 0;
}

.status-open    { background: var(--ink);    border-color: var(--ink);    color: var(--bg); }
.status-doing   { background: var(--warn);   border-color: var(--warn);   color: var(--bg); }
.status-done    { background: transparent;   border-color: var(--ink-3);  color: var(--ink-2); }
.status-blocked { background: var(--bad);    border-color: var(--bad);    color: var(--bg); }

/* --- Note / pre body ------------------------------------------------- */

.note-body {
  font-family: var(--font-mono);
  background: var(--bg);
  border: var(--border-thin);
  border-radius: 0;
  padding: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
  color: var(--ink);
  margin: 12px 0;
}

/* --- Data tables ----------------------------------------------------- */

table.data {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
  border-top: var(--border-thin);
  border-bottom: var(--border-thin);
}

table.data th,
table.data td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: var(--border-soft);
  vertical-align: top;
  /* Long unbroken cell values (audit detail blobs, tokens, paths) break
     within the cell instead of forcing the table past the panel. */
  overflow-wrap: anywhere;
}

table.data th {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: var(--bg-2);
}

table.data tr:last-child td { border-bottom: none; }

.active { font-weight: 700; color: var(--ink); }

/* =========================================================================
   Rendered Markdown (project file viewer) — engineering-sheet prose.
   Output comes from app/markdown_render.py (escape-first, injection-safe).
   ========================================================================= */
.md-body {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4,
.md-body h5,
.md-body h6 {
  font-family: var(--font-mono);
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.25;
  margin: 1.6em 0 0.6em;
}

.md-body h1 { font-size: 24px; }
.md-body h2 { font-size: 19px; }
.md-body h3 { font-size: 16px; }
.md-body h4,
.md-body h5,
.md-body h6 { font-size: 14px; }

.md-body h1,
.md-body h2 {
  padding-bottom: 6px;
  border-bottom: var(--border-thin);
}

.md-body > :first-child { margin-top: 0; }

.md-body p { margin: 0 0 1em; }

.md-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.md-body ul,
.md-body ol { margin: 0 0 1em; padding-left: 1.6em; }

.md-body li { margin: 0.2em 0; }

.md-body code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  padding: 1px 5px;
  background: var(--surface-2);
  border: var(--border-soft);
}

.md-body pre.code-block { margin: 0 0 1em; }
.md-body pre.code-block code {
  padding: 0;
  background: none;
  border: none;
}

.md-body blockquote {
  margin: 0 0 1em;
  padding: 4px 14px;
  border-left: 3px solid var(--accent);
  color: var(--ink-2);
}

.md-body hr {
  border: none;
  border-top: var(--border-thin);
  margin: 1.6em 0;
}

.md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1.2em;
  font-size: 13px;
  border: var(--border-thin);
}

.md-table th,
.md-table td {
  text-align: left;
  padding: 8px 10px;
  border: var(--border-soft);
  vertical-align: top;
  overflow-wrap: anywhere;
}

.md-table th {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: var(--bg-2);
}

.file-path-head { font-size: 20px; }

/* =========================================================================
   Helm-native components (forward-compatible class names)
   These match the names documented in docs/design/helm-design-system.md
   and the reference palette HTML. Use these on new markup.
   ========================================================================= */

/* Pills -------------------------------------------------------------- */

.helm-pill {
  display: inline-block;
  padding: 2px 7px;
  font-size: 11px;
  letter-spacing: 0.14em;
  font-weight: 700;
  text-transform: uppercase;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
}

.helm-pill-ok     { background: var(--ok);     border-color: var(--ok);     color: var(--bg); }
.helm-pill-warn   { background: var(--warn);   border-color: var(--warn);   color: var(--bg); }
.helm-pill-bad    { background: var(--bad);    border-color: var(--bad);    color: var(--bg); }
.helm-pill-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.helm-pill-muted  { background: transparent;   border-color: var(--ink-3);  color: var(--ink-2); }

/* Priority chips ----------------------------------------------------- */

.helm-prio {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 800;
  border: 1px solid var(--ink);
  vertical-align: middle;
}

.helm-prio-U { background: var(--bad);    color: var(--bg); border-color: var(--bad); }
.helm-prio-H { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.helm-prio-M { background: var(--ink);    color: var(--bg); }
.helm-prio-L { background: transparent;   color: var(--ink-2); border-color: var(--ink-3); }

/* Manifest tags ------------------------------------------------------ */

.helm-tag {
  display: inline-block;
  padding: 2px 6px;
  font-size: 12px;
  letter-spacing: 0.04em;
  font-weight: 600;
  border: var(--border-soft);
  background: var(--bg-2);
  color: var(--ink-2);
  text-decoration: none;
}

.helm-tag-skill::before { content: "● "; color: var(--ink-2); }
.helm-tag-mcp { background: var(--surface-2); border-color: var(--ink-3); }
.helm-tag-mcp::before { content: "▶ "; color: var(--accent); }

/* Count block (dominant numeric display) ----------------------------- */

.helm-count {
  display: inline-flex;
  flex-direction: column;
  border: var(--border-thin);
  padding: 10px 14px;
  background: var(--surface);
  min-width: 110px;
}

.helm-count + .helm-count { margin-left: 8px; }

.helm-count-value {
  font-size: 42px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.helm-count-label {
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 0.2em;
  font-weight: 700;
  color: var(--ink-2);
  text-transform: uppercase;
}

.helm-count-accent {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.helm-count-accent .helm-count-value { color: var(--accent-fg); }
.helm-count-accent .helm-count-label { color: var(--accent-fg); opacity: 0.85; }

/* Panel structure (inverted ink head) -------------------------------- */

.panel-sample {
  border: var(--border-thin);
  background: var(--surface);
}

.panel-sample-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ink);
  color: var(--bg);
  padding: 6px 12px;
}

.panel-sample-label {
  display: inline-flex;
  gap: 10px;
  align-items: baseline;
  font-size: 12.5px;
  letter-spacing: 0.18em;
  font-weight: 700;
  text-transform: uppercase;
}

.panel-sample-section {
  color: var(--accent);
  font-weight: 800;
}

.panel-sample-right {
  font-size: 11px;
  letter-spacing: 0.14em;
  opacity: 0.7;
}

.panel-sample-body {
  padding: 14px;
  color: var(--ink-2);
  font-size: 13px;
}

/* Section row (sec + sec-label + sec-body) --------------------------- */

.sec {
  display: grid;
  grid-template-columns: 120px 1fr;
  border-top: var(--border);
}

.sec:first-of-type { border-top: 0; }

.sec-label {
  background: var(--bg-2);
  padding: 18px 14px;
  border-right: var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sec-no {
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--ink-3);
  font-weight: 700;
}

.sec-title {
  font-size: 15.5px;
  letter-spacing: 0.16em;
  font-weight: 800;
  text-transform: uppercase;
}

.sec-body { padding: 20px 24px; }

/* Rules / dividers --------------------------------------------------- */

.rule-line {
  display: block;
  height: 1.5px;
  background: var(--ink);
}

.rule-line.dashed {
  background-image: linear-gradient(90deg, var(--ink) 50%, transparent 50%);
  background-size: 5px 1.5px;
  background-repeat: repeat-x;
  background-color: transparent;
}

.rule-lbl {
  font-size: 11px;
  letter-spacing: 0.18em;
  font-weight: 700;
  color: var(--ink-2);
  text-transform: uppercase;
}

/* --- Project Kanban -------------------------------------------------- */

.kanban-panel {
  margin-top: 22px;
  border: var(--border);
  background: var(--surface);
}

.kanban-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--bg);
  border-bottom: var(--border);
}

.kanban-panel-label {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--bg);
}

.kanban-panel-section {
  color: var(--accent);
  font-weight: 800;
  font-size: 14.5px;
}

.kanban-create-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: min(420px, 100%);
}

.kanban-create-form input[type="text"] {
  background: var(--bg);
  color: var(--ink);
  border: var(--border-thin);
  height: 30px;
  padding: 4px 8px;
}

.kanban-create-form input[type="text"]::placeholder {
  color: var(--ink-3);
  text-transform: none;
  letter-spacing: 0.04em;
}

.kanban-create-form .helm-btn-primary {
  height: 30px;
  padding: 4px 14px;
  line-height: 1.2;
}

.kanban-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0;
  background: var(--bg-2);
}

.kanban-column {
  min-width: 0;
  border-right: var(--border-thin);
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.kanban-column:last-child { border-right: none; }

.kanban-column-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 9px 8px;
  background: var(--ink);
  color: var(--bg);
  border-bottom: var(--border-thin);
}

.kanban-column-head h3 {
  margin: 0;
  min-width: 0;
  color: var(--bg);
  font-size: 11px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kanban-column-head .helm-pill-muted {
  border-color: var(--bg);
  color: var(--bg);
  background: transparent;
}

.kanban-dropzone {
  flex: 1;
  min-height: 360px;
  padding: 10px;
  background: var(--surface);
}

.kanban-dropzone.is-over {
  background: var(--bg-2);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.kanban-card {
  position: relative;
  margin: 0 0 10px;
  padding: 10px 10px 10px 12px;
  background: var(--surface-2);
  border: var(--border-thin);
  border-left: 3px solid var(--ink);
  cursor: grab;
  transition: transform 80ms linear, box-shadow 80ms linear;
}

.kanban-card:hover {
  background: var(--surface);
  box-shadow: 3px 3px 0 var(--ink);
  transform: translate(-1px, -1px);
}

.kanban-card:focus-visible,
.kanban-card:focus-within:not(:hover) {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.kanban-card.is-dragging {
  opacity: 0.55;
  cursor: grabbing;
  box-shadow: none;
  transform: none;
}

.kanban-card.prio-urgent { border-left-color: var(--bad); }
.kanban-card.prio-high   { border-left-color: var(--accent); }
.kanban-card.prio-medium { border-left-color: var(--ink); }
.kanban-card.prio-low    { border-left-color: var(--ink-3); }

.kanban-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.id-tag {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  font-feature-settings: "tnum" 1;
  vertical-align: middle;
}

.kanban-title-form {
  margin: 6px 0 0;
  min-width: 0;
}

.kanban-title-input {
  width: 100%;
  border: none;
  border-bottom: 1px dashed var(--rule-soft);
  background: transparent;
  padding: 0 0 3px;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.kanban-title-input:hover { border-bottom-color: var(--ink-3); }

.kanban-title-input:focus {
  outline: none;
  border-bottom: 1px solid var(--accent);
  box-shadow: none;
}

.kanban-card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.kanban-due {
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
}

.kanban-due::first-letter { color: var(--accent); }

.kanban-empty {
  margin: 8px 0;
  font-style: italic;
  color: var(--ink-3);
}

/* Collapsed columns hide overflow past the cap (kept in sync with
   COLLAPSE_CAP in project-kanban.js — show the first 8, hide the 9th on). */
.kanban-dropzone.is-collapsed .kanban-card:nth-of-type(n+9) { display: none; }

.kanban-toggle {
  display: block;
  width: 100%;
  margin: 2px 0 0;
  padding: 7px 10px;
  background: var(--surface);
  border: var(--border-thin);
  border-left: 3px solid var(--ink-3);
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
  transition: transform 80ms linear, box-shadow 80ms linear;
}

.kanban-toggle:hover {
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  transform: translate(-1px, -1px);
}

.kanban-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

body.kanban-flyout-open { overflow: hidden; }

.kanban-flyout {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.kanban-flyout.is-open { display: block; }

.kanban-flyout-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.kanban-flyout-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: clamp(560px, 65vw, 100vw);
  height: 100%;
  overflow-y: auto;
  background: var(--surface);
  color: var(--ink);
  border-left: var(--border);
  box-shadow: -8px 0 0 var(--ink);
  padding: 0 18px 18px;
}

.kanban-flyout-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 -18px 18px;
  padding: 12px 18px;
  background: var(--ink);
  color: var(--bg);
  border-bottom: var(--border);
}

.kanban-flyout-head h2 {
  margin: 0;
  color: var(--bg);
  font-size: 15.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.kanban-flyout-head .helm-btn {
  background: transparent;
  color: var(--bg);
  border-color: var(--bg);
}

.kanban-flyout-head .helm-btn:hover {
  background: var(--bg);
  color: var(--ink);
}

.kanban-flyout-provenance {
  margin: -6px 0 16px;
  padding-bottom: 12px;
  border-bottom: var(--border-soft);
}

.kanban-flyout-form { margin: 0; }

.kanban-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 12px;
}

.kanban-flyout-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: var(--border-soft);
}

/* Save sits on the left; Archive + Delete float to the right edge so the
   primary action stays clear of the destructive one. */
.kanban-flyout-footer #kanban-flyout-archive-form { margin-left: auto; }

/* --- Card ↔ file links (flyout) ------------------------------------- */
.kanban-flyout-links {
  margin-top: 18px;
  padding-top: 16px;
  border-top: var(--border-soft);
}

.kanban-flyout-links h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.kanban-links-list {
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.kanban-link-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border: var(--border-soft);
  margin-bottom: 6px;
}

.kanban-link-item a {
  overflow-wrap: anywhere;
}

.kanban-link-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 0;
}

/* Dropdown takes the remaining room but is capped so it doesn't hog the wide
   flyout; the Link button keeps its natural width instead of being squished. */
.kanban-link-form select { flex: 1 1 auto; min-width: 0; max-width: 420px; }
.kanban-link-form button { flex: 0 0 auto; white-space: nowrap; }

.kanban-link-pill { margin-right: 4px; }

.kanban-activity-pill {
  max-width: 100%;
  white-space: normal;
}

.kanban-flyout-activity {
  margin-top: 18px;
  padding-top: 16px;
  border-top: var(--border-soft);
}

.kanban-flyout-activity details {
  border: var(--border-soft);
  background: var(--surface-2);
}

.kanban-flyout-activity summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
}

.kanban-flyout-activity summary span:last-child {
  font-weight: 400;
  text-align: right;
  overflow-wrap: anywhere;
}

.kanban-activity-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 0 12px 12px;
}

.kanban-activity-groups h3 {
  margin: 6px 0 8px;
  font-size: 0.9rem;
}

.kanban-activity-list {
  margin: 0;
  padding-left: 18px;
}

.kanban-activity-list li {
  margin-bottom: 10px;
  overflow-wrap: anywhere;
}

.kanban-activity-list p {
  margin: 3px 0 0;
}

.kanban-evidence-uri {
  font-family: var(--font-mono);
  font-size: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Archived cards list (project Archives page) --------------------- */
.kanban-archived-list {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.kanban-archived-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 8px;
  border-top: var(--border-soft);
  cursor: pointer;
}

.kanban-archived-row:hover { background: var(--surface-2); }

.kanban-archived-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.kanban-archived-title {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

/* --- Archive detail flyout ------------------------------------------- */
.archive-flyout-card-title {
  margin: 0 0 12px;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.archive-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  margin: 0 0 14px;
}

.archive-detail-grid dt {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.archive-detail-grid dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

.archive-detail-heading {
  margin: 14px 0 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.archive-flyout-description {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-2);
}

@media (max-width: 900px) {
  .kanban-panel-head {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .kanban-create-form,
  .kanban-form-grid {
    grid-template-columns: 1fr;
  }

  .kanban-flyout-panel {
    width: 100vw;
    box-shadow: none;
  }
}

/* --- Drop zone (reusable D&D upload target) -------------------------- */

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 120px;
  margin: 14px 0;
  padding: 22px 18px;
  background: var(--surface);
  border: 1.5px dashed var(--ink);
  border-radius: 0;
  cursor: pointer;
  transition: background 0.08s ease-out, transform 0.08s ease-out, box-shadow 0.08s ease-out;
  font-family: var(--font-mono);
  color: var(--ink);
  text-align: center;
  user-select: none;
}

.drop-zone:hover {
  background: var(--surface-2);
}

.drop-zone.is-dragover {
  background: var(--bg-2);
  border-color: var(--accent);
  border-style: solid;
  box-shadow: 6px 6px 0 var(--ink);
  transform: translate(-2px, -2px);
}

.drop-zone .drop-zone-label {
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.drop-zone .drop-zone-hint {
  font-size: 13px;
  color: var(--ink-2);
}

.drop-zone .drop-zone-status {
  margin-top: 6px;
  font-size: 12.5px;
  letter-spacing: 0.05em;
  color: var(--ink-2);
  min-height: 14px;
}
.drop-zone .drop-zone-status[data-kind="ok"]   { color: var(--ok); }
.drop-zone .drop-zone-status[data-kind="bad"]  { color: var(--bad); }
.drop-zone .drop-zone-status[data-kind="info"] { color: var(--accent); }

/* --- Project files: drop zone + tree ------------------------------- */

.project-files-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 110px;
  margin: 14px 0;
  padding: 22px 18px;
  background: var(--surface);
  border: 1.5px dashed var(--ink);
  border-radius: 0;
  cursor: pointer;
  transition: background 0.08s ease-out, transform 0.08s ease-out, box-shadow 0.08s ease-out;
  font-family: var(--font-mono);
  color: var(--ink);
  text-align: center;
  user-select: none;
}

.project-files-drop:hover { background: var(--surface-2); }

.project-files-drop.is-dragover {
  background: var(--bg-2);
  border-color: var(--accent);
  border-style: solid;
  box-shadow: 6px 6px 0 var(--ink);
  transform: translate(-2px, -2px);
}

.project-files-drop-label {
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.project-files-drop-hint {
  font-size: 13px;
  color: var(--ink-2);
}

.project-files-drop-hint .link-button {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--ink);
  color: var(--ink);
  padding: 0 2px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.02em;
}

.project-files-drop-hint .link-button:hover {
  background: var(--ink);
  color: var(--bg);
}

.project-files-drop-status {
  margin-top: 6px;
  min-height: 14px;
  font-size: 12.5px;
  letter-spacing: 0.05em;
  color: var(--ink-2);
}

.project-files-drop-status[data-kind="ok"]   { color: var(--ok); }
.project-files-drop-status[data-kind="bad"]  { color: var(--bad); }
.project-files-drop-status[data-kind="info"] { color: var(--accent); }

.file-tree {
  list-style: none;
  padding: 0;
  margin: 12px 0 24px;
  border-top: var(--border-thin);
  border-bottom: var(--border-thin);
  font-family: var(--font-mono);
}

.file-tree-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px calc(12px + var(--depth, 0) * 18px);
  border-bottom: var(--border-soft);
  background-color: var(--surface);
  /* Hierarchy indent guides: one vertical rail per ancestor level, drawn only
     across the row's indent zone (depth * 18px). Rails line up row-to-row into
     continuous verticals; a collapsed folder hides its children so the rail
     naturally stops. background-color (not the shorthand) keeps this image. */
  background-image: repeating-linear-gradient(
    to right,
    var(--rule-soft) 0, var(--rule-soft) 1px,
    transparent 1px, transparent 18px
  );
  background-repeat: no-repeat;
  background-position-x: 17px;
  background-size: calc(var(--depth, 0) * 18px) 100%;
  font-size: 14px;
}

.file-tree-row:last-child { border-bottom: none; }

/* The collapse logic sets [hidden] on rows; the `display: flex` above would
   otherwise win over the UA [hidden] rule, so re-assert it with enough
   specificity to actually hide collapsed descendants. */
.file-tree-row[hidden] { display: none; }

.file-tree-row.is-dir {
  background-color: var(--bg-2);
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.02em;
}

.file-tree-row.is-file:hover {
  background-color: var(--bg-2);
}

.file-tree-name {
  flex: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-tree-name a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px dotted var(--rule-soft);
}

.file-tree-name a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.file-tree-glyph {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-2);
  width: 12px;
  display: inline-block;
  text-align: center;
}

.file-tree-row.is-dir .file-tree-glyph { color: var(--accent); }

/* Folder name doubles as the collapse toggle — a button reset to read as the
   row label, with the glyph rotating ▾/▸ for expanded/collapsed. */
.file-tree-toggle {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.file-tree-toggle:hover { color: var(--accent); }
.file-tree-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.file-tree-meta {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* Compact square icon button (e.g. row delete actions). Inherits the ghost
   danger treatment but sized to the icon. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: var(--border-thin);
  color: var(--ink-2);
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn .icon { width: 15px; height: 15px; display: block; }

.icon-btn.danger { color: var(--bad); border-color: var(--bad); }
.icon-btn.danger:hover { background: var(--bad); color: var(--bg); }
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* --- Skill list rows (compact stacked) ----------------------------- */

.skill-list { padding: 0; }

.skill-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: var(--border-soft);
  background: var(--surface);
  cursor: pointer;
  transition: background 0.08s ease-out;
}

.skill-row:hover,
.skill-row:focus {
  background: var(--bg-2);
  outline: none;
}

.skill-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.skill-row-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  color: var(--ink);
}

/* --- Skill detail modal -------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal[aria-hidden="true"] {
  display: none;
}

body.modal-open { overflow: hidden; }

.skill-modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(20, 17, 12, 0.45);
}

.skill-modal-panel {
  position: relative;
  width: min(860px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: var(--border);
  box-shadow: 8px 8px 0 var(--ink);
  border-radius: 0;
}

.skill-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: var(--ink);
  color: var(--bg);
  border-bottom: var(--border);
}

.skill-modal-head h2 {
  margin: 0;
  font-size: 16.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--bg);
}

.skill-modal-description {
  margin: 4px 0 0;
  color: var(--bg);
  opacity: 0.78;
}

.skill-modal-view,
.skill-modal-editor {
  padding: 18px 22px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 240px;
}

.skill-modal-textarea {
  width: 100%;
  min-height: 360px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
  border: var(--border-thin);
  border-radius: 0;
  padding: 12px 14px;
  resize: vertical;
}

/* --- Markdown rendered output ------------------------------------- */

.md-rendered { color: var(--ink); }
.md-rendered h1,
.md-rendered h2,
.md-rendered h3,
.md-rendered h4 {
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  margin: 18px 0 8px;
  color: var(--ink);
}
.md-rendered h1 { font-size: 22px; font-weight: 800; }
.md-rendered h2 { font-size: 17.5px; font-weight: 800; }
.md-rendered h3 { font-size: 15px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-2); }
.md-rendered p  { margin: 8px 0; }
.md-rendered ul,
.md-rendered ol { margin: 8px 0 8px 22px; padding: 0; }
.md-rendered li { margin: 3px 0; }
.md-rendered a  { color: var(--accent); }
.md-rendered code {
  font-family: var(--font-mono);
  background: var(--bg-2);
  padding: 1px 5px;
  border: var(--border-soft);
  border-radius: 0;
  font-size: 13px;
}
.md-rendered pre {
  background: var(--bg);
  border: var(--border-thin);
  border-radius: 0;
  padding: 12px 14px;
  overflow: auto;
  font-size: 13.5px;
}
.md-rendered pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13.5px;
}
.md-rendered blockquote {
  border-left: 3px solid var(--accent);
  margin: 10px 0;
  padding: 4px 12px;
  background: var(--bg-2);
  color: var(--ink-2);
}
.md-rendered table {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
}
.md-rendered th,
.md-rendered td {
  border: var(--border-soft);
  padding: 6px 10px;
}
.md-rendered th { background: var(--bg-2); text-align: left; }
.md-rendered hr { border: none; border-top: var(--border-soft); margin: 16px 0; }

/* Mono textarea helper used by the create-skill body field. */
textarea.mono {
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.5;
}

@media (max-width: 620px) {
  .modal { padding: 0; }
  .skill-modal-panel {
    width: 100vw;
    max-height: 100vh;
    box-shadow: none;
    border-left: none;
    border-right: none;
  }
}

/* ---- Scope picker (token creation form) -----------------------------------
   Used by /account/tokens. Uses design-system tokens — see
   docs/design/helm-design-system.md §01. */
.scope-picker {
  border: var(--border-thin);
  padding: 12px 14px 14px;
  margin: 12px 0 16px;
  background: var(--surface);
}
.scope-picker > legend {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  padding: 0 8px;
  color: var(--ink);
}
.scope-picker-help {
  margin: 0 0 12px;
  font-size: 13.5px;
  color: var(--ink-2);
  line-height: 1.5;
}
.scope-picker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.scope-picker-col h4 {
  margin: 0 0 8px;
  padding-bottom: 4px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink);
  border-bottom: var(--border-soft);
}
.scope-picker label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
  font-family: var(--font-mono);
  font-size: 14px;
  cursor: pointer;
  color: var(--ink);
}
.scope-picker label input[type="checkbox"] {
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--accent);
}
.scope-picker label code {
  font-weight: 600;
  color: var(--ink);
  background: none;
  padding: 0;
}
.scope-picker .scope-hint {
  color: var(--ink-2);
  font-size: 13px;
}
.scope-picker-admin {
  margin-top: 12px;
  padding-top: 10px;
  border-top: var(--border-soft);
}
.scope-picker-admin label code {
  color: var(--bad);
}
.scope-picker-admin .scope-hint {
  color: var(--bad);
}
@media (max-width: 620px) {
  .scope-picker-grid { grid-template-columns: 1fr; }
}

/* --- Settings · MCP prompts editor ----------------------------------- */
.prose-editor {
  width: 100%;
  /* font-family inherits var(--font-mono) from the base textarea rule */
}
.prose-actions { margin-top: 10px; }
.prompt-preview {
  white-space: pre-wrap;
  max-height: 30rem;
  overflow: auto;
}
