* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #1e1f22;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #313338;
  --bg-hover: #404249;
  --text-primary: #f2f3f5;
  --text-secondary: #b5bac1;
  --text-muted: #80848e;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --border: #3f4147;
  --success: #23a559;
  --danger: #da373c;
  
  /* Safe area insets for iOS */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  /* Use dvh with fallback for older browsers */
  height: 100vh;
  height: 100dvh;
  min-height: -webkit-fill-available;
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
}

/* =================================================================
   LAYOUT
================================================================= */

.container {
  display: flex;
  height: 100%;
  overflow: hidden;
  /* Account for safe areas */
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* =================================================================
   SIDEBAR
================================================================= */

.sidebar {
  width: 280px;
  min-width: 280px;
  background-color: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  transition: width 0.3s ease, min-width 0.3s ease;
  position: relative;
  z-index: 100;
  overflow: hidden;
}

.sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  padding: 0 !important;
  border-right: none !important;
  overflow: hidden !important;
  flex: 0 0 0 !important;
}

.sidebar.collapsed * {
  display: none;
}

/* Expand sidebar button - shows B icon when collapsed */
.sidebar-expand-btn {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 56px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 10px 10px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 101;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 0;
}

.sidebar-expand-btn:hover {
  background: var(--bg-hover);
}

body.sidebar-collapsed .sidebar-expand-btn {
  opacity: 1;
  pointer-events: auto;
}

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

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
}

.sidebar-drop-zone {
  flex: 1;
  min-height: 50px;
  transition: background 0.15s ease;
}

.sidebar-drop-zone.drag-over {
  background: rgba(88, 101, 242, 0.1);
  border-top: 2px solid var(--accent);
}

/* Category Selector */
.category-selector {
  padding: 8px 12px;
  margin-bottom: 4px;
}

.category-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.category-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--bg-tertiary);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.category-btn:hover {
  background: var(--bg-secondary);
  transform: scale(1.05);
}

.category-btn.selected {
  border-color: var(--accent);
  background: rgba(88, 101, 242, 0.15);
}

.category-btn-locked {
  opacity: 0.6;
}

.category-slider {
  padding: 12px 16px;
  display: flex;
  justify-content: center;
}

.slider-track {
  position: relative;
  height: 36px;
  background: var(--bg-tertiary);
  border-radius: 18px;
  display: flex;
  align-items: center;
  padding: 4px;
  gap: 0;
}

.slider-stop {
  flex: 1;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  border-radius: 14px;
  transition: all 0.2s ease;
  position: relative;
  z-index: 1;
  min-width: 40px;
}

.slider-stop:hover {
  background: rgba(255,255,255,0.1);
}

.slider-stop.active {
  color: white;
}

.slider-thumb {
  position: absolute;
  height: 28px;
  background: var(--accent);
  border-radius: 14px;
  transition: all 0.2s ease;
  z-index: 0;
}

.slider-labels,
.slider-fill,
.slider-emoji {
  display: none;
}

.slider-label {
  display: none;
}

.chat-drop-zone {
  height: 20px;
  transition: all 0.15s ease;
}

.chat-drop-zone.drag-over {
  border-top: 2px solid var(--accent);
  margin-top: -2px;
}

.sidebar-footer {
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background-color: var(--bg-tertiary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  margin-top: auto;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--accent);
  font-size: 18px;
  flex-shrink: 0;
}

.user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

/* =================================================================
   PROJECTS & CHATS
================================================================= */

.project {
  margin-bottom: 0;
}

/* Empty projects need more spacing since no chats create gap */
.project.empty-project {
  margin-bottom: 6px;
}

.project-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 8px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  user-select: none;
}

@media (hover: hover) {
  .project-header:hover {
    background-color: var(--bg-hover);
    color: var(--text-secondary);
  }
}

.project-name {
  display: flex;
  align-items: center;
  gap: 4px;
}

.project-chevron {
  transition: transform 0.2s;
  font-size: 10px;
}

.project.collapsed .project-chevron {
  transform: rotate(-90deg);
}

.project-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

@media (hover: hover) {
  .project-header:hover .project-actions {
    opacity: 1;
  }
}

