/*
 * style.css: the whole design system (D-041 §4.11, §4.13).
 *
 * Direction: calm, dense and flat. Neutral surfaces, 1px hairline borders, one accent
 * colour, status colours used sparingly and always beside text or a glyph. Compact
 * rows, not cards. Sentence case, two font weights (400 and 500), system fonts, no
 * gradients, no shadows (the focus ring is an outline).
 *
 * Sections: tokens, base, shell, controls, forms, tabs, tables, status, bands,
 * item pages, chat, dock, settings, states, phone width.
 *
 * Token names (colours): --bg --surface --surface-2 --border --border-strong --text
 * --text-muted --accent --accent-contrast --accent-soft --success --success-soft
 * --warning --warning-soft --danger --danger-soft --focus.
 * Other tokens: --font --font-mono --fs-xs --fs-sm --fs --fs-lg --fs-xl, --sp-1..--sp-6,
 * --radius, --topbar-h, --dock-w, --content-w.
 * Text/background pairs are at least 4.5:1 and --border-strong against --surface is
 * at least 3:1 in both themes. --border is a decorative hairline.
 */

/* Tokens ----------------------------------------------------------------- */

:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #eff1f3;
  --border: #dde1e5;
  --border-strong: #7f8892;
  --text: #1b1f24;
  --text-muted: #566069;
  --accent: #1c58b8;
  --accent-contrast: #ffffff;
  --accent-soft: #e6eefb;
  --success: #17663a;
  --success-soft: #e3f3e9;
  --warning: #85500a;
  --warning-soft: #fbefd9;
  --danger: #b02318;
  --danger-soft: #fce8e6;
  --focus: #1c58b8;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --radius: 4px;
  --topbar-h: 48px;
  --dock-w: 380px;
  --launcher-h: 56px; /* the floating chat button plus its gap, kept clear at the foot of main */
  --content-w: 1200px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #101317;
    --surface: #171b20;
    --surface-2: #1e2329;
    --border: #2a3037;
    --border-strong: #6d7782;
    --text: #e7eaee;
    --text-muted: #9ba5b0;
    --accent: #79adff;
    --accent-contrast: #0b1220;
    --accent-soft: #1a2740;
    --success: #55c982;
    --success-soft: #183024;
    --warning: #e6aa45;
    --warning-soft: #33280e;
    --danger: #ff8178;
    --danger-soft: #3b1d1b;
    --focus: #79adff;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101317;
  --surface: #171b20;
  --surface-2: #1e2329;
  --border: #2a3037;
  --border-strong: #6d7782;
  --text: #e7eaee;
  --text-muted: #9ba5b0;
  --accent: #79adff;
  --accent-contrast: #0b1220;
  --accent-soft: #1a2740;
  --success: #55c982;
  --success-soft: #183024;
  --warning: #e6aa45;
  --warning-soft: #33280e;
  --danger: #ff8178;
  --danger-soft: #3b1d1b;
  --focus: #79adff;
}

/* Base ------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs) / 1.5 var(--font);
}

h1, h2, h3, h4 { margin: 0; font-weight: 500; line-height: 1.3; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs); }
p { margin: 0 0 var(--sp-3); }
strong, b, th, summary, legend, dt { font-weight: 500; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--font-mono); font-size: var(--fs-sm); }
pre { margin: 0; padding: var(--sp-3); overflow-x: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; }
ul, ol { margin: 0 0 var(--sp-3); padding-left: var(--sp-5); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }

.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.wide { width: 100%; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }
h1[tabindex="-1"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }

.skip {
  position: absolute;
  left: var(--sp-2);
  top: -64px;
  z-index: 100;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
.skip:focus { top: var(--sp-2); }

/* Shell: top bar, grid, footer ---------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-height: var(--topbar-h);
  padding: 0 var(--sp-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 500; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }

.primary-nav { display: flex; gap: 2px; min-width: 0; scrollbar-width: thin; }
.primary-nav a {
  padding: 6px 10px;
  color: var(--text-muted);
  border-radius: var(--radius);
  white-space: nowrap;
}
.primary-nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.primary-nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 500; }

.topbar-end { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-2); }
.account { position: relative; display: flex; align-items: center; }

/* Account button, dropdown menu and profile dialog ---------------------------- */

