:root {
  color-scheme: dark;
  --bg: #0a111c;
  --surface: #0d1624;
  --surface-2: #121d2e;
  --surface-3: #172539;
  --raised: #1c2a40;
  --line: #1d2a3d;
  --line-strong: #2a3a52;
  --text: #eef2f8;
  --text-2: #c2ccda;
  --muted: #8291a7;
  --faint: #5a6980;
  --coral: #ff775f;
  --coral-soft: #ff775f1f;
  --cyan: #6de1d4;
  --cyan-soft: #6de1d41a;
  --yellow: #e7cf76;
  --paper: #fbfaf7;
  --ease: cubic-bezier(.22, .8, .24, 1);
  --font: Manrope, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --mono: "DM Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --topbar-h: 56px;
  --side-w: 264px;
  --list-w: 400px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
svg { display: block; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 2px 5px;
  margin: 0 2px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: 10.5px/1.2 var(--mono);
  color: var(--text-2);
  text-align: center;
}

/* Independent scroll regions: each pane scrolls on its own, the page never does. */
.scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  -webkit-overflow-scrolling: touch;
}
.scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.scroll::-webkit-scrollbar-track { background: transparent; }
.scroll::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 3px solid transparent;
  border-radius: 10px;
  background-clip: padding-box;
}
.scroll::-webkit-scrollbar-thumb:hover { background-color: #3a4d69; }

/* Shell */
.app-shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  background: radial-gradient(1100px 520px at 88% -12%, #17253a 0, transparent 62%), var(--bg);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px 0 24px;
  border-bottom: 1px solid var(--line);
  background: #0b1320d9;
}
.brand { display: flex; align-items: center; gap: 12px; font-size: 13px; font-weight: 800; letter-spacing: .18em; white-space: nowrap; }
.brand-mark { color: var(--coral); font-size: 22px; line-height: 1; letter-spacing: 0; }
.brand small { padding-left: 12px; border-left: 1px solid var(--line-strong); font: 400 10px var(--mono); letter-spacing: .12em; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.status { display: flex; align-items: center; gap: 8px; margin-right: 6px; font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 0 3px var(--cyan-soft); transition: background .2s, box-shadow .2s; }
.status[data-state="syncing"] .pulse { background: var(--yellow); box-shadow: 0 0 0 3px #e7cf7622; animation: pulse 1.2s ease-in-out infinite; }
.status[data-state="warn"] .pulse { background: var(--yellow); box-shadow: 0 0 0 3px #e7cf7622; }
.status[data-state="error"] .pulse { background: var(--coral); box-shadow: 0 0 0 3px var(--coral-soft); }
@keyframes pulse { 50% { opacity: .35; } }

/* Buttons */
.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: transparent;
  color: var(--text-2);
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.small { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.small svg { width: 14px; height: 14px; }
.icon-btn.spinning svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: var(--coral);
  color: #22120f;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 6px 20px #ff775f2e;
  transition: filter .15s, transform .15s;
}
.primary-btn svg { width: 14px; height: 14px; }
.primary-btn:active { transform: translateY(1px); }
.primary-btn:disabled { opacity: .6; }
.ghost-btn {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  transition: color .15s, border-color .15s;
}
.text-btn {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  transition: background .15s, color .15s;
}
.text-btn:disabled { opacity: .4; }
.danger-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border: 1px solid #7a3b32;
  border-radius: 7px;
  background: var(--coral-soft);
  color: var(--coral);
  font-size: 12.5px;
  font-weight: 700;
  transition: background .15s;
}
.danger-btn svg { width: 13px; height: 13px; }
.danger-btn:disabled { opacity: .5; }

/* Three-pane workspace */
.workspace {
  display: grid;
  grid-template-columns: var(--side-w) var(--list-w) minmax(0, 1fr);
  min-height: 0;
}
.eyebrow {
  display: block;
  overflow: hidden;
  font: 10.5px var(--mono);
  letter-spacing: .14em;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sidebar */
.sidebar { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: #0b131fb3; }
.side-heading { display: flex; align-items: flex-end; justify-content: space-between; padding: 22px 16px 14px 20px; }
.side-heading h1 { display: flex; align-items: baseline; gap: 8px; margin: 6px 0 0; font-size: 19px; font-weight: 800; letter-spacing: -.02em; }
.side-heading h1 span { font: 400 11px var(--mono); color: var(--muted); }
.add-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid #6b3a33;
  border-radius: 8px;
  background: var(--coral-soft);
  color: var(--coral);
  transition: background .15s;
}
.add-btn svg { width: 14px; height: 14px; }
.account-search {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  margin: 0 12px 10px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #080e18;
  color: var(--muted);
  transition: border-color .15s, box-shadow .15s;
}
.account-search:focus-within { border-color: #3d8f88; box-shadow: 0 0 0 3px var(--cyan-soft); }
.account-search svg { width: 14px; height: 14px; }
.account-search input { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: none; background: transparent; color: var(--text); font-size: 12.5px; }
.account-search input::placeholder { color: var(--muted); }
body.no-accounts .account-search, body.no-accounts #refreshBtn { display: none; }
.account-list { flex: 1; min-height: 0; padding: 2px 10px 12px; }
.account { position: relative; display: flex; align-items: center; margin-bottom: 2px; border-radius: 10px; transition: background .15s; }
.account.active { background: var(--surface-3); }
.account.active::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--coral); }
.account-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px 8px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
}
.account-main .avatar { width: 28px; height: 28px; border-radius: 8px; font-size: 12px; }
.account-email { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.account.active .account-email { font-weight: 700; color: var(--text); }
.account-remove {
  flex: none;
  width: 28px;
  height: 28px;
  margin-right: 6px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
}
.account-remove svg { width: 13px; height: 13px; }
.account.active .account-remove, .account-remove:focus-visible { opacity: 1; }
.side-empty { padding: 28px 12px; color: var(--muted); font-size: 13px; line-height: 1.7; text-align: center; }
.side-empty span { display: block; font-size: 11.5px; color: var(--faint); }
.sidebar-foot { display: flex; align-items: center; gap: 8px; padding: 12px 14px 12px 20px; border-top: 1px solid var(--line); font: 10.5px var(--mono); color: var(--muted); }
.foot-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.foot-dot.off { background: var(--faint); box-shadow: none; }
.cache-status { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot-btn { flex: none; padding: 4px 6px; border: 0; border-radius: 6px; background: none; color: var(--text-2); font: inherit; text-decoration: underline; text-underline-offset: 3px; }
.foot-btn[hidden] { display: none; }

.avatar {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: hsl(var(--av-h, 215) 30% 22%);
  color: hsl(var(--av-h, 215) 80% 80%);
  font: 500 13px var(--mono);
  text-transform: uppercase;
}

/* Message list */
.list-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line); background: #0c1522b3; }
.list-head { flex: none; padding: 20px 18px 0; border-bottom: 1px solid var(--line); }
.list-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.list-title > div { min-width: 0; }
.list-account { display: flex; align-items: center; gap: 6px; min-width: 0; }
.icon-btn.mini { position: relative; width: 26px; height: 26px; border-radius: 7px; }
.icon-btn.mini svg { width: 13px; height: 13px; }
.icon-btn.mini::after { content: ""; position: absolute; inset: -9px; }
.list-title h2 { margin: 2px 0 0; font-size: 22px; font-weight: 800; letter-spacing: -.03em; }
.count-label { padding-bottom: 5px; font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  margin-top: 16px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #080e18;
}
.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background .2s var(--ease), color .2s, box-shadow .2s;
}
.tab span { font: 400 10.5px var(--mono); color: var(--faint); transition: color .2s; }
.tab.active { background: var(--raised); color: var(--text); box-shadow: inset 0 1px 0 #ffffff0d, 0 2px 8px #0005; }
.tab.active span { color: var(--coral); }
.list-tools { position: relative; display: flex; align-items: center; height: 48px; }
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-2); cursor: pointer; user-select: none; transition: opacity .18s; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { position: relative; width: 30px; height: 18px; border-radius: 9px; background: var(--line-strong); transition: background .2s; }
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform .22s var(--ease), background .2s;
}
.switch input:checked + .switch-track { background: var(--cyan); }
.switch input:checked + .switch-track::after { transform: translateX(12px); background: #0d1b22; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--cyan); outline-offset: 2px; }
.selection-bar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity .18s, transform .2s var(--ease);
}
.selection-label { margin-right: auto; font-size: 12.5px; font-weight: 700; }
.list-tools.selecting .selection-bar { opacity: 1; pointer-events: auto; transform: none; }
.list-tools.selecting .switch { opacity: 0; pointer-events: none; }

.message-list { flex: 1; min-height: 0; padding: 6px 6px 24px 8px; scrollbar-gutter: stable; }
.message-row {
  --i: 0;
  position: relative;
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 2px;
  padding: 12px 12px 12px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  text-align: left;
  transition: background .15s;
}
.message-row.active { background: var(--surface-3); }
.message-row.active::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: var(--coral); }
.message-row.checked { background: #6de1d40d; }
.message-row.checked.active { background: #6de1d41a; }
.message-row.enter { animation: rise .34s var(--ease) both; animation-delay: calc(var(--i) * 16ms); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* Avatar doubles as the selection checkbox. */
.row-check {
  position: relative;
  flex: none;
  width: 32px;
  height: 32px;
  margin-top: 1px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: hsl(var(--av-h, 215) 30% 22%);
  color: hsl(var(--av-h, 215) 80% 80%);
  font: 500 13px var(--mono);
  transition: background .15s, box-shadow .15s;
}
.row-initial { transition: opacity .12s; }
.row-check svg { position: absolute; width: 15px; height: 15px; color: #0d1b22; opacity: 0; transform: scale(.6); transition: opacity .15s, transform .2s var(--ease); }
.selecting .row-check { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-strong); }
.selecting .row-initial, .message-row.checked .row-initial { opacity: 0; }
.message-row.checked .row-check { background: var(--cyan); box-shadow: none; }
.message-row.checked .row-check svg { opacity: 1; transform: none; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row-top, .row-bottom { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row-sender, .row-subject { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sender { font-size: 13.5px; font-weight: 700; color: var(--text); }
.row-date { flex: none; font: 11px var(--mono); color: var(--muted); }
.message-row.active .row-date { color: var(--text-2); }
.row-subject { font-size: 13px; color: var(--text-2); }
.row-preview { display: -webkit-box; overflow: hidden; font-size: 12px; color: var(--muted); -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row-tags, .reader-tags { flex: none; display: flex; gap: 4px; }
.tag {
  padding: 3px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font: 9.5px/1.2 var(--mono);
  letter-spacing: .06em;
  color: var(--muted);
  white-space: nowrap;
}
.tag.junk { border-color: #5f5534; background: #e7cf760d; color: var(--yellow); }
.tag.claude { border-color: #25615f; background: var(--cyan-soft); color: var(--cyan); }

/* Loading skeletons */
.skeleton-row { display: flex; gap: 12px; padding: 12px 12px 12px 10px; }
.sk-lines { flex: 1; display: flex; flex-direction: column; gap: 9px; padding-top: 4px; }
.sk {
  display: block;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 0, var(--surface-3) 40%, var(--surface-2) 80%);
  background-size: 300% 100%;
  animation: shimmer 1.4s linear infinite;
}
.sk-avatar { flex: none; width: 32px; height: 32px; border-radius: 9px; }
.sk-line { height: 10px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }

/* Empty / error states */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 72px 24px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  animation: fade .3s var(--ease);
}
.empty-state p { max-width: 300px; margin: 0; color: var(--muted); font-size: 12.5px; font-weight: 400; line-height: 1.6; overflow-wrap: anywhere; }
.empty-state .primary-btn, .empty-state .ghost-btn { margin-top: 14px; }
.empty-glyph {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
}
.empty-glyph svg { width: 20px; height: 20px; }
.empty-state.error .empty-glyph { border-color: #5a2f2a; background: var(--coral-soft); color: var(--coral); }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* Reader */
.message-reader { position: relative; min-width: 0; min-height: 0; }
.reader-empty {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 40px;
  color: var(--muted);
  text-align: center;
}
.reader-empty h3 { margin: 4px 0 0; font-size: 15px; color: var(--text-2); }
.reader-empty p { margin: 0; font-size: 12.5px; }
.reader-empty .kbd-hint { margin-top: 18px; font-size: 11.5px; color: var(--faint); }
.reader-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 20px 0 28px;
  border-bottom: 1px solid var(--line);
  background: #0b1320e6;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.reader-bar .icon-btn { margin-left: auto; }
.back-btn {
  display: none;
  align-items: center;
  gap: 2px;
  height: 32px;
  margin-left: -8px;
  padding: 0 10px 0 4px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.back-btn svg { width: 18px; height: 18px; }
.reader-content { max-width: 880px; margin: 0 auto; padding: 28px 36px 72px; animation: fade .26s var(--ease); }
.reader-subject { margin: 0 0 20px; font-size: 24px; font-weight: 800; line-height: 1.3; letter-spacing: -.025em; overflow-wrap: anywhere; }
.sender-line { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.sender-line .avatar { width: 40px; height: 40px; border-radius: 11px; font-size: 15px; }
.sender-meta { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 2px; }
.sender-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.sender-top strong { font-size: 14px; }
.sender-addr { font: 11.5px var(--mono); color: var(--muted); overflow-wrap: anywhere; }
.sender-meta small { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.sender-date { font: 11.5px var(--mono); color: var(--muted); white-space: nowrap; }
.reader-body > * { animation: fade .3s var(--ease); }
.quick-copy { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.quick-card {
  flex: 1 1 240px;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 12px 12px 16px;
  border: 1px solid #25615f;
  border-radius: 12px;
  background: #6de1d40d;
  color: var(--text);
  text-align: left;
  transition: background .15s, border-color .15s;
}
.quick-card.done { border-color: #3d8f88; background: #6de1d41a; }
.quick-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.quick-kind { font: 10.5px var(--mono); letter-spacing: .14em; color: var(--muted); }
.quick-value { overflow: hidden; font-size: 13px; color: var(--cyan); text-overflow: ellipsis; white-space: nowrap; }
.quick-card.is-code .quick-value { font: 500 24px/1.2 var(--mono); letter-spacing: .16em; color: var(--text); }
.quick-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 700;
  transition: background .15s, color .15s;
}
.quick-badge svg { width: 13px; height: 13px; }
.quick-card.done .quick-badge { background: var(--cyan); color: #0d1b22; }
.body-loading { display: flex; flex-direction: column; gap: 12px; padding: 4px 0; }
.body-loading .sk-line { height: 12px; }
.body-error { padding: 32px 24px; border: 1px solid #4a2a28; border-radius: 14px; background: #ff775f0a; color: var(--coral); font-weight: 600; text-align: center; }
.body-error p { margin: 6px 0 16px; color: var(--muted); font-size: 12.5px; font-weight: 400; overflow-wrap: anywhere; }
.mail-paper { overflow: hidden; border-radius: 14px; background: var(--paper); box-shadow: 0 24px 60px -28px #000c; }
.mail-frame { display: block; width: 100%; height: 120px; border: 0; background: var(--paper); }
.rendered-mail { padding: 28px 32px; color: #243247; font-size: 14.5px; line-height: 1.8; white-space: pre-wrap; overflow-wrap: anywhere; }
.links-section { margin-top: 24px; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.links-title { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.links-title > span:last-child { font: 11px var(--mono); color: var(--muted); }
.mail-link { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.mail-link + .mail-link { border-top: 1px solid var(--line); }
.mail-link a {
  flex: 1;
  min-width: 0;
  display: -webkit-box;
  overflow: hidden;
  color: var(--cyan);
  font-size: 12px;
  line-height: 1.5;
  text-decoration: none;
  overflow-wrap: anywhere;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.copy-link {
  flex: none;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 600;
  transition: border-color .15s, color .15s;
}
.copy-link.done { border-color: var(--cyan); color: var(--cyan); }

/* Import dialog */
dialog {
  width: min(560px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 40px 100px #000b;
}
dialog[open] { animation: pop .22s var(--ease); }
dialog::backdrop { background: #050b14b3; backdrop-filter: blur(6px); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
#importForm { padding: 24px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; }
.dialog-head h2 { margin: 6px 0 0; font-size: 21px; font-weight: 800; letter-spacing: -.02em; }
.close-btn { width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 8px; background: none; color: var(--muted); }
.close-btn svg { width: 16px; height: 16px; }
.dialog-copy { margin: 16px 0 14px; color: var(--muted); font-size: 12.5px; line-height: 1.75; }
.dialog-copy code { padding: 1px 5px; border: 1px solid var(--line); border-radius: 5px; background: #0a111c; color: var(--text-2); font: 11.5px var(--mono); overflow-wrap: anywhere; }
textarea {
  display: block;
  width: 100%;
  height: 180px;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
  background: #0a111c;
  color: var(--cyan);
  font: 12px/1.65 var(--mono);
  resize: vertical;
  transition: border-color .15s, box-shadow .15s;
}
textarea:focus { border-color: #3d8f88; box-shadow: 0 0 0 3px var(--cyan-soft); }
textarea::placeholder { color: var(--faint); }
.format-hint { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.format-hint span { padding: 3px 7px; border: 1px solid var(--line); border-radius: 6px; font: 10.5px var(--mono); color: var(--muted); }
.cache-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 18px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.cache-row select { height: 32px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: #0a111c; color: var(--text); font: inherit; font-weight: 500; }
.cache-row small { flex-basis: 100%; color: var(--muted); font-size: 11.5px; font-weight: 400; line-height: 1.6; }
.form-error { min-height: 18px; margin: 12px 0 10px; color: var(--coral); font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(480px, calc(100% - 32px));
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--cyan);
  color: #0e1f26;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 12px 30px #0007;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity .22s, transform .22s var(--ease);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--coral); color: #24110d; }

/* Hover styles only where a pointer can hover, so taps don't leave rows stuck highlighted. */
@media (hover: hover) {
  .icon-btn:hover { background: var(--surface-3); color: var(--text); }
  .primary-btn:hover { filter: brightness(1.06); }
  .ghost-btn:hover { border-color: #3a4d69; color: var(--text); }
  .text-btn:hover { background: var(--surface-3); color: var(--text); }
  .danger-btn:hover:not(:disabled) { background: #ff775f33; }
  .add-btn:hover { background: #ff775f33; }
  .foot-btn:hover { color: var(--coral); }
  .account:hover { background: var(--surface-2); }
  .account.active:hover { background: var(--surface-3); }
  .account:hover .account-remove { opacity: 1; }
  .account-remove:hover { background: var(--coral-soft); color: var(--coral); }
  .tab:hover:not(.active) { color: var(--text-2); }
  .message-row:hover { background: var(--surface-2); }
  .message-row.active:hover { background: var(--surface-3); }
  .row-check:hover { background: transparent; box-shadow: inset 0 0 0 1.5px var(--cyan); }
  .row-check:hover .row-initial { opacity: 0; }
  .message-row.checked .row-check:hover { background: var(--cyan); }
  .back-btn:hover { background: var(--surface-3); }
  .mail-link a:hover { text-decoration: underline; }
  .copy-link:hover { border-color: var(--cyan); color: var(--cyan); }
  .quick-card:hover:not(.done) { border-color: #3d8f88; background: #6de1d414; }
  .close-btn:hover { background: var(--surface-3); color: var(--text); }
}

@media (min-width: 1600px) {
  :root { --list-w: 440px; }
}
@media (max-width: 1180px) {
  :root { --side-w: 232px; --list-w: 340px; }
  .brand small { display: none; }
  .reader-content { padding: 24px 24px 64px; }
}

/* Phone / narrow: single column, reader slides over the list. */
@media (max-width: 860px) {
  :root { --topbar-h: 52px; }
  .topbar { padding: 0 12px 0 16px; padding-left: max(16px, env(safe-area-inset-left)); }
  .status { margin-right: 0; }
  .hide-sm { display: none; }
  .workspace { display: flex; flex-direction: column; }
  .sidebar { flex: none; border-right: 0; border-bottom: 1px solid var(--line); background: transparent; }
  .side-heading { display: none; }
  .sidebar-foot { padding: 0 10px 8px 16px; border-top: 0; }
  body.no-accounts .sidebar { display: none; }
  .account-search { height: 44px; margin: 10px 12px 0; border-radius: 12px; }
  .account-search input { font-size: 16px; }
  .account-list { display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 8px 12px 10px; scrollbar-width: none; }
  .account-list::-webkit-scrollbar { display: none; }
  .account { flex: none; max-width: 260px; margin: 0; border: 1px solid var(--line); background: var(--surface); }
  .account.active { border-color: var(--line-strong); }
  .account.active::before { display: none; }
  .account-main { gap: 8px; padding: 6px 6px 6px 8px; }
  .account .avatar { width: 26px; height: 26px; border-radius: 7px; font-size: 11px; }
  .account-remove { display: none; width: 24px; height: 24px; margin-right: 4px; }
  .account.active .account-remove { display: grid; }
  .list-pane { flex: 1; border-right: 0; }
  .list-head { padding: 14px 14px 0; }
  .list-title h2 { font-size: 20px; }
  .message-list { padding: 4px 4px calc(24px + env(safe-area-inset-bottom)) 6px; }
  .message-reader {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: var(--bg);
    visibility: hidden;
    transform: translateX(100%);
    transition: transform .32s var(--ease), visibility 0s linear .32s;
  }
  body.reading .message-reader { visibility: visible; transform: none; transition: transform .32s var(--ease); }
  .reader-bar { height: calc(52px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0 16px; }
  .back-btn { display: inline-flex; }
  .reader-bar .eyebrow { display: none; }
  .reader-content { padding: 20px 16px calc(48px + env(safe-area-inset-bottom)); }
  .reader-subject { font-size: 20px; }
  .mail-paper { border-radius: 10px; }
  .rendered-mail { padding: 20px; }
  .quick-card { flex-basis: 100%; padding: 10px 10px 10px 14px; }
  .quick-badge { height: 44px; padding: 0 14px; border-radius: 10px; font-size: 13px; }
}
@media (max-width: 360px) {
  #connectionLabel { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

/* Touch devices: larger tap targets, and no iOS zoom when focusing a field (needs >= 16px). */
@media (pointer: coarse) {
  .tab { height: 40px; }
  .text-btn, .danger-btn { height: 38px; padding: 0 14px; }
  .account-remove, .account.active .account-remove { width: 36px; height: 36px; }
  .row-check::after { content: ""; position: absolute; inset: -8px; }
  .copy-link { min-height: 36px; padding: 0 14px; }
}
@media (max-width: 860px) {
  textarea, select, input { font-size: 16px; }
  #importDialog { max-height: calc(100dvh - 24px); overflow-y: auto; }
}
