:root {
  --blue: #0078fd;
  --blue-deep: #0062d1;
  --ink: #10141c;
  --ink-soft: #4b5568;
  --line: #e6eaf1;
  --paper: #f4f6fb;
  --card: #ffffff;
  --danger: #c2413b;
  --radius: 18px;
  --shadow: 0 24px 60px rgba(16, 20, 28, 0.12);
  --sidebar: 248px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Outfit, "Segoe UI", sans-serif;
  letter-spacing: -0.01em;
}

.hidden { display: none !important; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }

.screen { min-height: 100%; }

.login-screen {
  display: grid;
  place-items: center;
  padding: 32px 16px;
  position: relative;
  overflow: hidden;
}
.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(900px 420px at 12% -10%, rgba(0, 120, 253, 0.18), transparent 60%),
    radial-gradient(700px 380px at 100% 0%, rgba(0, 120, 253, 0.08), transparent 55%),
    linear-gradient(#f7f9fd, #eef3fb);
}
.login-card {
  position: relative;
  width: min(520px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.brand-logo, .sidebar-brand img, .empty-read img { width: 52px; height: 52px; }
.brand h1 { margin: 0; font-size: 28px; letter-spacing: -0.04em; }
.brand p { margin: 4px 0 0; color: var(--ink-soft); font-size: 14px; }

.provider-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.provider {
  border: 1px solid var(--line);
  background: #fbfcfe;
  border-radius: 14px;
  padding: 10px 8px;
  font: inherit;
  cursor: pointer;
  color: var(--ink);
}
.provider.active {
  border-color: var(--blue);
  background: #eaf3ff;
  color: var(--blue-deep);
  font-weight: 650;
}

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-soft); }
input, select, textarea {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(0, 120, 253, 0.25);
  border-color: var(--blue);
}
form { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; }
.grow { flex: 1; }
.port { width: 88px; }
.hint, .fineprint { font-size: 12px; color: var(--ink-soft); margin: 0; }
.oauth-box { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.oauth-setup { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.oauth-setup summary { cursor: pointer; font-weight: 650; margin-bottom: 10px; }
.oauth-setup label { margin-bottom: 8px; }
.error { color: var(--danger); font-size: 13px; margin: 0; }

.btn {
  font: inherit;
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  background: #eef2f7;
  color: var(--ink);
}
.btn.primary { background: var(--blue); color: #fff; font-weight: 650; }
.btn.primary:hover { background: var(--blue-deep); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.icon-btn {
  width: 36px; height: 36px; border: 0; border-radius: 10px;
  background: #eef2f7; cursor: pointer; font: inherit;
}

.mail-screen {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(320px, 420px) 1fr;
  height: 100vh;
}
.sidebar {
  background: #0f1724;
  color: #dbe7f6;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sidebar-brand { display: flex; gap: 10px; align-items: center; }
.sidebar-brand img { width: 36px; height: 36px; filter: brightness(1.15); }
.sidebar-brand strong { display: block; font-size: 14px; }
.sidebar-brand span { display: block; font-size: 12px; color: #93a4bb; word-break: break-all; }
.folder-list { display: flex; flex-direction: column; gap: 4px; overflow: auto; flex: 1; }
.folder {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 10px; color: #c5d4e8; cursor: pointer; border: 0; background: transparent; font: inherit; text-align: left;
}
.folder:hover, .folder.active { background: rgba(0, 120, 253, 0.22); color: #fff; }
.badge {
  min-width: 20px; text-align: center; font-size: 11px; background: var(--blue);
  color: #fff; border-radius: 999px; padding: 1px 6px;
}
.logout { color: #93a4bb; margin-top: auto; }

.list-pane, .read-pane { background: #fff; border-left: 1px solid var(--line); min-height: 0; display: flex; flex-direction: column; }
.list-header, .reader-head { padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.list-header { display: flex; justify-content: space-between; gap: 12px; align-items: end; }
.list-header h2, .reader-head h2 { margin: 0; font-size: 22px; letter-spacing: -0.03em; }
.list-tools { display: flex; gap: 8px; align-items: center; }
.list-tools input { width: 190px; padding: 8px 10px; }
.message-list { flex: 1; overflow: auto; }
.msg {
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line);
  background: #fff; padding: 12px 16px; cursor: pointer; font: inherit; display: grid; gap: 3px;
}
.msg:hover { background: #f6f9ff; }
.msg.active { background: #eaf3ff; }
.msg.unseen .msub, .msg.unseen .mfrom { font-weight: 700; }
.mrow { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.msub { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 13px; }

.empty-read, .empty-list {
  flex: 1; display: grid; place-items: center; text-align: center; color: var(--ink-soft); padding: 32px;
}
.empty-read img { opacity: 0.8; margin: 0 auto 8px; }
.reader { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.reader-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; }
.reader-actions { display: flex; gap: 8px; margin-top: 12px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.attachments a {
  font-size: 12px; color: var(--blue-deep); background: #eaf3ff; padding: 6px 8px; border-radius: 8px; text-decoration: none;
}
#r-frame {
  flex: 1; width: 100%; border: 0; background: #fff;
}

.modal {
  position: fixed; inset: 0; background: rgba(16, 20, 28, 0.45);
  display: grid; place-items: center; padding: 16px; z-index: 20;
}
.modal-card {
  width: min(640px, 100%); background: #fff; border-radius: 20px; padding: 18px;
  box-shadow: var(--shadow);
}
.modal-card header { display: flex; justify-content: space-between; align-items: center; }
.modal-card h3 { margin: 0; }
.modal-card form { margin-top: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 999px; font-size: 13px; z-index: 30;
}

.mobile-bar { display: none; }

@media (max-width: 980px) {
  .mail-screen { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; height: 100vh; }
  .sidebar { display: none; }
  .mobile-bar {
    display: flex; gap: 8px; align-items: center; padding: 10px 12px;
    background: #0f1724; color: #fff;
  }
  .mobile-bar img { width: 28px; height: 28px; }
  .mobile-bar select { flex: 1; background: #1b2636; color: #fff; border-color: #2a3b52; }
  .read-pane { border-left: 0; border-top: 1px solid var(--line); max-height: 48vh; }
  .list-tools input { width: 140px; }
}
