:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --sidebar-bg: #1e2a3a;
  --sidebar-text: #c8d6e5;
  --sidebar-active: #2e86de;
  --topbar-bg: #2c3e50;
  --text: #2c3e50;
  --text-secondary: #7f8c8d;
  --accent: #2e86de;
  --accent-hover: #1a6fbd;
  --border: #e1e4e8;
  --unread: #eaf2fd;
  --badge-bg: #e74c3c;
  --badge-text: #fff;
  --reply-bg: #f8f9fa;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--topbar-bg);
  color: #fff;
  padding: 0 16px;
  height: 48px;
  flex-shrink: 0;
}

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

.hamburger {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.logo { font-size: 18px; font-weight: 700; letter-spacing: -0.5px; }
.user-name { font-size: 13px; opacity: 0.85; }

.layout { display: flex; flex: 1; overflow: hidden; }

.sidebar {
  width: 200px;
  background: var(--sidebar-bg);
  flex-shrink: 0;
  overflow-y: auto;
}

.folder-list { list-style: none; padding: 8px 0; }

.folder {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}

.folder:hover { background: rgba(255,255,255,0.06); }
.folder.active { background: var(--sidebar-active); color: #fff; }
.folder-icon { font-size: 16px; }

.badge {
  margin-left: auto;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.badge:empty { display: none; }

.content { flex: 1; overflow-y: auto; position: relative; }

.mail-list { max-width: 800px; }

.mail-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.mail-item:hover { background: rgba(0,0,0,0.02); }
.mail-item.unread { background: var(--unread); font-weight: 600; }
.mail-item.unread:hover { background: #dce9f8; }

.mail-item .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
}

.mail-item .mail-preview { flex: 1; min-width: 0; }

.mail-item .mail-preview-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.mail-item .sender {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-item .date {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  font-weight: 400;
}

.mail-item .subject {
  font-size: 13px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-item .snippet {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 400;
}

.mail-reader { padding: 16px; max-width: 800px; }
.mail-reader.hidden { display: none; }

.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 12px;
}

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

.mail-header {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.mail-subject { font-size: 20px; font-weight: 700; margin-bottom: 8px; }

.mail-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.mail-from { color: var(--text); font-weight: 600; }
.mail-date { color: var(--text-secondary); }

.mail-body {
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  margin-bottom: 24px;
}

.mail-thread {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.thread-message {
  background: var(--reply-bg);
  border-radius: 8px;
  padding: 12px 16px;
  border-left: 3px solid var(--border);
}

.thread-message.from-user {
  border-left-color: var(--accent);
  background: #eef4fc;
}

.thread-message .thread-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}

.thread-message .thread-meta .thread-sender { font-weight: 600; color: var(--text); }
.thread-message .thread-body { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }

.reply-box { display: flex; gap: 8px; align-items: flex-end; }

#reply-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 44px;
}

#reply-input:focus { outline: none; border-color: var(--accent); }

.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.send-btn:hover { background: var(--accent-hover); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 15px;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-style: italic;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 0;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: blink 1.4s infinite both;
}

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

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

@media (max-width: 640px) {
  .hamburger { display: block; }

  .sidebar {
    position: fixed;
    top: 48px;
    left: -200px;
    bottom: 0;
    z-index: 100;
    transition: left 0.2s;
  }

  .sidebar.open { left: 0; }
  .mail-item .avatar { width: 32px; height: 32px; font-size: 12px; }
  .mail-reader { padding: 12px; }
  .mail-subject { font-size: 17px; }
  .reply-box { flex-direction: column; }
  .send-btn { width: 100%; }
}
