/* ============================================================================
   App page specific styles (sidebar, chat, onboarding, modals, messages)
   Modern Gemini-inspired aesthetic
   ============================================================================ */

body { display: flex; flex-direction: row; }

/* ===== SIDEBAR ===== */
#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w); max-width: 85vw;
  background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 80;
  transition: transform .25s var(--ease), opacity .25s var(--ease); overflow: hidden;
}
#sidebar.collapsed { transform: translateX(-100%); opacity: 0; pointer-events: none; }
#sidebar-overlay {
  position: fixed; inset: 0; background: var(--overlay-scrim); backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px); z-index: 79;
  transition: opacity .25s var(--ease);
}
#sidebar-overlay.hidden { display: none; }
.sb-header { padding: 14px 12px; border-bottom: 1px solid var(--border); }
.sb-header button { width: 100%; padding: 10px; font-size: 13px; }
.sb-list { flex: 1; overflow-y: auto; padding: 8px; }
.sb-files-bar { padding: 8px; border-top: 1px solid var(--border); }
.sb-files-bar button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 14px; font-size: 13px;
  border-radius: var(--radius-sm); transition: all .2s var(--ease);
}
.sb-footer { padding: 8px; border-top: 1px solid var(--border); }
.sb-section { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 10px 10px 6px; letter-spacing: .5px; font-weight: 500; }
.sb-item {
  padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px;
  display: flex; flex-direction: row; align-items: center; gap: 4px;
  transition: all .2s var(--ease); position: relative; overflow: hidden;
}
.sb-item::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 0; height: 60%; background: var(--accent); border-radius: 0 3px 3px 0;
  transition: width .2s var(--ease);
}
.sb-item:hover { background: var(--panel-2); }
.sb-item:hover::before { width: 3px; }
.sb-item.active { background: var(--accent-bg); }
.sb-item.active::before { width: 3px; }
.sb-item .si-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sb-item .si-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-item .si-topic { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-item .si-meta { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.sb-item .si-delete {
  flex-shrink: 0; width: 26px; height: 26px; border: none; background: transparent;
  color: var(--muted); cursor: pointer; border-radius: var(--radius-pill); font-size: 12px;
  opacity: 0; transition: all .15s var(--ease); padding: 0; display: flex; align-items: center; justify-content: center;
}
.sb-item:hover .si-delete { opacity: 1; }
.sb-item .si-delete:hover { color: var(--red); background: var(--red-bg); transform: scale(1.1); }
.sb-item .si-live { flex-shrink: 0; display: flex; align-items: center; gap: 4px; }
.sb-item .si-live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--green-bright);
  box-shadow: 0 0 6px var(--green-bright-glow); flex-shrink: 0;
}
.sb-item .si-stop {
  flex-shrink: 0; width: 20px; height: 20px; border: none; background: transparent;
  color: var(--muted); cursor: pointer; border-radius: var(--radius-pill); font-size: 12px;
  opacity: 0; transition: all .15s var(--ease); padding: 0; display: flex; align-items: center; justify-content: center;
}
.sb-item:hover .si-stop { opacity: 1; }
.sb-item .si-stop:hover { color: var(--red); background: var(--red-bg); transform: scale(1.1); }
.sb-empty { padding: 24px 12px; color: var(--muted); font-size: 12px; text-align: center; }

/* ===== MAIN AREA ===== */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ===== ONBOARDING ===== */
#onboarding {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 32px; padding: 40px 20px; overflow-y: auto;
}
#onboarding.hidden { display: none; }
.start-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px; width: min(520px, 100%); display: flex; flex-direction: column; gap: 18px;
  box-shadow: var(--shadow-md);
}
.start-card label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.dir-display {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: all .2s var(--ease);
}
.dir-display:hover { border-color: var(--accent); box-shadow: var(--ring); }
.dir-display .icon { font-size: 18px; }
.dir-display .path { flex: 1; font-family: var(--mono); font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dir-display .placeholder { color: var(--muted); }
.start-card .actions { display: flex; gap: 10px; }
.start-card .actions .primary { flex: 1; padding: 12px; font-size: 15px; }
.recent-dirs { display: flex; flex-wrap: wrap; gap: 8px; }
.recent-dirs:empty { display: none; }
.recent-dirs .chip {
  font-family: var(--mono); font-size: 12px; padding: 6px 14px; border-radius: var(--radius-pill);
  background: var(--panel-2); border: 1px solid var(--border); cursor: pointer; color: var(--text-2);
  transition: all .2s var(--ease);
}
.recent-dirs .chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); transform: translateY(-1px); }
.recent-dirs .chip.live {
  border-color: var(--green);
  color: var(--green);
  box-shadow: 0 0 0 1px var(--green) inset;
}
.recent-dirs .chip.live::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  margin-right: 7px;
  vertical-align: middle;
  animation: livePulse 2s var(--ease) infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== CHAT VIEW ===== */
#chat-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#chat-view.hidden { display: none; }

/* reconnect banner */
.reconnect-banner {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 8px 16px; background: var(--yellow-bg); border-bottom: 1px solid var(--yellow);
  font-size: 13px; color: var(--yellow); animation: fadeIn .2s var(--ease);
}
.reconnect-banner.hidden { display: none; }
.reconnect-banner button { padding: 4px 12px; font-size: 12px; border-color: var(--yellow); color: var(--yellow); }
.reconnect-banner button:hover { background: var(--yellow); color: var(--text-on-fill); border-color: var(--yellow); }

.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-blur); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  flex-shrink: 0; z-index: 10;
}
[data-theme="light"] .chat-header { background: var(--panel-blur); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.chat-header .sub { color: var(--muted); font-size: 12px; font-family: var(--mono); margin-left: 4px; }
.chat-header .spacer { flex: 1; }

/* model picker */
.model-picker { position: relative; }
.model-picker-btn {
  display: flex; align-items: center; gap: 6px; padding: 7px 14px; font-size: 12px;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-pill);
  cursor: pointer; color: var(--text-2); white-space: nowrap;
  transition: all .2s var(--ease);
}
.model-picker-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); box-shadow: var(--ring); }
.model-picker-btn .mp-cost { font-size: 10px; color: var(--muted); }

