/* Connet's web app. Only tokens from tokens.css: no raw colours, fonts or sizes here. */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { overflow-x: clip; }
body { margin: 0; background: var(--color-paper); color: var(--color-ink); font-family: var(--font-body); font-size: var(--text-base); line-height: var(--leading-body); }
h1, h2, .wordmark, .sidebar-title { font-family: var(--font-display); font-weight: 400; font-style: normal; letter-spacing: -0.01em; margin: 0; overflow-wrap: anywhere; }
h1 { font-size: var(--text-3xl); line-height: var(--leading-tight); }
h2 { font-size: var(--text-xl); line-height: var(--leading-snug); }
p { margin: 0; }
a { color: var(--color-accent-ink); }
a:hover { color: var(--color-ink); }
code, .mono { font-family: var(--font-mono); font-size: var(--text-sm); }
code { background: var(--color-code); padding: var(--space-3xs) var(--space-2xs); border-radius: var(--radius-sm); word-break: break-all; }
.quiet { color: var(--color-ink-3); font-size: var(--text-sm); }
.quiet-2 { color: var(--color-ink-2); }
.error { color: var(--color-danger); min-height: 1.5em; }
.error:empty { min-height: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Controls. Every one has hover, focus, pressed and disabled states. */
button, .button {
  font: inherit; font-weight: 600; min-height: var(--target); padding: 0 var(--space-lg);
  border-radius: var(--radius-pill); border: 1px solid var(--color-rule-strong);
  background: transparent; color: var(--color-ink); cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
button:hover, .button:hover { background: var(--color-paper-3); color: var(--color-ink); }
button:active, .button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
button.primary, .button.primary { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-accent); }
button.primary:hover, .button.primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); color: var(--color-on-accent); }
button.primary:active, .button.primary:active { background: var(--color-accent-press); border-color: var(--color-accent-press); }
:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 2px; }
input, textarea, select {
  font: inherit; width: 100%; padding: var(--space-sm) var(--space-md); min-height: var(--target);
  border: 1px solid var(--color-rule); border-radius: var(--radius-lg);
  background: var(--color-paper); color: var(--color-ink);
}
input::placeholder, textarea::placeholder { color: var(--color-ink-3); }
label { display: block; margin-bottom: var(--space-sm); font-weight: 500; }
label input, label select { margin-top: var(--space-2xs); font-weight: 400; }

/* The mark: a C with a dot at its centre; the cinnabar piece split off by the gap is the AI's.
   The stroke matches the fill: it rounds the corners. */
.mark { flex: none; }
.mark-c { fill: var(--color-bone); stroke: var(--color-bone); }
.mark-dot { fill: var(--color-bone); }
.mark-ai { fill: var(--color-accent); stroke: var(--color-accent); }

