/* ============================================
   AI Chat Pro - Web App Full-Page Style
   Based on popup.css, adapted for 100vw/100vh
   ============================================ */

/* CSS Variables / Design Tokens */
:root {
  --font-sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica,
    Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-width: 260px;
}

/* Dark Theme */
.theme-dark {
  --color-bg-primary: #0d1117;
  --color-bg-secondary: #161b22;
  --color-bg-tertiary: #21262d;
  --color-bg-hover: #292e36;
  --color-bg-active: #31363e;
  --color-bg-overlay: rgba(0, 0, 0, 0.5);
  --color-border: #30363d;
  --color-border-subtle: #21262d;
  --color-text-primary: #e6edf3;
  --color-text-secondary: #8b949e;
  --color-text-tertiary: #6e7681;
  --color-text-inverse: #0d1117;
  --color-accent: #58a6ff;
  --color-accent-emphasis: #1f6feb;
  --color-accent-subtle: rgba(56, 139, 253, 0.15);
  --color-success: #3fb950;
  --color-success-subtle: rgba(63, 185, 80, 0.15);
  --color-danger: #f85149;
  --color-danger-subtle: rgba(248, 81, 73, 0.15);
  --color-warning: #d29922;
  --color-warning-subtle: rgba(210, 153, 34, 0.15);
  --color-user-msg-bg: #1f6feb;
  --color-user-msg-text: #ffffff;
  --color-ai-msg-bg: #161b22;
  --color-ai-msg-border: #30363d;
  --color-code-bg: #0d1117;
  --color-code-header: #161b22;
  --color-scrollbar: #484f58;
  --color-scrollbar-hover: #6e7681;
  --color-input-bg: #0d1117;
  --color-input-border: #30363d;
  --color-input-focus: #58a6ff;
}

/* Light Theme */
.theme-light {
  --color-bg-primary: #ffffff;
  --color-bg-secondary: #f6f8fa;
  --color-bg-tertiary: #eaeef2;
  --color-bg-hover: #eaeef2;
  --color-bg-active: #d0d7de;
  --color-bg-overlay: rgba(0, 0, 0, 0.3);
  --color-border: #d0d7de;
  --color-border-subtle: #eaeef2;
  --color-text-primary: #1f2328;
  --color-text-secondary: #656d76;
  --color-text-tertiary: #8b949e;
  --color-text-inverse: #ffffff;
  --color-accent: #0969da;
  --color-accent-emphasis: #0550ae;
  --color-accent-subtle: rgba(9, 105, 218, 0.1);
  --color-success: #1a7f37;
  --color-success-subtle: rgba(26, 127, 55, 0.1);
  --color-danger: #cf222e;
  --color-danger-subtle: rgba(207, 34, 46, 0.1);
  --color-warning: #9a6700;
  --color-warning-subtle: rgba(154, 103, 0, 0.1);
  --color-user-msg-bg: #0969da;
  --color-user-msg-text: #ffffff;
  --color-ai-msg-bg: #f6f8fa;
  --color-ai-msg-border: #d0d7de;
  --color-code-bg: #f6f8fa;
  --color-code-header: #eaeef2;
  --color-scrollbar: #c4c8cc;
  --color-scrollbar-hover: #9a9fa4;
  --color-input-bg: #ffffff;
  --color-input-border: #d0d7de;
  --color-input-focus: #0969da;
}

/* Reset & Base */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: var(--font-size, 14px);
  line-height: 1.5;
  color: var(--color-text-primary);
  background: var(--color-bg-primary);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--color-scrollbar);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-scrollbar-hover);
}

/* App Layout — full viewport
   --app-height is set by JS (window.innerHeight) to avoid Android PWA
   viewport bugs when the keyboard / nav bar appears or page navigations occur.
   Falls back to 100dvh → 100vh for non-JS environments. */
#app {
  display: flex;
  width: 100vw;
  height: var(--app-height, 100dvh);
  overflow: hidden;
}

/* PWA standalone mode adjustments */
@media (display-mode: standalone) {
  #app {
    padding-top: env(safe-area-inset-top);
  }
  .header {
    padding-top: 0;
  }
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--color-bg-secondary);
  border-right: 1px solid var(--color-border);
  transition:
    margin-left var(--transition),
    opacity var(--transition);
  z-index: 20;
  flex-shrink: 0;
}

.sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-width));
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--color-text-primary);
}

.logo svg {
  color: var(--color-accent);
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 12px;
  padding: 6px 10px;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-tertiary);
}

