/* ══════════════════════════════════════════════════════════════
   Hermes Mobile Hub v2 — UX/UI Promax Theme
   ══════════════════════════════════════════════════════════════ */

/* ── Theme Variables ───────────────────────────────────────── */
:root {
  --bg-0: #0a0f1e;
  --bg-1: #111827;
  --bg-2: #1e293b;
  --bg-3: #334155;
  --bg-glass: rgba(17, 24, 39, 0.72);
  --bg-bubble-user: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  --bg-bubble-ai: #1e293b;
  --border: rgba(71, 85, 105, 0.5);
  --border-focus: #3b82f6;
  --text-1: #f1f5f9;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --accent: #f59e0b;
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-purple: #8b5cf6;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.5);
  --header-h: 56px;
  --font-sans: 'Inter', 'Noto Sans Thai', -apple-system, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;
  --transition: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

html.light {
  --bg-0: #f8fafc;
  --bg-1: #ffffff;
  --bg-2: #f1f5f9;
  --bg-3: #e2e8f0;
  --bg-glass: rgba(255, 255, 255, 0.78);
  --bg-bubble-user: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  --bg-bubble-ai: #ffffff;
  --border: rgba(203, 213, 225, 0.6);
  --border-focus: #3b82f6;
  --text-1: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg-0);
  color: var(--text-1);
  overflow: hidden;
  height: 100dvh;
  width: 100vw;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ────────────────────────────────────────────────── */
.app-layout { display: flex; height: 100dvh; width: 100vw; position: relative; overflow: hidden; }

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 310px; max-width: 85vw;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  z-index: 100;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--transition);
  box-shadow: 4px 0 30px rgba(0,0,0,0.5);
}
.sidebar.open { transform: translateX(0); }

.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(3px);
  z-index: 90;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }

.sidebar-header {
  padding-top: max(18px, calc(14px + env(safe-area-inset-top, 0px)));
  padding-bottom: 14px;
  padding-left: 16px;
  padding-right: 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-avatar {
  width: 36px; height: 36px;
  background: rgba(245,158,11,0.12);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(245,158,11,0.3);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.brand-avatar svg { width: 22px; height: 22px; }
.brand-info h2 { font-size: 15px; font-weight: 700; }
.text-accent { color: var(--accent); }

.badge-online {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--accent-green); font-weight: 500;
}
.pulse-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent-green);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Profile Cards */
.profile-section { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.section-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-3); margin-bottom: 8px; }
.profile-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(85px, 1fr)); gap: 6px;
}
.profile-card {
  padding: 8px 6px; border-radius: var(--radius-sm);
  background: var(--bg-2); border: 1px solid transparent;
  text-align: center; cursor: pointer;
  transition: all 0.2s ease; font-size: 11px;
}
.profile-card:active, .profile-card.active { border-color: var(--accent); background: rgba(245,158,11,0.08); }
.profile-card .p-emoji {
  display: flex; align-items: center; justify-content: center;
  height: 24px; margin-bottom: 4px; color: var(--accent);
}
.profile-card .p-emoji svg { width: 20px; height: 20px; }
.profile-card .p-name { font-weight: 600; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-card .p-count { font-size: 10px; color: var(--text-3); }

.sidebar-actions { padding: 10px 14px; }

/* Search */
.search-box {
  padding: 0 14px 8px; position: relative;
}
.search-icon { position: absolute; left: 24px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search-box input {
  width: 100%; padding: 8px 10px 8px 32px;
  background: var(--bg-0); border: 1px solid var(--border); border-radius: var(--radius-full);
  color: var(--text-1); font-size: 13px; outline: none;
  transition: border-color 0.2s;
}
.search-box input:focus { border-color: var(--accent-blue); }

/* Sessions */
.sessions-header {
  padding: 4px 14px; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-3);
  display: flex; align-items: center; justify-content: space-between;
}
.sessions-list {
  flex: 1; overflow-y: auto; padding: 4px 10px 8px; display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: thin; scrollbar-color: var(--bg-3) transparent;
}
.session-group-label {
  padding: 6px 6px 2px; font-size: 10px; font-weight: 700;
  color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px;
}
.session-item {
  padding: 10px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
  transition: all 0.15s ease;
}
.session-item:hover { background: rgba(255,255,255,0.03); }
.session-item:active { background: rgba(255,255,255,0.06); }
.session-item.active { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); }
.session-title {
  font-size: 13px; font-weight: 600; color: var(--text-1);
  margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-meta { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); }