.project-chats {
  padding-left: 6px;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: -2px;
  margin-bottom: -8px;
  max-height: 500px;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.project.collapsed .project-chats {
  max-height: 0;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 8px;
  margin: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  user-select: none;
}

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

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

.chat-name {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-hash {
  color: var(--text-muted);
}

.chat-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

@media (hover: hover) {
  .chat-item:hover .chat-actions {
    opacity: 1;
  }
}

/* Always show actions on touch devices */
@media (hover: none) {
  .chat-actions {
    opacity: 0.6;
  }
  .project-actions {
    opacity: 0.6;
  }
}

/* Drag and drop */
.chat-item.dragging,
.project.dragging {
  opacity: 0.5;
}

.chat-item.drag-over {
  border-top: 2px solid var(--accent);
  margin-top: -2px;
}

.chat-item.drag-over-bottom {
  border-bottom: 2px solid var(--accent);
  margin-bottom: -2px;
}

.project-header.drag-over {
  background: var(--accent);
  color: white;
  border-radius: 4px;
}

.project.drag-over {
  border-top: 2px solid var(--accent);
  margin-top: -2px;
}

.project.drag-over-bottom {
  border-bottom: 2px solid var(--accent);
  margin-bottom: -2px;
}

.chat-item[draggable="true"],
.project[draggable="true"] {
  cursor: grab;
}

.chat-item[draggable="true"]:active,
.project[draggable="true"]:active {
  cursor: grabbing;
}

/* Divider row with new chat button */
.sidebar-divider-row {
  display: flex;
  align-items: center;
  margin: 6px 8px;
  gap: 8px;
}

.sidebar-divider {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.new-chat-btn,
.new-project-btn {
  opacity: 0.6;
  font-size: 14px;
  padding: 2px 6px;
}

.new-chat-btn:hover,
.new-project-btn:hover {
  opacity: 1;
}

/* Root level chats */
.root-chats {
  margin-top: 4px;
}

/* =================================================================
   CHAT AREA
================================================================= */

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
}

.chat-header {
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

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

.chat-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-actions {
  display: flex;
  gap: 8px;
}

#toggleSidebarBtn,
#backBtn {
  font-size: 20px;
}

#backBtn {
  font-size: 24px;
  font-weight: bold;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.welcome-message {
  text-align: center;
  margin-top: 100px;
  color: var(--text-secondary);
}

.welcome-message h3 {
  margin-bottom: 8px;
  font-size: 24px;
}

.message {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  margin-bottom: 8px;
}

.message:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.message.assistant .message-avatar {
  background-color: var(--success);
}

.message-content {
  flex: 1;
}

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

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

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

.message-text {
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-text code {
  background-color: var(--bg-tertiary);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.9em;
}

.message-text pre {
  background-color: var(--bg-tertiary);
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 8px 0;
}

/* Message attachments */
.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.message-attachment.image {
  max-width: 300px;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
}

.message-attachment.image img {
  width: 100%;
  height: auto;
  display: block;
  transition: opacity 0.2s;
}

.message-attachment.image img:hover {
  opacity: 0.9;
}

.message-attachment.file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 300px;
}

.message-attachment .attachment-icon {
  font-size: 24px;
}

.message-attachment .attachment-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-attachment .attachment-size {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background-color: var(--bg-tertiary);
  border-radius: 16px;
  width: fit-content;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-muted);
  animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
  }
  30% {
    opacity: 1;
  }
}

.typing-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  font-style: italic;
}

/* =================================================================
   MESSAGE INPUT - Discord-style on all devices
================================================================= */

.message-input-container {
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background-color: var(--bg-primary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.message-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
}

.attach-btn {
  display: flex;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 22px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.2s;
}

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

.input-with-send {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 6px 6px 6px 18px;
  min-height: 44px;
  max-height: 170px;
  transition: border-color 0.2s;
  overflow: hidden;
}

.input-with-send:focus-within {
  border-color: var(--accent);
}

.input-with-send textarea {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 0;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  min-height: 28px;
  max-height: 150px !important;
  line-height: 1.4;
  overflow-y: auto !important;
}

.input-with-send textarea::placeholder {
  color: var(--text-muted);
}

.input-with-send textarea:focus {
  outline: none;
}

.input-with-send textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#sendBtn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  padding: 0;
  background-color: var(--accent);
  color: white;
  border: none;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.2s;
}

#sendBtn:hover:not(:disabled) {
  background-color: var(--accent-hover);
  transform: scale(1.05);
}

#sendBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#sendBtn.stop-mode {
  background-color: var(--danger);
}

#sendBtn.stop-mode:hover {
  background-color: #c0392b;
  transform: scale(1.05);
}

.message-input-container button:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

.message-input-container button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =================================================================
   DROP ZONE & FILE PREVIEW
================================================================= */

.drop-zone-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(88, 101, 242, 0.15);
  border: 3px dashed var(--accent);
  border-radius: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: none;
}