/* model picker modal */
.mp-overlay {
  position: fixed; inset: 0; background: var(--overlay-scrim); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  animation: fadeIn .2s var(--ease);
}
.mp-overlay[hidden] { display: none; }
.mp-modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  width: min(480px, 92vw); max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: modalIn .25s var(--ease-out);
}
.mp-modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 10px; }
.mp-modal-head h2 { font-size: 15px; font-weight: 600; flex: 1; letter-spacing: -0.2px; }
.mpd-search { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.mpd-search input { width: 100%; font-size: 14px; border-radius: var(--radius-sm); }
.mpd-list { flex: 1; overflow-y: auto; padding: 6px; -webkit-overflow-scrolling: touch; }
.mpd-group { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 10px 12px 6px; letter-spacing: .5px; font-weight: 500; }
.mpd-item {
  padding: 12px 14px; cursor: pointer; font-size: 14px; display: flex; flex-direction: column; gap: 4px;
  min-height: 44px; justify-content: center; border-radius: var(--radius-sm);
  transition: all .15s var(--ease);
}
.mpd-item:hover { background: var(--panel-2); }
.mpd-item.selected { background: var(--accent-bg); box-shadow: inset 0 0 0 1px var(--accent); }
.mpd-item .mpd-label { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mpd-item .mpd-check { color: var(--green); font-size: 13px; }
.mpd-item .mpd-cost { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.mpd-item .mpd-tier { font-size: 10px; padding: 2px 8px; border-radius: var(--radius-pill); font-weight: 500; }
.mpd-item .mpd-tier.high { background: var(--red-bg); color: var(--red); }
.mpd-item .mpd-tier.medium { background: var(--yellow-bg); color: var(--yellow); }
.mpd-item .mpd-tier.low { background: var(--green-bg); color: var(--green); }

.chat-header .dir-badge {
  font-family: var(--mono); font-size: 11px; color: var(--text-2); padding: 5px 12px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-pill);
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer; transition: all .2s var(--ease);
}
.chat-header .dir-badge:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.chat-header .icon-header-btn {
  background: transparent; border: none; color: var(--muted); padding: 6px; border-radius: var(--radius-pill);
  display: flex; align-items: center; justify-content: center; transition: all .2s var(--ease);
}
.chat-header .icon-header-btn:hover { background: var(--panel-2); color: var(--text); box-shadow: var(--shadow-sm); }
.chat-header .icon-header-btn svg { width: 18px; height: 18px; }

#messages { flex: 1; overflow-y: auto; padding: 20px 0; scroll-behavior: smooth; }
#messages .inner { max-width: 820px; margin: 0 auto; padding: 0 20px; display: flex; flex-direction: column; gap: 16px; }

/* messages */
.msg-row { display: flex; gap: 12px; }
.msg-row.user { flex-direction: row-reverse; }

/* typing indicator */
.typing-indicator { max-width: 820px; margin: 0 auto; padding: 0 20px; display: flex; gap: 4px; align-items: center; height: 28px; }
.typing-indicator.hidden { display: none; }
.typing-indicator span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: typing-bounce 1.4s infinite ease-in-out; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-6px); opacity: 1; } }
.avatar { width: 30px; height: 30px; border-radius: var(--radius-sm); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; }
.avatar.agent { background: var(--accent-bg); color: var(--accent); }
.avatar.user { background: var(--green-bg); color: var(--green); }
.msg-content { flex: 1; min-width: 0; }
.msg-content .name { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg-bubble {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; word-break: break-word; line-height: 1.6;
  box-shadow: var(--shadow-sm); transition: box-shadow .2s var(--ease);
}
.msg-bubble:hover { box-shadow: var(--shadow-md); }
.msg-row.user .msg-bubble { background: var(--accent-bg); border-color: var(--accent-border); }
[data-theme="light"] .msg-row.user .msg-bubble { border-color: var(--accent-border); }
.msg-bubble p { margin: 0 0 8px; } .msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble code { font-family: var(--mono); font-size: 13px; background: var(--bg-2); padding: 2px 6px; border-radius: 6px; }
.msg-bubble pre { font-family: var(--mono); font-size: 13px; background: var(--bg-2); border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 12px; overflow-x: auto; margin: 8px 0; }
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble pre code.hljs { background: none; padding: 0; }
.msg-bubble .hljs { background: none; }
.msg-bubble ul, .msg-bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { font-size: 15px; font-weight: 600; margin: 8px 0 4px; }
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.msg-bubble a { color: var(--accent); text-decoration: none; } .msg-bubble a:hover { text-decoration: underline; }
.msg-bubble a.file-link { cursor: pointer; }
.msg-bubble a.file-link::before { content: "📄 "; font-size: 0.85em; opacity: 0.8; }

/* tool cards */
.tool-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm); transition: box-shadow .2s var(--ease);
}
.tool-card:hover { box-shadow: var(--shadow-md); }
.tool-card .tc-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; cursor: pointer; user-select: none; transition: background .15s var(--ease); }
.tool-card .tc-head:hover { background: var(--panel-2); }
.tool-card .tc-head .tc-icon { font-size: 14px; flex-shrink: 0; }
.tool-card .tc-head .tc-title { flex: 1; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-card .tc-head .tc-status { font-size: 11px; font-family: var(--mono); text-transform: uppercase; color: var(--muted); }
.tool-card .tc-head .tc-chevron { color: var(--muted); font-size: 12px; transition: transform .2s var(--ease); }
.tool-card.expanded .tc-chevron { transform: rotate(90deg); }
.tool-card .tc-body { display: none; padding: 0 16px 14px; font-family: var(--mono); font-size: 12px; color: var(--text-2); white-space: pre-wrap; word-break: break-word; border-top: 1px solid var(--border-2); max-height: 400px; overflow-y: auto; }
.tool-card.expanded .tc-body { display: block; }
.tool-card .tc-body:empty { display: none; }

/* tool card content elements */
.tc-body .tc-text { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; margin: 4px 0; }
.tc-body .tc-image { max-width: 100%; border-radius: var(--radius-sm); margin: 6px 0; border: 1px solid var(--border); }
.tc-body .tc-resource-link { font-size: 12px; color: var(--accent); margin: 4px 0; }
.tc-body .tc-terminal { font-size: 12px; color: var(--muted); font-style: italic; margin: 4px 0; }
.tc-body .tc-locations { margin-bottom: 6px; }
.tc-body .tc-location { font-size: 11px; color: var(--accent); margin: 2px 0; }
.tc-body .tc-raw { margin: 6px 0; }
.tc-body .tc-raw-label { font-size: 10px; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; letter-spacing: .5px; }
.tc-body .tc-raw pre { font-size: 11px; white-space: pre-wrap; word-break: break-word; }

/* diff viewer */
.tc-diff { margin: 6px 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.tc-diff .diff-path { font-size: 11px; font-weight: 600; padding: 6px 10px; background: var(--panel-2); border-bottom: 1px solid var(--border); color: var(--text); }
.tc-diff .diff-content { font-family: var(--mono); font-size: 11px; line-height: 1.5; overflow-x: auto; padding: 4px 0; white-space: pre; }
.tc-diff .diff-line { display: block; padding: 0 10px; }
.tc-diff .diff-line.add { background: var(--green-bg); color: var(--green); }
.tc-diff .diff-line.del { background: var(--red-bg); color: var(--red); }
.tc-diff .diff-line.ctx { color: var(--muted); }

/* images in messages */
.msg-bubble .msg-image { max-width: 100%; border-radius: var(--radius-sm); margin: 8px 0; border: 1px solid var(--border); }

/* GFM tables in agent messages */
.msg-bubble .table-scroll { overflow-x: auto; margin: 12px 0; -webkit-overflow-scrolling: touch; max-width: 100%; }
.msg-bubble table { border-collapse: collapse; width: 100%; font-size: 13px; display: table; min-width: max-content; }
.msg-bubble table thead { background: var(--panel-2); }
.msg-bubble table th, .msg-bubble table td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; white-space: normal; word-break: break-word; }
.msg-bubble table th { font-weight: 600; color: var(--text); }
.msg-bubble table td { color: var(--text-2); }
.msg-bubble table tbody tr:nth-child(even) { background: var(--panel); }
.msg-bubble table tbody tr:hover { background: var(--panel-2); }

/* unified composer input component */
.composer-input {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  transition: all .2s var(--ease);
}
.composer-input:focus-within { border-color: var(--accent); box-shadow: var(--ring); }

/* image paste preview lives inside the composer input */
.composer .paste-preview { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px 0; }
.composer .paste-preview:empty { display: none; }
.composer .paste-preview:not(:empty) { border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.composer .paste-preview .paste-thumb { position: relative; width: 60px; height: 60px; border-radius: var(--radius-sm); border: 1px solid var(--border); overflow: hidden; }
.composer .paste-preview .paste-thumb img { width: 100%; height: 100%; object-fit: cover; }
.composer .paste-preview .paste-thumb .paste-remove { position: absolute; top: 0; right: 0; background: var(--scrim-btn); color: var(--text-on-fill); border: none; cursor: pointer; font-size: 14px; width: 18px; height: 18px; border-radius: 0 0 0 4px; padding: 0; line-height: 1; }
.composer .paste-preview .vision-warn { width: 100%; font-size: 12px; color: var(--yellow); background: var(--yellow-bg); border: 1px solid var(--yellow); border-radius: var(--radius-sm); padding: 8px 12px; }
.composer-wrap .composer { flex-direction: column; align-items: stretch; }
.composer .composer-row { display: flex; gap: 10px; align-items: center; padding: 4px 8px; }
.composer .composer-text-col { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.composer-input .icon-btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text-2); flex-shrink: 0; border-radius: var(--radius-pill); transition: all .2s var(--ease); }
.composer-input .icon-btn.ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); box-shadow: var(--ring); }
.composer-input .icon-btn.ghost:disabled { opacity: 0.35; cursor: not-allowed; }
.composer-input .icon-btn.ghost svg { width: 18px; height: 18px; }