.sidebar-search input {
  flex: 1;
  border: none;
  background: none;
  color: var(--color-text-primary);
  font-size: 12px;
  outline: none;
  font-family: inherit;
}

.sidebar-search input::placeholder {
  color: var(--color-text-tertiary);
}

.sidebar-search:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-accent-subtle);
}

/* Conversation List */
.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
  color: var(--color-text-secondary);
  font-size: 13px;
  position: relative;
  user-select: none;
}

.conversation-item:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

.conversation-item.active {
  background: var(--color-accent-subtle);
  color: var(--color-accent);
}

.conversation-item .conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item .conv-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
  flex-shrink: 0;
}

.conversation-item:hover .conv-actions {
  opacity: 1;
}

.conversation-item .conv-rename,
.conversation-item .conv-delete {
  color: var(--color-text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
}

.conversation-item .conv-rename:hover {
  color: var(--color-accent);
}

.conversation-item .conv-delete:hover {
  color: var(--color-danger);
}

.conversation-item .conv-icon {
  flex-shrink: 0;
  color: var(--color-text-tertiary);
}

.conversation-item.active .conv-icon {
  color: var(--color-accent);
}

.conv-empty {
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--color-text-tertiary);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.btn-sidebar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
  transition: all var(--transition);
}

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

/* Sidebar overlay (mobile) */
/* Sidebar close handle (mobile only) */
.sidebar-close-handle {
  display: none;
}

@media (max-width: 700px) {
  .sidebar-close-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: -20px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 64px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-left: none;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    color: var(--color-text-tertiary);
    cursor: pointer;
    z-index: 21;
    padding: 0;
    transition: color var(--transition), background var(--transition);
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar-close-handle:active {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
  }

  .sidebar-close-handle svg {
    width: 16px;
    height: 16px;
  }
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 15;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================
   Main Content
   ============================================ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  min-height: 48px;
  flex-shrink: 0;
}

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

.header-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 14px;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 500;
  background: var(--color-accent-subtle);
  color: var(--color-accent);
  border: 1px solid transparent;
  margin-right: 4px;
}

/* Buttons */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  background: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all var(--transition);
}

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

.btn-icon-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: var(--color-text-tertiary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid var(--color-border);
}

.btn-primary {
  background: var(--color-accent-emphasis);
  color: #fff;
  border-color: var(--color-accent-emphasis);
}

.btn-primary:hover {
  opacity: 0.9;
}

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

.btn-secondary:hover {
  background: var(--color-bg-hover);
}

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

.btn-danger:hover {
  opacity: 0.9;
}

/* Input (for rename modal) */
.input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-input-bg);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

/* ============================================
   Chat Area
   ============================================ */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px;
  text-align: center;
  animation: fadeIn 0.4s ease;
}

.welcome-icon {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--color-accent-subtle);
  color: var(--color-accent);
  margin-bottom: 16px;
}

.welcome-screen h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 6px;
}

.welcome-screen p {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-bottom: 24px;
}

.welcome-suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  max-width: 520px;
}

.suggestion-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
}

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

.suggestion-chip svg {
  flex-shrink: 0;
  color: var(--color-accent);
}

/* Messages */
.messages {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.message {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  animation: slideIn 0.3s ease;
}

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
}

.message.user .message-avatar {
  background: var(--color-accent-emphasis);
  color: #fff;
}

.message.assistant .message-avatar {
  background: var(--color-bg-tertiary);
  color: var(--color-accent);
  border: 1px solid var(--color-border);
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.message-author {
  font-weight: 600;
  font-size: 13px;
  color: var(--color-text-primary);
}

.message-time {
  font-size: 11px;
  color: var(--color-text-tertiary);
}

.message-body {
  font-size: var(--font-size, 14px);
  line-height: 1.6;
  color: var(--color-text-primary);
  word-break: break-word;
}

.message-body p {
  margin-bottom: 8px;
}
.message-body p:last-child {
  margin-bottom: 0;
}

.message-body h1,
.message-body h2,
.message-body h3,
.message-body h4,
.message-body h5,
.message-body h6 {
  margin-top: 16px;
  margin-bottom: 8px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-text-primary);
}

.message-body h1 { font-size: 1.4em; }
.message-body h2 { font-size: 1.2em; }
.message-body h3 { font-size: 1.1em; }

.message-body strong { font-weight: 600; }
.message-body em { font-style: italic; }

