/* ACDC v6 · application shell: rail, top bar, view, command palette */

.app { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); height: 100vh; height: 100dvh; transition: grid-template-columns var(--med) var(--ease); }
.app[data-rail='collapsed'] { grid-template-columns: var(--rail-collapsed) minmax(0, 1fr); }

/* ---------- Rail ---------- */
.rail { display: flex; flex-direction: column; min-height: 0; color: var(--rail-ink); background: var(--rail-bg); border-right: 1px solid var(--rail-line); overflow: hidden; }
.rail a, .rail button { color: inherit; }
.rail-head { display: flex; align-items: center; gap: var(--s2); height: var(--topbar); padding: 0 var(--s3) 0 var(--s4); flex: none; }
.brand { display: inline-flex; align-items: center; height: 32px; color: #fff; border-radius: var(--r-sm); }
.brand svg { height: 24px; width: auto; fill: currentColor; }
.brand:hover { color: #fff; }
.rail-close { display: none; }
.rail-item.rail-only-narrow { display: none; }
button.rail-item { width: 100%; text-align: left; }
.rail-collapse { margin-left: auto; display: grid; place-items: center; width: 28px; height: 28px; color: var(--rail-ink-2); border-radius: var(--r-sm); }
.rail-collapse:hover { color: var(--rail-ink); background: var(--rail-hover); }

.rail-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: var(--s2) var(--s2) var(--s4); display: flex; flex-direction: column; gap: var(--s4); scrollbar-color: var(--rail-line) transparent; }
.rail-group { display: flex; flex-direction: column; gap: 1px; }
.rail-label { padding: 6px var(--s2) 4px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--rail-ink-2); white-space: nowrap; }

