:root {
  --ink: #1B2430;
  --navy: #14213D;
  --navy-2: #1d2f52;
  --paper: #F1F4F8;
  --card: #FFFFFF;
  --slate: #5B6472;
  --slate-soft: #8b93a1;
  --postmark-red: #C0392B;
  --airmail-blue: #2F5D8A;
  --airmail-soft: #eaf1f8;
  --green: #2C8A5B;
  --green-soft: #e7f4ec;
  --amber-soft: #fdf3e6;
  --border: rgba(20, 33, 61, 0.10);
  --border-strong: rgba(20, 33, 61, 0.16);
  --shadow-sm: 0 1px 2px rgba(20, 33, 61, 0.06);
  --shadow-md: 0 8px 24px rgba(20, 33, 61, 0.10);
  --radius: 12px;
  --radius-sm: 9px;
  --font-display: 'Fraunces', serif;
  --font-body: 'IBM Plex Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 32px;
}
.brand { display: inline-flex; align-items: center; text-decoration: none; }
.brand-logo { height: 40px; width: auto; display: block; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-avatar {
  position: relative;
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  background: linear-gradient(135deg, #F2711C, #E8590C);
}
.user-avatar::after {
  content: "";
  position: absolute;
  right: -1px; bottom: -1px;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #fff;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--navy);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-email {
  font-size: 12px;
  color: var(--slate-soft);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logout-link {
  margin-left: 6px;
  padding: 7px 13px;
  color: var(--slate);
  text-decoration: none;
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: border-color 0.13s ease, color 0.13s ease, background 0.13s ease;
}
.logout-link:hover { color: var(--postmark-red); border-color: rgba(192,57,43,0.35); background: #fdeeec; }

.airmail-stripe {
  height: 5px;
  background: repeating-linear-gradient(
    -45deg,
    var(--postmark-red) 0 14px,
    var(--airmail-blue) 14px 28px,
    #ffffff 28px 31px
  );
}

/* ---------- flash ---------- */
.flash-stack { max-width: 760px; margin: 18px auto 0; padding: 0 24px; }
.flash {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.flash-hide { opacity: 0; transform: translateY(-6px); }
.flash-icon {
  flex-shrink: 0;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  color: #fff;
}
.flash-text { padding-top: 1px; }
.flash-success { background: var(--green-soft); border-color: rgba(44,138,91,0.28); color: #1d5c3c; }
.flash-success .flash-icon { background: var(--green); }
.flash-error { background: #fdeeec; border-color: rgba(192,57,43,0.28); color: #8f2b20; }
.flash-error .flash-icon { background: var(--postmark-red); }
.flash-info { background: var(--airmail-soft); border-color: rgba(47,93,138,0.25); color: #244b70; }
.flash-info .flash-icon { background: var(--airmail-blue); }

/* ---------- page ---------- */
.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 24px 90px;
}
.eyebrow {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  color: var(--airmail-blue);
  margin: 0 0 8px;
}

/* ---------- login ---------- */
.login-card { margin-top: 7vh; }
.login-card h1 {
  font-family: var(--font-display);
  font-size: 44px;
  font-weight: 600;
  margin: 0 0 18px;
  line-height: 1.1;
  letter-spacing: -0.015em;
}
.lede {
  color: var(--slate);
  font-size: 16px;
  line-height: 1.65;
  max-width: 52ch;
  margin: 0 0 30px;
}
.btn-primary {
  display: inline-block;
  background: var(--navy);
  color: #fff;
  text-decoration: none;
  padding: 15px 28px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 15px;
  transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--airmail-blue); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:focus-visible { outline: 3px solid var(--airmail-blue); outline-offset: 2px; }
/* connect panel + credentials form */
.connect-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  max-width: 460px;
}
.connect-ready {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  color: #1d5c3c;
  background: var(--green-soft);
  border: 1px solid rgba(44,138,91,0.25);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  margin-bottom: 16px;
}
.ready-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(44,138,91,0.2);
  flex-shrink: 0;
}
.connect-hint { margin: 0 0 18px; font-size: 14px; color: var(--slate); line-height: 1.6; }
.link-toggle {
  display: inline-block;
  margin-top: 14px;
  background: none;
  border: none;
  padding: 0;
  color: var(--airmail-blue);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}
.link-toggle:hover { color: var(--postmark-red); }

.cred-form { display: grid; gap: 14px; }
.cred-form.is-hidden { display: none; }
.cred-form label { display: grid; gap: 6px; }
.cred-form label span {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--slate);
}
.cred-form input, .cred-form select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  transition: border-color 0.13s ease, box-shadow 0.13s ease;
}
.cred-form input:focus, .cred-form select:focus {
  outline: none;
  border-color: var(--airmail-blue);
  box-shadow: 0 0 0 3px rgba(47,93,138,0.14);
}
.cred-form .btn-primary { border: none; cursor: pointer; width: 100%; text-align: center; }
.cred-error {
  margin: 0;
  font-size: 13px;
  color: var(--postmark-red);
  background: #fdeeec;
  border: 1px solid rgba(192,57,43,0.25);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}
.fine-print { margin: 4px 0 0; font-size: 12px; color: var(--slate-soft); line-height: 1.6; }
.mono { font-family: var(--font-mono); font-size: 0.92em; color: var(--slate); }

.login-features {
  list-style: none;
  margin: 34px 0 0;
  padding: 0;
  display: grid;
  gap: 12px;
}
.login-features li {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 14.5px;
  color: var(--ink);
}
.feat-mark {
  flex-shrink: 0;
  display: grid; place-items: center;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--airmail-soft);
  color: var(--airmail-blue);
  font-size: 11px;
}

/* ---------- dashboard header ---------- */
.inbox-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.inbox-head h1 {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.subhead {
  margin: 6px 0 0;
  color: var(--slate);
  font-size: 14.5px;
}
.refresh-link {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--airmail-blue);
  text-decoration: none;
  white-space: nowrap;
  padding-bottom: 4px;
}
.refresh-link:hover { color: var(--postmark-red); }

/* ---------- mail list ---------- */
.mail-list { list-style: none; margin: 0; padding: 0; }
.mail-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.13s ease, box-shadow 0.13s ease, border-color 0.13s ease;
}
.mail-row:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.mail-open {
  display: flex;
  gap: 14px;
  flex: 1;
  min-width: 0;
  align-items: center;
  text-decoration: none;
  color: inherit;
}
.avatar {
  flex-shrink: 0;
  width: 42px; height: 42px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  color: #fff;
}
.avatar-0 { background: #2F5D8A; }
.avatar-1 { background: #C0392B; }
.avatar-2 { background: #2C8A5B; }
.avatar-3 { background: #7d4a9e; }
.avatar-4 { background: #b8791f; }
.avatar-5 { background: #1d7a8c; }

.mail-main { flex: 1; min-width: 0; }
.mail-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.mail-sender {
  font-weight: 600;
  font-size: 14px;
  color: var(--navy);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mail-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--slate-soft);
  white-space: nowrap;
}
.mail-subject {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  margin-top: 3px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clip { margin-left: 6px; font-size: 13px; }
.mail-snippet {
  margin-top: 3px;
  font-size: 13px;
  color: var(--slate);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- draft button ---------- */
.draft-form { margin: 0; flex-shrink: 0; }
.draft-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--airmail-blue);
  background: var(--airmail-soft);
  border: 1px solid rgba(47, 93, 138, 0.22);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.13s ease, color 0.13s ease, transform 0.1s ease;
}
.draft-btn:hover { background: var(--airmail-blue); color: #fff; transform: translateY(-1px); }
.draft-btn:focus-visible { outline: 2px solid var(--airmail-blue); outline-offset: 2px; }
.draft-btn.is-loading, .draft-btn:disabled { opacity: 0.75; cursor: progress; }
.draft-btn-solid {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
  font-size: 12px;
  padding: 11px 18px;
}
.draft-btn-solid:hover { background: var(--airmail-blue); border-color: var(--airmail-blue); }
.spinner {
  width: 12px; height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- pager ---------- */
.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 26px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.pager a { color: var(--airmail-blue); text-decoration: none; }
.pager a:hover { color: var(--postmark-red); }
.pager-disabled { color: var(--border-strong); }
.pager-current { color: var(--slate); }

/* ---------- empty state ---------- */
.empty-state { text-align: center; padding: 80px 20px; color: var(--slate); }
.empty-icon {
  font-size: 34px;
  width: 74px; height: 74px;
  margin: 0 auto 20px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  color: var(--airmail-blue);
}
.empty-state p:first-of-type {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--ink);
  margin-bottom: 8px;
}
.empty-sub { color: var(--slate); font-size: 14px; }

/* ---------- detail ---------- */
.detail-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}
.back-link {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--airmail-blue);
  text-decoration: none;
}
.back-link:hover { color: var(--postmark-red); }
.detail-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 34px;
  box-shadow: var(--shadow-sm);
}
.detail-subject {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  margin: 0 0 22px;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.detail-meta {
  margin: 0 0 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 18px;
  font-size: 14px;
}
.detail-meta dt {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--slate-soft);
  padding-top: 2px;
}
.detail-meta dd { margin: 0; color: var(--ink); word-break: break-word; }
.detail-body {
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.detail-body img { max-width: 100%; height: auto; }
.detail-body a { color: var(--airmail-blue); }

/* ---------- motion / responsive ---------- */
@media (prefers-reduced-motion: reduce) {
  .mail-row, .btn-primary, .draft-btn { transition: none; }
  .spinner { animation: none; }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 16px; }
  .brand-logo { height: 32px; }
  .page { padding: 26px 16px 64px; }
  .login-card h1 { font-size: 32px; }
  .inbox-head h1 { font-size: 24px; }
  .user-meta { display: none; }
  .mail-row { flex-wrap: wrap; }
  .draft-form { width: 100%; }
  .draft-btn { width: 100%; justify-content: center; }
  .detail-card { padding: 24px 20px; }
  .detail-meta { grid-template-columns: 1fr; gap: 2px 0; }
  .detail-meta dt { margin-top: 8px; }
}