.message-body a {
  color: var(--color-accent);
  text-decoration: none;
}
.message-body a:hover {
  text-decoration: underline;
}

.message-body ul,
.message-body ol {
  margin: 8px 0;
  padding-left: 24px;
}

.message-body li {
  margin-bottom: 4px;
}

.message-body blockquote {
  border-left: 3px solid var(--color-accent);
  padding: 4px 16px;
  margin: 8px 0;
  color: var(--color-text-secondary);
  background: var(--color-bg-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.message-body hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 12px 0;
}

/* Announcement Banner */
.announcement-container {
  padding: 8px 16px 0;
  flex-shrink: 0;
}

.announcement-container.hidden {
  display: none;
}

.announcement-banner-inner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  font-size: 13px;
  line-height: 1.4;
  position: relative;
  max-width: 900px;
  margin: 0 auto;
}

.announcement-banner-inner.announcement-info {
  border-color: rgba(59, 130, 246, 0.4);
  background: rgba(59, 130, 246, 0.08);
}

.announcement-banner-inner.announcement-update {
  border-color: rgba(34, 197, 94, 0.4);
  background: rgba(34, 197, 94, 0.08);
}

.announcement-banner-inner.announcement-warning {
  border-color: rgba(234, 179, 8, 0.5);
  background: rgba(234, 179, 8, 0.10);
}

.announcement-icon {
  flex: 0 0 auto;
  font-size: 16px;
  line-height: 1.2;
  padding-top: 1px;
}

.announcement-text {
  flex: 1 1 auto;
  min-width: 0;
}

.announcement-title {
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 2px;
}

.announcement-body {
  color: var(--color-text-secondary);
  word-wrap: break-word;
}

