/* ==========================================================================
   Sia Chat — Conversational Messaging Stylesheet
   Modern, mobile-first messenger aesthetics with dark mode support
   ========================================================================== */

:root {
  /* Conversational Light Palette */
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-hover: #e2e8f0;
  
  --border-subtle: #e2e8f0;
  --border-medium: #cbd5e1;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;

  /* Brand & Messenger Accents */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  --primary-subtle: #eef2ff;
  --primary-border: #c7d2fe;

  /* Conversational Message Bubbles */
  --bubble-user-bg: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  --bubble-user-text: #ffffff;
  --bubble-user-time: rgba(255, 255, 255, 0.75);

  --bubble-assistant-bg: #ffffff;
  --bubble-assistant-text: #0f172a;
  --bubble-assistant-border: #e2e8f0;
  --bubble-assistant-time: #94a3b8;

  --persona-card-bg: #ffffff;
  --persona-card-border: #e0e7ff;

  --online-status: #10b981;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-soft: #fef2f2;

  --toast-bg: #0f172a;
  --toast-text: #f8fafc;

  /* Typography & Layout */
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-bubble: 18px;
  --radius-sheet: 26px;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 36px rgba(15, 23, 42, 0.14);

  --sidebar-w: 320px;
  --touch-target: 44px;
}

[data-theme="dark"] {
  --bg-app: #0b0f19;
  --bg-surface: #111827;
  --bg-subtle: #1e293b;
  --bg-hover: #334155;

  --border-subtle: #1e293b;
  --border-medium: #334155;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-gradient: linear-gradient(135deg, #4338ca 0%, #4f46e5 100%);
  --primary-subtle: #1e1b4b;
  --primary-border: #312e81;

  --bubble-user-bg: linear-gradient(135deg, #4338ca 0%, #4f46e5 100%);
  --bubble-user-text: #ffffff;
  --bubble-user-time: rgba(255, 255, 255, 0.7);

  --bubble-assistant-bg: #1e293b;
  --bubble-assistant-text: #f1f5f9;
  --bubble-assistant-border: #334155;
  --bubble-assistant-time: #64748b;

  --persona-card-bg: #131c2e;
  --persona-card-border: #312e81;

  --danger-soft: rgba(239, 68, 68, 0.15);

  --toast-bg: #1e293b;
  --toast-text: #f8fafc;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   Base Mobile Reset & Global Styles
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.app {
  display: grid;
  grid-template-columns: 1fr;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  position: relative;
}

code, pre, .mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Conversational Navigation Drawer (Sidebar)
   ========================================================================== */
#sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(340px, 88vw);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 50;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transform: translate3d(-105%, 0, 0);
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-lg);
}

body.sidebar-open #sidebar {
  transform: translate3d(0, 0, 0);
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.2s ease;
}

body.sidebar-open #sidebar-scrim:not([hidden]) {
  display: block;
  opacity: 1;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.user-profile-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary-gradient);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.35);
  flex-shrink: 0;
}

.profile-name {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
}

.profile-status {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--online-status);
  display: inline-block;
  box-shadow: 0 0 8px var(--online-status);
}

.side-actions {
  padding: 12px 16px;
}

.side-section {
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.side-section.grow {
  flex: 1 1 auto;
}

.side-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.side-section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.count-tag, .count-badge {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-subtle);
  padding: 2px 8px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  font-size: 13px;
  color: var(--text-dim);
  pointer-events: none;
}

.search-input {
  padding: 0px 36px !important;
}

.search-clear-btn {
  position: absolute;
  right: 6px;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.search-clear-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

#session-list {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 2px;
}

/* Conversation list items */
.session-item {
  text-align: left;
  width: 100%;
  min-height: 58px;
  border-radius: var(--radius-md);
  padding: 8px 10px;
  cursor: pointer;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.session-item:hover {
  background: var(--bg-subtle);
}

.session-item.active {
  background: var(--primary-subtle);
  border-color: var(--primary-border);
}

.session-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
}

.session-item.active .session-avatar {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.session-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.session-title {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
}

.session-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
}

.companion-nav-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.side-foot {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.side-foot-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.side-foot-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.theme-switch-btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  color: var(--text-main);
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  padding: 3px 10px;
  cursor: pointer;
}

.theme-switch-btn:hover {
  background: var(--bg-hover);
}

.token-field-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.token-input {
  padding-right: 56px;
  font-size: 13px !important;
}

.token-toggle-btn {
  position: absolute;
  right: 6px;
  padding: 3px 8px;
  font-size: 11px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
}

.side-caption {
  font-size: 11px;
  color: var(--text-dim);
}

/* ==========================================================================
   Buttons & Inputs
   ========================================================================== */
.btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  border-radius: var(--radius-md);
  min-height: var(--touch-target);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  transition: all 0.15s ease;
}

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

