/* Mach33 5-Panel Shell — fixed layout, panel contracts, voice-aware. */

:root {
  --m33-bg: #0f1117;
  --m33-panel: #1a1d27;
  --m33-border: #2a2d3a;
  --m33-text: #e1e4ed;
  --m33-text-muted: #8b8fa3;
  --m33-accent: #6366f1;
  --m33-accent-hover: #818cf8;
  --m33-card: #22253a;
  --m33-good: #34d399;
  --m33-warn: #fbbf24;
  --m33-bad: #f87171;
}

[data-theme="light"] {
  --m33-bg: #f0f2f5;
  --m33-panel: #ffffff;
  --m33-border: #e0e3e8;
  --m33-text: #1a1d27;
  --m33-text-muted: #6b7280;
  --m33-accent: #6366f1;
  --m33-accent-hover: #4f46e5;
  --m33-card: #f8f9fb;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--m33-bg);
  color: var(--m33-text);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.4;
}

/* Grid — header / [left | center | right] / footer.
   Roles and positions are fixed (AP7). The application fills the cells. */
.m33-app {
  display: grid;
  grid-template-areas:
    "header header header"
    "left   center right"
    "footer footer footer";
  grid-template-columns: 240px 1fr 320px;
  grid-template-rows: 56px 1fr 32px;
  height: 100vh;
  gap: 1px;
  background: var(--m33-border);
  transition: grid-template-columns 0.25s ease;
}
.m33-app.m33-left-collapsed { grid-template-columns: 56px 1fr 320px; }
.m33-app.m33-right-collapsed { grid-template-columns: 240px 1fr 0; }
.m33-app.m33-left-collapsed.m33-right-collapsed { grid-template-columns: 56px 1fr 0; }

.m33-panel { background: var(--m33-panel); overflow-y: auto; }

/* Header — global. Logo, app name, app-nav, agent access, assistant access, profile, settings.
   The framework owns the right cluster (AP7). The application owns the left nav slot. */
.m33-header {
  grid-area: header;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--m33-border);
}
.m33-header-left, .m33-header-right { display: flex; align-items: center; gap: 10px; }
.m33-logo {
  width: 28px; height: 28px; border-radius: 6px;
  background: url('/m33-static/33fg_logo.png') center/contain no-repeat;
  /* Hide the inline "M33" text the framework template renders inside
   * the div — we replace it visually with the image but keep the text
   * for screen readers via text-indent + overflow. */
  color: transparent; text-indent: -9999px; overflow: hidden;
  display: inline-block; flex-shrink: 0;
}
.m33-app-name { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.m33-app-name-bold { font-weight: 700; }
.m33-app-name-thin { font-weight: 300; opacity: 0.85; letter-spacing: 0.01em; }

/* User profile dropdown — anchored to the avatar in the header right
 * cluster. Hidden by default; opened/positioned by JS in
 * lib/vega-shell-extras.js. */
.m33-profile-menu {
  position: fixed; top: 56px; right: 8px; min-width: 220px;
  background: var(--m33-panel); color: var(--m33-text);
  border: 1px solid var(--m33-border); border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
  display: none; z-index: 200; padding: 4px 0;
  font-size: 13px;
}
.m33-profile-menu.m33-open { display: block; }
.m33-profile-menu-head { padding: 10px 14px 8px; border-bottom: 1px solid var(--m33-border); }
.m33-profile-menu-name { font-weight: 600; }
.m33-profile-menu-id { font-size: 11px; color: var(--m33-text-muted); margin-top: 1px; }
.m33-profile-menu-item {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 8px 14px; background: transparent; border: 0;
  color: inherit; text-align: left; cursor: pointer; font: inherit;
}
.m33-profile-menu-item:hover { background: var(--m33-card); }
.m33-profile-menu-sep { height: 1px; background: var(--m33-border); margin: 4px 0; }
.m33-profile-menu-danger { color: var(--m33-warn, #ff5050); }
.m33-profile-menu-badge {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--m33-accent);
}
.m33-profile-menu-badge[hidden] { display: none; }
.m33-user { cursor: pointer; user-select: none; }

/* Generic modal harness — used by the profile dropdown panels (Agency
 * Settings, System Settings, Notifications, Agents). One shared
 * instance, content swapped per open. */
.m33-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none; align-items: flex-start; justify-content: center;
  z-index: 300;
  padding: 64px 16px 32px;
  overflow-y: auto;
}
.m33-modal-backdrop.m33-open { display: flex; }
.m33-modal {
  width: 100%; max-width: 540px;
  background: var(--m33-panel); color: var(--m33-text);
  border: 1px solid var(--m33-border); border-radius: 10px;
  box-shadow: 0 24px 56px rgba(0,0,0,0.5);
  display: flex; flex-direction: column;
  max-height: calc(100vh - 96px);
}
.m33-modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--m33-border); }
.m33-modal-title { font-size: 14px; font-weight: 600; flex: 1; margin: 0; text-transform: none; letter-spacing: 0; color: var(--m33-text); }
.m33-modal-close { background: transparent; border: 0; color: var(--m33-text-muted); font-size: 22px; cursor: pointer; padding: 0 6px; line-height: 1; }
.m33-modal-close:hover { color: var(--m33-text); }
.m33-modal-body { padding: 12px 16px 18px; overflow-y: auto; font-size: 13px; }
.m33-modal-loading { color: var(--m33-text-muted); padding: 20px 0; text-align: center; }
.m33-modal-section { padding: 10px 0; border-bottom: 1px solid color-mix(in oklab, var(--m33-border) 50%, transparent 50%); }
.m33-modal-section:last-child { border-bottom: 0; }
.m33-modal-section-head { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--m33-text-muted); margin-bottom: 6px; }
.m33-modal-row { display: flex; gap: 14px; padding: 6px 0; align-items: baseline; }
.m33-modal-row-key { flex: 0 0 130px; color: var(--m33-text-muted); font-size: 12px; }
.m33-modal-row-val { flex: 1; color: var(--m33-text); }
.m33-modal-note { padding: 6px 0; }
.m33-muted { color: var(--m33-text-muted); }
.m33-modal-note-row { padding: 10px 0; border-bottom: 1px solid color-mix(in oklab, var(--m33-border) 40%, transparent 60%); }
.m33-modal-note-row:last-child { border-bottom: 0; }
.m33-modal-note-title { font-weight: 500; margin-bottom: 2px; }
.m33-modal-note-body { color: var(--m33-text-muted); font-size: 12px; line-height: 1.45; }
.m33-modal-agent-row { padding: 12px 0; border-bottom: 1px solid color-mix(in oklab, var(--m33-border) 40%, transparent 60%); }
.m33-modal-agent-row:last-child { border-bottom: 0; }
.m33-modal-agent-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.m33-modal-agent-desc { color: var(--m33-text-muted); font-size: 12px; margin: 2px 0 4px; }
.m33-modal-agent-meta { font-size: 11px; color: var(--m33-text-muted); }
.m33-status-pill { font-size: 9px; font-weight: 600; padding: 2px 8px; border-radius: 8px; text-transform: uppercase; letter-spacing: 0.06em; }
.m33-status-built    { background: color-mix(in oklab, var(--m33-good)   25%, transparent 75%); color: var(--m33-good); }
.m33-status-planned  { background: color-mix(in oklab, var(--m33-text-muted) 20%, transparent 80%); color: var(--m33-text-muted); }
.m33-status-disabled { background: color-mix(in oklab, var(--m33-warn)   20%, transparent 80%); color: var(--m33-warn); }

/* Agents modal — tabbed view + per-agent inline CRUD form.
 * Fixed body size so switching tabs / drilling into an agent / popping
 * the New Agent form doesn't make the modal jump. The list, the detail
 * view, and the New form all share the same dimensions. */
.m33-modal:has(.m33-agents-modal),
.m33-modal:has(.m33-agent-detail),
.m33-modal:has(.m33-agent-new) { width: 980px; max-width: 95vw; }
.m33-modal:has(.m33-agents-modal) .m33-modal-body,
.m33-modal:has(.m33-agent-detail) .m33-modal-body,
.m33-modal:has(.m33-agent-new) .m33-modal-body {
  min-height: 540px; max-height: 70vh;
  overflow-y: auto;
}
.m33-agents-modal { display: flex; flex-direction: column; gap: 12px; }

/* Aggregate stats strip — slim inline summary at the top of the
 * Agents modal. Reads as a single header line, not a grid of cards.
 * "<value> <label>" pairs separated by middots. */
.m33-agents-stats {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: 4px 16px;
  padding: 2px 2px 6px;
  font-size: 11px;
  color: var(--m33-text-muted);
}
.m33-agents-stat-pill { display: inline-flex; align-items: baseline; gap: 4px; }
.m33-agents-stat-value {
  font-weight: 600; color: var(--m33-text);
  font-variant-numeric: tabular-nums;
}
.m33-agents-stat-value.m33-stat-good  { color: var(--m33-good); }
.m33-agents-stat-value.m33-stat-muted { color: var(--m33-text-muted); }
.m33-agents-stat-value.m33-stat-warn  { color: var(--m33-warn); }
.m33-agents-stat-label { color: var(--m33-text-muted); text-transform: lowercase; }
.m33-agents-tabs {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  border-bottom: 1px solid var(--m33-border); padding-bottom: 8px;
  position: sticky; top: 0; background: var(--m33-panel); z-index: 1;
}
.m33-agents-tab {
  background: transparent; border: 1px solid transparent; color: var(--m33-text-muted);
  padding: 6px 10px; border-radius: 6px; font-size: 12px; cursor: pointer;
  text-transform: capitalize; display: inline-flex; align-items: center; gap: 6px;
}
.m33-agents-tab:hover { color: var(--m33-text); background: var(--m33-card); }
.m33-agents-tab.m33-active { color: var(--m33-text); background: var(--m33-card); border-color: var(--m33-border); }
.m33-agents-tab-count { font-size: 10px; opacity: 0.7; padding: 1px 6px; border-radius: 8px; background: color-mix(in oklab, var(--m33-text-muted) 20%, transparent 80%); }
.m33-agents-new-btn {
  margin-left: auto; background: transparent; border: 1px dashed var(--m33-border);
  color: var(--m33-text-muted); padding: 4px 10px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.m33-agents-new-btn:hover { color: var(--m33-accent); border-color: var(--m33-accent); }

.m33-agents-pane { display: none; }
.m33-agents-pane.m33-active { display: block; }
.m33-agents-pane-grid.m33-active {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  padding: 4px 2px;
}

/* View-toggle (Grid | List) — small segmented control in the tab bar */
.m33-agents-view-toggle {
  display: inline-flex; align-items: center; gap: 0;
  margin-left: auto; padding: 2px;
  background: var(--m33-card); border: 1px solid var(--m33-border);
  border-radius: 6px;
}
.m33-agents-view-btn {
  background: transparent; border: 0; cursor: pointer;
  width: 28px; height: 24px; border-radius: 4px;
  color: var(--m33-text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.m33-agents-view-btn:hover { color: var(--m33-text); }
.m33-agents-view-btn.m33-active { background: var(--m33-panel); color: var(--m33-text); }
/* Push the "+ New agent" button right of the view toggle. */
.m33-agents-view-toggle + .m33-agents-new-btn { margin-left: 8px; }
.m33-agents-tabs:has(.m33-agents-view-toggle) .m33-agents-new-btn { margin-left: 8px; }

/* Square agent tile — grid view. Aspect 1:1, icon + name + stats. */
.m33-agent-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex; flex-direction: column; align-items: flex-start;
  justify-content: space-between;
  padding: 12px;
  background: var(--m33-card); border: 1px solid var(--m33-border);
  border-radius: 10px; cursor: pointer;
  text-align: left;
  font: inherit; color: var(--m33-text);
  transition: border-color 120ms, transform 120ms, box-shadow 120ms;
  overflow: hidden;
}
.m33-agent-tile:hover {
  border-color: var(--m33-accent);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px color-mix(in oklab, var(--m33-accent) 20%, transparent 80%);
}
.m33-agent-tile-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px;
  color: var(--m33-accent);
  background: color-mix(in oklab, var(--m33-accent) 14%, transparent 86%);
  margin-bottom: auto;
}
.m33-agent-tile-icon svg { width: 22px; height: 22px; }
.m33-agent-tile-name {
  font-weight: 600; font-size: 13px; line-height: 1.25;
  margin-top: 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}
.m33-agent-tile-cat {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--m33-text-muted); margin-top: 2px;
}
.m33-agent-tile-stats {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 8px; width: 100%;
}
.m33-agent-tile-runs { font-size: 10px; color: var(--m33-text-muted); }

/* Per-category tile accents — subtle colored top stripe so categories
 * read at a glance even when grouped together (e.g. on a non-grouped
 * search later). */