.announcement-link {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  background: var(--color-accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.announcement-link:hover {
  filter: brightness(1.1);
}

.announcement-close {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: var(--color-text-tertiary);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  margin: -2px -4px 0 0;
}

.announcement-close:hover {
  color: var(--color-text-primary);
}

/* Tables */
.message-body table.md-table {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 0.95em;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

.message-body table.md-table th,
.message-body table.md-table td {
  border: 1px solid var(--color-border);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}

.message-body table.md-table thead {
  background: var(--color-bg-tertiary);
}

.message-body table.md-table th {
  font-weight: 600;
  color: var(--color-text-primary);
}

.message-body table.md-table tbody tr:nth-child(even) {
  background: var(--color-bg-secondary);
}

/* Inline Code */
.message-body code:not(pre code) {
  background: var(--color-bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--color-accent);
}

/* Code Blocks */
.code-block {
  margin: 10px 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--color-code-header);
  border-bottom: 1px solid var(--color-border);
  font-size: 12px;
  color: var(--color-text-secondary);
}

.code-lang {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: lowercase;
}

.btn-copy-code {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: none;
  background: none;
  color: var(--color-text-tertiary);
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

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

.btn-copy-code.copied {
  color: var(--color-success);
}

.code-block pre {
  margin: 0;
  padding: 12px 16px;
  overflow-x: auto;
  background: var(--color-code-bg);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text-primary);
}

.code-block pre code {
  font-family: inherit;
  background: none !important;
  padding: 0 !important;
  border-radius: 0 !important;
}

/* Syntax Highlighting */
.token-keyword { color: #ff7b72; }
.token-string { color: #a5d6ff; }
.token-comment { color: #8b949e; font-style: italic; }
.token-number { color: #79c0ff; }
.token-function { color: #d2a8ff; }
.token-operator { color: #ff7b72; }
.token-class { color: #ffa657; }
.token-builtin { color: #ffa657; }

.theme-light .token-keyword { color: #cf222e; }
.theme-light .token-string { color: #0a3069; }
.theme-light .token-comment { color: #6e7781; }
.theme-light .token-number { color: #0550ae; }
.theme-light .token-function { color: #8250df; }
.theme-light .token-operator { color: #cf222e; }
.theme-light .token-class { color: #953800; }
.theme-light .token-builtin { color: #953800; }

/* Reasoning / Thinking Block */
.message-reasoning {
  margin-bottom: 8px;
}

.message-reasoning.hidden {
  display: none;
}

.message-reasoning details {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-primary);
  overflow: hidden;
}

.message-reasoning summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-tertiary);
  user-select: none;
  list-style: none;
  transition: color var(--transition);
}

.message-reasoning summary::-webkit-details-marker {
  display: none;
}

.message-reasoning summary::after {
  content: "";
  margin-left: auto;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--color-text-tertiary);
  transition: transform var(--transition);
}

.message-reasoning details[open] summary::after {
  transform: rotate(180deg);
}

.message-reasoning summary:hover {
  color: var(--color-text-secondary);
}

.message-reasoning summary svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.reasoning-content {
  padding: 8px 12px 10px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--color-text-secondary);
  border-top: 1px solid var(--color-border);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

/* Reasoning spinner (during streaming) */
.reasoning-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 4px;
  flex-shrink: 0;
}

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

/* Citations / Sources */
.message-sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border);
}

.sources-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.source-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  margin: 2px 4px 2px 0;
  border-radius: var(--radius-full);
  background: var(--color-accent-subtle);
  color: var(--color-accent);
  font-size: 11px;
  text-decoration: none;
  transition: all var(--transition);
}

.source-link:hover {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.typing-indicator.hidden {
  display: none;
}

.typing-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-tertiary);
  color: var(--color-accent);
  border: 1px solid var(--color-border);
}

.typing-dots {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-tertiary);
  animation: bounce 1.4s infinite ease-in-out both;
}

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

/* Scroll-to-bottom button */
.btn-scroll-bottom {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  z-index: 10;
  transition: opacity 200ms ease, transform 200ms ease, background var(--transition);
  opacity: 1;
  transform: translateY(0);
}

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

.btn-scroll-bottom:active {
  transform: scale(0.92);
}

.btn-scroll-bottom.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
}

@media (max-width: 700px) {
  .btn-scroll-bottom {
    bottom: calc(env(safe-area-inset-bottom) + 80px);
    right: 16px;
    width: 48px;
    height: 48px;
  }
}

/* ============================================
   Input Area
   ============================================ */
.input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  flex-shrink: 0;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--color-input-bg);
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
  max-width: 900px;
  margin: 0 auto;
}

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

.input-container textarea {
  flex: 1;
  border: none;
  background: none;
  color: var(--color-text-primary);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 20px;
}

.input-container textarea::placeholder {
  color: var(--color-text-tertiary);
}

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

.char-count {
  font-size: 11px;
  color: var(--color-text-tertiary);
}

.btn-send {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-accent-emphasis);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.btn-send:hover:not(:disabled) {
  background: var(--color-accent);
}

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

.input-hint {
  display: flex;
  justify-content: center;
  padding-top: 6px;
}

.input-hint span {
  font-size: 11px;
  color: var(--color-text-tertiary);
}

/* ============================================
   Modals
   ============================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden {
  display: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--color-bg-overlay);
}
.modal-content {
  position: relative;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  width: 400px;
  max-width: 90%;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.15s ease;
}
.modal-sm {
  width: 340px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
}
.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
}
.modal-body {
  padding: 16px;
}
.modal-body p {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.export-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: all var(--transition);
  margin-bottom: 8px;
}

.export-option:last-child {
  margin-bottom: 0;
}

.export-option:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.export-option svg {
  color: var(--color-text-secondary);
  flex-shrink: 0;
}
.export-option strong {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}
.export-option span {
  font-size: 12px;
  color: var(--color-text-secondary);
}

/* ============================================
   Activation Modal
   ============================================ */
.activation-modal-content {
  width: 460px;
  max-width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 0;
}

.activation-header {
  text-align: center;
  padding: 28px 24px 16px;
}

.activation-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--color-accent-subtle);
  color: var(--color-accent);
  margin: 0 auto 14px;
}

.activation-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 6px;
}

.activation-header p {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

.activation-section {
  padding: 16px 24px;
}

.activation-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.activation-section-header svg {
  color: var(--color-accent);
  flex-shrink: 0;
}

.activation-section-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.activation-desc {
  font-size: 12px;
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
}

.activation-file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 16px;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg-primary);
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  font-size: 13px;
}

.activation-file-drop:hover,
.activation-file-drop:focus-visible {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.activation-file-drop.dragover {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
  color: var(--color-accent);
  transform: scale(1.02);
}

.activation-file-drop svg {
  opacity: 0.6;
}

.activation-file-drop:hover svg,
.activation-file-drop.dragover svg {
  opacity: 1;
}

.activation-error {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--color-danger-subtle);
  color: var(--color-danger);
  font-size: 12px;
  line-height: 1.4;
}

.activation-success {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--color-success-subtle);
  color: var(--color-success);
  font-size: 12px;
  line-height: 1.4;
}

.activation-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
}

