/* ================================================
   Vortex Chat - Modern Interface Styles
   ================================================ */

/* Reset and Base */
body.chat-page {
  margin: 0;
  padding: 0;
}

.chat-page {
  margin: 0;
  padding: 0;
  display: flex;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  background: var(--paper, #f9fafb);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink, #1b1f24);
  position: relative;
  /* Chat-specific accent colors - refined palette */
  --chat-accent: #3eb4a9;
  --chat-accent-strong: #2a9d94;
  --chat-accent-warm: var(--accent, #ff6b5a);
  --chat-accent-warm-strong: #e57258;
  --chat-accent-soft: rgba(62, 180, 169, 0.08);
  --chat-accent-soft-strong: rgba(62, 180, 169, 0.14);
  --chat-border: rgba(0, 0, 0, 0.06);
}

/* Ensure form elements inherit fonts */
.chat-page input,
.chat-page textarea,
.chat-page select,
.chat-page button {
  font-family: inherit;
}

.chat-title,
.mobile-title,
.chat-welcome h2,
.shortcuts-header h3,
.sidebar-brand .brand-text {
  font-family: "Space Grotesk", "Inter", sans-serif;
  letter-spacing: -0.02em;
  font-weight: 600;
}

/* ================================================
   Left Sidebar
   ================================================ */
.chat-sidebar {
  width: 272px;
  min-width: 272px;
  height: 100vh;
  height: 100dvh;
  background: var(--surface, #fff);
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease, min-width 0.25s ease, transform 0.25s ease;
  position: relative;
  z-index: var(--z-sidebar, 100);
  color: var(--ink, #1b1f24);
  border-right: 1px solid var(--chat-border);
}

/* Ensure all sidebar text is visible on light background */
.chat-sidebar * {
  color: inherit;
}

.chat-sidebar a,
.chat-sidebar button,
.chat-sidebar span,
.chat-sidebar p,
.chat-sidebar strong {
  color: var(--muted, #667079);
}

.chat-sidebar.collapsed {
  transform: translateX(-100%);
  margin-left: -272px;
  will-change: transform, margin;
}

/* Sidebar Header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid rgba(27, 31, 36, 0.08);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink, #1b1f24);
  font-weight: 600;
  font-size: 1.1rem;
}

.sidebar-brand .logo {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #ff6b5a 0%, #53c6b7 100%);
  border-radius: 8px;
}

/* .sidebar-toggle uses shared styles from styles.css */

/* New Chat Button */
.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px 14px;
  padding: 10px 16px;
  background: var(--chat-accent);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.new-chat-btn:hover {
  background: var(--chat-accent-strong);
}

/* Sidebar Search */
.sidebar-search {
  position: relative;
  margin: 0 14px 10px;
}

.sidebar-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted, #9ca3af);
  pointer-events: none;
}

.sidebar-search input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  background: var(--paper-2, #f3f4f6);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink, #1b1f24);
  font-size: 0.85rem;
  transition: border-color 0.15s, background 0.15s;
}

.sidebar-search input::placeholder {
  color: var(--muted, #9ca3af);
}

.sidebar-search input:focus {
  outline: none;
  background: var(--surface, #fff);
  border-color: var(--chat-accent);
}

/* History List */
.chat-sidebar .history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: none;
  padding: 0 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
}

.chat-sidebar .history-list::-webkit-scrollbar {
  width: 5px;
}

.chat-sidebar .history-list::-webkit-scrollbar-track {
  background: transparent;
}

.chat-sidebar .history-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 3px;
}

/* History Items */
.chat-sidebar .history-item {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 12px;
  margin: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s ease;
  color: var(--ink, #1b1f24);
  border: none;
  background: transparent;
  position: relative;
  z-index: 1;
  width: 100%;
  text-align: left;
  box-sizing: border-box;
  min-height: 62px;
}

/* When summary is visible, give more vertical breathing room */
.chat-sidebar .history-item.has-summary {
  padding: 14px 12px;
  min-height: 92px;
}

/* Elevate item when menu is open so it isn't clipped by siblings */
.chat-sidebar .history-item:has(.history-menu.open),
.chat-sidebar .history-item.menu-open {
  z-index: 100;
}

/* Simple hover - no glow */
.chat-sidebar .history-item:hover {
  background: var(--paper-2, #f3f4f6);
}

.chat-sidebar .history-item.active {
  background: var(--chat-accent-soft);
  color: var(--ink, #1b1f24);
}

.chat-sidebar .history-item.pinned {
  background: var(--chat-accent-soft);
}

.chat-sidebar .history-item.pinned::before {
  content: "";
  width: 3px;
  height: calc(100% - 16px);
  position: absolute;
  left: 0;
  top: 8px;
  background: var(--chat-accent);
  border-radius: 0 2px 2px 0;
}

.chat-sidebar .history-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow: visible;
}

.chat-sidebar .history-info strong {
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  color: rgba(27, 31, 36, 0.9) !important;
}

.chat-sidebar .history-meta {
  font-size: 0.75rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  color: rgba(27, 31, 36, 0.6) !important;
}

.chat-sidebar .history-summary {
  font-size: 0.72rem;
  color: rgba(27, 31, 36, 0.5) !important;
  line-height: 1.45;
  word-break: break-word;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 2px;
  padding-top: 6px;
  border-top: 1px solid rgba(27, 31, 36, 0.06);
}

.chat-sidebar .history-item.has-summary .history-summary {
  min-height: 2.9em;
}

.chat-sidebar .history-item.summary-editing .history-summary {
  display: block !important;
  -webkit-line-clamp: initial;
  line-clamp: initial;
  -webkit-box-orient: vertical;
  overflow: visible;
  max-height: none;
  border-top: none;
  margin-top: 4px;
  padding-top: 0;
}

.chat-sidebar .summary-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 58px;
  border: 1px solid rgba(27, 31, 36, 0.15);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.78rem;
  line-height: 1.4;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink, #1b1f24);
  resize: none;
}

.chat-sidebar .summary-input:focus {
  outline: none;
  border-color: rgba(43, 180, 168, 0.45);
  box-shadow: 0 0 0 2px rgba(43, 180, 168, 0.12);
}

.chat-sidebar .history-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 6px;
  margin-top: 1px;
  opacity: 1;
  align-self: flex-start;
}

.chat-sidebar .history-item:hover .history-actions {
  opacity: 1;
}

.chat-sidebar .history-menu-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: rgba(27, 31, 36, 0.6);
  cursor: pointer;
  border-radius: 6px;
}

.chat-sidebar .history-menu-btn:hover {
  background: rgba(27, 31, 36, 0.08);
  color: var(--ink, #1b1f24);
}

.chat-sidebar .history-menu {
  position: absolute;
  right: 8px;
  top: 100%;
  background: var(--surface, #fff);
  border: 1px solid var(--border-default, rgba(27, 31, 36, 0.12));
  border-radius: 8px;
  padding: 4px;
  min-width: 120px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all 0.2s ease;
}

.chat-sidebar .history-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Override shared "open upwards" rule; handle direction via JS instead */
.chat-sidebar .history-item:nth-last-child(-n+3) .history-menu {
  top: 100%;
  bottom: auto;
  margin-bottom: 0;
}

.chat-sidebar .history-menu.drop-up {
  top: auto;
  bottom: 100%;
  margin-bottom: 6px;
  transform: translateY(4px);
}

.chat-sidebar .history-menu.drop-up.open {
  transform: translateY(0);
}

/* z-index elevation for menu-open handled above (line ~230) */
.chat-sidebar .history-item.menu-open {
  z-index: 100;
}

.chat-sidebar .history-menu button {
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: rgba(27, 31, 36, 0.85);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.chat-sidebar .history-menu button:hover {
  background: rgba(27, 31, 36, 0.06);
}

.chat-sidebar .history-menu button.danger {
  color: var(--danger, #ef4444);
}

.chat-sidebar .history-menu button.danger:hover {
  background: rgba(239, 68, 68, 0.12);
}

/* Empty State */
.chat-sidebar .history-empty {
  text-align: center;
  color: rgba(27, 31, 36, 0.45);
  font-size: 0.85rem;
  padding: 20px;
  margin: 0;
}

/* Load More Button */
.chat-sidebar .load-more-btn {
  display: block;
  width: calc(100% - 16px);
  margin: 8px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(27, 31, 36, 0.12);
  border-radius: 8px;
  color: rgba(27, 31, 36, 0.7);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-sidebar .load-more-btn:hover:not(:disabled) {
  background: var(--surface, #fff);
  border-color: rgba(43, 180, 168, 0.4);
  color: var(--ink, #1b1f24);
}

.chat-sidebar .load-more-btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* Sidebar Footer - uses shared styles from styles.css */

/* Guest/User visibility */
.chat-sidebar .guest-only {
  display: flex;
}

.chat-sidebar .user-only {
  display: none;
}

/* ================================================
   Main Chat Area
   ================================================ */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--paper, #f9fafb);
  position: relative;
}

.chat-main > *:not(.scroll-to-bottom) {
  position: relative;
  z-index: 1;
}

/* Mobile Header (hidden on desktop) */
.mobile-header {
  display: none;
}

/* Quota Warning Bar */
.quota-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-bottom: 1px solid rgba(217, 119, 6, 0.2);
  color: #92400e;
  font-size: 0.875rem;
  font-weight: 500;
}

.quota-warning svg {
  flex-shrink: 0;
  color: #d97706;
}

.quota-warning span {
  flex: 1;
}

.quota-warning-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: #92400e;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.2s;
}

.quota-warning-close:hover {
  background: rgba(146, 64, 14, 0.1);
}

/* Dark mode quota warning */
[data-theme="dark"] .quota-warning {
  background: linear-gradient(135deg, #422006 0%, #78350f 100%);
  border-color: rgba(251, 191, 36, 0.2);
  color: #fcd34d;
}

[data-theme="dark"] .quota-warning svg {
  color: #fbbf24;
}

[data-theme="dark"] .quota-warning-close {
  color: #fcd34d;
}

[data-theme="dark"] .quota-warning-close:hover {
  background: rgba(251, 191, 36, 0.15);
}

/* Chat Header */
.chat-page .chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface, #fff);
  border-bottom: 1px solid var(--chat-border);
  min-height: 52px;
}

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

/* .sidebar-collapse-btn uses shared styles from styles.css */

.chat-page .chat-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink, #1b1f24);
  margin: 0;
}

/* Connection Status Indicator - Hidden by default, shows on hover or offline */
.chat-page .connection-status {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted, #9ca3af);
  transition: opacity 0.2s ease;
  margin-left: 8px;
}

.chat-page .connection-status.offline {
  display: flex;
  color: #ef4444;
}

.chat-page .connection-status.reconnecting {
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
}

.chat-page .connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  position: relative;
}

.chat-page .connection-status:not(.offline):not(.reconnecting) .connection-dot {
  animation: pulse 2s infinite;
}

.chat-page .connection-status.reconnecting .connection-dot {
  animation: blink 0.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0);
  }
}

@keyframes blink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

.chat-page .connection-text {
  line-height: 1;
}

/* Hide on mobile */
@media (max-width: 768px) {
  .chat-page .connection-status {
    display: none;
  }
}

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

.header-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--muted, #9ca3af);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.12s, color 0.12s;
}

.header-action-btn:hover:not(:disabled) {
  background: var(--paper-2, #f3f4f6);
  color: var(--ink, #1b1f24);
}

.header-action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Export Dropdown */
.chat-page .export-dropdown {
  position: relative;
}

.chat-page .export-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--surface, #fff);
  border-radius: 10px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
  border: 1px solid var(--border-default, rgba(27, 31, 36, 0.12));
  min-width: 180px;
  padding: 4px;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s ease;
}

.chat-page .export-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.chat-page .export-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--ink, #1b1f24);
  border-radius: 8px;
  transition: background 0.15s ease;
  text-align: left;
}

.chat-page .export-option:hover {
  background: rgba(43, 180, 168, 0.08);
}

/* ================================================
   Messages Area
   ================================================ */
.chat-page .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: transparent;
}

.chat-page .load-earlier-indicator {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(27, 31, 36, 0.08);
  color: var(--muted, #667079);
  font-size: 0.85rem;
}

.chat-page .load-earlier-btn {
  border: none;
  background: rgba(var(--theme-accent-rgb, 83, 198, 183), 0.15);
  color: var(--chat-accent-strong, #1f8f84);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.chat-page .load-earlier-btn:hover {
  background: rgba(var(--theme-accent-rgb, 83, 198, 183), 0.25);
  transform: translateY(-1px);
}

/* ================================================
   Bookmarks Panel
   ================================================ */
.bookmark-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: var(--z-modal, 1000);
}

.bookmark-panel-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.bookmark-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;
  width: min(380px, 92vw);
  background: linear-gradient(180deg, #ffffff 0%, #f7f9fb 100%);
  box-shadow: -12px 0 28px rgba(15, 23, 42, 0.14);
  border-left: 1px solid rgba(27, 31, 36, 0.08);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: calc(var(--z-modal, 1000) + 1);
  display: flex;
  flex-direction: column;
}

.bookmark-panel.open {
  transform: translateX(0);
}

.bookmark-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(27, 31, 36, 0.08);
}

.bookmark-panel-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-family: "Space Grotesk", "Inter", sans-serif;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink, #1b1f24);
}