/* Context meter ring around the Send button. The ring is a conic-gradient
   on .send-ring; a ::before punches out the center to leave a 3px arc. The
   button itself drops its own border so the ring is the only outline. */
.send-ring {
  position: relative; width: 44px; height: 44px; border-radius: var(--radius-pill);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  background: var(--border); /* empty/unknown state = full track */
  transition: background .25s var(--ease);
}
.send-ring::before {
  content: ""; position: absolute; inset: 3px; border-radius: var(--radius-pill);
  background: var(--bg-2); /* match composer-input background to look punched out */
}
.send-ring .icon-btn { position: relative; z-index: 1; }
.send-ring .icon-btn.primary { border-color: transparent; background: transparent; }
.send-ring .icon-btn.primary:hover:not(:disabled) { background: var(--accent); }
.tool-card.pending .tc-status { color: var(--muted); }
.tool-card.in_progress .tc-status { color: var(--yellow); }
.tool-card.completed .tc-status { color: var(--green); }
.tool-card.failed .tc-status, .tool-card.cancelled .tc-status { color: var(--red); }
.tool-card.in_progress { border-left: 3px solid var(--yellow); }
.tool-card.completed { border-left: 3px solid var(--green); }
.tool-card.failed, .tool-card.cancelled { border-left: 3px solid var(--red); }
.tool-card.pending { border-left: 3px solid var(--muted); }

/* plan */
.plan-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.plan-card .pl-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.plan-card .pl-head .icon { font-size: 14px; } .plan-card .pl-head .title { font-size: 13px; font-weight: 600; }
.plan-card ul { list-style: none; padding: 0; }
.plan-card li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.plan-card li .p { font-size: 10px; font-family: var(--mono); padding: 2px 8px; border-radius: var(--radius-pill); text-transform: uppercase; font-weight: 500; }
.plan-card li.high .p { background: var(--red-bg); color: var(--red); }
.plan-card li.medium .p { background: var(--yellow-bg); color: var(--yellow); }
.plan-card li.low .p { background: var(--green-bg); color: var(--green); }
.plan-card li.completed { color: var(--muted); text-decoration: line-through; } .plan-card li.completed .p { opacity: .5; }

/* permission card */
.perm-card { background: var(--panel); border: 1px solid var(--yellow); border-left: 3px solid var(--yellow); border-radius: var(--radius); padding: 16px 18px; margin: 8px 0; box-shadow: var(--shadow-md); }
.perm-card.resolved { opacity: .55; border-color: var(--green); border-left-color: var(--green); }
.perm-card.rejected { opacity: .55; border-color: var(--red); border-left-color: var(--red); }
.perm-card .pm-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.perm-card .pm-head .pm-icon { font-size: 16px; flex-shrink: 0; }
.perm-card .pm-head .pm-title { font-size: 14px; font-weight: 600; color: var(--text); }
.perm-card .pm-kind { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .5px; padding: 3px 10px; border-radius: var(--radius-pill); background: var(--yellow-bg); color: var(--yellow); margin-bottom: 8px; font-weight: 500; }
.perm-card .pm-locations { margin-bottom: 8px; }
.perm-card .pm-location { font-size: 12px; color: var(--accent); font-family: var(--mono); margin: 2px 0; }
.perm-card .pm-content { margin-bottom: 8px; max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; }
.perm-card .pm-raw { margin-bottom: 8px; }
.perm-card .pm-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.perm-card .pm-btn { font-size: 13px; font-weight: 500; padding: 9px 18px; border-radius: var(--radius-pill); border: 1.5px solid var(--border); cursor: pointer; transition: all .25s var(--ease-out); background: transparent; }
.perm-card .pm-btn:disabled { opacity: .5; cursor: not-allowed; }
.perm-card .pm-btn.allow { border-color: var(--green); color: var(--green); }
.perm-card .pm-btn.allow:hover:not(:disabled) { background: var(--green); color: var(--text-on-fill); box-shadow: 0 4px 16px var(--green-glow); transform: translateY(-1px); }
.perm-card .pm-btn.bypass { border-color: var(--border); color: var(--text-2); }
.perm-card .pm-btn.bypass:hover:not(:disabled) { border-color: var(--green); color: var(--green); background: var(--green-bg); }
.perm-card .pm-btn.reject { border-color: var(--red); color: var(--red); }
.perm-card .pm-btn.reject:hover:not(:disabled) { background: var(--red); color: var(--text-on-fill); box-shadow: 0 4px 16px var(--red-glow); transform: translateY(-1px); }