/* Skeleton */
.skeleton-card, .skeleton-session {
  background: linear-gradient(90deg, var(--bg-2) 25%, var(--bg-3) 50%, var(--bg-2) 75%);
  background-size: 200% 100%; border-radius: var(--radius-sm);
  animation: shimmer 1.5s infinite;
}
.skeleton-card { height: 56px; }
.skeleton-session { height: 48px; margin-bottom: 4px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

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

/* ── Main Content ──────────────────────────────────────────── */
.main-content {
  flex: 1; display: flex; flex-direction: column;
  height: 100dvh; position: relative; background: var(--bg-0);
  overflow-x: hidden; min-width: 0;
}

/* Top Bar — Glassmorphism with Safe Area support */
.top-bar {
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  padding-bottom: 8px;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  min-height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  box-sizing: border-box;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-glass);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  z-index: 10; position: sticky; top: 0;
}
.active-session-meta { flex: 1; margin: 0 10px; overflow: hidden; display: flex; align-items: center; gap: 8px; min-width: 0; }
.profile-pill {
  font-size: 10px; padding: 2px 8px; font-weight: 600;
  background: rgba(245,158,11,0.12); color: var(--accent);
  border: 1px solid rgba(245,158,11,0.25); border-radius: var(--radius-full);
  white-space: nowrap; display: inline-flex; align-items: center; gap: 4px;
  flex-shrink: 0;
}
.profile-pill svg { width: 12px; height: 12px; }
.active-session-meta h1 {
  font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.top-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

/* ── Chat Container ────────────────────────────────────────── */
.chat-container {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px 12px;
  display: flex; flex-direction: column;
  scroll-behavior: smooth;
  scrollbar-width: thin; scrollbar-color: var(--bg-3) transparent;
  min-width: 0;
}

/* Welcome */
.welcome-box {
  margin: 32px auto; max-width: 400px; text-align: center;
  padding: 28px 20px; position: relative; overflow: hidden;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.welcome-glow {
  position: absolute; top: -40px; left: 50%; transform: translateX(-50%);
  width: 200px; height: 200px; border-radius: 50%;
  background: radial-gradient(circle, rgba(245,158,11,0.15) 0%, transparent 70%);
  pointer-events: none;
}
.welcome-icon { font-size: 42px; margin-bottom: 10px; position: relative; }
.welcome-box h2 { font-size: 17px; margin-bottom: 6px; position: relative; }
.welcome-box p { font-size: 13px; color: var(--text-2); line-height: 1.5; margin-bottom: 14px; position: relative; }
.quick-tips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; position: relative; }
.tip-pill {
  font-size: 11px; background: var(--bg-2); padding: 4px 10px;
  border-radius: var(--radius-full); color: var(--text-2);
  border: 1px solid var(--border);
}

/* Messages */
.messages-list {
  display: flex; flex-direction: column; gap: 8px;
  width: 100%; max-width: 780px; margin: 0 auto;
}

/* Message Row */
.msg-row {
  display: flex; gap: 8px; width: 100%;
  animation: msgSlideUp 0.3s ease-out;
  min-width: 0;
}
@keyframes msgSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px;
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--accent);
}
.msg-avatar svg { width: 16px; height: 16px; }
.msg-row.user .msg-avatar { background: rgba(124,58,237,0.15); color: #8b5cf6; order: 2; }

.msg-content {
  display: flex; flex-direction: column;
  max-width: 88%; min-width: 0;
  word-break: break-word; overflow-wrap: anywhere;
}
.msg-row.assistant .msg-content {
  max-width: calc(100% - 36px);
}

.msg-bubble {
  padding: 10px 14px; border-radius: var(--radius-md);
  font-size: 14px; line-height: 1.65;
  word-break: break-word; overflow-wrap: anywhere;
  position: relative; min-width: 0; max-width: 100%;
  box-sizing: border-box;
}
.msg-bubble:empty { display: none !important; }
.msg-row:has(.msg-bubble:empty) { display: none !important; }
.msg-row.user .msg-bubble {
  background: var(--bg-bubble-user); color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-row.assistant .msg-bubble {
  background: var(--bg-bubble-ai); border: 1px solid var(--border);
  color: var(--text-1); border-bottom-left-radius: 4px;
  width: fit-content; max-width: 100%;
}
.msg-time { font-size: 10px; color: var(--text-3); margin-top: 3px; padding: 0 4px; }
.msg-row.user .msg-time { text-align: right; }

/* Image in bubble */
.msg-image, .msg-bubble img {
  max-width: min(280px, 100%); max-height: 220px; border-radius: var(--radius-sm);
  margin-top: 4px; margin-bottom: 6px; cursor: pointer; object-fit: cover;
  border: 1px solid var(--border);
  display: block;
  transition: transform 0.2s;
}
.msg-image:active, .msg-bubble img:active { transform: scale(0.97); }

/* Markdown inside bubbles */
.msg-bubble p { margin-bottom: 6px; word-break: break-word; overflow-wrap: anywhere; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble pre {
  position: relative; margin: 8px 0;
  background: #0d1117; border: 1px solid rgba(71,85,105,0.3);
  border-radius: var(--radius-sm);
  overflow-x: auto; max-width: 100%;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}
.msg-bubble pre code {
  display: block; padding: 10px 12px;
  font-family: var(--font-mono); font-size: 12.5px;
  background: none;
  white-space: pre;
  word-break: normal;
  word-wrap: normal;
}
.msg-bubble code {
  background: rgba(0,0,0,0.25); padding: 1px 5px;
  border-radius: 4px; font-family: var(--font-mono); font-size: 12.5px;
  word-break: break-word; overflow-wrap: anywhere;
}
.msg-bubble ul, .msg-bubble ol { margin-left: 18px; margin-bottom: 6px; word-break: break-word; }
.msg-bubble blockquote {
  border-left: 3px solid var(--accent); padding-left: 10px;
  color: var(--text-2); margin: 6px 0;
  word-break: break-word; overflow-wrap: anywhere;
}
.msg-bubble table {
  border-collapse: collapse; margin: 8px 0; font-size: 13px;
  display: block; max-width: 100%; overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.msg-bubble th, .msg-bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.msg-bubble th { background: var(--bg-2); font-weight: 600; }

/* Code Copy Button */
.code-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 10px; background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(71,85,105,0.3);
  font-family: var(--font-mono); font-size: 11px; color: var(--text-3);
}
.code-copy-btn {
  background: none; border: none; color: var(--text-3); cursor: pointer;
  font-size: 11px; display: flex; align-items: center; gap: 3px;
  padding: 2px 6px; border-radius: 4px; transition: all 0.15s;
}
.code-copy-btn:hover { color: var(--text-1); background: rgba(255,255,255,0.08); }
.code-copy-btn.copied { color: var(--accent-green); }

/* Tool Pill */
.tool-pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; background: rgba(245,158,11,0.08);
  color: var(--accent); border: 1px solid rgba(245,158,11,0.2);
  border-radius: var(--radius-full); padding: 3px 10px; margin-bottom: 6px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 0 0 8px; max-width: 780px; margin: 0 auto; width: 100%;
  animation: msgSlideUp 0.3s ease-out;
}
.typing-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-2); border: 1px solid var(--border);
  flex-shrink: 0; color: var(--accent);
}
.typing-avatar svg { width: 16px; height: 16px; }
.typing-bubble {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: var(--radius-md); border-bottom-left-radius: 4px;
}
.typing-dots { display: flex; gap: 4px; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-3);
  animation: bounce 1.4s infinite ease-in-out both;
}
.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}
.typing-label { font-size: 12px; color: var(--text-3); }

