#header-status { font-size: 11px; color: var(--muted); margin-left: 6px; }

/* Main container */
.app {
  display: flex;
  flex-direction: row;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* #773/#1268: permanent left sidebar — new chat, session list, profile/settings footer.
   Desktop: a normal flex sibling of .app-main. Mobile: an off-canvas drawer toggled
   by the ☰ button in .site-nav (see .chat-sidebar.open below). */
.chat-sidebar {
  width: 264px;
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 140%);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  box-sizing: border-box;
  overflow: hidden;
}
.sidebar-toggle { display: none; }
.sidebar-new-chat {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: #fff;
  cursor: pointer;
  margin-bottom: 16px;
  font-size: 14px;
  text-align: left;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18), 0 0 0 1px rgba(255,255,255,.04) inset;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.sidebar-new-chat:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0, 0, 0, .24); }
.sidebar-new-chat:active { transform: translateY(0); }
.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 6px 10px;
}
.sessions-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin: 0 -4px; padding: 0 4px; }
.sessions-empty { opacity: .6; font-size: 13px; padding: 14px 4px; }
.session-item {
  display: flex;
  align-items: stretch;
  gap: 2px;
  border-radius: 9px;
  overflow: hidden;
  position: relative;
  transition: background 0.15s ease;
}
.session-item:hover { background: var(--surface2); }
.session-item.active {
  background: var(--surface2);
  box-shadow: inset 3px 0 0 0 var(--accent);
}
.session-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.session-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-meta { font-size: 11px; color: var(--muted); }
.session-menu-btn {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  opacity: 0; padding: 0 10px; font-size: 16px; line-height: 1; letter-spacing: 1px;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.session-item:hover .session-menu-btn,
.session-item.active .session-menu-btn { opacity: .55; }
.session-menu-btn:hover { opacity: 1 !important; color: var(--text); }

/* Inline rename field — sits where the title text was. */
.session-rename-input {
  flex: 1; min-width: 0; margin: 7px 8px; padding: 2px 6px;
  font-size: 13px; color: var(--text);
  background: var(--bg); border: 1px solid var(--accent); border-radius: 6px;
  outline: none;
}

/* Floating chat context menu (Rename / Delete). */
.session-menu {
  position: fixed; z-index: 1000; min-width: 150px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .28), 0 0 0 1px rgba(255, 255, 255, .03) inset;
  display: flex; flex-direction: column; gap: 2px;
}
.session-menu-item {
  text-align: left; background: transparent; border: none; cursor: pointer;
  color: var(--text); font-size: 13px; padding: 8px 10px; border-radius: 7px;
  transition: background 0.12s ease, color 0.12s ease;
}
.session-menu-item:hover { background: var(--surface2); }
.session-menu-item.danger { color: #e25555; }
.session-menu-item.danger:hover { background: rgba(226, 85, 85, .12); }
.sidebar-foot { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); flex-shrink: 0; }
.clear-all-btn {
  width: 100%;
  padding: 8px;
  border: 1px solid #e25555;
  color: #e25555;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  margin-bottom: 10px;
  transition: background 0.15s ease;
}
.clear-all-btn:hover { background: rgba(226, 85, 85, .1); }
.sidebar-foot-actions { display: flex; align-items: center; gap: 6px; }
.sidebar-foot-actions .nav-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0, 0, 0, .2); }

/* Brand glow + soft nav shadow (dream-chat only) */
.site-nav { box-shadow: 0 1px 0 var(--border), 0 4px 16px rgba(0, 0, 0, .08); }
.nav-brand { flex-shrink: 0; white-space: nowrap; }
.nav-brand img { filter: drop-shadow(0 0 6px rgba(6, 182, 212, .45)); }
.nav-links { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.nav-links::-webkit-scrollbar { display: none; }

@media (max-width: 580px) {
  /* Off-canvas on mobile: hidden by default, slides in via .open, toggled by ☰. */
  .chat-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1200;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 24px rgba(0, 0, 0, .25);
    width: 280px;
    max-width: 86vw;
  }
  .chat-sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .app-main { margin-left: 0; }
  .site-nav { padding: 0 12px; }
  .nav-links { display: none; }
  .nav-cta { display: none; }
  .input-wrapper { flex-direction: row; }
  .perf-monitor { bottom: 8px; right: 8px; font-size: 10px; padding: 8px 12px; }
}

@media (max-width: 480px) {
  .chat-container { padding: 12px; }
  .message-content { max-width: 90%; }
  .modal-content { margin: 16px; }
  .input-container { padding: 12px; }
  .empty-state { padding: 20px; }
  .empty-state h2 { font-size: 16px; }
}

