:root { --bg: #0f0f0f; --card: #1a1a1a; --border: #2a2a2a; --text: #e0e0e0; --dim: #888; --accent: #4f9cf7; --green: #4caf50; --yellow: #ffc107; --red: #f44336; --orange: #ff9800; --purple: #ab47bc; }
* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; overflow: hidden; }
body { font-family: -apple-system, system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100%; overflow: hidden; position: fixed; width: 100%; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }

#login { display: flex; align-items: center; justify-content: center; height: 100%; }
#login form { background: var(--card); padding: 32px; border-radius: 12px; width: 300px; }
#login input { width: 100%; padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 16px; margin-bottom: 12px; }
#login button { width: 100%; padding: 12px; background: var(--accent); border: none; border-radius: 8px; color: #fff; font-size: 16px; cursor: pointer; }

.nav { display: flex; gap: 8px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--border); z-index: 10; overflow-x: auto; flex-shrink: 0; }
.nav button { padding: 10px 16px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 14px; cursor: pointer; white-space: nowrap; flex-shrink: 0; min-height: 44px; }
.nav button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (max-width: 600px) {
  .nav { gap: 4px; padding: 8px; overflow: visible; }
  .nav button { padding: 8px; min-height: 40px; font-size: 12px; }
  .nav #provider-select { margin-left: auto !important; width: 76px; min-width: 0; min-height: 40px !important; padding: 6px !important; font-size: 12px !important; }
  .nav #theme-btn { width: 40px; padding: 6px; }
}

.view { display: none; }
.view.active { display: block; overflow-y: auto; animation: viewFadeIn 0.2s ease; }
@keyframes viewFadeIn { from { opacity: 0; } to { opacity: 1; } }

#app { height: 100%; display: flex; flex-direction: column; }
#app > .view { flex: 1; min-height: 0; }
#desktop-wrapper { display: none; height: 100%; }

.filters { display: flex; gap: 6px; padding: 10px 16px; overflow-x: auto; flex-wrap: nowrap; }
.filters button { padding: 10px 14px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; color: var(--dim); font-size: 13px; cursor: pointer; white-space: nowrap; flex-shrink: 0; min-height: 44px; }
.filters button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.attention-summary { display: flex; gap: 6px; padding: 0 16px 2px; overflow-x: auto; }
.attention-summary[hidden] { display: none; }
.attention-item { display: inline-flex; align-items: center; gap: 4px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; color: var(--dim); background: transparent; font: inherit; font-size: 11px; white-space: nowrap; cursor: pointer; }
.attention-item.active { box-shadow: inset 0 0 0 1px currentColor; }
.attention-item.blocked { color: var(--red); border-color: rgba(244,67,54,0.35); background: rgba(244,67,54,0.08); }
.attention-item.review { color: var(--orange); border-color: rgba(255,152,0,0.35); background: rgba(255,152,0,0.08); }
.attention-item.ready { color: var(--accent); border-color: rgba(79,156,247,0.35); background: rgba(79,156,247,0.08); }
.attention-item.running { color: var(--green); border-color: rgba(76,175,80,0.35); background: rgba(76,175,80,0.08); }
.attention-item.queued { color: var(--purple); border-color: rgba(171,71,188,0.35); background: rgba(171,71,188,0.08); }