/* Scroll FAB */
.scroll-fab {
  position: absolute; bottom: 140px; right: 16px;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md); transition: all 0.2s;
  animation: fadeIn 0.2s ease;
}
.scroll-fab:active { transform: scale(0.92); }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }

/* Drop Zone */
.drop-zone {
  position: absolute; inset: var(--header-h) 0 0 0; z-index: 20;
  background: rgba(10,15,30,0.85); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.drop-zone-inner {
  text-align: center; padding: 40px;
  border: 2px dashed var(--accent-blue); border-radius: var(--radius-lg);
  color: var(--accent-blue);
}
.drop-zone-inner p { margin-top: 10px; font-size: 15px; font-weight: 600; }

/* Attachment Preview */
.attach-preview {
  padding: 6px 12px;
  background: var(--bg-1); border-top: 1px solid var(--border);
}
.attach-items { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0; }
.attach-thumb {
  position: relative; flex-shrink: 0;
  width: 64px; height: 64px; border-radius: var(--radius-sm);
  overflow: hidden; border: 1px solid var(--border);
  background: var(--bg-2);
}
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach-thumb .file-icon {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; font-size: 11px; color: var(--text-2);
  text-align: center; word-break: break-all; padding: 4px;
}
.attach-remove {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,0.7); color: #fff; border: none;
  font-size: 11px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* ── Input Bar ─────────────────────────────────────────────── */
.input-bar {
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-1); border-top: 1px solid var(--border);
}
.input-wrapper {
  display: flex; align-items: flex-end; gap: 4px;
  background: var(--bg-0); border: 1.5px solid var(--border);
  border-radius: 24px; padding: 4px 6px;
  max-width: 780px; margin: 0 auto;
  transition: border-color 0.2s, box-shadow 0.3s;
}
.input-wrapper:focus-within {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.input-left-actions, .input-right-actions { display: flex; align-items: center; gap: 2px; margin-bottom: 2px; }
.input-wrapper textarea {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text-1); font-size: 14px; resize: none;
  min-height: 24px;
  max-height: 160px; line-height: 1.45; padding: 6px 4px;
  font-family: var(--font-sans);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  word-break: break-word;
  min-width: 0;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  padding: 8px 14px; border-radius: var(--radius-sm); border: none;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.15s; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; font-family: var(--font-sans);
}
.btn-primary { background: var(--accent-blue); color: #fff; }
.btn-primary:active { background: #1d4ed8; transform: scale(0.97); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:active { background: rgba(255,255,255,0.05); }
.btn-block { width: 100%; }
.btn-sm { font-size: 12px; padding: 6px 10px; }

.btn-send {
  width: 36px; height: 36px; padding: 0; border-radius: 50%;
  background: var(--accent-blue); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.btn-send:active { transform: scale(0.9); background: #1d4ed8; }

.icon-btn {
  width: 36px; height: 36px; display: flex; align-items: center;
  justify-content: center; background: transparent; border: none;
  color: var(--text-2); border-radius: 50%; cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:active { background: rgba(255,255,255,0.08); color: var(--text-1); }
.icon-btn.active { color: var(--accent-red); }
.icon-btn-sm {
  background: none; border: none; color: var(--text-3);
  cursor: pointer; display: flex; align-items: center;
}

/* ── Modals ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(6px);
  z-index: 200; display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px;
  width: 100%; max-width: 380px; text-align: center;
  box-shadow: var(--shadow-lg);
}
.animate-in { animation: modalPop 0.3s ease-out; }
@keyframes modalPop {
  from { opacity: 0; transform: scale(0.9) translateY(16px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-icon { font-size: 36px; margin-bottom: 10px; }
.modal-card h3 { font-size: 17px; margin-bottom: 6px; }
.modal-card p { font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
.modal-card input {
  width: 100%; padding: 12px; border-radius: var(--radius-sm);
  background: var(--bg-0); border: 1px solid var(--border);
  color: var(--text-1); font-size: 20px; text-align: center;
  letter-spacing: 6px; outline: none; margin-bottom: 10px;
  font-family: var(--font-mono);
  transition: border-color 0.2s;
}
.modal-card input:focus { border-color: var(--accent-blue); }
.error-msg { color: var(--accent-red); font-size: 12px; margin-bottom: 10px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; text-align: left;
}
.connect-options { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.connect-item {
  background: var(--bg-0); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px; position: relative;
}
.item-badge {
  position: absolute; top: 8px; right: 8px; font-size: 10px;
  background: rgba(16,185,129,0.15); color: var(--accent-green);
  padding: 1px 6px; border-radius: 6px; font-weight: 600;
}
.connect-item h4 { font-size: 13px; margin-bottom: 4px; }
.code-box {
  background: #000; color: #38bdf8; padding: 7px 10px;
  border-radius: 6px; font-family: var(--font-mono);
  font-size: 13px; user-select: all;
}

/* Image Viewer */
.viewer-close {
  position: absolute; top: 16px; right: 16px; z-index: 210;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0,0,0,0.6); border: none; color: #fff;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.viewer-img { max-width: 95vw; max-height: 90vh; object-fit: contain; border-radius: var(--radius-sm); }

.hidden { display: none !important; }
.loading-state { text-align: center; padding: 16px; color: var(--text-3); font-size: 13px; }

/* ── Desktop ───────────────────────────────────────────────── */
@media (min-width: 900px) {
  .sidebar { position: relative; transform: none; max-width: 290px; box-shadow: none; }
  .sidebar-overlay { display: none !important; }
  .mobile-only { display: none !important; }
  #btn-open-sidebar { display: none; }
}

/* ── Section Header Row ────────────────────────────────────────── */
.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.icon-btn-xs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--accent);
  border-radius: var(--radius-full);
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.icon-btn-xs:active {
  transform: scale(0.95);
  background: rgba(245, 158, 11, 0.25);
}

/* ── Meta Badges in Top Bar ────────────────────────────────────── */
.meta-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.model-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  background: rgba(14, 165, 233, 0.12);
  border: 1px solid rgba(14, 165, 233, 0.3);
  color: #38bdf8;
  cursor: pointer;
  transition: all 0.2s;
}
.model-pill:active {
  transform: scale(0.95);
  background: rgba(14, 165, 233, 0.25);
}

/* ── Session Delete Button ─────────────────────────────────────── */
.session-item {
  position: relative;
  padding-right: 32px !important;
}
.session-delete-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-3);
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0.5;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.session-item:hover .session-delete-btn,
.session-delete-btn:focus,
.session-delete-btn:active {
  opacity: 1;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

/* ── File Download Card ────────────────────────────────────────── */
.file-download-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin: 8px 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-1);
  transition: all 0.2s ease;
  max-width: 360px;
}
.file-download-card:hover {
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.4);
}
.file-card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.file-card-info {
  flex: 1;
  min-width: 0;
}
.file-card-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-card-sub {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
}
.file-card-action {
  color: var(--accent);
  display: flex;
  align-items: center;
  padding-left: 4px;
}

