/* homebox console. Tokens: tokens.css (see DESIGN.md). Whose view you are in is the
   one idea: each person has an ink, shared things are household green. */

:root {
  /* Colours, type, space and radii live in tokens.css. These are console-only. */
  --serif: "Iowan Old Style", "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --r-key: 14px; --r-item: 6px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 var(--step-0)/1.5 var(--sans); font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--me); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- shell: one sidebar (navigation, chats, account), then the page ---------- */
.shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px;
  padding: var(--s3) var(--s2); background: var(--paper); border-right: 1px solid var(--line); overflow: hidden;
}
.rail-top { display: flex; align-items: center; justify-content: space-between; padding: var(--s2) var(--s3) var(--s3); }
.mark { display: flex; align-items: center; gap: var(--s2); text-decoration: none; font-weight: 600; font-size: var(--step-1); letter-spacing: -0.01em; }
.mark svg { width: 22px; height: 22px; color: var(--ink); }
.rail svg { width: 16px; height: 16px; flex: none; }

.rail-new, .nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px var(--s3); border-radius: var(--r-ctl);
  text-decoration: none; color: var(--ink-2); font-size: var(--step-0);
}
.rail-new { color: var(--ink); font-weight: 500; margin-bottom: var(--s2); }
.rail-new:hover, .nav a:hover { color: var(--ink); background: var(--sunk); }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a[aria-current="page"] { color: var(--ink); background: var(--sunk); font-weight: 600; }
.badge { margin-left: auto; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--me); color: var(--surface); font-size: 11px; font-weight: 600; text-align: center; line-height: 18px; }

.rail-drawer { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 2px; }
.rail-chats { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: var(--s4); }
.rail-menu { display: none; width: 36px; height: 36px; place-items: center; border: 0; border-radius: var(--r-ctl); background: none; color: var(--ink); cursor: pointer; }
.rail-menu:hover { background: var(--sunk); }

.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--shared); flex: none; opacity: .8; }
.pulse.off { background: var(--danger); }
.pulse.busy { background: var(--budget); animation: hb-breathe 2.4s ease-in-out infinite; }
@keyframes hb-breathe { 50% { opacity: .35; } }

.account { position: relative; padding-top: var(--s2); border-top: 1px solid var(--line); }
.account-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px var(--s2); border: 0; border-radius: var(--r-ctl); background: none; cursor: pointer; text-align: left; color: var(--ink); }
.account-btn:hover, .account-btn[aria-expanded="true"] { background: var(--sunk); }
.account-btn svg { margin-left: auto; color: var(--ink-3); }
.account-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.key-dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--k); color: var(--surface); font-weight: 600; font-size: 13px; }
.account-menu {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); padding: 6px; display: grid; gap: 2px; z-index: 10;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-ctl); box-shadow: var(--lift);
}
.account-menu button, .account-menu a { display: flex; align-items: center; gap: 10px; padding: 6px var(--s2); border: 0; border-radius: var(--r-chip); background: none; color: var(--ink); text-decoration: none; cursor: pointer; text-align: left; font-size: var(--step-0); }
.account-menu .key-dot { width: 22px; height: 22px; font-size: 11px; }
.account-menu svg { width: 16px; height: 16px; margin: 0 3px; color: var(--ink-3); }
.account-menu button:hover, .account-menu a:hover { background: var(--sunk); }

.main { padding: var(--s6) var(--s7) var(--s8); min-width: 0; outline: none; }
.view { max-width: 760px; }
.view.wide { max-width: 1040px; }
.view.chat { max-width: none; height: 100vh; }
.main:has(.view.chat) { padding: 0; }
.main:has(.home.brief) { padding-bottom: var(--s4); }
h1 { font-family: var(--display); font-size: var(--step-3); line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 var(--s2); font-weight: 600; }
h2 { font-size: var(--step-1); margin: 0 0 var(--s3); font-weight: 600; letter-spacing: -0.005em; }
.lede { color: var(--ink-2); margin: 0 0 var(--s6); max-width: 62ch; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); padding: 9px 16px; border-radius: var(--r-ctl);
  border: 1px solid var(--ink); background: var(--ink); color: var(--surface); font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.me { background: var(--me); border-color: var(--me); }
.btn.quiet, .ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.quiet:hover, .ghost:hover { background: var(--surface); }
.ghost { padding: 6px 12px; border-radius: var(--r-ctl); cursor: pointer; }
.field { display: grid; gap: var(--s1); margin-bottom: var(--s4); }
.field label { font-weight: 600; font-size: var(--step--1); }
.field .hint { font-size: var(--step--1); color: var(--ink-3); }
input[type=text], input[type=password], input[type=datetime-local], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--surface);
}