.activation-divider::before,
.activation-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.activation-divider span {
  font-size: 12px;
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.activation-btn-full {
  width: 100%;
  justify-content: center;
}

.activation-footer {
  text-align: center;
  padding: 16px 24px 24px;
  border-top: 1px solid var(--color-border);
  margin-top: 8px;
}

.activation-footer p {
  font-size: 12px;
  color: var(--color-text-tertiary);
  margin-bottom: 4px;
}

.activation-email {
  font-size: 13px;
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
}

.activation-email:hover {
  text-decoration: underline;
}

@media (max-width: 700px) {
  .activation-modal-content {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
    max-height: 85vh;
  }

  .activation-header {
    padding: 24px 20px 14px;
  }

  .activation-header h2 {
    font-size: 17px;
  }

  .activation-section {
    padding: 14px 20px;
  }

  .activation-file-drop {
    padding: 28px 16px;
    font-size: 14px;
  }

  .activation-btn-full {
    min-height: 44px;
    font-size: 14px;
  }

  .activation-divider {
    padding: 0 20px;
  }

  .activation-footer {
    padding: 16px 20px 20px;
  }
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  color: var(--color-text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.3s ease;
  max-width: 320px;
}

.toast.success { border-color: var(--color-success); }
.toast.success svg { color: var(--color-success); }
.toast.error { border-color: var(--color-danger); }
.toast.error svg { color: var(--color-danger); }

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ============================================
   Utilities
   ============================================ */
.hidden {
  display: none !important;
}

/* ============================================
   Update Banner
   ============================================ */
.update-banner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--color-accent-subtle);
  border-bottom: 1px solid var(--color-accent);
  flex-shrink: 0;
  animation: slideDown 0.3s ease;
}

.update-banner.visible {
  display: flex;
}

.update-banner-content {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-accent);
  font-size: 13px;
  font-weight: 500;
}

.btn-update {
  padding: 6px 16px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-accent-emphasis);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-update:hover {
  filter: brightness(1.1);
}

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

@media (max-width: 700px) {
  .update-banner {
    padding: 12px 16px;
  }

  .update-banner-content {
    font-size: 14px;
  }

  .btn-update {
    padding: 8px 20px;
    font-size: 14px;
    min-height: 40px;
  }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-100%); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   Offline Banner
   ============================================ */
.offline-banner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--color-warning-subtle);
  border-bottom: 1px solid var(--color-warning);
  color: var(--color-warning);
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
  text-align: center;
}

.offline-banner.visible {
  display: flex;
}

/* ============================================
   Responsive — Mobile (<= 700px)
   ============================================ */