.bookmark-panel-close {
  border: none;
  background: rgba(15, 23, 42, 0.06);
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.bookmark-panel-close:hover {
  background: rgba(15, 23, 42, 0.12);
  transform: translateY(-1px);
}

.bookmark-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 0;
}

.bookmark-panel-status {
  display: none;
  color: var(--muted, #667079);
  font-size: 0.9rem;
  padding: 8px 0;
}

.bookmark-panel-status.show {
  display: block;
}

.bookmark-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bookmark-item {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(27, 31, 36, 0.08);
  border-radius: 12px;
  padding: 12px 12px 10px;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.06);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bookmark-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.bookmark-item-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink, #1b1f24);
}

.bookmark-item-time {
  font-size: 0.75rem;
  color: var(--muted, #667079);
}

.bookmark-item-content {
  font-size: 0.85rem;
  color: var(--ink, #1b1f24);
  line-height: 1.4;
  max-height: 4.2em;
  overflow: hidden;
}

.bookmark-item-actions {
  display: flex;
  justify-content: flex-end;
}

.bookmark-item-actions button {
  border: none;
  background: rgba(var(--theme-accent-rgb, 83, 198, 183), 0.15);
  color: var(--chat-accent-strong, #1f8f84);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  cursor: pointer;
}

.bookmark-item-actions button:hover {
  background: rgba(var(--theme-accent-rgb, 83, 198, 183), 0.25);
}

.bookmark-panel-footer {
  padding: 12px 18px 18px;
  border-top: 1px solid rgba(27, 31, 36, 0.08);
  display: flex;
  justify-content: flex-end;
}

.bookmark-panel-footer .btn {
  font-size: 0.85rem;
}

.message.bookmark-highlight .message-content {
  box-shadow: 0 0 0 3px rgba(var(--theme-accent-rgb, 83, 198, 183), 0.35);
  transition: box-shadow 0.3s ease;
}

.chat-page .chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-page .chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-page .chat-messages::-webkit-scrollbar-thumb {
  background: rgba(27, 31, 36, 0.15);
  border-radius: 4px;
}

.chat-sidebar .history-item:focus-visible,
.chat-sidebar .history-menu-btn:focus-visible,
.chat-sidebar .load-more-btn:focus-visible,
.chat-page .load-earlier-btn:focus-visible {
  outline: 2px solid var(--chat-accent-strong, #1f8f84);
  outline-offset: 2px;
}

/* Message Bubbles */
.chat-page .message {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px;
  animation: messageSlide 0.2s ease-out;
  box-sizing: border-box;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  position: relative;
}

body.selection-mode .chat-page .message {
  padding-left: 48px;
}

.message-select {
  position: absolute;
  left: 20px;
  top: 16px;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid var(--chat-border);
  background: #fff;
  cursor: pointer;
  display: none;
}

body.selection-mode .message-select {
  display: inline-block;
}

.message-select:checked {
  accent-color: var(--chat-accent);
}

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

.chat-page .message.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.chat-page .message.user .message-content {
  background: var(--chat-accent);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 12px 16px;
  max-width: 70%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  border: none;
  box-shadow: none;
}

.chat-page .message.user .message-content p {
  margin: 0;
  line-height: 1.5;
}

.chat-page .message.assistant {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.chat-page .message.assistant .message-content {
  background: var(--surface, #fff);
  border: 1px solid var(--chat-border);
  border-radius: 18px 18px 18px 4px;
  padding: 14px 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  max-width: 85%;
  line-height: 1.6;
  color: var(--ink, #1b1f24);
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
}

body.selection-mode .message.selected .message-content {
  box-shadow: 0 0 0 2px rgba(var(--theme-accent-rgb, 83, 198, 183), 0.45);
}

.chat-page .message.assistant .message-content p {
  margin: 0 0 12px;
}

.chat-page .message.assistant .message-content p:last-child {
  margin-bottom: 0;
}

.chat-page .message.assistant .message-content code {
  background: rgba(43, 180, 168, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.9em;
  word-break: break-word;
}

/* Code Block Wrapper with Header */
.chat-page .message.assistant .message-content .code-block-wrapper {
  margin: 12px 0;
  border-radius: 12px;
  overflow: hidden;
  background: #1e1e2e;
}

.chat-page .message.assistant .message-content .code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-page .message.assistant .message-content .code-block-lang {
  font-size: 12px;
  font-weight: 500;
  color: rgba(205, 214, 244, 0.7);
  text-transform: lowercase;
  font-family: 'SF Mono', Monaco, monospace;
}

.chat-page .message.assistant .message-content .code-block-copy {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: rgba(205, 214, 244, 0.5);
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
}

.chat-page .message.assistant .message-content .code-block-copy:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(205, 214, 244, 0.9);
}

.chat-page .message.assistant .message-content .code-block-copy.copied {
  color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
}

.chat-page .message.assistant .message-content .code-block-wrapper pre {
  margin: 0;
  border-radius: 0;
  background: transparent;
}

.chat-page .message.assistant .message-content pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 16px;
  border-radius: 12px;
  overflow-x: auto;
  margin: 12px 0;
}

.chat-page .message.assistant .message-content pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

/* Follow-up Suggestions */
.chat-page .follow-up-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 6px 20px 12px;
  animation: fadeIn 0.2s ease-out;
}

.chat-page .follow-up-chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  background: var(--surface, #fff);
  border: 1px solid var(--chat-border);
  border-radius: 18px;
  font-size: 0.85rem;
  color: var(--ink, #1b1f24);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  text-align: left;
  max-width: 100%;
  word-break: break-word;
}

.chat-page .follow-up-chip:hover {
  background: var(--chat-accent-soft);
  border-color: var(--chat-accent);
}

.chat-page .follow-up-chip:active {
  background: var(--chat-accent-soft-strong);
}

/* Dark mode follow-up chips */
[data-theme="dark"] .chat-page .follow-up-chip {
  background: var(--surface, #18181f);
  border-color: rgba(255, 255, 255, 0.08);
  color: var(--ink, #e5e5e5);
}

[data-theme="dark"] .chat-page .follow-up-chip:hover {
  background: rgba(62, 180, 169, 0.12);
  border-color: var(--chat-accent);
}

/* Continue Generation Button */
.chat-page .continue-generation-container {
  display: flex;
  justify-content: center;
  padding: 8px 20px 16px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}

.chat-page .continue-generation-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: linear-gradient(135deg, rgba(43, 180, 168, 0.15) 0%, rgba(243, 139, 99, 0.12) 100%);
  border: 1px solid rgba(43, 180, 168, 0.35);
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--chat-accent-strong, #1f8f84);
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-page .continue-generation-btn:hover {
  background: linear-gradient(135deg, rgba(43, 180, 168, 0.25) 0%, rgba(243, 139, 99, 0.18) 100%);
  border-color: rgba(43, 180, 168, 0.5);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(43, 180, 168, 0.2);
}

.chat-page .continue-generation-btn:active {
  transform: translateY(0);
}

.chat-page .continue-generation-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  stroke: none;
}

/* Dark mode continue button */
[data-theme="dark"] .chat-page .continue-generation-btn {
  background: linear-gradient(135deg, rgba(43, 180, 168, 0.2) 0%, rgba(243, 139, 99, 0.15) 100%);
  border-color: rgba(43, 180, 168, 0.4);
  color: #53c6b7;
}

[data-theme="dark"] .chat-page .continue-generation-btn:hover {
  background: linear-gradient(135deg, rgba(43, 180, 168, 0.3) 0%, rgba(243, 139, 99, 0.22) 100%);
  border-color: rgba(43, 180, 168, 0.6);
}

/* Message Actions */
.chat-page .message-actions {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.chat-page .message:hover .message-actions {
  opacity: 1;
}

.chat-page .message-action-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--muted, #9ca3af);
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
}

.chat-page .message-action-btn:hover {
  background: var(--chat-accent-soft);
  color: var(--chat-accent);
}

.chat-page .message-action-btn.copied {
  background: var(--chat-accent-soft);
  color: var(--chat-accent);
}

/* Message Reaction Buttons */
.chat-page .message-reactions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
  padding-left: 6px;
  border-left: 1px solid rgba(27, 31, 36, 0.1);
}

.chat-page .reaction-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--muted, #667079);
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s, transform 0.15s;
}

.chat-page .reaction-btn:hover {
  background: rgba(43, 180, 168, 0.12);
  color: var(--chat-accent, #2bb4a8);
  transform: scale(1.1);
}

.chat-page .reaction-btn.active {
  color: #2bb4a8;
  background: rgba(43, 180, 168, 0.18);
}

.chat-page .reaction-btn.active[data-reaction="helpful"] {
  color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
}

.chat-page .reaction-btn.active[data-reaction="not_helpful"] {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

.chat-page .bookmark-btn.active {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.15);
}

.chat-page .bookmark-btn:hover {
  color: #f59e0b;
}

/* Template Indicator Styles */
.chat-page .template-indicator {
  display: flex;
  justify-content: center;
  padding: 8px 16px 0;
}

.chat-page .template-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  background: rgba(43, 180, 168, 0.12);
  border: 1px solid rgba(43, 180, 168, 0.22);
  border-radius: 16px;
  font-size: 12px;
  color: var(--chat-accent, #2bb4a8);
}

.chat-page .template-icon {
  font-size: 14px;
}

.chat-page .template-name {
  font-weight: 500;
}

.chat-page .template-clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  background: transparent;
  color: var(--chat-accent, #2bb4a8);
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.2s;
  margin-left: 2px;
}

.chat-page .template-clear-btn:hover {
  background: rgba(43, 180, 168, 0.2);
}

/* Template Modal Styles */
.template-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

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

.template-modal-content {
  background: var(--surface, white);
  border-radius: 16px;
  width: 90%;
  max-width: 480px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  animation: slideUp 0.3s ease;
}

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

.template-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-default, rgba(20, 19, 32, 0.1));
}

.template-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--ink, #1f2937);
}

.template-modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--muted, #6b7280);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
}

.template-modal-close:hover {
  background: var(--paper-2, #f3f4f6);
  color: var(--ink, #1f2937);
}

.template-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.template-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.template-item:hover {
  background: var(--paper-2, #f3f4f6);
}

.template-item.active {
  background: rgba(43, 180, 168, 0.1);
  border: 1px solid rgba(43, 180, 168, 0.3);
}

.template-item-icon {
  font-size: 24px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper-2, #f3f4f6);
  border-radius: 10px;
}

.template-item.active .template-item-icon {
  background: rgba(43, 180, 168, 0.15);
}

.template-item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.template-item-name {
  font-weight: 500;
  color: var(--ink, #1f2937);
}

.template-custom-badge {
  font-size: 11px;
  color: var(--muted, #6b7280);
}

.template-delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--muted, #9ca3af);
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
}

.template-delete-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.template-modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-default, rgba(20, 19, 32, 0.1));
  display: flex;
  justify-content: flex-end;
}

/* Streaming Message Styles */
.chat-page .message.assistant.streaming {
  opacity: 0.95;
}

/* Streaming cursor animation */
.chat-page .streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: currentColor;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursor-blink 0.8s ease-in-out infinite;
}

@keyframes cursor-blink {
  0%, 50% {
    opacity: 1;
  }
  51%, 100% {
    opacity: 0;
  }
}

/* Ensure streaming content renders properly */
.chat-page .streaming-content {
  min-height: 1.5em;
}

/* Make cursor appear inline with last paragraph */
.chat-page .streaming-content > *:last-of-type:not(.streaming-cursor) {
  display: inline;
}

/* Typing Indicator */
.chat-page .typing-indicator {
  display: none;
  align-items: center;
  gap: 3px;
  padding: 10px 20px;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

.chat-page .typing-indicator.show {
  display: flex;
}

.chat-page .typing-indicator span:not(.typing-text) {
  width: 6px;
  height: 6px;
  background: var(--chat-accent);
  border-radius: 50%;
  animation: typingBounce 1.2s ease infinite;
  opacity: 0.7;
}

.chat-page .typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-page .typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

.chat-page .typing-text {
  font-size: 0.8rem;
  color: var(--muted, #9ca3af);
  margin-left: 6px;
}

/* ================================================
   Chat Input Area
   ================================================ */
.chat-input-wrapper {
  flex-shrink: 0;
  padding: 8px 20px 20px;
  background: linear-gradient(180deg, transparent 0%, rgba(249, 250, 251, 0.72) 16%, var(--paper, #f9fafb) 52%);
  position: relative;
  z-index: 10;
}

.selection-toolbar {
  max-width: 760px;
  margin: 0 auto 12px;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(27, 31, 36, 0.12);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.selection-toolbar.show {
  display: flex;
}

.selection-count {
  font-size: 0.85rem;
  color: var(--muted, #667079);
}

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

.chat-page .chat-input {
  max-width: 820px;
  margin: 0 auto;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(255, 255, 255, 0.9) 100%);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 22px;
  padding: 0;
  box-shadow:
    0 18px 48px rgba(15, 23, 42, 0.08),
    0 2px 10px rgba(15, 23, 42, 0.04);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 0;
  /* Override shared/styles.css .chat-input generic styles */
  grid-template-columns: unset;
}

.chat-page .chat-input::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, rgba(62, 180, 169, 0.35) 40%, rgba(255, 107, 90, 0.25) 100%);
  pointer-events: none;
}

.chat-page .chat-input:focus-within {
  border-color: rgba(62, 180, 169, 0.22);
  box-shadow:
    0 22px 56px rgba(15, 23, 42, 0.11),
    0 0 0 4px rgba(62, 180, 169, 0.08);
  transform: translateY(-1px);
}

.chat-page .chat-compose {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  min-height: 76px;
}

.compose-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding: 4px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.03);
  border: 1px solid rgba(15, 23, 42, 0.04);
}

.compose-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--muted, #7d8591);
  cursor: pointer;
  border-radius: 12px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.compose-btn:hover {
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink, #1b1f24);
  transform: translateY(-1px);
}

.compose-btn input[type="file"] {
  display: none;
}

.compose-input-shell {
  flex: 1;
  min-width: 0;
  min-height: 52px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(250, 251, 252, 0.96) 100%);
  border: 1px solid rgba(15, 23, 42, 0.06);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    inset 0 -1px 0 rgba(15, 23, 42, 0.02);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.chat-page .chat-input:focus-within .compose-input-shell {
  border-color: rgba(62, 180, 169, 0.2);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 0 0 3px rgba(62, 180, 169, 0.06);
}

.chat-page .chat-compose textarea {
  flex: 1;
  box-sizing: border-box;
  border: none;
  border-radius: 0;
  background: transparent;
  font-size: 0.97rem;
  line-height: 1.45;
  resize: none;
  max-height: 180px;
  min-height: 28px;
  padding: 12px 0;
  font-family: inherit;
  color: var(--ink, #1b1f24);
  overflow-y: hidden;
  outline: none;
  box-shadow: none;
  font-weight: 500;
}

.chat-page .chat-compose textarea::placeholder {
  color: #8f96a3;
  font-weight: 500;
}

.chat-page .chat-compose textarea:focus {
  outline: none;
  border: none;
  background: transparent;
  box-shadow: none;
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: none;
  background: linear-gradient(135deg, var(--chat-accent) 0%, #79d5cc 100%);
  color: #fff;
  cursor: pointer;
  border-radius: 16px;
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  flex-shrink: 0;
  box-shadow: 0 8px 18px rgba(62, 180, 169, 0.22);
}

.send-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--chat-accent-strong) 0%, #61c7bc 100%);
  transform: translateY(-1px);
  box-shadow: 0 12px 22px rgba(62, 180, 169, 0.28);
}

.send-btn:disabled {
  opacity: 0.55;
  background: linear-gradient(135deg, #d4e9e6 0%, #c9dfdd 100%);
  color: rgba(255, 255, 255, 0.88);
  box-shadow: none;
  cursor: not-allowed;
}

.send-btn.stop-btn {
  background: #ef4444;
}

.send-btn.stop-btn:hover {
  background: #dc2626;
}

/* Template Dropdown */
.chat-page .template-dropdown {
  position: relative;
}

.chat-page .template-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 8px;
  background: var(--surface, #fff);
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
  border: 1px solid var(--border-default, rgba(27, 31, 36, 0.12));
  min-width: 180px;
  padding: 6px;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: all 0.2s ease;
}

.chat-page .template-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.chat-page .template-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--ink, #1b1f24);
  border-radius: 8px;
  transition: background 0.15s ease;
  text-align: left;
}

.chat-page .template-option:hover {
  background: rgba(43, 180, 168, 0.08);
}

.chat-page .template-icon {
  font-size: 1rem;
}

.chat-page .template-label {
  font-weight: 500;
}

/* Drop Zone */
.chat-page .drop-zone {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(43, 180, 168, 0.08);
  border: 2px dashed rgba(43, 180, 168, 0.35);
  border-radius: 22px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #2bb4a8;
  font-weight: 500;
  z-index: 10;
}

.chat-page .drop-zone.dragover {
  display: flex;
}

/* Attachment Preview */
.chat-page .attachment-preview {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 12px 2px;
}

.chat-page .attachment-preview:has(.attachment-item) {
  display: flex;
}

.chat-page .attachment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(43, 180, 168, 0.1);
  border: 1px solid rgba(43, 180, 168, 0.18);
  border-radius: 8px;
  font-size: 0.85rem;
}

.chat-page .attachment-remove {
  width: 20px;
  height: 20px;
  border: none;
  background: rgba(27, 31, 36, 0.08);
  color: var(--muted, #667079);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: background 0.2s;
}

.chat-page .attachment-remove:hover {
  background: rgba(255, 107, 90, 0.2);
  color: #ff6b5a;
}

/* Failed Upload State */
.chat-page .attachment-item.upload-failed {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.chat-page .attachment-item .upload-error-text {
  color: #dc2626;
  font-weight: 500;
}

.chat-page .attachment-retry {
  padding: 4px 10px;
  margin-top: 4px;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.chat-page .attachment-retry:hover:not(:disabled) {
  background: #b91c1c;
}

.chat-page .attachment-retry:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Disclaimer */
.chat-disclaimer {
  text-align: center;
  font-size: 0.74rem;
  color: rgba(102, 112, 121, 0.82);
  margin: 10px 0 0;
  line-height: 1.45;
  letter-spacing: 0.01em;
}

/* ================================================
   Loading States
   ================================================ */
.chat-page .loading-overlay {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
}

.chat-page .loading-overlay.show {
  display: flex;
}

.chat-page .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(43, 180, 168, 0.2);
  border-top-color: #2bb4a8;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.chat-page .spinner-small {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

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

.chat-page .loading-text {
  font-size: 0.85rem;
  color: var(--muted, #667079);
}

/* ================================================
   Modal Styles
   ================================================ */
.chat-page .modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal, 1000);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.chat-page .modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.chat-page .modal-card {
  background: var(--surface, #fff);
  border-radius: 16px;
  padding: 32px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  transform: scale(0.95);
  transition: transform 0.3s ease;
}

.chat-page .modal-overlay.show .modal-card {
  transform: scale(1);
}

.chat-page .modal-icon {
  width: 64px;
  height: 64px;
  background: rgba(255, 107, 90, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  color: #ff6b5a;
}

.chat-page .modal-content h3 {
  font-size: 1.25rem;
  margin: 0 0 8px;
  color: var(--ink, #1b1f24);
}

.chat-page .modal-content p {
  font-size: 0.9rem;
  color: var(--muted, #667079);
  margin: 0 0 24px;
  line-height: 1.5;
}

.chat-page .modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.chat-page .modal-actions .btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-page .modal-actions .btn.secondary {
  background: rgba(27, 31, 36, 0.06);
  border: none;
  color: var(--ink, #1b1f24);
}

.chat-page .modal-actions .btn.secondary:hover {
  background: rgba(27, 31, 36, 0.1);
}

.chat-page .modal-actions .btn.danger {
  background: #ff6b5a;
  border: none;
  color: #fff;
}

.chat-page .modal-actions .btn.danger:hover {
  background: #e55a4a;
}

/* ================================================
   Mobile Responsive
   ================================================ */
.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-overlay, 90);
}

/* Tablet breakpoint - reduced sidebar width */
@media (max-width: 1024px) {
  .chat-sidebar {
    width: 256px;
    min-width: 256px;
  }
}

/* Mobile breakpoint - sidebar overlay */
@media (max-width: 768px) {
  .chat-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    min-width: 280px;
    transform: translateX(-100%);
    z-index: var(--z-sidebar, 100);
    transition: transform 0.3s ease;
  }

  /* Override collapsed state on mobile - use transform instead of width */
  .chat-sidebar.collapsed,
  body.sidebar-collapsed .chat-sidebar {
    width: 280px;
    min-width: 280px;
    overflow: visible;
  }

  .chat-sidebar.open {
    transform: translateX(0);
  }

  .mobile-overlay.show {
    display: block;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--surface, #fff);
    border-bottom: 1px solid var(--chat-border);
  }

  .mobile-menu-btn,
  .mobile-new-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--ink, #1b1f24);
    cursor: pointer;
    border-radius: 8px;
  }

  .mobile-title {
    font-weight: 600;
    font-size: 1rem;
  }

  .chat-page .chat-header {
    display: none;
  }

  .chat-page .chat-messages {
    padding: 12px 14px;
    gap: 12px;
  }

  .chat-page .message {
    padding: 0;
  }

  .chat-page .message.user .message-content,
  .chat-page .message.assistant .message-content {
    max-width: 88%;
  }

  .chat-input-wrapper {
    padding: 0 12px 14px;
  }

  .chat-page .chat-compose {
    padding: 8px;
    gap: 8px;
    min-height: 64px;
  }

  .compose-actions {
    display: none;
  }

  .compose-input-shell {
    min-height: 48px;
    border-radius: 14px;
    padding: 0 12px;
  }

  .send-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
  }

  .chat-page .chat-compose textarea {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 11px 0;
  }

  /* Larger touch targets for mobile accessibility (WCAG 2.1 Level AAA: 44x44px) */
  .chat-sidebar .history-menu-btn {
    width: 44px;
    height: 44px;
    margin: -8px;
    padding: 8px;
  }

  .chat-sidebar .history-item {
    min-height: 64px;
    padding: 14px 12px;
  }

  .chat-sidebar .history-item.has-summary {
    min-height: 98px;
    padding: 16px 12px;
  }

  .chat-sidebar .history-actions {
    opacity: 1; /* Always visible on mobile for better discoverability */
  }
}

/* ================================================
   Sidebar Collapsed State
   ================================================ */
body.sidebar-collapsed .chat-sidebar {
  transform: translateX(-100%);
  margin-left: -272px;
  will-change: transform, margin;
}

body.sidebar-collapsed .sidebar-collapse-btn svg {
  transform: scaleX(-1);
}

/* Pin Indicator */
.chat-sidebar .pin-indicator {
  display: none;
  color: #ff6b5a;
  margin-right: 6px;
}

.chat-sidebar .history-item.pinned .pin-indicator {
  display: inline-flex;
}

.chat-sidebar .history-title-wrap {
  display: flex;
  align-items: center;
  min-width: 0;
}

.chat-sidebar .history-title-wrap strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Rename input */
.chat-sidebar .rename-input {
  width: 100%;
  padding: 4px 8px;
  background: var(--surface, #fff);
  border: 1px solid rgba(43, 180, 168, 0.4);
  border-radius: 4px;
  color: var(--ink, #1b1f24);
  font-size: 0.875rem;
  font-weight: 500;
  outline: none;
}

.chat-sidebar .rename-input:focus {
  background: var(--surface, #fff);
  border-color: rgba(43, 180, 168, 0.6);
}

.chat-sidebar .history-item.renaming {
  pointer-events: auto;
}

.chat-sidebar .history-item.renaming .history-actions {
  display: none;
}

/* ==============================================
   DARK MODE OVERRIDES
   ============================================== */
[data-theme="dark"] .chat-page {
  background: var(--paper, #0f0f14);
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .chat-sidebar {
  background: var(--surface, #18181f);
  color: var(--ink, #f0eff4);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .chat-sidebar a,
[data-theme="dark"] .chat-sidebar button,
[data-theme="dark"] .chat-sidebar span,
[data-theme="dark"] .chat-sidebar p,
[data-theme="dark"] .chat-sidebar strong {
  color: var(--ink-2, #b8b5c4);
}

[data-theme="dark"] .sidebar-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .sidebar-brand {
  color: #fff;
}

[data-theme="dark"] .new-chat-btn {
  background: var(--chat-accent);
  border: none;
  color: #fff;
}

[data-theme="dark"] .new-chat-btn:hover {
  background: var(--chat-accent-strong);
}

[data-theme="dark"] .sidebar-search .search-icon {
  color: rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .sidebar-search input {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: #fff;
}

[data-theme="dark"] .sidebar-search input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .sidebar-search input:focus {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(43, 180, 168, 0.5);
}

[data-theme="dark"] .chat-sidebar .history-list {
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

[data-theme="dark"] .chat-sidebar .history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .chat-sidebar .history-item {
  color: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] .chat-sidebar .history-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .chat-sidebar .history-item.active {
  background: rgba(43, 180, 168, 0.2);
  color: #fff;
}

[data-theme="dark"] .chat-sidebar .history-info strong {
  color: rgba(255, 255, 255, 0.95) !important;
}

[data-theme="dark"] .chat-sidebar .history-meta {
  color: rgba(255, 255, 255, 0.7) !important;
}

[data-theme="dark"] .chat-sidebar .history-summary {
  color: rgba(255, 255, 255, 0.55) !important;
  border-top-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .chat-sidebar .summary-input {
  background: rgba(17, 24, 39, 0.85);
  border-color: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.9);
}

[data-theme="dark"] .chat-sidebar .history-menu-btn {
  color: rgba(255, 255, 255, 0.7);
}

[data-theme="dark"] .chat-sidebar .history-menu-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

[data-theme="dark"] .chat-sidebar .history-menu {
  background: #1b1f28;
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] .chat-sidebar .history-menu button {
  color: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] .chat-sidebar .history-menu button:hover {
  background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .chat-sidebar .history-empty {
  color: rgba(255, 255, 255, 0.45);
}

[data-theme="dark"] .chat-sidebar .load-more-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.75);
}

[data-theme="dark"] .chat-sidebar .load-more-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(43, 180, 168, 0.4);
  color: #fff;
}

[data-theme="dark"] .chat-sidebar .rename-input {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(43, 180, 168, 0.5);
  color: #fff;
}

[data-theme="dark"] .chat-sidebar .rename-input:focus {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(43, 180, 168, 0.7);
}

[data-theme="dark"] .chat-main {
  background: var(--paper, #0f0f14);
}

/* Chat Header */
[data-theme="dark"] .chat-page .chat-header {
  background: var(--surface, #18181f);
  border-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .chat-page .chat-title {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .header-action-btn {
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .header-action-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink, #f0eff4);
}

/* Export Menu */
[data-theme="dark"] .chat-page .export-menu {
  background: var(--paper-2, #1a1a24);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .chat-page .export-option {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .chat-page .export-option:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Messages Area */
[data-theme="dark"] .chat-messages {
  background: transparent;
}

[data-theme="dark"] .chat-page .chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .chat-page .message.assistant .message-content {
  background: var(--paper-2, #1a1a24);
  border-color: rgba(255, 255, 255, 0.08);
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .chat-page .message.assistant .message-content code {
  background: rgba(43, 180, 168, 0.15);
}

/* Chat Input Area */
[data-theme="dark"] .chat-input-container {
  background: rgba(26, 26, 36, 0.9);
  border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chat-page .chat-input {
  background: var(--surface, #18181f);
  border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .chat-page .chat-input:focus-within {
  border-color: var(--chat-accent);
  box-shadow: 0 0 0 2px rgba(62, 180, 169, 0.15);
}

[data-theme="dark"] .compose-actions {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .compose-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .compose-input-shell {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02) 0%, rgba(255, 255, 255, 0.01) 100%);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .chat-page .chat-input:focus-within .compose-input-shell {
  border-color: rgba(62, 180, 169, 0.26);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 0 0 3px rgba(62, 180, 169, 0.08);
}

[data-theme="dark"] .chat-page .chat-compose textarea {
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--ink, #e5e5e5);
}

[data-theme="dark"] .chat-page .chat-compose textarea:focus {
  background: transparent;
  border: none;
  box-shadow: none;
  outline: none;
}

[data-theme="dark"] .chat-input-wrapper {
  background: linear-gradient(180deg, transparent 0%, var(--paper, #0f0f14) 30%);
}

[data-theme="dark"] .selection-toolbar {
  background: var(--paper-2, #1a1a24);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

[data-theme="dark"] .selection-count {
  color: rgba(255, 255, 255, 0.7);
}

[data-theme="dark"] .message-select {
  background: rgba(17, 24, 39, 0.9);
  border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .chat-page textarea {
  background: transparent;
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .compose-btn {
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .compose-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink, #f0eff4);
}

/* Template Menu */
[data-theme="dark"] .chat-page .template-menu {
  background: var(--paper-2, #1a1a24);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .chat-page .template-option {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .chat-page .template-option:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Attachment Preview */
[data-theme="dark"] .chat-page .attachment-item {
  background: rgba(43, 180, 168, 0.12);
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .chat-page .attachment-remove {
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .chat-page .attachment-remove:hover {
  background: rgba(255, 107, 90, 0.2);
  color: var(--accent, #ff6b5a);
}

[data-theme="dark"] .chat-page .attachment-item.upload-failed {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
}

[data-theme="dark"] .chat-page .attachment-item .upload-error-text {
  color: #f87171;
}

[data-theme="dark"] .chat-disclaimer {
  color: var(--muted, #8a8698);
}

/* Loading States */
[data-theme="dark"] .chat-page .loading-text {
  color: var(--muted, #8a8698);
}

/* Modal */
[data-theme="dark"] .chat-page .modal-overlay {
  background: rgba(0, 0, 0, 0.7);
}

[data-theme="dark"] .chat-page .modal-card {
  background: var(--paper-2, #1a1a24);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chat-page .modal-content {
  background: var(--paper-2, #1a1a24);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chat-page .modal-card h3 {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .chat-page .modal-card p {
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .bookmark-panel {
  background: linear-gradient(180deg, #171923 0%, #111827 100%);
  border-left-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .bookmark-panel-header {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .bookmark-panel-header h3 {
  color: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] .bookmark-panel-close {
  background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .bookmark-panel-close:hover {
  background: rgba(255, 255, 255, 0.16);
}

[data-theme="dark"] .bookmark-item {
  background: rgba(17, 24, 39, 0.9);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

[data-theme="dark"] .bookmark-item-title,
[data-theme="dark"] .bookmark-item-content {
  color: rgba(255, 255, 255, 0.9);
}

[data-theme="dark"] .bookmark-item-time,
[data-theme="dark"] .bookmark-panel-status {
  color: rgba(255, 255, 255, 0.6);
}

[data-theme="dark"] .bookmark-panel-footer {
  border-top-color: rgba(255, 255, 255, 0.08);
}

/* Welcome Screen */
[data-theme="dark"] .chat-welcome {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .chat-welcome p {
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .quick-action {
  background: var(--paper-2, #1a1a24);
  border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .quick-action:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .quick-action h4,
[data-theme="dark"] .quick-action-title {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .quick-action p,
[data-theme="dark"] .quick-action-desc {
  color: var(--muted, #8a8698);
}

/* Scroll to Bottom */
[data-theme="dark"] .scroll-to-bottom {
  background: var(--paper-2, #1a1a24);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--ink, #f0eff4);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Keyboard Hint */
[data-theme="dark"] .keyboard-hint {
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .keyboard-hint kbd {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--ink, #f0eff4);
}

/* Shortcuts Modal */
[data-theme="dark"] .shortcuts-content {
  background: var(--paper-2, #1a1a24);
  box-shadow:
    0 24px 48px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .shortcuts-header {
  background: linear-gradient(135deg, rgba(43, 180, 168, 0.12) 0%, rgba(243, 139, 99, 0.12) 100%);
  border-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .shortcuts-header h3 {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .shortcuts-subtitle {
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .shortcuts-close {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .shortcuts-close:hover {
  background: rgba(255, 255, 255, 0.15);
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .shortcuts-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .shortcuts-section-title {
  color: var(--muted, #6b6a7a);
}

[data-theme="dark"] .shortcuts-list {
  background: rgba(255, 255, 255, 0.02);
}

[data-theme="dark"] .shortcut-item:hover {
  background: rgba(43, 180, 168, 0.1);
}

[data-theme="dark"] .shortcut-label {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .shortcut-keys kbd {
  background: linear-gradient(180deg, #2a2a3a 0%, #222232 100%);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--ink, #e0e0e8);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.05),
    0 2px 4px rgba(0, 0, 0, 0.2);
  text-shadow: none;
}

[data-theme="dark"] .shortcut-keys kbd.mod-key {
  background: linear-gradient(180deg, #333345 0%, #2a2a3a 100%);
}

[data-theme="dark"] .shortcuts-footer {
  background: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .shortcuts-footer-text {
  color: var(--muted, #6b6a7a);
}

[data-theme="dark"] .shortcuts-footer kbd {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--muted, #8a8698);
}

/* Mobile Header */
[data-theme="dark"] .mobile-header {
  background: var(--surface, #18181f);
  border-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .mobile-menu-btn,
[data-theme="dark"] .mobile-new-btn {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .mobile-title {
  color: var(--ink, #f0eff4);
}

/* Template Modal */
[data-theme="dark"] .template-modal {
  background: rgba(0, 0, 0, 0.7);
}

[data-theme="dark"] .template-modal-content {
  background: var(--paper-2, #1a1a24);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .template-modal-header {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .template-modal-header h3 {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .template-modal-close {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .template-modal-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .template-item {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .template-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .template-item.active {
  background: rgba(43, 180, 168, 0.15);
  border-color: rgba(43, 180, 168, 0.35);
}

[data-theme="dark"] .template-item-icon {
  background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .template-item.active .template-item-icon {
  background: rgba(43, 180, 168, 0.2);
}

[data-theme="dark"] .template-item-name {
  color: var(--ink, #f0eff4);
}

[data-theme="dark"] .template-custom-badge {
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .template-delete-btn {
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .template-delete-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

[data-theme="dark"] .template-modal-footer {
  border-top-color: rgba(255, 255, 255, 0.08);
}

/* Message Action Buttons - Dark Mode */
[data-theme="dark"] .chat-page .message-action-btn {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .chat-page .message-action-btn:hover {
  background: rgba(43, 180, 168, 0.15);
  color: var(--chat-accent, #2bb4a8);
}

[data-theme="dark"] .chat-page .message-action-btn.copied {
  background: rgba(43, 180, 168, 0.2);
  color: #2bb4a8;
}

[data-theme="dark"] .chat-page .message-reactions {
  border-left-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chat-page .reaction-btn {
  color: var(--muted, #8a8698);
}

[data-theme="dark"] .chat-page .reaction-btn:hover {
  background: rgba(43, 180, 168, 0.15);
  color: var(--chat-accent, #2bb4a8);
}

/* ================================================
   Welcome Screen
   ================================================ */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px 40px;
  text-align: center;
  max-width: 960px;
  margin: 0 auto;
  min-height: 55vh;
  animation: fadeIn 0.25s ease-out;
}

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

.chat-welcome h2 {
  font-size: 2rem;
  font-weight: 700;
  margin: 0 0 16px;
  color: var(--ink, #1b1f24);
  letter-spacing: -0.03em;
}

.chat-welcome .welcome-subtitle {
  font-size: 1.05rem;
  color: var(--muted, #6b7280);
  margin: 0 0 44px;
  line-height: 1.6;
  max-width: 600px;
}

.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 920px;
  margin-bottom: 8px;
}

.quick-action {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 20px 18px 18px;
  background: var(--surface, #fff);
  border: 1.5px solid var(--chat-border);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: left;
  overflow: hidden;
}

.quick-action:hover {
  border-color: var(--chat-accent);
  background: var(--chat-accent-soft);
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(43, 102, 241, 0.15);
}

.quick-action:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(43, 102, 241, 0.1);
}

.quick-action-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 12px;
}

.quick-action-category {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--chat-accent);
  padding: 3px 8px;
  background: var(--chat-accent-soft);
  border-radius: 4px;
}

.quick-action-icon {
  width: 36px;
  height: 36px;
  background: var(--chat-accent-soft);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-accent);
  transition: all 0.15s ease;
}

.quick-action:hover .quick-action-icon {
  background: var(--chat-accent);
  color: #fff;
}

.quick-action-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--ink, #1b1f24);
  line-height: 1.3;
}

.quick-action-desc {
  font-size: 0.85rem;
  color: var(--muted, #6b7280);
  margin: 0 0 12px;
  line-height: 1.45;
  flex-grow: 1;
}

.quick-action-arrow {
  position: absolute;
  bottom: 12px;
  right: 12px;
  opacity: 0;
  transform: translateX(-4px);
  transition: all 0.15s ease;
  color: var(--chat-accent);
}

.quick-action:hover .quick-action-arrow {
  opacity: 1;
  transform: translateX(0);
}

/* Legacy support for old class names */
.quick-action h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 6px;
  color: var(--ink, #1b1f24);
}

.quick-action p {
  font-size: 0.82rem;
  color: var(--muted, #6b7280);
  margin: 0;
  line-height: 1.4;
}

/* Keyboard hint in welcome */
.keyboard-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 36px;
  font-size: 0.85rem;
  color: var(--muted, #7a848c);
  opacity: 0.85;
}

.keyboard-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  background: rgba(27, 31, 36, 0.06);
  border: 1px solid rgba(27, 31, 36, 0.12);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink, #1b1f24);
}

/* Scroll to Bottom Button */
.scroll-to-bottom {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  background: var(--surface, #fff);
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all 0.15s ease;
  z-index: 50;
  font-size: 0.8rem;
  color: var(--muted, #6b7280);
}

.scroll-to-bottom.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.scroll-to-bottom:hover {
  background: var(--chat-accent);
  color: #fff;
  border-color: transparent;
}

.scroll-to-bottom svg {
  width: 14px;
  height: 14px;
}

/* Keyboard Shortcuts Modal */
.shortcuts-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.shortcuts-modal.show {
  opacity: 1;
  visibility: visible;
}

.shortcuts-content {
  background: var(--surface, #fff);
  border-radius: 20px;
  padding: 0;
  max-width: 480px;
  width: 94%;
  max-height: 85vh;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow:
    0 24px 48px rgba(15, 23, 42, 0.2),
    0 0 0 1px rgba(27, 31, 36, 0.05);
}

.shortcuts-modal.show .shortcuts-content {
  transform: scale(1) translateY(0);
}

.shortcuts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px 20px;
  background: linear-gradient(135deg, rgba(43, 180, 168, 0.08) 0%, rgba(243, 139, 99, 0.08) 100%);
  border-bottom: 1px solid rgba(27, 31, 36, 0.06);
}

.shortcuts-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.shortcuts-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #2bb4a8 0%, #f38b63 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 8px 18px rgba(43, 180, 168, 0.28);
}

.shortcuts-icon svg {
  width: 22px;
  height: 22px;
}

.shortcuts-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shortcuts-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
  color: var(--ink, #1b1f24);
}

.shortcuts-subtitle {
  font-size: 0.8rem;
  color: var(--muted, #667079);
  margin: 0;
}

.shortcuts-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(27, 31, 36, 0.06);
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted, #667079);
  transition: all 0.2s ease;
}

.shortcuts-close:hover {
  background: rgba(27, 31, 36, 0.12);
  color: var(--ink, #1b1f24);
  transform: rotate(90deg);
}

.shortcuts-body {
  padding: 8px 20px 20px;
  max-height: calc(85vh - 120px);
  overflow-y: auto;
}

.shortcuts-body::-webkit-scrollbar {
  width: 6px;
}

.shortcuts-body::-webkit-scrollbar-track {
  background: transparent;
}

.shortcuts-body::-webkit-scrollbar-thumb {
  background: rgba(27, 31, 36, 0.15);
  border-radius: 3px;
}

.shortcuts-section {
  margin-top: 16px;
}

.shortcuts-section:first-child {
  margin-top: 12px;
}

.shortcuts-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted, #7a848c);
  margin: 0 0 10px 4px;
}

.shortcuts-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(27, 31, 36, 0.02);
  border-radius: 12px;
  padding: 4px;
}

.shortcut-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 10px;
  transition: background 0.15s ease;
  border: none;
}

.shortcut-item:hover {
  background: rgba(43, 180, 168, 0.08);
}

.shortcut-label {
  font-size: 0.9rem;
  font-weight: 450;
  color: var(--ink, #1b1f24);
}

.shortcut-keys {
  display: flex;
  gap: 5px;
}

.shortcut-keys kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 28px;
  padding: 0 10px;
  background: linear-gradient(180deg, #fff 0%, #f5f5f7 100%);
  border: 1px solid rgba(27, 31, 36, 0.12);
  border-radius: 7px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--ink, #1b1f24);
  box-shadow:
    0 1px 0 rgba(27, 31, 36, 0.08),
    0 2px 4px rgba(27, 31, 36, 0.04);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.shortcut-keys kbd.mod-key {
  background: linear-gradient(180deg, #f0f0f5 0%, #e8e8ed 100%);
  min-width: 36px;
}

/* Shortcuts footer tip */
.shortcuts-footer {
  padding: 16px 24px;
  background: rgba(27, 31, 36, 0.02);
  border-top: 1px solid rgba(27, 31, 36, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.shortcuts-footer-text {
  font-size: 0.8rem;
  color: var(--muted, #7a848c);
}

.shortcuts-footer kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  background: rgba(27, 31, 36, 0.06);
  border: 1px solid rgba(27, 31, 36, 0.08);
  border-radius: 5px;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted, #667079);
}

/* Mobile Quick Actions */
@media (max-width: 768px) {
  .chat-welcome {
    padding: 40px 16px 24px;
    min-height: 50vh;
  }

  .chat-welcome h2 {
    font-size: 1.65rem;
    margin-bottom: 14px;
  }

  .chat-welcome .welcome-subtitle {
    font-size: 0.95rem;
    margin-bottom: 32px;
    line-height: 1.5;
  }

  .quick-actions-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    max-width: 100%;
  }

  .quick-action {
    padding: 16px 14px 14px;
  }

  .quick-action-header {
    margin-bottom: 10px;
  }

  .quick-action-category {
    font-size: 0.68rem;
  }

  .quick-action-icon {
    width: 32px;
    height: 32px;
  }

  .quick-action-title {
    font-size: 0.9rem;
  }

  .quick-action-desc {
    font-size: 0.8rem;
  }

  .keyboard-hint {
    display: none;
  }

  .scroll-to-bottom {
    bottom: 90px;
    padding: 8px 14px;
    font-size: 0.8rem;
  }

  /* Shortcuts modal mobile */
  .shortcuts-content {
    width: 96%;
    max-height: 90vh;
    border-radius: 16px;
  }

  .shortcuts-header {
    padding: 20px 20px 16px;
  }

  .shortcuts-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }

  .shortcuts-icon svg {
    width: 18px;
    height: 18px;
  }

  .shortcuts-header h3 {
    font-size: 1.05rem;
  }

  .shortcuts-subtitle {
    font-size: 0.75rem;
  }

  .shortcuts-body {
    padding: 4px 16px 16px;
  }

  .shortcut-item {
    padding: 10px 12px;
  }

  .shortcut-label {
    font-size: 0.85rem;
  }

  .shortcut-keys kbd {
    min-width: 26px;
    height: 26px;
    padding: 0 8px;
    font-size: 0.7rem;
  }

  .shortcuts-footer {
    padding: 14px 20px;
  }
}

/* System preference fallback */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chat-page {
    background: linear-gradient(135deg, #121218 0%, #161622 50%, #121218 100%);
    color: var(--ink, #f0eff4);
  }

  :root:not([data-theme="light"]) .chat-sidebar {
    background: linear-gradient(180deg, #14161d 0%, #0f131a 100%);
    color: var(--ink, #f0eff4);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
  }

  :root:not([data-theme="light"]) .chat-sidebar a,
  :root:not([data-theme="light"]) .chat-sidebar button,
  :root:not([data-theme="light"]) .chat-sidebar span,
  :root:not([data-theme="light"]) .chat-sidebar p,
  :root:not([data-theme="light"]) .chat-sidebar strong {
    color: rgba(240, 239, 244, 0.85);
  }

  :root:not([data-theme="light"]) .sidebar-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  :root:not([data-theme="light"]) .sidebar-brand {
    color: #fff;
  }

  :root:not([data-theme="light"]) .new-chat-btn {
    background: linear-gradient(135deg, rgba(43, 180, 168, 0.2) 0%, rgba(243, 139, 99, 0.18) 100%);
    border-color: rgba(43, 180, 168, 0.35);
    color: #e6fffb;
  }

  :root:not([data-theme="light"]) .sidebar-search .search-icon {
    color: rgba(255, 255, 255, 0.4);
  }

  :root:not([data-theme="light"]) .sidebar-search input {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
    color: #fff;
  }

  :root:not([data-theme="light"]) .sidebar-search input::placeholder {
    color: rgba(255, 255, 255, 0.4);
  }

  :root:not([data-theme="light"]) .sidebar-search input:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(43, 180, 168, 0.5);
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-item {
    color: rgba(255, 255, 255, 0.92);
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-item:hover {
    background: rgba(255, 255, 255, 0.06);
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-item.active {
    background: rgba(43, 180, 168, 0.2);
    color: #fff;
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-info strong {
    color: rgba(255, 255, 255, 0.95) !important;
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-meta {
    color: rgba(255, 255, 255, 0.7) !important;
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-summary {
    color: rgba(255, 255, 255, 0.55) !important;
    border-top-color: rgba(255, 255, 255, 0.06);
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-menu-btn {
    color: rgba(255, 255, 255, 0.7);
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-list {
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-menu {
    background: #1b1f28;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-menu button {
    color: rgba(255, 255, 255, 0.85);
  }

  :root:not([data-theme="light"]) .chat-sidebar .history-menu button:hover {
    background: rgba(255, 255, 255, 0.08);
  }

  :root:not([data-theme="light"]) .chat-sidebar .load-more-btn {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.75);
  }

  :root:not([data-theme="light"]) .chat-sidebar .load-more-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(43, 180, 168, 0.4);
    color: #fff;
  }

  :root:not([data-theme="light"]) .chat-sidebar .rename-input {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(43, 180, 168, 0.5);
    color: #fff;
  }

  :root:not([data-theme="light"]) .chat-sidebar .rename-input:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(43, 180, 168, 0.7);
  }

  :root:not([data-theme="light"]) .chat-main {
    background: linear-gradient(180deg, rgba(18, 18, 24, 0.95) 0%, rgba(14, 16, 22, 0.98) 100%);
  }

  :root:not([data-theme="light"]) .chat-main::before {
    background:
      radial-gradient(circle at 18% 8%, rgba(43, 180, 168, 0.08), transparent 58%),
      radial-gradient(circle at 85% 12%, rgba(243, 139, 99, 0.08), transparent 55%),
      radial-gradient(circle at 70% 85%, rgba(43, 180, 168, 0.06), transparent 60%);
  }

  :root:not([data-theme="light"]) .chat-page .chat-header {
    background: rgba(26, 26, 36, 0.95);
    border-color: rgba(255, 255, 255, 0.08);
  }

  :root:not([data-theme="light"]) .chat-page .chat-title {
    color: var(--ink, #f0eff4);
  }

  :root:not([data-theme="light"]) .header-action-btn {
    color: var(--muted, #8a8698);
  }

  :root:not([data-theme="light"]) .chat-page .export-menu {
    background: var(--paper-2, #1a1a24);
    border-color: rgba(255, 255, 255, 0.1);
  }

  :root:not([data-theme="light"]) .chat-page .export-option {
    color: var(--ink, #f0eff4);
  }

  :root:not([data-theme="light"]) .chat-page .message.assistant .message-content {
    background: var(--paper-2, #1a1a24);
    border-color: rgba(255, 255, 255, 0.08);
    color: var(--ink, #f0eff4);
  }

  :root:not([data-theme="light"]) .chat-input-container {
    background: rgba(26, 26, 36, 0.9);
    border-color: rgba(255, 255, 255, 0.1);
  }

  :root:not([data-theme="light"]) .chat-page .chat-input {
    background: var(--paper-2, #1a1a24);
    border-color: rgba(255, 255, 255, 0.1);
  }

  :root:not([data-theme="light"]) .compose-actions {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.05);
  }

  :root:not([data-theme="light"]) .compose-input-shell {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02) 0%, rgba(255, 255, 255, 0.01) 100%);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  }

  :root:not([data-theme="light"]) .chat-input-wrapper {
    background: linear-gradient(180deg, rgba(18, 18, 24, 0) 0%, rgba(18, 18, 24, 0.85) 45%, rgba(18, 18, 24, 0.98) 100%);
  }

  :root:not([data-theme="light"]) .chat-page textarea {
    color: var(--ink, #f0eff4);
  }

  :root:not([data-theme="light"]) .compose-btn {
    color: var(--muted, #8a8698);
  }

  :root:not([data-theme="light"]) .chat-page .template-menu {
    background: var(--paper-2, #1a1a24);
    border-color: rgba(255, 255, 255, 0.1);
  }

  :root:not([data-theme="light"]) .chat-page .template-option {
    color: var(--ink, #f0eff4);
  }

  :root:not([data-theme="light"]) .chat-welcome {
    color: var(--ink, #f0eff4);
  }

  :root:not([data-theme="light"]) .chat-welcome p {
    color: var(--muted, #8a8698);
  }

  :root:not([data-theme="light"]) .quick-action {
    background: var(--paper-2, #1a1a24);
    border-color: rgba(255, 255, 255, 0.08);
  }

  :root:not([data-theme="light"]) .quick-action:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
  }

  :root:not([data-theme="light"]) .quick-action h4,
  :root:not([data-theme="light"]) .quick-action-title {
    color: var(--ink, #f0eff4);
  }

  :root:not([data-theme="light"]) .quick-action p,
  :root:not([data-theme="light"]) .quick-action-desc {
    color: var(--muted, #8a8698);
  }

  :root:not([data-theme="light"]) .mobile-header {
    background: rgba(26, 26, 36, 0.95);
    border-color: rgba(255, 255, 255, 0.08);
  }

  :root:not([data-theme="light"]) .mobile-title {
    color: var(--ink, #f0eff4);
  }

  /* Shortcuts Modal - System Dark Mode */
  :root:not([data-theme="light"]) .shortcuts-content {
    background: var(--paper-2, #1a1a24);
    box-shadow:
      0 24px 48px rgba(0, 0, 0, 0.4),
      0 0 0 1px rgba(255, 255, 255, 0.08);
  }

  :root:not([data-theme="light"]) .shortcuts-header {
    background: linear-gradient(135deg, rgba(43, 180, 168, 0.12) 0%, rgba(243, 139, 99, 0.12) 100%);
    border-color: rgba(255, 255, 255, 0.06);
  }

  :root:not([data-theme="light"]) .shortcuts-header h3 {
    color: var(--ink, #f0eff4);
  }

  :root:not([data-theme="light"]) .shortcuts-subtitle {
    color: var(--muted, #8a8698);
  }

  :root:not([data-theme="light"]) .shortcuts-close {
    background: rgba(255, 255, 255, 0.08);
    color: var(--muted, #8a8698);
  }

  :root:not([data-theme="light"]) .shortcuts-section-title {
    color: var(--muted, #6b6a7a);
  }

  :root:not([data-theme="light"]) .shortcuts-list {
    background: rgba(255, 255, 255, 0.02);
  }

  :root:not([data-theme="light"]) .shortcut-item:hover {
    background: rgba(43, 180, 168, 0.1);
  }

  :root:not([data-theme="light"]) .shortcut-label {
    color: var(--ink, #f0eff4);
  }

  :root:not([data-theme="light"]) .shortcut-keys kbd {
    background: linear-gradient(180deg, #2a2a3a 0%, #222232 100%);
    border-color: rgba(255, 255, 255, 0.12);
    color: var(--ink, #e0e0e8);
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.05),
      0 2px 4px rgba(0, 0, 0, 0.2);
    text-shadow: none;
  }

  :root:not([data-theme="light"]) .shortcuts-footer {
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.06);
  }

  :root:not([data-theme="light"]) .shortcuts-footer-text {
    color: var(--muted, #6b6a7a);
  }

  :root:not([data-theme="light"]) .shortcuts-footer kbd {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--muted, #8a8698);
  }
}

/* ==============================================
   MESSAGE TIMESTAMP TOOLTIP
   ============================================== */

/* Custom tooltip for message timestamps */
.message[data-timestamp] {
  position: relative;
}

.message[data-timestamp]::before {
  content: attr(title);
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  padding: 6px 12px;
  background: var(--ink, #1b1f24);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.message[data-timestamp]::after {
  content: '';
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: var(--ink, #1b1f24) transparent transparent transparent;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 100;
}

.message[data-timestamp]:hover::before,
.message[data-timestamp]:hover::after {
  opacity: 1;
  visibility: visible;
}

.message[data-timestamp]:hover::before {
  transform: translateX(-50%) translateY(-100%) translateY(-4px);
}

/* Position adjustments for user messages (right-aligned) */
.message.user[data-timestamp]::before {
  left: auto;
  right: 0;
  transform: translateY(-100%);
}

.message.user[data-timestamp]::after {
  left: auto;
  right: 20px;
  transform: none;
}

.message.user[data-timestamp]:hover::before {
  transform: translateY(-100%) translateY(-4px);
}

/* Position adjustments for assistant messages (left-aligned) */
.message.assistant[data-timestamp]::before {
  left: 0;
  transform: translateY(-100%);
}

.message.assistant[data-timestamp]::after {
  left: 20px;
  transform: none;
}

.message.assistant[data-timestamp]:hover::before {
  transform: translateY(-100%) translateY(-4px);
}

/* Dark mode */
[data-theme="dark"] .message[data-timestamp]::before {
  background: var(--paper-2, #2a2a30);
  color: var(--ink, #f0eff4);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .message[data-timestamp]::after {
  border-color: var(--paper-2, #2a2a30) transparent transparent transparent;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .message[data-timestamp]::before {
    background: var(--paper-2, #2a2a30);
    color: var(--ink, #f0eff4);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  :root:not([data-theme="light"]) .message[data-timestamp]::after {
    border-color: var(--paper-2, #2a2a30) transparent transparent transparent;
  }
}

/* ============================================================
   Mobile Optimizations & Safe Area Support
   ============================================================ */

/* Safe area insets for devices with notches/rounded corners */
@supports (padding: env(safe-area-inset-bottom)) {
  /* Chat form at bottom needs padding for safe area */
  #chatForm {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  /* Sidebar needs padding at bottom */
  .chat-sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Fixed buttons need safe area consideration */
  #scrollToBottom {
    bottom: calc(100px + env(safe-area-inset-bottom));
  }

  /* Mobile menu overlay */
  .mobile-overlay {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Touch target improvements for mobile */
@media (max-width: 768px) {
  /* Ensure all interactive elements have minimum 44x44px touch target */
  button,
  a,
  .history-item,
  .history-menu-btn,
  .reaction-btn,
  .copy-code-btn,
  .message-action,
  input[type="checkbox"],
  input[type="radio"] {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Adjust padding for touch comfort */
  .history-menu-btn {
    padding: 12px;
    margin: -8px;
  }

  .reaction-btn {
    padding: 10px 12px;
    min-height: 44px;
  }

  /* Larger tap target for message actions */
  .message-actions button {
    min-height: 44px;
    min-width: 44px;
    padding: 12px;
  }

  /* History items should be easy to tap */
  .history-item {
    padding: 14px 16px;
    min-height: 60px;
  }

  /* File input and attachment buttons */
  .file-input-label,
  .attachment-remove {
    min-height: 44px;
    min-width: 44px;
    padding: 12px;
  }

  /* Ensure form submit button is large enough */
  #sendBtn {
    min-height: 48px;
    min-width: 48px;
    padding: 12px;
  }

  /* Dropdown and menu items */
  .history-menu button,
  .dropdown-item {
    min-height: 44px;
    padding: 12px 16px;
  }

  /* Long press feedback improvements */
  .history-item:active,
  button:active {
    transform: scale(0.97);
    transition: transform 0.1s ease;
  }

  /* Improve text input on mobile */
  #prompt {
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 48px;
    padding: 12px 16px;
  }

  /* Search input */
  #historySearch {
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 44px;
    padding: 10px 12px 10px 36px;
  }

  /* Ensure modals are properly positioned with safe area */
  .modal-overlay {
    padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) 
             env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  }

  /* Bottom sheet style panels respect safe area */
  .bookmark-panel,
  .shortcuts-panel {
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  }

  /* Scrollable areas need safe area padding */
  #messages {
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  }
}

/* Extra small devices (phones in portrait, less than 375px) */
@media (max-width: 374px) {
  /* Reduce padding on very small screens */
  .history-item {
    padding: 12px;
  }

  .message {
    padding: 12px 14px;
  }

  /* Slightly smaller minimum touch targets on tiny screens */
  button,
  a {
    min-height: 40px;
    min-width: 40px;
  }
}

/* Landscape mode on mobile devices */
@media (max-width: 896px) and (orientation: landscape) {
  /* Reduce vertical spacing in landscape */
  #chatForm {
    padding: 12px 16px;
  }

  .chat-sidebar {
    width: 280px; /* Narrower sidebar in landscape */
  }

  /* Smaller modals in landscape */
  .modal-card {
    max-width: 90vw;
    max-height: 85vh;
  }
}

/* Hover states only for devices that support hover */
@media (hover: hover) and (pointer: fine) {
  .history-item:hover,
  button:hover,
  .reaction-btn:hover {
    /* Only apply hover effects on mouse-capable devices */
    opacity: 0.9;
  }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .history-item:active,
  button:active {
    transform: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  button,
  .history-item,
  input,
  textarea {
    border: 2px solid currentColor;
  }

  .history-item.active {
    border: 3px solid currentColor;
  }
}