/* system messages */
.sys-msg { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.replay-loader .pill { animation: replay-pulse 1.2s ease-in-out infinite; }
@keyframes replay-pulse { 0%,100% { opacity: .6; } 50% { opacity: 1; } }

/* composer */
.composer-wrap {
  border-top: 1px solid var(--border);
  background: var(--panel-blur); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: 14px 18px; flex-shrink: 0;
}
[data-theme="light"] .composer-wrap { background: var(--panel-blur); }
.composer { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  width: 100%; resize: none; min-height: 44px; max-height: 200px; font-size: 14px; line-height: 1.5;
  padding: 11px 8px; background: transparent; border: none; outline: none; color: var(--text);
}
.composer .btn-col { display: flex; gap: 8px; align-items: center; }
.composer-wrap .hint { max-width: 820px; margin: 8px auto 0; font-size: 11px; color: var(--muted); text-align: center; }

/* Queued-messages tray: shows prompts the user sent while Devin was busy.
   Each chip displays the prompt text (truncated) with a position badge. */
.queued-tray {
  max-width: 820px; margin: 0 auto 8px; display: flex; flex-direction: column; gap: 6px;
}
.queued-tray[hidden] { display: none; }
.queued-tray .queued-label {
  font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px;
}
.queued-tray .queued-label .dot-mini {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}
.queued-chip {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text); overflow: hidden;
  cursor: grab;
}
.queued-chip:active { cursor: grabbing; }
.queued-chip.queued-dragging { opacity: .4; }
.queued-chip.queued-drag-over { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.queued-chip.queued-chip-running { cursor: default; border-color: var(--accent); }
.queued-chip .queued-pos {
  flex-shrink: 0; font-size: 10px; font-weight: 600; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 2px 7px; min-width: 20px; text-align: center;
}
.queued-chip .queued-text {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85;
}
.queued-chip .queued-imgs { flex-shrink: 0; font-size: 11px; color: var(--muted); }
.queued-chip .queued-spinner {
  flex-shrink: 0; width: 14px; height: 14px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: queued-spin 0.8s linear infinite;
}
.queued-chip .queued-cancel {
  flex-shrink: 0; width: 20px; height: 20px; line-height: 1; padding: 0;
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  border-radius: 50%; font-size: 12px; display: flex; align-items: center; justify-content: center;
}
.queued-chip .queued-cancel:hover { background: var(--bg); color: var(--text); }
@keyframes queued-spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* Empty-state: center the composer vertically until the first message is sent.
   Triggered by #chat-view.composer-centered (toggled from app.js based on
   whether #messages-inner contains any .msg-row). */
#chat-view.composer-centered #messages { flex: 0 0 auto; padding: 0; }
#chat-view.composer-centered .composer-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-top: none;
  padding: 24px 18px;
  transition: padding .25s var(--ease), border-top .25s var(--ease);
}
#chat-view.composer-centered .composer-wrap .composer { width: 100%; max-width: 760px; }
#chat-view.composer-centered .composer-wrap .hint { max-width: 760px; }
#chat-view.composer-centered .composer textarea { min-height: 56px; padding: 16px 8px; }
#chat-view.composer-centered .composer .composer-row { justify-content: center; }

/* Greeting shown above the composer only in the empty (centered) state.
   It is absolutely positioned above .composer-text-col so it doesn't push
   the textarea down or affect the button alignment on .composer-row. */
.composer-greeting { display: none; }
#chat-view.composer-centered .composer-greeting {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  margin-bottom: 24px;
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text);
}

