/* Prima Agent Hub — mission control and agent chat.
   Token values mirror the CRM's src/styles/tokens.css. */

:root {
  --navy-50: #E8EFF7; --navy-100: #D7E2F0; --navy-500: #1B4A86; --navy-600: #14396B;
  --navy-700: #0E2A52; --navy-800: #0A2748; --navy-900: #061A30;
  --gold-100: #FDE9B7; --gold-500: #EFAE2C; --gold-700: #7A5814;
  --gold-bg: #FEF6E3;
  --canvas: #EEF1F6; --hover: #F2F5F9; --separator: #E6EAF0; --separator-soft: #F0F3F7;
  --border-control: #7C899C;
  --text-primary: #0A1628; --text-secondary: #2A3B52; --text-muted: #5B6678; --text-faint: #606C7F;
  --sidebar-muted: #8298B4;
  --danger-bg: #FEE2E2; --danger-text: #B91C1C; --danger-border: #FECACA;
  --success-bg: #BBF7D0; --success-text: #146B34; --success-fg: #16A34A;
  --shadow-card: 0 1px 2px rgba(10, 22, 40, 0.04);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-family: var(--font-sans); font-size: 14px; line-height: 1.55; color: var(--text-primary); background: var(--canvas); }
h1, h2 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.02em; margin: 0; }