.drop-zone-overlay.active {
  display: flex;
}

.drop-zone-content {
  text-align: center;
  color: var(--accent);
}

.drop-zone-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.drop-zone-text {
  font-size: 18px;
  font-weight: 600;
}

.file-preview-container {
  display: none;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0 16px 12px 16px;
  flex-shrink: 0;
}

.file-preview-container.has-files {
  display: flex;
}

.file-preview-item {
  position: relative;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  width: 200px;
}

.file-preview-item .file-thumbnail {
  width: 100%;
  height: 120px;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  border-bottom: 1px solid var(--border);
}

.file-preview-item .file-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-preview-item .file-info {
  padding: 10px 12px;
}

.file-preview-item .file-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.file-preview-item .file-size {
  font-size: 11px;
  color: var(--text-muted);
}

/* Action buttons overlay (Discord style) */
.file-preview-item .file-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.file-preview-item:hover .file-actions {
  opacity: 1;
}

.file-preview-item .file-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: var(--bg-primary);
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.15s;
}

.file-preview-item .file-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.file-preview-item .file-action-btn.remove:hover {
  background: var(--danger);
  color: white;
}

/* =================================================================
   BUTTONS
================================================================= */

.icon-btn {
  padding: 6px 8px;
  background-color: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.2s, color 0.2s;
}

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

.icon-btn-small {
  padding: 2px 4px;
  font-size: 12px;
}

.btn-primary {
  padding: 10px 20px;
  background-color: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
}

.btn-secondary {
  padding: 10px 20px;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

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

.btn-danger {
  padding: 10px 20px;
  background-color: var(--danger);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

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

/* =================================================================
   MODALS
================================================================= */

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background-color: var(--bg-secondary);
  padding: 24px;
  border-radius: 8px;
  min-width: 400px;
  max-width: 500px;
}

.modal-content h3 {
  margin-bottom: 16px;
  font-size: 20px;
  color: var(--text-primary);
}

.modal-content input {
  width: 100%;
  padding: 12px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 14px;
  margin-bottom: 16px;
}

.modal-content input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-category-select {
  margin: 12px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-category-select label {
  color: var(--text-secondary);
  font-size: 14px;
}

.modal-category-select select {
  flex: 1;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 14px;
}

.modal-category-select select:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* =================================================================
   SCROLLBAR
================================================================= */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background-color: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background-color: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--bg-hover);
}

/* =================================================================
   SETTINGS PANEL
================================================================= */

.settings-panel {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.85);
  z-index: 9999;
  animation: fadeIn 0.2s ease;
}

.settings-panel.active {
  display: block;
}

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

.settings-container {
  display: flex;
  width: 100%;
  max-width: 1200px;
  height: 100%;
  margin: 0 auto;
  background-color: var(--bg-primary);
}

.settings-sidebar {
  width: 240px;
  background-color: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  padding: 60px 8px 20px 8px;
  overflow-y: auto;
}

.settings-nav {
  flex: 1;
}

.settings-nav-section {
  margin-bottom: 24px;
}

.settings-nav-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 8px 8px 4px 8px;
  letter-spacing: 0.5px;
}

.settings-nav-item {
  width: 100%;
  background: none;
  border: none;
  padding: 8px 12px;
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease;
}

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

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

.settings-nav-icon {
  font-size: 18px;
}

.settings-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 60px 40px 40px 40px;
}

.settings-panel-content {
  display: none;
}

.settings-panel-content.active {
  display: block;
}

.settings-panel-content h1 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.settings-description {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.settings-section {
  margin-bottom: 40px;
}

.settings-section h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}

/* Stat Cards */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background-color: var(--bg-secondary);
  padding: 24px;
  border-radius: 8px;
  text-align: center;
}

.stat-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.stat-label {
  font-size: 14px;
  color: var(--text-muted);
}

/* Usage Bar */
.usage-bar {
  height: 24px;
  background-color: var(--bg-secondary);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 8px;
}

.usage-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  transition: width 0.3s ease;
}

.usage-text {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Info Rows */
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.info-label {
  color: var(--text-muted);
  font-weight: 500;
}

.info-value {
  color: var(--text-primary);
}

/* Memory List */
.memory-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.memory-stat {
  background-color: var(--bg-secondary);
  padding: 20px;
  border-radius: 8px;
  text-align: center;
}

.memory-stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--success);
  margin-bottom: 8px;
}

.memory-stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

.memory-list {
  max-height: 400px;
  overflow-y: auto;
}

.memory-item {
  background-color: var(--bg-secondary);
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 8px;
  border-left: 3px solid var(--accent);
}

