:root {
  --app-height: 100dvh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", system-ui, sans-serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, monospace;

  /* Light Mode Palette (iOS Refined Daylight) */
  --bg-canvas: #F3F5F9;
  --bg-elevated: #FFFFFF;
  --bg-glass: rgba(246, 248, 252, 0.82);
  --bg-subtle: #E8ECF4;
  --bg-input: #FFFFFF;
  --bg-code: #F1F4F9;
  --bg-code-header: #E6EBF3;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #64748B;
  --text-on-accent: #FFFFFF;

  --border-hairline: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.15);

  --accent: #2563EB;
  --accent-pressed: #1D4ED8;
  --accent-soft: rgba(37, 99, 235, 0.11);
  --accent-border: rgba(37, 99, 235, 0.26);

  --capture-accent: #0D9488;
  --capture-soft: rgba(13, 148, 136, 0.12);
  --steer-accent: #D97706;
  --steer-soft: rgba(217, 119, 6, 0.14);

  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --danger-soft: rgba(239, 68, 68, 0.11);

  --bubble-user-bg: linear-gradient(145deg, #2563EB 0%, #1D4ED8 100%);
  --bubble-user-text: #FFFFFF;
  --bubble-assistant-bg: #FFFFFF;
  --bubble-assistant-border: rgba(15, 23, 42, 0.07);

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 26px rgba(15, 23, 42, 0.09);
  --shadow-lg: 0 20px 48px rgba(15, 23, 42, 0.16);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-canvas: #090D16;
    --bg-elevated: #121927;
    --bg-glass: rgba(12, 17, 29, 0.80);
    --bg-subtle: #1A2336;
    --bg-input: #141C2E;
    --bg-code: #0D1320;
    --bg-code-header: #162033;

    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --text-on-accent: #FFFFFF;

    --border-hairline: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.15);

    --accent: #3B82F6;
    --accent-pressed: #2563EB;
    --accent-soft: rgba(59, 130, 246, 0.16);
    --accent-border: rgba(59, 130, 246, 0.34);

    --capture-accent: #2DD4BF;
    --capture-soft: rgba(45, 212, 191, 0.15);
    --steer-accent: #FBBF24;
    --steer-soft: rgba(251, 191, 36, 0.16);

    --danger: #F87171;
    --danger-soft: rgba(248, 113, 113, 0.15);

    --bubble-user-bg: linear-gradient(145deg, #2563EB 0%, #1E40AF 100%);
    --bubble-user-text: #F8FAFC;
    --bubble-assistant-bg: #121928;
    --bubble-assistant-border: rgba(255, 255, 255, 0.08);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.28);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.42);
    --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.62);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: var(--app-height);
  overflow: hidden;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font-family: inherit;
  color: inherit;
}

.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* =========================================================
   Buttons & Inputs
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease, background-color 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.975);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-lg {
  padding: 14px 20px;
  font-size: 16px;
  border-radius: 15px;
}

.btn-sm {
  padding: 8px 13px;
  font-size: 13.5px;
  border-radius: 10px;
}

.btn-xs {
  padding: 6px 12px;
  font-size: 12.5px;
  border-radius: var(--radius-pill);
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-pressed);
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border-hairline);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.24);
}

.btn-pill-subtle {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 20px;
  transition: background-color 0.15s ease, transform 0.12s ease;
}

.icon-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.icon-btn:active {
  transform: scale(0.93);
}

.icon-btn--sm {
  width: 30px;
  height: 30px;
  font-size: 18px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.text-input {
  width: 100%;
  padding: 11px 13px;
  font-size: 16px; /* Prevents iOS Safari auto-zoom on focus */
  line-height: 1.35;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.text-input:disabled,
.text-input[readonly] {
  opacity: 0.72;
  cursor: default;
}

/* =========================================================
   Status Dots & Spinners
   ========================================================= */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot--online {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}

.status-dot--connecting {
  background: var(--warning);
  animation: pulseOpacity 1.4s infinite ease-in-out;
}

.status-dot--busy {
  background: var(--accent);
  animation: pulseOpacity 1s infinite ease-in-out;
}

.status-dot--offline,
.status-dot--idle {
  background: var(--text-muted);
}

@keyframes pulseOpacity {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =========================================================
   Toast Capsule
   ========================================================= */
.toast-container {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}

.toast {
  pointer-events: auto;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  background: rgba(15, 23, 42, 0.92);
  color: #F8FAFC;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: toastSlideIn 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  .toast {
    background: rgba(30, 41, 59, 0.94);
    border: 1px solid var(--border-strong);
  }
}

.toast--error {
  background: rgba(185, 28, 28, 0.95);
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* =========================================================
   Auth & Onboarding View
   ========================================================= */
.auth-view {
  height: var(--app-height);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-top) + 24px) calc(var(--safe-right) + 18px) calc(var(--safe-bottom) + 28px) calc(var(--safe-left) + 18px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 410px;
  margin: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: 24px;
  padding: 28px 22px 22px;
  box-shadow: var(--shadow-md);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 22px;
}

.auth-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  box-shadow: 0 8px 20px rgba(11, 17, 32, 0.25);
  margin-bottom: 12px;
}

.auth-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-subtitle {
  margin: 4px 0 10px;
  font-size: 13.5px;
  color: var(--text-secondary);
}

.auth-server-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  font-size: 12px;
  color: var(--text-secondary);
}