.m33-cat-ingestor    .m33-agent-tile-icon { color: #8ab4ff; background: color-mix(in oklab, #8ab4ff 14%, transparent 86%); }
.m33-cat-curator     .m33-agent-tile-icon { color: #ffb86b; background: color-mix(in oklab, #ffb86b 14%, transparent 86%); }
.m33-cat-critic      .m33-agent-tile-icon { color: #ff8a8a; background: color-mix(in oklab, #ff8a8a 14%, transparent 86%); }
.m33-cat-epistemic   .m33-agent-tile-icon { color: #c7a2ff; background: color-mix(in oklab, #c7a2ff 14%, transparent 86%); }
.m33-cat-inquirer    .m33-agent-tile-icon { color: #6fd6c8; background: color-mix(in oklab, #6fd6c8 14%, transparent 86%); }
.m33-cat-composer    .m33-agent-tile-icon { color: #b3e08e; background: color-mix(in oklab, #b3e08e 14%, transparent 86%); }
.m33-cat-observer    .m33-agent-tile-icon { color: #f0a8d6; background: color-mix(in oklab, #f0a8d6 14%, transparent 86%); }
.m33-cat-coordinator .m33-agent-tile-icon { color: var(--m33-accent); background: color-mix(in oklab, var(--m33-accent) 14%, transparent 86%); }

.m33-agent-row { padding: 12px 0; border-bottom: 1px solid color-mix(in oklab, var(--m33-border) 40%, transparent 60%); }
.m33-agent-row:last-child { border-bottom: 0; }
.m33-agent-row-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.m33-agent-row-title { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.m33-agent-row-actions { display: inline-flex; gap: 4px; }
.m33-agent-action {
  background: transparent; border: 1px solid var(--m33-border); color: var(--m33-text-muted);
  padding: 3px 10px; border-radius: 5px; font-size: 11px; cursor: pointer;
}
.m33-agent-action:hover { color: var(--m33-text); border-color: var(--m33-text-muted); }
.m33-agent-danger { color: var(--m33-warn); border-color: color-mix(in oklab, var(--m33-warn) 40%, var(--m33-border) 60%); }
.m33-agent-danger:hover { background: color-mix(in oklab, var(--m33-warn) 12%, transparent 88%); color: var(--m33-warn); }

.m33-agent-edit {
  margin-top: 10px; padding: 12px; background: var(--m33-card);
  border: 1px solid var(--m33-border); border-radius: 8px;
}
.m33-agent-edit[hidden] { display: none; }
.m33-agent-form { display: flex; flex-direction: column; gap: 8px; }
.m33-agent-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.m33-agent-cb-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0; }
.m33-agent-cb { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; cursor: pointer; }
.m33-agent-cb input { margin: 0; }

.m33-agent-new { background: color-mix(in oklab, var(--m33-accent) 5%, transparent 95%); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.m33-agent-new .m33-agent-edit { background: transparent; border: 0; padding: 0; margin-top: 0; }

/* Make the agent row a button-styled clickable surface (it's a <button>
 * for keyboard a11y). Strips browser button defaults so it reads as a
 * row, not a control. */
button.m33-agent-row {
  width: 100%; text-align: left; cursor: pointer;
  background: transparent; border: 0; border-bottom: 1px solid color-mix(in oklab, var(--m33-border) 40%, transparent 60%);
  padding: 12px 4px; color: inherit; font: inherit;
  display: flex; flex-direction: column; gap: 4px;
}
button.m33-agent-row:hover { background: color-mix(in oklab, var(--m33-card) 60%, transparent 40%); }
button.m33-agent-row:focus { outline: 2px solid var(--m33-accent); outline-offset: -2px; }
.m33-agent-row-chev { color: var(--m33-text-muted); font-size: 18px; line-height: 1; flex: 0 0 auto; }

/* Detail view — header, tabs, body */
.m33-agent-detail { display: flex; flex-direction: column; gap: 12px; }
.m33-agent-detail-head {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 8px; border-bottom: 1px solid var(--m33-border);
}
.m33-agent-back {
  background: transparent; border: 1px solid var(--m33-border);
  color: var(--m33-text-muted); padding: 4px 10px; border-radius: 6px;
  font-size: 12px; cursor: pointer;
}
.m33-agent-back:hover { color: var(--m33-text); border-color: var(--m33-text-muted); }
.m33-agent-detail-title { font-size: 14px; font-weight: 600; font-family: ui-monospace, 'SF Mono', Menlo, monospace; }
.m33-detail-tabs { padding-bottom: 0; border-bottom: 0; position: static; }
.m33-detail-tabs .m33-agents-tab { font-size: 12px; }
.m33-agent-detail-body { min-height: 200px; }

/* Memory / lessons preformatted blocks */
.m33-agent-memory-blob, .m33-agent-lessons {
  background: var(--m33-card); border: 1px solid var(--m33-border);
  border-radius: 6px; padding: 10px 12px; font-size: 11px;
  max-height: 300px; overflow: auto; white-space: pre-wrap;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  color: var(--m33-text-muted);
}
.m33-agent-lessons { color: var(--m33-text); white-space: pre-wrap; }

/* Drafts list + detail (Composer outputs). */
.m33-drafts-list { display: flex; flex-direction: column; gap: 12px; }
.m33-draft-card {
  display: block; padding: 14px 16px; border: 1px solid var(--m33-border);
  border-radius: 10px; background: var(--m33-card);
  text-decoration: none; color: inherit;
  transition: border-color 120ms, transform 120ms;
}
.m33-draft-card:hover { border-color: var(--m33-accent); transform: translateY(-1px); }
.m33-draft-card-head { display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--m33-text-muted); margin-bottom: 6px; }
.m33-draft-format { background: color-mix(in oklab, var(--m33-accent) 15%, transparent 85%); color: var(--m33-accent); padding: 2px 8px; border-radius: 8px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; }
.m33-draft-time { margin-left: auto; }
.m33-draft-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; line-height: 1.3; }
.m33-draft-prompt { font-size: 12px; color: var(--m33-text-muted); font-style: italic; margin-bottom: 6px; }
.m33-draft-meta { font-size: 11px; color: var(--m33-text-muted); }

.m33-status-draft     { background: color-mix(in oklab, var(--m33-text-muted) 20%, transparent 80%); color: var(--m33-text-muted); }
.m33-status-final     { background: color-mix(in oklab, var(--m33-good)   20%, transparent 80%); color: var(--m33-good); }
.m33-status-published { background: color-mix(in oklab, var(--m33-accent) 20%, transparent 80%); color: var(--m33-accent); }

.m33-draft-page { max-width: 760px; margin: 0 auto; padding: 8px 0; }
.m33-draft-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.m33-back-link { color: var(--m33-text-muted); text-decoration: none; font-size: 12px; padding: 4px 10px; border: 1px solid var(--m33-border); border-radius: 6px; }
.m33-back-link:hover { color: var(--m33-text); border-color: var(--m33-text-muted); }
.m33-draft-actions { margin-left: auto; display: inline-flex; gap: 6px; }
.m33-draft-title-h1 { font-size: 22px; font-weight: 700; margin: 0 0 8px; line-height: 1.25; }
.m33-draft-body {
  font-size: 14px; line-height: 1.7; color: var(--m33-text);
  white-space: pre-wrap; padding: 14px 0;
}
.m33-draft-cite {
  background: color-mix(in oklab, var(--m33-accent) 12%, transparent 88%);
  color: var(--m33-accent); border-radius: 4px;
  padding: 1px 4px; text-decoration: none; font-size: 11px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  cursor: pointer;
}
.m33-draft-cite:hover { background: color-mix(in oklab, var(--m33-accent) 25%, transparent 75%); }

/* Citations side-panel (right rail on /drafts?id=...) */
.m33-draft-cite-row {
  padding: 10px 0; border-bottom: 1px solid color-mix(in oklab, var(--m33-border) 40%, transparent 60%);
  transition: background 200ms;
}
.m33-draft-cite-row:last-child { border-bottom: 0; }
.m33-draft-cite-pulse { background: color-mix(in oklab, var(--m33-accent) 10%, transparent 90%); }
.m33-draft-cite-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.m33-draft-cite-id { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 11px; color: var(--m33-accent); }
.m33-draft-cite-pred { font-size: 12px; line-height: 1.4; color: var(--m33-text); margin-bottom: 4px; }
.m33-draft-cite-src { font-size: 10px; color: var(--m33-text-muted); word-break: break-all; }
.m33-draft-cite-src:hover { color: var(--m33-accent); }

/* Draft modal — two-column layout: prose on the left, citations on
 * the right. Falls back to a single column on narrow modals. */
.m33-draft-modal { display: flex; flex-direction: column; gap: 12px; }
.m33-draft-modal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-bottom: 8px; border-bottom: 1px solid var(--m33-border); }
.m33-draft-modal-actions { margin-left: auto; display: inline-flex; gap: 6px; }
.m33-draft-kfloor { font-size: 11px; color: var(--m33-text-muted); font-variant-numeric: tabular-nums; }
.m33-draft-modal-grid {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 24px;
}
@media (max-width: 720px) {
  .m33-draft-modal-grid { grid-template-columns: 1fr; }
}
.m33-draft-modal-body {
  font-size: 14px; line-height: 1.65; color: var(--m33-text);
  min-width: 0;
}
.m33-draft-modal-body h1 { font-size: 22px; font-weight: 700; margin: 18px 0 10px; line-height: 1.25; }
.m33-draft-modal-body h2 { font-size: 17px; font-weight: 700; margin: 18px 0 8px; }
.m33-draft-modal-body h3 { font-size: 14px; font-weight: 600; margin: 14px 0 6px; color: var(--m33-text); text-transform: uppercase; letter-spacing: 0.04em; }
.m33-draft-modal-body h4 { font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
.m33-draft-modal-body p  { margin: 0 0 12px; }
.m33-draft-modal-body ul, .m33-draft-modal-body ol { margin: 0 0 12px; padding-left: 22px; }
.m33-draft-modal-body li { margin: 4px 0; }
.m33-draft-modal-body strong { font-weight: 700; color: var(--m33-text); }
.m33-draft-modal-body em { font-style: italic; }
.m33-draft-modal-body code { background: var(--m33-card); padding: 1px 6px; border-radius: 4px; font-size: 12px; font-family: ui-monospace, 'SF Mono', Menlo, monospace; }
.m33-draft-modal-body blockquote { border-left: 3px solid var(--m33-accent); margin: 8px 0; padding: 4px 12px; color: var(--m33-text-muted); }
.m33-draft-modal-cites { min-width: 0; }
.m33-draft-modal-cites .m33-modal-section-head { margin-bottom: 8px; }

/* Make the modal wider for drafts so the prose has room. The harness
 * has a fixed default width; `.m33-modal--wide` opts into a roomier one. */
.m33-modal:has(.m33-draft-modal),
.m33-modal:has(.m33-draft-editor),
.m33-modal:has(.m33-pdf-paper) { max-width: 920px; width: 92vw; }

/* Login page — modal-style card on a soft gradient backdrop. The 33fg
 * logo crowns the card, brand name reads as the page title. */
body[data-skin="login"] {
  margin: 0; min-height: 100vh; color: var(--m33-text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at 30% 20%, color-mix(in oklab, var(--m33-accent) 14%, var(--m33-bg) 86%) 0%, var(--m33-bg) 60%) fixed;
}
.m33-login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 32px 24px; box-sizing: border-box; }
.m33-login-card {
  background: color-mix(in oklab, var(--m33-panel) 92%, transparent 8%);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid color-mix(in oklab, var(--m33-border) 70%, transparent 30%);
  border-radius: 16px;
  padding: 40px 40px 28px;
  width: 100%; max-width: 420px;
  box-shadow: 0 20px 64px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.02) inset;
  text-align: center;
}
.m33-login-logo-wrap { display: flex; align-items: center; justify-content: center; margin-bottom: 20px; }
.m33-login-logo { width: 64px; height: 64px; object-fit: contain; filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4)); }
.m33-login-title { font-size: 18px; font-weight: 500; margin: 0 0 4px; color: var(--m33-text); letter-spacing: -0.01em; }
.m33-login-title .m33-app-name-bold { font-weight: 700; }
.m33-login-title .m33-app-name-thin { font-weight: 300; opacity: 0.85; letter-spacing: 0.01em; }
.m33-login-subtitle { font-size: 12px; color: var(--m33-text-muted); margin-bottom: 24px; }
.m33-login-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.m33-login-field { display: flex; flex-direction: column; gap: 5px; }
.m33-login-field > span { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--m33-text-muted); }
.m33-login-field > input {
  background: var(--m33-card); border: 1px solid var(--m33-border); border-radius: 8px;
  color: var(--m33-text); padding: 11px 13px; font-size: 14px; width: 100%; box-sizing: border-box;
  outline: none; transition: border-color 120ms, box-shadow 120ms;
  font-family: inherit;
}
.m33-login-field > input::placeholder { color: color-mix(in oklab, var(--m33-text-muted) 60%, transparent 40%); }
.m33-login-field > input:focus { border-color: var(--m33-accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--m33-accent) 20%, transparent 80%); }
.m33-login-form .m33-primary-btn {
  margin-top: 10px; padding: 12px 16px; font-size: 14px; width: 100%;
  border-radius: 8px; font-weight: 600;
}

/* Password eye toggle — sits inside the field on the right edge. */
.m33-login-pw-wrap { position: relative; display: flex; align-items: stretch; }
.m33-login-pw-wrap > input { padding-right: 42px; flex: 1; }
.m33-login-pw-eye {
  position: absolute; top: 0; bottom: 0; right: 4px;
  background: transparent; border: 0; cursor: pointer;
  color: var(--m33-text-muted); padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px;
}
.m33-login-pw-eye:hover { color: var(--m33-text); background: color-mix(in oklab, var(--m33-text-muted) 12%, transparent 88%); }
.m33-login-pw-eye.m33-eye-open { color: var(--m33-accent); }

/* Passkey / Touch ID button — secondary action, only visible when the
 * browser supports a platform authenticator. */
.m33-login-passkey {
  margin-top: 4px; padding: 10px 14px; font-size: 13px; width: 100%;
  background: transparent; border: 1px solid var(--m33-border);
  color: var(--m33-text); border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: border-color 120ms, background 120ms;
}
.m33-login-passkey:hover { border-color: var(--m33-accent); background: color-mix(in oklab, var(--m33-accent) 8%, transparent 92%); }
.m33-login-passkey:disabled { opacity: 0.6; cursor: default; }
.m33-login-passkey svg { flex: 0 0 auto; }
.m33-login-foot { margin-top: 20px; padding-top: 16px; border-top: 1px solid color-mix(in oklab, var(--m33-border) 50%, transparent 50%); font-size: 11px; color: var(--m33-text-muted); }
.m33-login-page .m33-flash-error { margin-bottom: 14px; padding: 10px 12px; border-radius: 6px; font-size: 13px; text-align: left; }

/* Admin Settings — modal-wide layout + permission matrix */
.m33-modal:has(.m33-admin-modal) { max-width: 980px; width: 94vw; }
.m33-admin-modal { display: flex; flex-direction: column; gap: 12px; }
.m33-admin-body { min-height: 240px; }
.m33-perms-table input[type="checkbox"] { transform: scale(1.1); }
.m33-perms-table td:nth-child(n+3):not(:last-child) { text-align: center; }
.m33-admin-user-form { display: flex; flex-direction: column; gap: 10px; max-width: 560px; margin: 0 auto; }
.m33-users-list { display: flex; flex-direction: column; gap: 0; }
.m33-user-detail { display: flex; flex-direction: column; gap: 12px; }
.m33-user-detail-body { min-height: 240px; }
.m33-perm-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid color-mix(in oklab, var(--m33-border) 40%, transparent 60%); }
.m33-perm-row:last-child { border-bottom: 0; }
.m33-perm-row > input[type="checkbox"] { margin-top: 3px; transform: scale(1.1); flex: 0 0 auto; }
.m33-perm-row > span { font-size: 13px; line-height: 1.5; }
.m33-perm-row .m33-muted { font-size: 12px; }

/* "Jump to latest" pill — appears when the chat-stream is scrolled
 * away from the live edge. Click → smooth scroll back to bottom.
 * Hidden by default; the chat IIFE adds .m33-visible on scroll up. */
