/* Ghost UI -- components and layout. Tokens live in tokens.css, the orb and
 * voice-state motion in orb.css. Surfaces are lit from above instead of being
 * outlined; state is a dot + text, never a coloured side stripe. */

/* --- Page ground ------------------------------------------------------- */

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(90% 55% at 50% -8%, rgba(var(--light-blue-rgb), 0.16), transparent 62%),
    radial-gradient(60% 40% at 100% 100%, rgba(var(--light-violet-rgb), 0.07), transparent 70%),
    var(--night-1);
  background-attachment: fixed;
}

/* The top bar floats over the stage so the orb's halo is never clipped by it. */
header#topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-nav);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: calc(var(--s-3) + var(--safe-top)) calc(var(--s-4) + var(--safe-right)) var(--s-3) calc(var(--s-4) + var(--safe-left));
  pointer-events: none;
}

header#topbar .brand {
  flex: 1;
  min-width: 0;
}

/* Brand lockup: the owner-approved logo image (GhOSt + the Ghost sphere as
   the O + "AI Personal Assistant", all one asset -- see
   app/public/brand/ghost-logo-lockup.png). One rule per placement, scaling
   by max-width with height:auto (tokens.css) so the lockup only ever shrinks
   proportionally -- never stretched, never squeezed, never reassembled. */
.brand {
  display: inline-flex;
  min-width: 0;
}

.brand__logo {
  max-width: 108px; /* mobile top bar (<=768px, signed-in) */
}

/* The build fingerprint lives in the System section of the sheet/sidebar
   (version-info); the badge itself stays in the DOM for app.js but not on screen. */
#version-badge {
  display: none;
}

main {
  flex: 1;
  display: flex;
  min-height: 0;
  width: 100%;
}

/* --- Controls ---------------------------------------------------------- */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--touch);
  padding: 0 var(--s-4);
  border: 0;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink-1);
  box-shadow: inset 0 1px 0 var(--highlight-top);
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: background var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}

button:active {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Primary: the one lit action on a surface. */
.btn-primary {
  background: var(--light-cyan);
  color: var(--ink-on-light);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), var(--glow-2);
  font-weight: 600;
}

/* Quiet: a text-weight action that still keeps a 44px hit area. */
.btn-quiet {
  background: transparent;
  box-shadow: none;
  color: var(--ink-2);
  font-size: var(--fs-small);
  padding: 0 var(--s-3);
}

.icon-btn {
  width: var(--touch);
  padding: 0;
}

input[type='password'],
textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 0.7rem var(--s-4);
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface-1);
  color: var(--ink-1);
  box-shadow: inset 0 0 0 1px var(--hairline), inset 0 1px 0 var(--highlight-top);
  transition: box-shadow var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease-out);
}

input::placeholder,
textarea::placeholder {
  color: var(--ink-3);
}

input:focus-visible,
textarea:focus-visible {
  outline: none;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1.5px var(--light-cyan), var(--glow-1);
}

/* --- Login ------------------------------------------------------------- */

#login-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-4);
  width: 100%;
  max-width: 24rem;
  margin: 0 auto;
  padding: var(--s-4) var(--s-4) var(--s-7);
  text-align: center;
}

#login-view .login-lead {
  color: var(--ink-2);
  letter-spacing: 0.02em;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  width: 100%;
}

#login-error {
  width: 100%;
  text-align: left;
}

/* --- App shell: sidebar + chat panel (layout refined in the hero/desktop layers) --- */

#app-shell {
  flex: 1;
  display: flex;
  min-height: 0;
  width: 100%;
  position: relative;
}

#sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: var(--z-backdrop);
}

#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  padding: var(--s-4);
  overflow-y: auto;
  background: linear-gradient(180deg, var(--night-0), var(--night-1));
  box-shadow: inset -36px 0 48px -44px rgba(var(--light-blue-rgb), 0.16);
}

.new-conversation-btn {
  width: 100%;
  justify-content: flex-start;
  background: var(--surface-1);
  color: var(--ink-1);
}

#conversation-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#conversation-list li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: var(--touch);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease-out);
}

#conversation-list li.active {
  background: var(--surface-2);
  box-shadow: inset 0 1px 0 var(--highlight-top);
}

.conversation-title {
  font-size: var(--fs-small);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-timestamp {
  font-size: var(--fs-caption);
  color: var(--ink-3);
}

/* --- Status: connections as a dot + word ------------------------------ */

#status-panel {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-3) 0;
}

#status-panel h2 {
  padding: 0;
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--ink-3);
}

.status-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--fs-small);
}

#version-info {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px var(--s-3);
  color: var(--ink-3);
  font-size: var(--fs-caption);
}

#version-info dd {
  overflow-wrap: anywhere;
  color: var(--ink-2);
}

#version-info :is(dt, dd):nth-of-type(n + 3) {
  display: none;
}

.connection-row {
  /* Final polish (D66): a fixed two-liner -- the name, below it what Ghost may do or the problem. With the
     larger type a one-line row wrapped unevenly (and overlapped) in the narrow sidebar. */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.125rem;
  padding-block: var(--s-1);
  color: var(--ink-1);
  font-size: var(--fs-small);
}

.connection-service {
  overflow-wrap: anywhere;
}

.connection-service::first-letter {
  text-transform: uppercase;
}

.connection-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: var(--fs-caption);
  color: var(--ink-3);
}

.connection-badge::before {
  content: '';
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--ink-3);
}

.connection-row.status-configured .connection-badge::before {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(var(--ok-rgb), 0.7);
}

.connection-row.status-not_configured .connection-badge {
  color: var(--error);
}

.connection-row.status-not_configured .connection-badge::before {
  background: var(--error);
}

.connection-timestamp {
  display: none;
}

.connection-connect-link {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  font-size: var(--fs-small);
}

/* --- Surfaces shared by Tagesüberblick and Freigaben ------------------ */

/* Content layer: a standard material, never glass. HIG (materials.md, Liquid
   Glass): "Don't use Liquid Glass in the content layer." Blur and the lit edge
   belong to the floating layer only: the dock and the sheet. */
.daily-brief,
.approvals {
  position: relative;
  border-radius: var(--r-xl);
  background: var(--surface-section);
  /* A crisp level-2 boundary from the ground: contrast, not a heavy line. Plus
     the lit top edge and one sparse shadow (owner: shadow/elevation sparingly). */
  box-shadow: inset 0 0 0 1px var(--edge-section), inset 0 1px 0 var(--highlight-top), var(--shadow-1);
  flex-shrink: 0;
}

/* The lit edge: a masked 1px ring that takes the character's current light.
   Only on the two floating dock elements. */
:is(.dock__tabs, .dock__more)::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: 1px;
  border-radius: inherit;
  background: var(--glass-edge);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.daily-brief-header {
  display: flex;
  align-items: center;
  gap: var(--s-1);
}

.daily-brief-header .daily-brief-toggle-btn {
  flex: 1;
  min-width: 0;
}

.approvals-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
}

/* The brief's header is the compact "next appointment" row of the Start view. */
.daily-brief-toggle-btn {
  display: grid;
  grid-template-columns: 2.75rem 1fr auto;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: 4rem;
  padding: var(--s-2) var(--s-4) var(--s-2) var(--s-3);
  border-radius: var(--r-lg);
  background: transparent;
  box-shadow: none;
  text-align: left;
  font-weight: 400;
}

.brief-icon {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  box-shadow: inset 0 1px 0 var(--highlight-top);
}

.brief-head {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brief-head__label {
  font-size: var(--fs-small);
  color: var(--ink-3);
}

.brief-head__value {
  font-size: var(--fs-lead);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brief-head__date {
  display: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-small);
  color: var(--ink-3);
}

/* Open, the lead line moves into the Jetzt block: the header becomes "Heute · date". */
.daily-brief-toggle-btn[aria-expanded='true'] .brief-head {
  flex-direction: row;
  align-items: baseline;
  gap: var(--s-3);
}

.daily-brief-toggle-btn[aria-expanded='true'] .brief-head__label {
  font-size: var(--fs-title);
  font-weight: 500;
  color: var(--ink-1);
}

.daily-brief-toggle-btn[aria-expanded='true'] .brief-head__value {
  display: none;
}

/* Open, the calendar tile has done its job: the title and the date get the row. */
.daily-brief-toggle-btn[aria-expanded='true'] {
  grid-template-columns: 1fr auto;
  padding-left: var(--s-4);
}

.daily-brief-toggle-btn[aria-expanded='true'] .brief-icon {
  display: none;
}

.daily-brief-toggle-btn[aria-expanded='true'] .brief-head__date {
  display: block;
}

.brief-chev {
  color: var(--ink-3);
  transition: transform var(--dur-2) var(--ease-out);
}

.daily-brief-toggle-btn[aria-expanded='true'] .brief-chev {
  transform: rotate(90deg);
}

.approvals-toggle-btn {
  background: transparent;
  box-shadow: none;
  padding: 0 var(--s-2);
  font-size: var(--fs-lead);
  font-weight: 500;
}

.approvals-count {
  order: 1;
}

.approvals-open-btn {
  display: none;
  order: 2;
  margin-left: auto;
  color: var(--light-cyan);
  background: transparent;
  box-shadow: none;
  font-size: var(--fs-small);
  padding: 0 var(--s-2) 0 var(--s-3);
}

.approvals-open-btn .icon {
  width: 1rem;
  height: 1rem;
}

.approvals-refresh-btn {
  order: 3;
  margin-left: auto;
}

.approvals-open-btn + .approvals-refresh-btn {
  margin-left: 0;
}

.approvals-refresh-btn {
  background: transparent;
  box-shadow: none;
  color: var(--ink-2);
  font-size: var(--fs-small);
  padding: 0 var(--s-3);
}

.daily-brief-refresh-btn {
  flex: none;
  width: var(--touch);
  margin-right: var(--s-2);
  padding: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ink-3);
}

.daily-brief-header:has(.daily-brief-toggle-btn[aria-expanded='false']) .daily-brief-refresh-btn {
  display: none;
}

.daily-brief-refresh-btn[aria-busy='true'] .icon {
  animation: brief-refresh 0.9s linear infinite;
}

@keyframes brief-refresh {
  to {
    transform: rotate(360deg);
  }
}

.daily-brief-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  padding: var(--s-2) var(--s-4) var(--s-4);
}

/* --- Heute: the rail's executive summary --------------------------------
   Built from the brief's structured items (todayRail.js), never its markdown.
   One label language for every block (icon chip + small semibold ink-2), one
   row pattern (time or tag, title, one meta line), and colour only for the
   signals: amber = a decision waits, cyan = a person wrote, rosé = a source or
   Ghost has a problem. Everything else is ink. */
