/* 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 .wordmark {
  flex: 1;
  font-size: 1.5rem;
}

/* 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 {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-2);
  min-height: 2rem;
  color: var(--ink-2);
}

.connection-service {
  flex: 1;
  min-width: 0;
}

.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(--warn);
}

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

.connection-timestamp {
  display: none;
}

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

/* --- 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: linear-gradient(180deg, rgba(112, 164, 255, 0.07), rgba(112, 164, 255, 0.035)), var(--night-2);
  box-shadow: 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;
}

.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: rgba(112, 164, 255, 0.1);
  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-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;
}

.daily-brief-timestamp,
.approvals-hint {
  flex: 1;
  min-width: 0;
  color: var(--ink-3);
  font-size: var(--fs-caption);
}

/* The approvals hint reads as a sentence: it gets its own row under the title. */
.approvals-hint {
  order: 4;
  flex: 1 1 100%;
  padding: 0 var(--s-2) var(--s-1);
}

.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;
}

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

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

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

.daily-brief-summary {
  color: var(--ink-1);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  max-width: 65ch;
}

.daily-brief-sources {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11.5rem, 1fr));
  gap: var(--s-5) var(--s-5);
}

.daily-brief-section {
  min-width: 0;
}

.daily-brief-section h3 {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--ink-2);
}

.daily-brief-section h3 .icon {
  width: 1rem;
  height: 1rem;
  color: var(--light-cyan);
}

.daily-brief-section-badge .provenance {
  margin-top: 2px;
}

.daily-brief-section-content {
  margin-top: var(--s-2);
  font-size: var(--fs-small);
  color: var(--ink-1);
}

.daily-brief-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

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

.daily-brief-notion-title {
  font-weight: 500;
}

.daily-brief-notion-excerpt {
  margin-top: 2px;
  color: var(--ink-2);
  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;
}

.approvals-empty {
  color: var(--ink-3);
  font-size: var(--fs-small);
  padding: var(--s-2);
}

.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);
}

.proposal-card.status-pending,
.proposal-card.status-executing {
  background: linear-gradient(180deg, rgba(var(--warn-rgb), 0.09), var(--night-2) 70%);
  box-shadow: inset 0 1px 0 rgba(var(--warn-rgb), 0.28), inset 0 0 0 1px rgba(var(--warn-rgb), 0.16);
}

.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-small);
  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);
}

/* The mail body is exactly what the owner approves: keep its line breaks. */
.proposal-fact--body {
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  color: var(--ink-1);
  white-space: pre-wrap;
}

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

.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-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  font-size: var(--fs-small);
  overflow-wrap: anywhere;
}

.proposal-result.tone-ok { color: var(--ok); }
.proposal-result.tone-error { color: var(--error); }

.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;
}

.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-caption);
  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 card: name + status on the first line, a plain explanation and the
   write/send capability each on their own line, then one action. */
.connection-desc,
.connection-capability {
  flex-basis: 100%;
  font-size: var(--fs-caption);
  color: var(--ink-3);
}

/* Daily Brief: friendly "not connected" line + inline connect action, and the
   calm "still incomplete" notice. No raw status codes anywhere here. */
.daily-brief-unavailable {
  font-size: var(--fs-small);
  color: var(--ink-3);
}
.daily-brief-unavailable.tone-error { color: var(--error); }
.daily-brief-unavailable.tone-warn { color: var(--warn); }

.daily-brief-connect {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  margin-top: var(--s-1);
  font-size: var(--fs-caption);
}

.daily-brief-notice {
  font-size: var(--fs-small);
  color: var(--ink-3);
  margin-bottom: var(--s-2);
}
.daily-brief-notice.hidden { display: none; }

/* --- 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 wordmark takes the centre of the screen. */
body:has(#login-view:not(.hidden)) header#topbar {
  justify-content: center;
}

body:has(#login-view:not(.hidden)) header#topbar .wordmark {
  flex: none;
  font-size: 2rem;
}

#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);
}

.hero__greeting {
  margin-top: var(--s-2);
  font-size: 2.125rem;
  font-weight: 400; /* typography.md: "avoid light font weights" */
  line-height: var(--lh-tight);
}

.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;
  grid-template-columns: repeat(3, 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);
}

.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); }

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);
}

.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(--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);
}

#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;
  flex-direction: column;
  gap: var(--s-1);
  padding: var(--s-2) var(--s-3) var(--s-3);
}

.side-brand .wordmark {
  font-size: 1.875rem;
}

.side-brand__tag {
  font-size: var(--fs-caption);
  color: var(--ink-3);
  letter-spacing: 0.02em;
}

.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;
}

#app-shell[data-view='approvals'] .approvals {
  margin-top: calc(var(--s-4) + var(--safe-top));
}

/* --- 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);
  }

  .daily-brief-sources {
    grid-template-columns: 1fr;
  }

  .daily-brief-timestamp {
    flex: 1;
  }

  .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);
  }

  .hero__greeting {
    font-size: 3rem;
  }

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

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

  #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;
  }

  .voice-cta {
    width: min(100%, 26rem);
  }

  .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;
  }

  /* A waiting decision outranks the day's overview: it moves to the top of the rail. */
  :root[data-approvals] .rail #approvals {
    order: -1;
  }

  #app-shell[data-view='home'] .rail #approvals,
  #app-shell[data-view='chat'] .rail,
  #app-shell[data-view='chat'] .rail #approvals {
    display: block;
  }

  #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);
  }

  /* On the rail, Freigaben is a glance, not a decision: the open proposals show
     what would happen, and "Prüfen" leads to the destination where every detail
     is on screen. Approve / reject exist only there. */
  #app-shell:not([data-view='approvals']) .rail :is(.proposal-details, .proposal-actions, .proposal-lifecycle, .proposal-more, .proposal-result) {
    display: none;
  }

  #app-shell:not([data-view='approvals']) .rail .proposal-card:nth-child(n + 4) {
    display: none;
  }

  #app-shell:not([data-view='approvals']) .rail .approvals-open-btn {
    display: inline-flex;
  }

  #app-shell:not([data-view='approvals']) .rail .approvals-refresh-btn {
    display: none;
  }

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

  /* On the rail the brief is a stack, not a grid. */
  .rail .daily-brief-sources {
    grid-template-columns: 1fr;
  }

  .rail .daily-brief-toggle-btn .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);
  }

  .hero__greeting {
    font-size: 3.5rem;
  }
}

.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;
}

.approvals-none-open {
  display: none;
  padding: var(--s-2);
  color: var(--ink-3);
  font-size: var(--fs-small);
}

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

/* 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);
  }

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

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

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

  .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;
  }
}
