* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f0f2f5;
  height: 100vh;
  overflow: hidden;
  color: #1a1a2e;
}

/* ── Login page ──────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e2537 0%, #2d3561 100%);
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 48px 40px;
  width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo h1 { font-size: 22px; font-weight: 700; color: #1e2537; margin-top: 12px; }
.login-logo p  { color: #666; font-size: 14px; margin-top: 4px; }

.login-logo svg { width: 56px; height: 56px; }

.tab-switcher {
  display: flex;
  background: #f0f2f5;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 28px;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #666;
  transition: all 0.2s;
}

.tab-btn.active {
  background: #fff;
  color: #2d3561;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.form-group { margin-bottom: 18px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #444;
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #e0e0e0;
  border-radius: 10px;
  font-size: 15px;
  transition: border-color 0.2s;
  outline: none;
}

.form-group input:focus { border-color: #2d3561; }

.hint {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
}

.hint a { color: #2d3561; }

.btn-primary {
  width: 100%;
  padding: 14px;
  background: #2d3561;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover { background: #1e2537; }
.btn-primary:disabled { background: #aaa; cursor: not-allowed; }

.error-msg {
  color: #e74c3c;
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  display: none;
}

.qr-container { text-align: center; padding: 10px 0; }
.qr-container img { width: 200px; height: 200px; border-radius: 12px; }
.qr-container p { margin-top: 12px; color: #666; font-size: 13px; }

.step { display: none; }
.step.active { display: block; }

/* ── Main layout ─────────────────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  width: 320px;
  background: #1e2537;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-title {
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}

.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  outline: none;
}

.search-box input::placeholder { color: rgba(255,255,255,0.4); }

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255,255,255,0.4);
  font-size: 14px;
}

.new-dialog-btn {
  width: 100%;
  padding: 10px;
  margin-top: 10px;
  background: #2d6ef7;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.new-dialog-btn:hover { background: #1a5de0; }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.conv-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.conv-item:hover { background: rgba(255,255,255,0.06); }
.conv-item.active { background: rgba(255,255,255,0.1); }

.conv-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #2d3561;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  position: relative;
}

.highlight-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: #ff4757;
  border-radius: 50%;
  border: 2px solid #1e2537;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.conv-info {
  flex: 1;
  margin-left: 12px;
  min-width: 0;
}

.conv-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
}

.conv-name {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  flex-shrink: 0;
  margin-left: 8px;
}

.conv-bottom {
  display: flex;
  align-items: center;
  gap: 6px;
}

.conv-preview {
  font-size: 13px;
  color: rgba(255,255,255,0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.mode-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.mode-badge.auto  { background: rgba(46,213,115,0.2); color: #2ed573; }
.mode-badge.semi  { background: rgba(255,165,0,0.2);  color: #ffa502; }

/* ── Chat area ───────────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f0f2f5;
  min-width: 0;
  min-height: 0;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #aaa;
}

.empty-state svg { margin-bottom: 16px; opacity: 0.3; }
.empty-state p { font-size: 16px; }

.chat-header {
  padding: 14px 20px;
  background: #fff;
  border-bottom: 1px solid #e8e8e8;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #2d3561;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}

.chat-header-info { flex: 1; }
.chat-header-name { font-size: 16px; font-weight: 600; }
.chat-header-sub  { font-size: 12px; color: #999; margin-top: 1px; }

.header-actions { display: flex; align-items: center; gap: 12px; }

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f5f5f5;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.mode-toggle:hover { background: #e8e8e8; }

.toggle-switch {
  width: 36px;
  height: 20px;
  background: #ffa502;
  border-radius: 10px;
  position: relative;
  transition: background 0.3s;
}

.toggle-switch.on { background: #2ed573; }

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.3s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch.on::after { transform: translateX(16px); }

.mode-label { font-size: 13px; font-weight: 600; color: #444; white-space: nowrap; }

.btn-clear-highlight {
  padding: 6px 14px;
  background: #fff0f0;
  color: #e74c3c;
  border: 1px solid #ffc0c0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-clear-highlight:hover { background: #ffe0e0; }

/* ── Messages ────────────────────────────────────────────────────────── */
.messages-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.messages-area::-webkit-scrollbar { width: 6px; }
.messages-area::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }

.msg-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 2px;
}

.msg-row.us    { align-items: flex-end; }
.msg-row.client { align-items: flex-start; }

.msg-bubble {
  max-width: min(65%, 480px);
  min-width: 60px;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.us .msg-bubble {
  background: #2d6ef7;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-row.client .msg-bubble {
  background: #fff;
  color: #1a1a2e;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.msg-time {
  font-size: 11px;
  margin-top: 4px;
  text-align: right;
  opacity: 0.6;
}

.msg-row.client .msg-time { text-align: left; }

/* ── Suggestion panel ────────────────────────────────────────────────── */
.suggestion-panel {
  background: #fff;
  border-top: 2px solid #2d6ef7;
  padding: 14px 20px;
}

.suggestion-label {
  font-size: 12px;
  font-weight: 600;
  color: #2d6ef7;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.suggestion-text {
  font-size: 14px;
  color: #333;
  line-height: 1.5;
  background: #f8f9ff;
  border: 1px solid #e0e6ff;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  white-space: pre-wrap;
}

.suggestion-actions { display: flex; gap: 8px; }

.btn-send-sug {
  padding: 8px 18px;
  background: #2d6ef7;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-send-sug:hover { background: #1a5de0; }

.btn-edit-sug {
  padding: 8px 18px;
  background: #f5f5f5;
  color: #333;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-edit-sug:hover { background: #e8e8e8; }

.btn-reject-sug {
  padding: 8px 18px;
  background: #fff0f0;
  color: #e74c3c;
  border: 1px solid #ffc0c0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-reject-sug:hover { background: #ffe0e0; }

.btn-regen-sug {
  padding: 8px 18px;
  background: #f5f5f5;
  color: #555;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-regen-sug:hover { background: #e8e8e8; }
.btn-regen-sug:disabled { color: #aaa; cursor: not-allowed; }

/* edit mode */
.suggestion-edit-area {
  width: 100%;
  font-size: 14px;
  border: 1.5px solid #2d6ef7;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  resize: vertical;
  min-height: 80px;
  outline: none;
  font-family: inherit;
  line-height: 1.5;
}

/* ── Input area ──────────────────────────────────────────────────────── */
.input-area {
  background: #fff;
  border-top: 1px solid #e8e8e8;
  padding: 14px 20px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.message-input {
  flex: 1;
  padding: 11px 14px;
  border: 1.5px solid #e0e0e0;
  border-radius: 22px;
  font-size: 14px;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.5;
  max-height: 120px;
  transition: border-color 0.2s;
}

.message-input:focus { border-color: #2d6ef7; }

.send-btn {
  width: 44px;
  height: 44px;
  background: #2d6ef7;
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.send-btn:hover { background: #1a5de0; }
.send-btn:disabled { background: #aaa; cursor: not-allowed; }

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.show { opacity: 1; pointer-events: auto; }

.modal {
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

.modal .form-group input {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid #e0e0e0;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
}

.modal .form-group input:focus { border-color: #2d6ef7; }

.modal-actions { display: flex; gap: 10px; margin-top: 20px; }

.btn-secondary {
  flex: 1;
  padding: 11px;
  background: #f5f5f5;
  color: #333;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.btn-secondary:hover { background: #e8e8e8; }

.modal .btn-primary {
  flex: 1;
  padding: 11px;
  width: auto;
}

/* ── Highlight banner ────────────────────────────────────────────────── */
.highlight-banner {
  background: #fff0f0;
  border-bottom: 1px solid #ffc0c0;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #c0392b;
}

.highlight-banner strong { font-weight: 700; }
.highlight-banner span { flex: 1; }

/* ── Typing indicator ────────────────────────────────────────────────── */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: #fff;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.typing-dots span {
  width: 7px;
  height: 7px;
  background: #aaa;
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Attach button ───────────────────────────────────────────────────── */
.attach-btn {
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
}

.attach-btn:hover { background: #f0f0f0; color: #2d6ef7; }

/* ── Mic button & recording state ────────────────────────────────────── */
.mic-btn {
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
}

.mic-btn:hover { background: #f0f0f0; color: #2d6ef7; }

.mic-btn.recording {
  background: #fee2e2;
  color: #e74c3c;
  animation: mic-pulse 1.2s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(231,76,60,0); }
}

/* ── Voice message bubble ─────────────────────────────────────────────── */
.msg-voice {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
  max-width: 280px;
}

.msg-voice audio {
  width: 100%;
  height: 36px;
  border-radius: 20px;
  outline: none;
}

.msg-voice-transcript {
  font-size: 13px;
  opacity: 0.85;
  font-style: italic;
  line-height: 1.4;
}

/* ── Media in messages ───────────────────────────────────────────────── */
.msg-image {
  max-width: 260px;
  max-height: 300px;
  border-radius: 10px;
  display: block;
  cursor: pointer;
  object-fit: cover;
}

.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
}

.msg-file-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.msg-file-info { min-width: 0; }
.msg-file-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.msg-file-link {
  font-size: 12px;
  opacity: 0.7;
  text-decoration: none;
  display: block;
  margin-top: 2px;
}

.msg-file-link:hover { text-decoration: underline; }

/* ── Back button (mobile only) ───────────────────────────────────────── */
.btn-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  color: #444;
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
  margin-right: -4px;
}

.btn-back:hover { background: #f0f0f0; }

/* ── Mobile responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app {
    position: relative;
    overflow: hidden;
  }

  /* Sidebar: full screen, slides left when chat opens */
  .sidebar {
    position: absolute;
    inset: 0;
    width: 100%;
    z-index: 10;
    transition: transform 0.3s ease;
  }

  /* Chat area: slides in from right */
  .chat-area {
    position: absolute;
    inset: 0;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 20;
    background: #f0f2f5;
  }

  /* When a chat is open */
  .app.chat-open .sidebar {
    transform: translateX(-100%);
  }

  .app.chat-open .chat-area {
    transform: translateX(0);
  }

  /* Show back button on mobile */
  .btn-back { display: flex; }

  /* Login card full width */
  .login-card {
    width: calc(100% - 32px);
    padding: 32px 20px;
    margin: 0 16px;
  }

  /* Chat header compact */
  .chat-header { padding: 10px 12px; gap: 8px; }
  .chat-header-avatar { width: 34px; height: 34px; font-size: 13px; }
  .chat-header-name { font-size: 14px; }
  .chat-header-sub { font-size: 11px; }

  /* Hide mode text label, show only toggle */
  .mode-label { display: none; }
  .mode-toggle { padding: 5px 8px; }
  .toggle-switch { width: 30px; height: 17px; }
  .toggle-switch::after { width: 11px; height: 11px; top: 3px; left: 3px; }
  .toggle-switch.on::after { transform: translateX(13px); }

  /* Clear highlight button smaller */
  .btn-clear-highlight { padding: 5px 10px; font-size: 12px; }

  /* Messages wider bubbles */
  .msg-bubble { max-width: 85%; font-size: 14px; }
  .messages-area { padding: 12px 10px; }

  /* Suggestion panel compact */
  .suggestion-panel { padding: 10px 12px; }
  .suggestion-actions { flex-wrap: wrap; }
  .btn-send-sug, .btn-edit-sug, .btn-reject-sug, .btn-regen-sug {
    flex: 1;
    min-width: 70px;
    padding: 7px 8px;
    font-size: 12px;
  }

  /* Input area compact */
  .input-area { padding: 10px 12px; gap: 8px; }
  .message-input { font-size: 15px; padding: 10px 12px; }
  .send-btn { width: 40px; height: 40px; }

  /* Modal full width */
  .modal { width: calc(100% - 32px); margin: 0 16px; padding: 24px 20px; }

  /* Sidebar header */
  .sidebar-header { padding: 16px 12px 10px; }
  .sidebar-title { font-size: 16px; margin-bottom: 10px; }

  /* Conv items bigger tap area */
  .conv-item { padding: 14px 12px; }
}