/* Signed out. */
.top { display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-md) var(--space-lg); flex-wrap: wrap; }
.wordmark { display: flex; align-items: center; gap: var(--space-xs); font-size: var(--text-xl); color: var(--color-ink); text-decoration: none; }
.tag { color: var(--color-ink-3); font-size: var(--text-sm); }
.top .wordmark { margin-right: auto; }
.top-link { color: var(--color-ink-2); font-weight: 500; min-height: var(--target); display: inline-flex; align-items: center; }
.auth { max-width: 760px; margin: var(--space-xl) auto; padding: 0 var(--space-md); display: grid; gap: var(--space-md); grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.auth h1, .auth .error { grid-column: 1 / -1; }
/* Only one form showing (set up, or invite-only log in): one narrow column. */
.auth:has(> form.card[hidden]) { max-width: 520px; grid-template-columns: minmax(0, 1fr); }
.auth h1 { margin-bottom: var(--space-md); }
.card, .panel { background: var(--color-paper-2); border-radius: var(--radius-xl); padding: var(--space-lg); }
.card h2 { margin-bottom: var(--space-md); }

/* Pages before the app: recovery code, invite, reset, first workspace. */
.gate-page { max-width: 760px; margin: var(--space-xl) auto; padding: 0 var(--space-md); }
.gate-page.narrow { max-width: 560px; display: flex; flex-direction: column; gap: var(--space-md); }
.gate-note { grid-column: 1 / -1; color: var(--color-ink-2); font-size: var(--text-md); }
.auth .wide { grid-column: 1 / -1; }
.row { display: flex; gap: var(--space-xs); flex-wrap: wrap; }
.code-box { background: var(--color-paper-2); border-radius: var(--radius-xl); padding: var(--space-lg); }
.code-box code { font-size: var(--text-lg); background: transparent; padding: 0; }
.recover { margin-top: var(--space-md); }
.recover summary { cursor: pointer; color: var(--color-accent-ink); min-height: var(--target); display: flex; align-items: center; }
.recover p { margin-bottom: var(--space-sm); }

/* Signed in: rail, sidebar panel, and the view, all floating on the ground. */
.app { display: flex; gap: var(--space-md); padding: var(--space-md); min-height: 100vh; align-items: flex-start; }
.rail { flex: none; width: var(--rail-width); position: sticky; top: var(--space-md); height: calc(100vh - 2 * var(--space-md)); display: flex; flex-direction: column; align-items: center; gap: var(--space-xs); padding: var(--space-xs) 0; }
.rail-mark { display: grid; place-items: center; min-height: var(--target); min-width: var(--target); border-radius: var(--radius-lg); }
.rail-gap { flex: 1; }
.rail-list { list-style: none; margin: var(--space-sm) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-xs); }
.rail-ws { background: var(--color-paper-2); color: var(--color-ink); font-family: var(--font-display); font-size: var(--text-lg); text-decoration: none; }
.rail-ws[aria-current="page"] { background: var(--color-bone); color: var(--color-on-bone); }
.rail-ws[aria-current="page"]:hover { background: var(--color-bone); color: var(--color-on-bone); }
.rail-btn { width: var(--target); height: var(--target); min-height: 0; padding: 0; border: 0; border-radius: var(--radius-lg); color: var(--color-ink-2); background: transparent; display: grid; place-items: center; cursor: pointer; list-style: none; }
.rail-btn::-webkit-details-marker { display: none; }
.rail-btn:hover { background: var(--color-paper-3); color: var(--color-ink); }
.rail-btn svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.avatar { border-radius: 50%; background: var(--color-bone); color: var(--color-on-bone); font-weight: 700; }
.avatar:hover { background: var(--color-bone); color: var(--color-on-bone); }
.account { position: relative; }
.account-menu { position: absolute; left: calc(100% + var(--space-xs)); bottom: 0; z-index: 2; min-width: 200px; background: var(--color-paper-3); border-radius: var(--radius-lg); padding: var(--space-md); box-shadow: var(--shadow-pop); display: grid; gap: var(--space-sm); }
.account-name { font-weight: 600; overflow-wrap: anywhere; }

.sidebar { flex: none; width: var(--sidebar-width); position: sticky; top: var(--space-md); max-height: calc(100vh - 2 * var(--space-md)); overflow-y: auto; padding: var(--space-lg) var(--space-sm); display: flex; flex-direction: column; gap: var(--space-3xs); }
.sidebar-title { font-size: var(--text-lg); padding: 0 var(--space-sm) var(--space-sm); }
.search { padding: 0 var(--space-2xs) var(--space-sm); }
.search input { background: var(--color-paper); }
.nav-label { margin: var(--space-md) var(--space-sm) var(--space-2xs); font-size: var(--text-sm); color: var(--color-ink-3); }
.channel-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3xs); }
.nav { display: flex; align-items: center; gap: var(--space-sm); min-height: var(--target); padding: 0 var(--space-sm); border-radius: var(--radius-lg); color: var(--color-ink-2); text-decoration: none; font-weight: 500; }
.nav:hover { background: var(--color-paper-3); color: var(--color-ink); }
.nav[aria-current="page"] { background: var(--color-accent); color: var(--color-on-accent); font-weight: 700; }
.nav.has-new { color: var(--color-ink); font-weight: 700; }
.nav-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-new { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-accent-ink); font-weight: 500; }
.nav[aria-current="page"] .nav-new { color: var(--color-on-accent); }
.nav-lock { flex: none; width: 15px; height: 15px; fill: none; stroke: var(--color-ink-3); stroke-width: 2; stroke-linecap: round; }
.nav[aria-current="page"] .nav-lock { stroke: var(--color-on-accent); }
.online { padding: 0 var(--space-sm); }
.invite { margin: var(--space-sm) var(--space-2xs) 0; }
.replies { margin-top: var(--space-2xs); }