.auth-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-loading {
  align-items: center;
  padding: 18px 0;
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
}

.auth-alert {
  margin-bottom: 14px;
  padding: 11px 13px;
  border-radius: 12px;
  background: var(--danger-soft);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--danger);
  font-size: 13.5px;
  line-height: 1.45;
  word-break: break-word;
}

.invite-badge {
  padding: 9px 12px;
  border-radius: 11px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.28);
  color: var(--success);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.auth-hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.45;
}

.auth-disclosure {
  margin-top: 8px;
  border-top: 1px solid var(--border-hairline);
  padding-top: 12px;
}

.auth-api-disclosure {
  margin-top: 16px;
}

.auth-disclosure summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.auth-disclosure summary::-webkit-details-marker {
  display: none;
}

.auth-disclosure summary::after {
  content: "▾";
  font-size: 12px;
  opacity: 0.7;
  transition: transform 0.15s ease;
}

.auth-disclosure[open] summary::after {
  transform: rotate(180deg);
}

.disclosure-body {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* =========================================================
   Main Chat Workspace Layout
   ========================================================= */
.app-view {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: var(--app-height);
  overflow: hidden;
  position: relative;
}

.chat-header {
  flex-shrink: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 14px) 9px calc(var(--safe-left) + 16px);
  background: var(--bg-glass);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-bottom: 1px solid var(--border-hairline);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  flex-shrink: 0;
}

.header-titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header-name {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.connection-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.2;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-stop-pill {
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.25);
  font-size: 12.5px;
  font-weight: 600;
  gap: 6px;
}

.stop-square {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: currentColor;
}

/* =========================================================
   Top Contextual Banners (A2HS & Push)
   ========================================================= */
.top-banner {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px calc(var(--safe-right) + 14px) 9px calc(var(--safe-left) + 14px);
  border-bottom: 1px solid var(--border-hairline);
  font-size: 13px;
  line-height: 1.4;
}

.a2hs-banner {
  background: var(--accent-soft);
}

.push-banner {
  background: var(--bg-elevated);
  justify-content: space-between;
}

.banner-icon-wrap {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.banner-content {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}

.banner-text {
  margin: 0;
  color: var(--text-primary);
}

.banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.banner-close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
}

/* =========================================================
   Message List & Bubbles
   ========================================================= */
.message-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 14px calc(var(--safe-right) + 12px) 16px calc(var(--safe-left) + 12px);
  display: flex;
  flex-direction: column;
}

.load-older-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.empty-state {
  margin: auto;
  max-width: 360px;
  text-align: center;
  padding: 28px 14px;
}

.empty-orb img {
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 10px;
}

.empty-title {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
}

.empty-desc {
  margin: 0 0 18px;
  font-size: 13.5px;
  color: var(--text-secondary);
}

.starter-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.chip-btn {
  border: 1px solid var(--border-hairline);
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 8px 13px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.chip-btn:active {
  transform: scale(0.96);
}

.messages-container {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.date-divider {
  align-self: center;
  margin: 6px 0 2px;
  padding: 3px 11px;
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 500;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 88%;
}

@media (min-width: 680px) {
  .msg-row {
    max-width: 78%;
  }
}

.msg-row--user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row--assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-bubble {
  position: relative;
  padding: 10px 14px;
  border-radius: 18px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 15.5px;
  line-height: 1.54;
}

.msg-row--user .msg-bubble {
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 5px;
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.18);
}

.msg-row--assistant .msg-bubble {
  background: var(--bubble-assistant-bg);
  color: var(--text-primary);
  border: 1px solid var(--bubble-assistant-border);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}

/* Mode tag inside user bubble */
.msg-mode-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 5px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.18);
  font-size: 11px;
  font-weight: 600;
}