.account-button {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 36px;
  padding: 3px var(--sp-2) 3px 3px;
  color: var(--text);
  background: transparent;
  border-color: transparent;
  border-radius: 999px;
}
.account-button:hover:not(:disabled), .account-button[aria-expanded="true"] { background: var(--surface-2); }
.account-avatar { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; color: var(--accent); background: var(--accent-soft); border-radius: 50%; }
.account-icon { width: 18px; height: 18px; fill: currentColor; }
.account-name { max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-caret { color: var(--text-muted); font-size: var(--fs-xs); }

.account-menu {
  position: absolute;
  top: calc(100% + var(--sp-1));
  right: 0;
  z-index: 30;
  min-width: 240px;
  max-width: calc(100vw - 2 * var(--sp-3));
  padding: var(--sp-1) 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
.account-menu-head { padding: var(--sp-2) var(--sp-3); }
.account-menu-name { font-weight: 500; overflow-wrap: anywhere; }
.account-menu-sep { height: 1px; margin: var(--sp-1) 0; background: var(--border); }
.account-menu-label { padding: var(--sp-1) var(--sp-3) 0; color: var(--text-muted); font-size: var(--fs-sm); }
.account-item { display: block; width: 100%; min-height: 34px; padding: 6px var(--sp-3); text-align: left; background: transparent; border: 0; border-radius: 0; }
.account-item:hover:not(:disabled), .account-item:focus-visible { background: var(--surface-2); }
.account-item:focus-visible { outline-offset: -2px; }
.account-theme { display: flex; gap: var(--sp-1); padding: var(--sp-1) var(--sp-3) var(--sp-2); }
.account-theme .account-item { flex: 1; width: auto; text-align: center; border: 1px solid var(--border-strong); border-radius: var(--radius); }
.account-theme .account-item[aria-checked="true"] { color: var(--text); font-weight: 500; background: var(--accent-soft); border-color: var(--accent); }
.account-theme .account-item[aria-checked="true"]::before { content: "\2713\00a0"; }

.profile {
  width: min(760px, calc(100vw - 2 * var(--sp-4)));
  /* A fixed height keeps the tab list still when a tab with more or less content is chosen. */
  height: min(520px, calc(100vh - 2 * var(--sp-5)));
  max-height: calc(100vh - 2 * var(--sp-5));
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
.profile[open] { display: flex; flex-direction: column; }
.profile::backdrop { background: rgba(0, 0, 0, 0.5); }
.profile-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.profile-head h2 { margin: 0; }
.profile-body { display: grid; grid-template-columns: 180px minmax(0, 1fr); flex: 1; min-height: 0; }
.profile-tabs { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-3); background: var(--surface-2); border-right: 1px solid var(--border); }
.profile-tab { text-align: left; background: transparent; border-color: transparent; }
.profile-tab:hover:not(:disabled) { background: var(--surface); }
.profile-tab[aria-selected="true"] { font-weight: 500; background: var(--surface); border-color: var(--border-strong); }
.profile-panels { min-width: 0; padding: var(--sp-4); overflow: auto; }
.profile-panel[hidden] { display: none; }

#message {
  margin: 0;
  padding: var(--sp-2) var(--sp-4);
  background: var(--warning-soft);
  color: var(--warning);
  border-bottom: 1px solid var(--border);
}

.shell { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; }
body.dock-pinned .shell { grid-template-columns: minmax(0, 1fr) var(--dock-w); }

main { width: 100%; max-width: var(--content-w); margin: 0 auto; padding: var(--sp-5) var(--sp-4) calc(var(--sp-6) + var(--launcher-h)); min-width: 0; }
main:focus { outline: none; }

.footer { padding: var(--sp-3) var(--sp-4); color: var(--text-muted); font-size: var(--fs-sm); border-top: 1px solid var(--border); background: var(--surface); }

/* Sign-in */

.signin { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: var(--sp-6); align-items: start; padding-top: var(--sp-6); }
.signin .intro h1 { font-size: 28px; margin-bottom: var(--sp-3); }
.signin .intro p { color: var(--text-muted); font-size: var(--fs-lg); max-width: 46ch; }
.login { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-5); }
.login h2 { margin-bottom: var(--sp-3); }
.hosted-login .actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.hosted-login h3 { margin-bottom: var(--sp-2); }
.org-picker { list-style: none; margin: 0 0 var(--sp-3); padding: 0; display: grid; gap: var(--sp-2); }
.org-picker button { width: 100%; text-align: left; overflow-wrap: anywhere; }
.org-name { max-width: 24ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 1px var(--sp-2); font-size: var(--fs-sm); color: var(--text-muted); background: var(--surface-2); border-radius: 999px; }

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