/* ── Models Grid & Modal ───────────────────────────────────────── */
.modal-md {
  max-width: 440px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.models-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 12px;
  padding-right: 4px;
}
.model-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  color: var(--text-1);
}
.model-item:hover, .model-item.active {
  border-color: var(--accent);
  background: rgba(245, 158, 11, 0.08);
}
.model-item.active .model-name {
  color: var(--accent);
  font-weight: 600;
}
.model-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-3);
}
.custom-model-input-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.custom-model-input-row input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-family: inherit;
  font-size: 12px;
  outline: none;
}
.custom-model-input-row input:focus {
  border-color: var(--accent);
}
.form-group {
  margin-bottom: 12px;
  text-align: left;
}
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 4px;
}
.form-group input, .form-group textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.form-group input:focus, .form-group textarea:focus {
  border-color: var(--accent);
}

/* ── Agent switch (Hermes / OpenCode) ───────────────────────────── */
.agent-switch {
  display: flex;
  gap: 6px;
  padding: 10px 12px 2px;
}
.agent-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.agent-tab:active { transform: scale(0.97); }
.agent-tab.active {
  color: var(--text-1);
  border-color: var(--accent);
  background: rgba(245, 158, 11, 0.12);
}
.agent-tab.active svg { color: var(--accent); }