/* directory picker modal */
.picker-recents {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-2);
}
.picker-recents:empty { display: none; }
.picker-recents-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  flex-shrink: 0;
  margin-right: 2px;
}
.picker-recent-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 4px 4px 12px;
  border-radius: var(--radius-pill);
  background: var(--panel-2);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-2);
  transition: all .2s var(--ease);
  max-width: 280px;
}
.picker-recent-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}
.picker-recent-chip.live {
  border-color: var(--green);
}
.picker-recent-chip.live .picker-recent-name {
  color: var(--green);
}
.picker-recent-live {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
  animation: livePulse 2s var(--ease) infinite;
}
.picker-recent-chip .picker-recent-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.picker-recent-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.picker-recent-remove:hover {
  background: var(--red);
  color: var(--text-on-fill);
}
.picker-path { display: flex; gap: 8px; padding: 12px 18px; border-bottom: 1px solid var(--border-2); }
.picker-path input { flex: 1; font-family: var(--mono); font-size: 13px; }
.picker-roots { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 18px; border-bottom: 1px solid var(--border-2); }
.picker-roots:empty { display: none; }
.picker-roots .root-chip {
  font-size: 12px; padding: 6px 14px; border-radius: var(--radius-pill);
  background: var(--panel-2); border: 1px solid var(--border); cursor: pointer;
  transition: all .2s var(--ease);
}
.picker-roots .root-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.picker-list { flex: 1; overflow-y: auto; padding: 6px; }
.picker-item {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; font-size: 14px;
  border-radius: var(--radius-sm); transition: all .15s var(--ease);
}
.picker-item:hover { background: var(--panel-2); }
.picker-item.selected { background: var(--accent-bg); box-shadow: inset 0 0 0 1px var(--accent); }
.picker-item .pi-icon { font-size: 16px; }
.picker-item .pi-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-item .pi-type { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); }
.modal-foot .selected { font-size: 12px; color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-foot .spacer { flex: 1; }

/* ===== FILE VIEWER MODAL ===== */
#fv-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; z-index: 200; background: var(--panel); display: flex; flex-direction: column; }
#fv-overlay[hidden] { display: none; }
.fv-modal { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.fv-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); gap: 10px; }
.fv-breadcrumb { flex: 1; font-family: var(--mono); font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fv-head .close-btn {
  background: transparent; border: none; color: var(--muted); font-size: 20px;
  width: 32px; height: 32px; border-radius: var(--radius-pill); cursor: pointer; padding: 0; line-height: 1;
  flex-shrink: 0; transition: all .2s var(--ease); display: flex; align-items: center; justify-content: center;
}
.fv-head .close-btn:hover { background: var(--panel-2); color: var(--text); box-shadow: var(--shadow-sm); }
.fv-tabs { display: flex; align-items: stretch; gap: 2px; padding: 6px 10px; border-bottom: 1px solid var(--border); overflow-x: auto; flex-shrink: 0; background: var(--panel-2); }
.fv-tabs:empty { display: none; }
.fv-tab {
  display: flex; align-items: center; gap: 6px; padding: 7px 8px 7px 14px; cursor: pointer; font-size: 13px;
  color: var(--muted); white-space: nowrap; max-width: 200px; border-radius: var(--radius-pill);
  transition: all .2s var(--ease);
}
.fv-tab:hover { color: var(--text); background: var(--panel); }
.fv-tab.active { color: var(--text); background: var(--accent-bg); box-shadow: inset 0 0 0 1px var(--accent); }
.fv-tab .fv-tab-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fv-tab .fv-tab-close {
  background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 16px;
  line-height: 1; padding: 0; width: 22px; height: 22px; border-radius: var(--radius-pill); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transition: all .15s var(--ease);
}
.fv-tab .fv-tab-close:hover { background: var(--red-bg); color: var(--red); }
.fv-pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.fv-pane.hidden { display: none; }
/* Folder diff pane (shown when the ⇄ toolbar toggle is active). */
.fv-diff-pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.fv-diff-pane.hidden { display: none; }
.fv-diff-subtoolbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border-2); }
.fv-diff-subtoolbar input { flex: 1 1 120px; min-width: 120px; font-family: var(--mono); font-size: 13px; }
.fv-diff-subtoolbar select#fv-diff-base { flex: 1 1 140px; min-width: 140px; }
.fv-diff-subtoolbar input#fv-diff-filter { flex: 1 1 120px; min-width: 120px; }
.fv-diff-subtoolbar button.ghost { flex-shrink: 0; }
.fv-diff-subtoolbar select { flex-shrink: 0; font-size: 13px; }
/* File-viewer tab bodies (File ⇄ Diff toggle in the viewer header). */
.fv-file-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.fv-file-body.hidden { display: none; }
.fv-diff-body.hidden { display: none; }
.fv-view-toggle {
  display: inline-flex; flex-shrink: 0; border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden;
}
.fv-view-toggle-btn {
  padding: 4px 12px; font-size: 12px; font-weight: 500; color: var(--text-2);
  background: transparent; border: none; cursor: pointer; transition: all .15s var(--ease);
}
.fv-view-toggle-btn + .fv-view-toggle-btn { border-left: 1px solid var(--border); }
.fv-view-toggle-btn:hover { color: var(--text); background: var(--panel-2); }
.fv-view-toggle-btn.active { color: var(--accent); background: var(--accent-bg); }
.fv-toolbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border-2); }
.fv-toolbar input { flex: 1 1 120px; min-width: 120px; font-family: var(--mono); font-size: 13px; }
.fv-toolbar button.ghost { flex-shrink: 0; }
.fv-toolbar select { flex-shrink: 0; font-size: 13px; }
.fv-diff-summary {
  display: flex; align-items: center; gap: 12px; padding: 6px 14px;
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  border-bottom: 1px solid var(--border-2); flex-shrink: 0;
}
.fv-diff-summary:empty { display: none; }
.fv-diff-summary code { font-family: var(--mono); color: var(--text-2); background: var(--panel-2); padding: 1px 5px; border-radius: var(--radius-sm); }
.fv-diff-sum-add { color: var(--green); }
.fv-diff-sum-del { color: var(--red); }
.fv-diff-sum-mode { color: var(--text-2); text-transform: capitalize; }
.fv-diff-tree { flex: 1; overflow-y: auto; padding: 6px 4px; min-height: 0; }
.fv-diff-empty { padding: 24px 14px; color: var(--muted); font-size: 13px; text-align: center; }
.fv-diff-row {
  display: flex; align-items: center; gap: 8px; padding: 5px 8px; cursor: pointer;
  font-size: 13px; border-radius: var(--radius-sm); transition: background .12s var(--ease);
  font-family: var(--mono);
}
.fv-diff-row:hover { background: var(--panel-2); }
.fv-diff-icon { font-size: 13px; flex-shrink: 0; width: 16px; text-align: center; color: var(--text-2); }
.fv-diff-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.fv-diff-folder > .fv-diff-name { font-weight: 500; }
.fv-diff-badge {
  flex-shrink: 0; font-size: 11px; display: inline-flex; align-items: center; gap: 6px;
  padding: 1px 7px; border-radius: var(--radius-pill); white-space: nowrap;
  background: var(--panel-2);
}
.fv-diff-add { color: var(--green); font-weight: 600; }
.fv-diff-del { color: var(--red); font-weight: 600; }
.fv-diff-files { color: var(--muted); }
.fv-diff-children { display: block; }
.fv-diff-children[hidden] { display: none; }
.fv-diff-pre {
  flex: 1; overflow: auto; margin: 0; padding: 12px 16px; font-size: 12.5px; line-height: 1.55;
  font-family: var(--mono); min-height: 0; white-space: pre; color: var(--text-2);
}
.fv-diff-line { display: block; }
.fv-diff-line-add { color: var(--green); background: var(--green-bg); }
.fv-diff-line-del { color: var(--red); background: var(--red-bg); }
.fv-diff-line-hunk { color: var(--accent); }
.fv-diff-line-meta { color: var(--muted); font-weight: 600; }
.fv-list { flex: 1; overflow-y: auto; padding: 6px; min-height: 0; }
.fv-list.hidden { display: none; }
.fv-list:empty { display: none; }
.fv-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px; cursor: pointer; font-size: 14px;
  border-radius: var(--radius-sm); transition: all .15s var(--ease);
}
.fv-item:hover { background: var(--panel-2); }
.fv-item .fv-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.fv-item .fv-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fv-item .fv-size { font-size: 11px; color: var(--muted); font-family: var(--mono); flex-shrink: 0; }
.fv-delete-btn {
  flex-shrink: 0; width: 26px; height: 26px; padding: 0; border: none; background: transparent;
  color: var(--muted); font-size: 14px; cursor: pointer; border-radius: var(--radius-sm);
  opacity: 0; transition: all .15s var(--ease); display: flex; align-items: center; justify-content: center;
}
.fv-item:hover .fv-delete-btn { opacity: 1; }
.fv-delete-btn:hover { background: var(--red-bg); color: var(--red); }
@media (hover: none) { .fv-delete-btn { opacity: 1; } }

/* Context menu (right-click / long-press) for file-viewer items. */
.fv-menu {
  position: fixed; z-index: 600; min-width: 180px; max-width: 240px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 6px; display: flex; flex-direction: column; gap: 2px;
  animation: modalIn .15s var(--ease-out);
}
.fv-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px;
  border: none; background: transparent; color: var(--text); cursor: pointer;
  font-size: 13px; text-align: left; border-radius: var(--radius-sm);
  transition: all .12s var(--ease);
}
.fv-menu-item:hover { background: var(--panel-2); }
.fv-menu-item.fv-menu-destructive { color: var(--red); }
.fv-menu-item.fv-menu-destructive:hover { background: var(--red-bg); }
.fv-menu-icon { font-size: 14px; flex-shrink: 0; width: 18px; text-align: center; }
.fv-menu-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Multi-select mode for the Files tab. */
.fv-list-selecting .fv-delete-btn { display: none; }
.fv-list-selecting .fv-item { cursor: default; }
.fv-list-selecting .fv-item:hover { background: transparent; }
.fv-check {
  flex-shrink: 0; width: 18px; height: 18px; margin-right: 2px;
  border: 1.5px solid var(--border); border-radius: 4px;
  display: none; align-items: center; justify-content: center;
  font-size: 12px; color: var(--accent);
}
.fv-list-selecting .fv-check { display: flex; }
.fv-item-selected { background: var(--accent-bg); }
.fv-item-selected .fv-check { background: var(--accent); color: var(--text-on-fill); border-color: var(--accent); }
.fv-item-selected .fv-check::after { content: "✓"; }

/* Bottom action bar shown in select mode. */
.fv-actionbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--panel); border-top: 1px solid var(--border);
  position: sticky; bottom: 0; z-index: 5; flex-wrap: wrap;
}
.fv-actionbar-count { margin-left: auto; font-size: 12px; color: var(--muted); }
.fv-actionbar button {
  display: flex; align-items: center; gap: 6px; padding: 7px 10px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  border-radius: var(--radius-sm); font-size: 13px; cursor: pointer;
}
.fv-actionbar button:disabled { opacity: .4; cursor: not-allowed; }
.fv-actionbar button.fv-actionbar-danger { color: var(--red); border-color: var(--red); }

