:root {
  color-scheme: dark;
  --bg: #09090d;
  --panel: #0e0e14;
  --panel-2: #15151d;
  --line: rgba(255, 255, 255, .06);
  --line-2: rgba(255, 255, 255, .11);
  --text: #ececf2;
  --muted: #9a9aa8;
  --faint: #62626f;
  --accent: #8b5cf6;
  --accent-2: #b39dfc;
  --accent-soft: rgba(139, 92, 246, .13);
  --ok: #34d399;
  --danger: #f87171;
  --star: #fbbf24;
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
[data-icon] svg { display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  display: grid;
  grid-template-columns: 76px minmax(340px, 420px) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ---------- rail ---------- */
.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 22px 0 18px;
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
}
.logo {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(150deg, #9f7aea, #5b21b6);
  box-shadow: 0 8px 26px -8px rgba(139, 92, 246, .7);
  margin-bottom: 24px;
}
.rail-btn {
  position: relative;
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  color: var(--faint);
  transition: background .15s, color .15s;
}
.rail-btn:hover { color: var(--text); background: rgba(255, 255, 255, .04); }
.rail-btn.is-active { color: var(--text); background: var(--accent-soft); }
.rail-btn.is-active::before {
  content: "";
  position: absolute;
  inset-inline-start: -16px;
  top: 11px; bottom: 11px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}
.rail-spacer { flex: 1; }
.rail-btn.spin svg { animation: spin .7s linear; }
.badge {
  position: absolute;
  top: 4px; inset-inline-end: 3px;
  min-width: 17px; height: 17px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px; font-weight: 700;
  line-height: 17px;
  text-align: center;
}

/* ---------- emails (identities) column ---------- */
.ids-pane { display: none; }
@media (min-width: 1200px) {
  .app { grid-template-columns: 76px 280px minmax(340px, 400px) minmax(0, 1fr); }
  .ids-pane {
    display: flex;
    flex-direction: column;
    min-width: 0; min-height: 0;
    background: #0b0b11;
    border-inline-end: 1px solid var(--line);
  }
  .rail-btn[data-view="addresses"] { display: none; }
}
.ids-head { padding: 26px 14px 10px; }
.ids-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px;
  color: var(--faint);
  font-size: 12.5px; font-weight: 600;
}
.ids-count {
  min-width: 30px;
  padding: 1px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.search.search-sm { margin-top: 12px; height: 40px; padding: 0 12px; }
.ids-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 8px 20px;
  scrollbar-width: thin;
  scrollbar-color: #2a2a36 transparent;
}
.id-row {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .12s;
}
.id-row + .id-row { margin-top: 2px; }
.id-row:hover { background: rgba(255, 255, 255, .03); }
.id-row.is-active { background: rgba(255, 255, 255, .065); }
.id-row.is-active::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 11px; bottom: 11px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}
.id-row:focus-visible { outline: none; box-shadow: inset 0 0 0 1px var(--accent); }
.id-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; }
.id-row.has-unread .id-dot { background: var(--accent); }
.id-main { flex: 1; min-width: 0; }
.id-addr {
  display: block;
  direction: ltr; text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13.5px;
}
.id-addr b { font-weight: 600; }
.id-addr i { font-style: normal; color: var(--faint); font-size: 12px; }
.id-all-name { display: block; font-weight: 600; font-size: 13.5px; }
.id-sub {
  display: block;
  margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--faint);
  font-size: 11.5px;
  text-align: right;
}
.id-count { flex: none; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.id-row.has-unread .id-count { color: var(--accent-2); font-weight: 600; }
.ids-hint { padding: 16px 12px; color: var(--faint); font-size: 12.5px; line-height: 1.8; }
.ids-hint bdi { direction: ltr; color: var(--text); }
kbd {
  padding: 0 6px;
  border-radius: 5px;
  border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, .04);
  font: 600 11px/1.7 var(--mono);
  color: var(--muted);
}