/* Channel jacks: one patch-cable colour per channel. */
.jack { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--color-line-1); }
.jack.line-2 { background: var(--color-line-2); }
.jack.line-3 { background: var(--color-line-3); }
.jack.line-4 { background: var(--color-line-4); }
.nav[aria-current="page"] .jack { box-shadow: 0 0 0 2px var(--color-on-accent); }

.view { flex: 1; min-width: 0; padding: var(--space-lg) var(--space-lg) var(--space-xl); }

/* Overview. */
.overview { display: flex; flex-direction: column; gap: var(--space-xl); }
.ov-head { display: flex; flex-direction: column; gap: var(--space-xs); }
.ov-summary { color: var(--color-ink-2); font-size: var(--text-lg); max-width: 34em; }
.ov-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: var(--space-lg); align-items: start; }
.ov-thread h2, .ov-side h2 { margin-bottom: var(--space-md); }
.ov-side { display: flex; flex-direction: column; gap: var(--space-md); min-width: 0; }
.ov-side .quiet-2 { margin-bottom: var(--space-md); }
.mcp { margin-bottom: var(--space-md); }

.thread { list-style: none; margin: 0; padding: 0; }
.thread-item { display: grid; grid-template-columns: 4.75rem 20px minmax(0, 1fr); gap: var(--space-sm); }
.thread-time { color: var(--color-ink-3); padding-top: var(--space-3xs); white-space: nowrap; }
.thread-time.for-you { color: var(--color-accent-ink); }
.thread-wire { display: flex; flex-direction: column; align-items: center; }
.thread-wire .jack { width: 14px; height: 14px; margin-top: var(--space-2xs); }
.thread-wire .jack.ring { background: transparent; border: 2px solid var(--color-accent); }
.thread-wire::after { content: ""; flex: 1; width: 2px; background: var(--color-rule); }
.thread-item:last-child .thread-wire::after { display: none; }
.thread-link { display: flex; flex-direction: column; gap: var(--space-2xs); padding-bottom: var(--space-lg); color: var(--color-ink); text-decoration: none; min-width: 0; border-radius: var(--radius-md); }
.thread-link:hover .thread-who { text-decoration: underline; text-underline-offset: 3px; }
.thread-head { display: flex; flex-wrap: wrap; column-gap: var(--space-xs); align-items: baseline; }
.thread-who { font-weight: 600; font-size: var(--text-md); }
.thread-where { color: var(--color-ink-2); }
.thread-body { color: var(--color-ink-2); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.badge { align-self: flex-start; font-size: var(--text-xs); font-weight: 600; padding: var(--space-3xs) var(--space-xs); border-radius: var(--radius-pill); background: var(--color-accent-soft); color: var(--color-accent-ink); }
.badge.ai { background: var(--color-paper-3); color: var(--color-ink-2); }
.empty { display: flex; flex-direction: column; gap: var(--space-md); align-items: flex-start; color: var(--color-ink-2); }

.storage { display: flex; align-items: center; gap: var(--space-lg); flex-wrap: wrap; }
.storage-text { flex: 1 1 180px; }
.storage-text h2 { margin-bottom: var(--space-2xs); }
.storage .quiet-2 { margin-bottom: 0; }
.gauge { flex: none; }
.gauge path { fill: none; stroke-width: 10; stroke-linecap: round; }
.gauge-track { stroke: var(--color-paper-3); }
.gauge-fill { stroke: var(--color-accent); }

/* Settings and profile: a column of panels. */
.page { display: flex; flex-direction: column; gap: var(--space-md); max-width: 820px; }
.page > h1 { margin-bottom: var(--space-xs); }
.tabs { display: flex; flex-wrap: wrap; gap: var(--space-2xs); background: var(--color-paper-2); border-radius: var(--radius-pill); padding: var(--space-2xs); align-self: flex-start; max-width: 100%; }
.tab { border: 0; min-height: var(--control-h); padding: 0 var(--space-md); font-weight: 500; color: var(--color-ink-2); }
.tab:hover { color: var(--color-ink); }
.page .panel { scroll-margin-top: var(--space-lg); display: flex; flex-direction: column; gap: var(--space-sm); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--space-xs); max-width: 420px; }
.stack label { margin-bottom: 0; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); padding: var(--space-sm) 0; border-top: var(--rule); }
.list-row:first-child { border-top: 0; }
/* At least 12rem for the name, so an owner's buttons wrap below it instead of squeezing it. */
.list-main { flex: 1 1 12rem; min-width: 0; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.list-title { font-family: var(--font-body); font-size: var(--text-base); font-weight: 600; margin: var(--space-sm) 0 0; }
.todo { color: var(--color-ink-3); font-size: var(--text-sm); border: 1px dashed var(--color-rule-strong); border-radius: var(--radius-lg); padding: var(--space-sm) var(--space-md); }
.danger-zone h2 { color: var(--color-danger); }
button.danger { border-color: var(--color-danger); color: var(--color-danger); }
button.danger:hover { background: var(--color-danger-soft); color: var(--color-danger); }
.rail-btn[aria-current] { background: var(--color-paper-3); color: var(--color-ink); }
.account-menu .button { justify-content: flex-start; }

/* A channel. */
.channel { display: flex; flex-direction: column; min-height: calc(100vh - 2 * var(--space-md) - var(--space-lg) - var(--space-xl)); }
.channel-head { display: flex; align-items: baseline; gap: var(--space-md); flex-wrap: wrap; padding-bottom: var(--space-md); border-bottom: var(--rule); }
.channel-head h1 { font-size: var(--text-2xl); }
.messages { list-style: none; padding: var(--space-sm) 0; margin: 0; flex: 1; }
.message { display: flex; gap: var(--space-sm); padding: var(--space-sm) 0; }
.face { flex: none; width: 38px; height: 38px; border-radius: 50%; background: var(--color-bone); color: var(--color-on-bone); display: grid; place-items: center; font-weight: 700; }
.face.ai { border-radius: var(--radius-md); background: var(--color-accent); color: var(--color-on-accent); }
.message-main { min-width: 0; }
.message .who { font-weight: 600; }
.message .when { margin-left: var(--space-xs); }
.message .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.message .where { margin-left: var(--space-xs); }
.typing { min-height: 1.5em; }
.composer { display: flex; gap: var(--space-xs); align-items: flex-end; background: var(--color-paper-2); border-radius: var(--radius-xl); padding: var(--space-xs) var(--space-xs) var(--space-xs) var(--space-md); position: sticky; bottom: var(--space-md); }
.composer textarea { border: 0; background: transparent; resize: none; padding: var(--space-xs) 0; min-height: var(--target); }
/* The ring goes round the whole box, not just the text inside it. */
.composer textarea:focus-visible { outline: none; }
.composer:focus-within { outline: 3px solid var(--color-focus); outline-offset: 2px; }

/* The "Allow this AI?" page. */
.consent { max-width: 560px; margin: var(--space-2xl) auto; padding: 0 var(--space-md); display: grid; gap: var(--space-md); }
.consent form { display: flex; gap: var(--space-xs); margin-top: var(--space-lg); flex-wrap: wrap; }
.consent form label { flex-basis: 100%; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0ms !important; }
  button:active, .button:active { transform: none; }
}

