:root {
  --bg: #14171c;
  --surface-1: #1d2127;
  --surface-2: #262b33;
  --text-primary: #e7e9ec;
  --text-muted: #8a8f98;
  --accent: #e8a33d;
  --accent-ink: #1a1206;
  --bubble-out: #2b3a55;
  --border: rgba(231, 233, 236, 0.08);
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
}

button, input {
  font-family: inherit;
  color: inherit;
}

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- chat list panel ---------- */

.chat-list-panel {
  width: 340px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.chat-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}

.focus-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s ease;
}

.focus-dot.live {
  background: var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232, 163, 61, 0.35); }
  50% { box-shadow: 0 0 0 5px rgba(232, 163, 61, 0); }
}

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

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 17px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); }

.icon-btn.notify-on { color: var(--accent); }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.chat-item:hover, .chat-item.active { background: var(--surface-2); }

.chat-item-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-item-main { flex: 1; min-width: 0; }

.chat-item-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.chat-item-title {
  font-weight: 500;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-item-preview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.chat-item-preview {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

/* ---------- conversation panel ---------- */

.conversation-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.conversation-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  flex-shrink: 0;
}

.back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 19px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.back-btn:hover { background: var(--surface-2); }

.conversation-title { font-weight: 600; font-size: 15px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}

.message-bubble {
  max-width: 70%;
  padding: 9px 13px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
}

.message-bubble.in { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.message-bubble.out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 4px; }

.message-sender {
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 2px;
  font-weight: 600;
}

.message-time {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

.composer {
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-1);
  flex-shrink: 0;
}

.composer input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  outline: none;
}

.composer input:focus { border-color: var(--accent); }

.composer button {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 0 18px;
  border-radius: var(--radius-lg);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.composer button:disabled, .composer input:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- modal (work chats picker) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header { padding: 18px 20px 4px; }
.modal-header h2 { margin: 0; font-size: 16px; font-weight: 600; }

.hint { font-size: 12px; color: var(--text-muted); margin: 4px 0 0; }

.modal-search {
  margin: 12px 20px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13.5px;
  outline: none;
}

.modal-search:focus { border-color: var(--accent); }

.folder-chips {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
  padding: 10px 18px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-2) transparent;
}

.chat-list-panel .folder-chips { border-bottom: 1px solid var(--border); }

.folder-chips:empty { display: none; }

.folder-chips::-webkit-scrollbar { height: 6px; }
.folder-chips::-webkit-scrollbar-track { background: transparent; }
.folder-chips::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 999px; }
.folder-chips::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.folder-chip {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

.folder-chip:hover { color: var(--text-primary); }

.folder-chip.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

.modal-bulk-actions {
  display: flex;
  gap: 14px;
  padding: 0 20px 8px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover { text-decoration: underline; }

.modal-list {
  flex: 1;
  overflow-y: auto;
  padding: 2px 12px;
  min-height: 120px;
}

.modal-chat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.modal-chat-row:hover { background: var(--surface-2); }

.modal-chat-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.modal-chat-title {
  font-size: 13.5px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-chat-type {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-transform: uppercase;
  flex-shrink: 0;
}

.modal-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 12px;
}

.modal-manual-add {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  border-top: 1px solid var(--border);
}

.modal-manual-add input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}

.modal-manual-add input:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  cursor: pointer;
}

.btn-secondary:hover { color: var(--text-primary); border-color: var(--text-muted); }

/* ---------- mobile: single panel, slide navigation ---------- */

@media (max-width: 680px) {
  .app { position: relative; overflow: hidden; }

  .chat-list-panel, .conversation-panel {
    position: absolute;
    inset: 0;
    width: 100%;
    transition: transform 0.28s ease;
  }

  .chat-list-panel { transform: translateX(0); z-index: 1; }
  .conversation-panel { transform: translateX(100%); z-index: 2; }

  .app.show-conversation .chat-list-panel { transform: translateX(-100%); }
  .app.show-conversation .conversation-panel { transform: translateX(0); }

  .back-btn { display: flex; }
}
