:root {
  --bg-main: #131314;
  --bg-input: #1e1f20;
  --bg-bubble: #2a2a2d;
  --bg-hover: #252527;
  --text-primary: #e3e3e3;
  --text-secondary: #9aa0a6;
  --text-hint: #5f6368;
  --border-subtle: rgba(255,255,255,0.08);
  --border-input: rgba(255,255,255,0.1);
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-xl: 28px;
  --radius-full: 9999px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  font-family: 'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI',
               'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

.app {
  display: flex;
  height: 100%;
  overflow: hidden;
  position: relative;
}

/* ========== Sidebar Overlay ========== */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.sidebar-overlay.active { opacity: 1; pointer-events: auto; }

/* ========== Sidebar ========== */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 300px;
  background: var(--bg-main);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding-top: var(--safe-top);
  border-right: 1px solid var(--border-subtle);
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  flex-shrink: 0;
}

.sidebar-search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  color: var(--text-hint);
  font-size: 14px;
}
.sidebar-search svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-avatar { width: 28px; height: 28px; }
.sidebar-avatar svg { width: 18px; height: 18px; }

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  text-decoration: none;
}
.sidebar-item:hover { background: var(--bg-hover); }
.sidebar-item svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--text-secondary); }
.sidebar-item.sub { padding-left: 28px; }
.sidebar-item.sub svg { width: 18px; height: 18px; }

.sidebar-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 4px;
}
.sidebar-section .sidebar-section-label { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.sidebar-section svg { width: 12px; height: 12px; color: var(--text-secondary); }

.sidebar-divider { height: 1px; background: var(--border-subtle); margin: 8px 16px; }

.sidebar-section-label-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-hint);
  padding: 8px 16px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-chat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 14px 16px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.sidebar-chat:hover { background: var(--bg-hover); }
.sidebar-chat.active { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-chat span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-chat svg { width: 16px; height: 16px; opacity: 0.4; flex-shrink: 0; margin-left: 8px; }

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.hub-link { color: var(--text-secondary); font-size: 13px; }
.hub-link svg { width: 18px; height: 18px; }

.main {
  flex: 1;
  display: flex;
  min-width: 0;
  width: 100%;
}

/* Left rail — desktop only */
.left-rail {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 52px;
  padding: 8px 6px;
  flex-shrink: 0;
  padding-top: calc(8px + var(--safe-top));
}
.rail-spacer { flex: 1; }
.left-rail .icon-btn { width: 40px; height: 40px; }
.left-rail .icon-btn svg { width: 20px; height: 20px; }

.main-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ========== Top Bar ========== */
.topbar {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  flex-shrink: 0;
  padding-top: calc(6px + var(--safe-top));
  min-height: 48px;
}

.topbar-title {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-primary);
  margin-left: 4px;
}

.topbar-spacer { flex: 1; }

.topbar-conv-title {
  flex: 1;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-full);
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); }
.icon-btn svg { width: 20px; height: 20px; }

.pro-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border: 1px solid var(--text-hint);
  border-radius: 4px;
  margin: 0 4px;
}

.user-avatar-img {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(100,149,237,0.5);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  margin-left: 4px;
}
.user-avatar-img svg { width: 20px; height: 20px; }

/* ========== Chat Area ========== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

.chat-area.empty { justify-content: flex-start; }
.chat-area.empty .messages { flex: 1; display: flex; }

.messages {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px 24px;
  display: flex;
  flex-direction: column;
}

/* ========== Empty State ========== */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
}

.greeting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.greeting-sparkle svg {
  width: 22px;
  height: 22px;
}

.greeting-small {
  font-size: 18px;
  color: var(--text-secondary);
}

.greeting-large {
  font-size: 28px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 28px;
  line-height: 1.3;
  text-align: center;
}

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  background: none;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.chip:hover { background: var(--bg-hover); }
.chip-icon { font-size: 15px; line-height: 1; }

