/* ─── Chorus Design Tokens ─────────────────────────────────── */
:root {
  --bg: #0a0a0c;
  --surface: #111114;
  --surface-2: #1a1a1f;
  --surface-3: #222228;
  --border: #222228;
  --border-subtle: #1a1a1f;
  --text: #ededf0;
  --text-secondary: #b4b4be;
  --text-muted: #8b8b96;
  --text-dim: #5a5a66;
  --accent: #c8a2ff;
  --accent-dim: #9d6ee6;
  --accent-bg: rgba(200, 162, 255, 0.08);
  --accent-bg-hover: rgba(200, 162, 255, 0.12);
  --warm: #ffcba4;
  --green: #82dcc8;
  --red: #ff6b6b;
  --yellow: #ffd43b;
  --blue: #74b9ff;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --transition: 0.15s ease;
  --font-body: 'DM Sans', -apple-system, sans-serif;
  --font-display: 'Space Grotesk', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── App Layout ───────────────────────────────────────────── */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ─── Top Bar ──────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--text);
  text-decoration: none;
}
.logo span { color: var(--accent); }

.view-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 8px;
  padding: 2px;
}

.view-tab {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
}
.view-tab:hover { color: var(--text-secondary); }
.view-tab.active {
  color: var(--text);
  background: var(--surface-2);
}

/* Search */
.topbar-center { flex: 1; max-width: 480px; margin: 0 24px; }

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
  height: 36px;
  transition: border-color var(--transition);
}
.search-bar:focus-within {
  border-color: var(--accent-dim);
}
.search-bar svg { color: var(--text-dim); flex-shrink: 0; }
.search-bar input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
}
.search-bar input::placeholder { color: var(--text-dim); }
.search-bar kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  line-height: 1.4;
}

/* Top right */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-compose {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--bg);
  background: var(--accent);
  border: none;
  padding: 7px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-compose:hover {
  background: var(--accent-dim);
  transform: translateY(-1px);
}
.btn-compose svg { stroke: var(--bg); }

