:root {
  --bg-page: #f5f6f8;
  --bg-sidebar: rgba(255,255,255,0.85);
  --blur-sidebar: blur(24px);
  --bg-bubble-user: #e8f0fe;
  --bg-bubble-ai: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #5f6368;
  --accent: #4f6ef7;
  --danger: #d93025;
  --radius-bubble: 18px;
  --radius-input: 28px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-input: 0 2px 12px rgba(0,0,0,0.06);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
* { margin:0; padding:0; box-sizing:border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.app-wrapper {
  display: flex;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  backdrop-filter: var(--blur-sidebar);
  -webkit-backdrop-filter: var(--blur-sidebar);
  border-right: none;
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease, transform 0.25s ease;
  z-index: 20;
  position: relative;
  flex-shrink: 0;
}
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .conv-list,
.sidebar.collapsed .icon-btn span { display: none; }
.sidebar.collapsed .icon-btn { justify-content: center; }
.sidebar-header {
  padding: 18px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: none;
}
.sidebar-title { font-weight: 600; font-size: 16px; color: var(--text-primary); }
.sidebar-controls { display: flex; gap: 4px; }
.icon-btn {
  background: none;
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.icon-btn:hover { background: rgba(0,0,0,0.04); color: var(--text-primary); }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-item {
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: 12px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.conv-item:hover { background: rgba(0,0,0,0.03); }
.conv-item.active { background: rgba(79,110,247,0.08); }
.conv-item.active::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 60%;
  background: var(--accent);
  border-radius: 4px;
}
.conv-item .title {
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.conv-item .meta { display: none; }
.conv-item .delete-conv {
  display: none;
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
  padding: 4px;
  border-radius: 6px;
}
.conv-item:hover .delete-conv { display: flex; align-items: center; }

@media (max-width: 768px) {
  .sidebar {
    position: fixed; top:0; left:0; bottom:0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 100;
    background: var(--bg-sidebar);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    position: fixed; inset:0;
    background: rgba(0,0,0,0.3);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
  }
  .sidebar-overlay.active { opacity: 1; pointer-events: auto; }
}

.main-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-page);
}

.login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  padding: 20px;
}
.login h2 { font-weight: 600; font-size: 28px; color: var(--text-primary); }
.login .login-hint { color: var(--text-secondary); font-size: 15px; margin-bottom: 8px; }
.login-label { display: block; text-align: left; font-size: 14px; color: var(--text-primary); width: 100%; max-width: 320px; }
.login input {
  width: 100%; max-width: 320px;
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 14px;
  font-size: 15px;
  outline: none;
  transition: var(--transition);
  background: #ffffff;
}
.login input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,110,247,0.1); }
.totp-input { letter-spacing: 4px; }
.btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: #3b5de7; box-shadow: 0 4px 12px rgba(79,110,247,0.3); }
.btn:disabled { opacity: 0.5; cursor: default; box-shadow: none; }
.btn.logout-btn { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.qr-btn { background: #10b981; }
.btn.qr-btn:hover { background: #059669; }
.error-msg { color: var(--danger); font-size: 14px; min-height: 20px; }

.qr-container {
  text-align: center; margin-top: 16px;
  padding: 16px; background: #ffffff;
  border-radius: 20px; box-shadow: var(--shadow-sm);
  width: 100%; max-width: 320px;
}
.qr-container img { width: 200px; height: 200px; border-radius: 12px; }
.qr-hint { font-size: 13px; color: var(--text-secondary); margin-top: 8px; }
.qr-expired { color: var(--danger); }
.qr-timer { font-size: 12px; color: #9aa0a6; margin-top: 4px; }

.chat { display: none; flex-direction: column; height: 100%; }
.chat.active { display: flex; }

.chat-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  background: transparent;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
.sidebar-toggle { font-size: 18px; color: var(--text-secondary); cursor: pointer; background: none; border: none; }
.sidebar-toggle:hover { color: var(--text-primary); }
.spacer { flex: 1; }
.logout-link { font-size: 13px; color: var(--text-secondary); cursor: pointer; background: none; border: none; }
.logout-link:hover { color: var(--danger); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

.msg { display: flex; flex-direction: column; max-width: 85%; animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } }
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }
.msg-bubble {
  padding: 16px 20px;
  font-size: 15px;
  line-height: 1.7;
  word-break: break-word;
}
.msg.user .msg-bubble {
  background: var(--bg-bubble-user);
  color: var(--text-primary);
  border-radius: var(--radius-bubble) var(--radius-bubble) 4px var(--radius-bubble);
  margin-left: auto;
}
.msg.assistant .msg-bubble {
  background: var(--bg-bubble-ai);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-bubble) var(--radius-bubble) var(--radius-bubble) 4px;
}
.reasoning-box {
  margin-bottom: 6px;
  background: #f7f8fa;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: #4b5563;
  cursor: pointer;
}
.reasoning-box summary { font-weight: 500; color: var(--accent); margin-bottom: 4px; }

.msg-bubble pre {
  background: #f0f0f0;
  border-radius: 6px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.9em;
}
.msg-bubble code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  background: rgba(0,0,0,0.05);
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.9em;
}
.msg-bubble pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

.input-section {
  padding: 16px 24px 20px;
  background: transparent;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}
.model-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}
.model-minitab {
  padding: 5px 14px;
  border-radius: 20px;
  cursor: pointer;
  background: rgba(0,0,0,0.04);
  border: none;
  color: var(--text-secondary);
  transition: var(--transition);
  font-size: 13px;
  font-weight: 500;
}
.model-minitab.active { background: var(--accent); color: white; }
.model-minitab:disabled { opacity: 0.5; cursor: not-allowed; }
.thinking-minitoggle {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 5px 14px;
  border-radius: 20px;
  background: rgba(0,0,0,0.04);
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
}
.thinking-minitoggle input { margin: 0; accent-color: var(--accent); }

.input-wrapper {
  display: flex;
  align-items: center;
  background: #ffffff;
  border-radius: var(--radius-input);
  padding: 8px 8px 8px 22px;
  box-shadow: var(--shadow-input);
  transition: box-shadow 0.2s;
}
.input-wrapper:focus-within { box-shadow: 0 0 0 2px rgba(79,110,247,0.2), var(--shadow-input); }
.input-wrapper input {
  flex: 1;
  border: none;
  padding: 12px 0;
  font-size: 15px;
  outline: none;
  background: transparent;
  color: var(--text-primary);
}
.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.send-btn:hover { background: #3b5de7; }
.send-btn:disabled { opacity: 0.5; cursor: default; }
.stop-btn {
  background: var(--danger);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 13px;
}

.hidden { display: none !important; }

@media (max-width: 768px) {
  .messages { padding: 12px 12px 0; max-width: 100%; }
  .input-section { padding: 12px 12px 16px; }
  .msg-bubble { padding: 12px 16px; font-size: 14px; }
  .sidebar-toggle { font-size: 20px; }
  .reasoning-box { font-size: 13px; padding: 8px 12px; }
}