#app { display: flex; height: 100dvh; }
#main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; }
.view { flex-grow: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---- Rail ------------------------------------------------------------------ */

#rail { width: 240px; flex-shrink: 0; background: var(--navy-800); display: flex; flex-direction: column; padding: 16px 12px; gap: 18px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; min-height: 44px; text-decoration: none; }
.brand:focus-visible { outline: 2px solid var(--gold-500); outline-offset: 2px; border-radius: 8px; }
.brand-mark { width: 32px; height: 32px; flex-shrink: 0; border-radius: 8px; background: var(--gold-500); display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 700; font-size: 18px; color: var(--text-primary); }
.brand-name { font-family: var(--font-display); font-size: 16px; font-weight: 600; color: #FFFFFF; }

.rail-nav { display: flex; flex-direction: column; gap: 2px; }
.rail-link { position: relative; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 10px; width: 100%; border: 0; border-radius: 7px; background: transparent; color: var(--sidebar-muted); font-family: inherit; font-size: 12.5px; font-weight: 500; text-align: left; text-decoration: none; cursor: pointer; transition: background-color 150ms, color 150ms; }
.rail-link svg { flex-shrink: 0; }
.rail-link:hover:not(:disabled) { background: var(--navy-700); color: var(--navy-100); }
.rail-link:focus-visible { outline: 2px solid var(--gold-500); outline-offset: 2px; }
.rail-link.active { background: var(--navy-600); color: #FFFFFF; }
.rail-link:disabled { opacity: 0.45; cursor: default; }

.rail-section { display: flex; flex-direction: column; gap: 2px; flex-grow: 1; }
.rail-label { padding: 0 10px 4px; font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--sidebar-muted); }
#agent-list { display: flex; flex-direction: column; gap: 2px; }
.agent-item { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 10px; border-radius: 7px; width: 100%; text-decoration: none; background: transparent; color: var(--navy-100); font-size: 12.5px; font-weight: 500; transition: background-color 150ms, color 150ms; }
.agent-item:hover { background: var(--navy-700); }
.agent-item:focus-visible { outline: 2px solid var(--gold-500); outline-offset: 2px; }
.agent-item.active { background: var(--navy-600); color: #FFFFFF; }
.agent-item .name { flex-grow: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-initials { display: none; width: 26px; height: 26px; border-radius: 999px; background: var(--navy-600); color: #FFFFFF; font-size: 10px; font-weight: 600; align-items: center; justify-content: center; }
.rail-badge { flex-shrink: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--gold-500); color: var(--text-primary); font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

.dot { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; }
.dot.online { background: var(--navy-100); }
.dot.running { background: var(--success-fg); }
.dot.waiting_approval { background: var(--gold-500); }
.dot.offline { background: var(--sidebar-muted); }

.rail-user { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 8px; background: var(--navy-700); }
.rail-avatar { width: 30px; height: 30px; flex-shrink: 0; border-radius: 999px; background: var(--navy-500); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: #FFFFFF; }
.rail-user-text { display: flex; flex-direction: column; min-width: 0; }
.rail-user-name { font-size: 12.5px; font-weight: 500; color: #FFFFFF; }
.rail-user-role { font-size: 10px; color: var(--sidebar-muted); }

/* ---- Mission control -------------------------------------------------------- */

#view-overview { overflow-y: auto; padding: 24px 28px calc(24px + env(safe-area-inset-bottom)); gap: 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); }
.live-dot { width: 6px; height: 6px; border-radius: 999px; background: var(--success-fg); }
.live.offline .live-dot { background: var(--gold-500); }
.section-head { font-size: 14px; font-family: var(--font-sans); font-weight: 600; letter-spacing: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; align-items: start; }
.tile { background: #FFFFFF; border: 1px solid var(--separator); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow-card); }
.tile-label { font-size: 11px; font-weight: 500; color: var(--text-muted); }
.tile-value { font-family: var(--font-display); font-size: 28px; font-weight: 600; color: var(--text-primary); }
.tile-sub { font-family: var(--font-sans); font-size: 14px; font-weight: 400; color: var(--text-muted); }
.tile-gold { background: var(--gold-bg); border-color: var(--gold-100); box-shadow: none; }
.tile-gold .tile-label, .tile-gold .tile-value { color: var(--gold-700); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card { background: #FFFFFF; border: 1px solid var(--separator); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow-card); }
.card-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 36px; height: 36px; flex-shrink: 0; border-radius: 999px; background: var(--navy-50); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: var(--navy-600); }
.card-who { display: flex; flex-direction: column; min-width: 0; }
.card-name { font-size: 14px; font-weight: 600; }
.card-harness { font-size: 10px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-activity { font-size: 12.5px; color: var(--text-secondary); flex-grow: 1; }
.card-activity.muted { color: var(--text-muted); }
.card-when { color: var(--text-muted); }
.card-action { justify-content: center; width: 100%; }

.badge { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 10px; font-size: 11px; font-weight: 600; background: var(--canvas); color: var(--text-muted); }
.badge-dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.badge-running { background: var(--success-bg); color: var(--success-text); }
.badge-waiting_approval { background: var(--gold-bg); color: var(--gold-700); }
.badge-online { background: var(--navy-50); color: var(--navy-500); }
.badge-offline { background: var(--canvas); color: var(--text-muted); }

.pill { border-radius: 999px; padding: 2px 10px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill-navy { background: var(--navy-50); color: var(--navy-500); }
.pill-quiet { background: var(--canvas); color: var(--text-muted); font-weight: 500; }
.icon { display: inline-flex; }

.panel { background: #FFFFFF; border: 1px solid var(--separator); border-radius: 12px; box-shadow: var(--shadow-card); display: flex; flex-direction: column; overflow: hidden; }
.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--separator); font-family: var(--font-sans); font-size: 14px; font-weight: 600; letter-spacing: 0; }
.panel-body { display: flex; flex-direction: column; }
.empty { padding: 18px 16px; font-size: 12.5px; color: var(--text-muted); }

.run-row { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--separator-soft); }
.run-row:last-child { border-bottom: 0; }
.run-main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.run-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.run-name { font-size: 12.5px; font-weight: 500; }
.run-meta { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.run-bar { height: 6px; border-radius: 999px; background: var(--canvas); overflow: hidden; }
/* Phase 1 has no task progress to report, so the bar reads "in flight", not a
   percentage it would have to invent. Progress arrives with tasks in Phase 2. */
.run-bar-fill { width: 34%; height: 6px; border-radius: 999px; background: var(--navy-500); animation: run-slide 1.8s ease-in-out infinite; }
@keyframes run-slide { 0% { margin-left: 0; } 50% { margin-left: 66%; } 100% { margin-left: 0; } }
@media (prefers-reduced-motion: reduce) { .run-bar-fill { animation: none; } }

.approval-row { background: var(--gold-bg); align-items: flex-start; }
.approval-icon { color: var(--gold-700); display: flex; flex-shrink: 0; }
.approval-text { flex-grow: 1; min-width: 0; font-size: 12.5px; color: var(--gold-700); }
.approval-agent { font-weight: 600; }
.approval-detail { display: block; margin-top: 4px; font-family: var(--font-mono); font-size: 11px; color: var(--gold-700); opacity: 0.85; word-break: break-word; }
.approval-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.decided { font-size: 11px; font-weight: 600; color: var(--gold-700); white-space: nowrap; }

/* ---- Tasks and schedules ------------------------------------------------------ */

#view-tasks { overflow-y: auto; padding: 24px 28px calc(24px + env(safe-area-inset-bottom)); gap: 18px; }
.head-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--separator); overflow-x: auto; flex-shrink: 0; }
.tab { min-height: 44px; padding: 0 14px; flex-shrink: 0; border: 0; background: transparent; font-family: inherit; font-size: 12.5px; font-weight: 500; color: var(--text-muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; transition: color 150ms, border-color 150ms; }
.tab:hover { color: var(--text-secondary); }
.tab[aria-selected='true'] { color: var(--navy-600); font-weight: 600; border-bottom-color: var(--navy-600); }
.tab:focus-visible { outline: 2px solid var(--navy-500); outline-offset: -2px; }
[role='tabpanel']:focus-visible { outline: 2px solid var(--navy-500); outline-offset: 2px; }

/* The schedules table. Six columns on a laptop; on a phone the same cells stack
   into three lines with their labels turned on, so nothing is lost and nothing
   scrolls sideways. */
.table-head, .srow { display: grid; grid-template-columns: 2.2fr 1.1fr 1.2fr 1.2fr 1.3fr 0.7fr; gap: 12px; align-items: center; }
.table-head { padding: 10px 16px; border-bottom: 1px solid var(--separator); font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.srow { padding: 13px 16px; border-bottom: 1px solid var(--separator-soft); font-size: 12.5px; }
.srow:last-child { border-bottom: 0; }
.srow-main { display: flex; flex-direction: column; min-width: 0; }
.srow-name { font-weight: 500; }
.srow-sub { font-size: 11px; color: var(--text-muted); }
.srow-cell { color: var(--text-secondary); min-width: 0; overflow-wrap: anywhere; }
.srow-result { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.srow-result .srow-sub { line-height: 1.4; }
.srow-toggle { display: flex; justify-content: flex-start; }
.cell-label { display: none; color: var(--text-muted); }
.srow-warn { color: var(--danger-text); }

.switch { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; padding: 0; border: 0; background: transparent; border-radius: 8px; cursor: pointer; }
.switch:focus-visible { outline: 2px solid var(--navy-500); outline-offset: 2px; }
.switch-track { width: 34px; height: 20px; border-radius: 999px; background: var(--navy-600); border: 1px solid var(--navy-600); display: flex; align-items: center; justify-content: flex-end; padding: 1px; transition: background-color 150ms, border-color 150ms; }
.switch-knob { width: 16px; height: 16px; border-radius: 999px; background: #FFFFFF; }
.switch[aria-checked='false'] .switch-track { background: var(--canvas); border-color: var(--border-control); justify-content: flex-start; }
.switch[aria-checked='false'] .switch-knob { width: 14px; height: 14px; background: var(--border-control); }
.switch[disabled] { opacity: 0.6; cursor: default; }

.badge-done { background: var(--success-bg); color: var(--success-text); }
.badge-failed { background: var(--danger-bg); color: var(--danger-text); }
.badge-stopped, .badge-skipped, .badge-queued { background: var(--canvas); color: var(--text-muted); }

.task-actions { display: flex; gap: 8px; flex-shrink: 0; }
/* The artboard draws a 32px icon button; the hub's own rule is a 44px minimum
   hit target, and on a phone a Stop button is not the place to argue. */
.icon-btn { width: 44px; height: 44px; padding: 0; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--separator); border-radius: 7px; background: #FFFFFF; color: var(--text-secondary); cursor: pointer; transition: background-color 150ms; }
.icon-btn:hover:not([disabled]) { background: var(--hover); }
.icon-btn:focus-visible { outline: 2px solid var(--navy-500); outline-offset: 2px; }
.icon-btn[disabled] { opacity: 0.5; cursor: default; }
.icon-btn.danger { border-color: var(--danger-border); background: var(--danger-bg); color: var(--danger-text); }
.icon-btn.danger:hover:not([disabled]) { background: #FCCDCD; }

.hrow { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--separator-soft); font-size: 12.5px; }
.hrow:last-child { border-bottom: 0; }
.hrow-main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.hrow-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hrow-name { font-weight: 500; overflow-wrap: anywhere; }
.hrow-result { font-size: 11px; color: var(--text-muted); overflow-wrap: anywhere; }
.hrow-when { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* New schedule form */
.form-panel { padding: 16px; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field label { font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.optional { font-weight: 400; color: var(--text-muted); }
.field input, .field select, .field textarea { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border-control); border-radius: 8px; font-family: inherit; font-size: 14px; color: var(--text-primary); background: #FFFFFF; }
.field textarea { min-height: 76px; resize: vertical; line-height: 1.5; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { outline: 2px solid var(--navy-500); outline-offset: 1px; }
.hint { margin: 0; font-size: 11px; color: var(--text-muted); }
.hint code { font-family: var(--font-mono); font-size: 11px; color: var(--text-secondary); }
.form-error { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--danger-bg); color: var(--danger-text); font-size: 12.5px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

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

#view-chat { background: var(--canvas); }
#chat-header { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: #FFFFFF; border-bottom: 1px solid var(--separator); }
.back-link { display: none; width: 44px; height: 44px; flex-shrink: 0; align-items: center; justify-content: center; margin-left: -10px; border-radius: 7px; color: var(--text-secondary); }
.back-link:focus-visible { outline: 2px solid var(--navy-500); outline-offset: 2px; }
.chat-avatar { width: 36px; height: 36px; flex-shrink: 0; border-radius: 999px; background: var(--navy-50); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: var(--navy-600); }
.chat-heading { min-width: 0; }
.chat-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#chat-title { font-size: 16px; }
.chat-status { font-size: 11px; color: var(--text-muted); }
.chat-status.running { color: var(--success-text); }
.chat-status.waiting_approval { color: var(--gold-700); }

#messages { flex-grow: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.msg { max-width: 640px; padding: 9px 13px; border-radius: 12px; }
.msg.user { align-self: flex-end; background: var(--navy-600); color: #FFFFFF; border-radius: 12px 12px 4px 12px; }
.msg.agent { align-self: flex-start; background: #FFFFFF; border: 1px solid var(--separator); border-radius: 4px 12px 12px 12px; }
.msg.system { align-self: center; font-size: 11px; color: var(--text-faint); background: transparent; }
.msg.tool { align-self: flex-start; background: var(--navy-900); color: var(--navy-100); font-family: var(--font-mono); font-size: 11px; border-radius: 8px; }
.msg.streaming::after { content: '…'; color: var(--text-faint); }

.approval { align-self: flex-start; max-width: 640px; background: var(--gold-bg); border: 1px solid var(--gold-100); border-radius: 12px; padding: 13px 15px; display: flex; flex-direction: column; gap: 10px; }
.approval-title { font-size: 12.5px; font-weight: 600; color: var(--gold-700); }
.approval-body { font-size: 12.5px; color: var(--gold-700); }

.btn { min-height: 44px; padding: 0 16px; display: inline-flex; align-items: center; gap: 8px; border-radius: 7px; border: 1px solid transparent; background: transparent; font-family: inherit; font-size: 12.5px; font-weight: 500; text-decoration: none; cursor: pointer; transition: background-color 150ms, color 150ms, border-color 150ms; }
.btn:focus-visible { outline: 2px solid var(--navy-500); outline-offset: 2px; }
.btn[disabled] { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--navy-600); border-color: var(--navy-600); color: #FFFFFF; }
.btn-primary:hover:not([disabled]) { background: var(--navy-700); border-color: var(--navy-700); }
.btn-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }
.btn-danger:hover:not([disabled]) { background: #FCCDCD; }
.btn-quiet { background: #FFFFFF; border-color: var(--separator); color: var(--text-secondary); }
.btn-quiet:hover { background: var(--hover); }

#composer { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: #FFFFFF; border-top: 1px solid var(--separator); }
#input { flex-grow: 1; min-width: 0; min-height: 44px; padding: 0 14px; border: 1px solid var(--border-control); border-radius: 8px; font-family: inherit; font-size: 14px; color: var(--text-primary); }
#input:focus-visible { outline: 2px solid var(--navy-500); outline-offset: 1px; }
#send { width: 44px; min-height: 44px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; background: var(--navy-600); border: 0; border-radius: 8px; color: #FFFFFF; cursor: pointer; transition: background-color 150ms; }
#send:hover { background: var(--navy-700); }
#send:focus-visible { outline: 2px solid var(--gold-500); outline-offset: 2px; }

/* ---- Sign in -------------------------------------------------------------------- */

.signin { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); background: var(--navy-800); }
.signin-card { width: 100%; max-width: 380px; background: #FFFFFF; border-radius: 12px; padding: 24px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 10px 30px rgba(6, 26, 48, 0.35); }
.signin-mark { width: 40px; height: 40px; font-size: 22px; }
.signin-card h1 { font-size: 20px; }
.signin-sub { margin: -8px 0 0; font-size: 12.5px; color: var(--text-muted); }
.signin-submit { justify-content: center; }

/* ---- Staff access ----------------------------------------------------------------- */

#view-access, #view-audit { overflow-y: auto; padding: 24px 28px calc(24px + env(safe-area-inset-bottom)); gap: 18px; }
.head-titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.page-sub { margin: 0; font-size: 12.5px; color: var(--text-muted); }
.head-note { margin: 0; font-size: 11px; color: var(--text-muted); }
.head-note code { font-family: var(--font-mono); font-size: 11px; color: var(--text-secondary); }

/* The matrix: staff down the side, agents across the top. --agents is set per
   row from the agent count, so the columns match however many are configured. */
.matrix-head, .mrow { display: grid; grid-template-columns: 2fr 1.2fr repeat(var(--agents, 1), minmax(0, 1fr)); gap: 12px; align-items: center; }
.matrix-head { padding: 10px 16px; border-bottom: 1px solid var(--separator); font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.matrix-head .mcol { text-align: center; overflow: hidden; text-overflow: ellipsis; }
.mrow { padding: 13px 16px; border-bottom: 1px solid var(--separator-soft); font-size: 12.5px; }
.mrow:last-child { border-bottom: 0; }
.mrow-who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mrow-avatar { width: 32px; height: 32px; flex-shrink: 0; border-radius: 999px; background: var(--navy-50); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: var(--navy-600); }
.mrow-names { display: flex; flex-direction: column; min-width: 0; }
.mrow-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow-sub { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcell { display: flex; justify-content: center; align-items: center; }
.mcell .cell-label { display: none; }
.pill-gold { background: var(--gold-bg); color: var(--gold-700); }

.policy-card { gap: 12px; }
.policy-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.policy-name { font-size: 14px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border-radius: 999px; padding: 4px 12px; font-size: 11px; font-weight: 600; }
.chip-allow { background: var(--success-bg); color: var(--success-text); }
.chip-approve { background: var(--gold-bg); color: var(--gold-700); }
.chip-block { background: var(--danger-bg); color: var(--danger-text); }
.policy-foot { font-size: 11px; color: var(--text-muted); }
.cards-wide { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

/* ---- Audit ledger ------------------------------------------------------------------ */

.audit-head, .arow { display: grid; grid-template-columns: 130px 1.1fr 0.9fr 0.9fr 2.2fr; gap: 12px; align-items: baseline; }
.arow { padding: 11px 16px; border-bottom: 1px solid var(--separator-soft); font-size: 12.5px; }
.arow:last-child { border-bottom: 0; }
.arow-when { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.arow-event { font-weight: 500; color: var(--navy-600); overflow-wrap: anywhere; }
.arow-who { color: var(--text-secondary); overflow-wrap: anywhere; }
.arow-agent { min-width: 0; }
.arow-detail { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); overflow-wrap: anywhere; }
.field-inline { flex-direction: row; align-items: center; gap: 8px; }
.field-inline label { white-space: nowrap; }
.field-inline select { width: auto; min-width: 150px; }
/* Full 44px, like every other hit target — signing out is not the place to
   shave one, least of all on a phone. */
.rail-signout { margin-left: auto; flex-shrink: 0; border-color: var(--navy-600); background: var(--navy-600); color: var(--navy-100); }
.rail-signout:hover:not([disabled]) { background: var(--navy-500); }
.rail-signout:focus-visible { outline: 2px solid var(--gold-500); outline-offset: 2px; }

/* ---- Approvals, and the rest of the hub under More ------------------------------ */

#view-approvals, #view-more { overflow-y: auto; padding: 24px 28px calc(24px + env(safe-area-inset-bottom)); gap: 18px; }

.more-me { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--separator); }
.more-link { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 52px; padding: 0 16px; border: 0; border-bottom: 1px solid var(--separator-soft); background: transparent; font-family: inherit; font-size: 14px; font-weight: 500; text-align: left; text-decoration: none; color: var(--text-primary); cursor: pointer; transition: background-color 150ms; }
.more-link:last-child { border-bottom: 0; }
.more-link:hover { background: var(--hover); }
.more-link:focus-visible { outline: 2px solid var(--navy-500); outline-offset: -2px; }
.more-chevron { font-size: 18px; color: var(--text-muted); }
.more-danger { color: var(--danger-text); }

/* ---- The phone's chrome: a top bar and a tab bar ---------------------------------
   Both are off on a laptop, where the rail carries the same sections. There is
   one app, not two — the media query at 700px decides which chrome is on. */

#topbar, #tabbar { display: none; }
#view-chats { display: none; }

.topbar-brand { width: 44px; height: 44px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; margin-left: -6px; border-radius: 8px; text-decoration: none; }
.topbar-brand:focus-visible { outline: 2px solid var(--navy-500); outline-offset: 2px; }
.topbar-title { flex-grow: 1; min-width: 0; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-live { flex-shrink: 0; }
.topbar-me { width: 44px; height: 44px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border-radius: 999px; text-decoration: none; }
.topbar-me:focus-visible { outline: 2px solid var(--navy-500); outline-offset: 2px; }
.topbar-initials { width: 36px; height: 36px; border-radius: 999px; background: var(--navy-500); color: #FFFFFF; display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 600; }

.tab-link { position: relative; flex-grow: 1; flex-basis: 0; min-width: 0; min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border-radius: 8px; color: var(--text-muted); text-decoration: none; transition: color 150ms; }
.tab-link:focus-visible { outline: 2px solid var(--navy-500); outline-offset: -2px; }
.tab-link.active { color: var(--navy-600); }
.tab-text { font-size: 10px; font-weight: 500; }
.tab-link.active .tab-text { font-weight: 600; }
.tab-badge { position: absolute; top: 2px; left: calc(50% + 5px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--gold-500); color: var(--text-primary); font-size: 9px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.tab-badge-quiet { background: var(--navy-500); color: #FFFFFF; }

/* ---- The chats list (the phone's home) ------------------------------------------- */

.chat-list { flex-grow: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; background: #FFFFFF; }
.chat-row { display: flex; align-items: center; gap: 12px; min-height: 72px; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); border-bottom: 1px solid var(--separator-soft); color: var(--text-primary); text-decoration: none; transition: background-color 150ms; }
.chat-row:hover { background: var(--hover); }
.chat-row:focus-visible { outline: 2px solid var(--navy-500); outline-offset: -2px; }
.chat-row-avatar { position: relative; width: 48px; height: 48px; flex-shrink: 0; }
.chat-row-initials { width: 48px; height: 48px; border-radius: 999px; background: var(--navy-50); color: var(--navy-600); display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 600; }
.chat-row.offline .chat-row-initials { background: var(--canvas); color: var(--text-muted); }
/* An agent that is not there has no presence dot at all, rather than a grey one
   that has to be told apart from a blue one at arm's length. */
.chat-row-dot { position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 999px; border: 2px solid #FFFFFF; }
.chat-row-dot.online { background: var(--navy-500); }
.chat-row-dot.running { background: var(--success-fg); }
.chat-row-dot.waiting_approval { background: var(--gold-500); }
.chat-row-body { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-row-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.chat-row-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row-when { flex-shrink: 0; font-size: 11px; color: var(--text-faint); }
.chat-row-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-row-preview { min-width: 0; font-size: 12.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row-preview.muted { color: var(--text-faint); }
.chat-row.unread .chat-row-preview { color: var(--text-primary); font-weight: 500; }
.chat-row-badge { flex-shrink: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--gold-500); color: var(--text-primary); font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.chat-row-pip { flex-shrink: 0; width: 10px; height: 10px; border-radius: 999px; background: var(--navy-500); }
.chat-row-note { font-size: 11px; color: var(--text-muted); }
.chat-row-note.running { color: var(--success-text); }
.chat-row-note.waiting_approval { color: var(--gold-700); }

/* ---- A new build is cached ------------------------------------------------------- */

.update-bar { position: fixed; z-index: 20; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 24px); padding: 8px 8px 8px 16px; border-radius: 999px; background: var(--navy-800); color: #FFFFFF; font-size: 12.5px; box-shadow: 0 10px 30px rgba(6, 26, 48, 0.35); }
.update-text { white-space: nowrap; }
/* Full 44px, like every other hit target — a reload on a phone is a real tap. */
.update-bar .btn { flex-shrink: 0; }

.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ---- Phone (390px is the target width) ----------------------------------------
   The rail goes; a top bar and a bottom tab bar take its place, because a rail
   of icons is a laptop idiom and a thumb reaches the bottom of a phone, not the
   left edge of it. Safe-area insets are honoured on all four sides — the
   viewport is declared viewport-fit=cover, so the tab bar has to clear the home
   indicator itself. */

@media (max-width: 700px) {
  #app { flex-direction: column; }
  #main { min-height: 0; }
  #rail { display: none; }

  #topbar { display: flex; align-items: center; gap: 10px; flex-shrink: 0; padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); background: #FFFFFF; border-bottom: 1px solid var(--separator); }
  #tabbar { display: flex; flex-shrink: 0; padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); background: #FFFFFF; border-top: 1px solid var(--separator); }
  /* A chat is a full-screen view with its own way back, as the artboard has it. */
  #app.in-chat #topbar, #app.in-chat #tabbar { display: none; }
  .update-bar { bottom: calc(84px + env(safe-area-inset-bottom)); }
  #app.in-chat .update-bar { bottom: calc(16px + env(safe-area-inset-bottom)); }

  /* Mission control is the laptop's home; the phone's is the chats list. Same
     route, same payload, same state — only the chrome differs. */
  #view-overview { display: none; }
  #view-chats:not([hidden]) { display: flex; }

  #view-overview { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); gap: 16px; }
  /* The top bar already names the view, so a second heading directly beneath it
     is a duplicate that costs a phone a line. It stays in the document — the
     page still has a proper h1 for anyone reading it with a screen reader. */
  .page-head h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  /* …and a header carrying nothing else should not leave a gap behind it. */
  #view-more .page-head { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .cards { gap: 12px; }
  .run-row { flex-wrap: wrap; gap: 10px; }
  .run-meta { width: 100%; }
  .approval-actions { width: 100%; }
  .approval-actions .btn { flex-grow: 1; justify-content: center; }

  #chat-header { padding: calc(10px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); }
  .back-link { display: flex; }
  #messages { padding: 16px 12px; }
  .msg, .approval { max-width: 88%; }
  /* The artboard's composer: a rounded field and a round send key. */
  #composer { gap: 8px; padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  #input, #send { border-radius: 999px; }

  #view-tasks, #view-access, #view-audit, #view-approvals, #view-more {
    padding: 16px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    gap: 14px;
  }
  /* Connection state is on the top bar on a phone; a second Live pill inside
     each view is the same fact twice. */
  #main .live { display: none; }
  .head-right { width: 100%; }
  .head-right > .btn { flex-grow: 1; justify-content: center; }
  .field-inline { flex-grow: 1; }
  .field-inline select { width: 100%; min-width: 0; }
  .form-actions .btn { flex-grow: 1; justify-content: center; }
  /* The row wraps at this width; Stop belongs at the end of the line it lands
     on, not adrift at the left margin. */
  .task-actions { margin-left: auto; }
}

/* The schedules table stops being a table before the phone breakpoint: six
   columns are unreadable long before 390px. Each row becomes three lines with
   its labels switched on, and the toggle keeps its own column. */
@media (max-width: 900px) {
  .table-head { display: none; }
  /* Two flexible columns of equal footing, so a long "last result" cannot
     squeeze the cadence into a column of single letters. */
  .srow { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px; gap: 8px 10px; padding: 14px 16px; }
  .cell-label { display: inline; }
  .srow-main { grid-column: 1 / 3; grid-row: 1; }
  .srow-toggle { grid-column: 3; grid-row: 1; justify-content: flex-end; }
  .srow-cadence { grid-column: 1; grid-row: 2; }
  .srow-next { grid-column: 2 / 4; grid-row: 2; text-align: right; }
  .srow-agent { grid-column: 1; grid-row: 3; align-self: start; }
  .srow-result { grid-column: 2 / 4; grid-row: 3; align-items: flex-end; text-align: right; }
  .hrow { flex-wrap: wrap; }
  .hrow-when { width: 100%; }

  /* The matrix stops being a matrix: one card per person, with a labelled
     switch per agent underneath. Nothing is lost and nothing scrolls sideways. */
  .matrix-head { display: none; }
  .mrow { display: flex; flex-direction: column; align-items: stretch; gap: 0; padding: 12px 16px 4px; }
  .mrow-role { padding: 8px 0 4px; }
  .mcell { justify-content: space-between; gap: 12px; min-height: 44px; border-top: 1px solid var(--separator-soft); }
  .mcell .cell-label { display: inline; color: var(--text-secondary); }

  /* The ledger reads as three lines: what happened, then who and where, then
     the detail. */
  .audit-head { display: none; }
  .arow { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 12px 16px; }
  .arow-event { grid-column: 1; grid-row: 1; }
  .arow-when { grid-column: 2; grid-row: 1; text-align: right; }
  .arow-who { grid-column: 1; grid-row: 2; font-size: 11px; }
  .arow-agent { grid-column: 2; grid-row: 2; justify-self: end; }
  .arow-detail { grid-column: 1 / 3; grid-row: 3; }
}