.sync-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
}
.sync-indicator:hover {
  background: var(--surface-2);
  color: var(--text);
}
.sync-indicator.syncing svg {
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.user-menu { position: relative; }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.avatar:hover { background: var(--accent-bg-hover); }

/* ─── Main Area ────────────────────────────────────────────── */
.main-area {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Thread List Panel ────────────────────────────────────── */
.thread-list-panel {
  width: 400px;
  min-width: 320px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.thread-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.thread-count {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text);
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
.thread-list::-webkit-scrollbar { width: 6px; }
.thread-list::-webkit-scrollbar-track { background: transparent; }
.thread-list::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 3px;
}

/* Thread Item */
.thread-item {
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.thread-item:hover { background: var(--surface-2); }
.thread-item.selected {
  background: var(--accent-bg);
}
.thread-item.selected::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.thread-item.unread .thread-from { color: var(--text); font-weight: 600; }
.thread-item.unread .thread-subject { color: var(--text); font-weight: 500; }
.thread-item.unread::after {
  content: '';
  position: absolute;
  right: 16px;
  top: 18px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.thread-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.thread-from {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.thread-date {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  white-space: nowrap;
  flex-shrink: 0;
}

.thread-subject {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.thread-snippet {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.thread-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.thread-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text-muted);
}
.thread-badge.starred {
  background: rgba(255, 212, 59, 0.1);
  color: var(--yellow);
}

.thread-msg-count {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

/* ─── Thread Detail Panel ──────────────────────────────────── */
.thread-detail-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.empty-state .empty-icon { opacity: 0.6; }
.empty-state h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  color: var(--text-muted);
}
.empty-state p {
  font-size: 14px;
  color: var(--text-dim);
}
.empty-state kbd {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
}

/* Thread Detail */
.thread-detail {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.thread-detail-subject {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 16px;
}

.thread-detail-actions {
  display: flex;
  gap: 4px;
}

.btn-action {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-action:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--surface-3);
}
.btn-action.active {
  background: rgba(255, 212, 59, 0.1);
  border-color: rgba(255, 212, 59, 0.2);
  color: var(--yellow);
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
.messages-container::-webkit-scrollbar { width: 6px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 3px;
}

.message-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 12px;
  transition: border-color var(--transition);
  animation: fadeIn 0.2s ease;
}
.message-card:hover { border-color: var(--surface-3); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.message-sender-info { display: flex; flex-direction: column; }
.message-from {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.message-email {
  font-size: 12px;
  color: var(--text-dim);
}
.message-to {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.message-date {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.message-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-secondary);
  overflow-wrap: break-word;
  word-break: break-word;
}
.message-body p { margin-bottom: 12px; }
.message-body a {
  color: var(--accent);
  text-decoration: none;
}
.message-body a:hover { text-decoration: underline; }
.message-body blockquote {
  border-left: 3px solid var(--border);
  padding-left: 16px;
  color: var(--text-dim);
  margin: 12px 0;
}
.message-body img { max-width: 100%; border-radius: var(--radius); }

/* Reply Box */
.reply-box {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.reply-box textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  padding: 14px 16px;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
  min-height: 120px;
}
.reply-box textarea:focus { border-color: var(--accent-dim); }
.reply-box textarea::placeholder { color: var(--text-dim); }

.reply-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.btn-send {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--bg);
  background: var(--accent);
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-send:hover { background: var(--accent-dim); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-send svg { stroke: var(--bg); }

.btn-cancel {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-cancel:hover { background: var(--surface-2); color: var(--text); }

.reply-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: auto;
}
.reply-hint kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ─── Shortcuts Bar ────────────────────────────────────────── */
.shortcuts-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.shortcut {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.shortcut kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  min-width: 20px;
  text-align: center;
}

/* ─── Modals ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.15s ease;
}

.compose-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 600px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.compose-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.compose-header h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
}

.btn-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-close:hover { background: var(--surface-2); color: var(--text); }

.compose-body { padding: 16px 20px; flex: 1; display: flex; flex-direction: column; gap: 12px; }

.compose-field {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 10px;
}
.compose-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  width: 60px;
  flex-shrink: 0;
}
.compose-field input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
}
.compose-field input::placeholder { color: var(--text-dim); }

.compose-body textarea {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  padding: 14px 16px;
  resize: none;
  outline: none;
  transition: border-color var(--transition);
  min-height: 200px;
}
.compose-body textarea:focus { border-color: var(--accent-dim); }
.compose-body textarea::placeholder { color: var(--text-dim); }

.compose-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* Shortcuts Modal */
.shortcuts-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 560px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}
.shortcuts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.shortcuts-header h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
}
.shortcuts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 24px;
  padding: 20px;
}
.shortcut-group h4 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.shortcut-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
.shortcut-row kbd {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  min-width: 28px;
  text-align: center;
}
.shortcut-row span { color: var(--text-muted); }

/* ─── Connect Screen ───────────────────────────────────────── */
.connect-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.connect-card {
  text-align: center;
  max-width: 420px;
  padding: 48px 40px;
}

.connect-icon { margin-bottom: 28px; opacity: 0.9; }

.connect-card h2 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 12px;
}

.connect-subtitle {
  font-size: 16px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 32px;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 12px 28px;
  border-radius: var(--radius);
  text-decoration: none;
  transition: all var(--transition);
}
.btn-google:hover {
  background: var(--surface-2);
  border-color: var(--surface-3);
  transform: translateY(-1px);
}

.connect-note {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 20px;
}

/* ─── Toast ────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 60px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn 0.2s ease;
  max-width: 360px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── Loading States ───────────────────────────────────────── */
.thread-item.skeleton {
  pointer-events: none;
}
.skeleton-line {
  height: 14px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}
.skeleton-line.short { width: 60%; }
.skeleton-line.medium { width: 80%; }
.skeleton-line.full { width: 100%; }
.skeleton-line + .skeleton-line { margin-top: 8px; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Mobile Responsive ────────────────────────────────────── */
@media (max-width: 768px) {
  .thread-list-panel { width: 100%; }
  .thread-detail-panel { display: none; }
  .thread-detail-panel.active {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: var(--bg);
    padding-top: 56px;
  }
  .topbar-center { display: none; }
  .shortcuts-bar { display: none; }
  .btn-compose span { display: none; }
  .btn-action span { display: none; }
  .shortcuts-grid { grid-template-columns: 1fr; }
}