/* ---------- Ask ---------- */

.answer { font-size: var(--step-1); line-height: 1.62; max-width: 66ch; }
.answer p { margin: 0 0 var(--s3); }
.answer strong { font-weight: 700; }
.answer ul { margin: 0 0 var(--s3); padding-left: 1.2em; }
.cite {
  font-family: var(--sans); font-size: 0.72em; font-weight: 600; vertical-align: 0.25em; line-height: 1;
  padding: 2px 6px; margin: 0 1px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-2); cursor: pointer;
}
.cite:hover { border-color: var(--me); color: var(--me); }
.cite.shared { color: var(--shared); }
.gaps { margin: var(--s3) 0 0; display: grid; gap: var(--s2); }
.gap { font-size: var(--step--1); color: var(--ink-2); padding: var(--s2) var(--s3); background: var(--sunk); border-radius: var(--r-item); max-width: 66ch; }
.gap.locked {
  display: flex; gap: var(--s3); align-items: center; color: var(--ink);
  background: var(--sunk);
}
.gap.locked svg { width: 16px; height: 16px; flex: none; }
.sources { margin-top: var(--s3); display: flex; flex-wrap: wrap; gap: var(--s2); }
.src-chip {
  display: inline-flex; align-items: center; gap: var(--s2); max-width: 100%; padding: 6px 10px; border-radius: var(--r-item);
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: var(--step--1); text-align: left;
}
.src-chip:hover { border-color: var(--ink-3); }
.src-chip .ref { font-weight: 700; color: var(--ink-3); }
.src-chip .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34ch; }


/* ---------- Feed ---------- */
.budget { display: flex; align-items: center; gap: var(--s5); flex-wrap: wrap; padding: var(--s4) 0 var(--s5); margin-bottom: var(--s5); border-bottom: 1px solid var(--line); }
.meter { display: flex; gap: 6px; }
.meter i { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--budget); }
.meter i.used { background: var(--budget); }
.budget .what { font-weight: 600; }
.budget .why { color: var(--ink-3); font-size: var(--step--1); }
.band { margin-bottom: var(--s7); }
.band > h2 { display: flex; align-items: baseline; gap: var(--s3); }
.band > h2 small { font-weight: 400; color: var(--ink-3); font-size: var(--step--1); }
.cards { display: grid; gap: var(--s3); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-item); padding: var(--s4) var(--s5); }
.card.confirm { background: var(--me-wash); border-color: transparent; }
.card.push .when::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--budget); margin-right: 8px; vertical-align: 1px; }
.card h3 { margin: 0 0 var(--s1); font-size: var(--step-1); line-height: 1.3; }
.card .body { font-family: var(--serif); color: var(--ink); margin: 0 0 var(--s3); white-space: pre-line; max-width: 68ch; }
.card .foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--s3); }
.card .when { font-size: var(--step--1); color: var(--ink-3); }
.card .actions { display: flex; gap: var(--s2); flex-wrap: wrap; }
.fb[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.empty { color: var(--ink-3); }

/* ---------- Sources ---------- */
/* Box status: one quiet line of facts, not a row of metric cards. */
.models { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); margin-bottom: var(--s6); padding-bottom: var(--s4); border-bottom: 1px solid var(--line); }
.stat { display: flex; align-items: baseline; gap: 6px; }
.stat .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--ink-3); font-size: var(--step--1); }
.srcs { width: 100%; border-collapse: collapse; margin-bottom: var(--s7); font-variant-numeric: tabular-nums; }
.srcs th { text-align: left; font-size: var(--step--1); font-weight: 600; color: var(--ink-3); padding: var(--s2) var(--s3) var(--s2) 0; border-bottom: 1px solid var(--line); }
.srcs td { padding: var(--s3) var(--s3) var(--s3) 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.bar { height: 6px; background: var(--sunk); border-radius: 3px; overflow: hidden; min-width: 120px; }
.bar > span { display: block; height: 100%; background: var(--me); }
tr:has(.whose[style*="--shared"]) .bar > span { background: var(--shared); }
.whose { display: inline-flex; align-items: center; gap: 6px; font-size: var(--step--1); }
.whose i { width: 10px; height: 10px; border-radius: 50%; background: var(--k, var(--shared)); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-item); padding: var(--s5); margin-bottom: var(--s6); }
.panel p { max-width: 64ch; }
.steps-list { margin: 0 0 var(--s4); padding-left: 1.3em; display: grid; gap: var(--s2); }
.mapping { display: grid; grid-template-columns: max-content 1fr; gap: var(--s2) var(--s4); margin: var(--s3) 0 var(--s4); }
.mapping dt { color: var(--ink-3); font-size: var(--step--1); }
.mapping dd { margin: 0; font-weight: 600; }
.drop { display: grid; place-items: center; gap: var(--s2); padding: var(--s6); border: 2px dashed var(--line); border-radius: var(--r-item); text-align: center; color: var(--ink-2); cursor: pointer; }
.drop:hover, .drop.over { border-color: var(--me); color: var(--me); }
.code { font-size: var(--step-4); font-weight: 600; letter-spacing: 0.18em; font-variant-numeric: tabular-nums; }
.inline-form { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: end; }
.inline-form .field { margin: 0; flex: 1 1 200px; }

