:root {
  --bg0: #070b14;
  --bg1: #0c1222;
  --bg2: #111827;
  --bg3: #1a2236;
  --card: rgba(255,255,255,.04);
  --border: rgba(255,255,255,.08);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --dim: #64748b;
  --accent: #6366f1;
  --accent2: #22d3ee;
  --danger: #f87171;
  --radius: 14px;
  --sidebar-w: 240px;
  --list-w: 380px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg0);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Login ── */
.login-page { display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(900px 500px at 0% -10%, rgba(99,102,241,.25), transparent),
              radial-gradient(700px 400px at 100% 0%, rgba(34,211,238,.12), transparent),
              var(--bg0);
}
.login-wrap { width: min(420px, 92vw); padding: 24px; }
.login-card {
  background: rgba(255,255,255,.05);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 32px;
  box-shadow: 0 24px 80px rgba(0,0,0,.45);
}
.brand { display: flex; gap: 16px; align-items: center; margin-bottom: 28px; }
.logo-mark {
  width: 52px; height: 52px; border-radius: 16px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: grid; place-items: center;
  box-shadow: 0 10px 28px rgba(99,102,241,.4);
}
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand-name {
  font-size: 1.65rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1;
  color: #fff;
}
.brand-name .accent {
  background: linear-gradient(90deg, #a5b4fc, #22d3ee);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-tag {
  font-size: .72rem; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted);
}
.login-card .brand-tag { letter-spacing: .06em; text-transform: none; font-size: .88rem; font-weight: 400; }
.login-card label { display: block; font-size: .78rem; color: var(--muted); margin: 14px 0 6px; }
.login-card input, .modal-card input, .modal-card textarea, .list-head input {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: rgba(0,0,0,.35);
  color: var(--text); font: inherit; outline: none;
  transition: border .2s, box-shadow .2s;
}
.login-card input:focus, .modal-card input:focus, .modal-card textarea:focus, .list-head input:focus {
  border-color: rgba(99,102,241,.6);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.btn-primary, .login-card button[type=submit], .btn-compose {
  border: none; cursor: pointer; font: inherit; font-weight: 600;
  color: #fff; background: linear-gradient(135deg, var(--accent), #4f46e5);
  border-radius: 12px; transition: transform .15s, box-shadow .15s;
}
.login-card button[type=submit] { width: 100%; padding: 13px; margin-top: 20px; }
.btn-primary:hover, .login-card button[type=submit]:hover, .btn-compose:hover { transform: translateY(-1px); }
.err { color: #fecaca; background: rgba(248,113,113,.12); border: 1px solid rgba(248,113,113,.3);
  padding: 10px 12px; border-radius: 10px; font-size: .85rem; margin-top: 12px; }
.login-foot { text-align: center; margin-top: 20px; color: var(--muted); font-size: .88rem; }
.login-foot a { color: var(--accent2); text-decoration: none; }

/* ── App layout ── */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg1); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand-compact {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 8px 18px; margin-bottom: 4px;
}
.brand-compact .logo-mark {
  width: 44px; height: 44px; border-radius: 13px;
}
.brand-compact .brand-name { font-size: 1.35rem; }
.brand-compact .brand-tag { font-size: .65rem; }
.btn-compose {
  width: 100%; padding: 12px; margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(99,102,241,.25);
}
.folders { flex: 1; overflow-y: auto; }
.folder-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  color: var(--muted); font-size: .92rem; font-weight: 500;
  transition: background .15s, color .15s; border: none; background: none; width: 100%; text-align: left;
}
.folder-item:hover { background: rgba(255,255,255,.04); color: var(--text); }
.folder-item.active { background: rgba(99,102,241,.15); color: #fff; }
.folder-item .badge {
  background: var(--accent); color: #fff; font-size: .7rem; font-weight: 700;
  padding: 2px 7px; border-radius: 99px; min-width: 20px; text-align: center;
}
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; }
.user-email { display: block; font-size: .75rem; color: var(--dim); margin-bottom: 8px; word-break: break-all; padding: 0 8px; }
.btn-ghost { background: none; border: 1px solid var(--border); color: var(--muted); border-radius: 10px; padding: 8px 12px; cursor: pointer; font: inherit; font-size: .85rem; width: 100%; }
.btn-ghost:hover { color: var(--text); border-color: rgba(255,255,255,.2); }
.btn-ghost.sm { width: auto; padding: 6px 14px; }