button, a.button {
  font: inherit;
  min-height: 32px;
  padding: 5px var(--sp-3);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
a.button { display: inline-flex; align-items: center; justify-content: center; line-height: 1.5; white-space: nowrap; }
a.button:hover { text-decoration: none; }
button:hover:not(:disabled), a.button:hover { background: var(--surface-2); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary, a.button.primary { color: var(--accent-contrast); background: var(--accent); border-color: var(--accent); }
button.primary:hover:not(:disabled), a.button.primary:hover { background: var(--accent); filter: brightness(1.08); }
button.quiet { background: transparent; border-color: transparent; color: var(--text-muted); }
button.quiet:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.quiet.danger { border-color: transparent; }
button.danger:hover:not(:disabled) { background: var(--danger-soft); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.stack > * + * { margin-top: var(--sp-3); }
.grow { flex: 1; min-width: 0; }

/* Forms -------------------------------------------------------------------- */

label { display: block; margin: var(--sp-3) 0 var(--sp-1); font-weight: 500; }
input, select, textarea {
  display: block;
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 6px var(--sp-2);
}
input[type="checkbox"], input[type="radio"] { display: inline-block; width: auto; margin: 0; accent-color: var(--accent); }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
form button[type="submit"], form > button { margin-top: var(--sp-3); }
fieldset { margin: var(--sp-3) 0 0; padding: var(--sp-2) var(--sp-3) var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
legend { padding: 0 var(--sp-1); }
.field { margin-top: var(--sp-3); }
.field > label { margin-top: 0; }
.hint { margin: var(--sp-1) 0 0; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
.check { display: flex; align-items: center; gap: var(--sp-2); font-weight: 400; }
.source-options { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); }
.source-choice { display: inline-flex; align-items: center; gap: var(--sp-2); margin: 0; font-weight: 400; }

/* Tabs --------------------------------------------------------------------- */

.tabs { display: flex; gap: var(--sp-1); margin: 0 0 var(--sp-3); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin; }
.tabs a, .tabs button {
  min-height: 0;
  padding: var(--sp-2) var(--sp-3);
  color: var(--text-muted);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  white-space: nowrap;
}
.tabs a:hover, .tabs button:hover:not(:disabled) { color: var(--text); background: var(--surface-2); text-decoration: none; }
.tabs [aria-current="page"], .tabs [aria-current="true"], .tabs [aria-selected="true"] { color: var(--text); font-weight: 500; border-bottom-color: var(--accent); }
.tab-count { margin-left: var(--sp-1); color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Tables ------------------------------------------------------------------- */

.table-wrap, .table-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.data, .table-scroll table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table caption { padding: var(--sp-2) var(--sp-3); text-align: left; color: var(--text-muted); }
table.data th, table.data td, .table-scroll th, .table-scroll td { padding: 6px var(--sp-3); text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
table.data th, .table-scroll th { color: var(--text-muted); white-space: nowrap; background: var(--surface); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data th.num, table.data td.num { text-align: right; }
.cell-title { max-width: 52ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.data th button.sort {
  min-height: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 0;
  cursor: pointer;
}
table.data th[aria-sort="ascending"] button.sort::after { content: " ▲"; font-size: 10px; }
table.data th[aria-sort="descending"] button.sort::after { content: " ▼"; font-size: 10px; }
table.data th[aria-sort] { color: var(--text); }
.table-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--border); }
.filters { display: flex; flex-wrap: wrap; align-items: end; gap: var(--sp-3); margin: 0 0 var(--sp-3); }
.filters label { margin: 0 0 var(--sp-1); font-size: var(--fs-sm); color: var(--text-muted); }
.filters > * { min-width: 0; }
.filters select { width: auto; min-width: 140px; }
.filter-slot:empty { display: none; }
.notice { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); margin: 0 0 var(--sp-3); color: var(--accent); background: var(--accent-soft); border: 1px solid var(--border); border-radius: var(--radius); }
.notice button.quiet { color: var(--accent); font-weight: 500; }
.notice button.quiet:hover:not(:disabled) { color: var(--accent); background: var(--surface); }

/* Status: pills, dots, bars ------------------------------------------------- */

.pill { display: inline-flex; align-items: center; gap: var(--sp-1); padding: 1px var(--sp-2); font-size: var(--fs-xs); line-height: 18px; white-space: nowrap; border-radius: 999px; }
.pill .glyph { font-size: 10px; }
.pill.tone-success { color: var(--success); background: var(--success-soft); }
.pill.tone-warning { color: var(--warning); background: var(--warning-soft); }
.pill.tone-danger { color: var(--danger); background: var(--danger-soft); }
.pill.tone-accent { color: var(--accent); background: var(--accent-soft); }
.pill.tone-neutral { color: var(--text-muted); background: var(--surface-2); }

.dot-label { display: inline-flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.dot.tone-success { background: var(--success); }
.dot.tone-warning { background: var(--warning); }
.dot.tone-danger { background: var(--danger); }
.dot.tone-accent { background: var(--accent); }

.segbar { display: inline-flex; gap: 1px; width: 96px; height: 8px; vertical-align: middle; overflow: hidden; background: var(--surface-2); border-radius: 2px; }
.seg { flex: var(--n, 1) 1 0; min-width: 2px; background: var(--border-strong); }
.seg.tone-success { background: var(--success); }
.seg.tone-warning { background: var(--warning); }
.seg.tone-danger { background: var(--danger); }
.seg.tone-accent { background: var(--accent); }

.avatar { flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; font-size: var(--fs-xs); font-weight: 500; color: var(--accent); background: var(--accent-soft); border-radius: 50%; }

/* Page and bands ----------------------------------------------------------- */

.view-root { min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--sp-3) var(--sp-4); margin: 0 0 var(--sp-4); }
.page-head p { margin: var(--sp-1) 0 0; }
.band { margin: 0 0 var(--sp-5); }
.band-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-1) var(--sp-3); margin: 0 0 var(--sp-2); }
.band-head h2 { margin-right: auto; font-size: var(--fs-lg); }
.stack > .band + .band { margin-top: 0; }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); margin: var(--sp-2) 0 0; padding: 0; list-style: none; color: var(--text-muted); font-size: var(--fs-sm); }

/* Needs attention: a ranked, compact list */

.attention { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.attention > li { display: grid; grid-template-columns: minmax(6.5em, max-content) minmax(0, 1fr) auto; align-items: center; gap: var(--sp-3); padding: 6px var(--sp-3); border-bottom: 1px solid var(--border); }
.attention > li:last-child { border-bottom: 0; }
.attention > li > .pill { justify-self: start; }
.attention-body { min-width: 0; }
.attention-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attention-meta { color: var(--text-muted); font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attention-action { padding: 3px var(--sp-3); font-size: var(--fs-sm); border: 1px solid var(--border-strong); border-radius: var(--radius); color: var(--text); background: var(--surface); }
.attention-action:hover { background: var(--surface-2); text-decoration: none; }
button.attention-action { font: inherit; font-size: var(--fs-sm); cursor: pointer; }
button.attention-action:disabled { cursor: default; opacity: 0.6; }
.attention-title.wrap, .attention-meta.wrap { overflow: visible; text-overflow: clip; white-space: normal; overflow-wrap: anywhere; }

/* Alerts, responsibilities and Inbox rows (D-048 section 4.14). Colour is never the only signal:
   every severity shows a glyph and a word, and the outline differs (solid for critical, dashed for warning). */
.pill.severity-critical { font-weight: 500; border: 1px solid currentColor; }
.pill.severity-warning { border: 1px dashed currentColor; }
.attention > li[data-key^="responsibility-"] { grid-template-columns: minmax(0, 1fr) auto; }
.cover-list { margin: 0; padding: 0; list-style: none; }
.mode-list { margin: var(--sp-1) 0 0; padding: 0; list-style: none; }
.resp-health { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-1); }
.attention-more { padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--border); background: var(--surface); }
.attention + p { margin: var(--sp-2) 0 0; }

/* Team strip */

.team-strip { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.agent { display: flex; align-items: center; gap: var(--sp-3); min-width: 220px; padding: var(--sp-2) var(--sp-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.agent-name { font-weight: 500; }
.agent-meta { color: var(--text-muted); font-size: var(--fs-sm); }

/* Item and detail pages ---------------------------------------------------- */

.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--sp-1) var(--sp-4); margin: 0 0 var(--sp-4); }
.facts dt { color: var(--text-muted); font-weight: 400; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts dd ul { margin: var(--sp-1) 0 0; padding: 0; list-style: none; }
.facts dd > * + * { margin-top: var(--sp-1); }
.facts dd time { white-space: nowrap; }
.crumbs { margin: 0 0 var(--sp-2); }
.detail-heading { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); margin: 0 0 var(--sp-4); }
.status { margin: 0 0 var(--sp-1); color: var(--text-muted); }
.progress { color: var(--text-muted); }
.request-note, .report, .continuation { margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.request-note h2, .report h2, .continuation h2 { margin-bottom: var(--sp-2); }
.report li { margin-bottom: var(--sp-2); }
.item-section { margin: 0 0 var(--sp-4); }
.item-section h2, .report h2 { margin-bottom: var(--sp-2); }
.item-section ul { margin-bottom: 0; }
.citations { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin-top: var(--sp-1); }
.citation { min-height: 0; padding: 1px var(--sp-2); font-size: var(--fs-xs); color: var(--accent); background: var(--accent-soft); border-color: transparent; border-radius: 999px; }
.evidence-item { margin-bottom: var(--sp-2); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.evidence-item > summary { padding: var(--sp-2) var(--sp-3); cursor: pointer; }
.evidence-item pre { border: 0; border-top: 1px solid var(--border); border-radius: 0; }
.timeline { list-style: none; margin: 0 0 var(--sp-4); padding: 0 0 0 var(--sp-4); border-left: 1px solid var(--border-strong); }
.timeline li { position: relative; padding: 0 0 var(--sp-3) var(--sp-3); }
.timeline li::before { content: ""; position: absolute; left: -21px; top: 6px; width: 9px; height: 9px; background: var(--surface); border: 2px solid var(--accent); border-radius: 50%; }
.timeline p { margin: 0; }
.timeline li > * + * { margin-top: 2px; }
.timeline .step-meta { color: var(--text-muted); font-size: var(--fs-sm); }

/* Outbound effects on a work item page (D-047). */
.effect-card h3 { margin-bottom: var(--sp-1); }
.effect-card h4 { margin: var(--sp-3) 0 var(--sp-1); font-size: var(--fs-sm); color: var(--text-muted); font-weight: 500; }
.effect-card pre { max-height: 24rem; overflow: auto; }
.effect-card .field { margin: var(--sp-3) 0 var(--sp-2); }
.effect-card .settings-error { margin: var(--sp-2) 0; }

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

.exchange { margin: 0 0 var(--sp-2); padding: var(--sp-2) var(--sp-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.exchange.user { background: var(--accent-soft); }
.exchange h2, .exchange h3 { margin-bottom: var(--sp-1); font-size: var(--fs-xs); font-weight: 500; color: var(--text-muted); }
.exchange p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { margin-top: var(--sp-3); }
.chat-layout { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.chat-side, .chat-main { min-width: 0; }
.chat-disabled { grid-column: 1 / -1; }
.chat-main > :not([hidden]) ~ :not([hidden]) { margin-top: var(--sp-4); }
.chat-create > h2, .chat-create > h3 { margin-bottom: var(--sp-1); }
.chat-detail > * + * { margin-top: var(--sp-3); }
.chat-detail p { margin-bottom: 0; }
.chat-detail .detail-heading { margin-bottom: var(--sp-3); }
.chat-detail .exchange { margin-bottom: 0; }
.chat-detail .exchange + .exchange { margin-top: var(--sp-2); }
.conversation-list, .task-list { display: flex; flex-direction: column; gap: 1px; max-height: 60vh; overflow-y: auto; }
.chat-compact { grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); }
.chat-compact .conversation-list { max-height: 168px; }
.chat-compact .form-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
.chat-compact .composer textarea { min-height: 4.5em; }
.task-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: var(--sp-2) var(--sp-3); text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.task-item span { color: var(--text-muted); font-size: var(--fs-sm); }
.task-item[aria-current="true"] { border-color: var(--accent); }
.list-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-2); }
.memory-context, .memory-note, .capability { margin: 0 0 var(--sp-3); padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.memory-context > summary, .capability summary { cursor: pointer; }
.capability > h2, .capability > h3 { margin: 0 0 var(--sp-2); }
.capability .row h3 { margin: 0; }
.capability p { margin-bottom: var(--sp-2); }
.capability details, .capability pre, .capability .facts { margin-top: var(--sp-2); }
.capability details > summary + * { margin-top: var(--sp-2); }
.band > h3, .band section > h3 { margin: var(--sp-3) 0 var(--sp-2); }
.plugin-columns fieldset { margin-top: var(--sp-3); }
.plugin-columns label:first-child { margin-top: 0; }
.plugin-columns { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: var(--sp-5); margin-top: var(--sp-4); }
.plugin-columns > section { min-width: 0; }
.plugin-detail { margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--border); }

/* People and access ----------------------------------------------------------- */

.person { padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.person > * + * { margin-top: var(--sp-2); }
.person h3 { margin: 0; }
.person p { margin: 0; }
.person-role label { margin: 0; }
.person-role select { width: auto; min-width: 140px; }
.person-identities { margin: var(--sp-2) 0 0; padding: 0; list-style: none; }
.person-identities li { padding: var(--sp-1) 0; border-bottom: 1px solid var(--border); }
.person-identity-box > summary { cursor: pointer; }
.person-identity-box > summary + * { margin-top: var(--sp-2); }
.setup-link { padding: var(--sp-3); background: var(--warning-soft); border: 1px solid var(--warning); border-radius: var(--radius); }
.setup-link > * + * { margin-top: var(--sp-2); }
.setup-link p { margin: 0; }
.setup-url { font-family: var(--font-mono); font-size: var(--fs-sm); overflow-wrap: anywhere; word-break: break-all; max-width: 100%; user-select: all; }
.person-invite { max-width: 720px; }
/* Channels (D-050 §4.15): the one-time link code reuses .setup-link; the Enter secret control sits under its field. */
.channel-code-value { font-family: var(--font-mono); font-size: var(--fs-xl); letter-spacing: 0.08em; user-select: all; }

/* Delegation and coding runs (D-046 §5.13): the vendor sign-in panel reuses .setup-link; results are untrusted text in <pre>. */
.delegation-account { padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius); }
.delegation-account p { margin: 0; }
.run-entry > * + * { margin-top: var(--sp-2); }
.run-entry p { margin: 0; }
.run-result { margin-top: var(--sp-2); padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius); }
.run-result h4 { margin: 0 0 var(--sp-1); }
.run-diff, .run-tests { max-height: 28rem; overflow: auto; font-family: var(--font-mono); font-size: var(--fs-sm, 0.875rem); }
.run-paths { margin: 0; padding-left: var(--sp-4); }
.run-summary { white-space: pre-wrap; overflow-wrap: anywhere; }
.run-pr code { overflow-wrap: anywhere; }
.secret-entry { margin-top: var(--sp-1); }
.secret-entry input { font-family: var(--font-mono); font-size: var(--fs-sm); }

/* Access tokens (D-043 §4.8): the one-time secret reuses .setup-link; this makes the field and examples fit. */
.token-secret input { font-family: var(--font-mono); font-size: var(--fs-sm); }
.token-example { margin: var(--sp-1) 0 0; padding: var(--sp-2) var(--sp-3); overflow-x: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.token-create { max-width: 720px; }

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

.dock-launcher {
  position: fixed;
  right: var(--sp-4);
  bottom: var(--sp-4);
  z-index: 30;
  padding: 6px var(--sp-4);
  color: var(--accent-contrast);
  background: var(--accent);
  border-color: var(--accent);
  border-radius: 999px;
}
.dock-launcher:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.dock-launcher[aria-expanded="true"] { display: none; }

#dock {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: min(var(--dock-w), 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
}
body.dock-pinned #dock { position: sticky; top: var(--topbar-h); z-index: auto; width: auto; height: calc(100vh - var(--topbar-h)); }
.dock-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); }
.dock-actions { display: flex; gap: var(--sp-1); }
.dock-body { flex: 1; min-height: 0; padding: var(--sp-3); overflow-y: auto; }
.dock-foot { margin: 0; padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--border); }

