/* ── Homeward Wise · operations console ───────────────────────
   Deliberate single visual world: a dark control room.
   Every colour painted explicitly so it holds on any host ground. */

:root {
  color-scheme: dark;

  --bg:        #0b100f;
  --panel:     #121a19;
  --panel-2:   #182220;
  --panel-3:   #1e2a28;
  --line:      #24322f;
  --line-2:    #354744;

  --ink:       #e9f1ef;
  --ink-2:     #93a5a1;
  --ink-3:     #5f716e;

  --accent:    #3ad6c4;
  --accent-dim:#1b4a45;
  --accent-ink:#08201e;

  --data:      #4a95e8;
  --data-dim:  #16304d;

  --good:      #52c777;
  --warn:      #eba43c;
  --crit:      #f0605f;
  --crit-dim:  #3c1f1f;

  --r: 6px;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Archivo", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-dim); color: var(--ink); }

button, textarea, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; border: 2px solid var(--bg); }

/* ── shell ─────────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: 246px minmax(0, 1fr);
  min-height: 100vh;
}

.nav {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.15rem .85rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: .6rem; padding: 0 .35rem; }
.brand__mark { color: var(--accent); display: flex; }
.brand__txt { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand__txt strong { font-size: .95rem; font-weight: 700; letter-spacing: -.01em; }
.brand__txt span { font-size: .66rem; color: var(--ink-3); font-family: var(--mono); letter-spacing: .02em; }

.nav__list { display: flex; flex-direction: column; gap: 1px; flex: 1; }

.navitem {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .6rem;
  border-radius: var(--r);
  background: none; border: 0;
  color: var(--ink-2);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background .12s, color .12s;
}
.navitem:hover { background: var(--panel-2); color: var(--ink); }
.navitem[aria-current="true"] { background: var(--panel-3); color: var(--ink); }
.navitem[aria-current="true"] .navitem__ic { color: var(--accent); }
.navitem__ic { width: 1.1rem; text-align: center; color: var(--ink-3); font-size: .95rem; flex: none; }
.navitem__tx { font-size: .84rem; font-weight: 500; }
.navitem__n {
  margin-left: auto; font-family: var(--mono); font-size: .65rem;
  color: var(--ink-3); background: var(--panel-3); padding: .05rem .3rem; border-radius: 3px;
}

.nav__foot { display: flex; flex-direction: column; gap: .7rem; }

.tenant { display: flex; flex-direction: column; padding: .6rem; background: var(--panel-2); border-radius: var(--r); border: 1px solid var(--line); }
.tenant__k { font-family: var(--mono); font-size: .6rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); }
.tenant__v { font-size: .82rem; font-weight: 600; }

.livebox { display: flex; gap: .5rem; align-items: flex-start; padding: .55rem .6rem; border: 1px solid var(--accent-dim); background: #10201e; border-radius: var(--r); }
.livebox b { display: block; font-family: var(--mono); font-size: .68rem; color: var(--accent); font-weight: 500; word-break: break-all; }
.livebox span { font-size: .64rem; color: var(--ink-3); font-family: var(--mono); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-top: .35rem; flex: none; box-shadow: 0 0 0 0 rgba(58,214,196,.6); animation: pulse 2.4s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(58,214,196,0); } 100% { box-shadow: 0 0 0 0 rgba(58,214,196,0); } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }

.demoflag { margin: 0; font-family: var(--mono); font-size: .6rem; color: var(--ink-3); text-align: center; letter-spacing: .04em; }

/* ── main ──────────────────────────────────────────────────── */

.main { padding: 1.6rem clamp(1rem, 2.6vw, 2.2rem) 4rem; min-width: 0; }
.boot { color: var(--ink-3); font-family: var(--mono); padding: 4rem 0; text-align: center; }

.screenhead { margin-bottom: 1.4rem; }
.screenhead h1 {
  margin: 0 0 .25rem;
  font-size: clamp(1.3rem, 2.6vw, 1.7rem);
  font-weight: 700; letter-spacing: -.02em;
}
.screenhead p { margin: 0; color: var(--ink-2); max-width: 76ch; font-size: .88rem; }

.eyebrow {
  font-family: var(--mono); font-size: .64rem; letter-spacing: .14em;
  text-transform: uppercase; color: var(--accent); margin: 0 0 .4rem;
}