.job-list { padding: 0 12px 12px; }
@media (min-width: 768px) { .job-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; } .job-list .empty, .job-list .empty-state, .job-list .loading, .job-list .skeleton { grid-column: 1 / -1; } }
@media (min-width: 1200px) { .job-list { grid-template-columns: repeat(3, 1fr); } }
.job-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 6px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 56px; transition: background 0.15s; }
@media (min-width: 768px) { .job-card { margin-bottom: 0; } }
.job-card:active { background: #222; }
.job-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.job-card.is-blocked { border-left: 3px solid var(--orange); }
.job-card.is-running { border-left: 3px solid var(--green); }
.job-card.has-queue:not(.is-running):not(.is-blocked) { border-left: 3px solid var(--purple); }
.job-card.is-stale { border-left: 3px solid var(--yellow); }
.job-card .info { flex: 1; min-width: 0; }
.job-card .info h3 { font-size: 14px; font-weight: 600; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-card .info .meta { font-size: 12px; color: var(--dim); }
.job-card .info .desc { font-size: 12px; color: var(--dim); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badges { display: flex; gap: 4px; flex-shrink: 0; flex-direction: column; align-items: flex-end; }
.badge { font-size: 10px; padding: 3px 8px; border-radius: 6px; font-weight: 600; white-space: nowrap; }
.badge.lead { background: #ffc10720; color: var(--yellow); }
.badge.active { background: #4caf5020; color: var(--green); }
.badge.completed { background: #4f9cf720; color: var(--accent); }
.badge.lost { background: #f4433620; color: var(--red); }
.badge.blocked { background: #f4433620; color: var(--red); }
.badge.review { background: #ff980020; color: var(--orange); }
.badge.working { background: #4caf5020; color: var(--green); font-variant-numeric: tabular-nums; }
.badge.queued { background: #ab47bc20; color: var(--purple); }
.badge.draft { background: #77777725; color: var(--dim); }
.running-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); flex-shrink: 0; animation: pulse 1.5s infinite; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; box-shadow: 0 0 0 3px rgba(79,156,247,0.12); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes thinking { 0% { opacity: 0.3; } 50% { opacity: 1; } 100% { opacity: 0.3; } }
.msg.thinking { animation: thinking 1.5s infinite; color: var(--dim); font-style: italic; }
.pin { font-size: 10px; padding: 3px 8px; border-radius: 6px; font-weight: 600; white-space: nowrap; }
.pin.new { background: #66666630; color: #999; }
.pin.in-progress { background: #4f9cf720; color: var(--accent); }
.pin.blocked { background: #ff980020; color: var(--orange); }
.pin.review { background: #ab47bc20; color: var(--purple); }
.pin.done { background: #4caf5020; color: var(--green); }

#chat-view { display: none; flex-direction: column; height: 100%; }
#chat-view.active { display: flex; animation: viewFadeIn 0.2s ease; }

/* Desktop split-pane layout */
@media (min-width: 1024px) {
  #desktop-wrapper { display: flex; height: 100%; overflow: hidden; }
  #desktop-wrapper #app { width: 360px; min-width: 360px; border-right: 1px solid var(--border); height: 100%; display: flex !important; flex-direction: column; overflow: hidden; }
  #desktop-wrapper #app > .nav { flex-shrink: 0; }
  #desktop-wrapper #app > .view.active { flex: 1; overflow-y: auto; }
  #desktop-wrapper #chat-view { flex: 1; min-width: 0; }
  #desktop-wrapper #chat-view .chat-messages { padding: 16px 10%; }
  #desktop-wrapper #chat-view .msg { max-width: 720px; }
  #desktop-wrapper #chat-view .msg.assistant { max-width: 780px; }
  #desktop-wrapper #chat-view .chat-header { padding: 10px 24px; }
  #desktop-wrapper #chat-view .chat-input { padding: 10px 24px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  #desktop-wrapper #chat-view #ctx-indicator { padding: 4px 24px; }
  #desktop-wrapper .chat-header .back { display: none; }
  #desktop-wrapper .job-card.selected { background: var(--accent); border-color: var(--accent); }
  #desktop-wrapper .job-card.selected .info h3 { color: #fff; }
  #desktop-wrapper .job-card.selected .info .meta,
  #desktop-wrapper .job-card.selected .info .desc { color: rgba(255,255,255,0.7); }
  #desktop-wrapper .job-card.selected .badge,
  #desktop-wrapper .job-card.selected .pin { background: rgba(255,255,255,0.15); color: #fff; }
  #desktop-wrapper #chat-view:not(.active) { display: flex; align-items: center; justify-content: center; color: var(--dim); }
  #desktop-wrapper #chat-view:not(.active)::after { content: 'Select a job to view chat'; font-size: 15px; }
  #desktop-wrapper #chat-view:not(.active) > * { display: none; }
  /* Job list single column in sidebar */
  #desktop-wrapper .job-list { display: block !important; grid-template-columns: unset !important; }
  #desktop-wrapper .job-list .job-card { margin-bottom: 6px; }
  /* Compact nav in sidebar */
  #desktop-wrapper #app .nav { flex-wrap: wrap; padding: 8px 10px; gap: 4px; }
  #desktop-wrapper #app .nav button { padding: 8px 10px; font-size: 12px; min-height: 36px; }
  /* Compact filters */
  #desktop-wrapper #app .filters { padding: 6px 12px; }
  #desktop-wrapper #app .filters button { padding: 6px 10px; font-size: 12px; min-height: 32px; }
}
.chat-header { padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--border); }
.chat-header-top { display: flex; align-items: center; gap: 10px; }
.chat-header .back { background: none; border: none; color: var(--accent); font-size: 24px; cursor: pointer; padding: 0 4px; }
.chat-header .title { flex: 1; min-width: 0; }
.chat-header .title h2 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header .title .sub { font-size: 11px; color: var(--dim); }
.chat-job-stepper { display: flex; gap: 4px; }
.chat-job-stepper button { width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 16px; cursor: pointer; }
.chat-job-stepper button:disabled { opacity: 0.3; cursor: default; }
.chat-actions { display: flex; gap: 6px; padding-top: 8px; flex-wrap: wrap; }
.chat-actions button, .chat-actions select { padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 12px; cursor: pointer; white-space: nowrap; font-family: inherit; min-height: 38px; }
.chat-actions select { appearance: none; padding-right: 6px; font-size: 16px; }

/* Files panel */
.file-browser { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--bg); z-index: 200; display: flex; flex-direction: column; }
.fb-header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--border); }
.fb-header button { background: none; border: none; color: var(--text); cursor: pointer; font-size: 18px; }
.fb-breadcrumb { font-size: 13px; color: var(--dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fb-breadcrumb span { cursor: pointer; color: var(--accent); }
.fb-body { flex: 1; display: flex; overflow: hidden; }
.fb-tree { width: 260px; min-width: 200px; border-right: 1px solid var(--border); overflow-y: auto; padding: 8px 0; background: var(--card); }
.fb-tree-item { display: flex; align-items: center; gap: 6px; padding: 6px 12px; cursor: pointer; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fb-tree-item:hover { background: var(--border); }
.fb-tree-item.active { background: var(--accent); color: #fff; }
.fb-tree-item.dir { font-weight: 600; }
.fb-viewer { flex: 1; overflow: auto; padding: 0; }
.fb-viewer-content { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; line-height: 1.6; padding: 16px; white-space: pre-wrap; word-break: break-all; color: var(--text); min-height: 100%; }
.fb-viewer-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--dim); font-size: 14px; }
.fb-viewer-actions { display: flex; gap: 8px; padding: 8px 16px; background: var(--card); border-top: 1px solid var(--border); font-size: 12px; align-items: center; }
.fb-viewer-actions .fb-meta { color: var(--dim); flex: 1; }
.fb-line-num { display: inline-block; width: 40px; text-align: right; padding-right: 12px; color: var(--dim); user-select: none; }
@media (max-width: 600px) { .fb-tree { width: 100%; } .fb-body { flex-direction: column; } .fb-viewer { border-top: 1px solid var(--border); } }

/* Durable job state */
.state-panel { position: fixed; inset: 0 0 0 auto; width: min(640px, 100%); background: var(--bg); border-left: 1px solid var(--border); z-index: 300; flex-direction: column; box-shadow: -16px 0 40px rgba(0,0,0,0.28); }
.state-header { min-height: 64px; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--border); }
.state-header > div { flex: 1; min-width: 0; }
.state-header h2 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state-sub { color: var(--dim); font-size: 11px; margin-top: 2px; }
.state-header button, .state-edit-actions button { min-height: 38px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); cursor: pointer; }
.state-body { flex: 1; overflow-y: auto; }
.state-section { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.state-section h3 { font-size: 12px; color: var(--dim); text-transform: uppercase; margin-bottom: 12px; }
.state-current { font-size: 13px; line-height: 1.6; }
.state-current code { background: var(--card); border-radius: 4px; padding: 1px 4px; }
.state-current pre { padding: 10px; background: var(--card); border: 1px solid var(--border); border-radius: 6px; overflow: auto; }
.state-turn { font-size: 13px; line-height: 1.5; }
.state-turn p { margin-bottom: 10px; }
.state-stage { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px; margin-bottom: 10px; border: 1px solid rgba(79,156,247,0.35); border-radius: 6px; background: rgba(79,156,247,0.07); }
.state-stage span { color: var(--accent); text-transform: capitalize; }
.state-contract { display: grid; gap: 6px; margin-top: 10px; }
.state-contract > strong { color: var(--dim); font-size: 11px; text-transform: uppercase; }
.state-contract > div { padding: 7px 9px; border-left: 2px solid var(--accent); background: var(--card); }
.state-contract > div > span { display: inline-block; min-width: 38px; margin-right: 6px; color: var(--accent); font-size: 10px; font-weight: 700; }
.state-contract.risks > div { border-left-color: var(--orange); }
.state-list { display: flex; flex-direction: column; gap: 6px; }
.state-alert, .state-deliverable { padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; line-height: 1.4; }
.state-alert { border-color: rgba(255,152,0,0.35); background: rgba(255,152,0,0.07); color: var(--orange); }
.state-deliverable { background: var(--card); }
.state-runs { display: flex; flex-direction: column; gap: 8px; }
.state-run { background: var(--card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.state-run > summary { display: flex; align-items: flex-start; gap: 8px; padding: 11px 12px; cursor: pointer; font-size: 13px; line-height: 1.4; }
.state-run > summary::marker { color: var(--dim); }
.state-run-status { flex-shrink: 0; padding: 2px 6px; border-radius: 4px; background: #7772; color: var(--dim); font-size: 10px; text-transform: uppercase; }
.state-run-status.completed { color: var(--green); background: #4caf5020; }
.state-run-status.needs_review, .state-run-status.error { color: var(--red); background: #f4433620; }
.state-run-status.needs_input, .state-run-status.needs_confirmation, .state-run-status.escalated { color: var(--orange); background: #ff980020; }
.state-run-detail { display: flex; flex-direction: column; gap: 10px; padding: 0 12px 12px; color: var(--text); font-size: 12px; line-height: 1.5; }
.state-run-meta, .state-muted { color: var(--dim); }
.state-loading, .state-empty { padding: 32px 20px; color: var(--dim); font-size: 13px; }
#state-memory-edit { width: 100%; min-height: 320px; padding: 12px; border: 1px solid var(--accent); border-radius: 6px; background: var(--card); color: var(--text); resize: vertical; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.state-edit-actions { display: flex; justify-content: flex-end; padding-top: 10px; }
.state-edit-actions[hidden] { display: none; }
.state-edit-actions button { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (min-width: 1024px) { .chat-job-stepper { display: none; } }
@media (max-width: 600px) { .state-panel { width: 100%; border-left: 0; } .state-section { padding: 15px 16px; } .chat-job-stepper button { width: 34px; } }

.chat-messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; position: relative; scroll-behavior: smooth; overflow-anchor: none; }
.drop-zone { position: absolute; inset: 0; background: rgba(79,156,247,0.15); border: 2px dashed var(--accent); display: flex; align-items: center; justify-content: center; font-size: 18px; color: var(--accent); z-index: 100; pointer-events: none; display: none; }
.drop-zone.visible { display: flex; }
.msg { max-width: 85%; flex-shrink: 0; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.5; word-wrap: break-word; overflow-wrap: break-word; animation: msgIn 0.2s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.msg.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.user.client-fwd { background: #2d5a2d; border: 1px solid #3a7a3a; }
.msg.clamped { position: relative; max-height: 520px; overflow: hidden; padding-bottom: 30px; }
.msg.clamped.expanded { max-height: none; padding-bottom: 30px; }
.msg.clamped::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 56px; background: linear-gradient(transparent, rgba(0,0,0,0.4)); pointer-events: none; }
.msg.clamped.expanded::after { display: none; }
body.light .msg.assistant.clamped::after { background: linear-gradient(transparent, rgba(255,255,255,0.8)); }
body.light .show-more-btn { background: rgba(20,20,20,0.9); color: #fff; }
body.light .show-more-btn:hover { background: #000; }
.show-more-btn { position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%); z-index: 1; background: rgba(255,255,255,0.92); color: #111; border: none; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 3px 12px; cursor: pointer; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,0.3); }
.show-more-btn:hover { background: #fff; }
.msg.assistant { background: var(--card); border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 4px; max-width: 92%; }
.msg.system { background: #1e1e1e; color: var(--dim); align-self: center; font-size: 12px; text-align: center; border-radius: 16px; padding: 6px 14px; }
.msg.assistant p { margin-bottom: 6px; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant code { background: #0a0a0a; padding: 1px 5px; border-radius: 3px; font-size: 12px; font-family: monospace; }
.msg.assistant pre { background: #0a0a0a; padding: 10px; border-radius: 6px; overflow-x: auto; margin: 6px 0; max-width: 100%; -webkit-overflow-scrolling: touch; }
.msg.assistant pre code { background: transparent; padding: 0; white-space: pre; word-break: normal; overflow-wrap: normal; display: block; }
.msg.assistant a { color: var(--accent); }
.reply-block { background: rgba(76,175,80,0.16); border: 1px solid rgba(76,175,80,0.55); border-left: 3px solid var(--green); border-radius: 10px; padding: 11px 13px; margin-top: 8px; font-size: 13.5px; line-height: 1.5; position: relative; white-space: pre-wrap; }
.reply-block, .action-block, .summary-block, .manager-reply-block { animation: fadeIn 0.2s ease-in; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.reply-block .block-label { font-size: 10px; font-weight: 700; color: var(--green); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; user-select: none; -webkit-user-select: none; padding-right: 50px; }
.reply-block .copy-btn { position: absolute; top: 8px; right: 8px; background: var(--green); border: none; border-radius: 5px; color: #fff; font-size: 10px; font-weight: 600; padding: 4px 9px; cursor: pointer; }
.reply-block .copy-btn:hover { filter: brightness(1.1); }
.reply-block.is-sent { opacity: 0.65; }
.reply-block .mark-sent-row { margin-top: 8px; }
.reply-block .mark-sent-btn { background: transparent; border: 1px solid var(--green); border-radius: 5px; color: var(--green); font-size: 11px; font-weight: 600; padding: 4px 10px; cursor: pointer; }
.reply-block .mark-sent-btn:hover { background: var(--green); color: #fff; }
.reply-block .unsend-btn { background: transparent; border: 1px solid #e74c3c; border-radius: 5px; color: #e74c3c; font-size: 11px; font-weight: 600; padding: 4px 10px; cursor: pointer; margin-left: 6px; }
.reply-block .unsend-btn:hover { background: #e74c3c; color: #fff; }
.reply-block .sent-tag { margin-top: 8px; font-size: 11px; font-weight: 600; color: var(--green); }
.summary-block { font-size: 12.5px; line-height: 1.45; color: var(--dim); margin-bottom: 2px; padding: 2px 0 2px 22px; position: relative; }
.summary-block::before { content: '📝'; position: absolute; left: 0; top: 2px; font-size: 13px; }
.manager-reply-block { background: #16162e; border: 1px solid #2a2a4a; border-radius: 10px; padding: 11px 13px; margin-top: 8px; font-size: 13.5px; line-height: 1.5; position: relative; }
.manager-reply-block::before { content: 'For you'; display: block; font-size: 10px; font-weight: 700; color: #8aa0ff; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.manager-reply-block .copy-btn { position: absolute; top: 8px; right: 8px; background: #6b8afd; border: none; border-radius: 5px; color: #fff; font-size: 10px; font-weight: 600; padding: 4px 9px; cursor: pointer; }
.action-block { background: #2a1f3a; border: 1px solid #4a3560; border-radius: 8px; padding: 10px 12px; margin-top: 8px; font-size: 13px; line-height: 1.45; position: relative; white-space: pre-wrap; }
.action-block::before { content: '⚡ Action needed'; display: block; font-size: 10px; font-weight: 600; color: var(--purple); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.chat-input { padding: 8px 12px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); background: var(--card); border-top: 1px solid var(--border); display: flex; gap: 6px; align-items: flex-end; flex-wrap: wrap; }
.chat-input textarea { flex: 1; padding: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 16px; resize: none; min-height: 44px; max-height: 120px; font-family: inherit; line-height: 1.4; min-width: 0; width: 100%; }
.chat-input textarea#manager-note { border-color: #4a3560; background: #1a1225; font-size: 14px; min-height: 36px; }
.chat-input textarea#manager-note::placeholder { color: #8a6ab0; }
.chat-input button { padding: 10px 16px; border: none; border-radius: 8px; color: #fff; font-size: 15px; cursor: pointer; white-space: nowrap; height: 44px; }
.chat-input button:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-input-btns { display: flex; gap: 6px; align-items: center; width: 100%; }
.chat-input-row { display: flex; gap: 6px; align-items: flex-end; width: 100%; }
.chat-input-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.note-toggle { background: #2a1f3a !important; border: 1px solid #4a3560 !important; color: #c4a0ff !important; font-size: 12px !important; padding: 4px 10px !important; height: 44px; border-radius: 8px; }
.note-toggle.active { background: #4a3560 !important; color: #e0c8ff !important; }
.btw-toggle { background: var(--card); border: 1px solid var(--border); color: var(--dim); font-size: 12px; padding: 4px 10px; height: 44px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btw-toggle.active { background: #3a2f1f; border-color: #60502a; color: #ffd98a; }
@media (max-width: 600px) {
  .chat-input { gap: 4px; padding: 6px 8px; padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
  .chat-input textarea { min-width: 0; flex: 1; }
  #chat-mic, #chat-upload { padding: 4px 8px !important; font-size: 16px !important; height: 40px !important; min-width: 40px; }
  #chat-send { padding: 8px 12px; font-size: 14px; height: 40px; }
  #chat-pause, #chat-stop { padding: 8px 10px; font-size: 14px; height: 40px; }
  .source-toggle { font-size: 11px !important; padding: 4px 8px !important; height: 40px !important; }
  .note-toggle { font-size: 11px !important; padding: 4px 8px !important; height: 40px !important; }
  .btw-toggle { font-size: 11px !important; padding: 4px 8px !important; height: 40px !important; }
}
#attachments { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; }
#attachments:empty { display: none; }
.attach-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--border); border-radius: 4px; padding: 2px 8px; font-size: 12px; color: var(--text); transition: background 0.15s; }
.attach-chip button { background: none; border: none; color: var(--red); cursor: pointer; font-size: 14px; padding: 0 2px; height: auto; }
#chat-send { background: var(--accent); }
#chat-pause { background: var(--orange); display: none; }
#chat-stop { background: var(--red); display: none; }
.source-toggle { background: var(--card); border: 1px solid var(--border); border-radius: 8px; font-size: 12px; padding: 4px 10px; cursor: pointer; height: 44px; color: var(--text); white-space: nowrap; }
.source-toggle.manager { background: #2a1f3a; border-color: #4a3560; color: #c4a0ff; }
.source-toggle.client { background: #1b3a1b; border-color: #2d5a2d; color: #7ddf7d; }
.btw-card { background: #16140e; border: 1px dashed #4a3f22; border-radius: 10px; padding: 10px 12px; margin: 8px 0; opacity: 0.85; font-size: 14px; }
.btw-card .btw-q { color: #d8c89a; font-size: 13px; cursor: pointer; list-style: none; }
.btw-card .btw-q::-webkit-details-marker { display: none; }
.btw-card .btw-tag { display: inline-block; font-size: 10px; font-weight: 600; color: #ffd98a; background: #3a2f1f; border-radius: 4px; padding: 1px 6px; margin-right: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.btw-card .btw-a { color: var(--text); line-height: 1.5; margin-top: 8px; }
.btw-card .btw-pending { color: var(--dim); font-style: italic; }
.btw-card .btw-work { margin-top: 8px; }
.btw-card .btw-work summary { cursor: pointer; color: var(--dim); font-size: 12px; }
.btw-card .btw-work pre { margin-top: 6px; font-size: 11px; color: var(--dim); white-space: pre-wrap; max-height: 300px; overflow-y: auto; }
.btw-card .btw-error { color: var(--red); }
.file-path-link { color: var(--accent); cursor: pointer; text-decoration: none; word-break: break-all; }
.file-path-link:hover { text-decoration: underline; }
.msg.user.manager-msg { background: #2a1f3a; border: 1px solid #4a3560; }
.source-label { display: block; font-size: 10px; font-weight: 600; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; user-select: none; -webkit-user-select: none; }
.manager-label { color: #c4a0ff; }
.stage-label { display: inline-block; font-size: 10px; font-weight: 600; margin-bottom: 4px; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.5px; user-select: none; -webkit-user-select: none; background: rgba(100,140,255,0.15); color: #8ab4ff; margin-right: 6px; }

.form-view { padding: 16px; }
.form-view h2 { font-size: 18px; margin-bottom: 16px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--dim); margin-bottom: 4px; }
.field input, .field textarea { width: 100%; padding: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 15px; font-family: inherit; }
.field textarea { min-height: 80px; resize: vertical; }
.form-view button.submit { width: 100%; padding: 12px; background: var(--accent); border: none; border-radius: 8px; color: #fff; font-size: 16px; cursor: pointer; margin-top: 8px; }

.loading { color: var(--dim); font-style: italic; padding: 20px; text-align: center; }
.empty { color: var(--dim); text-align: center; padding: 40px 20px; font-size: 14px; }

/* Skeleton loading */
.skeleton { padding: 12px 14px; margin-bottom: 6px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
.skeleton-line { height: 14px; background: linear-gradient(90deg, var(--border) 25%, #333 50%, var(--border) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 4px; margin-bottom: 8px; }
.skeleton-line:last-child { margin-bottom: 0; }
.skeleton-line.short { width: 60%; }
.skeleton-line.shorter { width: 35%; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
body.light .skeleton-line { background: linear-gradient(90deg, #e0e0e0 25%, #f0f0f0 50%, #e0e0e0 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: var(--dim); }
.empty-state-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state-text { font-size: 15px; margin-bottom: 4px; }
.empty-state-sub { font-size: 13px; opacity: 0.7; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100%); background: var(--card); border: 1px solid var(--border); color: var(--text); padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 1000; opacity: 0; transition: opacity 0.3s ease, transform 0.3s ease; pointer-events: none; max-width: 90%; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { border-color: var(--green); color: var(--green); }
#toast.error { border-color: var(--red); color: var(--red); }
#toast.info { border-color: var(--accent); color: var(--accent); }
@media (min-width: 768px) {
  #toast { left: auto; right: 20px; transform: translateX(0) translateY(100%); }
  #toast.show { transform: translateX(0) translateY(0); }
}
body.light { --bg: #f5f5f5; --card: #ffffff; --border: #e0e0e0; --text: #1a1a1a; --dim: #666; }
body.light .msg.assistant pre, body.light .msg.assistant code { background: #e8e8e8; }
body.light .job-card:active { background: #eee; }
body.light .reply-block { background: #d4edda; border-color: #a3d9a5; color: #1a1a1a; }
body.light .action-block { background: #e8d5f5; border-color: #c9a5e0; color: #1a1a1a; }
body.light .msg.user { background: #3b82f6; }
body.light .msg.user.client-fwd { background: #d4edda; color: #1a1a1a; border-color: #a3d9a5; }
body.light .msg.system { background: #e8e8e8; color: #1a1a1a; }

/* Mobile touch fixes */
input, textarea, select { font-size: 16px; }
#toast { bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
.nav { scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
@media (max-width: 600px) {
  .fb-tree { max-height: 40vh; }
  .fb-viewer { min-height: 40vh; }
}
/* Desktop: wider file browser split */
@media (min-width: 768px) {
  .fb-tree { width: 300px; min-width: 240px; }
  .fb-body { gap: 0; }
}

/* Manager task UI was removed in the QA/comms migration; classes deleted as dead code. */
.file-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--border); border-radius: 6px; padding: 3px 10px; font-size: 12px; cursor: pointer; margin: 2px 4px 2px 0; white-space: nowrap; }
.file-chip:hover { background: var(--accent); color: #fff; }

/* Work toggle (view full process) */
.work-toggle { margin-top: 10px; border-radius: 9px; background: #0d1117; border: 1px solid var(--border); font-size: 12px; overflow: hidden; transition: border-color 0.2s; }
.work-toggle:hover { border-color: #3a3a3a; }
.work-toggle summary { padding: 9px 12px; cursor: pointer; color: var(--dim); list-style: none; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 6px; user-select: none; }
.work-toggle summary::-webkit-details-marker { display: none; }
.work-toggle[open] summary { color: var(--accent); border-bottom: 1px solid var(--border); }
.work-toggle .work-size { font-size: 11px; font-weight: 400; opacity: 0.7; }
.work-content { padding: 4px 12px 8px; max-height: 440px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.proc-stage { border-bottom: 1px solid var(--border); }
.proc-stage:last-child { border-bottom: none; }
.proc-stage > summary.proc-stage-h { font-size: 11px; font-weight: 700; color: var(--accent); padding: 9px 2px; text-transform: uppercase; letter-spacing: 0.5px; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 7px; user-select: none; -webkit-user-select: none; }
.proc-stage > summary.proc-stage-h::-webkit-details-marker { display: none; }
.proc-stage > summary.proc-stage-h::before { content: '▸'; font-size: 9px; opacity: 0.6; transition: transform 0.15s; }
.proc-stage[open] > summary.proc-stage-h::before { transform: rotate(90deg); }
.proc-stage[open] > .proc-feed { padding: 2px 2px 9px; }
.proc-stage-b { color: var(--dim); font-size: 11px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.proc-feed { display: flex; flex-direction: column; gap: 3px; }
.proc-say { font-size: 12.5px; line-height: 1.55; color: var(--text); margin: 6px 0; }
.proc-say:first-child { margin-top: 0; }
.proc-say ul, .proc-say ol { margin: 4px 0; padding-left: 18px; }
.proc-act { display: flex; align-items: flex-start; gap: 8px; padding: 3px 9px; font-size: 11.5px; color: var(--dim); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: rgba(255,255,255,0.03); border-radius: 6px; }
.proc-ico { flex-shrink: 0; }
.proc-lbl { overflow-wrap: anywhere; white-space: pre-wrap; }
body.light .proc-act { background: rgba(0,0,0,0.04); }
body.light .work-toggle { background: #f0f0f0; }
body.light .proc-stage-b { color: #555; }

/* Reconnect banner */
/* Message edit */
.edit-msg-btn { position: absolute; top: 4px; right: 4px; background: none; border: none; cursor: pointer; opacity: 0; font-size: 12px; padding: 2px 4px; border-radius: 4px; transition: opacity 0.15s; }
.msg:hover .edit-msg-btn { opacity: 0.5; }
.msg:hover .edit-msg-btn:hover { opacity: 1; background: rgba(255,255,255,0.05); }
.msg { position: relative; }
.msg.editing { padding: 8px; }
.edit-area { width: 100%; }
.edit-textarea { width: 100%; min-height: 60px; background: var(--bg); border: 1px solid var(--accent); border-radius: 6px; color: var(--text); font-size: 13px; font-family: inherit; padding: 8px; resize: vertical; line-height: 1.5; box-sizing: border-box; }
.edit-delay { margin-top: 6px; font-size: 12px; color: var(--dim); }
.edit-delay input { width: 60px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; color: var(--text); padding: 2px 6px; font-size: 12px; }
.edit-actions { margin-top: 6px; display: flex; gap: 8px; }
.edit-save { background: var(--accent); color: #fff; border: none; border-radius: 6px; padding: 4px 12px; font-size: 12px; cursor: pointer; }
.edit-cancel { background: none; border: 1px solid var(--border); color: var(--dim); border-radius: 6px; padding: 4px 12px; font-size: 12px; cursor: pointer; }
@media (hover: none) { .edit-msg-btn { opacity: 0.4; } }

/* Hold mechanics */
.msg-held { border-left: 3px solid var(--orange); }
.msg-cancelled { opacity: 0.4; border-left: 3px solid var(--red); }
.msg-cancelled .reply-block, .msg-cancelled .manager-reply-block { text-decoration: line-through; }

/* Future-delivery banner (held messages) */
.hold-banner { display: flex; align-items: center; gap: 8px; background: linear-gradient(90deg, rgba(255,152,0,0.14), rgba(255,152,0,0.04)); border: 1px solid rgba(255,152,0,0.45); border-radius: 9px; padding: 8px 10px; margin-bottom: 8px; font-size: 12px; color: var(--orange); }
.hold-banner .hold-ico { font-size: 13px; }
.hold-banner .hold-txt { font-weight: 600; }
.hold-banner .hold-countdown { color: var(--text); opacity: 0.75; font-variant-numeric: tabular-nums; }
.hold-banner .release-btn { margin-left: auto; background: var(--orange); color: #fff; border: none; border-radius: 6px; padding: 5px 11px; font-size: 11px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.hold-banner .release-btn:hover { filter: brightness(1.1); }
.hold-banner.cancelled { background: rgba(244,67,54,0.08); border-color: rgba(244,67,54,0.4); color: var(--red); }
.pause-badge { font-size: 10px; color: var(--orange); margin-bottom: 6px; font-weight: 600; letter-spacing: 0.3px; }

/* Ack messages: light inline note */
.msg-ack { padding: 7px 12px !important; background: transparent !important; border: none !important; border-left: 2px solid var(--accent) !important; border-radius: 0 8px 8px 0 !important; opacity: 0.85; }
.msg-ack .reply-block { background: transparent; border: none; padding: 0; margin: 0; font-size: 13px; }
.msg-ack .reply-block .block-label { display: none; }
.msg-ack .reply-block .copy-btn { display: none; }

/* ── Live pipeline card ── */
.pipeline-card { align-self: stretch; max-width: 100%; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; animation: msgIn .2s ease; }
.pl-steps { display: flex; align-items: center; gap: 8px; }
.pl-step { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--dim); white-space: nowrap; transition: color .3s; }
.pl-dot { width: 9px; height: 9px; border-radius: 50%; background: #3a3a3a; flex-shrink: 0; transition: background .3s; }
.pl-step.active { color: var(--accent); }
.pl-step.active .pl-dot { background: var(--accent); animation: pulse 1.2s infinite; }
.pl-step.done { color: var(--green); }
.pl-step.done .pl-dot { background: var(--green); }
.pl-sep { flex: 1; height: 2px; min-width: 10px; background: #3a3a3a; border-radius: 2px; transition: background .3s; }
.pl-sep.done { background: var(--green); }
.pl-activity { margin-top: 10px; }
.pl-activity > summary { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); cursor: pointer; list-style: none; }
.pl-activity > summary::-webkit-details-marker { display: none; }
.pl-live { color: var(--green); font-size: 9px; animation: pulse 1s infinite; flex-shrink: 0; }
.pl-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pl-log { margin-top: 8px; max-height: 320px; overflow-y: auto; background: #0a0a0a; border-radius: 8px; padding: 4px 10px; -webkit-overflow-scrolling: touch; }
.pl-log:empty { display: none; }
.pl-log .proc-stage { padding: 0; }
body.light .pl-log { background: #f4f4f4; }

/* ── Quiet-window pill ── */
.quiet-pill { align-self: center; display: inline-flex; align-items: center; gap: 10px; background: #1e1a12; border: 1px solid var(--orange); color: var(--orange); font-size: 12px; padding: 6px 14px; border-radius: 18px; animation: msgIn .2s ease; }
.quiet-pill button { background: var(--orange); border: none; border-radius: 12px; color: #fff; font-size: 11px; padding: 4px 10px; cursor: pointer; }
.quiet-pill button:hover { opacity: 0.85; }
.ready-dot { width: 10px; height: 10px; border-radius: 50%; background: #6b8afd; flex-shrink: 0; }

/* ── Responsiveness polish ── */
/* Top progress bar: appears only when a request exceeds 200ms (see _reqStart/_reqEnd) */
.nav-progress { display: none !important; }
.nav-progress.active { display: none !important; }
.nav-progress.done { display: none !important; }

/* Action buttons in flight: immediate feedback + blocks duplicate clicks (pointer-events:none) */
.btn-busy { opacity: 0.55; cursor: progress !important; pointer-events: none; }

/* New job cards fade in without shifting neighbours (keyed reconciliation keeps the rest stable) */
@keyframes jobIn { from { opacity: 0; } to { opacity: 1; } }
.job-card-enter { animation: jobIn 0.18s ease; }

/* Momentum scrolling for job/submitted lists on touch devices */
.view.active, .job-list { -webkit-overflow-scrolling: touch; }