.memory-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.memory-item-type {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
}

.memory-item-date {
  font-size: 12px;
  color: var(--text-muted);
}

.memory-item-content {
  color: var(--text-primary);
  font-size: 14px;
}

/* Plan Cards */
.plan-card {
  background-color: var(--bg-secondary);
  padding: 24px;
  border-radius: 8px;
  border: 2px solid var(--border);
}

.plan-card.active-plan {
  border-color: var(--accent);
}

.plan-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.plan-header h3 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.plan-price {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}

.plan-features {
  margin-bottom: 20px;
}

.plan-feature {
  padding: 8px 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.plans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

/* Form Elements in Settings */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-primary);
  font-size: 14px;
}

.form-group input {
  width: 100%;
  padding: 12px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 14px;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.form-group small {
  display: block;
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

/* Toggle Switches */
.toggle-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

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

.toggle-item:last-child {
  border-bottom: none;
}

.toggle-label {
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.toggle-description {
  font-size: 13px;
  color: var(--text-muted);
}

.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-tertiary);
  transition: 0.3s;
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.toggle input:checked + .toggle-slider {
  background-color: var(--accent);
}

.toggle input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

.toggle input:disabled + .toggle-slider {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Danger Zone */
.danger-zone {
  background-color: rgba(218, 55, 60, 0.1);
  border: 1px solid var(--danger);
  padding: 20px;
  border-radius: 8px;
}

.loading-spinner {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* =================================================================
   RESPONSIVE
================================================================= */

@media (max-width: 768px) {
  /* Mobile: 4-Panel Swipeable Layout */
  
  /* Container becomes horizontal scroll container */
  .container {
    display: flex;
    width: 400vw; /* 4 panels × 100vw */
    height: 100dvh;
    overflow: hidden;
    touch-action: pan-y; /* Allow vertical scroll, but we handle horizontal */
    padding: 0;
  }
  
  /* Each panel takes full viewport width */
  .swipe-panel {
    width: 100vw;
    min-width: 100vw;
    height: 100dvh;
    flex-shrink: 0;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
  }
  
  /* Panel 1: Sidebar */
  .sidebar {
    border-right: none;
  }
  
  /* Panel 2: Chat */
  .chat-area {
    display: flex;
    flex-direction: column;
  }
  
  /* Panel 3 & 4: Features & Settings */
  .features-panel-full,
  .settings-panel-full {
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  
  .features-panel-full .panel-header,
  .settings-panel-full .panel-header {
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  
  .panel-content-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    min-height: 0; /* Important for flex overflow to work */
  }
  
  /* Hide desktop-only elements on mobile */
  .desktop-only {
    display: none !important;
  }
  
  /* Hide old navigation buttons */
  #toggleSidebarBtn,
  #backBtn,
  .sidebar-expand-btn {
    display: none !important;
  }
  
  /* Mobile input adjustments - extra padding for browser toolbar */
  .message-input-container {
    padding: 10px 12px !important;
    padding-bottom: 18px !important;
    background: var(--bg-secondary) !important;
    border-top: none !important;
  }
  
  .message-input-wrapper {
    align-items: center !important;
  }
  
  .attach-btn {
    width: 36px;
    height: 36px;
    font-size: 20px;
    border: none;
  }
  
  .input-with-send {
    border: none;
    border-radius: 20px;
    padding: 4px 4px 4px 14px;
    min-height: 38px;
  }
  
  .input-with-send textarea {
    font-size: 16px; /* Prevents zoom on iOS */
    max-height: 120px;
    padding: 6px 0;
  }
  
  #sendBtn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    font-size: 14px;
  }
  
  /* Sidebar footer - compact single row */
  .sidebar-footer {
    padding: 10px 12px;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  }
  
  /* Features/Settings panels - safe area padding */
  .features-panel-full .panel-content-scroll,
  .settings-panel-full .panel-content-scroll {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  }
  
  .modal-content {
    min-width: 90%;
    margin: 0 16px;
  }
  
  .message-input-container textarea {
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  .messages-container {
    padding-bottom: 20px;
  }
  
  .settings-container {
    flex-direction: column;
  }
  
  .settings-sidebar {
    width: 100%;
    padding: 20px 12px;
    max-height: 40vh;
  }
  
  .settings-content {
    padding: 20px 16px;
  }
  
  .settings-panel-content h1 {
    font-size: 24px;
  }
  
  .stat-cards,
  .plans-grid {
    grid-template-columns: 1fr;
  }
  
  .modal-content {
    min-width: 90%;
    margin: 0 16px;
  }
  
  /* Mobile: Adjust message input */
  .message-input-container {
    padding-bottom: env(safe-area-inset-bottom, 16px); /* iOS safe area */
  }
  
  .message-input-container textarea {
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  /* Ensure messages container doesn't overflow */
  .messages-container {
    padding-bottom: 20px;
  }
  
  /* Mobile: Settings Panel */
  .settings-container {
    flex-direction: column;
  }
  
  .settings-sidebar {
    width: 100%;
    padding: 20px 12px;
    max-height: 40vh;
  }
  
  .settings-content {
    padding: 20px 16px;
  }
  
  .settings-panel-content h1 {
    font-size: 24px;
  }
  
  .stat-cards,
  .plans-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 769px) {
  /* Desktop: Traditional 2-column layout - NO swipe panels */
  .container {
    width: 100% !important;
    height: 100vh !important;
    transform: none !important;
    display: flex !important;
    align-items: stretch !important;
    overflow: hidden !important;
  }
  
  /* Reset swipe panel styles for desktop */
  .swipe-panel {
    width: auto !important;
    min-width: auto !important;
    flex-shrink: 1 !important;
  }
  
  .sidebar {
    position: relative;
    width: 280px !important;
    min-width: 280px !important;
    height: 100% !important;
    flex-shrink: 0 !important;
  }
  
  .chat-area {
    flex: 1 !important;
    width: auto !important;
    min-width: 0 !important;
    height: 100% !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }
  
  .chat-area .messages-container {
    flex: 1 !important;
    overflow-y: auto !important;
    min-height: 0 !important;
  }
  
  /* HIDE mobile-only panels (3 & 4) on desktop completely */
  #featuresFullPanel,
  #settingsFullPanel,
  .features-panel-full,
  .settings-panel-full {
    display: none !important;
    width: 0 !important;
    min-width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    visibility: hidden !important;
    position: absolute !important;
    left: -9999px !important;
  }
  
  /* Desktop overlay panels - hidden by default, shown when .active */
  .panel.desktop-only {
    display: flex;
  }
  
  .panel-overlay.desktop-only {
    display: block;
  }
  
  /* Desktop: Keep normal input layout */
  .message-input-wrapper {
    display: contents;
  }
  
  .attach-btn {
    display: flex !important;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
  }
  
  .input-with-send {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 12px;
  }
  
  .message-input-container {
    padding-bottom: 16px !important;
  }
  
  .message-input-container textarea {
    flex: 1;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 20px;
    padding: 10px 16px;
    max-height: 150px !important;
    overflow-y: hidden;
  }
  
  .message-input-container #sendBtn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    border-radius: 50% !important;
    padding: 0 !important;
    font-size: 16px !important;
  }
  
  /* Desktop sidebar footer - normal padding */
  .sidebar-footer {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
  }
  
  /* Desktop: Show toggle button */
  #toggleSidebarBtn {
    display: flex !important;
    opacity: 0.3;
  }
  
  #toggleSidebarBtn:hover {
    opacity: 1;
  }
  
  .sidebar.collapsed ~ .chat-area #toggleSidebarBtn {
    opacity: 1;
  }
  
  /* Desktop: Never show back button */
  #backBtn {
    display: none !important;
  }
  
  /* ========================================
     DESKTOP ALIGNMENT: Headers & Footers
     ======================================== */
  
  /* Match sidebar header height - sidebar uses padding:16px = 32px + ~24px content = ~56px */
  .sidebar-header {
    height: 56px;
    padding: 0 16px;
    display: flex;
    align-items: center;
  }
  
  /* Chat header already has height:56px, ensure same styling */
  .chat-header {
    height: 56px;
    padding: 0 16px;
    background: transparent; /* Match sidebar header (no special background) */
  }
  
  /* Match footer heights */
  .sidebar-footer {
    height: 56px;
    padding: 0 12px !important;
    display: flex;
    align-items: center;
    background-color: var(--bg-tertiary) !important;
  }
  
  .message-input-container {
    min-height: 56px;
    max-height: 180px;
    padding: 0 16px !important;
    display: flex;
    align-items: center;
    background: var(--bg-tertiary) !important; /* Match sidebar footer */
    flex-shrink: 0 !important;
    margin-top: auto;
  }
  
  /* Fix input layout within the fixed-height container */
  .message-input-wrapper {
    display: flex !important;
    align-items: center;
    width: 100%;
    gap: 12px;
  }
  
  .input-with-send {
    display: flex !important;
    flex: 1;
    align-items: center;
    gap: 12px;
  }
  
  .message-input-container textarea {
    flex: 1;
    min-height: 36px;
    max-height: 150px !important;
    padding: 8px 12px;
    resize: none;
    overflow-y: hidden;
  }
  
  .message-input-container #sendBtn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    border-radius: 50% !important;
    padding: 0 !important;
  }
}

