 /* Enhanced Mobile Responsiveness with Height Adjustments - White Theme */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-card: #ffffff;
  --primary: #1e40af;
  --primary-hover: #1d4ed8;
  --accent: #2563eb;
  --accent-weak: rgba(37, 99, 235, 0.08);
  --text-primary: #1f2937;
  --text-secondary: #374151;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08);
  --shadow-soft: 0 4px 12px rgba(0,0,0,0.04);
  --glow: 0 0 0 2px rgba(37, 99, 235, 0.15);
  --safe-area-inset-top: env(safe-area-inset-top);
  --safe-area-inset-bottom: env(safe-area-inset-bottom);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.6;
  padding-top: var(--safe-area-inset-top);
  padding-bottom: var(--safe-area-inset-bottom);
}

/* Main Layout */
.shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: stretch;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg-secondary);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* Mobile First Styles */
.mobile-bar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 12px 16px;
  background: var(--bg-primary);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  padding-top: calc(12px + var(--safe-area-inset-top));
}

.m-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.m-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hamb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  display: grid;
  place-items: center;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.hamb:hover {
  border-color: var(--accent);
  background: var(--accent-weak);
  transform: translateY(-1px);
}

.brand-mini {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 160px;
  height: 44px;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 16px;
  overflow: hidden;
}

.logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-title {
  font-family: 'Inter', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

/* Sidebar */
.side {
  width: 360px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px;
  position: relative;
  z-index: 50;
  box-shadow: var(--shadow-soft);
  height: 100%;
  overflow: hidden;
}

.brand {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.brand h1 {
  margin: 0;
  font-family: 'Inter', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.brand small {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

.side h3 {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.history {
  overflow: auto;
  padding-right: 8px;
  flex: 1;
  height: 0; /* Allow flex to control height */
}

.history::-webkit-scrollbar {
  width: 6px;
}

.history::-webkit-scrollbar-track {
  background: transparent;
}

.history::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.history::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.chat-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--radius);
  margin: 12px 0;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  box-shadow: var(--shadow);
}

.chat-card:hover {
  border-color: var(--accent);
  background: var(--accent-weak);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.chat-card.active {
  border-color: var(--accent);
  background: var(--accent-weak);
  box-shadow: var(--glow);
}

.chat-card .title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.chat-card .preview {
  color: var(--text-muted);
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.chat-card .meta {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.side-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.btn {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  flex: 1;
  justify-content: center;
  font-family: 'Inter', sans-serif;
  min-height: 44px;
}

.btn:hover {
  border-color: var(--accent);
  background: var(--accent-weak);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--bg-primary);
  border-color: var(--border);
  color: var(--danger);
}

.btn-danger:hover {
  border-color: var(--danger);
  background: rgba(220, 38, 38, 0.08);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-accent {
  background: var(--bg-primary);
  border-color: var(--accent);
  color: var(--accent);
}

/* Mobile Drawer */
.drawer {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1000;
}

.drawer.open {
  display: block;
}

.drawer .overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.3);
  backdrop-filter: blur(4px);
}

.drawer .panel {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 85%;
  max-width: 360px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  transform: translateX(-100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  height: 100%;
  overflow: hidden;
  padding-top: calc(24px + var(--safe-area-inset-top));
}

.drawer.open .panel {
  transform: translateX(0);
}

/* Main Content */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  position: relative;
  overflow: hidden;
  height: 100%;
}

.top {
  padding: 20px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-primary);
  box-shadow: var(--shadow-soft);
  flex-shrink: 0;
}

.heading {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.top h2 {
  font-family: 'Inter', sans-serif;
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.top p {
  color: var(--text-muted);
  margin: 0;
  font-size: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'Inter', sans-serif;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  box-shadow: var(--shadow);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Chat Area */
.canvas {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 24px;
  position: relative;
  z-index: 1;
  overflow: hidden;
  height: 0; /* Allow flex to control height */
}

.chat {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.messages {
  flex: 1;
  padding: 28px 28px 20px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--bg-primary);
  scroll-behavior: smooth;
  min-height: 0;
  height: 0; /* Allow flex to control height */
}

.messages::-webkit-scrollbar {
  width: 8px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.msg {
  display: flex;
  gap: 16px;
  max-width: 90%;
  animation: fadeInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  display: grid;
  place-items: center;
  color: var(--accent);
  border: 1px solid var(--border);
  flex: 0 0 auto;
  font-weight: 600;
  font-size: 16px;
  box-shadow: var(--shadow);
}

.user .avatar {
  background: var(--primary);
  color: white;
  border: 1px solid var(--primary);
}

.bubble {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  line-height: 1.6;
  font-size: 15px;
  color: var(--text-primary);
  max-width: 100%;
  word-wrap: break-word;
  position: relative;
  font-family: 'Inter', sans-serif;
  box-shadow: var(--shadow);
}

.user .bubble {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.bubble .meta {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Inter', sans-serif;
}

.user .bubble .meta {
  color: rgba(255,255,255,0.8);
}

.copy-response-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0.7;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
}

.copy-response-btn:hover {
  color: var(--accent);
  opacity: 1;
  background: var(--accent-weak);
}

.copy-response-btn.copied {
  color: var(--success);
}

.copy-response-btn.copied svg {
  stroke: var(--success);
}

.bubble .clean-response {
  font-family: 'Inter', sans-serif;
  line-height: 1.7;
}

.bubble .clean-response p {
  margin: 12px 0;
}

.bubble .clean-response ul, .bubble .clean-response ol {
  margin: 12px 0;
  padding-left: 24px;
}

.bubble .clean-response li {
  margin: 6px 0;
}

.bubble .clean-response strong {
  font-weight: 600;
  color: inherit;
}

/* Message Input */
.composer {
  position: sticky;
  bottom: 0;
  padding: 20px 28px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  z-index: 10;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.03);
  flex-shrink: 0;
  padding-bottom: calc(20px + var(--safe-area-inset-bottom));
}

.inputbar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: var(--bg-primary);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.inputbar:focus-within {
  border-color: var(--accent);
  box-shadow: var(--glow);
}

textarea {
  flex: 1;
  resize: none;
  height: 52px;
  max-height: 120px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
  font-family: 'Inter', system-ui, sans-serif;
}

textarea::placeholder {
  color: var(--text-muted);
}

.tools {
  display: flex;
  gap: 12px;
  align-items: center;
}

.chip-btn {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 12px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  user-select: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Inter', sans-serif;
  min-height: 44px;
}

.chip-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-weak);
  transform: translateY(-1px);
}

.chip-btn input {
  display: none;
}

.send {
  background: var(--primary);
  border: 1px solid var(--primary);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Inter', sans-serif;
  min-height: 44px;
}

.send:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.send:disabled {
  opacity: .6;
  cursor: not-allowed;
}

/* File Upload */
.dropzone {
  margin-top: 16px;
  display: none;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  transition: all 0.3s ease;
  font-family: 'Inter', sans-serif;
}

.dropzone.active {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: var(--accent);
}

.file-list {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.file-pill {
  background: var(--bg-primary);
  border: 1px solid var(--success);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 20px;
  display: flex;
  gap: 8px;
  align-items: center;
  transition: all 0.3s ease;
  font-family: 'Inter', sans-serif;
  background: rgba(5, 150, 105, 0.08);
}

.file-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.file-pill button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: auto;
}

.file-pill button:hover {
  background: var(--danger);
  color: white;
}

.file-attachments {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.file-attachments-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingAnimation 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingAnimation {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Scroll to Bottom */
.scroll-to-bottom {
  position: absolute;
  bottom: 100px;
  right: 28px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 20;
  opacity: 0;
  transform: translateY(10px);
}

.scroll-to-bottom.visible {
  opacity: 1;
  transform: translateY(0);
}

.scroll-to-bottom:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
}

/* Delete Button */
.delete-chat-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  opacity: 0.7;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.delete-chat-btn:hover {
  color: var(--danger);
  opacity: 1;
  background: rgba(220, 38, 38, 0.08);
}

/* Additional Components */
.mode-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 12px;
  background: var(--accent-weak);
  color: var(--accent);
  border: 1px solid rgba(37, 99, 235, 0.2);
}

.mode-info-panel {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-soft);
}

.mode-info-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.mode-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: white;
}

.mode-info-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.mode-info-description {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.mode-features {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.mode-feature {
  background: var(--bg-secondary);
  padding: 6px 10px;
  border-radius: 16px;
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.file-upload-info {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.file-upload-info ul {
  margin: 8px 0 0 16px;
}

.file-upload-info li {
  margin: 4px 0;
}

.clean-response {
  font-family: 'Inter', system-ui, sans-serif;
  line-height: 1.7;
}

.clean-response p {
  margin: 12px 0;
}

.clean-response ul, .clean-response ol {
  margin: 12px 0;
  padding-left: 24px;
}

.clean-response li {
  margin: 6px 0;
}

.clean-response strong {
  font-weight: 600;
  color: var(--text-primary);
}

/* Search Bar */
.search-container {
  margin-bottom: 16px;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  transition: all 0.3s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--glow);
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* Settings Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(4px);
  padding: 20px;
  box-sizing: border-box;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: var(--radius-xl);
  padding: 28px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: scale(0.9) translateY(-20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-title {
  font-family: 'Inter', sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 6px;
  transition: all 0.3s ease;
}

.modal-close:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Enhanced Mobile Responsiveness */
@media (max-width: 1100px) {
  .mobile-bar {
    display: block;
  }
  
  .side {
    display: none;
  }
  
  .shell {
    max-width: 100%;
  }
  
  .chat {
    border-radius: 0;
    border-left: none;
    border-right: none;
    height: 100%;
  }
  
  .canvas {
    padding: 0;
    height: 100%;
  }
  
  .messages {
    padding: 20px 20px 12px;
    max-height: none;
    height: 0; /* Allow flex to control height */
  }
  
  .msg {
    max-width: 95%;
  }
  
  .top {
    padding: 16px 20px;
  }
  
  .avatar {
    width: 40px;
    height: 40px;
  }
  
  .bubble {
    padding: 16px;
  }
}

@media (max-width: 768px) {
  .shell {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }
  
  .side {
    width: 100%;
    height: auto;
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: none;
  }
  
  .side.active {
    display: flex;
  }
  
  .main {
    flex: 1;
    height: 0; /* Allow flex to control height */
  }
  
  .mobile-bar {
    display: flex;
    padding: 12px 16px;
    flex-shrink: 0;
  }
  
  .top {
    padding: 12px 16px;
    flex-shrink: 0;
  }
  
  .top h2 {
    font-size: 18px;
  }
  
  .messages {
    padding: 16px;
    max-height: none;
    height: 0; /* Allow flex to control height */
  }
  
  .msg {
    max-width: 95%;
    gap: 10px;
  }
  
  .avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }
  
  .bubble {
    padding: 12px;
    font-size: 14px;
  }
  
  .composer {
    padding: 16px;
    flex-shrink: 0;
  }
  
  .inputbar {
    padding: 12px;
    flex-direction: column;
    gap: 12px;
  }
  
  .tools {
    width: 100%;
    justify-content: space-between;
  }
  
  .chip-btn, .send {
    padding: 10px 14px;
    font-size: 13px;
    min-height: 44px;
  }
  
  .file-pill {
    font-size: 12px;
    padding: 6px 10px;
  }
  
  .scroll-to-bottom {
    bottom: 90px;
    right: 20px;
    width: 40px;
    height: 40px;
  }
  
  .logo {
    width: 140px;
    height: 40px;
  }
  
  .brand-title {
    font-size: 17px;
  }
  
  .canvas {
    padding: 0;
    height: 0; /* Allow flex to control height */
  }
}

@media (max-width: 480px) {
  .mobile-bar {
    padding: 10px 12px;
  }
  
  .top {
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .top h2 {
    font-size: 16px;
  }
  
  .messages {
    padding: 12px;
  }
  
  .msg {
    max-width: 98%;
    gap: 8px;
  }
  
  .avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
  }
  
  .bubble {
    padding: 10px;
    font-size: 13px;
  }
  
  .composer {
    padding: 12px;
  }
  
  .inputbar {
    padding: 10px;
  }
  
  textarea {
    font-size: 14px;
    min-height: 44px;
  }
  
  .side-actions {
    flex-wrap: wrap;
  }
  
  .btn {
    padding: 10px 12px;
    font-size: 13px;
    min-height: 44px;
  }
  
  .modal-content {
    margin: 0;
    padding: 20px;
    width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-lg);
  }
  
  .drawer .panel {
    width: 90%;
    padding: 20px;
  }
  
  .inputbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .tools {
    flex-direction: row;
    justify-content: space-between;
  }
  
  .chip-btn, .send {
    flex: 1;
    min-width: 0;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  .btn, .chip-btn, .send {
    min-height: 44px;
    padding: 12px 16px;
  }
  
  .file-pill button {
    min-width: 32px;
    min-height: 32px;
  }
  
  .copy-response-btn {
    min-width: 32px;
    min-height: 32px;
  }
  
  input, textarea {
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  .chat-card {
    padding: 14px;
  }
  
  /* Increase tap targets */
  .avatar {
    min-width: 44px;
    min-height: 44px;
  }
  
  .hamb {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Desktop specific styles */
@media (min-width: 1101px) {
  .mobile-bar {
    display: none;
  }
  
  .drawer {
    display: none !important;
  }
}

/* Height optimization for very small screens */
@media (max-height: 600px) {
  .brand {
    margin-bottom: 16px;
    padding-bottom: 12px;
  }
  
  .side h3 {
    margin: 0 0 12px;
  }
  
  .chat-card {
    padding: 12px;
    margin: 8px 0;
  }
  
  .messages {
    padding: 16px 16px 12px;
    gap: 16px;
  }
  
  .bubble {
    padding: 14px;
  }
  
  .composer {
    padding: 16px;
  }
}

/* Landscape mode optimizations */
@media (max-width: 768px) and (orientation: landscape) {
  .side {
    max-height: 70vh;
  }
  
  .messages {
    max-height: none;
  }
  
  .composer {
    padding-bottom: calc(16px + var(--safe-area-inset-bottom));
  }
}