/* ========== User Message ========== */
.message { animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-user {
  display: flex;
  justify-content: flex-end;
  padding: 20px 0 8px;
}

.message-bubble {
  background: var(--bg-bubble);
  border-radius: var(--radius-xl);
  padding: 12px 20px;
  max-width: 85%;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
}

/* ========== Assistant Message ========== */
.message-assistant {
  padding: 16px 0;
}

.assistant-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.gemini-sparkle {
  width: 28px; height: 28px;
  flex-shrink: 0;
}

.thinking-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 0;
}
.thinking-toggle svg {
  width: 14px; height: 14px;
  opacity: 0.6;
  margin-top: 1px;
}

.assistant-header .more-btn {
  margin-left: auto;
}

.assistant-content {
  font-size: 16px;
  line-height: 1.8;
  color: var(--text-primary);
  padding-left: 38px;
}

.assistant-content p { margin-bottom: 16px; }
.assistant-content p:last-child { margin-bottom: 0; }

.assistant-content h4 {
  font-size: 16px;
  font-weight: 600;
  margin: 24px 0 10px;
}
.assistant-content h4:first-child { margin-top: 8px; }

.assistant-content ul {
  padding-left: 20px;
  margin-bottom: 14px;
}

.assistant-content li {
  margin-bottom: 10px;
  line-height: 1.7;
}

.assistant-content strong {
  font-weight: 600;
}

/* ========== Response Actions ========== */
.response-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 38px;
  margin-top: 16px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-full);
  padding: 6px;
  transition: background 0.15s;
}
.action-btn:hover { background: var(--bg-hover); }
.action-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.action-btn span {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

/* Typing indicator */
.typing-dots {
  display: flex;
  gap: 5px;
  padding: 8px 0;
  padding-left: 38px;
}
.typing-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-hint);
  animation: dotPulse 1.4s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

/* ========== Input Area ========== */
.input-area {
  padding: 0 12px;
  padding-bottom: calc(4px + var(--safe-bottom));
  flex-shrink: 0;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.input-container {
  background: var(--bg-input);
  border-radius: var(--radius-xl);
  padding: 0 16px;
  transition: border-color 0.15s;
}
.input-container:focus-within { background: #252527; }

.input-box {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 16px;
  font-family: inherit;
  line-height: 1.5;
  padding: 14px 0 4px;
  outline: none;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
}
.input-box::placeholder { color: var(--text-hint); }

.input-toolbar {
  display: flex;
  align-items: center;
  padding: 4px 0 8px;
  gap: 2px;
}

.tool-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
  gap: 6px;
}
.tool-btn:hover { background: var(--bg-hover); }
.tool-btn svg { width: 20px; height: 20px; flex-shrink: 0; }

.tool-text-btn {
  width: auto;
  padding: 0 10px 0 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-secondary);
}

.toolbar-spacer { flex: 1; }

.model-tag {
  display: flex;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.model-tag:hover { background: var(--bg-hover); }
.model-tag svg { width: 12px; height: 12px; opacity: 0.6; }

.mic-btn {
  width: 40px; height: 40px;
}

.input-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-hint);
  padding: 6px 0 2px;
}

/* ========== Send button (appears when has text) ========== */
.send-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bg-bubble);
  color: var(--text-primary);
  display: none;
  align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn.visible { display: flex; }
.send-btn svg { width: 18px; height: 18px; }

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ========== Responsive ========== */
.sidebar-collapse-btn { display: none; }

@media (min-width: 768px) {
  .sidebar {
    position: relative;
    transform: none;
    flex-shrink: 0;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .sidebar-overlay { display: none; }
  .sidebar-collapse-btn { display: flex; }
  .left-rail { display: none; }
  .topbar .menu-btn { display: none; }

  .app.sidebar-collapsed .sidebar { margin-left: -300px; }
  .app.sidebar-collapsed .left-rail { display: flex; }
  .app.sidebar-collapsed .topbar .menu-btn { display: flex; }

  .messages { padding: 0 32px 24px; }
  .input-area { padding: 0 24px; padding-bottom: 12px; }
  .message-bubble { max-width: 65%; }
}