.today {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  color: var(--ink-1);
}

.tb {
  --ti-lead: 4.75rem;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.tb__label {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-small);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink-2);
}

.tb__label .icon {
  box-sizing: content-box;
  width: 1rem;
  height: 1rem;
  padding: 0.28rem;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink-2);
}

/* The attention block takes the tone of its most important item. */
.tb--decision .tb__label {
  color: var(--warn);
}

.tb--decision .tb__label .icon {
  background: rgba(var(--warn-rgb), 0.14);
  color: var(--warn);
}

.tb--person .tb__label .icon {
  background: rgba(var(--light-cyan-rgb), 0.14);
  color: var(--light-cyan);
}

.ti {
  display: grid;
  grid-template-columns: var(--ti-lead) minmax(0, 1fr);
  column-gap: var(--s-3);
  row-gap: 2px;
  align-items: baseline;
  justify-content: stretch;
  width: 100%;
  min-height: 0;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  background: var(--surface-card);
  box-shadow: inset 0 0 0 1px var(--edge-card), inset 0 1px 0 var(--highlight-top);
  color: var(--ink-1);
  font-size: var(--fs-body);
  font-weight: 400;
  line-height: 1.35;
  text-align: left;
}

button.ti {
  min-height: var(--touch);
}

/* Tagged rows: the tag leads the title line; title and meta use the full width. */
.ti--tagged {
  grid-template-columns: minmax(0, 1fr);
}

.ti--action:active {
  transform: scale(0.985);
}

/* Jetzt: the lead appointment is the one lit row; the rest are quiet lines. */
.tb--now .ti:not(.ti--lead) {
  padding: 0 var(--s-3);
  background: transparent;
  box-shadow: none;
}

.ti__time {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-small);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.ti__title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  min-width: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.ti--lead .ti__time {
  font-size: var(--fs-body);
  font-weight: 500;
  color: var(--ink-1);
}

.ti--lead .ti__title {
  font-size: var(--fs-lead);
  font-weight: 500;
}

.ti__meta {
  grid-column: -2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-caption);
  color: var(--ink-3);
}

.ti__action {
  grid-column: -2;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-top: 2px;
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--ink-2);
}

.ti__action .icon {
  width: 0.95rem;
  height: 0.95rem;
}

.ti__tag {
  display: inline-block;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: 0.08em;
  margin-right: 0.45em;
  padding: 0.05rem 0.45rem;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--fs-caption);
  font-weight: 500;
}

.ti__tag--decision {
  background: rgba(var(--warn-rgb), 0.16);
  color: var(--warn);
}

.ti__tag--person {
  background: rgba(var(--light-cyan-rgb), 0.14);
  color: var(--light-cyan);
}

.tb__note,
.tb__more,
.today__hint {
  padding: 0 var(--s-3);
  font-size: var(--fs-small);
  color: var(--ink-3);
}

.tb__note--calm {
  font-size: var(--fs-body);
  color: var(--ink-2);
}

/* A system state: Ghost or a source cannot deliver. */
.tb__note--system {
  color: var(--error);
}

.tb__more {
  font-size: var(--fs-caption);
}

button.tb__more--link {
  justify-content: flex-start;
  min-height: 2rem;
  background: transparent;
  box-shadow: none;
  color: var(--ink-2);
  font-weight: 400;
}

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

.rail-connect {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}

/* Loading: three still lines where the day will be -- no spinner, no shimmer. */
.ti-skeleton {
  display: block;
  height: 0.9rem;
  margin: 0.2rem var(--s-3);
  border-radius: var(--r-pill);
  background: var(--surface-2);
}

.ti-skeleton:first-child {
  width: 70%;
  height: 1.1rem;
}

.ti-skeleton:nth-child(2) {
  width: 55%;
}

.ti-skeleton:nth-child(3) {
  width: 40%;
}

/* Quellen: one quiet footer line. A reached source is a neutral dot; one that
   is not reached is rosé and carries its one repair action. */
.daily-brief-sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-3);
  padding: var(--s-3) var(--s-3) 0;
  font-size: var(--fs-caption);
  color: var(--ink-3);
}

.daily-brief-source-list {
  display: contents;
}

.src {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  color: var(--ink-3);
}

.src::before {
  content: '';
  flex: none;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--ink-3);
  opacity: 0.6;
}

.src--quiet::before {
  opacity: 0.3;
}

.src--down {
  color: var(--error);
}

.src--down::before {
  background: var(--error);
  opacity: 1;
}

a.src {
  min-height: 2rem;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}

.daily-brief-timestamp {
  margin-left: auto;
  white-space: nowrap;
}

/* "Termine morgen" (quick action) lists its result in the chat. */
.daily-brief-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.daily-brief-list li {
  overflow-wrap: anywhere;
}

/* --- Freigaben --------------------------------------------------------- */

.approvals-count {
  min-width: 1.5rem;
  padding: 0.05rem 0.5rem;
  border-radius: var(--r-pill);
  background: var(--warn);
  color: var(--ink-on-light);
  font-size: var(--fs-caption);
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.approvals-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3) var(--s-3);
  max-height: 45vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* An approve/reject/execute failure must stay visible even when the list
   below it is scrolled. */
#approvals-error {
  position: sticky;
  top: 0;
  z-index: var(--z-raised);
  flex-shrink: 0;
}

/* "Nothing waits": one calm, centred state -- a lit check and a headline, no explanation
   (UX polish 2026-10-26). Shared by the open filter (.approvals-none-open) and the empty list. */
.approvals-done {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-7) var(--s-4);
  text-align: center;
}

.approvals-done__icon {
  display: grid;
  place-items: center;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: rgba(var(--ok-rgb), 0.1);
  box-shadow: inset 0 0 0 1px rgba(var(--ok-rgb), 0.2), 0 0 36px rgba(var(--ok-rgb), 0.1);
  color: var(--ok);
}

.approvals-done__icon .icon {
  width: 2rem;
  height: 2rem;
}

.approvals-done__title {
  margin: 0;
  font-size: var(--fs-title);
  font-weight: 600;
  color: var(--ink-1);
}

.approvals-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

/* A proposal is an object the owner decides on -- the one place a card earns
   its keep. Status is a pill with a dot, not a coloured side stripe. */
.proposal-card {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-width: 0;
  padding: var(--s-4);
  border-radius: var(--r-md);
  background: var(--night-2);
  box-shadow: inset 0 1px 0 var(--highlight-top), inset 0 0 0 1px var(--hairline);
}

/* Final polish (D66): no amber frame on a waiting card -- under "Offen" every card waits, and the amber
   mark stays the signal for what really differs (Ausgang unklar, Läuft bald ab). */
.proposal-card.status-succeeded,
.proposal-card.status-rejected,
.proposal-card.status-expired,
.proposal-card.status-failed {
  background: var(--night-1);
}

.proposal-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.proposal-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--ink-2);
}

.proposal-status::before {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}

.proposal-status.tone-ok { color: var(--ok); }
.proposal-status.tone-warn { color: var(--warn); }
.proposal-status.tone-error { color: var(--error); }
.proposal-status.tone-accent { color: var(--light-cyan); }

.proposal-title {
  font-weight: 600;
  color: var(--ink-2);
}

.proposal-description {
  font-size: var(--fs-lead);
  line-height: 1.4;
  overflow-wrap: anywhere;
  /* The server-generated description is authoritative and multi-line for a
     calendar event (issue #19); keep its line breaks readable. */
  white-space: pre-line;
}

/* Compact approval facts: each decision-relevant fact once (proposalFacts.js).
   WHAT reads first, WHEN second, the rest is quiet supporting text. */
.proposal-facts {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  min-width: 0;
}

.proposal-fact {
  margin: 0;
  font-size: var(--fs-body);
  line-height: 1.4;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.proposal-fact__label {
  margin-right: 0.45em;
  color: var(--ink-3);
}

.proposal-fact--what {
  font-size: var(--fs-lead);
  font-weight: 600;
  color: var(--ink-1);
}

.proposal-fact--when {
  font-size: var(--fs-body);
  color: var(--ink-1);
}

/* One line per attachment (name, sizes, send copy yes/no). */
.proposal-fact--attachments {
  white-space: pre-line;
}

/* The mail body is exactly what the owner approves: keep its line breaks. Final polish (D66): no box
   inside the card -- the letter reads as a letter, set in by a hairline that marks where it begins and ends. */
.proposal-fact--body {
  margin-block: var(--s-1);
  padding: var(--s-1) 0 var(--s-1) var(--s-3);
  border-left: 1px solid var(--hairline-strong);
  color: var(--ink-1);
  white-space: pre-wrap;
}

.proposal-fact--expiry {
  color: var(--ink-3);
  font-size: var(--fs-small);
}

/* A mail is told apart by its subject: it leads the card, the kind of mail steps back. */
.proposal-card--mail .proposal-fact--subject {
  order: -1;
  font-size: var(--fs-lead);
  font-weight: 600;
  color: var(--ink-1);
}

.proposal-card--mail .proposal-fact--subject .proposal-fact__label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.proposal-card--mail .proposal-fact--what {
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--ink-2);
}

.proposal-more .proposal-description--full {
  margin-top: var(--s-2);
  font-size: var(--fs-small);
  color: var(--ink-2);
}

.proposal-details {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--s-1) var(--s-4);
  font-size: var(--fs-small);
}

.proposal-details dt {
  color: var(--ink-3);
}

.proposal-details dd {
  color: var(--ink-1);
  overflow-wrap: anywhere;
}

.proposal-result {
  padding: var(--s-3);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  font-size: var(--fs-small);
  overflow-wrap: anywhere;
}

/* A confirmed outcome reads as one: tinted, a check, the sentence in full weight. */
.proposal-result.tone-ok {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  background: rgba(var(--ok-rgb), 0.1);
  box-shadow: inset 0 0 0 1px rgba(var(--ok-rgb), 0.2);
  color: var(--ok);
  font-size: var(--fs-body);
  font-weight: 600;
}

.proposal-result.tone-ok::before {
  content: '';
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Cpath d='m8.5 12.3 2.3 2.3 4.7-4.9'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Cpath d='m8.5 12.3 2.3 2.3 4.7-4.9'/%3E%3C/svg%3E") center / contain no-repeat;
}

.proposal-result.tone-error {
  background: rgba(var(--error-rgb), 0.08);
  color: var(--error);
}

/* Outcome unknown (timeout): amber, the owner has to look -- never the red of "nothing happened". */
.proposal-result.tone-unclear {
  background: rgba(var(--warn-rgb), 0.08);
  box-shadow: inset 0 0 0 1px rgba(var(--warn-rgb), 0.2);
  color: var(--warn);
}