@media (max-width: 700px) {
  /* Safe area insets for notch / home bar */
  #app {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* ---- Sidebar ---- */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 85vw;
    max-width: 320px;
    min-width: auto;
    height: 100%;
    padding-left: env(safe-area-inset-left);
    z-index: 20;
    transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1),
                opacity 200ms cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(0);
    margin-left: 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
    opacity: 0;
    margin-left: 0;
    pointer-events: none;
    box-shadow: none;
  }

  /* Sidebar header — bigger tap targets */
  .sidebar-header {
    padding: 16px 18px;
    min-height: 56px;
  }

  .sidebar-header .btn-icon {
    width: 44px;
    height: 44px;
  }

  .logo {
    font-size: 16px;
    gap: 10px;
  }

  .logo svg {
    width: 22px;
    height: 22px;
  }

  /* Sidebar search — finger-friendly */
  .sidebar-search {
    margin: 12px 14px;
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    min-height: 44px;
  }

  .sidebar-search input {
    font-size: 15px;
  }

  .sidebar-search svg {
    width: 16px;
    height: 16px;
  }

  /* Conversation list — larger items */
  .conversation-list {
    padding: 6px 10px;
  }

  .conversation-item {
    padding: 14px 16px;
    min-height: 48px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    gap: 10px;
    margin-bottom: 2px;
  }

  /* Show actions always on mobile (no hover) */
  .conversation-item .conv-actions {
    opacity: 1;
    gap: 4px;
  }

  .conversation-item .conv-rename,
  .conversation-item .conv-delete {
    padding: 8px;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
  }

  .conversation-item .conv-rename:active {
    background: var(--color-accent-subtle);
  }

  .conversation-item .conv-delete:active {
    background: var(--color-danger-subtle);
  }

  /* Sidebar footer — bigger settings button */
  .sidebar-footer {
    padding: 10px 14px;
  }

  .btn-sidebar {
    min-height: 48px;
    padding: 12px 16px;
    font-size: 14px;
    border-radius: var(--radius-lg);
    gap: 12px;
  }

  .btn-sidebar svg {
    width: 18px;
    height: 18px;
  }

  .btn-sidebar:active {
    background: var(--color-bg-active);
  }

  /* ---- Header ---- */
  .header {
    padding: 8px 12px;
    min-height: 52px;
    padding-right: calc(env(safe-area-inset-right) + 12px);
  }

  .btn-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-lg);
  }

  .btn-icon:active {
    background: var(--color-bg-active);
  }

  .btn-icon-sm {
    width: 36px;
    height: 36px;
  }

  .header-title span {
    font-size: 15px;
  }

  /* Hide model badge on very small screens */
  @media (max-width: 380px) {
    .badge { display: none; }
    .header-actions .btn-icon:not(#btn-toggle-sidebar) { display: none; }
  }

  /* ---- Input Area ---- */
  .input-area {
    padding: 10px 12px;
    padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
  }

  .input-container {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    gap: 10px;
    min-height: 52px;
  }

  .input-container textarea {
    font-size: 16px; /* prevents iOS auto-zoom on focus */
    min-height: 24px;
    max-height: 140px;
    line-height: 1.5;
  }

  .btn-send {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    flex-shrink: 0;
  }

  .btn-send svg {
    width: 20px;
    height: 20px;
  }

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

  .char-count {
    font-size: 12px;
  }

  /* Hide keyboard hint on mobile */
  .input-hint {
    display: none;
  }

  /* ---- Welcome Screen ---- */
  .welcome-suggestions {
    grid-template-columns: 1fr;
    max-width: 340px;
  }

  .welcome-screen {
    padding: 24px 16px;
  }

  .welcome-screen h2 {
    font-size: 17px;
  }

  .suggestion-chip {
    padding: 14px 16px;
    font-size: 13px;
    min-height: 48px;
    border-radius: var(--radius-lg);
  }

  .suggestion-chip:active {
    background: var(--color-accent-subtle);
    border-color: var(--color-accent);
  }

  /* ---- Messages ---- */
  .messages {
    padding: 10px 12px;
  }

  .message {
    gap: 10px;
    padding: 10px 0;
  }

  .message-body {
    font-size: 15px;
  }

  /* Code blocks: smaller font on mobile */
  .code-block pre {
    font-size: 12px;
    padding: 10px 12px;
  }

  /* ---- Modals — full-width, bottom-aligned on mobile ---- */
  .modal {
    align-items: flex-end;
  }

  .modal-content {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
    animation: slideUp 0.2s ease;
  }

  .modal-header {
    padding: 18px 20px;
    min-height: 56px;
  }

  .modal-header h3 {
    font-size: 17px;
  }

  .modal-body {
    padding: 18px 20px;
  }

  .modal-body p {
    font-size: 14px;
  }

  .modal-body .input {
    font-size: 16px;
    padding: 12px 14px;
    min-height: 48px;
    border-radius: var(--radius-lg);
  }

  .modal-footer {
    padding: 14px 20px 18px;
    gap: 10px;
  }

  .modal-footer .btn {
    min-height: 44px;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: var(--radius-lg);
    flex: 1;
  }

  .export-option {
    padding: 16px;
    min-height: 56px;
    border-radius: var(--radius-lg);
  }

  .export-option strong {
    font-size: 14px;
  }

  .export-option span {
    font-size: 13px;
  }

  /* ---- Toast ---- */
  .toast-container {
    bottom: calc(env(safe-area-inset-bottom) + 80px);
    right: 16px;
    left: 16px;
  }

  .toast {
    max-width: 100%;
    padding: 12px 16px;
    font-size: 14px;
  }

  /* Announcement banner */
  .announcement-banner-inner {
    font-size: 12px;
    padding: 8px 10px;
  }

  /* ---- Mobile interaction improvements ---- */
  html {
    overscroll-behavior: none;
  }

  /* Prevent text selection on UI elements, allow on messages */
  .sidebar,
  .header,
  .input-area,
  .btn-icon,
  .btn-sidebar {
    -webkit-user-select: none;
    user-select: none;
  }

  /* Smooth momentum scrolling */
  .chat-area,
  .conversation-list {
    -webkit-overflow-scrolling: touch;
  }

  /* Active states for touch feedback */
  .conversation-item:active {
    background: var(--color-bg-active);
  }

  .conversation-item.active:active {
    background: var(--color-accent-subtle);
  }
}
