:root {
  --paper: #f6f3ea;
  --paper-2: #fffdf7;
  --ink: #1f2328;
  --ink-2: #4a4f57;
  --ink-3: #8a8f98;
  --line: #e2ddcf;
  --dot: #d9d3c2;
  --accent: #b5462f;      /* priority / signifier red-ink */
  --accent-2: #2f6fb5;    /* events / links */
  --ok: #2f7d4f;
  --warn: #b7791f;
  --bad: #b5462f;
  --chip: #ece7da;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16181c;
    --paper-2: #1d2025;
    --ink: #e8e6e1;
    --ink-2: #b6b3ad;
    --ink-3: #7d8088;
    --line: #2c3037;
    --dot: #2a2d33;
    --accent: #e3735a;
    --accent-2: #6aa5e6;
    --ok: #5cb784;
    --warn: #e0a84a;
    --bad: #e3735a;
    --chip: #262a30;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html, body { overflow-x: hidden; }
body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  font: 14px/1.5 var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.2px);
  background-size: 18px 18px;
  display: flex;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- nav ---------- */
#nav {
  width: 210px; flex: none; height: 100vh; position: sticky; top: 0;
  background: var(--paper-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 10px 12px; overflow-y: auto;
}
.brand { font: 600 18px/1 var(--serif); padding: 0 10px 18px; letter-spacing: .2px; }
.brand-dot { color: var(--accent); }
#nav nav { display: flex; flex-direction: column; gap: 1px; }
#nav a {
  text-decoration: none; padding: 6px 10px; border-radius: 6px; color: var(--ink-2);
  display: flex; align-items: center; justify-content: space-between;
}
#nav a:hover { background: var(--chip); color: var(--ink); }
#nav a.active { background: var(--ink); color: var(--paper-2); }
.nav-h { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); padding: 14px 10px 4px; }
.badge { background: var(--accent); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center; }
.badge:empty, .count:empty { display: none; }
.count { font-size: 12px; color: var(--ink-3); }
#nav a.active .count { color: inherit; opacity: .7; }
.vault-path { margin-top: auto; font: 11px/1.3 var(--mono); color: var(--ink-3); padding: 10px; word-break: break-all; }

/* ---------- main ---------- */
main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#top {
  position: sticky; top: 0; z-index: 5; padding: 12px 24px;
  background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center;
}
#menu-btn { display: none; border: 0; background: none; font-size: 20px; cursor: pointer; }
#capture { flex: 1; min-width: 0; display: flex; gap: 8px; }
#capture input {
  flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper-2); font-family: var(--mono); font-size: 13px;
}
#capture input:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
#capture select, .btn, #capture button {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-2); cursor: pointer;
}
#capture button, .btn.primary { background: var(--ink); color: var(--paper-2); border-color: var(--ink); }
.btn:hover { border-color: var(--ink-3); }
.btn.small { padding: 2px 8px; font-size: 12px; border-radius: 6px; }
#view { padding: 22px 24px 60px; max-width: 1400px; width: 100%; }

#toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--paper-2); padding: 8px 14px; border-radius: 8px; font-size: 13px;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); color: #fff; }

h1 { font: 600 26px/1.2 var(--serif); margin: 0 0 4px; }
h2 { font: 600 17px/1.3 var(--serif); margin: 0; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 0 0 6px; font-weight: 600; }
.sub { color: var(--ink-3); margin: 0 0 18px; }
.muted { color: var(--ink-3); }
.mono { font-family: var(--mono); }