.proposal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
}

.proposal-actions button {
  min-height: 44px; /* comfortable touch target */
  font-size: var(--fs-small);
}

.proposal-approve-btn {
  background: var(--light-cyan);
  color: var(--ink-on-light);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), var(--glow-2);
  font-weight: 600;
}

.proposal-execute-btn {
  background: var(--ok);
  color: var(--ink-on-light);
  font-weight: 600;
}

/* D34: a DELETE reads as one -- rosé (the app's "problem/irreversible" tone), in words AND
   colour ("Termin löschen", "Löschen genehmigen", "Jetzt löschen"), never the friendly cyan/green. */
.proposal-card--destructive .proposal-title {
  color: var(--error);
}

.proposal-card--destructive.status-pending,
.proposal-card--destructive.status-executing {
  background: linear-gradient(180deg, rgba(var(--error-rgb), 0.1), var(--night-2) 70%);
  box-shadow: inset 0 1px 0 rgba(var(--error-rgb), 0.3), inset 0 0 0 1px rgba(var(--error-rgb), 0.2);
}

.proposal-card--destructive .proposal-approve-btn,
.proposal-card--destructive .proposal-execute-btn {
  background: var(--error);
  color: var(--ink-on-light);
  box-shadow: none;
}

.proposal-fact--destructive {
  color: var(--error);
  font-weight: 600;
}

.proposal-reject-btn {
  background: transparent;
  color: var(--ink-2);
  box-shadow: inset 0 0 0 1px var(--hairline-strong);
}

.proposal-lifecycle,
.proposal-more {
  font-size: var(--fs-small);
  color: var(--ink-3);
}

.proposal-lifecycle summary,
.proposal-more summary {
  cursor: pointer;
  min-height: 2rem;
  display: flex;
  align-items: center;
}

.proposal-more .proposal-details {
  margin-top: var(--s-2);
}

.proposal-lifecycle ol {
  margin-top: var(--s-2);
  padding-left: 1.1rem;
}

/* Connector row (UX polish 2026-10-26): the name, and on the right, dimmed, what Ghost may do with
   it. A problem replaces that with the rosé "Nicht verbunden" and its one action below. */
.connection-capability {
  font-size: var(--fs-caption);
  color: var(--ink-3);
}

/* --- Stage: hero, context, chat, approvals ---------------------------- */

html,
body {
  height: 100%;
}

body {
  height: 100dvh;
  overflow: hidden;
}

/* Faint stars: static, sparse, never the subject. */
.sky::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(70% 46% at 50% 24%, color-mix(in srgb, var(--orb-color) 13%, transparent), transparent 72%);
}

.sky {
  position: fixed;
  inset: 0;
  z-index: var(--z-base);
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 8% 14%, rgba(190, 220, 255, 0.65), transparent 60%),
    radial-gradient(1px 1px at 22% 38%, rgba(190, 220, 255, 0.4), transparent 60%),
    radial-gradient(1.5px 1.5px at 35% 9%, rgba(190, 220, 255, 0.55), transparent 60%),
    radial-gradient(1px 1px at 51% 27%, rgba(190, 220, 255, 0.35), transparent 60%),
    radial-gradient(1px 1px at 63% 12%, rgba(190, 220, 255, 0.6), transparent 60%),
    radial-gradient(1.5px 1.5px at 78% 33%, rgba(190, 220, 255, 0.45), transparent 60%),
    radial-gradient(1px 1px at 91% 19%, rgba(190, 220, 255, 0.6), transparent 60%),
    radial-gradient(1px 1px at 15% 62%, rgba(190, 220, 255, 0.3), transparent 60%),
    radial-gradient(1px 1px at 86% 58%, rgba(190, 220, 255, 0.3), transparent 60%),
    radial-gradient(1px 1px at 44% 71%, rgba(190, 220, 255, 0.25), transparent 60%);
}

main {
  position: relative;
  z-index: var(--z-raised);
}

main {
  overflow-x: hidden;
  overflow-y: auto;
}

#login-view {
  margin: auto;
  padding-top: var(--s-6);
}

/* Signed out: the logo takes the centre of the screen, at any viewport width
   (the login topbar is not gated to mobile the way the signed-in one is). */
body:has(#login-view:not(.hidden)) header#topbar {
  justify-content: center;
}

body:has(#login-view:not(.hidden)) header#topbar .brand {
  flex: none;
}

body:has(#login-view:not(.hidden)) header#topbar .brand__logo {
  max-width: 168px;
}

#stage:focus,
#stage:focus-visible {
  outline: none; /* focus target of the skip link, not a control */
}

#stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + var(--s-4));
}

.hero {
  --orb-size: min(88vw, 38dvh, 24rem);
  --hero-top: calc(3.25rem + var(--safe-top));
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
  padding: var(--hero-top) var(--s-4) var(--s-4);
  text-align: center;
}

/* The character master has empty margin around the figure; pull the scene
   together so the greeting reads as the character's own line, not a caption. */
.hero > .orb {
  margin: calc(var(--orb-size) * -0.05) 0 calc(var(--orb-size) * -0.1);
}

/* The character lights its own scene: a wide pool of the current light behind
   it, so the figure is the source of light rather than an image on a background. */
.hero::before {
  content: '';
  position: absolute;
  left: 50%;
  top: calc(var(--hero-top) + var(--orb-size) * 0.5);
  width: 150%;
  aspect-ratio: 1.3;
  transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, color-mix(in srgb, var(--orb-color) 14%, transparent), transparent);
  pointer-events: none;
}

.hero > *:not(.hero__horizon) {
  position: relative;
  z-index: 1;
}

/* A planet's limb behind the greeting. Its light takes the orb's current
   colour, so the whole scene shifts with the voice state. */
.hero__horizon {
  position: absolute;
  left: 0;
  right: 0;
  /* The limb sits just above the greeting, so the greeting stands on the planet's face:
     greeting top = hero-top + orb x 0.85 + gap; the disc starts 3rem below this box. */
  top: calc(var(--hero-top) + var(--orb-size) * 0.85 - 2.9rem);
  height: 11rem;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  -webkit-mask-image: radial-gradient(75% 100% at 50% 0, #000 30%, transparent 100%);
  mask-image: radial-gradient(75% 100% at 50% 0, #000 30%, transparent 100%);
}

.hero__horizon::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 3rem;
  width: 190%;
  aspect-ratio: 1;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(2, 6, 13, 0.96) 97%, color-mix(in srgb, var(--orb-color) 50%, transparent) 100%);
  box-shadow:
    0 -1px 0 color-mix(in srgb, var(--orb-color-2) 60%, transparent),
    0 -18px 46px color-mix(in srgb, var(--orb-color) 32%, transparent);
}

.hero__horizon::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 2.2rem;
  width: 72%;
  height: 5rem;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, color-mix(in srgb, var(--orb-color) 30%, transparent), transparent);
}

/* The greeting IS the primary line of the Start scene: same size, line-height and weight tokens as
   the working primary (--wp-*, stage.css), and a box that already holds the icon track above it and
   the room the stage copy's other lines take -- so "Guten Morgen" -> "Ich lese die Mail." changes
   the words, not the geometry (Phase C.1). */
.hero__greeting {
  box-sizing: border-box;
  margin-top: var(--s-2);
  padding-top: var(--wp-icon);
  height: calc(var(--wp-block) - var(--wp-meta));
  font-size: var(--wp-pri-size);
  font-weight: var(--wp-pri-weight);
  line-height: var(--wp-pri-lh);
  letter-spacing: -0.005em;
}

.hero .voice-panel {
  margin-top: var(--s-1);
}

.rail {
  order: 1;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: 0 var(--s-4);
}

.approval-strip {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: 3.5rem;
  padding: 0 var(--s-4);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(var(--warn-rgb), 0.15), rgba(var(--warn-rgb), 0.06));
  box-shadow: inset 0 1px 0 rgba(var(--warn-rgb), 0.3), inset 0 0 0 1px rgba(var(--warn-rgb), 0.18);
  color: var(--ink-1);
  font-weight: 500;
  text-align: left;
}

.approval-strip .icon {
  color: var(--warn);
}

.approval-strip .icon--chev {
  color: var(--ink-3);
}

.tool-buttons {
  order: 2;
  display: grid;
  /* Phone: four quick actions in one row (D47 adds "Neue Mail"). */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s-3); /* ~12pt around bezeled controls (accessibility.md) */
  margin: var(--s-3) var(--s-4) 0;
}

.tool-buttons button {
  flex-direction: column;
  gap: 0.35rem;
  min-height: 4.25rem;
  padding: var(--s-2) 0.25rem;
  border-radius: var(--r-md);
  background: var(--surface-1);
  color: var(--ink-2);
  font-size: var(--fs-small);
  font-weight: 400;
  line-height: 1.2;
  text-align: center;
}

/* --- Chat -------------------------------------------------------------- */

#chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: var(--s-3) var(--s-4) 0;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding-bottom: var(--s-3);
}

.chat-head__orb {
  flex: none;
  width: var(--touch);
  height: var(--touch);
  padding: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
}

.chat-head__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-head__title {
  font-size: var(--fs-lead);
  font-weight: 500;
  line-height: 1.2;
}

.chat-head__status {
  font-size: var(--fs-small);
  color: var(--ink-3);
}

/* Toolbar titles name the content, not the app; the voice line only shows while
   a voice session is not idle. */
.chat-head__title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

:root[data-voice='idle'] .chat-head__status {
  display: none;
}

#messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--s-2) 0 var(--s-3);
}

#messages:empty {
  display: none;
}

.chat-empty {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-6) var(--s-4);
  text-align: center;
}

#messages:empty + .chat-empty {
  display: flex;
}

.chat-empty__title {
  font-size: var(--fs-lead);
  font-weight: 500;
  color: var(--ink-2);
}

.chat-empty__hint {
  max-width: 24rem;
  color: var(--ink-3);
  font-size: var(--fs-small);
}

.msg {
  max-width: 85%;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: var(--lh-body);
}

/* The owner's words: a soft lit block, right-aligned. */
.msg.user {
  align-self: flex-end;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-lg) var(--r-lg) var(--s-1) var(--r-lg);
  background: rgba(var(--light-blue-rgb), 0.2);
  box-shadow: inset 0 1px 0 rgba(160, 200, 255, 0.22);
}

/* Ghost speaks in open type on the night -- no bubble, just a small light. */
.msg.assistant {
  align-self: flex-start;
  position: relative;
  padding: 0 0 0 var(--s-5);
  max-width: min(100%, 68ch);
}