.m33-chat-jump {
  position: absolute; bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(8px);
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--m33-panel); border: 1px solid var(--m33-border);
  color: var(--m33-text-muted);
  cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease, color 120ms, background 120ms;
  z-index: 60;
}
.m33-chat-jump.m33-visible {
  opacity: 1; transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.m33-chat-jump:hover { color: var(--m33-text); background: var(--m33-card); border-color: var(--m33-text-muted); }
/* Compact mode (right rail of canvas) — pull the pill closer to the
 * input since the rail is narrower and the form sits tighter. */
.m33-chat-compact .m33-chat-jump { bottom: 64px; }

/* Scope chip — sits above the chat input, only visible when the user
 * has cards selected on the canvas. Tells the user that their next
 * message will be scoped to the selection (and Vega will acknowledge). */
.m33-scope-chip {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 0 8px 6px; padding: 5px 10px;
  background: color-mix(in oklab, var(--m33-accent) 14%, transparent 86%);
  border: 1px solid color-mix(in oklab, var(--m33-accent) 35%, transparent 65%);
  border-radius: 999px;
  font-size: 11px; color: var(--m33-text);
  align-self: flex-start;
}
.m33-scope-chip[hidden] { display: none; }
.m33-scope-chip-icon { color: var(--m33-accent); font-size: 12px; }
.m33-scope-chip-label { font-weight: 500; }
.m33-scope-chip-clear {
  background: transparent; border: 0; color: var(--m33-text-muted);
  cursor: pointer; padding: 0 4px; font-size: 14px; line-height: 1;
}
.m33-scope-chip-clear:hover { color: var(--m33-text); }

/* Scope badge — small chip attached under a user message bubble that
 * went over the wire with a canvas selection scope. Confirms to the
 * user that Vega received the selection and which cards (on hover). */
.m33-chat-scope-badge {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 4px; padding: 2px 8px;
  background: color-mix(in oklab, var(--m33-accent) 14%, transparent 86%);
  border: 1px solid color-mix(in oklab, var(--m33-accent) 30%, transparent 70%);
  border-radius: 999px;
  font-size: 10px; color: var(--m33-text-muted);
  align-self: flex-end;
  cursor: help;
}
.m33-chat-scope-badge-icon { color: var(--m33-accent); }
.m33-chat-scope-badge-text { font-variant-numeric: tabular-nums; }

/* Compose progress modal — spinner + status text shown while the
 * Composer agent is generating a draft. Replaced by the edit modal
 * once the result event lands. */
.m33-compose-progress { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 28px 16px 12px; }
.m33-compose-spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid color-mix(in oklab, var(--m33-text-muted) 30%, transparent 70%);
  border-top-color: var(--m33-accent);
  animation: m33-spin 900ms linear infinite;
}
@keyframes m33-spin { to { transform: rotate(360deg); } }
.m33-compose-progress-label { font-size: 14px; font-weight: 500; color: var(--m33-text); }
.m33-compose-progress-hint { font-size: 11px; color: var(--m33-text-muted); text-align: center; max-width: 420px; line-height: 1.5; }

/* Inline draft editor (in modal) */
.m33-draft-editor { display: flex; flex-direction: column; gap: 10px; }
.m33-draft-editor-body {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 13px; line-height: 1.55;
  background: var(--m33-card); border: 1px solid var(--m33-border);
  color: var(--m33-text); padding: 12px; border-radius: 8px;
  resize: vertical; min-height: 300px;
}

/* PDF preview — "paper" inside the modal. Light background, serif
 * type, generous margins — looks like a printed page. */