/* ---------- An item's own page (a source opened from chat, Home or a project) ---------- */
.item-page { max-width: 760px; }
.item-page h1 { font-size: var(--step-2); line-height: 1.25; margin: 0 0 var(--s2); }
.item-kind { font-size: var(--step--1); color: var(--ink-3); margin: var(--s4) 0 var(--s1); }
.item-page img { max-width: 100%; border: 1px solid var(--line); border-radius: var(--r-item); }
.item-page .scope-tag { margin-bottom: var(--s4); }
.back-link { display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px 6px 6px; margin-left: -6px; border: 0; border-radius: 8px;
  background: none; color: var(--ink-2); font: inherit; font-size: var(--step--1); cursor: pointer; }
.back-link::before { content: ""; width: 7px; height: 7px; border-left: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor; transform: rotate(45deg); margin-right: 4px; }
.back-link:hover { color: var(--ink); background: var(--sunk); }
/* Arriving at an entry, record or reminder: a short wash in the person's colour. */
.route-flash { background-color: var(--me-wash) !important; transition: background-color .6s ease; }
[data-route-target] { scroll-margin: 96px; }
.mm-src { color: inherit; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.mm-src:hover { color: var(--ink); text-decoration-color: currentColor; }
.headers { display: grid; grid-template-columns: max-content 1fr; gap: 2px var(--s3); font-size: var(--step--1); margin: 0 0 var(--s4); }
.headers dt { color: var(--ink-3); }
.headers dd { margin: 0; word-break: break-word; }
.doc { white-space: pre-wrap; line-height: 1.6; }
.doc mark { background: var(--me-wash); color: var(--ink); }
.drawer-body img { max-width: 100%; border: 1px solid var(--line); border-radius: var(--r-item); }
.drawer-body .scope-tag { margin-bottom: var(--s4); }
.scope-tag { display: inline-flex; align-items: center; gap: 6px; font-size: var(--step--1); padding: 2px 10px; border-radius: 999px; background: var(--sunk); }
.scope-tag i { width: 8px; height: 8px; border-radius: 50%; background: var(--k, var(--shared)); }

.toast { position: fixed; bottom: var(--s5); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 18px; border-radius: var(--r-ctl); z-index: 30; max-width: 90vw; }

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  /* Phone width: a compact top bar; navigation and chats slide over from the left. */
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .rail { position: sticky; top: 0; z-index: 25; height: auto; flex-direction: row; align-items: center; gap: var(--s1); padding: 6px var(--s2); border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .rail-top { flex: 1; gap: var(--s1); justify-content: flex-start; padding: 0; }
  .rail-menu { display: grid; }
  .rail-new { margin: 0; padding: 8px; }
  .rail-new .lbl { display: none; }
  .account { border: 0; padding: 0; }
  .account-btn { padding: 4px; }
  .account-name, .account-btn > svg { display: none; }
  .account-menu { left: auto; right: 0; bottom: auto; top: calc(100% + 6px); min-width: 200px; }
  .rail-drawer {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(300px, 86vw); z-index: 30;
    padding: var(--s4) var(--s2); background: var(--paper); box-shadow: var(--lift); border-right: 1px solid var(--line);
    transform: translateX(-105%); transition: transform .22s ease-out; visibility: hidden;
  }
  body.rail-open .rail-drawer { transform: none; visibility: visible; }
  body.rail-open::after { content: ""; position: fixed; inset: 0; background: rgb(0 0 0 / .25); z-index: 24; } /* below the bar (25), whose drawer sits on top */
  .main { padding: var(--s5) var(--s4) var(--s7); }
  .main:has(.view.chat) { padding: 0; }
  .view.chat { height: calc(100vh - 49px); }
}
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.pairing { display: flex; gap: var(--s5); align-items: center; flex-wrap: wrap; }
.qr svg { display: block; background: #fff; border-radius: var(--r-item); border: 1px solid var(--line); filter: none; color-scheme: light; }
.demo-banner { margin: calc(-1 * var(--s6)) calc(-1 * var(--s7)) var(--s5); padding: 10px var(--s7); background: var(--me-wash); color: var(--ink); font-size: var(--step--1); border-bottom: 1px solid var(--line); }
.demo-banner a { font-weight: 600; }
.map-form { padding: var(--s4) 0; border-top: 1px solid var(--line); margin-bottom: var(--s4); }
.map-done { margin-bottom: var(--s3); font-size: var(--step--1); color: var(--ink-2); }
.map-done summary { cursor: pointer; }

.lists { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.list-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); margin-bottom: var(--s2); }
.entries { list-style: none; margin: 0 0 var(--s3); padding: 0; display: grid; gap: 2px; }
.entries li { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); padding: 4px 0; border-bottom: 1px solid var(--sunk); font-family: var(--serif); }
.entries label { display: flex; gap: var(--s2); align-items: center; cursor: pointer; }
.entries .done { text-decoration: line-through; color: var(--ink-3); }
.entries .x { border: 0; background: none; color: var(--ink-3); font-size: 18px; cursor: pointer; padding: 0 6px; }
.note-body { font-family: var(--serif); }
details.panel > summary { cursor: pointer; list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }
@media (max-width: 820px) { .demo-banner { margin: calc(-1 * var(--s5)) calc(-1 * var(--s4)) var(--s4); padding: 10px var(--s4); } }