/* Sort control in the Files-tab toolbar. */
.fv-sort { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.fv-sort select, .fv-sort button {
  font-size: 12px; padding: 4px 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); border-radius: var(--radius-sm);
}

/* Mobile: action bar buttons collapse to icons, count wraps to its own row. */
@media (max-width: 600px) {
  .fv-actionbar { gap: 6px; padding: 6px 8px; }
  .fv-actionbar button .fv-actionbar-label { display: none; }
  .fv-actionbar-count { width: 100%; order: -1; margin: 0 0 4px; text-align: center; }
}

/* Upload progress overlay. */
.fv-upload-overlay {
  position: fixed; inset: 0; background: var(--overlay-scrim); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center;
  z-index: 600; animation: fadeIn .2s var(--ease);
}
.fv-upload-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px 24px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow-lg); animation: modalIn .25s var(--ease-out);
}
.fv-upload-title { font-size: 14px; font-weight: 600; color: var(--text); }
.fv-upload-bar { height: 6px; background: var(--bg-2); border-radius: var(--radius-pill); overflow: hidden; }
.fv-upload-fill { height: 100%; width: 0; background: var(--accent); border-radius: var(--radius-pill); transition: width .2s var(--ease); }
.fv-upload-status { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.fv-viewer-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border-2); font-size: 13px; flex-wrap: wrap; }
.fv-viewer-head .fv-head-info { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.fv-viewer-head .fv-filename { font-weight: 600; color: var(--text); flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.fv-viewer-head .fv-name-input {
  font-weight: 600; color: var(--text); font-size: 13px; font-family: var(--mono);
  padding: 4px 8px; border: 1px solid var(--accent); border-radius: var(--radius-sm);
  background: var(--bg); min-width: 0; flex: 1 1 140px; max-width: 320px; outline: none;
}
.fv-viewer-head .fv-name-input:focus { box-shadow: var(--ring); }
.fv-viewer-head .fv-meta { color: var(--muted); font-family: var(--mono); font-size: 11px; flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.fv-viewer-head .fv-actions { display: flex; gap: 6px; flex-shrink: 0; }
.fv-action-btn {
  font-size: 12px; font-weight: 500; padding: 5px 14px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: transparent; color: var(--text-2); cursor: pointer;
  transition: all .15s var(--ease);
}
.fv-action-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.fv-action-btn.fv-save-btn { border-color: var(--accent); color: var(--accent); }
.fv-action-btn.fv-save-btn:hover:not(:disabled) { background: var(--accent); color: var(--text-on-fill); }
.fv-action-btn.fv-cancel-btn:hover:not(:disabled) { border-color: var(--red); color: var(--red); background: var(--red-bg); }
.fv-action-btn:disabled { opacity: .5; cursor: default; }
.fv-refresh-btn { font-size: 14px; line-height: 1; padding: 5px 9px; }
.fv-tab.fv-tab-stale .fv-tab-label::after {
  content: " ●"; color: var(--accent); font-size: 8px; vertical-align: top; margin-left: 2px;
}
.fv-pane .fv-editor {
  flex: 1; overflow: auto; margin: 0; padding: 14px 18px; font-size: 13px; line-height: 1.6;
  font-family: var(--mono); min-height: 0; resize: none; border: none; outline: none;
  background: var(--bg); color: var(--text); tab-size: 2;
}
.fv-pane pre { flex: 1; overflow: auto; margin: 0; padding: 14px 18px; font-size: 13px; line-height: 1.6; font-family: var(--mono); min-height: 0; }
.fv-pane pre code.hljs { background: var(--bg); padding: 0; border-radius: 0; }
.fv-markdown { flex: 1; overflow: auto; padding: 18px 24px; font-size: 14px; line-height: 1.7; color: var(--text); }
.fv-markdown h1, .fv-markdown h2, .fv-markdown h3, .fv-markdown h4 { margin: 20px 0 10px; font-weight: 600; line-height: 1.3; }
.fv-markdown h1 { font-size: 22px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.fv-markdown h2 { font-size: 18px; }
.fv-markdown h3 { font-size: 16px; }
.fv-markdown p { margin: 10px 0; }
.fv-markdown ul, .fv-markdown ol { margin: 10px 0; padding-left: 24px; }
.fv-markdown li { margin: 4px 0; }
.fv-markdown a { color: var(--accent); text-decoration: none; }
.fv-markdown a:hover { text-decoration: underline; }
.fv-markdown blockquote { margin: 10px 0; padding: 10px 16px; border-left: 3px solid var(--border); color: var(--text-2); background: var(--panel-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.fv-markdown code { font-family: var(--mono); font-size: 13px; background: var(--panel-2); padding: 2px 6px; border-radius: 6px; }
.fv-markdown pre { margin: 12px 0; padding: 14px 16px; background: var(--bg); border-radius: var(--radius-sm); overflow-x: auto; }
.fv-markdown pre code { background: none; padding: 0; }
.fv-markdown table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13px; }
.fv-markdown table th, .fv-markdown table td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.fv-markdown table th { background: var(--panel-2); font-weight: 600; }
.fv-markdown hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.fv-markdown img { max-width: 100%; border-radius: var(--radius); }
.fv-truncated { padding: 10px 18px; background: var(--yellow-bg); color: var(--yellow); font-size: 12px; text-align: center; border-top: 1px solid var(--border); }
.fv-pdf { flex: 1; border: none; margin: 0; min-height: 0; background: var(--bg); }
.fv-html { flex: 1; border: none; margin: 0; min-height: 0; background: #fff; /* intentionally white — HTML content rendered in iframe, not UI chrome */ }
.fv-docx { flex: 1; overflow: auto; padding: 18px 24px; font-size: 14px; line-height: 1.7; color: var(--text); }
.fv-docx h1, .fv-docx h2, .fv-docx h3, .fv-docx h4 { margin: 20px 0 10px; font-weight: 600; line-height: 1.3; }
.fv-docx h1 { font-size: 22px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.fv-docx h2 { font-size: 18px; }
.fv-docx h3 { font-size: 16px; }
.fv-docx p { margin: 10px 0; }
.fv-docx ul, .fv-docx ol { margin: 10px 0; padding-left: 24px; }
.fv-docx li { margin: 4px 0; }
.fv-docx a { color: var(--accent); text-decoration: none; }
.fv-docx a:hover { text-decoration: underline; }
.fv-docx table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13px; }
.fv-docx table th, .fv-docx table td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.fv-docx table th { background: var(--panel-2); font-weight: 600; }
.fv-docx img { max-width: 100%; border-radius: var(--radius); }
.fv-error { flex: 1; overflow: auto; padding: 18px 24px; font-size: 14px; color: var(--red); font-family: var(--mono); }
.fv-sheet { flex: 1; overflow: auto; padding: 14px 18px; font-size: 13px; line-height: 1.5; color: var(--text); }
.fv-sheet-info { color: var(--muted); font-family: var(--mono); font-size: 11px; margin-bottom: 8px; }
.fv-sheet-title { font-weight: 600; font-size: 15px; margin: 4px 0 8px; color: var(--text); }
.fv-sheet-sep { height: 1px; background: var(--border); margin: 20px 0; }
.fv-sheet table { border-collapse: collapse; width: 100%; font-size: 13px; }
.fv-sheet table th, .fv-sheet table td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; white-space: nowrap; max-width: 400px; overflow: hidden; text-overflow: ellipsis; }
.fv-sheet table th { background: var(--panel-2); font-weight: 600; position: sticky; top: 0; z-index: 1; }
.fv-sheet table td:hover { white-space: normal; overflow: visible; text-overflow: clip; }

/* ===== CUSTOM PROMPT DIALOG ===== */
.cp-overlay {
  position: fixed; inset: 0; background: var(--overlay-scrim); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; z-index: 500;
  animation: fadeIn .2s var(--ease);
}
.cp-modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  width: min(420px, 92vw); display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: modalIn .25s var(--ease-out);
}
.cp-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 10px; }
.cp-head h2 { font-size: 15px; font-weight: 600; flex: 1; letter-spacing: -0.2px; }
.cp-close {
  background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 22px;
  line-height: 1; padding: 0; width: 28px; height: 28px; border-radius: var(--radius-pill);
  display: flex; align-items: center; justify-content: center; transition: all .15s var(--ease);
}
.cp-close:hover { background: var(--red-bg); color: var(--red); }
.cp-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.cp-label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.cp-input {
  width: 100%; font-size: 14px; font-family: var(--mono); padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-2);
  color: var(--text); outline: none; transition: all .15s var(--ease);
}
.cp-input:focus { border-color: var(--accent); box-shadow: var(--ring); }
.cp-error { font-size: 12px; color: var(--red); background: var(--red-bg); padding: 6px 10px; border-radius: var(--radius-sm); }
.cp-message { font-size: 13px; color: var(--text-2); line-height: 1.5; }
/* Segmented toggle (File ⇄ Folder) inside the New dialog. */
.cp-segmented {
  display: flex; gap: 0; border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--bg-2);
}
.cp-seg-btn {
  flex: 1; padding: 8px 12px; font-size: 13px; font-weight: 500; color: var(--text-2);
  background: transparent; border: none; cursor: pointer; transition: all .15s var(--ease);
}
.cp-seg-btn + .cp-seg-btn { border-left: 1px solid var(--border); }
.cp-seg-btn:hover { color: var(--text); background: var(--panel-2); }
.cp-seg-btn.active { color: var(--accent); background: var(--accent-bg); }
.cp-actions { display: flex; gap: 10px; padding: 12px 20px 16px; justify-content: flex-end; }
.cp-btn {
  font-size: 13px; font-weight: 500; padding: 9px 20px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: transparent; color: var(--text-2); cursor: pointer;
  transition: all .15s var(--ease);
}
.cp-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.cp-btn.cp-ok { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.cp-btn.cp-ok:hover { background: var(--accent); color: var(--text-on-fill); }
.cp-btn.cp-ok.cp-destructive { border-color: var(--red); color: var(--red); background: var(--red-bg); }
.cp-btn.cp-ok.cp-destructive:hover { background: var(--red); color: var(--text-on-fill); }

/* mobile */
@media (max-width: 600px) {
  .mp-overlay { align-items: flex-start; padding-top: env(safe-area-inset-top, 0); }
  .mp-modal { width: 100vw; max-height: 100vh; border-radius: 0; border: none; }
  .cp-overlay { align-items: flex-end; }
  .cp-modal { width: 100vw; border-radius: 16px 16px 0 0; border: none; border-bottom: none; }
  .fv-toolbar { gap: 6px; padding: 8px 10px; }
  .fv-toolbar #fv-new-file { flex: 1 1 100%; }
  .fv-toolbar #fv-upload { flex: 1 1 100%; }
  .fv-viewer-head { padding: 8px 12px; gap: 8px; }
  .chat-header .sub { display: none; }
  .chat-header .dir-badge { max-width: 120px; }
  /* Match the dir-badge mobile width constraint. Height already matches
     the model-picker-btn (7px padding, 12px font) so no override needed. */
  .mode-badge { max-width: 120px; }
  .model-picker-btn span#mp-current { max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .composer textarea { max-height: 160px; }
  #messages .inner { padding: 0 12px; }
  .composer-wrap { padding: 10px 12px; }
  /* Centered empty-state on mobile: keep the composer compact and make
     sure the attach/send/stop buttons stay vertically centered with the
     textbox rather than stretched edge-to-edge. */
  #chat-view.composer-centered .composer-wrap { padding: 16px 12px; }
  #chat-view.composer-centered .composer-wrap .composer { max-width: 100%; }
  #chat-view.composer-centered .composer textarea { min-height: 48px; }
  #chat-view.composer-centered .composer-greeting { font-size: 18px; margin-bottom: 18px; }
}

/* ============================================================================
   Shells sidebar button + badge
   ============================================================================ */
.sb-files-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.sb-files-bar button.ghost {
  flex: 1 1 calc(50% - 2px);
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  font-size: 12px;
  padding: 6px 8px;
  position: relative;
}
.sb-badge {
  background: var(--accent);
  color: var(--text-on-fill);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.sb-badge.hidden { display: none; }

/* ============================================================================
   Stats modal — full screen performance dashboard
   ============================================================================ */
#stats-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
}
#stats-overlay.hidden { display: none; }
#stats-modal {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: auto;
}
.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}
.stats-title {
  font-size: 14px;
  font-weight: 600;
}
#stats-content {
  flex: 1;
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  align-content: start;
}
.stats-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.stats-card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 12px;
}
.stats-big-num {
  font-size: 36px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.stats-big-unit {
  font-size: 16px;
  color: var(--muted);
  font-weight: 400;
}
.stats-bar-large {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin: 12px 0 8px;
}
.stats-bar-large .sb-stats-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease, background 0.5s ease;
}
.stats-detail {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}
.stats-detail span {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.sb-stats-fill.low { background: var(--green); }
.sb-stats-fill.mid { background: var(--yellow); }
.sb-stats-fill.high { background: var(--red); }

/* Process table in stats modal */
.stats-card-wide {
  grid-column: 1 / -1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.stats-proc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 600px;
}
.stats-proc-table th {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
  background: var(--panel);
}
.stats-proc-table th.th-sortable {
  cursor: pointer;
  user-select: none;
}
.stats-proc-table th.th-sortable:hover {
  color: var(--text);
  background: var(--text-faint-1);
}
.stats-proc-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--text-faint-1);
}
.stats-proc-table .proc-bar-cell {
  position: relative;
  min-width: 80px;
  background-clip: padding-box;
}
.proc-bar-val {
  position: relative;
  z-index: 1;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.stats-proc-table tr:hover td {
  background: var(--text-faint-2);
}
.stats-proc-table .proc-cmd {
  max-width: 500px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 11px;
}
.proc-kill-cell { text-align: center; width: 32px; }
.proc-kill-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}
.proc-kill-btn:hover {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-bg);
}
.proc-kill-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.proc-kill-btn.killed {
  color: var(--green);
  border-color: var(--green);
}