.m33-pdf-toolbar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px; padding-bottom: 10px;
  border-bottom: 1px solid var(--m33-border);
}
.m33-pdf-hint { font-size: 11px; color: var(--m33-text-muted); margin-left: auto; }
.m33-pdf-paper {
  background: #ffffff; color: #111111;
  padding: 56px 64px;
  font-family: 'Georgia', 'Times New Roman', Times, serif;
  font-size: 13px; line-height: 1.6;
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  /* Letter / A4-ish proportions inside the modal. The actual print
   * sizing is set by @media print below. */
  max-width: 760px; margin: 0 auto;
}
.m33-pdf-paper-head { margin-bottom: 24px; padding-bottom: 12px; border-bottom: 1px solid #ddd; }
.m33-pdf-paper-meta { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: #777; margin-bottom: 8px; }
.m33-pdf-paper-title { font-size: 24px; font-weight: 700; margin: 0 0 6px; line-height: 1.25; color: #111; }
.m33-pdf-paper-subtitle { font-size: 12px; color: #555; font-style: italic; }
.m33-pdf-paper-body h1 { font-family: 'Georgia', serif; font-size: 24px; font-weight: 700; margin: 24px 0 10px; line-height: 1.25; color: #111; }
.m33-pdf-paper-body h2 { font-family: 'Georgia', serif; font-size: 18px; font-weight: 700; margin: 22px 0 8px; color: #111; border-bottom: 1px solid #ddd; padding-bottom: 4px; }
.m33-pdf-paper-body h3 { font-family: 'Georgia', serif; font-size: 14px; font-weight: 700; margin: 18px 0 6px; color: #222; text-transform: uppercase; letter-spacing: 0.05em; }
.m33-pdf-paper-body h4 { font-family: 'Georgia', serif; font-size: 13px; font-weight: 700; margin: 14px 0 4px; color: #333; font-style: italic; }
.m33-pdf-paper-body p  { margin: 0 0 12px; }
.m33-pdf-paper-body ul, .m33-pdf-paper-body ol { margin: 0 0 12px; padding-left: 24px; }
.m33-pdf-paper-body li { margin: 3px 0; }
.m33-pdf-paper-body strong { font-weight: 700; }
.m33-pdf-paper-body em { font-style: italic; }
.m33-pdf-paper-body code { background: #f4f4f4; padding: 1px 6px; border-radius: 3px; font-size: 12px; font-family: 'Courier New', monospace; }
.m33-pdf-paper-body blockquote { border-left: 3px solid #555; margin: 8px 0; padding: 4px 12px; color: #444; font-style: italic; }
.m33-pdf-cite { font-size: 9px; vertical-align: super; color: #555; }
.m33-pdf-paper-footnotes {
  margin-top: 32px; padding-top: 14px; border-top: 1px solid #ccc;
  font-size: 11px; color: #444;
}
.m33-pdf-paper-footnotes h2 { font-size: 12px; font-weight: 600; margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.08em; color: #555; }
.m33-pdf-paper-footnotes ol { margin: 0; padding-left: 24px; }
.m33-pdf-footnote { padding: 3px 0; }
.m33-pdf-footnote-num { font-weight: 600; color: #333; }
.m33-pdf-footnote-meta { color: #888; }
.m33-pdf-footnote-src { color: #335588; word-break: break-all; }

/* Print stylesheet — when the user clicks "Print / Save as PDF" in
 * the PDF preview modal, hide the entire Vega app chrome (header,
 * left rail, right rail, footer, modal backdrop) and show only the
 * paper. The browser's Save-as-PDF then captures just the document.
 *
 * Implementation: hide everything by default in print, then show
 * only .m33-pdf-paper and its descendants. The paper unscrolls to
 * its full content height so the print engine can paginate it.
 */
@media print {
  body * { visibility: hidden !important; }
  .m33-pdf-paper, .m33-pdf-paper * { visibility: visible !important; }
  .m33-pdf-paper {
    position: absolute !important;
    left: 0; top: 0;
    width: 100% !important; max-width: none !important;
    margin: 0 !important;
    padding: 24mm 18mm !important;
    box-shadow: none !important; border-radius: 0 !important;
    background: #ffffff !important;
    color: #000 !important;
  }
  /* Force backgrounds + colors to print exactly as styled */
  .m33-pdf-paper { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* Hide the modal toolbar in print */
  .m33-pdf-toolbar { display: none !important; }
}

/* History tab — stats grid + timeline of calls + lifecycle events. */
.m33-agent-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px;
  margin-bottom: 16px;
}
.m33-stat-card {
  background: var(--m33-card); border: 1px solid var(--m33-border);
  border-radius: 8px; padding: 10px 12px;
}
.m33-stat-card-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--m33-text-muted); margin-bottom: 4px; }
.m33-stat-card-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--m33-text); }
.m33-stat-card-value.m33-status-built    { color: var(--m33-good); }
.m33-stat-card-value.m33-status-disabled { color: var(--m33-warn); }
.m33-stat-card-value.m33-status-planned  { color: var(--m33-text-muted); }

.m33-history-row {
  padding: 8px 0; border-bottom: 1px solid color-mix(in oklab, var(--m33-border) 40%, transparent 60%);
}
.m33-history-row:last-child { border-bottom: 0; }
.m33-history-row-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 11px; color: var(--m33-text-muted);
}
.m33-history-marker { font-weight: bold; width: 14px; text-align: center; flex: 0 0 auto; }
.m33-history-marker-call   { color: var(--m33-accent); }
.m33-history-marker-change { color: var(--m33-text-muted); }
.m33-history-when    { font-variant-numeric: tabular-nums; color: var(--m33-text); }
.m33-history-kind    { background: var(--m33-card); padding: 2px 8px; border-radius: 6px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; }
.m33-history-by      { color: var(--m33-text-muted); margin-left: auto; font-size: 10px; }
.m33-history-latency { color: var(--m33-text-muted); margin-left: auto; }

.m33-history-row-body { margin: 6px 0 0 24px; display: flex; flex-direction: column; gap: 3px; }
.m33-history-pair { display: flex; gap: 8px; align-items: baseline; font-size: 11px; }
.m33-history-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--m33-text-muted); width: 28px; flex: 0 0 auto; padding-top: 2px; }
.m33-history-pair code {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 10px;
  background: var(--m33-card); border: 1px solid var(--m33-border);
  padding: 2px 6px; border-radius: 4px;
  color: var(--m33-text-muted); flex: 1; word-break: break-word; min-width: 0;
}
.m33-history-pair.m33-history-err code { color: var(--m33-warn); border-color: color-mix(in oklab, var(--m33-warn) 40%, var(--m33-border) 60%); }

/* The detail view's modal-row component reuses the System modal's row */
.m33-agent-detail .m33-modal-row { display: flex; gap: 12px; padding: 4px 0; font-size: 12px; }
.m33-agent-detail .m33-modal-row-key { color: var(--m33-text-muted); width: 110px; flex: 0 0 auto; }
.m33-agent-detail .m33-modal-row-val { color: var(--m33-text); flex: 1; min-width: 0; word-break: break-word; }

/* Agency Settings — full editable form: photo upload + name/role/
 * mandate/voice/tts preferences. Saves through /api/agency on submit
 * and the photo upload route. */
.m33-agency-form { display: flex; flex-direction: column; gap: 4px; }
.m33-agency-photo-row { display: flex; gap: 14px; align-items: center; padding: 12px 0 16px; border-bottom: 1px solid color-mix(in oklab, var(--m33-border) 50%, transparent 50%); }
.m33-agency-photo { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--m33-card); border: 1px solid var(--m33-border); display: block; }
.m33-agency-photo-placeholder { display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 22px; color: var(--m33-text); background: var(--m33-card); }
.m33-agency-photo-actions { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.m33-agency-upload-btn { display: inline-block; padding: 6px 12px; background: var(--m33-accent); color: white; border-radius: 5px; font-size: 12px; cursor: pointer; align-self: flex-start; }
.m33-agency-upload-btn:hover { background: var(--m33-accent-hover); }
.m33-agency-photo-remove { background: transparent; border: 1px solid var(--m33-border); color: var(--m33-text-muted); padding: 5px 11px; border-radius: 5px; font-size: 12px; cursor: pointer; align-self: flex-start; margin-top: 4px; }
.m33-agency-photo-remove:hover { color: var(--m33-warn); border-color: var(--m33-warn); }
.m33-agency-photo-hint { font-size: 11px; color: var(--m33-text-muted); margin-top: 4px; }
.m33-agency-field { display: flex; flex-direction: column; gap: 4px; padding: 8px 0; }
.m33-agency-field > span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--m33-text-muted); }
.m33-agency-field input, .m33-agency-field textarea, .m33-agency-field select {
  background: var(--m33-bg); color: var(--m33-text);
  border: 1px solid var(--m33-border); border-radius: 5px;
  padding: 7px 10px; font: inherit; font-size: 13px;
}
.m33-agency-field input:focus, .m33-agency-field textarea:focus, .m33-agency-field select:focus { outline: none; border-color: var(--m33-accent); }
.m33-agency-field textarea { resize: vertical; min-height: 60px; font-family: inherit; }
.m33-agency-checkbox { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; }
.m33-agency-checkbox input { margin: 0; }
.m33-agency-actions { display: flex; align-items: center; gap: 12px; padding: 14px 0 4px; border-top: 1px solid var(--m33-border); margin-top: 8px; }
.m33-agency-status { font-size: 12px; color: var(--m33-text-muted); }
.m33-agency-status-err { color: var(--m33-warn); }

/* Header avatar — photo variant. When the saved profile has a
 * photo_url, the framework's text avatar gets the m33-user-photo class
 * and a background-image; the inner text is cleared. */
.m33-user.m33-user-photo {
  background-color: transparent;
  background-size: cover;
  background-position: center;
  color: transparent;
}
.m33-app-nav { display: flex; gap: 4px; margin-left: 12px; }
.m33-nav-link {
  color: var(--m33-text-muted); text-decoration: none;
  padding: 6px 10px; border-radius: 6px; font-size: 13px;
}
.m33-nav-link:hover { background: var(--m33-card); color: var(--m33-text); }

.m33-icon-btn {
  background: transparent; border: 1px solid var(--m33-border);
  color: var(--m33-text-muted); width: 32px; height: 32px; border-radius: 6px;
  cursor: pointer; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 8px;
}
.m33-icon-btn:hover { color: var(--m33-text); border-color: var(--m33-text-muted); }

.m33-primary-btn {
  background: var(--m33-accent); color: white; border: none;
  padding: 6px 14px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer;
}
.m33-primary-btn:hover { background: var(--m33-accent-hover); }

.m33-user {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--m33-card); color: var(--m33-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}

/* Visible name label next to the header avatar. Forms a clickable
 * cluster with the avatar; both open the profile dropdown. */
.m33-user-name {
  font-size: 13px; font-weight: 500; color: var(--m33-text);
  cursor: pointer; user-select: none;
  padding: 0 8px 0 4px; line-height: 28px;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.m33-user-name:hover { color: var(--m33-accent); }
@media (max-width: 720px) { .m33-user-name { display: none; } }

/* Left sliding panel — navigation. Slides; persists open/closed; remembers selection. */
/* Floating chevron handles for collapsing the left/right rails. Both
 * are body-level fixed-position circles pinned to the viewport bottom
 * so they never jump vertically when a panel toggles — only their
 * horizontal offset changes. JS keeps the offset in sync with each
 * panel's current width via the --m33-rail-chev-* CSS vars. */
.m33-rail-chevron {
  position: fixed; bottom: 8px;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--m33-panel); border: 1px solid var(--m33-border);
  color: var(--m33-text-muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; z-index: 50; opacity: 0.7;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: opacity 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease, left 200ms ease, right 200ms ease;
}
.m33-rail-chevron:hover { opacity: 1; color: var(--m33-text); background: var(--m33-card); }
/* Horizontal offsets driven by JS (set on :root). Defaults match the
 * agent-skin grid (192px / 256px) before JS runs to avoid first-paint flash. */
:root { --m33-rail-chev-left: 192px; --m33-rail-chev-right: 256px; }
.m33-rail-chevron-left  { left:  calc(var(--m33-rail-chev-left)  - 36px); }
.m33-rail-chevron-right { right: calc(var(--m33-rail-chev-right) - 36px); }
/* Direction flip — pointer always indicates "this click takes you HERE". */
.m33-rail-chevron-left.m33-flip svg,
.m33-rail-chevron-right:not(.m33-flip) svg { transform: scaleX(-1); }

/* When the right panel is fully hidden, the chevron-right slides to the
 * viewport edge so the user can still re-expand. The right CSS var is
 * driven to 0 (or negative) by JS in that state, but we provide a fallback
 * here so the affordance is always reachable. */
body:has(.m33-app.m33-right-collapsed) .m33-rail-chevron-right { right: 8px; }

/* Hide framework footer's app-name (left) and user-name (right) labels in
 * Vega — the chevron handles now occupy that space, and the app name +
 * user identity already live in the header. The centre telemetry stays. */
body[data-skin="agent"] .m33-footer-left,
body[data-skin="agent"] .m33-footer-right { visibility: hidden; }

.m33-panel-left { grid-area: left; padding: 12px 8px; transition: padding 0.25s ease; }
.m33-left-collapsed .m33-panel-left { padding: 8px 4px; }
.m33-left-collapsed .m33-nav-label,
.m33-left-collapsed .m33-nav-section,
.m33-left-collapsed .m33-nav-badge { display: none; }
.m33-nav-list { display: flex; flex-direction: column; gap: 2px; }
.m33-nav-section {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--m33-text-muted); padding: 12px 8px 4px;
}
.m33-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px;
  color: var(--m33-text-muted); text-decoration: none; font-size: 13px;
  white-space: nowrap;
}
.m33-nav-item:hover { background: var(--m33-card); color: var(--m33-text); }
.m33-nav-item.m33-active { background: var(--m33-card); color: var(--m33-text); }
.m33-nav-icon {
  width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.m33-nav-icon svg { width: 16px; height: 16px; }
.m33-nav-badge {
  margin-left: auto; background: var(--m33-accent); color: white;
  font-size: 10px; padding: 2px 6px; border-radius: 10px;
}
/* Collapsed: nav items center their icon; labels and section headings hide. */
.m33-left-collapsed .m33-nav-item { justify-content: center; padding: 8px 0; }
.m33-left-collapsed .m33-nav-icon { width: 24px; height: 24px; }
.m33-left-collapsed .m33-nav-icon svg { width: 18px; height: 18px; }

/* Center panel — the application's working surface. Renders a lens. */
.m33-panel-center { grid-area: center; padding: 20px; overflow: auto; }
.m33-panel-center h2 { margin: 0 0 12px; font-size: 18px; font-weight: 600; }
.m33-empty { color: var(--m33-text-muted); padding: 40px; text-align: center; }

/* Right sliding panel — details and palette in context to the center. */
.m33-panel-right { grid-area: right; padding: 16px; border-left: 1px solid var(--m33-border); }
.m33-right-collapsed .m33-panel-right { display: none; }
.m33-panel-right h3 { font-size: 11px; font-weight: 600; margin: 0 0 8px; color: var(--m33-text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.m33-panel-right .m33-block { margin-bottom: 18px; }

/* Property view — key/value rows. */
.m33-prop { display: grid; grid-template-columns: 100px 1fr; gap: 8px; padding: 4px 0; font-size: 12px; }
.m33-prop-key { color: var(--m33-text-muted); font-family: ui-monospace, 'SF Mono', Menlo, monospace; }
.m33-prop-val { color: var(--m33-text); word-break: break-word; }
.m33-action-btn {
  display: inline-block; margin: 4px 6px 0 0;
  background: var(--m33-card); color: var(--m33-text);
  border: 1px solid var(--m33-border); border-radius: 6px;
  padding: 6px 10px; font-size: 12px; cursor: pointer;
}
.m33-action-btn:hover { border-color: var(--m33-accent); color: var(--m33-text); }
.m33-action-result {
  margin-top: 10px; padding: 10px; background: var(--m33-card);
  border-radius: 6px; font-size: 12px; color: var(--m33-text-muted);
  font-family: ui-monospace, 'SF Mono', Menlo, monospace; white-space: pre-wrap;
}

/* Row hover + selection in center panel. */
.m33-row { cursor: pointer; }
.m33-row.m33-selected { outline: 2px solid var(--m33-accent); outline-offset: -2px; }
table.m33-table tr.m33-selected { background: rgba(99,102,241,0.08); }

/* Footer — telemetry. The application's continuous self-report. */
.m33-footer {
  grid-area: footer;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; font-size: 11px; color: var(--m33-text-muted);
  border-top: 1px solid var(--m33-border);
}
.m33-footer-center { font-family: ui-monospace, 'SF Mono', Menlo, monospace; }

/* Cards / tables — generic primitives the lens registry uses. */
.m33-card {
  background: var(--m33-card); border: 1px solid var(--m33-border);
  border-radius: 8px; padding: 14px; margin-bottom: 10px;
}
.m33-card h4 { margin: 0 0 6px; font-size: 14px; }
.m33-card .m33-meta { font-size: 11px; color: var(--m33-text-muted); }

table.m33-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.m33-table th {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--m33-border);
  color: var(--m33-text-muted); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
table.m33-table td { padding: 10px; border-bottom: 1px solid var(--m33-border); }
table.m33-table tr:hover { background: var(--m33-card); }

.m33-envelope-badge {
  display: inline-block; padding: 2px 6px; border-radius: 4px;
  font-size: 10px; font-weight: 600; font-family: ui-monospace, monospace;
}
.m33-envelope-E1 { background: rgba(52,211,153,0.15); color: var(--m33-good); }
.m33-envelope-E2 { background: rgba(52,211,153,0.10); color: var(--m33-good); }
.m33-envelope-E3 { background: rgba(99,102,241,0.15); color: var(--m33-accent); }
.m33-envelope-E4 { background: rgba(251,191,36,0.15); color: var(--m33-warn); }
.m33-envelope-E5 { background: rgba(248,113,113,0.15); color: var(--m33-bad); }

/* Bell + tray panels (notifications, settings). */
.m33-bell-btn { position: relative; }
.m33-bell-dot {
  position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--m33-bad);
}
.m33-tray {
  position: fixed; right: 16px; top: 64px;
  width: 360px; max-height: 480px;
  background: var(--m33-panel); border: 1px solid var(--m33-border);
  border-radius: 10px; padding: 0; color: var(--m33-text);
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
  display: none; flex-direction: column;
}
.m33-tray[open] { display: flex; }
.m33-tray-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--m33-border);
}
.m33-tray-body {
  flex: 1; overflow-y: auto; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.m33-note {
  padding: 10px 12px; border-radius: 8px;
  background: var(--m33-card);
  border-left: 3px solid var(--m33-accent);
  font-size: 12px;
}
.m33-note.m33-note-failed { border-left-color: var(--m33-bad); }
.m33-note.m33-note-finished { border-left-color: var(--m33-good); }
.m33-note .m33-note-title { font-weight: 600; color: var(--m33-text); }
.m33-note .m33-note-body { color: var(--m33-text-muted); margin-top: 2px; }
.m33-note .m33-note-ts { color: var(--m33-text-muted); font-size: 10px; font-family: ui-monospace, monospace; margin-top: 4px; }

.m33-setting-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; gap: 12px; }
.m33-setting-key { color: var(--m33-text-muted); font-size: 12px; font-family: ui-monospace, monospace; }
.m33-setting-val { color: var(--m33-text); font-size: 13px; }
.m33-toggle-row { display: flex; gap: 4px; }
.m33-toggle-row button {
  background: var(--m33-card); color: var(--m33-text-muted);
  border: 1px solid var(--m33-border); border-radius: 6px;
  padding: 6px 12px; font-size: 12px; cursor: pointer;
}
.m33-toggle-row button.m33-on { background: var(--m33-accent); color: white; border-color: var(--m33-accent); }
.m33-section { margin: 8px 0 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--m33-text-muted); }

/* Assistant — opened by the framework-owned button in the header. */
.m33-assistant-panel {
  position: fixed; right: 16px; bottom: 48px;
  width: 380px; height: 480px; max-height: 80vh;
  background: var(--m33-panel); border: 1px solid var(--m33-border);
  border-radius: 10px; padding: 0;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
  display: none;
  flex-direction: column;
  color: var(--m33-text);
}
.m33-assistant-panel[open] { display: flex; }
.m33-assistant-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--m33-border);
}
.m33-assistant-body {
  flex: 1; overflow-y: auto; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.m33-assistant-msg {
  padding: 8px 12px; border-radius: 8px; font-size: 13px; max-width: 90%;
}
.m33-msg-system { background: var(--m33-card); color: var(--m33-text-muted); }
.m33-msg-user { background: var(--m33-accent); color: white; align-self: flex-end; }
.m33-msg-assistant { background: var(--m33-card); }
.m33-assistant-form {
  display: flex; gap: 8px; padding: 12px 14px;
  border-top: 1px solid var(--m33-border);
}
.m33-assistant-form input {
  flex: 1; background: var(--m33-bg); color: var(--m33-text);
  border: 1px solid var(--m33-border); border-radius: 6px;
  padding: 8px 10px; font-size: 13px; outline: none;
}
.m33-assistant-form input:focus { border-color: var(--m33-accent); }

/* ---------------------------------------------------------------------------
 * Agent skin — same 5-panel structure, walls dissolved (per spec §5.8).
 * The DOM is identical to Application skin. Only visual weight changes:
 * header/footer borders fade, side panels recede toward the center colour,
 * and the chat in the center owns attention. Apps select this by passing
 * skin: 'agent' to renderShell, which sets data-skin="agent" on <body>.
 * --------------------------------------------------------------------------*/
body[data-skin="agent"] {
  --m33-border: rgba(120, 130, 160, 0.12);
}
body[data-skin="agent"] .m33-app { background: transparent; gap: 0; }
body[data-skin="agent"] .m33-panel { background: var(--m33-bg); }
body[data-skin="agent"] .m33-header { border-bottom-color: transparent; }
body[data-skin="agent"] .m33-footer { border-top-color: transparent; }
body[data-skin="agent"] .m33-panel-left,
body[data-skin="agent"] .m33-panel-right {
  background: var(--m33-bg);
}
body[data-skin="agent"] .m33-panel-center { background: var(--m33-bg); }

/* Agent skin reclaims width from the rails for the centre panel. The
 * Application skin keeps the wider 240/320 because it relies on the rails
 * to surface sub-content (lists, properties, Greeks). The Agent skin's
 * rails are mostly nav + lightweight inspector, so a narrower 192/256 hands
 * roughly 112px back to the canvas / chat without clipping any controls. */
body[data-skin="agent"] .m33-app                                            { grid-template-columns: 192px 1fr 256px; }
body[data-skin="agent"] .m33-app.m33-left-collapsed                          { grid-template-columns: 56px 1fr 256px; }
body[data-skin="agent"] .m33-app.m33-right-collapsed                         { grid-template-columns: 192px 1fr 0; }
body[data-skin="agent"] .m33-app.m33-left-collapsed.m33-right-collapsed      { grid-template-columns: 56px 1fr 0; }

/* App launcher (waffle) and skin toggle — Vega-injected via headerExtras. */
.m33-launcher { position: relative; }
.m33-launcher-btn { display: inline-grid; grid-template-columns: repeat(2, 1fr); gap: 2px; padding: 8px; background: transparent; border: 1px solid var(--m33-border); border-radius: 6px; color: var(--m33-text-muted); cursor: pointer; }
.m33-launcher-btn:hover { color: var(--m33-text); border-color: var(--m33-text-muted); }
.m33-launcher-btn span { display: block; width: 5px; height: 5px; background: currentColor; border-radius: 1px; }
.m33-launcher-panel { position: fixed; top: 56px; right: 16px; width: 360px; background: var(--m33-panel); border: 1px solid var(--m33-border); border-radius: 10px; box-shadow: 0 14px 40px rgba(0,0,0,0.35); padding: 10px; z-index: 1000; display: none; }
.m33-launcher.m33-open .m33-launcher-panel { display: block; }
.m33-launcher-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.m33-launcher-tile { position: relative; display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 8px; background: var(--m33-card); border: 1px solid transparent; text-decoration: none; color: var(--m33-text); transition: border-color 120ms; }
.m33-launcher-tile:hover { border-color: var(--m33-text-muted); }
.m33-launcher-tile.m33-active { border-color: var(--m33-accent); background: color-mix(in oklab, var(--m33-card) 80%, var(--m33-accent) 20%); }
.m33-launcher-tile.m33-disabled { opacity: 0.4; pointer-events: none; }
.m33-launcher-glyph { width: 28px; height: 28px; border-radius: 6px; background: var(--m33-bg); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: 0 0 28px; color: var(--m33-text-muted); }
.m33-launcher-tile.m33-active .m33-launcher-glyph { background: var(--m33-accent); color: white; }
.m33-launcher-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.m33-launcher-app { font-size: 11px; color: var(--m33-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.m33-launcher-skin { font-weight: 600; font-size: 13px; color: var(--m33-text); }
.m33-launcher-soon { position: absolute; top: 6px; right: 8px; font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--m33-text-muted); }

/* Surface transition — full-viewport overlay shown briefly while the next
 * surface loads. The walls of the previous skin go away; a centered card
 * with a spinner and a "Switching to X" message holds attention until the
 * next page replaces the DOM. The next surface owns its own first paint. */
.m33-transition { position: fixed; inset: 0; background: #000; display: flex; align-items: center; justify-content: center; z-index: 9999; opacity: 0; transition: opacity 650ms ease-in; pointer-events: none; }
.m33-transition.m33-show { opacity: 1; pointer-events: auto; }
.m33-transition-card { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.m33-spinner { width: 36px; height: 36px; border: 3px solid var(--m33-border); border-top-color: var(--m33-accent); border-radius: 50%; animation: m33-spin 800ms linear infinite; }
@keyframes m33-spin { to { transform: rotate(360deg); } }
.m33-transition-msg { font-size: 13px; color: var(--m33-text-muted); letter-spacing: 0.02em; }

.m33-skin-toggle { display: inline-flex; padding: 2px; background: var(--m33-card); border: 1px solid var(--m33-border); border-radius: 8px; gap: 0; }
.m33-skin-toggle a { padding: 5px 10px; font-size: 12px; color: var(--m33-text-muted); text-decoration: none; border-radius: 6px; }
.m33-skin-toggle a.m33-active { background: var(--m33-panel); color: var(--m33-text); box-shadow: 0 1px 2px rgba(0,0,0,0.25); }
.m33-skin-toggle a:hover:not(.m33-active) { color: var(--m33-text); }

/* Chat surface — center panel of Agent skin. The chat fills the panel
 * edge-to-edge; an inner reading column constrains the message width
 * without creating a nested-box feel. */
.m33-panel-center:has(.m33-chat) { padding: 0; overflow: hidden; }
.m33-chat { display: flex; flex-direction: column; height: 100%; padding: 0; position: relative; }
.m33-chat-stream { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 24px max(16px, calc((100% - 760px) / 2)) 16px; }
.m33-chat-msg { max-width: 80%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.m33-chat-msg.m33-from-user { align-self: flex-end; background: var(--m33-accent); color: white; border-bottom-right-radius: 4px; }
.m33-chat-msg.m33-from-vega { align-self: flex-start; background: var(--m33-card); color: var(--m33-text); border-bottom-left-radius: 4px; }
.m33-chat-msg.m33-from-system { align-self: center; background: transparent; color: var(--m33-text-muted); font-size: 12px; font-style: italic; }
.m33-chat-msg.m33-from-tool { align-self: center; max-width: 90%; padding: 6px 12px; background: transparent; color: var(--m33-text-muted); font-size: 12px; font-style: italic; border-left: 2px solid var(--m33-accent); border-radius: 0; text-align: left; }

/* Per-bubble action strip — small, subtle, hover-revealed. Sits below the
 * bubble. Aligned to the bubble side: user-right, vega-left, tool-left
 * (since tool rows are full-width). */
.m33-chat-row { display: flex; flex-direction: column; gap: 3px; max-width: 100%; }
.m33-chat-row.m33-from-user { align-items: flex-end; align-self: flex-end; max-width: 80%; }
.m33-chat-row.m33-from-vega { align-items: flex-start; align-self: flex-start; max-width: 80%; }
.m33-chat-row.m33-from-tool { align-items: flex-start; align-self: center; max-width: 90%; }
.m33-chat-row.m33-from-system { align-items: center; align-self: center; }
.m33-chat-row > .m33-chat-msg { max-width: 100%; }
/* Author + time label above each authored bubble (spec figs 7a/7b/7c —
 * "AARON" / "VEGA" headers). Tool and system rows skip this row. */
.m33-chat-meta { display: flex; gap: 8px; align-items: baseline; padding: 0 4px; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--m33-text-muted); }
.m33-chat-author { font-weight: 600; }
.m33-chat-time   { opacity: 0.65; font-weight: 500; letter-spacing: 0.04em; }
.m33-chat-row.m33-from-user .m33-chat-meta { flex-direction: row-reverse; }
.m33-chat-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 140ms ease; padding: 0 4px; }

/* "Searching…" placeholder — shown in an assistant bubble while a tool
 * round-trip (e.g. web_search) is in flight, then replaced by the
 * post-tool transcript. Pulses subtly so the user knows it's not a
 * stalled bubble. */
.m33-chat-msg.m33-chat-msg-thinking {
  font-style: italic;
  color: var(--m33-text-muted);
  animation: m33-thinking-pulse 1.4s ease-in-out infinite;
}
@keyframes m33-thinking-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}
.m33-chat-row:hover .m33-chat-actions,
.m33-chat-actions:focus-within { opacity: 0.7; }
.m33-msg-action { background: transparent; border: none; color: var(--m33-text-muted); cursor: pointer; padding: 2px 6px; border-radius: 4px; font-size: 11px; line-height: 1.2; display: inline-flex; align-items: center; gap: 4px; }
.m33-msg-action:hover { color: var(--m33-text); background: rgba(255,255,255,0.06); }
.m33-msg-action svg { width: 12px; height: 12px; }
.m33-msg-action.m33-copied { color: var(--m33-good); }

/* Chat ↔ Canvas mode toggle. Lives in headerExtras; CSS hides it unless we
 * are in the agent skin (the application skin has no modes). */
.m33-mode-toggle { display: none; padding: 2px; background: var(--m33-card); border: 1px solid var(--m33-border); border-radius: 8px; gap: 0; }
body[data-skin="agent"] .m33-mode-toggle { display: inline-flex; }
.m33-mode-toggle a { padding: 5px 12px; font-size: 12px; color: var(--m33-text-muted); text-decoration: none; border-radius: 6px; }
.m33-mode-toggle a.m33-active { background: var(--m33-panel); color: var(--m33-text); box-shadow: 0 1px 2px rgba(0,0,0,0.25); }
.m33-mode-toggle a:hover:not(.m33-active) { color: var(--m33-text); }

/* Agent surfaces — Artifacts ↔ Semantics sub-toggle, used in BOTH the Chat
 * right strip and the Canvas centre. The sub-toggle is a smaller variant of
 * the mode toggle. */
.m33-agent-surface { display: flex; flex-direction: column; height: 100%; }
.m33-subtoggle { display: inline-flex; padding: 2px; background: var(--m33-card); border: 1px solid var(--m33-border); border-radius: 7px; gap: 0; align-self: flex-start; margin: 0 0 12px; flex: 0 0 auto; }
.m33-subtoggle-btn { padding: 4px 10px; font-size: 11px; line-height: 1.2; color: var(--m33-text-muted); background: transparent; border: none; border-radius: 5px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; letter-spacing: 0.04em; text-transform: uppercase; }
.m33-subtoggle-btn:hover:not(.m33-active) { color: var(--m33-text); }
.m33-subtoggle-btn.m33-active { background: var(--m33-panel); color: var(--m33-text); box-shadow: 0 1px 2px rgba(0,0,0,0.25); }
.m33-subtoggle-count { font-size: 10px; padding: 1px 5px; border-radius: 9px; background: var(--m33-bg); color: var(--m33-text-muted); }

/* Arrangement toggle (Free / Cluster / future modes) — same look as the
 * Artifacts/Semantics toggle, sits next to it on the canvas. Hidden in
 * the chat strip surface where layout choice is irrelevant. */
.m33-arrange-toggle { margin-left: 8px; }
.m33-strip-surface .m33-arrange-toggle { display: none; }

/* Position-transition during arrangement is in the world-layer block now. */

/* Insights panel — surfaces canvas_signals from detector agents.
 * Collapsed by default (just a tag in the bottom-left); expanded shows
 * grouped signals with click-to-jump and a resolve button per row.
 * The detector layer is meaningless without a place to read its
 * findings — this is that place. */
.m33-canvas-insights {
  position: absolute; bottom: 14px; left: 14px; z-index: 50;
  background: color-mix(in oklab, var(--m33-panel) 80%, transparent 20%);
  border: 1px solid color-mix(in oklab, var(--m33-border) 50%, transparent 50%);
  border-radius: 8px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; flex-direction: column;
  max-height: calc(100vh - 200px); max-width: 320px;
  overflow: hidden;
  font-size: 12px;
}
.m33-canvas-insights[data-collapsed="1"] .m33-insights-body { display: none; }
.m33-canvas-insights[data-collapsed="0"] { width: 320px; }
.m33-insights-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent; border: 0; color: var(--m33-text);
  padding: 8px 12px; cursor: pointer;
  font-size: 12px; letter-spacing: 0.02em;
}
.m33-insights-toggle:hover { background: color-mix(in oklab, var(--m33-card) 70%, transparent 30%); }
.m33-insights-icon { font-size: 13px; color: var(--m33-text-muted); }
.m33-insights-label { font-weight: 600; }
.m33-insights-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 18px; padding: 0 6px; border-radius: 9px;
  background: color-mix(in oklab, var(--m33-accent) 30%, transparent 70%);
  color: var(--m33-text); font-size: 10px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.m33-insights-count[data-zero="1"] { background: var(--m33-card); color: var(--m33-text-muted); }
.m33-insights-body {
  border-top: 1px solid var(--m33-border);
  overflow-y: auto; padding: 6px 0;
}
.m33-insights-empty {
  padding: 16px 12px; color: var(--m33-text-muted); font-size: 11px; text-align: center;
}
.m33-insights-group { margin-bottom: 6px; }
.m33-insights-group-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px 2px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--m33-text-muted);
}
.m33-insights-row {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 6px 12px; cursor: pointer;
  border-left: 2px solid transparent;
  transition: background 120ms, border-color 120ms;
}
.m33-insights-row:hover { background: color-mix(in oklab, var(--m33-card) 60%, transparent 40%); border-left-color: var(--m33-accent); }
.m33-insights-row[data-severity="flag"]  { border-left-color: #ff7373; }
.m33-insights-row[data-severity="alert"] { border-left-color: #ff3b3b; }
.m33-insights-row[data-severity="note"]  { border-left-color: var(--m33-accent); }
.m33-insights-row[data-severity="info"]  { border-left-color: var(--m33-text-muted); }
.m33-insights-row-text {
  flex: 1; min-width: 0; line-height: 1.3;
  font-size: 11px; color: var(--m33-text);
}
.m33-insights-row-rationale {
  font-size: 10px; color: var(--m33-text-muted); margin-top: 2px;
}
.m33-insights-row-resolve {
  flex: 0 0 auto; background: transparent; border: 0;
  color: var(--m33-text-muted); font-size: 14px; line-height: 1;
  cursor: pointer; padding: 0 2px; opacity: 0;
  transition: opacity 120ms, color 120ms;
}
.m33-insights-row:hover .m33-insights-row-resolve { opacity: 1; }
.m33-insights-row-resolve:hover { color: var(--m33-text); }

/* Card highlight pulse — applied when a signal row is clicked. */
.m33-card.m33-signal-flash {
  animation: m33-signal-pulse 1.6s ease-out 1;
  z-index: 12;
}
@keyframes m33-signal-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in oklab, var(--m33-accent) 80%, transparent 20%); }
  60%  { box-shadow: 0 0 0 12px color-mix(in oklab, var(--m33-accent) 0%, transparent 100%); }
  100% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--m33-accent) 0%, transparent 100%); }
}
/* Edge between two flashed cards pulses to draw attention to the
 * relationship at the heart of the signal. */