/* =================================================================
   MOBILE: Sidebar Expand Button (Swipe Handle)
================================================================= */

@media (max-width: 768px) {
  /* Show expand button on mobile when in chat view */
  body.mobile-chat-active .sidebar-expand-btn {
    opacity: 1;
    pointer-events: auto;
    left: 0;
    width: 24px;
    height: 80px;
    border-radius: 0 12px 12px 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-left: none;
  }
  
  .sidebar-expand-btn::after {
    content: '‹';
    font-size: 20px;
    color: var(--text-muted);
  }
  
  body.mobile-chat-active .sidebar-expand-btn::after {
    content: '‹';
  }
}

/* =================================================================
   PULL TO REFRESH - Peek behind the screen
================================================================= */

.pull-refresh-bg {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 140px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 10px;
  background: linear-gradient(180deg, #0d1117 0%, #161b22 50%, #1a1f26 100%);
  z-index: 0;
  opacity: 0;
  transition: opacity 0.2s ease-out;
  overflow: hidden;
  pointer-events: none;
}

/* Grid floor effect */
.pull-refresh-bg::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: 
    linear-gradient(90deg, rgba(88, 101, 242, 0.1) 1px, transparent 1px),
    linear-gradient(0deg, rgba(88, 101, 242, 0.1) 1px, transparent 1px);
  background-size: 20px 20px;
  transform: perspective(200px) rotateX(60deg);
  transform-origin: bottom;
}