/* Quoted reply block inside message */
.msg-reply-ref {
  margin-bottom: 6px;
  padding: 5px 9px;
  border-left: 3px solid rgba(255, 255, 255, 0.6);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.14);
  font-size: 12.5px;
  opacity: 0.92;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.msg-row--assistant .msg-reply-ref {
  border-left-color: var(--accent);
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

/* Message Footer Meta */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.msg-quote-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: 4px;
}

.msg-quote-btn:hover {
  color: var(--accent);
  background: var(--bg-subtle);
}

/* =========================================================
   Markdown Typography inside Bubbles
   ========================================================= */
.md-content > *:first-child {
  margin-top: 0;
}

.md-content > *:last-child {
  margin-bottom: 0;
}

.md-content p {
  margin: 0 0 8px;
}

.md-content h1,
.md-content h2,
.md-content h3,
.md-content h4,
.md-content h5,
.md-content h6 {
  margin: 12px 0 6px;
  font-weight: 700;
  line-height: 1.3;
}

.md-content h1 { font-size: 18px; }
.md-content h2 { font-size: 17px; }
.md-content h3 { font-size: 16px; }
.md-content h4,
.md-content h5,
.md-content h6 { font-size: 15px; }

.md-content ul,
.md-content ol {
  margin: 6px 0 8px;
  padding-left: 20px;
}

.md-content li {
  margin-bottom: 3px;
}

.md-content blockquote {
  margin: 8px 0;
  padding: 6px 11px;
  border-left: 3px solid var(--accent);
  background: var(--bg-subtle);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
}

.msg-row--user .md-content blockquote {
  border-left-color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.14);
  color: inherit;
}

.md-content hr {
  border: none;
  border-top: 1px solid var(--border-hairline);
  margin: 10px 0;
}

.md-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-row--user .md-content a {
  color: #FFFFFF;
}

.md-content code.inline-code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--bg-code);
  border: 1px solid var(--border-hairline);
}

.msg-row--user .md-content code.inline-code {
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.2);
  color: #FFFFFF;
}

.code-block {
  margin: 8px 0;
  border-radius: 11px;
  overflow: hidden;
  border: 1px solid var(--border-hairline);
  background: var(--bg-code);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  background: var(--bg-code-header);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-secondary);
}

.copy-code-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  cursor: pointer;
}

.copy-code-btn:hover {
  background: var(--border-hairline);
  color: var(--text-primary);
}

.code-block pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.48;
  color: var(--text-primary);
}

.md-table-wrap {
  margin: 8px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.md-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13.5px;
}

.md-table th,
.md-table td {
  border: 1px solid var(--border-strong);
  padding: 6px 9px;
  text-align: left;
}

.md-table th {
  background: var(--bg-subtle);
  font-weight: 600;
}

/* =========================================================
   Message Attachments & Interactive Approval Buttons
   ========================================================= */
.msg-attachments {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 6px;
}

.msg-attachments:last-child {
  margin-bottom: 0;
}

.msg-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 6px;
}

.msg-image-item {
  display: block;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-hairline);
  background: var(--bg-subtle);
  cursor: zoom-in;
  max-height: 280px;
}

.msg-image-item img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 280px;
  object-fit: cover;
}

.msg-audio-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-audio-card audio {
  width: 240px;
  max-width: 100%;
  height: 38px;
}

.msg-file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  border-radius: 11px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-hairline);
  text-decoration: none;
  color: inherit;
}

.msg-row--user .msg-file-card {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.22);
  color: #FFFFFF;
}

.file-card-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.file-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.file-card-name {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-card-meta {
  font-size: 11.5px;
  opacity: 0.78;
}

/* Interactive Approval Button Rows */
.approval-actions {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.approval-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.approval-btn {
  flex: 1 1 auto;
  min-height: 36px;
  padding: 7px 13px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease, opacity 0.15s ease;
}

.approval-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.approval-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.approval-btn--approve {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.approval-btn--deny {
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, 0.28);
  color: var(--danger);
}

/* Busy Indicator Row */
.busy-row {
  width: 100%;
  max-width: 780px;
  margin: 10px auto 2px;
  display: flex;
  justify-content: flex-start;
}

.busy-bubble {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  color: var(--text-secondary);
  font-size: 13px;
  box-shadow: var(--shadow-sm);
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotBounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.65); opacity: 0.45; }
  40% { transform: scale(1); opacity: 1; }
}

