:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel2: #243044;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent2: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --fb: #1877f2;
  --border: #2d3a4f;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); font-size: 0.85rem; display: block; }
code { font-size: 0.8rem; color: var(--muted); }

/* Login */
.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 20% 20%, #1e3a5f 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, #1a2744 0%, transparent 45%),
    var(--bg);
}
.login-wrap { width: min(420px, 92vw); }
.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 20px;
}
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: 0.02em; }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }
.logo {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #60a5fa);
  display: grid; place-items: center;
  font-weight: 800; font-size: 1.4rem;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.35);
}
.logo.sm { width: 36px; height: 36px; font-size: 1rem; border-radius: 10px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 26px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.card h2 { margin: 0 0 18px; font-size: 1.25rem; }
label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 12px 0 6px;
}
input[type="email"],
input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.2); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn.primary {
  width: 100%;
  margin-top: 18px;
  padding: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: #7f1d1d; color: #fca5a5; }
.btn.danger:hover { background: #7f1d1d33; }
.hint { margin: 16px 0 0; font-size: 0.78rem; color: var(--muted); line-height: 1.4; }

.flash {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.flash.error { background: #7f1d1d55; border: 1px solid #ef444466; color: #fecaca; }
.flash.message { background: #14532d55; border: 1px solid #22c55e66; }

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.top-left, .top-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.badge {
  background: #1877f233;
  color: #93c5fd;
  border: 1px solid #1877f266;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Inbox */
.inbox { max-width: 1100px; margin: 0 auto; padding: 20px; }
.empty {
  text-align: center;
  padding: 60px 20px;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  color: var(--muted);
}
.mail-list {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.mail-head, .mail-row {
  display: grid;
  grid-template-columns: 200px 1fr 140px;
  gap: 12px;
  padding: 12px 16px;
  align-items: center;
}
.mail-head {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--panel2);
  border-bottom: 1px solid var(--border);
}
.mail-row {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.mail-row:hover { background: #243044aa; }
.mail-row:last-child { border-bottom: none; }
.from { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--fb); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}
.subj { overflow: hidden; }
.subj strong { display: block; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subj em {
  display: block;
  font-style: normal;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.date { color: var(--muted); font-size: 0.8rem; text-align: right; }

/* Mail view */
.mail-view { max-width: 900px; margin: 0 auto; padding: 20px; }
.mail-meta {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  line-height: 1.6;
}
.tabs details {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  padding: 10px 14px;
}
.tabs summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.body-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
  max-height: 70vh;
  overflow: auto;
  margin: 0;
}
.body-html {
  width: 100%;
  min-height: 60vh;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

@media (max-width: 720px) {
  .mail-head { display: none; }
  .mail-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .date { text-align: left; }
}

/* Loading overlay */
.hidden { display: none !important; }
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(8, 12, 18, 0.82);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
}
.loading-box {
  text-align: center;
  padding: 32px 40px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.45);
  min-width: 280px;
}
.loading-box h3 {
  margin: 18px 0 6px;
  font-size: 1.15rem;
}
.spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--fb);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.body-html.full {
  width: 100%;
  min-height: 72vh;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  display: block;
}