.pull-refresh-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
}

.pull-text {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.pull-refresh-bg.ready .pull-text {
  color: #3fb950;
}

/* Isometric Server Room - Peeking behind the screen */
.server-farm {
  position: relative;
  width: 220px;
  height: 90px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.server-rack {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  transform: perspective(400px) rotateX(5deg);
}

.server {
  width: 32px;
  height: 55px;
  background: linear-gradient(180deg, #484f58 0%, #2d333b 100%);
  border-radius: 4px;
  position: relative;
  box-shadow: 
    0 6px 12px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.15),
    inset 0 -1px 0 rgba(0,0,0,0.3);
}

/* LED status light */
.server::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  height: 5px;
  background: #3fb950;
  border-radius: 2px;
  box-shadow: 0 0 10px #3fb950, 0 0 20px rgba(63, 185, 80, 0.3);
  animation: serverBlink 2s ease-in-out infinite;
}

/* Ventilation slots */
.server::after {
  content: '';
  position: absolute;
  top: 18px;
  left: 6px;
  right: 6px;
  bottom: 8px;
  background: repeating-linear-gradient(
    0deg,
    #21262d 0px,
    #21262d 5px,
    #161b22 5px,
    #161b22 10px
  );
  border-radius: 2px;
}

/* Varying server heights */
.server:nth-child(1) { height: 50px; }
.server:nth-child(2) { height: 60px; }
.server:nth-child(3) { height: 55px; }

/* Different blink timing per server */
.server:nth-child(1)::before { animation-delay: 0s; }
.server:nth-child(2)::before { animation-delay: 0.7s; background: #58a6ff; box-shadow: 0 0 10px #58a6ff, 0 0 20px rgba(88, 166, 255, 0.3); }
.server:nth-child(3)::before { animation-delay: 1.4s; }

@keyframes serverBlink {
  0%, 90%, 100% { opacity: 1; }
  95% { opacity: 0.3; }
}

/* Cute Robots working hard */
.robot {
  position: absolute;
  font-size: 22px;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.6));
  animation: robotBounce 1s ease-in-out infinite;
  z-index: 5;
}

.robot-1 {
  bottom: 5px;
  left: 15px;
  animation-delay: 0s;
}

.robot-2 {
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  animation-delay: 0.33s;
  font-size: 20px;
}

.robot-3 {
  bottom: 5px;
  right: 15px;
  animation-delay: 0.66s;
}

@keyframes robotBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes robotWork {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-4px) rotate(-10deg); }
  75% { transform: translateY(-4px) rotate(10deg); }
}

.pull-refresh-bg.refreshing .server::before {
  animation: blinkFast 0.15s infinite !important;
}