/* ============================================================================
   Live Sessions modal
   ============================================================================ */
#sessions-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-scrim-strong);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
#sessions-overlay.hidden { display: none; }
#sessions-modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sessions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sessions-title {
  font-size: 14px;
  font-weight: 600;
}
#sessions-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.sessions-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.session-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  transition: background 0.15s;
}
.session-row:hover {
  background: var(--text-faint-2);
}
.session-row-info {
  flex: 1;
  min-width: 0;
}
.session-row-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-row-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}
.session-row-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green-bright);
  box-shadow: 0 0 6px var(--green-bright-glow);
  flex-shrink: 0;
}
.session-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.session-row-actions button {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}
.session-row-actions button:hover {
  background: var(--text-faint-3);
}
.session-row-actions button.danger:hover {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-bg);
}
.session-row-actions button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ============================================================================
   Terminal modal
   ============================================================================ */
#terminal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
}
#terminal-overlay.hidden { display: none; }
#terminal-modal {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.terminal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}
.terminal-tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  flex: 1;
}
.terminal-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
}
.terminal-tab:hover { background: var(--border); }
.terminal-tab.active {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}
.terminal-tab .term-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.terminal-tab .term-dot.dead { background: var(--red); }
.terminal-tab .term-close {
  margin-left: 4px;
  opacity: 0.5;
  font-size: 14px;
  line-height: 1;
}
.terminal-tab .term-close:hover { opacity: 1; color: var(--red); }
.terminal-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.terminal-actions button.small {
  padding: 3px 8px;
  font-size: 12px;
}
#terminal-container {
  flex: 1;
  position: relative;
  background: var(--bg);
  overflow: hidden;
  /* We implement custom touch scrolling below, so disable the browser's
     default touch actions (which otherwise conflict with xterm.js). */
  touch-action: none;
  overscroll-behavior: contain;
}
#terminal-container .xterm {
  padding: 8px;
  height: 100%;
  /* Prevent the xterm viewport from triggering layout on scroll */
  contain: layout style;
}
.terminal-pane {
  position: absolute;
  inset: 0;
  display: none;
}
.terminal-pane.active {
  display: block;
}
.terminal-pane.empty-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
}