.msg.assistant::before {
  content: '';
  position: absolute;
  left: 0.2rem;
  top: 0.6rem;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--light-cyan);
  box-shadow: 0 0 10px rgba(var(--light-cyan-rgb), 0.8);
}

/* Assistant markdown (chatMarkdown.js parses, app.js builds these elements
   via createElement/textContent only -- never innerHTML). Quiet typography:
   bold reads clearly but at the app's own 600 weight (not the browser
   default 700, which felt heavier than the rest of the UI); no docs/SaaS
   look -- no oversized headline styles, no rule lines, list markers muted
   instead of full-strength black-on-dark. Single soft line breaks within a
   paragraph already render correctly via the inherited
   .msg { white-space: pre-wrap } above -- no extra markup needed for those. */
.msg.assistant .text .md-p {
  margin: 0;
}

.msg.assistant .text .md-p + .md-p,
.msg.assistant .text .md-p + .md-list,
.msg.assistant .text .md-list + .md-p {
  margin-top: var(--s-3);
}

.msg.assistant .text .md-list {
  margin: var(--s-1) 0 0;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.msg.assistant .text .md-list + .md-list {
  margin-top: var(--s-3);
}

.msg.assistant .text .md-list li::marker {
  color: var(--ink-3);
}

.msg.assistant .text strong {
  font-weight: 600;
  color: var(--ink-1);
}

.msg.assistant .text code {
  padding: 0.05em 0.35em;
  border-radius: 5px;
  background: var(--surface-2);
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.9em;
}

.provenance {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: var(--s-2);
  font-size: var(--fs-caption);
  color: var(--ink-3);
}

.provenance::before {
  content: '';
  flex: none;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--ink-3);
}

.provenance.tone-ok::before { background: var(--ok); }
.provenance.tone-warn { color: var(--warn); }
.provenance.tone-warn::before { background: var(--warn); }
.provenance.tone-error { color: var(--error); }
.provenance.tone-error::before { background: var(--error); }

.provenance-message {
  margin-top: 2px;
  font-size: var(--fs-caption);
  color: var(--ink-3);
}

.provenance-message.tone-warn { color: var(--warn); }
.provenance-message.tone-error { color: var(--error); }

/* --- Working card (D32, Working Presence 2.0) --------------------------
   The assistant bubble's honest, live progress card for a deep text turn
   (public/workingCard.js). Standard material like the rest of the content
   layer (materials.md: "Don't use Liquid Glass in the content layer") -- a
   quiet lit card, never blurred glass, never dominant next to the Ghost
   figure. Desktop: title + up to 5 rows. Mobile (<=640px, see below): at
   most 3 rows, never taller than ~40% of the viewport. Motion stays to
   opacity/transform (a row's entrance, the note pulse) plus plain colour/
   background transitions for tone changes (cheap, paint-only, never a
   layout-thrashing property); a collapse is a content SWAP (the existing
   global .hidden utility -- instant, like every other disclosure in this
   app), never an animated height. */
.working-card {
  position: relative;
  margin: 0 0 var(--s-3);
  padding: var(--s-3);
  border-radius: var(--r-lg);
  background: var(--surface-card);
  box-shadow: inset 0 0 0 1px var(--edge-card), inset 0 1px 0 var(--highlight-top);
  font-size: var(--fs-small);
  color: var(--ink-2);
  --wc-accent: var(--light-cyan);
  transition: background var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}

.working-card.tone-done { --wc-accent: var(--ink-2); }
.working-card.tone-soft { --wc-accent: var(--ink-3); }
.working-card.tone-problem { --wc-accent: var(--error); }
.working-card.tone-decision { --wc-accent: var(--warn); }
.working-card.tone-pending { --wc-accent: var(--ink-3); }

.working-card__live {
  position: absolute;
}

.working-card__header {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  min-height: 1.5rem;
  padding: 0;
  background: transparent;
  box-shadow: none;
  text-align: left;
  font: inherit;
  color: var(--ink-1);
}

/* The acknowledgement is the "Ghost understood me" moment -- it may wrap to a
   second line on a phone instead of being cut off mid-sentence. */
.working-card__title {
  flex: 1;
  min-width: 0;
  font-weight: 500;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

/* A subtle chevron, not a button chrome -- flips when the card is collapsed
   (it is expanded/open by default, so the resting arrow already points down). */
.working-card__chevron {
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 1.5px solid var(--ink-3);
  border-bottom: 1.5px solid var(--ink-3);
  transform: rotate(45deg);
  transition: transform var(--dur-2) var(--ease-out);
}

.working-card.is-collapsed .working-card__chevron {
  transform: rotate(-45deg);
}

.working-card__status {
  margin-top: 2px;
  color: var(--wc-accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.working-card.is-live .working-card__status {
  /* Phase C: a live card keeps one line for the status (phase / outcome copy comes and
     goes between steps; the rows and the answer below must not follow it). */
  min-height: calc(var(--fs-small) * var(--lh-body));
}

.working-card.tone-running .working-card__status,
.working-card.tone-done .working-card__status,
.working-card.tone-soft .working-card__status,
.working-card.tone-pending .working-card__status {
  /* Only a genuine problem or a decision borrows the accent for body text
     (matches .provenance-message: everyday copy stays ink, not lit up). */
  color: var(--ink-3);
}

/* A transient "Ich bin noch dran." note (a status ping while busy) -- fades
   in/out with opacity only, never pushes the layout (position: absolute over
   the status line's row). */
.working-card__note {
  position: absolute;
  right: var(--s-3);
  bottom: var(--s-3);
  max-width: 60%;
  padding: 2px var(--s-2);
  border-radius: var(--r-pill);
  background: var(--surface-card-hover);
  color: var(--ink-2);
  font-size: var(--fs-caption);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateY(2px);
  pointer-events: none;
  transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
}

.working-card__note.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* A calm, one-shot pulse on the card itself when a status ping lands --
   colour/shadow only, no size change. */
.working-card.is-pulsing {
  box-shadow: inset 0 0 0 1px var(--hairline-strong), inset 0 1px 0 var(--highlight-top), 0 0 0 3px rgba(var(--light-cyan-rgb), 0.12);
}

.working-card__rows {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  margin: var(--s-2) 0 0;
  padding: 0;
  list-style: none;
}

.working-card__row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 1.5rem;
  animation: wc-row-in var(--dur-2) var(--ease-out);
}

@keyframes wc-row-in {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.working-card__icon {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.working-card__mark {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  font-size: 0.7rem;
  color: var(--wc-accent);
}

.working-card__row.tone-running .working-card__mark {
  color: var(--light-cyan);
}

.working-card__row.tone-decision .working-card__mark {
  color: var(--warn);
}

.working-card__row.tone-problem .working-card__mark {
  color: var(--error);
}

.working-card__row.tone-pending .working-card__mark {
  color: var(--ink-3);
  opacity: 0.7;
}

/* The one row actually running right now: a calm breathing dot -- opacity
   only, never a size change (never layout-affecting). */
.working-card__row.is-animated .working-card__mark {
  animation: wc-pulse 1.6s var(--ease-in-out) infinite;
}

@keyframes wc-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.working-card__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-2);
}

.working-card__row.tone-problem .working-card__label {
  color: var(--error);
}

.working-card__row.tone-decision .working-card__label {
  color: var(--warn);
}

.working-card__row.tone-pending .working-card__label {
  color: var(--ink-3);
}

.working-card__hidden {
  margin-top: var(--s-1);
  padding-left: calc(20px + 1rem + var(--s-2) + var(--s-2));
  color: var(--ink-3);
  font-size: var(--fs-caption);
}

.working-card.is-collapsed .working-card__rows,
.working-card.is-collapsed .working-card__hidden {
  display: none;
}

@media (max-width: 640px) {
  .working-card {
    max-height: 40vh;
    overflow-y: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .working-card__row {
    animation: none;
  }
  .working-card__row.is-animated .working-card__mark {
    animation: none;
  }
  .working-card__chevron,
  .working-card__note {
    transition: none;
  }
}

/* One calm line under #voice-status (voice.js, fed by voiceActivityLine.js):
   the same honest activity vocabulary as the working card, in voice's own
   single-line form. A small icon + label, muted ink (never the lit voice-
   status colours above it), at most one line, fades in/out with opacity only
   -- it must never compete with the status line or the CTA above it. */
.voice-activity {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  max-width: 24rem;
  min-height: 1.1rem;
  margin: -0.25rem auto 0;
  color: var(--ink-3);
  font-size: var(--fs-caption);
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease-out);
}

.voice-activity.is-visible,
.voice-activity[data-visible='true'] {
  opacity: 1;
}

.voice-activity .am {
  --am-size: 16px;
  flex: none;
}

.voice-activity__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .voice-activity {
    transition: none;
  }
}

/* A small "sending.../waiting..." marker under the owner's OWN bubble while a
   message is queued behind a running turn, or waiting out a 409 (another tab
   / a live voice turn already working in this conversation). */
.msg-queue-marker {
  display: block;
  margin-top: 2px;
  color: var(--ink-3);
  font-size: var(--fs-caption);
  font-style: italic;
}

form#composer {
  padding: var(--s-3) var(--s-4);
}

/* A single capsule (like a search field): the send action sits inside it and
   only appears once there is something to send. */
.composer__field {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  border-radius: 26px;
  background: var(--surface-1);
  box-shadow: inset 0 0 0 1px var(--hairline), inset 0 1px 0 var(--highlight-top);
  transition: box-shadow var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease-out);
}

.composer__field:focus-within {
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1.5px var(--light-cyan), var(--glow-1);
}

form#composer textarea {
  flex: 1;
  resize: none;
  min-height: var(--touch);
  max-height: 9rem;
  padding: 0.8rem 3.5rem 0.7rem var(--s-4);
  border-radius: 26px;
  background: transparent;
  box-shadow: none;
  line-height: 1.35;
}

form#composer textarea:focus-visible {
  background: transparent;
  box-shadow: none;
}

.composer__send {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 2rem;
  min-height: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 50%;
  background: var(--light-cyan);
  color: var(--ink-on-light);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
  transition: opacity var(--dur-1) var(--ease-out), transform 420ms var(--spring-soft);
}

/* Hit region stays 44pt although the visible disc is 32pt. */
.composer__send::after {
  content: '';
  position: absolute;
  inset: -6px;
}

.composer__send .icon {
  width: 1.1rem;
  height: 1.1rem;
  stroke-width: 2;
}

/* The moment there is text, Send becomes the one prominent action. */
.composer__field:has(textarea:not(:placeholder-shown)) .composer__send {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* Desktop shortcut hint (shown only with a fine pointer, while idle and empty). */
.composer__hint {
  display: none;
  position: absolute;
  right: var(--s-3);
  bottom: 0.7rem;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink-3);
  font: inherit;
  font-size: var(--fs-caption);
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .composer__hint {
    display: inline-flex;
  }
}