@keyframes blinkFast {
  0%, 100% { opacity: 1; background: #3fb950; box-shadow: 0 0 15px #3fb950; }
  50% { opacity: 1; background: #f0883e; box-shadow: 0 0 15px #f0883e; }
}

.pull-refresh-bg.refreshing .robot {
  animation: robotWork 0.25s ease-in-out infinite !important;
}

.pull-refresh-bg.refreshing .pull-text {
  color: #f0883e;
}

/* =================================================================
   PULL SCENES - Different for each panel
================================================================= */

.pull-scene {
  position: relative;
  width: 220px;
  height: 90px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

/* Scene 1: Files - Creatures organizing folders */
.files-scene .file-cabinet {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.files-scene .drawer {
  width: 40px;
  height: 45px;
  background: linear-gradient(180deg, #8b6914 0%, #5c4a0f 100%);
  border-radius: 4px;
  position: relative;
  box-shadow: 0 4px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}

.files-scene .drawer::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 6px;
  background: #c9a227;
  border-radius: 2px;
}

.files-scene .drawer-1 { height: 40px; }
.files-scene .drawer-2 { height: 50px; }
.files-scene .drawer-3 { height: 45px; }

.files-scene .creature {
  position: absolute;
  font-size: 24px;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.5));
  animation: creatureBounce 1s ease-in-out infinite;
}

.files-scene .creature-1 { bottom: 5px; left: 20px; animation-delay: 0s; }
.files-scene .creature-2 { bottom: 5px; right: 20px; animation-delay: 0.5s; }

.files-scene .floating-file {
  position: absolute;
  font-size: 16px;
  animation: fileFloat 2s ease-in-out infinite;
}

.files-scene .file-1 { top: 10px; left: 40px; animation-delay: 0s; }
.files-scene .file-2 { top: 5px; left: 100px; animation-delay: 0.7s; }
.files-scene .file-3 { top: 15px; right: 40px; animation-delay: 1.4s; }

@keyframes fileFloat {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-8px) rotate(5deg); }
}

@keyframes creatureBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* Scene 2: Chat - Creatures chatting */
.chat-scene .chat-creatures {
  display: flex;
  gap: 20px;
  align-items: flex-end;
}

.chat-scene .chatter {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: chatterBounce 1.2s ease-in-out infinite;
}

.chat-scene .chatter-1 { animation-delay: 0s; }
.chat-scene .chatter-2 { animation-delay: 0.4s; }
.chat-scene .chatter-3 { animation-delay: 0.8s; }

.chat-scene .chatter-avatar {
  font-size: 28px;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.5));
}

.chat-scene .speech-bubble {
  font-size: 18px;
  animation: bubblePop 1.5s ease-in-out infinite;
  position: relative;
  top: -5px;
}

.chat-scene .chatter-1 .speech-bubble { animation-delay: 0.2s; }
.chat-scene .chatter-2 .speech-bubble { animation-delay: 0.6s; }
.chat-scene .chatter-3 .speech-bubble { animation-delay: 1s; }

@keyframes chatterBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes bubblePop {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
}

/* Scene 4: Tools - Creatures with tools */
.tools-scene .workbench {
  width: 120px;
  height: 35px;
  background: linear-gradient(180deg, #4a3728 0%, #2d2118 100%);
  border-radius: 4px;
  position: relative;
  box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}

.tools-scene .workbench::before {
  content: '';
  position: absolute;
  top: -3px;
  left: -5px;
  right: -5px;
  height: 6px;
  background: linear-gradient(180deg, #5c4632 0%, #3d2d1f 100%);
  border-radius: 2px;
}

.tools-scene .mechanic {
  position: absolute;
  font-size: 26px;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.5));
  animation: mechanicWork 0.8s ease-in-out infinite;
}

.tools-scene .mechanic-1 { bottom: 5px; left: 15px; animation-delay: 0s; }
.tools-scene .mechanic-2 { bottom: 5px; left: 50%; transform: translateX(-50%); animation-delay: 0.27s; }
.tools-scene .mechanic-3 { bottom: 5px; right: 15px; animation-delay: 0.54s; }

.tools-scene .floating-tool {
  position: absolute;
  font-size: 18px;
  animation: toolSpin 2s linear infinite;
}

.tools-scene .tool-1 { top: 8px; left: 35px; animation-delay: 0s; }
.tools-scene .tool-2 { top: 5px; left: 50%; animation-delay: 0.7s; animation-duration: 3s; }
.tools-scene .tool-3 { top: 12px; right: 35px; animation-delay: 1.4s; }

@keyframes mechanicWork {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-4px) rotate(-5deg); }
  75% { transform: translateY(-4px) rotate(5deg); }
}