.list-pane {
  width: var(--list-w); flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg2); display: flex; flex-direction: column;
}
.list-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--border); }
.list-head h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 12px; }
.list-actions { display: flex; gap: 8px; }
.list-head input { flex: 1; font-size: .88rem; padding: 9px 12px; }
.icon-btn { background: rgba(255,255,255,.05); border: 1px solid var(--border); color: var(--muted); border-radius: 10px; width: 38px; cursor: pointer; font-size: 1.1rem; }
.icon-btn:hover { color: var(--text); }

.msg-list { flex: 1; overflow-y: auto; padding: 8px; }
.msg-card {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: transparent; border: 1px solid transparent;
  border-radius: 12px; padding: 12px 14px; margin-bottom: 4px;
  transition: background .15s, border-color .15s;
  color: var(--text);
}
.msg-card:hover { background: rgba(255,255,255,.04); }
.msg-card.active { background: rgba(99,102,241,.12); border-color: rgba(99,102,241,.3); }
.msg-card.unread .mc-subject { font-weight: 700; color: #fff; }
.msg-card.unread .mc-dot { background: var(--accent2); box-shadow: 0 0 8px var(--accent2); }
.mc-row1 { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.mc-dot { width: 8px; height: 8px; border-radius: 50%; background: transparent; flex-shrink: 0; }
.mc-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: .75rem; font-weight: 700; color: #fff;
}
.mc-from { flex: 1; font-size: .85rem; font-weight: 600; color: #cbd5e1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mc-date { font-size: .72rem; color: var(--dim); flex-shrink: 0; }
.mc-subject { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 50px; }
.msg-card.unread .mc-from { color: #fff; }

.read-pane {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  background:
    radial-gradient(ellipse 90% 70% at 80% 10%, rgba(99,102,241,.12), transparent 55%),
    radial-gradient(ellipse 70% 60% at 10% 90%, rgba(34,211,238,.07), transparent 50%),
    linear-gradient(165deg, #151d32 0%, #1a2440 45%, #172038 100%);
  border-left: 1px solid rgba(255,255,255,.04);
}
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 40px;
}
.empty-art {
  position: relative; width: 96px; height: 96px;
  display: grid; place-items: center; margin-bottom: 20px;
  color: rgba(129,140,248,.7);
}
.empty-ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, rgba(99,102,241,.15) 0%, transparent 70%);
  border: 1px solid rgba(99,102,241,.2);
}
.empty-title { font-size: 1.05rem; font-weight: 600; color: #cbd5e1; margin-bottom: 6px; }
.empty-sub { font-size: .88rem; color: var(--dim); max-width: 240px; line-height: 1.5; }

.mail-view {
  flex: 1; display: flex; flex-direction: column;
  max-width: 820px; margin: 0 auto; width: 100%;
  padding: 28px 32px 40px;
}
.mail-head {
  margin-bottom: 20px;
  padding: 20px 22px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
}
.mail-head h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.35; margin-bottom: 14px; color: #f8fafc; }
.mail-meta { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 16px; }
.mail-meta .avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: .9rem;
}
.mv-from { font-weight: 600; font-size: .95rem; color: var(--text); }
.mv-to { font-size: .82rem; color: var(--dim); margin-top: 2px; }
.mail-meta time { margin-left: auto; font-size: .78rem; color: var(--dim); white-space: nowrap; }
.mail-toolbar { display: flex; gap: 8px; }
.mail-body {
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px; padding: 28px 32px;
  font-size: .96rem; line-height: 1.8; color: #e2e8f0;
  min-height: 180px; word-break: break-word;
  box-shadow: 0 12px 40px rgba(0,0,0,.15), inset 0 1px 0 rgba(255,255,255,.06);
}
.mail-body .plain-body {
  font-family: inherit; white-space: pre-wrap; margin: 0;
  background: transparent; border: none; color: inherit;
}
.mail-body a { color: var(--accent2); }
.mail-body img { max-width: 100%; border-radius: 8px; }

/* ── Compose modal ── */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }
.modal-card {
  position: relative; width: min(560px, 94vw);
  background: var(--bg2); border: 1px solid var(--border); border-radius: 18px;
  padding: 24px; box-shadow: 0 32px 80px rgba(0,0,0,.5);
}
.modal-card header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-card label { display: block; font-size: .78rem; color: var(--muted); margin: 12px 0 6px; }
.modal-card textarea { resize: vertical; min-height: 140px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-actions .btn-primary { padding: 10px 22px; }

.loading { text-align: center; padding: 40px; color: var(--dim); font-size: .88rem; }

@media (max-width: 900px) {
  .read-pane { display: none; }
  .app.reading .list-pane { display: none; }
  .app.reading .read-pane { display: flex; width: 100%; }
}