.m33-canvas-edges line.m33-signal-edge-flash {
  animation: m33-edge-pulse 1.6s ease-out 1;
}
@keyframes m33-edge-pulse {
  0%, 100% { stroke-width: inherit; opacity: inherit; }
  50%      { stroke-width: 5; opacity: 1; }
}

/* Cluster bound — soft shaded rectangle behind the cards giving a
 * cluster a visible region. Lives BEHIND cards (z-index lower than
 * .m33-card) and BEHIND edges (which are at z-index 0; bounds at -1).
 * Pointer-events:none so dragging on a bound area still pans/drags. */
.m33-cluster-bound {
  position: absolute; pointer-events: none;
  background: color-mix(in oklab, var(--m33-card) 50%, transparent 50%);
  border: 1px dashed color-mix(in oklab, var(--m33-border) 70%, transparent 30%);
  border-radius: 12px;
  z-index: -1;
}
/* Tension knots: red-tinted bound, solid border. Reads as "this is a
 * fight" — distinct from the neutral cluster bound. */
.m33-cluster-bound[data-kind="tension"] {
  background: color-mix(in oklab, var(--m33-warn) 8%, var(--m33-card) 50%);
  border: 1px solid color-mix(in oklab, var(--m33-warn) 60%, transparent 40%);
}
/* Subject-fallback groups: members were grouped via subject-token
 * similarity, NOT belief edges. Use a fainter dotted border + lower
 * opacity so the user knows this is a soft inference, not a fact. */
.m33-cluster-bound[data-kind="subject-fallback"] {
  background: color-mix(in oklab, var(--m33-card) 70%, transparent 30%);
  border: 1px dotted color-mix(in oklab, var(--m33-text-muted) 40%, transparent 60%);
  opacity: 0.7;
}
.m33-cluster-label[data-kind="subject-fallback"] {
  color: var(--m33-text-muted);
  font-style: italic;
  font-weight: 500;
}
.m33-cluster-label[data-kind="subject-fallback"]::before {
  content: '~ ';      /* tilde hints "approximate / by topic similarity" */
  opacity: 0.6;
}
.m33-cluster-label[data-kind="tension"] {
  color: color-mix(in oklab, var(--m33-warn) 80%, var(--m33-text) 20%);
  font-weight: 700;
}
/* κ-band rings get a soft accent tint so they read as "confidence
 * gradient" rather than "categorical groups". */
.m33-cluster-bound[data-kind="kappa-band"] {
  background: color-mix(in oklab, var(--m33-accent) 5%, var(--m33-card) 60%);
  border: 1px dotted color-mix(in oklab, var(--m33-accent) 40%, transparent 60%);
}
/* Phase bands (timeline mode) — neutral but with a top-border accent
 * to suggest "moving forward in time". */
.m33-cluster-bound[data-kind="phase"] {
  background: color-mix(in oklab, var(--m33-card) 70%, transparent 30%);
  border: 1px solid transparent;
  border-top: 2px solid color-mix(in oklab, var(--m33-accent) 30%, transparent 70%);
  border-radius: 8px;
}

/* Cluster label — soft floating tag rendered above each cluster's
 * bounding box. Lives inside the freeform grid alongside the cards. */
.m33-cluster-label {
  position: absolute; pointer-events: none;
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  color: var(--m33-text);
  text-transform: uppercase;
  text-align: left;
  padding-left: 4px;
  z-index: 2;
}

/* "Working" state on the grid while the canvas-grapher agent is thinking.
 * Subtle pulse on the toggle so the user knows something's running but
 * the canvas itself stays interactive. */
.m33-canvas-surface .m33-agent-grid.m33-grapher-working {
  cursor: progress;
}
.m33-canvas-surface .m33-agent-grid.m33-grapher-working::after {
  content: 'rearranging…';
  position: absolute; top: 8px; right: 12px;
  font-size: 10px; color: var(--m33-text-muted);
  background: color-mix(in oklab, var(--m33-card) 70%, transparent 30%);
  padding: 4px 8px; border-radius: 999px;
  border: 1px solid var(--m33-border);
  z-index: 30;
  animation: m33-grapher-pulse 1.4s ease-in-out infinite;
}
@keyframes m33-grapher-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}
.m33-subtoggle-btn.m33-active .m33-subtoggle-count { background: var(--m33-accent); color: white; }

/* Show only the active grid for the surface's data-active. */
.m33-agent-grid { display: none; }
.m33-agent-surface[data-active="artifacts"] .m33-agent-grid-artifacts { display: grid; }
.m33-agent-surface[data-active="semantics"] .m33-agent-grid-semantics { display: grid; }

/* Card grids. The Chat right strip uses a single column (vertical stack);
 * the Canvas centre starts as a responsive multi-column grid then JS flips
 * each grid to .m33-canvas-freeform — absolute-positioned cards on a
 * scrollable surface (per spec §5.8: "freeform field of artifact nodes"). */
.m33-strip-surface .m33-agent-grid { grid-template-columns: 1fr; gap: 6px; padding: 0 4px; overflow-y: auto; }
/* Float the Artifacts/Semantics sub-toggle as an overlay on the canvas
 * surface (top-left, above the grid) so the canvas reclaims the row
 * the toggle previously consumed. m33-canvas-surface becomes the
 * positioning anchor; the grid extends full-height under the toggle. */