.rail-item {
  position: relative; display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 var(--s2) 0 10px;
  font-size: var(--text-md); font-weight: 450; color: var(--rail-ink-2); white-space: nowrap; border-radius: var(--r-md);
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.rail-item:hover { color: var(--rail-ink); background: var(--rail-hover); text-decoration: none; }
.rail-item[aria-current='page'] { color: #fff; background: var(--rail-active); font-weight: 550; }
.rail-item[aria-current='page']::before { content: ''; position: absolute; left: -8px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 2px 2px 0; background: var(--accent-mark); }
.rail-item .icon { width: 17px; height: 17px; flex: none; }
.rail-item-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.rail-badge { min-width: 18px; height: 18px; padding: 0 5px; display: inline-grid; place-items: center; font-size: 10.5px; font-weight: 650; font-variant-numeric: tabular-nums; color: #fff; background: var(--accent); border-radius: 9px; }
.rail-badge[data-quiet] { color: var(--rail-ink-2); background: var(--rail-active); }
.rail-kbd { font-family: var(--font-mono); font-size: 10px; color: var(--rail-ink-2); opacity: 0; transition: opacity var(--fast) var(--ease); }
.rail-item:hover .rail-kbd, .rail-item:focus-visible .rail-kbd { opacity: 0.8; }
.rail :focus-visible { outline-color: #fff; outline-offset: -2px; }

.project-switch { display: flex; align-items: center; gap: 10px; width: 100%; height: 40px; padding: 0 var(--s2) 0 var(--s2); text-align: left; border-radius: var(--r-md); border: 1px solid var(--rail-line); background: var(--rail-hover); }
.project-switch:hover { border-color: #33423f; }
.project-mark { flex: none; display: grid; place-items: center; width: 24px; height: 24px; font-size: 11px; font-weight: 700; color: #fff; background: #2b3a37; border-radius: 5px; }
.project-switch-name { flex: 1 1 auto; min-width: 0; font-weight: 600; color: var(--rail-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-switch .icon { color: var(--rail-ink-2); width: 14px; height: 14px; }

.rail-foot { flex: none; padding: var(--s2); border-top: 1px solid var(--rail-line); display: flex; flex-direction: column; gap: 1px; }
.actor-switch { display: flex; align-items: center; gap: 10px; width: 100%; height: 44px; padding: 0 var(--s2); text-align: left; border-radius: var(--r-md); }
.actor-switch:hover { background: var(--rail-hover); }
.actor-switch .avatar { color: #fff; background: #2b3a37; border-color: transparent; box-shadow: none; }
.actor-switch .avatar[data-kind='agent'] { background: var(--accent); }
.actor-switch-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.actor-switch-name { font-weight: 600; color: var(--rail-ink); }
.actor-switch-role { font-size: var(--text-xs); color: var(--rail-ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actor-switch > .icon { color: var(--rail-ink-2); width: 14px; height: 14px; }

.app[data-rail='collapsed'] .rail-label,
.app[data-rail='collapsed'] .rail-item-label,
.app[data-rail='collapsed'] .rail-kbd,
.app[data-rail='collapsed'] .project-switch-name,
.app[data-rail='collapsed'] .project-switch > .icon,
.app[data-rail='collapsed'] .actor-switch-text,
.app[data-rail='collapsed'] .actor-switch > .icon,
.app[data-rail='collapsed'] .brand { display: none; }
.app[data-rail='collapsed'] .rail-head { padding: 0; justify-content: center; }
.app[data-rail='collapsed'] .rail-collapse { margin: 0; }
.app[data-rail='collapsed'] .rail-item { justify-content: center; padding: 0; }
.app[data-rail='collapsed'] .rail-item[aria-current='page']::before { left: -8px; }
.app[data-rail='collapsed'] .rail-badge { position: absolute; top: 2px; right: 2px; min-width: 15px; height: 15px; font-size: 9.5px; padding: 0 3px; }
.app[data-rail='collapsed'] .project-switch, .app[data-rail='collapsed'] .actor-switch { justify-content: center; padding: 0; }
.app[data-rail='collapsed'] .rail-group + .rail-group { padding-top: var(--s3); border-top: 1px solid var(--rail-line); }

/* "More in <project>": collapsed by default; the current item stays visible */
.rail-more-toggle .icon { width: 14px; height: 14px; }
.rail-more-toggle .rail-item-label { font-size: var(--text-sm); }
.rail-more-list { display: flex; flex-direction: column; gap: 1px; }
.app[data-rail='collapsed'] .rail-more-toggle .rail-item-label { display: none; }

/* ---------- Main column ---------- */
.main { display: grid; grid-template-rows: var(--topbar) minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
.product-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 24px; padding: 8px var(--s8); border-top: 1px solid var(--line); background: var(--bg); color: var(--ink-3); font-size: 12px; line-height: 1.5; }
.product-footer-name { flex: 1 1 330px; overflow-wrap: anywhere; }
.product-footer-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; }
.product-footer-meta > span { white-space: nowrap; }
.product-footer-version { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
@media (max-width: 900px) { .product-footer { padding: 8px var(--s4); } }
.topbar { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s5) 0 var(--s8); background: var(--bg); border-bottom: 1px solid var(--line); min-width: 0; }
.topbar-menu { display: none; }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 auto; font-size: var(--text-md); color: var(--ink-3); overflow: hidden; white-space: nowrap; }
.crumbs a { color: var(--ink-3); border-radius: 3px; }
.crumbs a:focus-visible { outline-offset: -2px; }
.crumbs a:hover { color: var(--ink); text-decoration: none; }
.crumbs .crumb-sep { color: var(--ink-faint); }
.crumbs [aria-current='page'] { color: var(--ink); font-weight: 550; overflow: hidden; text-overflow: ellipsis; }

.topbar-tools { display: flex; align-items: center; gap: var(--s2); flex: none; }
.search-trigger {
  display: inline-flex; align-items: center; gap: var(--s2); height: var(--control); width: 240px; padding: 0 8px 0 10px;
  font-size: var(--text-sm); color: var(--ink-3); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-md);
  transition: border-color var(--fast) var(--ease);
}
.search-trigger:hover { border-color: var(--ink-4); color: var(--ink-2); }
.search-trigger span { flex: 1 1 auto; min-width: 0; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-trigger .icon { width: 14px; height: 14px; }

.clock-chip {
  display: inline-flex; align-items: center; gap: 7px; height: var(--control); padding: 0 10px;
  font-size: var(--text-sm); color: var(--ink-2); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-md); white-space: nowrap;
}
.clock-chip:hover { border-color: var(--ink-4); color: var(--ink); }
.clock-chip time { font-family: var(--font-mono); font-weight: 600; color: var(--ink); }
.clock-chip .icon { width: 14px; height: 14px; color: var(--ink-3); }
.clock-chip[data-live] { border-color: var(--run-line); background: var(--run-bg); }
.clock-chip[data-live] .icon { color: var(--run-mark); animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.clock-scene { color: var(--ink-3); min-width: 132px; text-align: left; }

/* The link to the service: said the moment it changes, absent when all is well */
.link-state { display: inline-flex; align-items: center; gap: 6px; height: var(--control); padding: 0 10px; font-size: var(--text-sm); font-weight: 550; white-space: nowrap; border: 1px solid var(--warn-line); background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--r-md); }
.link-state[hidden] { display: none; }
.link-state .icon { width: 14px; height: 14px; }
.link-state[data-tone='hold'] { border-color: var(--hold-line); background: var(--hold-bg); color: var(--accent-ink); }
.link-state-more { font-weight: 450; }

.new-trigger { gap: 6px; }
.new-trigger .icon { width: 14px; height: 14px; }

/* ---------- Session ended: the page stays, typed text with it ---------- */
.session-ended { position: fixed; inset: 0; z-index: 85; display: grid; place-items: center; padding: var(--s4); background: var(--scrim); }
.session-ended-panel { width: min(440px, 100%); display: flex; flex-direction: column; gap: var(--s3); padding: var(--s6); color: var(--ink); background: var(--overlay); border-radius: var(--r-lg); box-shadow: var(--shadow-dialog); }
.session-ended-panel h2 { font-size: var(--text-xl); }
.session-ended-panel p { color: var(--ink-2); }
.session-ended-actions { display: flex; justify-content: flex-end; }

/* ---------- Account menu in a shared workspace ---------- */
.account-card { display: flex; align-items: center; gap: var(--s3); padding: 6px 9px 8px; }
.account-card-text { display: flex; flex-direction: column; line-height: 1.3; }
.account-card-text span { font-size: var(--text-sm); color: var(--ink-3); }

/* ---------- Someone else changed what is on screen ---------- */
.view [data-changed] { outline: 2px solid var(--run-mark); outline-offset: 2px; border-radius: var(--r-sm); transition: outline-color 600ms var(--ease); }
.view [data-changed='fade'] { outline-color: transparent; }
@media (prefers-reduced-motion: reduce) {
  .view [data-changed] { transition: none; }
  .view [data-changed='fade'] { outline-color: var(--run-mark); }
}

/* ---------- A preview that changed while it was open ---------- */
.dialog-changed { display: flex; flex-direction: column; gap: var(--s2); }
/* The live parts of a preview keep the spacing the dialog body gives its children */
.dialog-effects, [data-dialog-extra], [data-dialog-blocked] { display: flex; flex-direction: column; gap: var(--s4); }
[data-dialog-extra]:empty, [data-dialog-blocked]:empty { display: none; }
.dialog-changed[hidden] { display: none; }
.dialog-reread { font-weight: 550; }

/* No smooth scrolling here: a new screen must start at its top at once */
.view { position: relative; min-height: 0; overflow-y: auto; overflow-x: hidden; background: var(--bg); }
.view:focus { outline: none; }
.view[data-enter] > .page { animation: view-in 220ms var(--ease); }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.proto-note { padding: var(--s4) var(--s8) var(--s6); font-size: var(--text-xs); color: var(--ink-4); text-align: right; }

/* ---------- Command palette ---------- */
dialog.palette {
  width: min(640px, calc(100vw - 32px)); max-height: min(560px, calc(100dvh - 96px)); padding: 0; margin: 12vh auto auto;
  color: var(--ink); background: var(--overlay); border: 0; border-radius: var(--r-lg); box-shadow: var(--shadow-dialog); overflow: hidden;
}
dialog.palette[open] { display: flex; flex-direction: column; animation: dialog-in var(--fast) var(--ease); }
dialog.palette::backdrop { background: var(--scrim); }
.palette-input-row { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s4); border-bottom: 1px solid var(--line); }
.palette-input-row .icon { color: var(--ink-3); width: 18px; height: 18px; }
.palette-input { flex: 1 1 auto; height: 52px; font-size: var(--text-lg); background: transparent; border: 0; outline: none; color: var(--ink); min-width: 0; }
.palette-input::placeholder { color: var(--ink-4); }
.palette-list { flex: 1 1 auto; overflow-y: auto; padding: 6px; }
.palette-group { padding: 8px 10px 4px; font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); }
.palette-item { display: grid; grid-template-columns: 20px minmax(0, auto) minmax(0, 1fr) auto; align-items: center; gap: var(--s3); width: 100%; min-height: 36px; padding: 5px 10px; text-align: left; border-radius: var(--r-md); color: var(--ink); }
.palette-item .icon { color: var(--ink-3); }
.palette-item[aria-selected='true'] { background: var(--sunken); }
.palette-item-id { font-family: var(--font-mono); font-size: var(--text-sm); font-weight: 600; white-space: nowrap; }
.palette-item-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item-title small { font-size: var(--text-sm); color: var(--ink-3); margin-left: 6px; }
.palette-item-meta { font-size: var(--text-sm); color: var(--ink-3); white-space: nowrap; }
.palette-empty { padding: var(--s8) var(--s4); text-align: center; color: var(--ink-3); }
.palette-foot { display: flex; align-items: center; gap: var(--s4); padding: 8px var(--s4); border-top: 1px solid var(--line); background: var(--surface-2); font-size: var(--text-xs); color: var(--ink-3); }
.palette-foot span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- Help sheet ---------- */
.keys { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s5) var(--s8); }
.keys h3 { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); margin-bottom: var(--s2); }
.keys dl { display: flex; flex-direction: column; gap: 6px; }
.keys dl > div { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); font-size: var(--text-sm); }
.keys dd { display: inline-flex; gap: 3px; flex: none; }
.keys-words { grid-column: 1 / -1; font-size: var(--text-sm); }
.keys-words p + p { margin-top: var(--s1); font-size: var(--text-xs); }
@media (max-width: 600px) { .keys { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Scenario menu ---------- */
.scene-list { display: flex; flex-direction: column; }
.scene { position: relative; display: grid; grid-template-columns: 14px 78px minmax(0, 1fr); gap: var(--s3); align-items: baseline; width: 100%; padding: 8px 9px; text-align: left; border-radius: var(--r-sm); }
.scene:hover { background: var(--sunken); }
.scene::before { content: ''; position: absolute; left: 15px; top: 22px; bottom: -8px; width: 1px; background: var(--line-2); }
.scene:last-child::before { display: none; }
.scene-dot { width: 9px; height: 9px; margin-left: 2px; border-radius: 50%; border: 2px solid var(--ink-4); background: var(--overlay); align-self: center; z-index: 1; }
.scene[aria-checked='true'] .scene-dot { border-color: var(--accent-mark); background: var(--accent-mark); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-mark) 22%, transparent); }
.scene time { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-3); }
.scene-name { font-weight: 550; display: block; }
.scene-detail { font-size: var(--text-xs); color: var(--ink-3); display: block; line-height: 1.35; }

/* ---------- Signing in to a shared workspace ---------- */
.signin { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: var(--s4); background: var(--bg); overflow-y: auto; }
.signin[aria-busy='true'] { opacity: 0.6; pointer-events: none; }
.signin[aria-busy='true'] .signin-gh button { pointer-events: auto; }
.signin-panel { width: min(440px, 100%); display: flex; flex-direction: column; gap: var(--s3); }
.signin-panel h1 { font-size: var(--text-2xl); letter-spacing: -0.02em; }
.signin-note { font-size: var(--text-sm); color: var(--ink-3); }
.signin-error { font-size: var(--text-sm); color: var(--accent-ink); min-height: 1.4em; }
.signin-list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.signin-person { display: flex; align-items: center; gap: var(--s3); width: 100%; padding: 10px var(--s4); text-align: left; border-bottom: 1px solid var(--line); }
.signin-person:last-child { border-bottom: 0; }
.signin-person:hover, .signin-person:focus-visible { background: var(--surface-2); }
.signin-person:focus-visible { outline-offset: -2px; }
.signin-name { display: flex; flex-direction: column; line-height: 1.3; }
.signin-name span { font-size: var(--text-sm); color: var(--ink-3); }
.signin-form { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.signin-subtitle { font-size: var(--text-md); font-weight: 600; }
.signin-actions { display: flex; justify-content: flex-start; }
.signin-more { align-self: flex-start; }
.signin-sep { border: 0; border-top: 1px solid var(--line); margin: var(--s2) 0; }
.signin-gh-start { align-self: stretch; }
.signin-gh-start .btn, .signin-gh-start { width: 100%; }
.signin-gh { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.signin-gh-status { font-size: var(--text-sm); color: var(--ink-2); }
.signin-gh-code { font-family: var(--font-mono); font-size: var(--text-2xl); letter-spacing: 0.18em; text-align: center; padding: var(--s3); background: var(--sunken); border-radius: var(--r-sm); }
.signin-gh-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ---------- Walkthrough ---------- */
.tour-trigger { gap: 6px; padding: 0 8px; }
.tour-count { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-3); }
.tour { display: flex; flex-direction: column; }
.tour-step { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: var(--s3); align-items: start; padding: 7px 9px; color: var(--ink); border-radius: var(--r-sm); }
.tour-step:hover, .tour-step:focus-visible { background: var(--sunken); text-decoration: none; color: var(--ink); }
.tour-mark { display: grid; place-items: center; width: 22px; height: 22px; font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600; color: var(--ink-3); border: 1.5px solid var(--line-2); border-radius: 50%; }
.tour-mark .icon { width: 12px; height: 12px; stroke-width: 2.5; }
.tour-step[data-done] .tour-mark { color: var(--surface); background: var(--ok-mark); border-color: var(--ok-mark); }
.tour-step[data-next] .tour-mark { color: var(--on-accent); background: var(--accent-mark); border-color: var(--accent-mark); }
.tour-label { display: block; font-weight: 550; }
.tour-step[data-done] .tour-label { color: var(--ink-3); font-weight: 450; }
.tour-note { display: block; font-size: var(--text-xs); color: var(--ink-3); line-height: 1.35; }

/* ---------- Narrow screens ---------- */
/* The breadcrumb keeps its room: the tools give way first */
@media (max-width: 1360px) {
  .clock-scene { display: none; }
  .search-trigger { width: 200px; }
}
@media (max-width: 1180px) {
  .search-trigger { width: auto; }
  .search-trigger span, .search-trigger kbd { display: none; }
  .tour-trigger > span:not(.tour-count) { display: none; }
  .link-state-more { display: none; }
}
@media (max-width: 900px) {
  .app, .app[data-rail='collapsed'] { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(280px, 86vw); transform: translateX(-102%); transition: transform var(--med) var(--ease); visibility: hidden; }
  .app[data-drawer='open'] .rail { transform: none; visibility: visible; box-shadow: var(--shadow-dialog); }
  .rail-scrim { position: fixed; inset: 0; z-index: 39; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity var(--med) var(--ease); }
  .app[data-drawer='open'] .rail-scrim { opacity: 1; pointer-events: auto; }
  .rail-collapse { display: none; }
  .rail-close { display: grid; place-items: center; margin-left: auto; width: 32px; height: 32px; color: var(--rail-ink-2); border-radius: var(--r-sm); }
  .rail-close:hover { color: var(--rail-ink); background: var(--rail-hover); }
  .rail-item.rail-only-narrow { display: flex; }
  .topbar { padding: 0 var(--s3); gap: var(--s2); }
  .crumbs > *:not(:nth-last-child(-n + 1)) { display: none; }
  .clock-chip { padding: 0 8px; }
  .tour-count { display: none; }
  .new-trigger > span { display: none; }
  .new-trigger { padding: 0 8px; }
  .clock-scene { display: none; }
  .topbar-menu { display: inline-flex; }
  /* The drawer always shows full labels, even if the rail was collapsed on desktop */
  .app[data-rail='collapsed'] .rail-label, .app[data-rail='collapsed'] .rail-item-label, .app[data-rail='collapsed'] .project-switch-name,
  .app[data-rail='collapsed'] .actor-switch-text, .app[data-rail='collapsed'] .brand { display: revert; }
  .app[data-rail='collapsed'] .rail-item { justify-content: flex-start; padding: 0 var(--s2) 0 10px; }
  .app[data-rail='collapsed'] .rail-head { padding: 0 var(--s3) 0 var(--s4); justify-content: flex-start; }
  .app[data-rail='collapsed'] .project-switch, .app[data-rail='collapsed'] .actor-switch { justify-content: flex-start; padding: 0 var(--s2); }
  .app[data-rail='collapsed'] .rail-badge { position: static; }
  .proto-note { padding: var(--s4); text-align: left; }
  .toast-stack { right: var(--s3); left: var(--s3); bottom: var(--s3); align-items: stretch; }
}
@media (min-width: 901px) { .rail-scrim { display: none; } }
@media (max-width: 600px) {
  /* Appearance and shortcuts stay reachable from the command palette */
  .topbar-tools > [data-action='theme.menu'], .topbar-tools > [data-action='help.open'] { display: none; }
}

@media print {
  .rail, .topbar, .toast-stack { display: none !important; }
  .app { display: block; height: auto; }
  .view { overflow: visible; }
}