.pair-requests { position: fixed; right: var(--s5); bottom: var(--s5); z-index: 40; display: grid; gap: var(--s2); max-width: 420px; }
.pair-request { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-item); padding: var(--s4); box-shadow: 0 8px 24px rgba(0,0,0,.18); display: grid; gap: var(--s2); }
.pair-request p { margin: 0; }
.pair-request-actions { display: flex; gap: var(--s2); }

/* ⓘ: how-this-works text, out of the main flow until asked for (click, or hover for the title). */
details.info { display: inline-block; position: relative; vertical-align: middle; font-size: var(--step--1); font-weight: 400; }
details.info > summary { list-style: none; cursor: pointer; color: var(--ink-3); display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; }
details.info > summary::-webkit-details-marker { display: none; }
details.info > summary:hover, details.info[open] > summary { color: var(--ink); background: var(--sunk); }
details.info > summary:focus-visible { outline: 2px solid var(--me); outline-offset: 2px; }
details.info > p { position: absolute; z-index: 20; top: 26px; left: -8px; width: min(340px, 80vw); margin: 0; padding: var(--s3) var(--s4);
  background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); border-radius: var(--r-ctl); box-shadow: var(--lift); line-height: 1.45; }
details.more-settings > summary { cursor: pointer; color: var(--ink-2); font-weight: 600; }

/* Settings: one row per panel with its gist; it opens in place. */
details.set-row { padding: 0; margin-bottom: var(--s2); }
details.set-row > summary { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s5); cursor: pointer; list-style: none; }
details.set-row > summary::-webkit-details-marker { display: none; }
details.set-row > summary::after { content: "›"; margin-left: var(--s2); color: var(--ink-3); transition: transform .12s; }
details.set-row[open] > summary::after { transform: rotate(90deg); }
details.set-row > summary:hover { background: var(--sunk); border-radius: var(--r-item, 16px); }
.set-title { font-weight: 600; }
.set-gist { margin-left: auto; color: var(--ink-3); font-size: var(--step--1); }
details.set-row[open] { padding-bottom: var(--s5); }
details.set-row[open] > :not(summary) { margin-left: var(--s5); margin-right: var(--s5); }
.set-gist { white-space: nowrap; } .set-help { margin: 0 0 var(--s3); }

/* Sign in, away from the Mac: just the code and one button. */
.signin-page .rail { display: none; }
.signin { position: fixed; inset: 0; margin: auto; width: min(22rem, calc(100% - 2 * var(--s4))); height: max-content; display: grid; gap: var(--s3); }
.signin-form { display: flex; gap: var(--s2); }
.signin-form input { flex: 1; min-width: 0; font-size: var(--step-1); letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.signin-form .btn { white-space: nowrap; }
.signin .btn.quiet { justify-self: start; }