/* Phones and narrow windows: the rail becomes a top bar and the sidebar stacks above the view. */
@media (max-width: 760px) {
  .app { flex-direction: column; align-items: stretch; padding: var(--space-xs); gap: var(--space-xs); }
  .rail { position: static; width: auto; height: auto; flex-direction: row; padding: 0 var(--space-2xs); }
  .rail-list { flex-direction: row; margin: 0; }
  .account-menu { left: auto; right: 0; bottom: auto; top: calc(100% + var(--space-xs)); }
  .sidebar { position: static; width: auto; max-height: none; }
  .view { padding: var(--space-md) var(--space-xs); }
  h1 { font-size: var(--text-2xl); }
}

/* Added with the backend wiring (bare, for the UI chat to restyle). */
.block-text { white-space: pre-wrap; font-size: var(--text-sm); max-height: 22rem; overflow: auto; }
.list-row select { width: auto; }
.list-actions { display: flex; gap: var(--space-xs); flex-wrap: wrap; margin-left: auto; }
.check { display: flex; align-items: center; gap: var(--space-xs); }
.check input { width: auto; }

/* Loading: animations made from the mark (public/loader.js). Start up while the app opens,
   Draw while a channel loads, Orbit for short waits, Turn for long jobs. */
.loader { display: block; overflow: visible; }
.loader * { transform-box: view-box; transform-origin: 256px 256px; }
.loading-block { display: grid; place-items: center; padding: var(--space-2xl) 0; }
.loading-block .loader { width: 64px; height: 64px; }
.loading-inline { display: inline-flex; vertical-align: middle; }
.loading-inline .loader { width: 20px; height: 20px; }
.ov-date-row { display: flex; align-items: center; gap: var(--space-xs); }