/* ---------- list ---------- */
.list-pane {
  display: flex;
  flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
}
.list-head { padding: 24px 20px 10px; }
.title-row { display: flex; align-items: center; gap: 10px; }
h1 { margin: 0; font-size: 23px; font-weight: 700; letter-spacing: -.01em; }
.live {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 2.6s ease-out infinite;
}
.btn-new {
  margin-inline-start: auto;
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px 0 14px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 13px; font-weight: 600;
  transition: background .15s;
}
.btn-new:hover { background: rgba(139, 92, 246, .22); }
.sub-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; min-height: 20px; }
.domain { color: var(--faint); font-size: 12.5px; direction: ltr; }
.demo-pill {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 6px;
  color: #fcd34d;
  background: rgba(251, 191, 36, .1);
}
.search {
  margin-top: 16px;
  display: flex; align-items: center; gap: 10px;
  height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--faint);
  transition: border-color .15s;
}
.search:focus-within { border-color: rgba(139, 92, 246, .5); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; font-size: 13.5px; }
.search input::placeholder { color: var(--faint); }
.search input::-webkit-search-cancel-button { filter: invert(.6); }

.filter-chip {
  margin-top: 10px;
  display: inline-flex; align-items: center; gap: 8px;
  max-width: 100%;
  padding: 4px 6px 4px 10px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 12.5px;
}
.chip-addr { direction: ltr; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-chip button {
  width: 20px; height: 20px;
  border-radius: 6px;
  font-size: 15px; line-height: 1;
  color: var(--accent-2);
}
.filter-chip button:hover { background: rgba(255, 255, 255, .08); }

.list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 10px 24px;
  scrollbar-width: thin;
  scrollbar-color: #2a2a36 transparent;
}
.item {
  position: relative;
  display: flex; gap: 12px;
  padding: 14px 14px 14px 12px;
  border-radius: 13px;
  cursor: pointer;
  transition: background .12s;
}
.item + .item { margin-top: 2px; }
.item:hover { background: rgba(255, 255, 255, .028); }
.item.is-selected { background: var(--accent-soft); }
.item:focus-visible { outline: none; box-shadow: inset 0 0 0 1px var(--accent); }
.item.unread::before {
  content: "";
  position: absolute;
  inset-inline-start: 3px; top: 30px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.item.is-new { animation: arrive 1.6s ease-out; }
.avatar {
  flex: none;
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  background: hsl(var(--h) 32% 17%);
  color: hsl(var(--h) 85% 80%);
}
.item-main { flex: 1; min-width: 0; }
.item-main .from, .item-main .subject, .item-main .snippet { text-align: right; }
.item-top { display: flex; align-items: center; gap: 6px; }
.from {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-weight: 500;
}
.item.unread .from { color: var(--text); font-weight: 600; }
.star-mini { color: var(--star); }
time { color: var(--faint); font-size: 12px; white-space: nowrap; }
.subject {
  margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted);
}
.item.unread .subject { color: var(--text); font-weight: 600; }
.snippet {
  margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--faint); font-size: 13px;
}
.item-meta { display: flex; align-items: center; gap: 6px; margin-top: 9px; min-width: 0; }
.to-chip {
  direction: ltr;
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 2px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, .045);
  color: var(--muted);
  font-size: 12px;
}
.to-chip b { color: var(--text); font-weight: 600; }
.to-chip i { font-style: normal; color: var(--faint); }
.code-chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px;
  border-radius: 7px;
  background: rgba(139, 92, 246, .17);
  color: #d4c8ff;
  font: 700 12px/1.6 var(--mono);
  letter-spacing: .08em;
  direction: ltr;
  transition: background .15s;
}
.code-chip:hover { background: rgba(139, 92, 246, .3); }
.code-chip.copied { background: rgba(52, 211, 153, .18); color: #a7f3d0; }

.list-empty { padding: 60px 24px; text-align: center; color: var(--faint); }
.list-empty strong { display: block; color: var(--muted); font-size: 15px; margin-bottom: 6px; }
.list-empty bdi { direction: ltr; color: var(--muted); }

/* addresses view */
.addr-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 12px;
  border-radius: 13px;
  cursor: pointer;
  transition: background .12s;
}
.addr-row:hover { background: rgba(255, 255, 255, .028); }
.addr-icon {
  flex: none;
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: var(--panel-2);
  color: var(--accent-2);
}
.addr-main { flex: 1; min-width: 0; }
.addr {
  display: block;
  direction: ltr; text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13.5px;
}
.addr b { font-weight: 600; }
.addr i { font-style: normal; color: var(--faint); }
.addr-label { display: block; margin-top: 1px; color: var(--faint); font-size: 12.5px; }
.addr-side { text-align: left; flex: none; }
.addr-count { display: block; color: var(--muted); font-size: 12.5px; }
.addr-count.has-unread { color: var(--accent-2); font-weight: 600; }

