:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
}

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

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

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 20px; font-weight: 700; }

.user-info { display: flex; align-items: center; gap: 14px; }

#user-email { color: var(--muted); font-size: 14px; }

#compose-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}
#compose-btn:hover { background: var(--accent-dark); }

.folder-nav {
  display: flex;
  gap: 8px;
  padding: 10px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.folder-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
}
.folder-btn.active {
  background: #eff6ff;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  overflow: hidden;
}

.email-list {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.list-header, .email-item {
  display: grid;
  grid-template-columns: 28px 1.2fr 1.6fr 90px;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
}

.list-header {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
}

.email-item {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
  transition: background .12s;
}
.email-item:hover { background: #f8fafc; }
.email-item.selected { background: #eff6ff; border-left: 3px solid var(--accent); }
.email-item.unread .from,
.email-item.unread .subject { font-weight: 700; }

.from, .subject {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.date { color: var(--muted); font-size: 12px; text-align: right; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 12px;
}
.empty-state svg { width: 56px; height: 56px; opacity: .4; }

.email-viewer { background: var(--panel); overflow-y: auto; }

.email-header {
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--border);
}
.email-header h2 { font-size: 19px; margin-bottom: 8px; }
.email-meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }

.email-content {
  padding: 20px 24px;
  line-height: 1.6;
  font-size: 14px;
  white-space: pre-wrap;
  flex: 1;
}

.email-actions {
  display: flex;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
}
.email-actions button {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
}
.email-actions button:hover { background: #e2e8f0; }
#delete-btn { color: #dc2626; }

.compose-modal {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.compose-content {
  background: var(--panel);
  width: min(560px, 92vw);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
}
.compose-content h3 { margin-bottom: 14px; font-size: 17px; }
#compose-form { display: flex; flex-direction: column; gap: 10px; }
#compose-form input, #compose-form textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}
#compose-form textarea { min-height: 140px; resize: vertical; }
.compose-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.compose-actions button {
  border-radius: 8px; padding: 9px 18px; font-size: 14px; cursor: pointer;
  border: 1px solid var(--border); background: #f1f5f9;
}
#send-btn { background: var(--accent); color: #fff; border-color: var(--accent); }

@media (max-width: 760px) {
  main { grid-template-columns: 1fr; }
  .email-viewer { display: none; }
}