.composer__field:focus-within .composer__hint,
.composer__field:has(textarea:not(:placeholder-shown)) .composer__hint {
  display: none;
}

.error-banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  background: rgba(var(--error-rgb), 0.1);
  box-shadow: inset 0 0 0 1px rgba(var(--error-rgb), 0.22);
  color: var(--error);
  font-size: var(--fs-small);
}

#chat-error {
  margin-bottom: var(--s-2);
}

/* Post-OAuth return notice (§8): a calm one-line confirmation shown after the
   connector callback redirects cleanly back into the app. Same quiet material
   as the error banner, tinted by tone -- never a coloured side stripe. */
.connect-notice {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin: 0 auto var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  font-size: var(--fs-small);
}
.connect-notice.tone-ok {
  background: rgba(var(--ok-rgb), 0.1);
  box-shadow: inset 0 0 0 1px rgba(var(--ok-rgb), 0.22);
  color: var(--ok);
}
.connect-notice.tone-error {
  background: rgba(var(--error-rgb), 0.1);
  box-shadow: inset 0 0 0 1px rgba(var(--error-rgb), 0.22);
  color: var(--error);
}

.retry-btn {
  min-height: 2.25rem;
  background: rgba(var(--error-rgb), 0.18);
  color: var(--ink-1);
  font-size: var(--fs-small);
}

#logout-btn {
  align-self: flex-start;
  background: transparent;
  box-shadow: none;
  color: var(--ink-3);
  font-size: var(--fs-small);
}

/* --- Navigation -------------------------------------------------------- */

.nav-item {
  position: relative;
  background: transparent;
  box-shadow: none;
  color: var(--ink-3);
  font-weight: 500;
}

.nav-item[aria-current='page'] {
  color: var(--ink-1);
}

.nav-item[aria-current='page'] .icon {
  color: var(--light-cyan);
  filter: drop-shadow(0 0 7px rgba(var(--light-cyan-rgb), 0.6));
}

.nav-badge {
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  border-radius: var(--r-pill);
  background: var(--badge-bg, var(--warn));
  color: var(--ink-on-light);
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1.15rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* The dock (iOS): a floating tab capsule for the three destinations plus one
   separate accessory for the overlay -- tabs navigate, they don't act, so
   "Mehr" is not a tab. tab-bars.md: "Use a tab bar to support navigation, not to
   provide actions." Concentric radii: 32px dock, 6px inset, 26px lens. */
#bottom-nav {
  position: fixed;
  left: max(var(--s-3), var(--safe-left));
  right: max(var(--s-3), var(--safe-right));
  bottom: calc(var(--s-2) + var(--safe-bottom));
  z-index: var(--z-nav);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.dock__tabs,
.dock__more {
  position: relative;
  background: linear-gradient(180deg, rgba(14, 28, 52, 0.62), rgba(6, 13, 26, 0.72));
  -webkit-backdrop-filter: blur(26px) saturate(1.7);
  backdrop-filter: blur(26px) saturate(1.7);
  box-shadow: inset 0 1px 0 var(--highlight-top), 0 20px 44px -14px rgba(0, 0, 0, 0.85);
}

.dock__tabs {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 6px;
  border-radius: 32px;
}

.dock__more {
  flex: none;
  width: 64px;
  height: 64px;
  padding: 0;
  border-radius: 50%;
  color: var(--ink-2);
}

.dock__more[aria-expanded='true'] {
  color: var(--ink-1);
}

/* The selection lens slides between tabs on a spring: state, not decoration. */
.dock__lens {
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 6px;
  width: calc((100% - 12px) / 3);
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(120, 170, 255, 0.22), rgba(120, 170, 255, 0.09));
  box-shadow: inset 0 1px 0 rgba(200, 225, 255, 0.26);
  transform: translateX(calc(var(--i, 0) * 100%));
  transition: transform 560ms var(--spring-soft);
}

#bottom-nav[data-active='1'] .dock__lens { --i: 1; }
#bottom-nav[data-active='2'] .dock__lens { --i: 2; }

#bottom-nav .nav-item {
  z-index: 1;
  flex-direction: column;
  gap: 3px;
  min-height: 52px;
  padding: 0;
  border-radius: 26px;
  font-size: 12px; /* fixed, like the system tab bar */
  white-space: nowrap;
}

#bottom-nav .nav-item .icon {
  width: 22px;
  height: 22px;
}

/* Filled symbols for the selected tab (tab-bars.md: "Prefer filled symbols"). */
#bottom-nav .nav-item[aria-current='page'] .icon {
  fill: color-mix(in srgb, currentColor 32%, transparent);
}

.nav-badge--person {
  --badge-bg: var(--light-cyan);
}

#bottom-nav .nav-badge {
  position: absolute;
  top: 4px;
  left: calc(50% + 6px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  line-height: 18px;
}

.side-nav .nav-item {
  justify-content: flex-start;
  gap: var(--s-3);
  width: 100%;
  min-height: var(--touch);
  padding: 0 var(--s-3);
  border-radius: var(--r-md);
  color: var(--ink-2);
}

.side-nav .nav-item[aria-current='page'] {
  background: linear-gradient(180deg, rgba(var(--light-blue-rgb), 0.24), rgba(var(--light-blue-rgb), 0.1));
  box-shadow: inset 0 1px 0 rgba(160, 200, 255, 0.28), 0 0 26px -6px rgba(var(--light-blue-rgb), 0.5);
}

.side-nav .nav-badge {
  margin-left: auto;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-brand {
  display: flex;
  padding: var(--s-2) var(--s-3) var(--s-3);
}

.side-brand__logo {
  max-width: 150px; /* desktop/tablet sidebar, >=769px */
}

.side-heading {
  padding: 0 var(--s-3);
  margin-bottom: var(--s-2);
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--ink-3);
}

.sheet-close,
.sheet-bar,
#sidebar > .segmented {
  display: none;
}

.sheet-body {
  display: contents;
}

/* --- View switching: one destination at a time below 1100px ------------ */

#app-shell[data-view='home'] :is(#chat-view, #composer, #approvals),
#app-shell[data-view='chat'] :is(.hero, .tool-buttons, .rail),
#app-shell[data-view='approvals'] :is(.hero, .tool-buttons, #chat-view, #composer, #approval-strip, #daily-brief) {
  display: none;
}

#app-shell[data-view='chat'] #stage {
  overflow: hidden;
}

#app-shell[data-view='approvals'] .approvals-body {
  max-height: none;
}

/* Freigaben as a destination: a real title, and a stored draft as wide as the proposals beside it. */
#app-shell[data-view='approvals'] .approvals-toggle-btn {
  font-size: var(--fs-title);
  font-weight: 600;
}

.approval-draft .mail-draft-card {
  max-width: none;
  margin: 0;
  padding: var(--s-4);
  border-radius: var(--r-md);
}

#app-shell[data-view='approvals'] .approvals {
  margin-top: calc(var(--s-4) + var(--safe-top));
  /* Final polish (D66): the destination has no outer frame. Title and filter stand on the stage,
     the cards are the only boxes (one container level instead of three). */
  background: none;
  box-shadow: none;
}

#app-shell[data-view='approvals'] .approvals-header,
#app-shell[data-view='approvals'] .approvals-body {
  padding-inline: 0;
}

/* --- Mobile: <= 768px --------------------------------------------------- */

@media (max-width: 768px) {
  body:has(#app-shell:not(.hidden):not([data-view='home'])) header#topbar {
    display: none;
  }

  /* The sidebar becomes a bottom sheet (sheets.md): a grabber, a title with a
     leading Close, two detents (medium / large), swipe to dismiss. Content is
     two closely related panels behind a segmented control: Verlauf | System. */
  #sidebar {
    --sheet-offset: 34dvh; /* medium detent: the sheet rests ~56% high */
    position: fixed;
    left: 0;
    right: 0;
    bottom: -1rem; /* extends below the edge so a spring overshoot never shows a gap */
    z-index: var(--z-sheet);
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    width: auto;
    height: calc(90dvh + 1rem);
    padding: 0 var(--s-4) 1rem;
    overflow: hidden;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    background: linear-gradient(180deg, rgba(14, 28, 52, 0.84), rgba(6, 13, 26, 0.95));
    -webkit-backdrop-filter: blur(30px) saturate(1.6);
    backdrop-filter: blur(30px) saturate(1.6);
    box-shadow: inset 0 1px 0 var(--highlight-top), 0 -30px 70px -20px rgba(0, 0, 0, 0.95);
    transform: translateY(105%);
    visibility: hidden;
    /* Exit is faster than enter (emil-design-eng / motion.md: brief, cancellable). */
    transition: transform var(--dur-2) var(--ease-drawer), visibility 0s linear var(--dur-2);
  }

  #sidebar.open {
    transform: translateY(var(--sheet-offset));
    visibility: visible;
    transition: transform 520ms var(--spring-snappy), visibility 0s;
  }

  #sidebar.open[data-detent='large'] {
    --sheet-offset: 0px;
  }

  #sidebar.dragging {
    transition: none;
  }

  .sheet-grabber {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2;
    height: 2.25rem;
    touch-action: none;
    cursor: grab;
  }

  #sidebar::before {
    content: '';
    position: absolute;
    top: 0.5rem;
    left: 50%;
    width: 2.25rem;
    height: 4px;
    margin-left: -1.125rem;
    border-radius: 2px;
    background: var(--hairline-strong);
  }

  .sheet-bar {
    display: grid;
    grid-template-columns: var(--touch) 1fr var(--touch);
    align-items: center;
    margin-top: 1.5rem;
  }

  .sheet-title {
    grid-column: 2;
    text-align: center;
    font-size: var(--fs-body);
    font-weight: 600;
  }

  .sheet-close {
    display: inline-flex;
    grid-column: 1;
    grid-row: 1;
    background: var(--surface-2);
    color: var(--ink-2);
  }

  #sidebar > .segmented {
    display: grid;
    flex: none;
  }

  .sheet-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: var(--s-4);
    min-height: 0;
    overflow-y: auto;
    padding-bottom: calc(var(--s-4) + var(--safe-bottom));
  }

  /* At the medium detent the lower part of the sheet is off screen; keep the
     content scrollable into view. */
  #sidebar.open:not([data-detent='large']) .sheet-body {
    padding-bottom: calc(var(--sheet-offset) + var(--s-4) + var(--safe-bottom));
  }

  .sheet-body .side-heading {
    display: none;
  }

  #sidebar:not([data-segment='system']) [data-segment-panel='system'],
  #sidebar[data-segment='system'] [data-segment-panel='history'] {
    display: none;
  }

  .side-brand,
  .side-nav {
    display: none;
  }

  #status-panel {
    margin-top: 0;
  }

  .msg {
    max-width: 92%;
  }

  /* With the keyboard up, the nav steps aside. */
  body:has(#message-input:focus) #bottom-nav {
    display: none;
  }

  body:has(#message-input:focus) #stage {
    padding-bottom: var(--s-2);
  }

  a.src,
  .rail-connect {
    display: inline-flex;
    align-items: center;
    min-height: var(--touch);
  }

  .proposal-details {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .proposal-details dd {
    margin-bottom: var(--s-2);
  }

  .proposal-actions button {
    flex: 1 1 0;
  }

  /* The decision stays reachable while the owner reads the details above it. */
  .proposal-card.status-pending .proposal-actions,
  .proposal-card.status-approved .proposal-actions {
    position: sticky;
    bottom: calc(var(--nav-height) + var(--safe-bottom) + var(--s-2));
    z-index: var(--z-raised);
    margin: 0 calc(var(--s-2) * -1);
    padding: var(--s-3) var(--s-2) var(--s-1);
    border-radius: var(--r-md);
    background: linear-gradient(180deg, rgba(8, 17, 31, 0), var(--night-2) 34%);
  }

  .connection-connect-link {
    min-height: var(--touch);
  }
}