.m33-canvas-surface { position: relative; }
.m33-canvas-surface > .m33-subtoggle {
  position: absolute; top: 8px; left: 8px;
  margin: 0; z-index: 25;
  background: color-mix(in oklab, var(--m33-card) 80%, transparent 20%);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
/* ---- Canvas Stage (camera-based viewport) ----
 * The grid is the STAGE — fixed-size, clips overflow, doesn't scroll.
 * Inside it, .m33-canvas-world is the world layer that gets the camera
 * transform (translate + scale). Cards live in layout coords inside the
 * world; pan / zoom / center / fit only ever change the world's
 * transform. This is the standard camera-based canvas pattern. */
.m33-canvas-surface .m33-agent-grid {
  position: relative;
  width: 100%; height: 100%;
  overflow: hidden;                     /* world is clipped by the stage */
  /* Dotted grid background — subtle positional reference. */
  background-image:
    radial-gradient(circle, color-mix(in oklab, var(--m33-text-muted) 15%, transparent 85%) 1px, transparent 1px),
    radial-gradient(circle, color-mix(in oklab, var(--m33-text-muted) 30%, transparent 70%) 1px, transparent 1px);
  background-size: 12px 12px, 96px 96px;
  background-position: 0 0, 0 0;
  cursor: grab;                          /* world panable on bare drag */
  touch-action: none;
}
.m33-canvas-surface .m33-agent-grid.m33-canvas-panning { cursor: grabbing; }
/* Active-view visibility */
.m33-canvas-surface[data-active="artifacts"] .m33-agent-grid-artifacts,
.m33-canvas-surface[data-active="semantics"] .m33-agent-grid-semantics {
  display: block;
}
/* The world: positioned absolutely so cards inside use their layout coords
 * directly. Transform-origin top-left so translate+scale composes cleanly. */
.m33-canvas-world {
  position: absolute; top: 0; left: 0;
  width: 1px; height: 1px;               /* doesn't matter; children are absolute */
  transform-origin: 0 0;
  will-change: transform;
}
.m33-canvas-world > .m33-card {
  position: absolute; width: 96px; height: 96px;
  cursor: grab; user-select: none; touch-action: none;
  transition: box-shadow 120ms, transform 120ms, left 380ms cubic-bezier(.2,.7,.2,1), top 380ms cubic-bezier(.2,.7,.2,1);
}
/* During a drag, kill the position transition so the card follows the cursor live. */
.m33-canvas-world > .m33-card.m33-dragging {
  cursor: grabbing; box-shadow: 0 12px 28px rgba(0,0,0,0.4);
  z-index: 10; transition: none;
}
/* Pinned cards — user dragged them in a non-Free mode, so the agent
 * respects their position on subsequent arrangements. Visible indicator:
 * a small accent dot in the top-right of the card. */
.m33-canvas-world > .m33-card.m33-pinned::after {
  content: '';
  position: absolute; top: 4px; right: 4px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--m33-accent);
  box-shadow: 0 0 0 1px var(--m33-bg);
  pointer-events: none;
}
.m33-canvas-world > .m33-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
/* Only animate position during arrangement; otherwise drag should snap. */
.m33-agent-grid:not(.m33-arranging) .m33-canvas-world > .m33-card {
  transition: box-shadow 120ms;
}

/* Multi-select highlight — Shift+click adds/removes a card from the
 * canvas selection. The accent ring distinguishes selected cards from
 * the focus / hover treatments above. */
.m33-card.m33-selected {
  border-color: var(--m33-accent) !important;
  box-shadow: 0 0 0 2px var(--m33-accent), 0 4px 16px color-mix(in oklab, var(--m33-accent) 40%, transparent 60%) !important;
  z-index: 5;
}
.m33-card.m33-selected.m33-dragging { z-index: 11; }

/* Canvas minimap — scaled overview of all cards in the active view, plus
 * a translucent viewport rectangle. Subtle by default; brightens on hover.
 * Click anywhere on it to scroll. */
.m33-canvas { position: relative; }
.m33-canvas-minimap { position: absolute; right: 14px; bottom: 14px; width: 200px; height: 130px; background: color-mix(in oklab, var(--m33-panel) 70%, transparent 30%); border: 1px solid color-mix(in oklab, var(--m33-border) 50%, transparent 50%); border-radius: 6px; overflow: hidden; z-index: 50; cursor: crosshair; opacity: 0.55; transition: opacity 200ms ease, height 200ms ease, width 200ms ease; backdrop-filter: blur(4px); }
.m33-canvas-minimap:hover { opacity: 0.95; }
.m33-minimap-content { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; }
.m33-minimap-card { position: absolute; background: var(--m33-text-muted); border-radius: 4px; opacity: 0.5; }
.m33-canvas-minimap:hover .m33-minimap-card { opacity: 0.75; }
.m33-minimap-card.m33-promoted { background: var(--m33-accent); opacity: 0.7; }
.m33-canvas-minimap:hover .m33-minimap-card.m33-promoted { opacity: 0.95; }
.m33-minimap-viewport { position: absolute; border: 1px solid color-mix(in oklab, var(--m33-accent) 60%, transparent 40%); background: color-mix(in oklab, transparent 94%, var(--m33-accent) 6%); pointer-events: none; border-radius: 2px; transition: border-color 200ms; }
.m33-canvas-minimap:hover .m33-minimap-viewport { border-color: var(--m33-accent); }

/* Canvas cards — the visual grammar.
 *
 * Layout (every card is the same): a 28×28 platform/kind chip pinned
 * top-left, a κ ring + claim-count pinned top-right, then title (small,
 * muted) + description (bold, prominent) flowing at the bottom. The
 * whole card carries a category tint — speech-act for envelopes,
 * platform brand for artifacts — so a glance at the canvas reveals
 * structure without reading text.
 *
 * The artifacts row vs the envelopes row should read as visually
 * parallel — both put κ in the same coordinates, both use whole-card
 * tint, both sit on the same dark chip for their corner glyph. */
.m33-card {
  background: var(--m33-card); border: 1px solid var(--m33-border);
  border-radius: 8px; padding: 7px 8px;
  cursor: pointer; transition: border-color 120ms, transform 120ms, box-shadow 120ms;
  outline: none; display: flex; flex-direction: column; gap: 3px;
  overflow: hidden; position: relative;
}
.m33-card:hover, .m33-card:focus { border-color: var(--m33-accent); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0,0,0,0.3); }

/* κ ring — top-right of every card. Track is faint; fill colour
 * encodes confidence band: low (<.40) amber, mid (.40–.70) brand
 * indigo, high (≥.70) green. The numeric κ sits inside the ring. */
