:root {
  --bg: #090a0f;
  --sidebar-bg: #0e0f14;
  --pane-bg: #121318;
  --reader-bg: #16171d;
  --border: rgba(255, 255, 255, 0.07);
  --border-focus: rgba(255, 255, 255, 0.2);
  --text: #f0f1f5;
  --text-muted: #828795;
  --accent: #ffffff;
  --accent-text: #090a0f;
  --hover: rgba(255, 255, 255, 0.04);
  --unread-dot: #38bdf8;
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

.screen { width: 100vw; height: 100vh; display: flex; }
.hidden { display: none !important; }

/* Auth Screen */
#auth-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 20%, #171822 0%, var(--bg) 75%);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 36px;
  background: var(--pane-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.65);
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  color: #fff;
}

.auth-card h2 { font-size: 1.3rem; font-weight: 600; letter-spacing: -0.02em; }
.subtitle { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; margin-bottom: 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.75rem; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; }

input, textarea {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: #fff;
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  transition: all 0.2s ease;
}

input:focus, textarea:focus {
  border-color: var(--border-focus);
  background: rgba(255, 255, 255, 0.05);
}

button { cursor: pointer; border: none; font-family: inherit; transition: all 0.2s; }

#login-btn, .send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.875rem;
  margin-top: 10px;
}
#login-btn:hover, .send-btn:hover { opacity: 0.92; transform: translateY(-1px); }
#login-btn:active, .send-btn:active { transform: translateY(0); }

.error-msg {
  color: #f87171;
  font-size: 0.8rem;
  margin-top: 14px;
  text-align: center;
  animation: shake 0.25s ease-in-out;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  margin-bottom: 18px;
}

.avatar {
  width: 30px;
  height: 30px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

.email-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compose-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 20px;
}
.compose-btn:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.15); }

.nav-section { flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.15s ease;
}
.nav-item.active { background: var(--hover); color: #fff; }

.logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: 6px;
}
.logout-btn:hover { color: #f87171; background: var(--hover); }

/* Messages Pane */
.messages-pane {
  width: 340px;
  background: var(--pane-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.pane-header {
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.pane-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pane-title-group h3 { font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }

.sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  transition: background 0.3s ease;
}
.sync-dot.syncing {
  background: #f59e0b;
  animation: pulse 1s infinite alternate;
}

.icon-btn {
  background: none;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { color: #fff; background: var(--hover); }

.mail-list { flex: 1; overflow-y: auto; }

.mail-item {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease;
  animation: slideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.mail-item:hover { background: var(--hover); }
.mail-item.selected { background: rgba(255, 255, 255, 0.06); }

.mail-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.mail-sender {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  max-width: 190px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mail-time { font-size: 0.75rem; color: var(--text-muted); }
.mail-subject { font-size: 0.85rem; color: #a1a7b4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.unread .mail-sender { color: #fff; font-weight: 600; }
.unread .mail-subject { color: #d1d5db; }
.unread::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 22px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--unread-dot);
}

/* Reader Pane */
.reader-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--reader-bg);
}

.reader-empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
}
.empty-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}

.reader-view { display: flex; flex-direction: column; height: 100%; animation: fadeIn 0.2s ease; }

.reader-header {
  padding: 32px 40px 24px;
  border-bottom: 1px solid var(--border);
}
.reader-header h2 { font-size: 1.4rem; font-weight: 600; margin-bottom: 14px; letter-spacing: -0.02em; }

.meta-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.85rem; }
.author { font-weight: 600; color: #fff; }
.recipient { color: var(--text-muted); margin-left: 8px; font-size: 0.8rem; }
time { color: var(--text-muted); font-size: 0.8rem; }

.reader-frame-container {
  flex: 1;
  padding: 24px 40px;
  overflow: hidden;
  display: flex;
}
iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

/* Skeletons */
.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.03) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}
.skeleton-title { height: 28px; width: 60%; margin-bottom: 14px; }
.skeleton-subtitle { height: 16px; width: 30%; }
.skeleton-body { width: 100%; height: 100%; border-radius: 12px; }

/* Spinner */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
  z-index: 50;
}

.modal {
  width: 100%;
  max-width: 580px;
  background: var(--pane-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal form input, .modal form textarea { margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; }
.modal-actions .send-btn { width: auto; padding: 9px 24px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: #1e2029;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.85rem;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  animation: slideUp 0.2s ease;
  z-index: 99;
}

/* Keyframes */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { from { opacity: 0.5; } to { opacity: 1; } }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Attachments Bar */
.attachments-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.attachment-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #fff;
  text-decoration: none;
  font-size: 0.8rem;
  transition: all 0.15s ease;
  max-width: 280px;
}

.attachment-pill:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.attachment-pill svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

.attachment-pill:hover svg {
  color: #fff;
}

.att-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.att-size {
  color: var(--text-muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.att-dl {
  margin-left: 2px;
  opacity: 0.6;
}

.attachment-pill:hover .att-dl {
  opacity: 1;
}