/* Settings: section list and content ---------------------------------------- */

.settings { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { padding: 6px var(--sp-3); color: var(--text-muted); border-radius: var(--radius); }
.settings-nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.settings-nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 500; }

/* Managed settings (D-044): save feedback, field errors, history diff. */
.settings-feedback > * + * { margin-top: var(--sp-2); }
.pending-banner { padding: var(--sp-2) var(--sp-3); color: var(--warning); background: var(--warning-soft); border: 1px solid var(--border); border-radius: var(--radius); }
.settings-error { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); color: var(--danger); background: var(--danger-soft); border: 1px solid var(--danger); border-radius: var(--radius); }
.field-invalid { padding: var(--sp-2); border: 1px solid var(--danger); border-radius: var(--radius); background: var(--danger-soft); }
.diff { font-family: var(--font-mono); font-size: var(--fs-sm); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.diff-line { display: flex; gap: var(--sp-2); padding: 0 var(--sp-3); white-space: pre; }
.diff-line code { font: inherit; }
.diff-mark { flex: none; width: 1ch; color: var(--text-muted); }
.diff-add { color: var(--success); background: var(--success-soft); }
.diff-del { color: var(--danger); background: var(--danger-soft); }
.diff-add .diff-mark, .diff-del .diff-mark { color: inherit; font-weight: 500; }

/* Knowledge (D-049): tab select, cards, plain text. */
.tab-select { display: none; margin: 0 0 var(--sp-3); }
.plain-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.learning-card { padding: var(--sp-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.learning-card h3 { margin: 0 0 var(--sp-1); }
.learning-card > * + * { margin-top: var(--sp-2); }
.badges { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin-top: var(--sp-1); }
.sources { margin: 0; padding: 0; list-style: none; }
.sources li { overflow-wrap: anywhere; }
.tab-panel > * + * { margin-top: var(--sp-3); }

/* Integrations (D-045): catalog cards, method lists, flow panels. */
.integration-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--sp-3); }
.integration-card, .integration-panel { padding: var(--sp-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.integration-card h4 { margin: 0 0 var(--sp-1); }
.integration-methods, .integration-installations { margin: 0; padding: 0; list-style: none; }
.integration-methods > li, .integration-installations > li { padding: var(--sp-2) 0; border-top: 1px solid var(--border); }
.integration-methods > li > * + * { margin-top: var(--sp-1); }
.integration-card .notice { display: block; }
details[data-key="advanced"] > summary { cursor: pointer; margin-bottom: var(--sp-2); }

/* Operations (D-045): the project page panel, the ops dots, and the project settings editor. */
.ops-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--sp-3); }
.ops-card { min-width: 0; padding: var(--sp-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.ops-card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.ops-card-head h3 { margin: 0; }
.ops-card-head .dot-label { margin-left: auto; }
.ops-indicators, .ops-targets { margin: 0; padding: 0; list-style: none; }
.ops-indicator { padding: var(--sp-2) 0; border-top: 1px solid var(--border); }
.ops-line, .ops-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-1) var(--sp-3); min-width: 0; }
.ops-summary { overflow-wrap: anywhere; }
.ops-trend { font-family: var(--font-mono); letter-spacing: 0.1em; }
.ops-memory { margin-top: var(--sp-3); }
.ops-memory h3 { margin: 0 0 var(--sp-1); }
.ops-targets { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); }
.ops-target { white-space: nowrap; }
.ops-editor { display: grid; gap: var(--sp-3); }
.ops-editor fieldset { min-width: 0; }
.ops-row { display: flex; flex-wrap: wrap; align-items: end; gap: var(--sp-2); padding: var(--sp-2) 0; }
.ops-row .field { margin: 0; min-width: 0; }
.ops-nested { margin-left: var(--sp-3); padding-left: var(--sp-3); border-left: 2px solid var(--border); }
.ops-params { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* Empty, loading and error states -------------------------------------------- */

.empty { margin: 0; padding: var(--sp-5) var(--sp-4); color: var(--text-muted); text-align: center; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.loading { padding: var(--sp-4) 0; }
.error-panel { padding: var(--sp-4); background: var(--danger-soft); border: 1px solid var(--border); border-radius: var(--radius); }
.error-panel h1 { margin-bottom: var(--sp-2); color: var(--danger); font-size: var(--fs-lg); }
.placeholder { max-width: 60ch; }

/* Phone width (375 x 812 checked): nothing scrolls the page sideways ------------ */

@media (max-width: 900px) {
  .signin { grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); padding-top: var(--sp-3); }
  .plugin-columns { grid-template-columns: minmax(0, 1fr); }
  body.dock-pinned .shell { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar { position: static; flex-wrap: wrap; gap: 0 var(--sp-3); padding: var(--sp-1) var(--sp-3) 0; }
  .topbar-end { gap: var(--sp-1); }
  .primary-nav { order: 3; flex: 1 0 100%; margin: 0 calc(-1 * var(--sp-3)); padding: 0 var(--sp-3); overflow-x: auto; overscroll-behavior-x: contain; }
  main { padding: var(--sp-4) var(--sp-3) calc(var(--sp-5) + var(--launcher-h)); }
  .footer { padding-bottom: 64px; }
  .form-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  button, a.button { min-height: 40px; }
  .page-head .actions { width: 100%; }
  .table-foot { padding: var(--sp-2) 0; border-top: 0; }
  .table-foot .actions { margin-left: auto; }
  .notice { align-items: stretch; }
  .chat-layout { grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); }
  .chat-side .conversation-list { max-height: 240px; }
  .legend { gap: var(--sp-1) var(--sp-3); }
  .tabs button, .tabs a { padding: var(--sp-3); }
  .settings { grid-template-columns: minmax(0, 1fr); gap: var(--sp-3); }
  .settings-nav { flex-direction: row; flex-wrap: wrap; gap: var(--sp-1); padding-bottom: var(--sp-2); border-bottom: 1px solid var(--border); }
  .settings-nav a { padding: var(--sp-2) var(--sp-3); white-space: nowrap; }
  .facts { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .facts dd { margin-bottom: var(--sp-2); }
  .filters select { width: 100%; }
  .knowledge-tabs { display: none; }
  .tab-select { display: block; }
  .tab-select select { width: 100%; }
  .agent { min-width: 0; width: 100%; }
  .plugin-columns { gap: var(--sp-4); }

  /* An attention row stacks: status, then the full title and facts (they wrap), then the action. */
  .attention > li, .attention > li[data-key^="responsibility-"] { grid-template-columns: minmax(0, 1fr); gap: var(--sp-1); padding: var(--sp-2) var(--sp-3); }
  .attention-title, .attention-meta { white-space: normal; overflow: visible; }
  .attention-action { justify-self: start; margin-top: var(--sp-1); }

  /* Tables become stacked rows. The header stays for assistive technology only. */
  .table-wrap, .table-scroll { overflow-x: visible; background: none; border: 0; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; }
  table.data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.data tr { margin: 0 0 var(--sp-2); padding: var(--sp-1) 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
  table.data td { display: grid; grid-template-columns: 8.5em minmax(0, 1fr); gap: var(--sp-2); padding: 4px var(--sp-3); border-bottom: 0; }
  table.data td[data-label]::before { content: attr(data-label); color: var(--text-muted); }
  table.data td > * { grid-column: 2; }
  table.data td > .pill, table.data td > .segbar { justify-self: start; align-self: center; }
  table.data td.num { text-align: left; }
  table.data tbody tr:hover td { background: none; }
  .cell-title { max-width: none; white-space: normal; }

  /* The dock becomes a full-screen sheet and cannot be pinned beside the page. */
  #dock, body.dock-pinned #dock { position: fixed; inset: 0; z-index: 50; width: auto; height: auto; border-left: 0; }
  .dock-launcher { right: var(--sp-3); bottom: var(--sp-3); }
}

@media (max-width: 599px) {
  .account-name { display: none; }
  .profile-body { grid-template-columns: minmax(0, 1fr); }
  .profile-tabs { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border); }
}

@media (forced-colors: active) {
  .account-theme .account-item[aria-checked="true"] { border-color: Highlight; }
  .profile-tab[aria-selected="true"] { border-color: Highlight; }
  .pill { border: 1px solid CanvasText; }
  .dot, .seg { forced-color-adjust: none; }
  .segbar { border: 1px solid CanvasText; }
  .tabs [aria-current="page"], .tabs [aria-current="true"], .tabs [aria-selected="true"] { border-bottom-color: Highlight; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Devices section of the profile dialog (D-076 §3.7). */
.devices { list-style: none; margin: 0; padding: 0; }
.device { padding: var(--sp-3) 0; border-bottom: 1px solid var(--border); }
.device:last-child { border-bottom: 0; }
.device-name { font-weight: 500; }