/* ---------- cards / grids ---------- */
.card {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow);
  min-width: 0;
}
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-h a { text-decoration: none; }
.card-h a:hover h2 { text-decoration: underline; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.auto { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
section + section, .block + .block { margin-top: 18px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(108px, 1fr)); gap: 10px; margin-bottom: 18px; }
.kpi { background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; text-decoration: none; display: block; }
.kpi:hover { border-color: var(--ink-3); }
.kpi .n { font: 600 24px/1.1 var(--serif); }
.kpi .l { font-size: 12px; color: var(--ink-3); }
.kpi.bad .n { color: var(--bad); }
.kpi.warn .n { color: var(--warn); }

/* ---------- BuJo entries ---------- */
.log { display: flex; flex-direction: column; }
.entry {
  display: grid; grid-template-columns: 18px 22px minmax(0, 1fr) auto; align-items: start;
  padding: 3px 4px; border-radius: 6px; position: relative;
}
.entry:hover { background: var(--chip); }
.entry .sig { font: 700 14px/22px var(--mono); color: var(--accent); text-align: center; }
.entry .glyph {
  font: 700 16px/22px var(--mono); border: 0; background: none; padding: 0; cursor: pointer; width: 22px; text-align: center; color: var(--ink);
}
.entry .glyph:hover { color: var(--accent); }
.entry .text { line-height: 22px; overflow-wrap: anywhere; }
.entry .text[contenteditable="true"] { outline: 1px solid var(--ink-3); border-radius: 4px; padding: 0 4px; background: var(--paper-2); }
.entry .meta { display: flex; gap: 4px; align-items: center; padding-left: 8px; line-height: 22px; }
.entry .acts { display: none; gap: 2px; }
.entry:hover .acts, .entry:focus-within .acts { display: flex; }
.entry .acts button {
  border: 1px solid var(--line); background: var(--paper-2); border-radius: 5px; width: 24px; height: 22px; padding: 0;
  font: 600 13px/1 var(--mono); cursor: pointer; color: var(--ink-2);
}
.entry .acts button:hover { border-color: var(--ink); color: var(--ink); }
.entry.b-done .text, .entry.b-migrated .text, .entry.b-scheduled .text { color: var(--ink-3); }
.entry.b-done .glyph, .entry.b-migrated .glyph, .entry.b-scheduled .glyph { color: var(--ink-3); }
.entry.b-irrelevant .text, .entry.b-irrelevant .glyph { text-decoration: line-through; color: var(--ink-3); }
.entry.b-event .glyph { color: var(--accent-2); }
.entry.b-note .glyph { color: var(--ink-3); }
.entry.b-note .text { color: var(--ink-2); font-style: italic; }
.entry.started .glyph { color: var(--warn); }
.entry.d1 { margin-left: 22px; } .entry.d2 { margin-left: 44px; } .entry.d3 { margin-left: 66px; }
.chip {
  display: inline-block; font-size: 11.5px; line-height: 18px; padding: 0 7px; border-radius: 9px; background: var(--chip); color: var(--ink-2);
  white-space: nowrap; text-decoration: none;
}
a.chip:hover { background: var(--ink); color: var(--paper-2); }
.chip.link { color: var(--accent-2); }
.chip.due { font-family: var(--mono); }
.chip.overdue { background: var(--bad); color: #fff; }
.chip.today { background: var(--warn); color: #fff; }
.chip.age { font-family: var(--mono); }
.empty { color: var(--ink-3); font-style: italic; padding: 6px 4px; }
.more { font-size: 12px; color: var(--ink-3); padding: 4px; text-decoration: none; display: block; }
.more:hover { color: var(--ink); }
.inline-add { margin-top: 6px; }
.inline-add input {
  width: 100%; border: 1px dashed var(--line); background: transparent; border-radius: 6px; padding: 4px 8px; font-family: var(--mono); font-size: 12.5px;
}
.inline-add input:focus { outline: none; border-style: solid; border-color: var(--ink-3); background: var(--paper-2); }

.group-h { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; }
.group-h:first-child { margin-top: 0; }
.group-h h3 { margin: 0; }

/* ---------- popover ---------- */
.popover {
  position: fixed; z-index: 40; background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,.15); padding: 4px; min-width: 200px; max-height: 60vh; overflow: auto;
}
.popover button, .popover .lbl {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 10px; border-radius: 5px; cursor: pointer;
}
.popover .lbl { cursor: default; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); padding-top: 8px; }
.popover button:hover { background: var(--chip); }
.popover .g { font-family: var(--mono); font-weight: 700; display: inline-block; width: 20px; }
.popover input { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); font-family: var(--mono); }
.popover .hint { font-size: 11px; color: var(--ink-3); padding: 4px 2px 6px; }