.btn-primary {
  background: var(--primary-gradient);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn-surface {
  background: var(--bg-subtle);
  border-color: var(--border-subtle);
}

.btn-surface:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-subtle);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
}

.icon-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

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

.input, textarea.input, #system-input, #bot-prompt, #bot-name, #bot-desc, #prompt-input {
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  color: var(--text-main);
  border-radius: var(--radius-md);
  min-height: var(--touch-target);
  padding: 10px 14px;
  font-size: 16px; /* 16px prevents mobile browser zoom */
  width: 100%;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 12px 0 6px;
}

/* ==========================================================================
   Conversational Main Viewport & Header
   ========================================================================== */
#main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: var(--bg-app);
}

#chat-header {
  min-height: 58px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: env(safe-area-inset-top, 0px) 12px 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 20;
}

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

.header-companion-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-gradient);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}

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

.header-title-row {
  display: flex;
  align-items: center;
}

#session-title {
  font-weight: 700;
  font-size: 14.5px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  border-radius: 4px;
}

#session-title:hover {
  text-decoration: underline;
}

.header-subtitle-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.companion-status-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--online-status);
  display: inline-block;
}

.bot-badge-text {
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
}

.bot-badge-text:hover {
  text-decoration: underline;
}

.header-status-sep {
  color: var(--text-dim);
}

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

.header-btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  color: var(--text-main);
  border-radius: 999px;
  min-height: 34px;
  padding: 4px 12px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.header-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-medium);
}

.header-btn-icon {
  font-size: 13px;
}

.header-btn-label {
  display: none;
}

/* ==========================================================================
   Conversational Message Stream
   ========================================================================== */
.messages-viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 12px;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
}

.chat-stream {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.scroll-fab {
  position: absolute;
  bottom: 12px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-surface);
  color: var(--primary);
  border: 1px solid var(--border-medium);
  box-shadow: var(--shadow-md);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: transform 0.15s ease;
}

.scroll-fab:hover {
  transform: translateY(-2px);
}

/* Persona Card pinned at the top of the conversation */
.persona-card {
  background: var(--persona-card-bg);
  border: 1px solid var(--persona-card-border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.persona-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.persona-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
}

.persona-actions {
  display: flex;
  gap: 6px;
}

.persona-preview-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

/* Conversational Message Bubbles */
.chat-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  width: 100%;
}

.chat-row-user {
  justify-content: flex-end;
}

.chat-row-assistant {
  justify-content: flex-start;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-gradient);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.msg-wrapper {
  max-width: 86%;
  display: flex;
  flex-direction: column;
}

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

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

/* Speech bubbles with conversational tails */
.chat-bubble {
  border-radius: var(--radius-bubble);
  padding: 11px 16px;
  font-size: 15px;
  line-height: 1.6;
  position: relative;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.chat-row-user .chat-bubble {
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.2);
}

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

.chat-bubble p {
  margin: 0 0 8px;
}

.chat-bubble p:last-child {
  margin-bottom: 0;
}

.chat-bubble a {
  color: inherit;
  text-decoration: underline;
}

.chat-meta-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--text-dim);
}

.branch-nav-inline {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-subtle);
  border-radius: 999px;
  padding: 1px 6px;
  font-variant-numeric: tabular-nums;
}

.branch-nav-inline button {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 10px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 50%;
}

.branch-nav-inline button:hover {
  background: var(--bg-surface);
}

/* Message actions bar (Floating pill) */
.chat-action-strip {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 2px 6px;
  box-shadow: var(--shadow-sm);
  width: fit-content;
}

.chat-act-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 8px;
  min-height: 28px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
}

.chat-act-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.chat-act-btn.danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

/* Inline conversational editor */
.chat-edit-card {
  width: 100%;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-edit-card textarea {
  border: 1px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg-surface);
  color: var(--text-main);
  resize: vertical;
  min-height: 80px;
  width: 100%;
}

.chat-edit-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Typing wave indicator */
.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 12px 18px;
  background: var(--bubble-assistant-bg);
  border: 1px solid var(--bubble-assistant-border);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingPulse 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
  0%, 100% { opacity: 0.3; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* Code blocks & markdown extras */
.chat-bubble pre {
  background: rgba(0, 0, 0, 0.08);
  border-radius: var(--radius-sm);
  padding: 10px;
  overflow-x: auto;
  font-size: 13px;
  margin: 6px 0;
}

[data-theme="dark"] .chat-bubble pre {
  background: rgba(0, 0, 0, 0.35);
}

.code-wrapper {
  position: relative;
}

.code-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-muted);
  border-radius: 6px;
  font-size: 11px;
  padding: 2px 8px;
  cursor: pointer;
}

.code-copy-btn:hover {
  color: var(--text-main);
}