/* Turn: the C turns round the still dot. */
.loader-turn .spin { animation: loader-turn 1.4s cubic-bezier(.6, .1, .4, .9) infinite; }
@keyframes loader-turn { to { transform: rotate(-360deg); } }

/* Orbit: the AI's piece runs round a faint C. */
.loader-orbit .track { opacity: .22; }
.loader-orbit .track .mark-ai { fill: var(--color-bone); stroke: var(--color-bone); }
.loader-orbit .spin { animation: loader-turn 1.1s linear infinite; }

/* Draw: the stroke draws the C from its top end, holds, then wipes away from the top end, the same way round.
   pathLength="100", so the line is 100 long: 100 hidden, 0 drawn, -100 wiped. */
.loader-draw .draw-line { stroke-dasharray: 100 100; stroke-dashoffset: 100; animation: loader-draw 2.6s cubic-bezier(.55, 0, .45, 1) infinite; }
@keyframes loader-draw { 0% { stroke-dashoffset: 100; } 42%, 58% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -100; } }

/* Start up: the boot screen. While loading, the dot breathes. When ready: it swells into a disc, hollows into
   a ring, the mouth splits open, the lower end pulls back to uncover the AI's piece, and a new dot lands. */
.boot { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--color-paper); transition: opacity .3s ease; }
.boot[data-state="gone"] { opacity: 0; pointer-events: none; }
.loader-startup { width: 96px; height: 96px; }
.loader-startup .disc { fill: var(--color-bone); }
.loader-startup .close { stroke: var(--color-bone); stroke-dasharray: 100 100; stroke-dashoffset: 0; }
.loader-startup .grow { transform: scale(.1667); }
.loader-startup .hole, .loader-startup .newdot { transform: scale(.001); } /* not 0: Chromium ignores a zero scale in a mask */
.boot[data-state="loading"] .grow { animation: startup-breathe 1.4s ease-in-out infinite; }
@keyframes startup-breathe { 0%, 100% { transform: scale(.1667); } 50% { transform: scale(.2333); } }
.boot:not([data-state="loading"]) .grow { animation: startup-grow 2.4s cubic-bezier(.3, 0, .1, 1) forwards; }
@keyframes startup-grow { 0% { transform: scale(.1667); } 25%, 100% { transform: scale(1); } }
.boot:not([data-state="loading"]) .hole { animation: startup-hole 2.4s cubic-bezier(.5, 0, .2, 1) forwards; }
@keyframes startup-hole { 0%, 22% { transform: scale(.001); } 45%, 100% { transform: scale(1); } }
.boot:not([data-state="loading"]) .disc { animation: startup-disc 2.4s linear forwards; }
@keyframes startup-disc { 0%, 44% { opacity: 1; } 46%, 100% { opacity: 0; } }
.boot:not([data-state="loading"]) .close-upper { animation: startup-open 2.4s cubic-bezier(.6, 0, .3, 1) forwards; }
.boot:not([data-state="loading"]) .close-lower { animation: startup-uncover 2.4s cubic-bezier(.6, 0, .4, 1) forwards; }
@keyframes startup-open { 0%, 45% { stroke-dashoffset: 0; } 60%, 100% { stroke-dashoffset: 100; } }
@keyframes startup-uncover { 0%, 45% { stroke-dashoffset: 0; } 82%, 100% { stroke-dashoffset: 100; } }
.boot:not([data-state="loading"]) .newdot { animation: startup-dot 2.4s cubic-bezier(.3, 1.5, .5, 1) forwards; }
@keyframes startup-dot { 0%, 78% { transform: scale(.001); } 95%, 100% { transform: scale(1); } }

/* Reduced motion: no movement, just a slow fade; Start up shows the whole mark. */
@media (prefers-reduced-motion: reduce) {
  .loader * { animation: none !important; }
  .loader { animation: loader-calm 2s ease-in-out infinite; }
  .loader-draw .draw-line { stroke-dashoffset: 0; }
  .loader-startup .grow, .loader-startup .hole, .loader-startup .newdot { transform: none; }
  .loader-startup .close, .loader-startup .disc { display: none; }
}
@keyframes loader-calm { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