/* ── OpenCode tool chips ────────────────────────────────────────── */
.tool-status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}
.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  color: var(--text-2);
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  padding: 3px 8px;
  border-radius: var(--radius-full);
}
.tool-chip.tool-done { color: var(--accent-green); border-color: rgba(16, 185, 129, 0.35); background: rgba(16, 185, 129, 0.08); }
.tool-chip.tool-error { color: var(--accent-red); border-color: rgba(239, 68, 68, 0.4); background: rgba(239, 68, 68, 0.08); }
.tool-chip b { font-weight: 700; font-size: 9.5px; opacity: 0.7; }
.tool-pill.tool-error { color: var(--accent-red); border-color: rgba(239, 68, 68, 0.4); }
.mini-spinner {
  width: 9px; height: 9px;
  border: 2px solid rgba(148, 163, 184, 0.35);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Permission approval card ───────────────────────────────────── */
.permission-card {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  max-width: 100%;
}
.permission-card.perm-approved {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.45);
}
.permission-card.perm-denied {
  background: rgba(239, 68, 68, 0.07);
  border-color: rgba(239, 68, 68, 0.45);
}
.permission-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-1);
  margin-bottom: 8px;
}
.permission-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.18);
  flex: none;
}
.permission-resources {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}
.permission-resources code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  word-break: break-all;
}
.permission-message { font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.permission-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.permission-actions .btn { flex: 1; min-width: 96px; }
.permission-actions .perm-reject { color: var(--accent-red); }
.permission-result { font-size: 12px; color: var(--accent-green); font-weight: 600; }
.permission-result.error { color: var(--accent-red); }

/* ── Search Messages ──────────────────────────────────────────── */
.search-messages-container {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.search-messages-input {
  flex: 1; padding: 6px 12px; border-radius: var(--radius-full);
  background: var(--bg-0); border: 1px solid var(--border);
  color: var(--text-1); font-size: 12px; outline: none;
  transition: all 0.2s;
  width: 0; opacity: 0; visibility: hidden; max-width: 200px;
}
.search-messages-input:focus {
  width: 200px; opacity: 1; visibility: visible;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.search-messages-input::placeholder { color: var(--text-3); }
.search-messages-btn {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius-full);
  background: transparent; border: none; color: var(--text-3);
  cursor: pointer; padding: 0; margin-left: 4px;
  transition: background 0.15s;
}
.search-messages-btn:active { background: var(--bg-2); }
.search-messages-btn:hover { color: var(--accent); }

/* ── Message Search Results ───────────────────────────────────── */
.msg-row.search-highlight {
  animation: searchHighlight 0.3s ease;
}
@keyframes searchHighlight {
  from { background: rgba(59,130,246,0.15); }
  to { background: transparent; }
}

/* ── Search: expanded state (ปุ่มกดเปิด/ปิดได้ ไม่ต้องพึ่ง :focus) ── */
.search-messages-input.open,
.search-messages-input:focus {
  width: min(200px, 38vw);
  opacity: 1; visibility: visible;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.search-messages-container { gap: 2px; }
.top-bar.searching #top-profile-badge,
.top-bar.searching #btn-model-selector { display: none; }
.top-bar.searching .search-messages-input.open,
.top-bar.searching .search-messages-input:focus { width: min(260px, 58vw); }
/* ตอนเปิดค้นหา: ซ่อน pill/ชื่อแชทแล้วให้ช่องค้นหากินเต็มแถบ */
.top-bar.searching .active-session-meta { display: none; }
.top-bar.searching .search-messages-container { flex: 1; margin: 0 8px; min-width: 0; }
.top-bar.searching .search-messages-input.open,
.top-bar.searching .search-messages-input:focus { width: 100%; max-width: none; }
/* ตัวนับผลลัพธ์ค้นหา */
.search-hits {
  font-size: 10px; font-weight: 700; font-family: var(--font-mono);
  color: var(--accent-green); background: rgba(16,185,129,0.12);
  border: 1px solid rgba(16,185,129,0.3); border-radius: var(--radius-full);
  padding: 1px 6px; min-width: 16px; text-align: center; flex-shrink: 0;
}
.search-hits.empty { color: var(--accent-red); background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); }
.search-hits:empty { display: none; }

/* ── IP card (sidebar footer) ─────────────────────────────────── */
.ip-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.ip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px;
}
.ip-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.5;
}
.ip-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  opacity: 0.85;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ip-value.busy { opacity: 0.55; }
/* ── ปุ่มส่ง: ปิดเมื่อยังไม่มีข้อความ/ไฟล์ ── */
.btn-send:disabled { opacity: 0.35; cursor: default; }
.btn-send:disabled:active { transform: none; background: var(--accent-blue); }

/* ── แถบหัวบนจอแคบ: จำกัดความกว้าง pill ให้ชื่อแชทมีที่ ── */
.profile-pill span { max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#current-model-label { max-width: 76px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.active-session-meta h1 { flex: 1 1 auto; min-width: 48px; }
/* จอแคบ: ย่อ pill โปรไฟล์เหลือไอคอน เพื่อคืนที่ให้ชื่อแชท */
@media (max-width: 430px) {
  #top-profile-badge span { display: none; }
  #top-profile-badge { padding: 3px 7px; }
  .active-session-meta { gap: 6px; }
  .profile-pill svg { width: 13px; height: 13px; }
}
/* จอแคบ: ชื่อแชทลงบรรทัดที่สองเต็มความกว้าง (pills + ปุ่มอยู่บรรทัดแรก) */
@media (max-width: 430px) {
  .top-bar { flex-wrap: wrap; row-gap: 4px; }
  .active-session-meta { display: contents; }
  .top-actions { order: 3; margin-left: auto; }
  .active-session-meta h1 { order: 5; flex: 1 0 100%; margin: 0; font-size: 13px; }
}
@media (max-width: 430px) {
  #current-model-label { max-width: 150px; }
}