/* Starter greeting cards */
.welcome-card {
  text-align: center;
  padding: 28px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.welcome-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary-gradient);
  color: #ffffff;
  font-size: 24px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.welcome-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.welcome-subtitle {
  font-size: 13.5px;
  color: var(--text-muted);
  max-width: 44ch;
  margin: 0 auto;
  line-height: 1.5;
}

.welcome-chips {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 18px;
}

.conversation-chip {
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  transition: all 0.15s ease;
}

.conversation-chip:hover {
  background: var(--primary-subtle);
  border-color: var(--primary-border);
  color: var(--primary);
}

/* ==========================================================================
   Conversational Composer (Thumb-Zone Dock)
   ========================================================================== */
#composer-wrap {
  padding: 6px 12px max(10px, env(safe-area-inset-bottom, 10px));
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  z-index: 20;
}

.composer-suggestion-strip {
  max-width: 800px;
  margin: 0 auto 6px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0;
}

.composer-suggestion-strip::-webkit-scrollbar {
  display: none;
}

.suggestion-pill {
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  color: var(--text-muted);
  border-radius: 999px;
  min-height: 32px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.suggestion-pill:hover {
  background: var(--primary-subtle);
  border-color: var(--primary-border);
  color: var(--primary);
}

#composer-form {
  max-width: 800px;
  margin: 0 auto;
}

.composer-container {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--bg-app);
  border: 1px solid var(--border-medium);
  border-radius: 24px;
  padding: 6px 8px 6px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer-container:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

#composer-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  max-height: 140px;
  min-height: 28px;
  font-size: 16px; /* 16px to prevent iOS auto zoom */
  line-height: 1.45;
  color: var(--text-main);
  font-family: inherit;
  padding: 6px 0;
  min-width: 0;
}

#composer-input:focus {
  outline: none;
}

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

.composer-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--primary-gradient);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}

.composer-send-btn:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: scale(1.04);
}

.composer-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.composer-stop-btn {
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 12px;
  white-space: nowrap;
}

.composer-stop-btn:hover {
  background: var(--danger);
  color: #ffffff;
}

.composer-footer-hint {
  display: none;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 6px;
}

/* ==========================================================================
   Modals & Conversational Bottom Sheets
   ========================================================================== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
}

.overlay[hidden] {
  display: none;
}

.modal {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 10px 18px max(20px, env(safe-area-inset-bottom, 20px));
  animation: sheetSlideUp 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes sheetSlideUp {
  from { transform: translate3d(0, 24px, 0); opacity: 0; }
  to { transform: translate3d(0, 0, 0); opacity: 1; }
}

.sheet-handle {
  width: 42px;
  height: 5px;
  background: var(--border-medium);
  border-radius: 999px;
  margin: 2px auto 14px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
}

.modal-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.45;
}

.modal-button-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.modal-button-row .btn {
  flex: 1 1 auto;
}

/* Companion Library Cards */
.companion-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 10px;
  background: var(--bg-app);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s ease;
}

.companion-card:hover {
  border-color: var(--primary-border);
}

.companion-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.companion-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
}

.companion-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 2px 8px;
  border-radius: 999px;
}

.companion-card-bio {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}

.companion-prompt-snippet {
  font-size: 12px;
  font-family: var(--font-mono);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.companion-card-buttons {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

/* Toasts */
#toasts {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--toast-bg);
  color: var(--toast-text);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast-badge {
  font-size: 14px;
}

.toast.success .toast-badge { color: #34d399; }
.toast.error .toast-badge { color: #f87171; }

.toast > span {
  flex: 1;
}

.toast-close-btn {
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
}

.only-mobile {
  display: inline-flex;
}

.only-mobile-inline {
  display: inline-flex;
}

/* ==========================================================================
   Tablet & Desktop Breakpoints
   ========================================================================== */
@media (min-width: 768px) {
  .welcome-chips {
    grid-template-columns: repeat(3, 1fr);
  }

  .header-btn-label {
    display: inline;
  }

  #composer-wrap {
    padding: 8px 24px 14px;
  }

  .composer-footer-hint {
    display: block;
  }

  .overlay {
    align-items: center;
    padding: 24px;
  }

  .modal {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    max-width: 560px;
    max-height: 84vh;
    padding: 20px;
  }

  .modal-compact {
    max-width: 420px;
  }

  .sheet-handle {
    display: none;
  }

  .modal-button-row .btn {
    flex: 0 0 auto;
  }

  #toasts {
    bottom: 24px;
  }
}

@media (min-width: 1024px) {
  body.app {
    grid-template-columns: var(--sidebar-w) 1fr;
  }

  #sidebar {
    position: static;
    width: var(--sidebar-w);
    transform: none !important;
    box-shadow: none;
  }

  #sidebar-scrim {
    display: none !important;
  }

  .only-mobile, .only-mobile-inline {
    display: none !important;
  }
}