/* ---------- ventures / agents / ideas ---------- */
.venture .one { color: var(--ink-2); margin: -2px 0 10px; }
.metric { margin: 6px 0; }
.metric .lbl { display: flex; justify-content: space-between; font-size: 12.5px; }
.bar { height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar > i { display: block; height: 100%; background: var(--ink); border-radius: 3px; }
.gitline { font: 12px/1.5 var(--mono); color: var(--ink-3); margin: 8px 0; overflow-wrap: anywhere; }
.gitline b { color: var(--ink-2); font-weight: 600; }
.next { border-left: 3px solid var(--accent); padding: 4px 10px; margin: 10px 0 4px; font-size: 13px; background: var(--chip); border-radius: 0 6px 6px 0; }

.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: var(--chip); color: var(--ink-2); white-space: nowrap; }
.pill.running { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.waiting { background: color-mix(in srgb, var(--accent-2) 16%, transparent); color: var(--accent-2); }
.pill.blocked, .pill.stale { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.pill.review { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.pill.done { text-decoration: line-through; }

.agent { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.agent:first-child { border-top: 0; padding-top: 0; }
.agent .name { font-weight: 600; }
.agent .info { font-size: 12.5px; color: var(--ink-3); }
.agent .na { font-size: 13px; color: var(--ink-2); grid-column: 1 / -1; }
.agent.attention .name::before { content: "! "; color: var(--accent); font-family: var(--mono); }
.agent details { grid-column: 1 / -1; font-size: 12.5px; }
.agent details summary { cursor: pointer; color: var(--ink-3); }
.agent .loglines { font: 12px/1.6 var(--mono); color: var(--ink-2); margin: 6px 0; max-height: 220px; overflow: auto; }
.agent form { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.agent form input { flex: 1; min-width: 160px; }
input.field, select.field, textarea.field {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper);
}

.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(170px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.lane { background: color-mix(in srgb, var(--paper-2) 60%, transparent); border: 1px solid var(--line); border-radius: 10px; padding: 10px; min-height: 120px; }
.lane > h3 { display: flex; justify-content: space-between; }
.idea { background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-top: 8px; box-shadow: var(--shadow); }
.idea .t { font-weight: 600; }
.idea .o { font-size: 12.5px; color: var(--ink-2); margin: 2px 0 6px; }
.idea .ice { font: 11.5px var(--mono); color: var(--ink-3); }
.idea .nx { font-size: 12px; margin-top: 6px; color: var(--ink-2); }
.idea .row { margin-top: 8px; }
.pipeline { display: flex; gap: 6px; flex-wrap: wrap; }
.pipeline .stage { flex: 1; min-width: 64px; text-align: center; background: var(--chip); border-radius: 8px; padding: 8px 4px; text-decoration: none; }
.pipeline .stage .n { font: 600 20px/1 var(--serif); }
.pipeline .stage .l { font-size: 11.5px; color: var(--ink-3); }

.cal { font: 12.5px/1.8 var(--mono); }
.cal .d { display: grid; grid-template-columns: 52px 1fr; border-bottom: 1px dotted var(--line); }
.cal .d.today { color: var(--accent); font-weight: 700; }
.cal .d.we { color: var(--ink-3); }

.key-table { border-collapse: collapse; width: 100%; max-width: 640px; }
.key-table td, .key-table th { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.key-table .g { font: 700 18px var(--mono); width: 50px; text-align: center; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--chip); padding: 1px 5px; border-radius: 4px; }

form.add-form { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
form.add-form label { font-size: 12px; color: var(--ink-3); display: flex; flex-direction: column; gap: 3px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  body { display: block; }
  #nav { position: fixed; z-index: 30; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  #nav.open { transform: none; }
  #menu-btn { display: block; }
  #top { padding: 10px 16px; }
  #capture select { max-width: 110px; }
  #view { padding: 16px 16px 60px; }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  /* Phones: tap a task's text to reveal its actions (no hover on touch). */
  .entry .acts, .entry:hover .acts { display: none; }
  .entry.sel .acts { display: flex; }
  .entry.sel { background: var(--chip); }
  /* 16px inputs stop iOS from zooming the page on focus. */
  input, select, textarea, #capture input { font-size: 16px; }
  #capture button { padding: 8px 12px; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 8px 10px; }
  .kpi .n { font-size: 20px; }
  .card { padding-left: 14px; padding-right: 14px; }
  .dash-view { height: calc(100dvh - 90px); }
  #dash-frame { min-height: 0; }
  .dash-head h1 { font-size: 22px; }
  /* Popover menus sized for thumbs. */
  .popover { max-width: calc(100vw - 24px); }
  .popover button { min-height: 40px; }
  .entry { grid-template-columns: 16px 20px minmax(0, 1fr); }
  .entry .meta { grid-column: 3; padding-left: 0; flex-wrap: wrap; }
}

/* venture's own dashboard */
.dashbox { border: 1px solid var(--line, var(--ink-4, #ccc)); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.dashbox.down { border-style: dashed; }
a.btn.dash { text-decoration: none; display: inline-flex; gap: 4px; align-items: center; }
a.btn.dash.up { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
a.btn.dash.down { color: var(--ink-3); }
.attn { font-size: 12px; margin: 6px 0; display: grid; gap: 2px; }
.attn .warn { color: var(--warn); }
.attn .bad { color: var(--bad); font-weight: 600; }

.dash-view { display: flex; flex-direction: column; gap: 10px; height: calc(100vh - 120px); }
.dash-head { flex-wrap: wrap; gap: 8px; }
#dash-frame { flex: 1; width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-height: 480px; }
#nav .dot.up { color: var(--ok); }
#nav .dot.down { color: var(--ink-3); }
#nav-dash a { justify-content: flex-start; gap: 8px; }

/* hosted mode */
body.scoped .full-only { display: none; }
.account { font-size: 12px; color: var(--ink-3); padding: 8px 10px 0; overflow-wrap: anywhere; }
.sync-banner { background: color-mix(in srgb, var(--warn) 18%, var(--paper-2)); color: var(--ink); font-size: 13px; padding: 8px 24px; border-bottom: 1px solid var(--line); }