/* Scroll to bottom floating pill */
.scroll-bottom-btn {
  position: absolute;
  right: calc(var(--safe-right) + 16px);
  bottom: calc(var(--safe-bottom) + 118px);
  z-index: 25;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

/* =========================================================
   Composer Dock
   ========================================================= */
.composer-dock {
  flex-shrink: 0;
  z-index: 30;
  background: var(--bg-glass);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-top: 1px solid var(--border-hairline);
  padding: 8px calc(var(--safe-right) + 12px) calc(var(--safe-bottom) + 8px) calc(var(--safe-left) + 12px);
}

body.keyboard-open .composer-dock {
  padding-bottom: 8px;
}

.mode-bar,
.quote-preview,
.attachment-strip,
.composer-row {
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;
}

.mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  overflow-x: auto;
  scrollbar-width: none;
}

.mode-bar::-webkit-scrollbar {
  display: none;
}

.mode-pills {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mode-pill {
  border: 1px solid var(--border-hairline);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.mode-pill.is-active[data-mode="chat"] {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.mode-pill.is-active[data-mode="capture"] {
  background: var(--capture-soft);
  border-color: var(--capture-accent);
  color: var(--capture-accent);
}

.mode-pill--steer {
  border-color: rgba(217, 119, 6, 0.35);
}

.mode-pill.is-active[data-mode="steer"] {
  background: var(--steer-soft);
  border-color: var(--steer-accent);
  color: var(--steer-accent);
}

.mode-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Quote Preview */
.quote-preview {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 7px;
  padding: 6px 10px;
  border-radius: 11px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
}

.quote-bar-accent {
  width: 3px;
  align-self: stretch;
  border-radius: 2px;
  background: var(--accent);
}

.quote-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.quote-author {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
}

.quote-text {
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Pending Attachment Strip */
.attachment-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 8px;
  -webkit-overflow-scrolling: touch;
}

.pending-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 6px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
  max-width: 210px;
}

.pending-chip.is-error {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.pending-thumb {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg-subtle);
  flex-shrink: 0;
}

.pending-file-badge {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.pending-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.pending-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pending-status {
  font-size: 11px;
  color: var(--text-muted);
}

.pending-remove {
  border: none;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

/* Composer Input Row */
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer-attach-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease;
}

.composer-attach-btn:active {
  transform: scale(0.93);
}

.composer-input-wrap {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 7px 13px;
  display: flex;
  align-items: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer-textarea {
  width: 100%;
  max-height: 144px;
  border: none;
  outline: none;
  resize: none;
  padding: 0;
  margin: 0;
  background: transparent;
  font-size: 16px; /* Prevents iOS zoom */
  line-height: 1.4;
  color: var(--text-primary);
  overflow-y: auto;
}

.composer-textarea::placeholder {
  color: var(--text-muted);
}

.composer-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease, background-color 0.15s ease;
}

.composer-send-btn:disabled {
  background: var(--bg-subtle);
  color: var(--text-muted);
  cursor: default;
}

.composer-send-btn:active:not(:disabled) {
  transform: scale(0.92);
}

/* =========================================================
   Settings Sheet Drawer
   ========================================================= */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(5, 10, 20, 0.52);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.settings-sheet {
  width: 100%;
  max-width: 540px;
  max-height: 88dvh;
  background: var(--bg-canvas);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border: 1px solid var(--border-hairline);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
  animation: sheetSlideUp 0.24s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes sheetSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 38px;
  height: 5px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  margin: 9px auto 4px;
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 18px 12px;
  border-bottom: 1px solid var(--border-hairline);
  flex-shrink: 0;
}

.sheet-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.settings-group-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 7px;
  padding: 0 4px;
}

.settings-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: 16px;
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-kv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
}

.kv-value {
  font-weight: 600;
  color: var(--text-secondary);
}

.settings-note {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.settings-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 2px;
}

/* Quick Command Grid */
.quick-cmd-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.cmd-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 13px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.cmd-card:active {
  transform: scale(0.97);
}

.cmd-name {
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent);
}

.cmd-card--warn .cmd-name {
  color: var(--danger);
}

.cmd-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

/* =========================================================
   Image Lightbox
   ========================================================= */
.lightbox-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(4, 7, 15, 0.94);
  display: flex;
  flex-direction: column;
}

.lightbox-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
}

.lightbox-btn {
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.lightbox-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 12px calc(var(--safe-bottom) + 16px);
  overflow: auto;
}

.lightbox-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}