/* --- Desktop and tablet: >= 769px --------------------------------------- */

@media (min-width: 769px) {
  #menu-toggle-btn,
  #bottom-nav,
  #sidebar-backdrop {
    display: none;
  }

  body:has(#app-shell:not(.hidden)) header#topbar {
    display: none;
  }

  #sidebar {
    padding: var(--s-5) var(--s-3) var(--s-4);
    gap: var(--s-3);
    overflow: hidden;
  }

  .conversations {
    flex: 1;
    min-height: 6rem;
    overflow-y: auto;
    scrollbar-width: thin;
    -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 2rem), transparent);
    mask-image: linear-gradient(180deg, #000 calc(100% - 2rem), transparent);
  }

  .conversations + #status-panel {
    margin-top: 0;
  }

  .connection-row {
    min-height: 1.75rem;
  }

  #stage {
    align-items: center;
    padding: var(--s-5) var(--s-6);
  }

  #stage > .hero,
  #stage > .tool-buttons,
  #stage > .rail,
  #stage > #chat-view,
  #stage > #composer {
    width: 100%;
    max-width: 46rem;
  }

  .hero {
    --orb-size: min(40vw, 50dvh, 30rem);
    --hero-top: var(--s-4);
    padding: var(--hero-top) 0 var(--s-5);
  }

  /* The desktop sidebar is vibrancy, not a solid panel: the scene's light shows through. */
  #sidebar {
    background: linear-gradient(180deg, rgba(2, 6, 13, 0.86), rgba(5, 11, 23, 0.74));
    -webkit-backdrop-filter: blur(30px) saturate(1.5);
    backdrop-filter: blur(30px) saturate(1.5);
  }

  .tool-buttons,
  .rail {
    margin-inline: 0;
    padding: 0;
  }

  .tool-buttons {
    order: 1;
    grid-template-columns: repeat(3, minmax(0, 15rem));
    justify-content: center;
    margin-top: 0;
  }

  #write-btn {
    display: none;
  }

  #stage > .rail {
    order: 2;
  }

  .tool-buttons button {
    flex-direction: row;
    min-height: var(--touch);
    border-radius: var(--r-pill);
    padding: 0 var(--s-4);
  }

  /* The command bar: Ghost's text input sits under the voice call to action. */
  #app-shell[data-view='home'] #composer {
    display: flex;
  }

  #stage > #composer {
    padding: var(--s-4) 0 var(--s-3);
  }

  #chat-view {
    padding: 0;
  }

  .hero .voice-panel {
    gap: var(--s-3);
  }
}

/* --- Control Room: >= 1100px -- Ghost centred, context on the rail ------- */

@media (min-width: 1100px) {
  #stage {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--rail-width);
    grid-template-rows: 1fr auto auto auto 1fr;
    column-gap: var(--s-6);
    justify-items: center;
    align-items: start;
    padding: 0 var(--s-6);
    overflow-y: auto;
  }

  #stage > .hero { grid-column: 1; grid-row: 2; }
  #stage > #composer { grid-column: 1; grid-row: 3; }
  #stage > .tool-buttons { grid-column: 1; grid-row: 4; }
  #stage > #chat-view { grid-column: 1; grid-row: 1; min-height: 0; height: 100%; }

  /* The rail: today's context, always in view, scrolling on its own. */
  #stage > .rail {
    grid-column: 2;
    grid-row: 1 / -1;
    position: sticky;
    top: 0;
    align-self: start;
    justify-self: stretch;
    max-width: none;
    max-height: 100dvh;
    overflow-y: auto;
    padding: var(--s-5) 0;
    gap: var(--s-4);
    scrollbar-width: thin;
  }

  .rail #approval-strip {
    display: none;
  }

  /* On Start and Chat an open approval shows as one line in "Braucht
     Aufmerksamkeit" (the Heute card), leading to Freigaben; the cards with
     their decisions live only in the Freigaben destination. */
  #app-shell:not([data-view='approvals']) .rail #approvals {
    display: none;
  }

  #app-shell[data-view='chat'] .rail {
    display: flex;
  }

  #app-shell[data-view='chat'] #stage {
    grid-template-rows: minmax(0, 1fr) auto;
    height: 100%;
    padding-top: var(--s-5);
    overflow: hidden;
  }

  #app-shell[data-view='chat'] #stage > #composer {
    grid-row: 2;
  }

  /* Freigaben as a full destination: the decision takes the centre, the brief stays on the rail. */
  #app-shell[data-view='approvals'] .rail {
    display: contents;
  }

  #app-shell[data-view='approvals'] #stage {
    grid-template-rows: 1fr;
  }

  #app-shell[data-view='approvals'] #approvals {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    max-width: 46rem;
    margin-top: var(--s-5);
    align-self: start;
  }

  #app-shell[data-view='approvals'] #daily-brief {
    display: block;
    grid-column: 2;
    grid-row: 1;
    align-self: start;
    justify-self: stretch;
    margin-top: var(--s-5);
  }

  /* One scroller on the rail: the rail itself, never a scroller inside it. */
  .rail .approvals-body {
    max-height: none;
    overflow-y: visible;
  }

  /* The rail card is permanent: "Heute" and the date are its title, not a toggle. */
  .rail .daily-brief-toggle-btn {
    grid-template-columns: minmax(0, 1fr);
    min-height: 3.5rem;
    padding-left: var(--s-4);
    cursor: default;
  }

  .rail .daily-brief-toggle-btn:active {
    transform: none;
  }

  .rail .daily-brief-toggle-btn :is(.brief-icon, .brief-chev) {
    display: none;
  }
}

@media (min-width: 1100px) and (max-height: 700px) {
  #app-shell[data-view='chat'] #stage {
    overflow-y: auto;
  }
}

/* --- Wide: >= 1600px ---------------------------------------------------- */

@media (min-width: 1600px) {
  :root {
    --sidebar-width: 17rem;
    --rail-width: 26rem;
  }

  .hero {
    --orb-size: min(26vw, 52dvh, 34rem);
  }
}

.brief-head__value,
.daily-brief-list,
.conversation-timestamp,
.daily-brief-timestamp,
.proposal-details dd,
.nav-badge,
.approvals-count {
  font-variant-numeric: tabular-nums;
}

/* --- Segmented control ---------------------------------------------------
   segmented-controls.md: "Use a segmented control to provide closely related
   choices that affect an object, state, or view", equal widths, nouns as labels.
   Used for Verlauf | System in the sheet and Offen | Alle for the approvals. */

.segmented {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n, 2), 1fr);
  padding: 3px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--hairline);
}

.segmented__thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / var(--n, 2));
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, rgba(200, 225, 255, 0.22), rgba(120, 170, 255, 0.15));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 2px 8px rgba(0, 0, 0, 0.35);
  transform: translateX(calc(var(--i, 0) * 100%));
  transition: transform 460ms var(--spring-snappy);
}

.segmented[data-index='1'] { --i: 1; }
.segmented[data-index='2'] { --i: 2; }

.segmented button {
  position: relative;
  z-index: 1;
  min-height: 2.375rem;
  background: transparent;
  box-shadow: none;
  color: var(--ink-2);
  font-size: var(--fs-small);
  font-weight: 500;
}

.segmented button[aria-selected='true'] {
  color: var(--ink-1);
  font-weight: 600;
}

/* Approvals: the filter is presentation only -- the list is always fully rendered. */
#approvals[data-filter='open'] .proposal-card:not(.status-pending, .status-approved, .status-executing) {
  display: none;
}

/* Under "Offen" a waiting card needs no "Wartet auf Freigabe": the filter says it (D66). "Alle" keeps it. */
#approvals[data-filter='open'] .proposal-card.status-pending .proposal-status {
  display: none;
}

.approvals-none-open {
  display: none;
}

#approvals[data-filter='open']:not(:has(.status-pending, .status-approved, .status-executing)) .approvals-none-open {
  display: flex;
}

/* Never two "Alles erledigt": with an empty list the list's own state speaks. */
#approvals:has(#approvals-empty:not(.hidden)) .approvals-none-open {
  display: none;
}

/* An action that takes a moment shows an activity indicator inside its button
   (buttons.md, iOS: "Configure a button to display an activity indicator"). */
.proposal-card[data-busy] button:disabled {
  cursor: progress;
}

.proposal-card[data-busy='approve'] .proposal-approve-btn::after,
.proposal-card[data-busy='execute'] .proposal-execute-btn::after {
  content: '';
  width: 1rem;
  height: 1rem;
  margin-left: var(--s-1);
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- View change: a short settle, never a sequence ---------------------- */

@keyframes view-in {
  from {
    opacity: 0;
  }
}

#app-shell :is(.hero, .tool-buttons, .rail, #chat-view, #composer, #approvals) {
  animation: view-in 160ms var(--ease-out) backwards;
}

/* --- Skip link ---------------------------------------------------------- */

.skip-link {
  position: absolute;
  top: var(--s-2);
  left: var(--s-2);
  z-index: calc(var(--z-sheet) + 10);
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-pill);
  background: var(--night-3);
  color: var(--ink-1);
  box-shadow: inset 0 0 0 1px var(--hairline-strong);
  transform: translateY(-200%);
}

.skip-link:focus-visible {
  transform: none;
}