.icon-btn {
  flex: none;
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  color: var(--muted);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .02);
  transition: color .15s, border-color .15s, background .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--line-2); background: rgba(255, 255, 255, .04); }
.icon-btn.on { color: var(--star); }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn.copied { color: var(--ok); }

/* ---------- reader ---------- */
.reader {
  position: relative;
  min-width: 0;
  overflow-y: auto;
  background:
    radial-gradient(900px 520px at 40% -8%, rgba(124, 58, 237, .13), transparent 65%),
    var(--bg);
  scrollbar-width: thin;
  scrollbar-color: #2a2a36 transparent;
}
.reader-empty {
  height: 100%;
  display: grid; place-content: center; justify-items: center; gap: 10px;
  color: var(--faint);
}
.reader-empty p { margin: 0; }
.empty-mark {
  width: 64px; height: 64px;
  border-radius: 20px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .03);
  border: 1px solid var(--line);
  color: #3f3f4c;
}
.reader-content { max-width: 880px; margin: 0 auto; padding: 26px 40px 70px; }
.reader-bar { display: flex; align-items: center; gap: 6px; margin-bottom: 24px; }
.reader-bar .grow { flex: 1; }
.back { display: none; }
.r-subject { margin: 0 0 18px; font-size: 24px; line-height: 1.45; font-weight: 700; letter-spacing: -.01em; }
.r-meta {
  display: flex; align-items: center; gap: 14px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.r-meta .avatar { width: 44px; height: 44px; border-radius: 13px; font-size: 16px; }
.r-who { flex: 1; min-width: 0; }
.r-from { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.r-from-name { font-weight: 600; }
.r-from-addr { color: var(--faint); font-size: 13px; direction: ltr; }
.r-to { margin-top: 3px; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.to-copy {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%;
  padding: 2px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, .045);
  direction: ltr;
  transition: background .15s;
}
.to-copy:hover { background: rgba(255, 255, 255, .08); }
.to-copy b { font-weight: 600; color: var(--text); }
.to-copy i { font-style: normal; color: var(--faint); }
.r-time { align-self: flex-start; padding-top: 4px; }

.code-card {
  margin-top: 22px;
  display: flex; align-items: center; gap: 22px;
  padding: 18px 22px;
  border-radius: 18px;
  background: linear-gradient(120deg, rgba(139, 92, 246, .18), rgba(139, 92, 246, .04));
  border: 1px solid rgba(139, 92, 246, .32);
}
.code-label { color: var(--accent-2); font-size: 12.5px; font-weight: 600; }
.code-value {
  margin-top: 2px;
  font: 700 34px/1.2 var(--mono);
  letter-spacing: .24em;
  direction: ltr;
  text-align: right;
}
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: #7c4def; }
.btn-primary:active { transform: scale(.98); }
.btn-primary.copied { background: #10b981; }
.code-card .btn-primary { margin-inline-start: auto; }

.r-body { margin-top: 22px; }
.r-body iframe {
  display: block;
  width: 100%;
  min-height: 140px;
  border: 0;
  border-radius: 14px;
  background: transparent;
}
.r-body.is-html iframe { background: #fff; }

/* ---------- dialog ---------- */
.dlg {
  width: min(460px, calc(100vw - 32px));
  padding: 26px;
  border: 1px solid var(--line-2);
  border-radius: 20px;
  background: #121219;
  color: var(--text);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .8);
}
.dlg::backdrop { background: rgba(4, 4, 8, .65); backdrop-filter: blur(3px); }
.dlg h3 { margin: 0; font-size: 18px; }
.dlg-hint { margin: 6px 0 18px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.new-addr {
  display: flex; align-items: center;
  height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  font: 600 15px var(--mono);
}
.new-addr:focus-within { border-color: rgba(139, 92, 246, .6); }
.new-addr input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; font: inherit; color: var(--text); }
.new-dom { color: var(--faint); }
.dlg-input {
  width: 100%;
  margin-top: 10px;
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  outline: 0;
  font-size: 13.5px;
}
.dlg-input:focus { border-color: rgba(139, 92, 246, .5); }
.dlg-input::placeholder { color: var(--faint); }
.dlg-error { margin: 8px 0 0; color: var(--danger); font-size: 12.5px; }
.dlg-actions { display: flex; gap: 8px; margin-top: 20px; }
.dlg-actions .btn-primary { margin-inline-start: auto; }
.btn-ghost {
  height: 42px; padding: 0 16px;
  border-radius: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  transition: color .15s, border-color .15s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--line-2); }

/* ---------- login ---------- */
.login {
  position: fixed; inset: 0;
  z-index: 40;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(700px 420px at 50% 20%, rgba(124, 58, 237, .16), transparent 70%),
    var(--bg);
}
.login-card {
  width: min(360px, 100%);
  display: flex; flex-direction: column; align-items: center;
  padding: 34px 28px 28px;
  border-radius: 22px;
  background: rgba(18, 18, 25, .9);
  border: 1px solid var(--line-2);
  box-shadow: 0 30px 80px -24px rgba(0, 0, 0, .8);
}
.login-card .logo { width: 52px; height: 52px; border-radius: 16px; margin-bottom: 16px; }
.login-card h2 { margin: 0; font-size: 21px; }
.login-domain { margin: 4px 0 22px; color: var(--faint); font-size: 13px; direction: ltr; }
.login-card .dlg-input { margin: 0; text-align: center; }
.login-card .dlg-error { align-self: stretch; text-align: center; }
.login-card .btn-primary { width: 100%; margin-top: 14px; }
.btn-primary:disabled { opacity: .6; cursor: default; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: 28px;
  transform: translate(-50%, 16px);
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 12px;
  background: #1c1c26;
  border: 1px solid var(--line-2);
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .7);
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast bdi { direction: ltr; color: var(--accent-2); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, .55); }
  70%, 100% { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes arrive {
  0% { background: rgba(139, 92, 246, .28); }
  100% { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .list-pane { grid-row: 1; border: 0; }
  .rail {
    grid-row: 2;
    flex-direction: row;
    justify-content: space-around;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
    border-inline-end: 0;
    border-top: 1px solid var(--line);
  }
  .logo, .rail-spacer { display: none; }
  .rail-btn.is-active::before { display: none; }
  .list-head { padding: 18px 16px 8px; }
  .list { padding: 4px 6px 16px; }
  .reader {
    position: fixed; inset: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform .26s cubic-bezier(.2, .8, .2, 1);
    visibility: hidden;
  }
  .app.show-reader .reader { transform: none; visibility: visible; }
  .reader-content { padding: 14px 16px 50px; }
  .back { display: grid; }
  .r-subject { font-size: 20px; }
  .r-time { display: none; }
  .code-card { flex-wrap: wrap; gap: 14px; padding: 16px 18px; }
  .code-value { font-size: 30px; }
  .code-card .btn-primary { margin-inline-start: 0; width: 100%; }
}