@keyframes toolSpin {
  0% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-10px) rotate(180deg); }
  100% { transform: translateY(0) rotate(360deg); }
}

/* Refreshing states for all scenes */
.pull-refresh-bg.refreshing .creature,
.pull-refresh-bg.refreshing .chatter,
.pull-refresh-bg.refreshing .mechanic {
  animation-duration: 0.3s !important;
}

.pull-refresh-bg.refreshing .floating-file,
.pull-refresh-bg.refreshing .speech-bubble,
.pull-refresh-bg.refreshing .floating-tool {
  animation-duration: 0.5s !important;
}

/* =================================================================
   CONFETTI CELEBRATION 🎉
================================================================= */

.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

.confetti {
  position: absolute;
  top: -20px;
  width: 12px;
  height: 12px;
  animation: confettiFall linear forwards;
  opacity: 0.9;
}

.confetti.square {
  border-radius: 2px;
}

.confetti.circle {
  border-radius: 50%;
  width: 10px;
  height: 10px;
}

.confetti.ribbon {
  width: 8px;
  height: 20px;
  border-radius: 2px;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg) scale(1);
    opacity: 1;
  }
  25% {
    transform: translateY(25vh) rotate(180deg) scale(0.9);
    opacity: 0.9;
  }
  50% {
    transform: translateY(50vh) rotate(360deg) scale(0.8);
    opacity: 0.8;
  }
  75% {
    transform: translateY(75vh) rotate(540deg) scale(0.7);
    opacity: 0.6;
  }
  100% {
    transform: translateY(110vh) rotate(720deg) scale(0.5);
    opacity: 0;
  }
}

/* =================================================================
   CHAT CONTEXT MENU
================================================================= */

.chat-context-menu {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  min-width: 150px;
  padding: 6px;
  z-index: 1000;
  animation: menuFadeIn 0.15s ease;
}

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

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.context-menu-item:hover {
  background: var(--bg-hover);
}

.context-menu-item.danger {
  color: var(--danger);
}

.context-menu-item.danger:hover {
  background: rgba(218, 55, 60, 0.15);
}

.context-menu-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  position: relative;
}

.context-menu-item.disabled:hover {
  background: transparent;
}

.context-menu-item.disabled::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  margin-left: 8px;
  z-index: 10002;
}

.context-menu-item.disabled:hover::after {
  opacity: 1;
}

.context-menu-item.active {
  color: var(--accent);
}

.context-menu-submenu {
  position: relative;
}

.submenu-arrow {
  margin-left: auto;
  opacity: 0.5;
}

.context-submenu-items {
  display: none;
  position: absolute;
  left: 100%;
  top: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  min-width: 140px;
  z-index: 10001;
  padding: 4px 0;
}

.context-submenu-items.show {
  display: block;
}

/* Show submenu on hover (desktop) */
.context-menu-submenu:hover > .context-submenu-items {
  display: block;
}

/* Mobile: show submenu below instead of to the right */
@media (max-width: 768px) {
  .context-submenu-items {
    position: relative;
    left: 0;
    margin-top: 4px;
    box-shadow: none;
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 0;
    padding-left: 20px;
  }
}

.context-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

/* =================================================================
   PINNED CHATS
================================================================= */

.chat-item.pinned {
  background: rgba(88, 101, 242, 0.08);
}

.chat-item.pinned:hover {
  background: rgba(88, 101, 242, 0.15);
}

.pin-icon {
  font-size: 10px;
  margin-right: 4px;
}

/* Chat/Project indicator icons with instant tooltips */
.chat-indicators {
  display: inline-flex;
  align-items: center;
  margin-right: 4px;
  gap: 2px;
}

.chat-indicator {
  font-size: 10px;
  position: relative;
  cursor: default;
}

.chat-indicator::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  margin-bottom: 4px;
  z-index: 1000;
}

@media (hover: hover) {
  .chat-indicator:hover::after {
    opacity: 1;
  }
}

.chat-name {
  display: flex;
  align-items: center;
}

.chat-menu-btn {
  opacity: 0;
  transition: opacity 0.2s;
}

@media (hover: hover) {
  .chat-item:hover .chat-menu-btn {
    opacity: 1;
  }
}

.chat-item.active .chat-menu-btn {
  opacity: 1;
}

@media (max-width: 768px) {
  .chat-menu-btn {
    opacity: 0.7;
    /* Larger touch target on mobile */
    min-width: 44px;
    min-height: 44px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    margin: -8px;
    padding: 8px;
  }
  
  .chat-actions {
    opacity: 1 !important;
  }
}