body:has(#app-shell.hidden) .skip-link {
  display: none;
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  /* The sheet crossfades instead of travelling. */
  #sidebar {
    transform: none;
    opacity: 0;
  }

  #sidebar.open {
    opacity: 1;
  }
}

/* --- Scroll edge effect (mobile) ------------------------------------------
   layout.md: "Instead of a background, use a scroll edge effect to provide a
   transition between content and the control area." Content fades where it
   meets the dock and the top edge; one effect per view; the chat scrolls
   inside its own frame and needs none. */

@media (max-width: 768px) {
  #app-shell:is([data-view='home'], [data-view='approvals']) #stage {
    -webkit-mask-image: linear-gradient(
      180deg,
      transparent 0,
      #000 calc(1.75rem + var(--safe-top)),
      #000 calc(100% - var(--nav-height) - 0.75rem),
      transparent calc(100% - var(--nav-height) + 1.25rem)
    );
    mask-image: linear-gradient(
      180deg,
      transparent 0,
      #000 calc(1.75rem + var(--safe-top)),
      #000 calc(100% - var(--nav-height) - 0.75rem),
      transparent calc(100% - var(--nav-height) + 1.25rem)
    );
  }
}

/* --- The figure recedes as the context scrolls in (progressive enhancement) --- */

@supports (animation-timeline: scroll()) {
  @keyframes orb-recede {
    to {
      transform: scale(0.84) translateY(-5%);
      opacity: 0.6;
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    #stage .hero .orb {
      animation: orb-recede linear both;
      animation-timeline: scroll(nearest block);
      animation-range: 0 260px;
    }
  }
}

/* --- Chat: the character's light reaches the conversation ---------------- */

#chat-view {
  position: relative;
}

#chat-view::before {
  content: '';
  position: absolute;
  top: -3rem;
  left: 50%;
  width: min(120%, 44rem);
  height: 15rem;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, color-mix(in srgb, var(--orb-color) 13%, transparent), transparent);
  pointer-events: none;
  z-index: -1;
}

.chat-head__orb {
  width: 3.25rem;
  height: 3.25rem;
}

.chat-head .orb--mini {
  --orb-size: 3rem;
}

/* --- Sheet grabber (mobile): drag down to dismiss ------------------------- */

.sheet-grabber {
  display: none;
}

/* --- Hover: only on devices that really hover (touch taps must not stick) --- */

@media (hover: hover) and (pointer: fine) {
  button:hover {
    background: var(--surface-3);
  }

  .btn-primary:hover {
    background: #8fe3ff;
  }

  .btn-quiet:hover {
    background: var(--surface-1);
    color: var(--ink-1);
  }

  #conversation-list li:hover {
    background: var(--surface-1);
  }

  .daily-brief-toggle-btn:hover {
    background: var(--surface-1);
  }

  .external-chat-list li[role='button']:hover {
    background: var(--surface-1);
  }

  .ti--action:hover {
    background: var(--surface-card-hover);
  }

  .approvals-toggle-btn:hover {
    background: var(--surface-1);
  }

  .proposal-approve-btn:hover {
    background: #8fe3ff;
  }

  .proposal-execute-btn:hover {
    background: #8af0c8;
  }

  .proposal-card--destructive .proposal-approve-btn:hover,
  .proposal-card--destructive .proposal-execute-btn:hover {
    background: #ffa9b3;
  }

  .approval-strip:hover {
    background: linear-gradient(180deg, rgba(var(--warn-rgb), 0.2), rgba(var(--warn-rgb), 0.09));
  }

  .tool-buttons button:hover {
    color: var(--ink-1);
  }

  #logout-btn:hover {
    color: var(--ink-1);
  }

  .nav-item:hover {
    background: var(--surface-1);
    color: var(--ink-1);
  }
}

/* --- Reduce Transparency: the floating layer becomes opaque -----------------
   Last in the cascade on purpose, so it wins over every glass rule above. */
@media (prefers-reduced-transparency: reduce) {
  .dock__tabs,
  .dock__more,
  #sidebar {
    background: var(--night-3);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .dock__tabs::before,
  .dock__more::before {
    opacity: 0.5;
  }
}

/* --- Drive media card (Drive Media Preview) -----------------------------
   A quiet, Apple-adjacent card for an image Ghost found in Drive: a stable
   framed thumbnail (no layout shift -- the frame reserves its box via
   aspect-ratio before the image loads), the file name, and two calm actions.
   Capped width so it looks right at half a desktop window, full width on a
   phone. All controls keep a 44px touch target. */
.media-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: min(360px, 100%);
  margin: 6px 0 2px;
  padding: 10px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  box-sizing: border-box;
}

.media-card__frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;           /* reserves the box before load -> no shift */
  overflow: hidden;
  border-radius: var(--r-md);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;             /* preserves aspect ratio (no stretch) */
  display: block;
}

.media-card__frame--broken {
  font-size: 13px;
  color: var(--ink-3);
  padding: 12px;
  text-align: center;
}

.media-card__name {
  font-size: 13px;
  line-height: 1.3;
  color: var(--ink-2);
  /* one clean line; a cryptic long name never blows out the card */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-card__actions {
  display: flex;
  gap: 8px;
}

.media-card__btn {
  flex: 1;
  min-height: var(--touch);
  padding: 0 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--hairline-strong);
  background: var(--surface-2);
  color: var(--ink-1);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease;
}
.media-card__btn:hover { background: var(--surface-3); }
.media-card__btn:active { transform: scale(0.98); }

.media-card__btn--primary {
  background: var(--light-cyan);
  color: var(--ink-on-light);
  border-color: transparent;
}
.media-card__btn--primary:hover { background: var(--light-cyan); filter: brightness(1.05); }

/* No media-send channel yet: a calm, clearly-inactive state (never an error). */
.media-card__btn--disabled {
  background: transparent;
  color: var(--ink-3);
  border-color: var(--hairline);
  font-size: 13px;
  cursor: default;
}
.media-card__btn--disabled:hover { background: transparent; }
.media-card__btn--disabled:active { transform: none; }

/* Document card (Drive Document Preview): a PDF page-1 preview with a badge,
   a humanized title, a source/last-changed line, and Öffnen/Zusammenfassen. */
.media-card__frame--document {
  aspect-ratio: 3 / 4;             /* portrait: a document page, not a photo */
  max-height: 260px;
  background: var(--surface-2);
}
.media-card__frame--document .media-card__img {
  object-fit: contain;             /* show the whole page top-aligned, uncropped */
  object-position: top center;
}
.media-card__frame--document.media-card__frame--broken {
  aspect-ratio: 3 / 4;
  max-height: 200px;
}
.media-card__badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--light-cyan);
  color: var(--ink-on-light);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.media-card__meta {
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-card--document .media-card__name {
  white-space: normal;             /* a document title may wrap to two lines */
  font-weight: 600;
  color: var(--ink-1);
}

/* Larger in-app preview ("Öffnen") -- never a new Google tab. */
.media-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.media-lightbox.hidden { display: none; }
.media-lightbox__backdrop {
  position: absolute;
  inset: 0;
  /* A plain scrim, not glass: per the design rule, backdrop blur belongs only
     to the floating dock/sheet layer, never to a content overlay like this. */
  background: var(--scrim, rgba(2, 8, 18, 0.82));
}
.media-lightbox__stage {
  position: relative;
  margin: 0;
  max-width: min(920px, 92vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.media-lightbox__img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;           /* whole image, uncropped, in the open view */
  border-radius: var(--r-md);
  box-shadow: var(--shadow-3);
}
.media-lightbox__name {
  font-size: 13px;
  color: var(--ink-2);
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Inline PDF ("Öffnen" on a document card): the browser's own native viewer. */
.media-lightbox__stage--doc {
  width: min(920px, 92vw);
}
.media-lightbox__pdf {
  width: 100%;
  height: 80vh;
  border: 0;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-3);
  background: var(--surface-1);
}
.media-lightbox__close {
  position: absolute;
  top: -6px;
  right: -6px;
  width: var(--touch);
  height: var(--touch);
  border-radius: var(--r-pill);
  border: 1px solid var(--hairline-strong);
  background: var(--surface-3);
  color: var(--ink-1);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

/* The card is capped at a tasteful tile width on ALL sizes. On a phone
   (~360px content width) that cap is effectively the full available width;
   at half a desktop window (~700px, which this app already treats as its
   mobile breakpoint) it stays a calm tile rather than a full-bleed slab. */

/* --- Media overview chip (compact "N Medien" in the chat head) ------------
   Owner request: quickly see how many images a conversation holds and jump to
   them. A quiet pill, pushed to the trailing edge of the chat head; hidden when
   the conversation has no media. Small enough not to crowd a phone header. */
.media-strip {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 45%;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--hairline);
  background: var(--surface-1);
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.08s ease;
}
.media-strip:hover { background: var(--surface-2); }
.media-strip:active { transform: scale(0.97); }
.media-strip.hidden { display: none; }
.media-strip__icon { color: var(--ink-3); font-size: 12px; }
.media-strip__count {
  font-weight: 600;
  color: var(--ink-1);
}
.media-strip__label { color: var(--ink-3); }

/* Brief highlight when the chip jumps to a card. */
.media-card--flash {
  animation: media-card-flash 0.9s ease;
}
@keyframes media-card-flash {
  0%, 100% { box-shadow: var(--shadow-1); }
  30% { box-shadow: 0 0 0 2px var(--light-cyan), var(--shadow-2); }
}

@media (max-width: 768px) {
  /* Keep the label from crowding a narrow header: show the icon + count only. */
  .media-strip__label { display: none; }
  .media-strip { max-width: 40%; }
}

/* --- Externe Chats (D28): the owner reads along, read-only -------------
   Daily-driver polish: active contacts first, the quiet ones on one line, a
   cyan count for "a person wrote" (amber stays for approvals), a "Für dich"
   pill for a relay instead of a side stripe, and the time on the right. */

.external-chats {
  margin-bottom: var(--s-3);
}

.external-chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.external-chat-list li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: var(--touch);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease-out);
}
.external-chat-list li.active {
  background: var(--surface-2);
  box-shadow: inset 0 1px 0 var(--highlight-top);
}
.external-chat-list li.unread .conversation-title { font-weight: 600; }
.external-chat-list li.unread .external-chat__text { color: var(--ink-2); }
.external-chat__row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
}
.external-chat__row .conversation-title { min-width: 0; }
.external-chat__when {
  flex: none;
  margin-left: auto;
  font-size: var(--fs-caption);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.external-chat__relay {
  flex: none;
  padding: 0 0.45rem;
  border-radius: var(--r-pill);
  background: rgba(var(--light-cyan-rgb), 0.14);
  color: var(--light-cyan);
  font-size: var(--fs-caption);
  font-weight: 500;
  line-height: 1.35rem;
}
.external-chat__preview {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  font-size: var(--fs-caption);
  color: var(--ink-3);
}
.external-chat__preview .icon {
  width: 0.9rem;
  height: 0.9rem;
}
.external-chat__text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.external-chat__row .nav-badge { flex: none; margin-left: auto; }
.external-chat-list li.external-chat__quiet {
  min-height: 0;
  padding: var(--s-1) var(--s-3);
  font-size: var(--fs-caption);
  color: var(--ink-3);
  cursor: default;
}
.side-heading .nav-badge { margin-left: 0.35em; vertical-align: 0.1em; }
.dock__more { position: relative; }
.dock__more .nav-badge { position: absolute; top: 2px; right: 2px; }

/* Read-only: while an external chat is open there is no composer. */
#app-shell[data-external-chat] #composer { display: none; }

.external-chat-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-3);
  margin: 0 0 var(--s-3);
  padding: var(--s-2) var(--s-2) var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  font-size: var(--fs-small);
  color: var(--ink-3);
  background: var(--surface-2);
}
.external-chat-note__back {
  min-height: 2.25rem;
  padding: 0 var(--s-3);
  background: var(--surface-3);
  font-size: var(--fs-small);
}
.external-chat__empty { color: var(--ink-3); font-size: var(--fs-small); }