/* ── generic panel ─────────────────────────────────────────── */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 1rem 1.1rem;
  min-width: 0;
}
.panel__head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .85rem; }
.panel__title { font-size: .8rem; font-weight: 600; letter-spacing: .01em; margin: 0; }
.panel__sub { font-family: var(--mono); font-size: .63rem; color: var(--ink-3); }

.grid { display: grid; gap: .85rem; }
.grid--kpi { grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(21rem, 1fr)); }
.mb { margin-bottom: .85rem; }

/* ── kpi tiles ─────────────────────────────────────────────── */

.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: .8rem .9rem; }
.kpi__k { font-family: var(--mono); font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); display: block; margin-bottom: .3rem; }
.kpi__v { font-family: var(--mono); font-size: 1.6rem; font-weight: 600; letter-spacing: -.02em; display: block; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi__n { font-size: .68rem; color: var(--ink-3); display: block; margin-top: .2rem; }
.kpi--crit .kpi__v { color: var(--crit); }
.kpi--warn .kpi__v { color: var(--warn); }
.kpi--good .kpi__v { color: var(--good); }
.kpi--accent .kpi__v { color: var(--accent); }

/* ── funnel ────────────────────────────────────────────────── */

.fun { display: flex; flex-direction: column; gap: .3rem; }
.funrow { display: grid; grid-template-columns: minmax(8rem, 12rem) minmax(0,1fr) auto auto; gap: .75rem; align-items: center; }
.funrow__l { font-size: .78rem; color: var(--ink-2); }
.funrow__t { position: relative; height: 1.45rem; background: var(--panel-3); border-radius: 3px; overflow: hidden; }
.funrow__f { height: 100%; background: var(--data); border-radius: 3px; transition: width .7s cubic-bezier(.2,.8,.3,1); }
.funrow--last .funrow__f { background: var(--crit); }
.funrow__v { font-family: var(--mono); font-size: .78rem; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 3.4rem; text-align: right; }
.funrow__d { font-family: var(--mono); font-size: .68rem; color: var(--ink-3); min-width: 3.6rem; text-align: right; font-variant-numeric: tabular-nums; }
.funrow--last .funrow__d { color: var(--crit); }
@media (prefers-reduced-motion: reduce) { .funrow__f { transition: none; } }

.leak {
  margin-top: .9rem; padding: .75rem .85rem;
  border: 1px solid var(--crit-dim); background: #1a1211; border-radius: var(--r);
  font-size: .82rem;
}
.leak b { color: var(--crit); }
.cite { font-family: var(--mono); font-size: .63rem; color: var(--ink-3); margin-top: .5rem; display: block; }

/* ── county cartogram ──────────────────────────────────────── */

.cartowrap { overflow-x: auto; padding-bottom: .4rem; }
.carto { display: grid; gap: 4px; grid-auto-flow: row; min-width: 44rem; }
.tile {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .4rem .45rem;
  background: var(--panel-2);
  cursor: pointer;
  text-align: left;
  min-height: 3.9rem;
  display: flex; flex-direction: column; justify-content: space-between;
  transition: transform .12s, border-color .12s;
}
.tile:hover { transform: translateY(-2px); border-color: var(--line-2); }
.tile[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tile__n { font-size: .68rem; font-weight: 600; line-height: 1.15; }
.tile__g { font-family: var(--mono); font-size: .82rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile__pip { font-family: var(--mono); font-size: .52rem; color: var(--accent); letter-spacing: .06em; }

.legend { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .8rem; font-family: var(--mono); font-size: .63rem; color: var(--ink-3); }
.legend__sw { display: flex; gap: 2px; }
.legend__sw i { width: 1.5rem; height: .55rem; border-radius: 2px; display: block; }

/* ── table ─────────────────────────────────────────────────── */

.tablewrap { overflow-x: auto; }
table.dt { width: 100%; border-collapse: collapse; font-size: .8rem; min-width: 34rem; }
table.dt th {
  text-align: left; font-family: var(--mono); font-size: .62rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3); font-weight: 500;
  border-bottom: 1px solid var(--line-2); padding: .4rem .7rem .4rem 0; white-space: nowrap;
}
table.dt td { padding: .5rem .7rem .5rem 0; border-bottom: 1px solid var(--line); color: var(--ink-2); vertical-align: top; }
table.dt tbody tr:hover td { background: var(--panel-2); }
table.dt td.n { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
table.dt td.name { color: var(--ink); font-weight: 500; }
table.dt tbody tr:last-child td { border-bottom: 0; }

.pill {
  display: inline-block; font-family: var(--mono); font-size: .6rem; font-weight: 500;
  letter-spacing: .05em; text-transform: uppercase; padding: .12rem .4rem; border-radius: 3px; white-space: nowrap;
}
.pill--active { background: #123024; color: var(--good); }
.pill--idle   { background: #33260f; color: var(--warn); }
.pill--dormant{ background: var(--crit-dim); color: var(--crit); }
.pill--pip    { background: var(--accent-dim); color: var(--accent); }
.pill--tag    { background: var(--panel-3); color: var(--ink-2); }

/* ── filters ───────────────────────────────────────────────── */

.filters { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-bottom: .9rem; }
.chip {
  font-family: var(--mono); font-size: .68rem;
  padding: .28rem .6rem; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--ink-2);
  cursor: pointer; transition: .12s;
}
.chip:hover { color: var(--ink); border-color: var(--ink-3); }
.chip[aria-pressed="true"] { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.filters__sp { flex: 1; }

/* ── buttons ───────────────────────────────────────────────── */

.btn {
  font-family: var(--sans); font-size: .8rem; font-weight: 600;
  padding: .48rem .9rem; border-radius: var(--r); cursor: pointer;
  border: 1px solid transparent; transition: .12s; white-space: nowrap;
}
.btn--go { background: var(--accent); color: var(--accent-ink); }
.btn--go:hover { filter: brightness(1.1); }
.btn--go:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn--ghost { background: transparent; border-color: var(--line-2); color: var(--ink-2); }
.btn--ghost:hover { color: var(--ink); border-color: var(--ink-3); }
.btn--sm { font-size: .72rem; padding: .32rem .65rem; }

.iconbtn {
  background: none; border: 1px solid var(--line-2); color: var(--ink-2);
  width: 1.9rem; height: 1.9rem; border-radius: var(--r); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.iconbtn:hover { color: var(--ink); border-color: var(--ink-3); }
.iconbtn--sm { width: 1.5rem; height: 1.5rem; font-size: .7rem; }

/* ── agent cards ───────────────────────────────────────────── */

.groupsec { margin-bottom: 1.6rem; }
.groupsec__h { display: flex; align-items: baseline; gap: .6rem; margin-bottom: .7rem; padding-bottom: .4rem; border-bottom: 1px solid var(--line); }
.groupsec__h h2 { margin: 0; font-size: .95rem; font-weight: 700; letter-spacing: -.01em; }
.groupsec__h p { margin: 0; font-size: .76rem; color: var(--ink-3); }

.acards { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr)); }

.acard {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: .85rem .9rem; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: .35rem;
  transition: border-color .12s, transform .12s, background .12s;
}
.acard:hover { border-color: var(--accent); transform: translateY(-2px); background: var(--panel-2); }
.acard__top { display: flex; align-items: center; gap: .5rem; }
.acard__ic {
  width: 1.7rem; height: 1.7rem; border-radius: 5px; flex: none;
  background: var(--accent-dim); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: .85rem;
}
.acard__nm { font-size: .85rem; font-weight: 600; letter-spacing: -.005em; }
.acard__bl { font-size: .76rem; color: var(--ink-2); margin: 0; }
.acard__sv { font-family: var(--mono); font-size: .62rem; color: var(--ink-3); margin-top: auto; padding-top: .25rem; }

/* ── drawer ────────────────────────────────────────────────── */

.drawer { position: fixed; inset: 0; z-index: 60; display: flex; justify-content: flex-end; }
.drawer[hidden] { display: none; }
.drawer__scrim { position: absolute; inset: 0; background: rgba(4,8,7,.72); backdrop-filter: blur(2px); }
.drawer__panel {
  position: relative; width: min(46rem, 100%);
  background: var(--bg); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; height: 100%;
  animation: slide .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes slide { from { transform: translateX(24px); opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .drawer__panel { animation: none; } }

.drawer__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); background: var(--panel);
}
.drawer__id { display: flex; gap: .7rem; align-items: flex-start; min-width: 0; }
.drawer__icon {
  width: 2rem; height: 2rem; border-radius: 6px; flex: none;
  background: var(--accent-dim); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.drawer__head h2 { margin: 0; font-size: 1rem; font-weight: 700; letter-spacing: -.01em; }
.drawer__head p { margin: 0; font-size: .78rem; color: var(--ink-2); }

/* min-height:0 is load-bearing: without it a flex item defaults to min-height:auto,
   grows to fit its content, and overflow-y never engages. */
.drawer__body {
  padding: 1.1rem 1.2rem 2.5rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: .9rem;
}

/* the head must not shrink, or it gets squeezed as output grows */
.drawer__head { flex: none; }

/* direct children keep their natural height so the body scrolls, not them */
.drawer__body > * { flex: none; }

.field { display: flex; flex-direction: column; gap: .35rem; }
.field__lab { font-family: var(--mono); font-size: .63rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
textarea {
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r);
  padding: .7rem .8rem; resize: vertical; min-height: 7rem;
  font-family: var(--mono); font-size: .76rem; line-height: 1.6; color: var(--ink);
}
textarea:focus { border-color: var(--accent); outline: none; }

.drawer__actions { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.runmeta { font-family: var(--mono); font-size: .66rem; color: var(--ink-3); margin-left: auto; text-align: right; }

.output { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); overflow: hidden; }
.output__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .45rem .7rem; border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: .63rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
}
.output__body { padding: .9rem 1rem; font-size: .84rem; }

/* rendered markdown */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { font-size: .9rem; font-weight: 700; margin: 1.1rem 0 .4rem; letter-spacing: -.005em; color: var(--ink); }
.md h1 { font-size: 1rem; }
.md p { margin: 0 0 .7rem; color: var(--ink-2); }
.md strong { color: var(--ink); font-weight: 600; }
.md em { color: var(--ink-2); }
.md ul, .md ol { margin: 0 0 .7rem; padding-left: 1.15rem; color: var(--ink-2); }
.md li { margin-bottom: .25rem; }
.md li::marker { color: var(--accent); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: .9rem 0; }
.md code { font-family: var(--mono); font-size: .78em; background: var(--panel-3); padding: .08rem .3rem; border-radius: 3px; color: var(--accent); }
.md blockquote { margin: 0 0 .7rem; padding-left: .8rem; border-left: 2px solid var(--line-2); color: var(--ink-3); }
.md table { width: 100%; border-collapse: collapse; font-size: .76rem; margin: 0 0 .8rem; }
.md th { text-align: left; font-family: var(--mono); font-size: .6rem; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); border-bottom: 1px solid var(--line-2); padding: .35rem .55rem .35rem 0; font-weight: 500; }
.md td { padding: .4rem .55rem .4rem 0; border-bottom: 1px solid var(--line); color: var(--ink-2); vertical-align: top; }
.md .tblwrap { overflow-x: auto; }

.cursor { display: inline-block; width: .5rem; height: .9rem; background: var(--accent); vertical-align: text-bottom; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor { animation: none; } }

.errbox { border: 1px solid var(--crit-dim); background: #1a1211; color: var(--crit); padding: .7rem .85rem; border-radius: var(--r); font-size: .8rem; }

/* ── feed ──────────────────────────────────────────────────── */

.feed { display: flex; flex-direction: column; gap: .5rem; }
.feeditem { display: flex; gap: .6rem; align-items: flex-start; padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
.feeditem:last-child { border-bottom: 0; padding-bottom: 0; }
.feeditem__ic { width: 1.4rem; height: 1.4rem; border-radius: 4px; background: var(--panel-3); color: var(--ink-2); display: flex; align-items: center; justify-content: center; font-size: .7rem; flex: none; }
.feeditem__b { min-width: 0; }
.feeditem__t { font-size: .78rem; color: var(--ink); }
.feeditem__m { font-family: var(--mono); font-size: .63rem; color: var(--ink-3); }

/* ── child cards ───────────────────────────────────────────── */

.kids { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); }
.kid { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: .85rem .9rem; display: flex; flex-direction: column; gap: .45rem; }
.kid__h { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.kid__id { font-family: var(--mono); font-size: .82rem; font-weight: 600; }
.kid__w { font-family: var(--mono); font-size: .64rem; color: var(--warn); }
.kid__m { font-size: .74rem; color: var(--ink-2); }
.kid__tags { display: flex; gap: .25rem; flex-wrap: wrap; }

.note { font-size: .74rem; color: var(--ink-3); font-family: var(--mono); }

/* ── responsive ────────────────────────────────────────────── */

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0,1fr); }
  .nav { position: static; height: auto; flex-direction: column; }
  .nav__list { flex-direction: row; flex-wrap: wrap; }
  .navitem { width: auto; }
  .navitem__n { display: none; }
  .funrow { grid-template-columns: minmax(0,1fr) auto; }
  .funrow__t { grid-column: 1 / -1; order: 3; }
  .funrow__d { order: 2; }
}