.m33-card-ring { position: absolute; top: 5px; right: 5px; width: 18px; height: 18px; }
.m33-card-ring svg { width: 100%; height: 100%; }
.m33-card-ring .m33-card-ring-track { stroke: rgba(255,255,255,0.14); }
.m33-card-ring .m33-card-ring-fill  { stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; }
.m33-card-ring .m33-card-ring-fill.m33-kappa-low  { stroke: #ffb86b; }
.m33-card-ring .m33-card-ring-fill.m33-kappa-mid  { stroke: var(--m33-accent); }
.m33-card-ring .m33-card-ring-fill.m33-kappa-high { stroke: #b3e08e; }
.m33-card-ring-num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 6px; font-weight: 600; color: var(--m33-text); font-variant-numeric: tabular-nums; }

/* Stats sit directly under the ring — claim count for artifacts,
 * "open"/"resolved" for inquiries, etc. Small, tabular, right-aligned. */
.m33-card-stats {
  position: absolute; top: 26px; right: 6px;
  font-size: 6px; color: var(--m33-text-muted);
  line-height: 1.1; text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Speech-act pill for envelopes. Self-aligned to the start so it sits
 * at the top-left where the platform chip would be on artifacts. */
.m33-card-act {
  font-size: 6px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700;
  padding: 1px 4px; border-radius: 4px; background: rgba(255,255,255,0.08);
  display: inline-block; align-self: flex-start;
}
.m33-card-act.m33-act-text-assertion    { color: #8ab4ff; }
.m33-card-act.m33-act-text-formal       { color: #c7a2ff; }
.m33-card-act.m33-act-text-contested    { color: #ff8a8a; }
.m33-card-act.m33-act-text-hunch        { color: #ffb86b; }
.m33-card-act.m33-act-text-analogy      { color: #6fd6c8; }
.m33-card-act.m33-act-text-question     { color: var(--m33-accent); }
.m33-card-act.m33-act-text-performative { color: #b3e08e; }
.m33-card-act.m33-act-text-expression   { color: #c7a2ff; }

/* Whole-card speech-act tint (envelopes). Folder-color level — calm
 * enough to read, distinct enough to count at a glance. */
.m33-act-assertion    { background: color-mix(in oklab, #5b8dff 10%, var(--m33-card) 90%); border-color: color-mix(in oklab, #5b8dff 38%, var(--m33-border) 62%); }
.m33-act-formal       { background: color-mix(in oklab, #c7a2ff 12%, var(--m33-card) 88%); border-color: color-mix(in oklab, #c7a2ff 38%, var(--m33-border) 62%); }
.m33-act-contested    { background: color-mix(in oklab, #ff7373 10%, var(--m33-card) 90%); border-color: color-mix(in oklab, #ff7373 40%, var(--m33-border) 60%); }
.m33-act-hunch        { background: color-mix(in oklab, #ffb86b 12%, var(--m33-card) 88%); border-color: color-mix(in oklab, #ffb86b 38%, var(--m33-border) 62%); }
.m33-act-analogy      { background: color-mix(in oklab, #6fd6c8 10%, var(--m33-card) 90%); border-color: color-mix(in oklab, #6fd6c8 38%, var(--m33-border) 62%); }
.m33-act-question     { background: color-mix(in oklab, var(--m33-accent) 8%, var(--m33-card) 92%); border-color: color-mix(in oklab, var(--m33-accent) 32%, var(--m33-border) 68%); }
.m33-act-performative { background: color-mix(in oklab, #b3e08e 10%, var(--m33-card) 90%); border-color: color-mix(in oklab, #b3e08e 36%, var(--m33-border) 64%); }
.m33-act-expression   { background: color-mix(in oklab, #c7a2ff 8%, var(--m33-card) 92%); border-color: color-mix(in oklab, #c7a2ff 32%, var(--m33-border) 68%); }

/* Whole-card platform tint (artifacts) — parallels the speech-act tint
 * pattern. Per-publication overrides (CNBC peacock teal, Bloomberg
 * orange, etc.) take precedence over the generic press tint so each
 * brand reads true. */
.m33-platform-x        { background: color-mix(in oklab, #ffffff 6%, var(--m33-card) 94%); border-color: color-mix(in oklab, #ffffff 22%, var(--m33-border) 78%); }
.m33-platform-reddit   { background: color-mix(in oklab, #ff4500 9%, var(--m33-card) 91%); border-color: color-mix(in oklab, #ff4500 36%, var(--m33-border) 64%); }
.m33-platform-youtube  { background: color-mix(in oklab, #ff0000 9%, var(--m33-card) 91%); border-color: color-mix(in oklab, #ff0000 36%, var(--m33-border) 64%); }
.m33-platform-linkedin { background: color-mix(in oklab, #0a66c2 11%, var(--m33-card) 89%); border-color: color-mix(in oklab, #0a66c2 38%, var(--m33-border) 62%); }
.m33-platform-github   { background: color-mix(in oklab, #ffffff 5%, var(--m33-card) 95%); border-color: color-mix(in oklab, #ffffff 18%, var(--m33-border) 82%); }
.m33-platform-arxiv    { background: color-mix(in oklab, #b31b1b 10%, var(--m33-card) 90%); border-color: color-mix(in oklab, #b31b1b 38%, var(--m33-border) 62%); }
.m33-platform-paper    { background: color-mix(in oklab, var(--m33-accent) 8%, var(--m33-card) 92%); border-color: color-mix(in oklab, var(--m33-accent) 32%, var(--m33-border) 68%); }
.m33-platform-press    { background: color-mix(in oklab, #888 14%, var(--m33-card) 86%); border-color: color-mix(in oklab, #888 38%, var(--m33-border) 62%); }
.m33-platform-cnbc       { background: color-mix(in oklab, #00a4e4 9%, var(--m33-card) 91%); border-color: color-mix(in oklab, #00a4e4 36%, var(--m33-border) 64%); }
.m33-platform-bloomberg  { background: color-mix(in oklab, #ff6900 9%, var(--m33-card) 91%); border-color: color-mix(in oklab, #ff6900 36%, var(--m33-border) 64%); }
.m33-platform-reuters    { background: color-mix(in oklab, #ff8000 8%, var(--m33-card) 92%); border-color: color-mix(in oklab, #ff8000 34%, var(--m33-border) 66%); }
.m33-platform-nyt        { background: color-mix(in oklab, #ffffff 5%, var(--m33-card) 95%); border-color: color-mix(in oklab, #ffffff 20%, var(--m33-border) 80%); }
.m33-platform-ft         { background: color-mix(in oklab, #fff1e5 8%, var(--m33-card) 92%); border-color: color-mix(in oklab, #f4b8a0 34%, var(--m33-border) 66%); }
.m33-platform-wsj        { background: color-mix(in oklab, #ffffff 5%, var(--m33-card) 95%); border-color: color-mix(in oklab, #ffffff 18%, var(--m33-border) 82%); }
.m33-platform-substack   { background: color-mix(in oklab, #ff6719 9%, var(--m33-card) 91%); border-color: color-mix(in oklab, #ff6719 36%, var(--m33-border) 64%); }
/* Document types — branded colours for at-a-glance file-type recognition */
.m33-platform-pdf      { background: color-mix(in oklab, #d93025 10%, var(--m33-card) 90%); border-color: color-mix(in oklab, #d93025 38%, var(--m33-border) 62%); }
.m33-platform-gdoc     { background: color-mix(in oklab, #1a73e8 10%, var(--m33-card) 90%); border-color: color-mix(in oklab, #1a73e8 38%, var(--m33-border) 62%); }
.m33-platform-word     { background: color-mix(in oklab, #2b579a 14%, var(--m33-card) 86%); border-color: color-mix(in oklab, #2b579a 40%, var(--m33-border) 60%); }
.m33-platform-pptx     { background: color-mix(in oklab, #d24726 10%, var(--m33-card) 90%); border-color: color-mix(in oklab, #d24726 38%, var(--m33-border) 62%); }
.m33-platform-xlsx     { background: color-mix(in oklab, #217346 12%, var(--m33-card) 88%); border-color: color-mix(in oklab, #217346 38%, var(--m33-border) 62%); }
.m33-platform-db       { background: color-mix(in oklab, #c7a2ff 12%, var(--m33-card) 88%); border-color: color-mix(in oklab, #c7a2ff 38%, var(--m33-border) 62%); }

/* Platform/kind icon chip — small corner glyph, uniform polarity
 * (light marks on dark chip for every platform). The chip background
 * stays the same dark across the row so the row reads as one family. */
.m33-card-icon {
  width: 28px; height: 28px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.22);
  align-self: flex-start; flex: 0 0 auto;
  color: #fff;
}
.m33-card-icon svg { width: 18px; height: 18px; }
/* Wordmark icons (CNBC, Bloomberg, arXiv, etc.) need a wider/shorter
 * slot so the wordmark doesn't get cropped or rendered too small. */
.m33-card-icon.m33-card-icon-wordmark svg      { width: 24px; height: 12px; }
.m33-card-icon.m33-card-icon-wordmark-wide svg { width: 26px; height: 10px; }

/* Title (smaller, muted) above description (bold, prominent). The
 * description carries the meaning; the title is just a label. */
.m33-card-title { font-weight: 500; font-size: 8px; color: var(--m33-text-muted); line-height: 1.15; -webkit-line-clamp: 1; -webkit-box-orient: vertical; display: -webkit-box; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 4px; flex: 0 0 auto; }
.m33-card-desc  { font-weight: 700; font-size: 10px; color: var(--m33-text); line-height: 1.2; -webkit-line-clamp: 3; -webkit-box-orient: vertical; display: -webkit-box; overflow: hidden; margin-top: 1px; flex: 1; }
/* Envelope body keeps its older role — multi-line muted text under the
 * title; envelopes show subject-as-title and predicate-as-body. */
.m33-card-body { font-size: 8px; line-height: 1.25; color: var(--m33-text-muted); flex: 1; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; margin-top: 1px; }
.m33-card-meta { font-size: 7px; color: var(--m33-text-muted); display: flex; align-items: center; justify-content: space-between; gap: 3px; flex: 0 0 auto; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; margin-top: 2px; }
.m33-card-meta > * { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.m33-promoted-badge { padding: 1px 4px; border-radius: 4px; background: var(--m33-accent); color: white; font-size: 6px; font-weight: 700; letter-spacing: 0.04em; }
.m33-envelope-card.m33-promoted { border-color: var(--m33-accent); }

/* Inquiry card — uses the question speech-act tint via .m33-act-question.
 * No κ ring (questions don't carry confidence). */
.m33-inquiry-card .m33-card-title { font-weight: 500; color: var(--m33-text); font-size: 9px; white-space: normal; -webkit-line-clamp: 3; }

/* Proto-claim card — dashed border communicates "tentative, no claimant
 * yet". The act tint still applies for the predicate's speech act. */
.m33-card.m33-proto-card { border-style: dashed; opacity: 0.94; }
.m33-proto-card .m33-card-meta { font-style: italic; }

/* Canvas SVG edge layer — lives inside the freeform grid behind the cards.
 * Two origin classes (inferred / discourse) cross three kinds (supports /
 * contradicts / seeds), per spec §5.8. Discourse-confirmed edges are bold
 * and saturated; inferred edges are thin, dashed, and muted so the user
 * can tell at a glance which connections Vega just guessed at vs which
 * the user-and-Vega named together. */
.m33-canvas-edges { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 0; }
/* non-scaling-stroke so the line widths below stay readable at any zoom */
.m33-canvas-edges line { vector-effect: non-scaling-stroke; }

/* Supports — green family. Discourse-confirmed = solid bold. Inferred =
 * solid mid-weight in muted green so it still reads at low zoom. */
.m33-canvas-edges .m33-edge-supports                                { stroke: #6fcf7f; stroke-width: 2;   opacity: 0.78; }
.m33-canvas-edges .m33-edge-supports.m33-edge-origin-discourse      { stroke: var(--m33-good); stroke-width: 3; opacity: 1; }
.m33-canvas-edges .m33-edge-supports.m33-edge-origin-inferred       { stroke-dasharray: 5 4; }

/* Contradicts — orange dashed. Bumped weight + opacity so they stay
 * visible at 10–20 % zoom where the canvas looks like a minimap. */
.m33-canvas-edges .m33-edge-contradicts                             { stroke: var(--m33-warn); stroke-width: 2.5; stroke-dasharray: 6 4; opacity: 1; }
.m33-canvas-edges .m33-edge-contradicts.m33-edge-origin-discourse   { stroke-width: 3.5; }

/* Corroborates — independent agreement across sources. Brighter teal
 * solid stroke; symmetric (no arrow). Thicker than supports because the
 * cross-source signal is the most informative. */
.m33-canvas-edges .m33-edge-corroborates                            { stroke: #6fd6c8; stroke-width: 2.5; opacity: 0.95; }
.m33-canvas-edges .m33-edge-corroborates.m33-edge-origin-discourse  { stroke-width: 3.5; }

/* Refines — A is a more specific version of B. Cool blue to set it
 * apart from the green/teal "this backs that" family. */
.m33-canvas-edges .m33-edge-refines                                 { stroke: #6ba6f0; stroke-width: 2; opacity: 0.85; stroke-dasharray: 8 3; }

/* Seeds — light grey dotted; almost always inferred. */
.m33-canvas-edges .m33-edge-seeds                                   { stroke: var(--m33-text-muted); stroke-width: 1.5; stroke-dasharray: 2 4; opacity: 0.7; }
.m33-canvas-edges .m33-edge-seeds.m33-edge-origin-discourse         { stroke-width: 2; opacity: 0.95; }

/* Canvas surface chrome */
.m33-canvas { display: flex; flex-direction: column; height: 100%; padding: 16px max(16px, calc((100% - 1100px) / 2)) 0; gap: 12px; box-sizing: border-box; }
.m33-canvas-banner { display: flex; align-items: baseline; gap: 12px; padding-bottom: 4px; border-bottom: 1px solid var(--m33-border); flex: 0 0 auto; }
.m33-canvas-banner-title { font-size: 14px; font-weight: 600; }
.m33-canvas-banner-meta { font-size: 11px; color: var(--m33-text-muted); flex: 1; }
.m33-canvas-surface { flex: 1 1 auto; min-height: 0; }

/* Stats footer — replaces the in-banner meta line, sits flush with the
 * bottom of the canvas so the surface gets back the full vertical track. */
.m33-canvas-footer {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 4px; border-top: 1px solid var(--m33-border);
  font-size: 11px; color: var(--m33-text-muted);
}
.m33-canvas-foot-stat { white-space: nowrap; }
.m33-canvas-foot-sep { opacity: 0.5; }
.m33-canvas-foot-spacer { flex: 1; }
.m33-canvas-foot-hint { font-size: 10px; opacity: 0.7; white-space: nowrap; }
@media (max-width: 720px) { .m33-canvas-foot-hint { display: none; } }

/* Zoom + pan toolbar — floats top-right of the canvas surface. Mirrors
 * the minimap's translucent / blurred chrome. */
.m33-canvas-zoombar {
  position: absolute; top: 12px; right: 12px; z-index: 50;
  display: inline-flex; align-items: center; gap: 2px;
  background: color-mix(in oklab, var(--m33-panel) 70%, transparent 30%);
  border: 1px solid color-mix(in oklab, var(--m33-border) 50%, transparent 50%);
  border-radius: 8px; padding: 3px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0.55; transition: opacity 200ms ease;
}
.m33-canvas-zoombar:hover { opacity: 1; }
.m33-zoom-btn, .m33-zoom-level {
  background: transparent; border: 0; color: var(--m33-text-muted);
  width: 28px; height: 24px; border-radius: 5px;
  font-size: 14px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.m33-zoom-level { width: auto; padding: 0 8px; font-size: 11px; }
.m33-zoom-btn:hover, .m33-zoom-level:hover { background: var(--m33-card); color: var(--m33-text); }
.m33-zoom-sep {
  width: 1px; height: 16px;
  background: color-mix(in oklab, var(--m33-border) 40%, transparent 60%);
  margin: 0 2px;
}

/* Canvas arrangement control — independent from the Artifacts/Semantics
 * view toggle. Sits in the canvas top-right alongside zoom; visually
 * distinct (sentence-case label, smaller text) so it doesn't read as a
 * second copy of the view toggle. Always shows which mode is active. */
.m33-canvas-arrange {
  position: absolute; top: 12px; right: 184px; z-index: 50;
  display: inline-flex; align-items: center; gap: 2px;
  background: color-mix(in oklab, var(--m33-panel) 70%, transparent 30%);
  border: 1px solid color-mix(in oklab, var(--m33-border) 50%, transparent 50%);
  border-radius: 8px; padding: 3px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0.7; transition: opacity 200ms ease;
}
.m33-canvas-arrange:hover { opacity: 1; }
.m33-arrange-btn {
  background: transparent; border: 0; color: var(--m33-text-muted);
  height: 24px; padding: 0 10px; border-radius: 5px;
  font-size: 11px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  letter-spacing: 0.02em;
}
.m33-arrange-btn:hover:not(.m33-active) { color: var(--m33-text); background: var(--m33-card); }
.m33-arrange-btn.m33-active { background: var(--m33-accent); color: #fff; }

/* Pan affordance — when space is held, swap the cursor on the canvas
 * surface so the user knows a left-drag will pan, not start a card drag. */
body.m33-canvas-pan-mode .m33-canvas-surface,
body.m33-canvas-pan-mode .m33-canvas-surface .m33-agent-grid,
body.m33-canvas-pan-mode .m33-canvas-surface .m33-card { cursor: grab !important; }
.m33-canvas-surface .m33-agent-grid.m33-canvas-panning,
.m33-canvas-surface .m33-agent-grid.m33-canvas-panning .m33-card { cursor: grabbing !important; }

/* When hoisted into the global header (see canvas page render), the
 * banner sits inline with the app-name cluster. We strip the bottom
 * border, tighten the padding, and let it flex into the centre so the
 * stats and Reset button float between the left logo and the right
 * launcher. The canvas content then starts immediately under the header
 * border, reclaiming ~32px of vertical space for the graph. */
.m33-canvas-banner.m33-canvas-banner-in-header {
  padding: 0 16px; border-bottom: 0; flex: 1; gap: 14px;
  align-items: center; align-self: center; min-width: 0;
}
.m33-canvas-banner-in-header .m33-canvas-banner-title { font-size: 13px; white-space: nowrap; }
.m33-canvas-banner-in-header .m33-canvas-banner-meta { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Ideation switcher button — pinned to the geometric center of the
 * header so it lands at the same screen coordinates in every skin
 * (Application / Chat / Canvas), regardless of which other buttons
 * sit in header-right. The header itself is the positioning anchor.
 *
 * Visual tone: subtle. The active ideation is informational context,
 * not a primary action — softer color + lighter weight + smaller size
 * than the brand mark on the left. Hover surfaces the affordance. */
.m33-header { position: relative; }
.m33-ideation-switcher {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  background: transparent; border: 1px solid transparent;
  color: var(--m33-text-muted);
  padding: 3px 10px; border-radius: 6px;
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px; font-weight: 400; letter-spacing: 0.01em;
  max-width: 40vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.m33-ideation-switcher:hover { color: var(--m33-text); background: var(--m33-card); border-color: var(--m33-border); }
.m33-ideation-switcher[aria-expanded="true"] { color: var(--m33-text); background: var(--m33-card); border-color: var(--m33-border); }
.m33-ideation-switcher .m33-canvas-banner-title {
  overflow: hidden; text-overflow: ellipsis; max-width: 100%;
  font-weight: 400; font-size: 12px; color: inherit;
}
.m33-ideation-switcher[hidden] { display: none; }

/* Floating Vega chat — desktop-style overlay that opens from the
 * "Chat @Vega" button without navigating away. Iframes /chat scoped
 * to the active ideation so the realtime stack works as-is. */
.m33-vega-float {
  position: fixed; right: 16px; bottom: 16px;
  width: min(440px, 90vw); height: min(640px, 80vh);
  background: var(--m33-panel); border: 1px solid var(--m33-border);
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.02) inset;
  z-index: 800;
  display: flex; flex-direction: column;
}
.m33-vega-float[hidden] { display: none; }
.m33-vega-float-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--m33-border);
  background: color-mix(in oklab, var(--m33-card) 70%, var(--m33-panel) 30%);
  cursor: grab; user-select: none;
}
.m33-vega-float-dragging .m33-vega-float-head { cursor: grabbing; }
.m33-vega-float-dragging { transition: none; }
.m33-vega-float-title { font-weight: 600; font-size: 13px; color: var(--m33-text); }
.m33-vega-float-sub { font-size: 11px; color: var(--m33-text-muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m33-vega-float-pop, .m33-vega-float-close {
  background: transparent; border: 0; color: var(--m33-text-muted);
  font-size: 14px; padding: 2px 8px; border-radius: 4px; cursor: pointer; line-height: 1;
}
.m33-vega-float-pop:hover, .m33-vega-float-close:hover { color: var(--m33-text); background: var(--m33-card); }
.m33-vega-float-close { font-size: 18px; }
.m33-vega-float-body {
  flex: 1; width: 100%; min-height: 0;
  background: var(--m33-bg);
  display: flex; flex-direction: column;
  overflow: hidden;
}
/* Inside the float, the .m33-app wrapper is decorative — it lets the
 * chat IIFE find its expected ancestor for CSS variables. We hide
 * everything from the inline chat shell except the chat surface itself
 * (no header, no rails, no footer — just the conversation). */
.m33-vega-float-app { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.m33-vega-float-app > .m33-chat { flex: 1; min-height: 0; }
.m33-vega-float-app .m33-chat-stream { flex: 1; padding: 12px; }
.m33-vega-float-app .m33-chat-form { padding: 8px 10px; border-top: 1px solid var(--m33-border); }

/* Collapsed state — panel shrinks to a small icon button */
.m33-vega-float-collapsed {
  width: 48px !important; height: 48px !important;
  min-width: 0; min-height: 0;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.06) inset;
}
.m33-vega-float-collapsed .m33-vega-float-head,
.m33-vega-float-collapsed .m33-vega-float-body { display: none; }
.m33-vega-float-icon {
  display: none; /* hidden when panel is expanded */
  width: 100%; height: 100%;
  align-items: center; justify-content: center;
  background: transparent; border: 0; color: var(--m33-accent, #7d8aff);
  cursor: pointer; padding: 0;
  transition: color 150ms, transform 150ms;
}
.m33-vega-float-icon:hover { color: var(--m33-text, #f0f2ff); transform: scale(1.12); }
.m33-vega-float-collapsed .m33-vega-float-icon { display: flex; }

/* "Chat @Vega" — replaces the framework's prominent indigo Assistant
 * button. Reads as a secondary, text-led navigation hint: muted by
 * default, brightens on hover. */
.m33-chat-vega-btn {
  background: transparent;
  border: 1px solid var(--m33-border);
  color: var(--m33-text-muted);
  padding: 5px 12px; border-radius: 6px;
  font-size: 12px; font-weight: 500;
  cursor: pointer;
  transition: color 120ms, border-color 120ms, background 120ms;
}
.m33-chat-vega-btn:hover {
  color: var(--m33-accent);
  border-color: color-mix(in oklab, var(--m33-accent) 50%, var(--m33-border) 50%);
  background: color-mix(in oklab, var(--m33-accent) 8%, transparent 92%);
}
.m33-ideation-switcher:hover { background: var(--m33-card); border-color: var(--m33-border); }
.m33-ideation-switcher[aria-expanded="true"] { background: var(--m33-card); border-color: var(--m33-border); }
.m33-ideation-chev { color: var(--m33-text-muted); font-size: 10px; transition: transform 120ms; }
.m33-ideation-switcher[aria-expanded="true"] .m33-ideation-chev { transform: rotate(180deg); }

/* Dropdown panel — body-level fixed-position list of ideations. */
.m33-ideation-menu {
  position: fixed; min-width: 360px; max-width: 480px; max-height: 70vh;
  overflow-y: auto;
  background: var(--m33-panel); border: 1px solid var(--m33-border); border-radius: 10px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.45);
  z-index: 80; padding: 6px;
  display: none;
}
.m33-ideation-menu.m33-open { display: block; }
.m33-ideation-menu-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 8px; border-bottom: 1px solid var(--m33-border);
  margin-bottom: 4px;
}
.m33-ideation-menu-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--m33-text-muted); }
.m33-ideation-menu-new {
  background: transparent; border: 1px dashed var(--m33-border); color: var(--m33-text-muted);
  padding: 4px 10px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.m33-ideation-menu-new:hover { color: var(--m33-accent); border-color: var(--m33-accent); }
.m33-ideation-menu-list { display: flex; flex-direction: column; gap: 2px; }

.m33-ideation-row {
  display: block; padding: 8px 10px; border-radius: 6px;
  text-decoration: none; color: inherit;
  transition: background 120ms;
}
.m33-ideation-row:hover { background: var(--m33-card); }
.m33-ideation-row.m33-active { background: color-mix(in oklab, var(--m33-accent) 14%, transparent 86%); border: 1px solid color-mix(in oklab, var(--m33-accent) 30%, transparent 70%); }
.m33-ideation-row-head { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.m33-ideation-row-title { font-weight: 600; font-size: 13px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m33-ideation-pin { color: var(--m33-accent); font-size: 11px; }
.m33-ideation-row-mandate { font-size: 11px; color: var(--m33-text-muted); margin: 2px 0; line-height: 1.4; }
.m33-ideation-row-meta { font-size: 10px; color: var(--m33-text-muted); }
.m33-canvas-banner-in-header .m33-canvas-reset { padding: 4px 10px; font-size: 11px; flex: 0 0 auto; }
.m33-canvas-reset { padding: 4px 10px; font-size: 11px; background: transparent; border: 1px solid var(--m33-border); color: var(--m33-text-muted); border-radius: 6px; cursor: pointer; }
.m33-canvas-reset:hover { color: var(--m33-text); border-color: var(--m33-text-muted); }

/* Rollover detail panel — appears on hover beside any card. Position is
 * fixed so it escapes any container overflow. Wider than a card so the
 * full predicate, provenance, and connections fit. */
.m33-rollover { position: fixed; z-index: 200; width: 320px; max-width: 90vw; max-height: 80vh; overflow-y: auto; background: var(--m33-panel); border: 1px solid var(--m33-border); border-radius: 10px; padding: 12px 14px; box-shadow: 0 14px 40px rgba(0,0,0,0.5); font-size: 12px; line-height: 1.4; color: var(--m33-text); pointer-events: auto; }
.m33-roll-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.m33-roll-tier { font-size: 9px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--m33-text-muted); padding: 2px 6px; background: var(--m33-card); border-radius: 8px; }
.m33-roll-kappa { font-size: 11px; color: var(--m33-text); font-variant-numeric: tabular-nums; margin-left: auto; }
.m33-roll-badge { font-size: 9px; padding: 2px 6px; border-radius: 8px; }
.m33-roll-promoted { background: var(--m33-accent); color: white; font-weight: 600; }
.m33-roll-title { font-size: 14px; font-weight: 600; line-height: 1.25; margin-bottom: 8px; }
.m33-roll-section { margin-bottom: 8px; }
.m33-roll-section:last-of-type { margin-bottom: 0; }
.m33-roll-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--m33-text-muted); margin-bottom: 2px; }
.m33-roll-url { font-size: 10px; color: var(--m33-accent); word-break: break-all; }
.m33-roll-meta { font-size: 10px; color: var(--m33-text-muted); }
.m33-roll-greeks { display: flex; flex-wrap: wrap; gap: 4px; }
.m33-roll-greek { padding: 2px 6px; background: var(--m33-card); border-radius: 6px; font-size: 10px; font-variant-numeric: tabular-nums; }
.m33-roll-greek-sym { font-weight: 600; margin-right: 4px; }
.m33-roll-tension { color: var(--m33-warn); }
.m33-roll-hint { font-size: 10px; color: var(--m33-text-muted); margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--m33-border); font-style: italic; }
.m33-canvas .m33-agent-surface { flex: 1; min-height: 0; }
.m33-canvas .m33-agent-grid { padding-bottom: 24px; }

.m33-stat-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12px; }
.m33-stat-row strong { font-variant-numeric: tabular-nums; }
.m33-meta { font-size: 11px; color: var(--m33-text-muted); line-height: 1.5; }

/* Canvas page should also have zero center-panel padding so the grid can
 * use the full width. */
.m33-panel-center:has(.m33-canvas) { padding: 0; overflow: hidden; }

/* Envelope detail dialog — opens on card click. Native <dialog>; backdrop
 * styled via ::backdrop. */
.m33-envelope-dialog { width: min(560px, 92vw); max-height: 86vh; padding: 0; border: 1px solid var(--m33-border); border-radius: 12px; background: var(--m33-panel); color: var(--m33-text); box-shadow: 0 24px 60px rgba(0,0,0,0.55); }
.m33-envelope-dialog::backdrop { background: rgba(0,0,0,0.55); }
.m33-envelope-dialog-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--m33-border); }
.m33-env-dialog-tier { font-size: 10px; font-weight: 600; letter-spacing: 0.06em; padding: 2px 8px; border-radius: 9px; background: var(--m33-card); color: var(--m33-text-muted); white-space: nowrap; }
.m33-env-dialog-title { flex: 1; font-size: 15px; line-height: 1.3; }
.m33-envelope-dialog-body { padding: 14px 16px; overflow-y: auto; max-height: calc(86vh - 130px); }
.m33-envelope-dialog-actions { padding: 12px 16px; border-top: 1px solid var(--m33-border); background: var(--m33-bg); }

.m33-env-section { margin-bottom: 14px; }
.m33-env-section:last-child { margin-bottom: 0; }
.m33-env-label { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--m33-text-muted); margin-bottom: 4px; }
.m33-env-predicate { font-size: 14px; line-height: 1.45; }
.m33-env-provenance { font-size: 12px; color: var(--m33-text-muted); display: flex; flex-direction: column; gap: 2px; }
.m33-env-key { display: inline-block; min-width: 70px; color: var(--m33-text); }

.m33-greeks { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.m33-greek { padding: 6px 4px; background: var(--m33-card); border: 1px solid var(--m33-border); border-radius: 6px; text-align: center; }
.m33-greek-sym { display: block; font-size: 14px; font-weight: 600; color: var(--m33-text); }
.m33-greek-val { display: block; font-size: 11px; color: var(--m33-text-muted); font-variant-numeric: tabular-nums; margin-top: 2px; }

.m33-connection { display: grid; grid-template-columns: auto auto 1fr; gap: 8px; align-items: baseline; padding: 6px 8px; border-left: 2px solid var(--m33-border); margin-bottom: 4px; font-size: 12px; }
.m33-conn-tension { border-left-color: var(--m33-bad); }
.m33-conn-support { border-left-color: var(--m33-good); }
.m33-conn-seed    { border-left-color: var(--m33-warn); }
.m33-conn-kind { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--m33-text-muted); }
.m33-conn-arrow { color: var(--m33-text-muted); }
.m33-conn-other strong { font-weight: 600; }

.m33-precheck-list { margin: 0 0 10px 0; padding-left: 18px; font-size: 12px; color: var(--m33-bad); }
.m33-precheck-list li { margin-bottom: 2px; }
.m33-precheck-override { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--m33-warn); margin-bottom: 10px; }
.m33-env-promote-buttons { display: flex; gap: 8px; }
.m33-env-promote-buttons button { flex: 1; }
.m33-env-promoted-banner { padding: 8px 12px; border-radius: 6px; background: color-mix(in oklab, var(--m33-card) 70%, var(--m33-accent) 30%); color: var(--m33-text); font-size: 12px; }
.m33-flash-error { padding: 8px 12px; border-radius: 6px; background: color-mix(in oklab, var(--m33-card) 70%, var(--m33-bad) 30%); color: var(--m33-text); font-size: 12px; margin-top: 8px; }
@keyframes m33-shake { 0%,100%{transform:translateX(0);} 25%{transform:translateX(-4px);} 75%{transform:translateX(4px);} }
.m33-shake { animation: m33-shake 320ms ease; }
.m33-chat-form { display: flex; gap: 8px; padding: 12px max(16px, calc((100% - 760px) / 2)) 24px; border-top: 1px solid var(--m33-border); background: var(--m33-bg); }
.m33-chat-form input { flex: 1; background: var(--m33-panel); color: var(--m33-text); border: 1px solid var(--m33-border); border-radius: 8px; padding: 12px 14px; font-size: 14px; outline: none; }
.m33-chat-form input:focus { border-color: var(--m33-accent); }

/* Compact chat surface — used when the discourse runs in the Canvas right
 * inspector (256-px rail) rather than the full-width centre. Tightens
 * bubble width, padding, and form chrome so the conversation reads cleanly
 * at narrow widths without overflowing or clipping the voice controls. */
.m33-panel-right:has(.m33-chat-compact) { padding: 0; overflow: hidden; }
.m33-chat.m33-chat-compact { height: 100%; }
.m33-chat-compact .m33-chat-stream { padding: 12px 12px 8px; gap: 10px; }
.m33-chat-compact .m33-chat-msg { font-size: 13px; padding: 8px 11px; max-width: 92%; line-height: 1.45; }
.m33-chat-compact .m33-chat-row.m33-from-user,
.m33-chat-compact .m33-chat-row.m33-from-vega { max-width: 92%; }
.m33-chat-compact .m33-chat-form { padding: 8px 10px 12px; gap: 6px; flex-wrap: wrap; }
.m33-chat-compact .m33-chat-form input { padding: 8px 10px; font-size: 13px; min-width: 0; flex: 1 1 100%; order: -1; }
.m33-chat-compact .m33-chat-form .m33-icon-btn { width: 32px; height: 32px; flex: 0 0 32px; }
.m33-chat-compact .m33-chat-form .m33-icon-btn svg { width: 14px; height: 14px; }
.m33-chat-compact .m33-chat-form .m33-primary-btn { padding: 6px 10px; font-size: 12px; }
.m33-chat-empty { color: var(--m33-text-muted); text-align: center; padding: 40px 0; }

/* Voice rails on the chat form. The mic button pulses red while recording
 * (the standard "I'm listening" affordance) and fades to a "thinking" tone
 * while the audio is on the wire to the STT proxy. The speaker toggle is
 * sticky — once on, it sits accent-coloured to remind the user that
 * replies are being read aloud. */
.m33-chat-form .m33-icon-btn { width: 40px; height: 40px; flex: 0 0 40px; }
.m33-chat-form .m33-icon-btn svg { width: 18px; height: 18px; }
.m33-chat-form .m33-mic-btn.m33-recording {
  color: #fff; border-color: var(--m33-warn, #ff5050); background: var(--m33-warn, #ff5050);
  animation: m33-mic-pulse 1.4s ease-in-out infinite;
}
.m33-chat-form .m33-mic-btn.m33-busy { opacity: 0.6; cursor: progress; }
.m33-chat-form .m33-tts-btn.m33-active {
  color: var(--m33-accent); border-color: var(--m33-accent);
}
@keyframes m33-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 80, 80, 0.5); }
  50%      { box-shadow: 0 0 0 8px rgba(255, 80, 80, 0); }
}

/* Vega-mention spotlight — when Vega's streaming reply names a card on the
 * canvas, that card gets the m33-vega-mentioned class. The accent outline
 * + pulsing ring makes the link between discourse and canvas visible:
 * "she's talking about THIS one." Cleared a beat after the reply completes. */
.m33-vega-mentioned {
  outline: 2px solid var(--m33-accent);
  outline-offset: 2px;
  position: relative;
  z-index: 5;
  animation: m33-mention-pulse 1.6s ease-in-out infinite;
}
@keyframes m33-mention-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--m33-accent) 55%, transparent 45%); }
  50%      { box-shadow: 0 0 0 10px color-mix(in oklab, var(--m33-accent) 0%, transparent 100%); }
}

/* Web-search results panel — surfaces when Vega calls the search_web
 * tool. Floats over the canvas without taking it over, so the user sees
 * Vega's spoken summary alongside the candidate sources and clicks one
 * to ingest. Closes on × or after a successful ingest. */
.m33-search-panel {
  position: fixed; right: 24px; top: 96px; width: 380px; max-height: 70vh;
  display: flex; flex-direction: column;
  background: var(--m33-panel); color: var(--m33-text);
  border: 1px solid var(--m33-border); border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.4);
  font-size: 13px;
  z-index: 60;
  overflow: hidden;
}
.m33-search-head { display: flex; align-items: baseline; gap: 8px; padding: 12px 14px 8px; border-bottom: 1px solid var(--m33-border); cursor: grab; user-select: none; touch-action: none; }
.m33-search-panel.m33-search-dragging { user-select: none; }
.m33-search-panel.m33-search-dragging .m33-search-head { cursor: grabbing; }
.m33-search-title { font-weight: 600; flex: 1; }
.m33-search-intent { color: var(--m33-text-muted); font-size: 11px; }
.m33-search-close { background: transparent; border: 0; color: var(--m33-text-muted); font-size: 18px; cursor: pointer; padding: 0 4px; line-height: 1; }
.m33-search-close:hover { color: var(--m33-text); }
.m33-search-summary { padding: 10px 14px; color: var(--m33-text-muted); font-size: 12px; border-bottom: 1px solid var(--m33-border); white-space: pre-wrap; }
.m33-search-results { overflow-y: auto; padding: 4px 0; }
.m33-search-result { padding: 10px 14px; border-bottom: 1px solid color-mix(in oklab, var(--m33-border) 50%, transparent 50%); }
.m33-search-result:last-child { border-bottom: 0; }
.m33-search-result-host { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--m33-text-muted); margin-bottom: 2px; }
.m33-search-result-title { display: block; color: var(--m33-text); font-weight: 500; text-decoration: none; }
.m33-search-result-title:hover { text-decoration: underline; }
.m33-search-result-snippet { color: var(--m33-text-muted); margin: 4px 0 8px; font-size: 12px; line-height: 1.4; }
.m33-search-ingest { background: var(--m33-accent); color: white; border: 0; padding: 5px 12px; border-radius: 5px; font-size: 12px; cursor: pointer; }
.m33-search-ingest:hover:not(:disabled) { background: var(--m33-accent-hover); }
.m33-search-ingest:disabled { opacity: 0.6; cursor: progress; }
.m33-search-ingest.m33-ingested { background: var(--m33-good); color: white; cursor: default; }

/* Loading state — appears the moment Vega starts a search, before any
 * results land. Spinner + status text occupy the body until results
 * replace them. */
.m33-search-body { overflow-y: auto; }
.m33-search-panel.m33-search-loading .m33-search-body { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px 14px; gap: 12px; }
.m33-search-spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid color-mix(in oklab, var(--m33-text-muted) 25%, transparent 75%);
  border-top-color: var(--m33-accent);
  animation: m33-spin 0.9s linear infinite;
}
.m33-search-loading-msg { color: var(--m33-text-muted); font-size: 12px; text-align: center; }
@keyframes m33-spin { to { transform: rotate(360deg); } }

/* Paste-text fallback inside the search panel — shown when a host
 * blocks server-side fetch (Forbes-class anti-bot, paywalled sites). */
.m33-search-paste-fallback { padding: 12px 14px; border: 1px solid var(--m33-warn); border-radius: 6px; margin: 8px 14px; background: color-mix(in oklab, var(--m33-warn) 8%, transparent 92%); }
.m33-search-paste-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; font-size: 12px; }
.m33-search-paste-open { color: var(--m33-accent); text-decoration: none; font-size: 11px; }
.m33-search-paste-open:hover { text-decoration: underline; }
.m33-search-paste-msg { font-size: 12px; color: var(--m33-text-muted); margin-bottom: 8px; }
.m33-search-paste-text { width: 100%; box-sizing: border-box; background: var(--m33-bg); color: var(--m33-text); border: 1px solid var(--m33-border); border-radius: 4px; padding: 8px 10px; font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; min-height: 100px; }
.m33-search-paste-go { margin-top: 8px; background: var(--m33-accent); color: white; border: 0; padding: 6px 14px; border-radius: 5px; font-size: 12px; cursor: pointer; }
.m33-search-paste-go:hover:not(:disabled) { background: var(--m33-accent-hover); }
.m33-search-paste-go:disabled { opacity: 0.6; cursor: progress; }
