/* ─── Reset & base ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; }

:root {
  --blue-dark: #1F3864;
  --blue: #2E75B6;
  --blue-light: #D6E4F0;
  --bg: #F0F2F5;
  --sidebar-bg: #1a2744;
  --sidebar-text: #c8d4e8;
  --border: #e0e4ed;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

/* ─── Login page ─────────────────────────────────────────────────────── */
.login-page {
  background: linear-gradient(135deg, #1a2744 0%, #2E75B6 100%);
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.login-box {
  background: #fff; border-radius: 16px; padding: 40px 36px;
  width: 400px; max-width: 95vw; box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.login-logo { display: flex; align-items: center; gap: 14px; margin-bottom: 32px; }
.logo-icon {
  width: 48px; height: 48px; background: var(--blue-dark); color: #fff;
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: bold;
}
.logo-title { font-size: 18px; font-weight: 700; color: var(--blue-dark); }
.logo-sub { font-size: 12px; color: #888; margin-top: 2px; }

.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: #444; margin-bottom: 6px; }
.input-row { display: flex; gap: 8px; }
.form-group input {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; outline: none; transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--blue); }
.field-hint { font-size: 12px; color: #999; margin-top: 5px; }

.btn-primary {
  width: 100%; padding: 13px; background: var(--blue); color: #fff; border: none;
  border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; transition: background 0.2s;
  margin-top: 4px;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { background: #aaa; cursor: not-allowed; }

.btn-secondary {
  padding: 11px 16px; background: var(--blue-light); color: var(--blue);
  border: 1.5px solid var(--blue); border-radius: 8px; font-size: 13px;
  font-weight: 600; cursor: pointer; white-space: nowrap; transition: all 0.2s; flex-shrink: 0;
}
.btn-secondary:hover { background: var(--blue); color: #fff; }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.email-display {
  padding: 10px 14px; background: #f5f7fa; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 14px; color: #555;
}
.link-row { display: flex; justify-content: space-between; margin-top: 12px; }
.link-row a { font-size: 13px; color: var(--blue); text-decoration: none; }
.link-row a:hover { text-decoration: underline; }
.set-pwd-banner {
  background: #e8f5e9; color: #2e7d32; border-radius: 8px;
  padding: 12px 14px; font-size: 14px; margin-bottom: 16px; text-align: center;
}
.btn-outline {
  padding: 13px; background: #fff; color: #666; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 14px; cursor: pointer; transition: all 0.15s;
}
.btn-outline:hover { border-color: #aaa; color: #333; }

.msg { margin-top: 14px; padding: 10px 14px; border-radius: 8px; font-size: 13px; min-height: 36px; }
.msg.success { background: #e6f4ea; color: #2e7d32; }
.msg.error { background: #fde8e8; color: #c62828; }

/* ─── Chat page layout ───────────────────────────────────────────────── */
.chat-page { display: flex; height: 100vh; background: var(--bg); overflow: hidden; }

/* ─── Sidebar ────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; flex-shrink: 0;
  transition: width 0.22s ease; overflow: hidden;
}
.sidebar.collapsed { width: 0; }

.sidebar-header {
  height: 56px; padding: 0 12px 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 15px; font-weight: 700; color: #fff; flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sidebar-collapse-btn {
  background: none; border: none; color: rgba(255,255,255,0.35); cursor: pointer;
  width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.15s, color 0.15s;
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.sidebar-collapse-btn svg { transition: transform 0.22s ease; }
.sidebar.collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }

/* 折叠时显示在左边缘的展开 tab */
.sidebar-expand-tab {
  display: none; position: fixed; left: 0; top: 50%; transform: translateY(-50%);
  background: var(--sidebar-bg); color: rgba(255,255,255,0.6);
  border: none; cursor: pointer; padding: 10px 5px; border-radius: 0 6px 6px 0;
  font-size: 12px; z-index: 100; transition: color 0.15s;
}
.sidebar-expand-tab:hover { color: #fff; }
.sidebar.collapsed ~ .sidebar-expand-tab,
.sidebar-expand-tab.visible { display: block; }
.logo-icon-sm {
  width: 28px; height: 28px; background: var(--blue); color: #fff;
  border-radius: 7px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: bold; flex-shrink: 0;
}

/* New chat */
.sidebar-new { padding: 16px 14px 12px; flex-shrink: 0; }
.btn-new-chat {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 9px 0;
  background: transparent; color: #a8c0e8;
  border: 1.5px dashed rgba(255,255,255,0.2); border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.15s;
}
.btn-new-chat:hover {
  background: rgba(255,255,255,0.08); color: #fff;
  border-color: rgba(255,255,255,0.35);
}

/* History */
.sidebar-history {
  flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0;
}
.sidebar-label {
  padding: 0 14px 6px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: #3d5070;
}
.conv-list { flex: 1; overflow-y: auto; padding: 0 6px 8px; }
.conv-list::-webkit-scrollbar { width: 3px; }
.conv-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }
.conv-empty { font-size: 12px; color: #3d5070; padding: 8px 8px; }

.conv-item {
  padding: 8px 8px 7px; border-radius: 7px; cursor: pointer;
  color: var(--sidebar-text); transition: background 0.12s; margin-bottom: 2px;
  display: flex; flex-direction: column; gap: 3px;
}
.conv-item:hover { background: rgba(255,255,255,0.07); }
.conv-item.active { background: rgba(255,255,255,0.12); color: #fff; }
.conv-item-title {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px;
}
.conv-item-meta { font-size: 10.5px; color: #3d5070; display: flex; gap: 5px; align-items: center; }
.conv-item-meta .archived-dot { color: #4caf50; font-size: 8px; }

/* Footer */
.sidebar-footer {
  flex-shrink: 0; padding: 10px 12px 14px;
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex; flex-direction: column; gap: 10px;
}
.user-info { display: flex; align-items: center; gap: 8px; padding: 0 2px; }
.user-avatar {
  width: 26px; height: 26px; background: var(--blue); color: #fff; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
#userName { font-size: 13px; color: #a0b4cc; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-actions { display: flex; gap: 6px; }
.btn-ghost {
  flex: 1; padding: 7px 4px;
  background: rgba(255,255,255,0.05); color: #8aa0bc;
  border: 1px solid rgba(255,255,255,0.08); border-radius: 7px;
  font-size: 12px; cursor: pointer; transition: all 0.15s; text-align: center;
}
.btn-ghost:hover { background: rgba(255,255,255,0.12); color: #fff; border-color: rgba(255,255,255,0.18); }

/* Main chat */
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-header {
  padding: 16px 24px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}
.chat-title { font-size: 16px; font-weight: 700; color: var(--blue-dark); }
.chat-subtitle { font-size: 12px; color: #999; }

/* Messages */
.messages {
  flex: 1; overflow-y: auto; padding: 24px 24px 8px;
  display: flex; flex-direction: column; gap: 16px;
}

.welcome-msg {
  text-align: center; padding: 48px 24px; color: #888;
}
.welcome-icon { font-size: 40px; margin-bottom: 12px; }
.welcome-title { font-size: 18px; font-weight: 600; color: var(--blue-dark); margin-bottom: 8px; }
.welcome-desc { font-size: 14px; line-height: 1.7; color: #666; }
.welcome-desc em { font-style: normal; color: var(--blue); }
.example-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.chip {
  padding: 7px 14px; background: var(--blue-light); color: var(--blue); border: 1px solid #b8d4ee;
  border-radius: 20px; font-size: 13px; cursor: pointer; transition: all 0.15s;
}
.chip:hover { background: var(--blue); color: #fff; }

/* Message bubbles */
.msg-row { display: flex; gap: 10px; align-items: flex-start; }
.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
}
.msg-row.user .msg-avatar { background: var(--blue); color: #fff; }
.msg-row.assistant .msg-avatar { background: var(--blue-dark); color: #fff; }

.msg-content { max-width: 75%; display: flex; flex-direction: column; }
.msg-row.user .msg-content { align-items: flex-end; }

.msg-bubble {
  padding: 12px 16px; border-radius: 12px; font-size: 14px; line-height: 1.65;
  word-break: break-word;
}

.msg-actions {
  display: flex; gap: 4px; margin-top: 4px;
  opacity: 0; transition: opacity 0.15s;
}
.msg-row:hover .msg-actions { opacity: 1; }
.msg-action-btn {
  background: none; border: 1px solid #d0d7e2; border-radius: 4px;
  padding: 2px 9px; font-size: 11px; color: #888; cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.msg-action-btn:hover { background: #f0f4f8; color: #333; border-color: #b0bcd0; }
.msg-row.user .msg-bubble {
  background: var(--blue); color: #fff; border-top-right-radius: 3px;
}
.msg-row.assistant .msg-bubble {
  background: #fff; color: #333; border-top-left-radius: 3px; box-shadow: var(--shadow);
}

/* Markdown in assistant bubbles */
.msg-row.assistant .msg-bubble h1,
.msg-row.assistant .msg-bubble h2,
.msg-row.assistant .msg-bubble h3 { color: var(--blue-dark); margin: 14px 0 6px; }
.msg-row.assistant .msg-bubble h2 { font-size: 15px; }
.msg-row.assistant .msg-bubble h3 { font-size: 14px; }
.msg-row.assistant .msg-bubble { overflow-x: auto; }
.msg-row.assistant .msg-bubble table {
  border-collapse: collapse; width: max-content; min-width: 100%; margin: 10px 0; font-size: 13px;
}
.msg-row.assistant .msg-bubble th,
.msg-row.assistant .msg-bubble td { white-space: nowrap; }
.msg-row.assistant .msg-bubble th {
  background: var(--blue-dark); color: #fff; padding: 6px 10px; text-align: left;
}
.msg-row.assistant .msg-bubble td { padding: 5px 10px; border: 1px solid #dde; }
.msg-row.assistant .msg-bubble tr:nth-child(even) td { background: #f7f9fc; }
.msg-row.assistant .msg-bubble code {
  background: #f0f4f8; padding: 1px 5px; border-radius: 4px; font-family: monospace; font-size: 12px;
}
.msg-row.assistant .msg-bubble pre { background: #f0f4f8; padding: 10px; border-radius: 6px; overflow-x: auto; margin: 8px 0; }
.msg-row.assistant .msg-bubble pre code { background: none; padding: 0; }
.msg-row.assistant .msg-bubble ul, .msg-row.assistant .msg-bubble ol { padding-left: 20px; margin: 6px 0; }
.msg-row.assistant .msg-bubble strong { color: var(--blue-dark); }
.msg-row.assistant .msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.msg-row.assistant .msg-bubble p { margin: 4px 0; }

/* Typing indicator */
.typing-indicator {
  display: flex; align-items: center; gap: 5px; padding: 4px 24px 0;
  font-size: 13px; color: #999;
}
.dot {
  width: 7px; height: 7px; background: var(--blue); border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Input area */
.input-area { padding: 12px 24px 16px; background: #fff; border-top: 1px solid var(--border); }
.input-box { display: flex; gap: 10px; align-items: flex-end; }
.input-box textarea {
  flex: 1; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; line-height: 1.5; resize: none; outline: none;
  transition: border-color 0.2s; font-family: inherit; max-height: 180px; overflow-y: auto;
}
.input-box textarea:focus { border-color: var(--blue); }
.send-btn {
  width: 42px; height: 42px; background: var(--blue); color: #fff; border: none;
  border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.15s;
}
.send-btn:hover:not(:disabled) { background: var(--blue-dark); }
.send-btn:disabled { background: #ccc; cursor: not-allowed; }
.input-hint { font-size: 11px; color: #bbb; margin-top: 5px; text-align: right; }

/* Similar inquiry hint card */
.similar-hint {
  background: #fffbea; border: 1px solid #f0d060; border-radius: 10px;
  padding: 10px 14px; font-size: 13px; color: #5a4a00;
  margin: 0 0 4px;
}
.similar-header {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; margin-bottom: 8px; color: #7a5f00;
}
.similar-close {
  background: none; border: none; font-size: 16px; cursor: pointer;
  color: #999; line-height: 1; padding: 0 2px;
}
.similar-close:hover { color: #333; }
.similar-item { display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; }
.similar-item:last-child { margin-bottom: 0; }
.similar-model { font-weight: 600; color: #333; }
.similar-meta { font-size: 11.5px; color: #888; }

/* History read-only banner */
.history-banner {
  display: flex; align-items: center; gap: 8px;
  background: #f0f4ff; border: 1px solid #c8d6f0; border-radius: 8px;
  padding: 9px 14px; font-size: 13px; color: #2e4a80; margin-bottom: 4px;
}

/* Tool use label */
.tool-label {
  font-size: 12px; color: #999; font-style: italic; margin: 2px 0; padding: 0 16px;
}

/* ─── Mobile hamburger + backdrop ─────────────────────────────────────── */
/* Default: visible (mobile-first); desktop hides via @media below */
.menu-toggle {
  display: inline-flex; align-items: center;
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--blue-dark);
  padding: 6px 10px; margin-right: 4px; line-height: 1;
  border-radius: 6px;
}
.menu-toggle:hover { background: var(--blue-light); }
.chat-header-row { display: flex; align-items: center; gap: 4px; }
.chat-header-row .chat-title-group { flex: 1; min-width: 0; }

/* Hide welcome during boot (until JS decides state) */
body.booting .welcome-msg { visibility: hidden; }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 90; opacity: 0; transition: opacity 0.2s;
}
.sidebar-backdrop.open { opacity: 1; }

/* ─── Desktop layout (≥769px) ─ hide hamburger ───────────────────────── */
@media (min-width: 769px) {
  .menu-toggle { display: none; }
}

/* ─── Mobile layout (≤768px) ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 240px; z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 14px rgba(0,0,0,0.25);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }

  .chat-main { width: 100%; }
  .chat-header { padding: 12px 14px; }
  .chat-title { font-size: 15px; }
  .chat-subtitle { font-size: 11px; }
  .chat-subtitle.mobile-hide { display: none; }

  .messages { padding: 14px 12px 6px; gap: 12px; }
  .welcome-msg { padding: 32px 12px; }
  .msg-content { max-width: 85%; }
  .msg-bubble { font-size: 14px; padding: 10px 13px; }

  .input-area { padding: 10px 12px 12px; }
  .input-box textarea { font-size: 15px; padding: 10px 12px; }
  .send-btn { width: 40px; height: 40px; }
  .input-hint { display: none; }

  .example-chips { gap: 6px; }
  .chip { font-size: 12px; padding: 6px 12px; }
}