/* ===== SLASH COMMAND PICKER ===== */
.cmd-overlay {
  position: fixed;
  z-index: 90;
  display: block;
}
.cmd-overlay.hidden { display: none; }
.cmd-popover {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(440px, 92vw);
  max-height: 360px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn .18s var(--ease-out);
  overflow: hidden;
}
.cmd-search {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.cmd-prefix {
  color: var(--muted);
  font-size: 15px;
  font-family: var(--mono);
  flex-shrink: 0;
}
.cmd-search input {
  flex: 1;
  font-size: 14px;
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
}
.cmd-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
  -webkit-overflow-scrolling: touch;
}
.cmd-empty {
  padding: 16px 14px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.cmd-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 40px;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background .12s var(--ease);
}
.cmd-item:hover, .cmd-item.selected {
  background: var(--panel-2);
}
.cmd-item.selected {
  box-shadow: inset 0 0 0 1px var(--accent);
}
.cmd-item .cmd-name {
  font-weight: 500;
  font-family: var(--mono);
  color: var(--text);
}
.cmd-item .cmd-name .cmd-slash {
  color: var(--muted);
}
.cmd-item .cmd-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
}
.cmd-item .cmd-hint {
  font-size: 11px;
  color: var(--accent);
  font-style: italic;
}

/* ===== @-MENTION FILE PICKER ===== */
/* Reuses .cmd-overlay / .cmd-popover / .cmd-list / .cmd-item / .cmd-empty
   from the slash-command picker. Only the query display + file row bits
   need their own styles. */
.fm-query {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  font-family: var(--mono);
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fm-query:empty::before {
  content: "search files…";
  color: var(--muted);
  font-family: inherit;
}
.fm-item .fm-name {
  display: flex;
  align-items: center;
  gap: 6px;
}
.fm-item .fm-icon {
  flex-shrink: 0;
  font-size: 13px;
  color: var(--muted);
}
.fm-item .fm-rel {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== MODE BADGE ===== */
/* Styled to match the .dir-badge pill — same height, font, padding.
   The traffic-light status color is reflected via the border color
   (set by updateModeIndicator adding a status class). */
.mode-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  color: var(--text-2);
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  background: var(--panel-2);
  border: 1px solid var(--border);
  white-space: nowrap;
  text-align: center;
  cursor: pointer;
  transition: all .2s var(--ease);
  width: fit-content;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.mode-badge:hover, .mode-badge:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-bg);
  box-shadow: var(--ring);
  outline: none;
}
.mode-badge.hidden { display: none; }
.mode-badge.mode-bypass, .mode-badge.mode-dangerous {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-bg);
}
.mode-badge.mode-plan {
  color: var(--blue);
  border-color: var(--blue);
  background: var(--blue-bg);
}
/* Status (traffic-light) border colors — mirror the removed status dot.
   These override the mode-specific border colors above. */
.mode-badge.status-live { border-color: var(--green); box-shadow: 0 0 8px var(--green-glow); }
.mode-badge.status-busy { border-color: var(--yellow); animation: pulse 1.2s infinite; }
.mode-badge.status-err { border-color: var(--red); box-shadow: 0 0 8px var(--red-glow); }

/* ===== MODE PICKER POPOVER ===== */
/* Backdrop: only visible on mobile (see media query below). On desktop
   the dropdown has no backdrop — outside clicks are handled in JS. */
.mode-overlay {
  position: fixed; inset: 0; background: var(--overlay-scrim); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 94;
  animation: fadeIn .2s var(--ease);
}
.mode-overlay.hidden { display: none; }
.mode-menu {
  position: fixed;
  z-index: 95;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(280px, 92vw);
  max-height: 360px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn .18s var(--ease-out);
  overflow: hidden;
}
.mode-menu.hidden { display: none; }
.mode-menu-head {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.mode-menu-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
  -webkit-overflow-scrolling: touch;
}
.mode-menu-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-radius: var(--radius-sm);
  transition: background .12s var(--ease);
}
.mode-menu-item:hover { background: var(--panel-2); }
.mode-menu-item.selected {
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.mode-menu-item .mmi-name {
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.mode-menu-item .mmi-check {
  color: var(--accent);
  font-size: 12px;
  margin-left: auto;
}
.mode-menu-item .mmi-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}
.mode-menu-empty {
  padding: 14px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
/* On mobile, render the mode picker as a centered modal with a backdrop
   instead of a tiny dropdown anchored to the header badge. The badge's
   touch target is too small and the dropdown too cramped on phones. */
@media (max-width: 600px) {
  .mode-menu {
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: min(360px, 92vw);
    max-height: 70vh;
  }
  .mode-menu-item { padding: 12px 14px; min-height: 44px; }
}

/* ===== QUEUED PROMPT HINT ===== */
.composer-hint-queued {
  font-size: 11px;
  color: var(--accent);
  padding: 2px 4px;
}