.app-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
}

/* Messages area */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 20px;
  padding: 40px;
}
.empty-icon { font-size: 48px; opacity: 0.5; }
.empty-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}
.empty-state p {
  color: var(--muted);
  max-width: 300px;
  line-height: 1.5;
}

/* Message bubbles */
.message {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.message.user { justify-content: flex-end; }
.message-content {
  max-width: 70%;
  padding: 11px 15px;
  border-radius: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 4px 12px rgba(0, 0, 0, .05);
}
.message.user .message-content {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: white;
  border-bottom-right-radius: 4px;
}
.message.agent .message-content {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Replayed-history bubbles (.msg-row/.bubble, used after a reload) — match the
   live .message/.message-content gradient treatment instead of the older flat
   --user-bubble/--agent-bubble colors, so a reload doesn't look like a downgrade. */
.msg-row.user .bubble {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: white;
  border: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 4px 12px rgba(0, 0, 0, .05);
}
.msg-row.agent .bubble {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 4px 12px rgba(0, 0, 0, .05);
}
/* Agent replies append the route signature and the "Read aloud" button as siblings
   of .message-content. Since .message is a flex ROW, without this they get laid out
   in wide horizontal columns beside the bubble (dead clickable space). Stack them
   vertically under the bubble instead, left-aligned and compact. */
.message.agent { flex-direction: column; align-items: flex-start; }
.message.agent > .read-aloud-btn { margin-top: 2px; }

/* Input area */
.input-container {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.input-wrapper {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.input-field {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
  resize: none;
  max-height: 100px;
}
.input-field:focus {
  border-color: var(--accent);
  background: var(--surface2);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, .15);
}
.input-field::placeholder { color: var(--muted); }
.input-wrapper { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 6px; box-shadow: 0 2px 10px rgba(0, 0, 0, .06); }
.input-wrapper .input-field { border: none; background: transparent; }
.input-wrapper .input-field:focus { box-shadow: none; }
.send-button {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  flex-shrink: 0;
  font-size: 18px;
  box-shadow: 0 2px 8px rgba(6, 182, 212, .3);
}
.send-button:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(6, 182, 212, .4); }
.send-button:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

/* Performance monitor */
.perf-monitor {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 11px;
  color: var(--muted);
  max-width: 200px;
  z-index: 999;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.perf-monitor:hover { opacity: 1; }
.perf-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 2px 0;
}
.perf-label { font-weight: 600; }
.perf-value { text-align: right; color: var(--text); }

/* Modal overlays */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.modal-content {
  width: 100%;
  max-width: 600px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  max-height: 80vh;
  overflow-y: auto;
  margin-left: auto;
  margin-right: auto;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
.modal-overlay.open .modal-content {
  transform: translateY(0);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}
.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.modal-close:hover {
  background: var(--surface2);
  color: var(--text);
}
.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Form elements */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: all 0.2s;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--muted); }

/* Settings card */
.setting-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.setting-card-icon { font-size: 20px; }
.setting-card-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.setting-card-title { font-size: 14px; font-weight: 500; color: var(--text); }
.setting-card-status { font-size: 12px; color: var(--muted); }
.setting-card-status.ok { color: #34d399; }
.setting-card-status.err { color: var(--accent); }

/* Buttons */
.button-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.button-primary:hover { background: var(--accent-hover); }
.button-secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.button-secondary:hover { border-color: var(--text); color: var(--text); }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* Streaming cursor */
.stream-cursor {
  display: inline-block; width: 2px; height: 1em;
  background: var(--accent); margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.7s step-end infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* Quick-start chips */
.starter-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }
.starter-chip {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--muted); font-size: 0.82rem; font-family: inherit;
  padding: 7px 16px; border-radius: 20px; cursor: pointer;
  transition: border-color 0.15s, color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.starter-chip:hover {
  border-color: var(--accent); color: var(--text);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
}

/* Error / muted agent text */
.message.agent.error .message-content { color: var(--muted); font-style: italic; }

/* TTS word highlighting */
.tts-word { border-radius: 2px; transition: background 0.08s; }
.tts-active { background: rgba(255, 220, 50, 0.22); }

/* Status indicators */
.status-indicator {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}
.status-indicator.ok { background: #34d399; }
.status-indicator.err { background: var(--accent); }
.status-indicator.pending { background: #fbbf24; }

/* Priority items */
.priority-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface2);
  border-radius: 6px;
  margin-bottom: 4px;
}
.priority-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}
.priority-badge.p0 { background: var(--accent); color: white; }
.priority-badge.p1 { background: #fbbf24; color: black; }
.priority-badge.p2 { background: #34d399; color: white; }
.priority-badge.p3 { background: var(--muted); color: var(--text); }
.priority-title { font-size: 12px; color: var(--text); flex: 1; }

/* Connector sidecar */
.connector-grid { display: flex; flex-direction: column; gap: 10px; }
.connector-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color 0.15s;
}
.connector-card:hover { border-color: var(--accent); }
.connector-card-icon { font-size: 20px; width: 28px; text-align: center; }
.connector-card-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.connector-card-title { font-size: 14px; font-weight: 500; color: var(--text); }
.connector-card-meta { font-size: 11px; color: var(--muted); }
.connector-card-status {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.connector-card-status.ok { color: #34d399; border-color: #34d39933; background: #34d39911; }
.connector-card-status.err { color: var(--accent); border-color: var(--accent)33; background: var(--accent)11; }
.connector-card-status.pending { color: #fbbf24; border-color: #fbbf2433; background: #fbbf2411; }
.connector-btn {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.connector-btn:hover { border-color: var(--accent); color: var(--text); }
.connector-btn.primary { background: var(--accent); color: white; border-color: var(--accent); }
.connector-btn.primary:hover { background: var(--accent-hover); }

/* Message footer: source · latency */
.msg-footer {
  font-size: 0.67rem;
  color: var(--muted);
  padding: 0 4px;
  align-self: flex-start;
  opacity: 0.65;
  letter-spacing: 0.02em;
}
.msg-footer.offline { opacity: 0.45; }
.msg-footer.anthropic { color: var(--accent); opacity: 0.8; }
.msg-footer.ollama { color: #4ade80; opacity: 0.8; }
.msg-footer.grok { color: #e2c97e; opacity: 0.8; }
.msg-footer.gemini { color: #4fc3f7; opacity: 0.8; }

/* Route signature */
.msg-route-sig {
  font-size: 0.68rem;
  color: var(--accent, #e2c97e);
  opacity: 1;
  font-weight: 500;
  padding: 2px 8px;
  align-self: flex-start;
  letter-spacing: 0.04em;
}
/* Debug-route replies render their signature in black (per request) so the
   "Keystone · debug route" label reads distinctly from the gold chat route. */
.msg-route-sig.route-debug {
  color: #000;
}
.msg-row.agent .msg-route-sig,
.msg-row.agent .msg-footer,
.msg-row.agent .msg-label {
  align-self: flex-start;
  text-align: left;
}
.msg-row.user .msg-label {
  align-self: flex-end;
  text-align: right;
  padding-right: 8px;
}

/* Routing card shown while backend delegates */
.route-card {
  font-size: 0.75rem;
  color: var(--accent-dim, #a08840);
  opacity: 0.8;
  padding: 2px 0 4px;
  font-style: italic;
  letter-spacing: 0.02em;
}

/* PR / Issue link pills */
.pr-pill {
  display: inline-block;
  background: rgba(52,211,153,0.12);
  border: 1px solid rgba(52,211,153,0.35);
  color: #34d399;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.82rem;
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s;
  margin: 2px 0;
  word-break: break-all;
}
.pr-pill:hover { background: rgba(52,211,153,0.22); }
.issue-pill {
  display: inline-block;
  background: rgba(251,191,36,0.10);
  border: 1px solid rgba(251,191,36,0.30);
  color: #fbbf24;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.82rem;
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s;
  margin: 2px 0;
}
.issue-pill:hover { background: rgba(251,191,36,0.20); }

/* Code blocks */
.code-block {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  font-family: 'SF Mono','Monaco','Consolas',monospace;
  font-size: 0.82rem;
  overflow-x: auto;
  margin: 6px 0;
  white-space: pre;
  display: block;
}
.inline-code {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: 'SF Mono','Monaco','Consolas',monospace;
  font-size: 0.85em;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Spinner: apply animation via class so reduced-motion can override cleanly */
.thinking-spin { animation: spin 2s linear infinite; }

/* Respect prefers-reduced-motion — stop decorative spin, keep label visible */
@media (prefers-reduced-motion: reduce) {
  .thinking-spin { animation: none; opacity: 0.4; }
}

/* Disclosure triangle for per-reply debug details — reset browser default marker */
.sig-debug > summary { display: inline; list-style: none; }
.sig-debug > summary::-webkit-details-marker { display: none; }