.msg-meta {
  margin-top: 4px;
  font-size: var(--fs-caption);
  color: var(--ink-3);
  white-space: normal;
}
.msg-meta .icon {
  width: 0.85rem;
  height: 0.85rem;
  margin-right: 0.2em;
  vertical-align: -0.14em;
}
/* A relay is a person's message for the owner: cyan, like every "someone wrote". */
.msg.relay {
  align-self: stretch;
  max-width: 100%;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  background: rgba(var(--light-cyan-rgb), 0.07);
  box-shadow: inset 0 0 0 1px rgba(var(--light-cyan-rgb), 0.22);
}
.msg.relay .msg-meta { margin: 0 0 4px; color: var(--light-cyan); }
.msg.relay.unread .msg-meta { font-weight: 600; }

.contact-ping {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + var(--s-3));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  max-width: min(92vw, 420px);
  padding: var(--s-2) var(--s-4);
  border: 0;
  border-radius: var(--r-pill);
  font: inherit;
  font-size: var(--fs-small);
  color: inherit;
  /* solid, not glass: glass stays in the dock/sheet layer (materials rule) */
  background: var(--night-3);
  box-shadow: inset 0 0 0 1px rgba(var(--light-cyan-rgb), 0.35), 0 6px 24px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.contact-ping .icon { color: var(--light-cyan); }
.contact-ping span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Two lists in "Chats": keep both headings visible, also in the mobile sheet,
   and let the (short) contact list take only the room it needs. */
.sheet-body .external-chats .side-heading,
.sheet-body .external-chats + .conversations .side-heading { display: block; }
.external-chats.conversations {
  flex: 0 0 auto;
  min-height: 0;
  overflow: visible;
  -webkit-mask-image: none;
  mask-image: none;
}


/* --- Customer Zero V1: setup steps for a provisioned customer instance (instanceSetup.js) -------
   Owner-only surfaces are hidden for a customer instance: the external chats (the owner's contacts),
   the club-mailbox "Neue Mail", the owner's generic connector list (the setup card replaces it), and
   voice when the instance has it switched off. The owner's deployment never gets data-instance. */
html[data-instance='customer'] #external-chats,
html[data-instance='customer'] #compose-btn,
html[data-instance='customer'] #contact-ping,
html[data-instance='customer'] #connections-list {
  display: none !important;
}
html[data-instance='customer'][data-voice='off'] .voice-panel {
  display: none !important;
}

#setup-home {
  width: min(100% - 2 * var(--s-4), 34rem);
  /* clear the absolutely positioned top bar (logo) */
  margin: calc(4.5rem + env(safe-area-inset-top, 0px)) auto var(--s-4);
}
#setup-system {
  margin-bottom: var(--s-4);
}

.setup-card {
  padding: var(--s-4);
  border-radius: var(--r-md);
  background: var(--surface-card);
  box-shadow: inset 0 0 0 1px var(--edge-card);
  color: var(--ink-2);
}
.setup-card__title {
  margin: 0 0 var(--s-2);
  font-size: 1.05rem;
  color: var(--ink-1);
}
.setup-card__lead,
.setup-card__note {
  margin: 0 0 var(--s-3);
  font-size: var(--fs-small);
  line-height: 1.45;
}
.setup-card__problem {
  margin: 0 0 var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  background: rgba(var(--warn-rgb), 0.1);
  color: var(--warn);
  font-size: var(--fs-small);
}
.setup-steps {
  list-style: none;
  margin: 0 0 var(--s-3);
  padding: 0;
  display: grid;
  gap: var(--s-3);
}
.setup-step {
  display: grid;
  grid-template-columns: 1.75rem 1fr;
  gap: var(--s-3);
  align-items: start;
}
.setup-step__mark {
  display: inline-grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  font-size: var(--fs-caption);
  background: var(--surface-2);
  color: var(--ink-2);
}
.setup-step--done .setup-step__mark {
  background: rgba(var(--ok-rgb), 0.16);
  color: var(--ok);
}
.setup-step__body {
  min-width: 0;
}
.setup-step__title {
  margin: 0.2rem 0 0;
  color: var(--ink-1);
  font-size: var(--fs-small);
}
.setup-step--done .setup-step__title {
  color: var(--ink-2);
}
.setup-step__why {
  margin: 0.2rem 0 0;
  font-size: var(--fs-caption);
  line-height: 1.4;
  color: var(--ink-3);
}
.setup-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem; /* 44 px touch target (Android/iOS) */
  margin-top: var(--s-2);
  padding: 0 var(--s-4);
  border: 0;
  border-radius: 999px;
  background: var(--light-blue);
  color: var(--ink-on-light);
  font: inherit;
  font-size: var(--fs-small);
  text-decoration: none;
  cursor: pointer;
}
.setup-btn--secondary {
  background: var(--surface-2);
  color: var(--ink-1);
  box-shadow: inset 0 0 0 1px var(--hairline-strong);
}
.setup-btn:focus-visible {
  outline: 2px solid var(--light-cyan);
  outline-offset: 2px;
}
.setup-btn[disabled] {
  opacity: 0.6;
  cursor: progress;
}
.setup-check {
  list-style: none;
  margin: var(--s-2) 0 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
  font-size: var(--fs-caption);
}
.setup-check .is-ok::before {
  content: '● ';
  color: var(--ok);
}
.setup-check .is-off::before {
  content: '● ';
  color: var(--error);
}
.setup-check-result {
  font-size: var(--fs-caption);
  margin-top: var(--s-2);
}

/* --- Chat sessions (D61): search, closed chats, digest ---------------------- */

.history-search {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: 0 var(--s-1) var(--s-2);
}

.history-search__input {
  flex: 1;
  min-width: 0;
  min-height: var(--touch);
  padding: 0 var(--s-3);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  color: var(--ink-1);
  border: 1px solid var(--hairline);
}

.history-search__filter {
  min-height: var(--touch);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  color: var(--ink-1);
  border: 1px solid var(--hairline);
}

.history-note {
  margin: 0 var(--s-1) var(--s-2);
  font-size: var(--fs-caption);
  color: var(--ink-2);
}

#conversation-list li.is-closed .conversation-title { color: var(--ink-2); }

.conversation-digest {
  font-size: var(--fs-caption);
  color: var(--ink-3);
}

.conversation-digest__topics { color: var(--light-cyan); }

.conversation-digest__summary {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tag-closed {
  display: inline-block;
  align-self: flex-start;
  padding: 2px var(--s-2);
  border-radius: var(--r-sm);
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface-2);
}

.chat-close-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: var(--touch);
  padding: 0 var(--s-3);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  color: var(--ink-1);
}

.chat-close-btn[aria-busy='true'] { opacity: 0.6; cursor: progress; }

/* D62: the chat's own microphone -- continues THIS chat by voice (the Start button opens a new one). */
.chat-voice-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  flex: none;
  min-height: var(--touch);
  padding: 0 var(--s-3);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  color: var(--ink-1);
}

.chat-voice-btn .icon--stop,
.chat-voice-btn[data-active='true'] .icon--mic {
  display: none;
}

.chat-voice-btn[data-active='true'] .icon--stop {
  display: inline-block;
}

.chat-voice-btn[data-active='true'] {
  background: rgba(var(--light-blue-rgb), 0.22);
  color: var(--ink-1);
  box-shadow: inset 0 0 0 1px rgba(var(--light-cyan-rgb), 0.45);
}

.chat-voice-btn[aria-disabled='true'] {
  opacity: 0.5;
}

#app-shell[data-external-chat] .chat-voice-btn {
  display: none;
}

@media (max-width: 480px) {
  .chat-voice-btn__label {
    display: none;
  }
}

.closed-chat-bar {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin: 0 var(--s-4) var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  background: var(--surface-1);
  box-shadow: inset 0 1px 0 var(--highlight-top);
}

.closed-chat-bar.hidden { display: none; }

.closed-chat-bar__tag { margin: 0; color: var(--ink-3); font-size: var(--fs-caption); }

.closed-chat-digest p, .closed-chat-digest ul { margin: 0 0 var(--s-2); }
.closed-chat-digest .digest-topics { color: var(--light-cyan); font-size: var(--fs-small); }
.closed-chat-digest .digest-summary { color: var(--ink-1); }
.closed-chat-digest .digest-missing { color: var(--ink-2); }
.closed-chat-digest .digest-caveat { color: var(--warn); font-size: var(--fs-small); }
.closed-chat-digest .digest-heading { margin: var(--s-2) 0 var(--s-1); font-size: var(--fs-small); color: var(--ink-2); }
.closed-chat-digest .digest-list { padding-left: var(--s-4); }
.closed-chat-digest .digest-footnote { color: var(--ink-3); font-size: var(--fs-caption); }

.closed-chat-note { margin: 0; color: var(--warn); font-size: var(--fs-small); }

.closed-chat-bar__actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }

.closed-chat-bar__actions button {
  min-height: var(--touch);
  padding: 0 var(--s-4);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink-1);
}

.closed-chat-bar__actions .closed-chat-bar__primary { background: var(--light-cyan); color: var(--ink-on-light); font-weight: 600; }
.closed-chat-bar__actions button.hidden { display: none; }

/* A trusted contact's chat is read-only and not the owner's to close or resume. */
#app-shell[data-external-chat] :is(#chat-close-btn, #closed-chat-bar) { display: none; }
