/* FDM Mail (Fifth Dimension Media) — minimal, fast, touch friendly */
:root {
  --bg: #f8f8fb;
  --panel: #ffffff;
  --text: #16151f;
  --muted: #646278;
  --faint: #9896ab;
  --line: #eae8f0;
  --field: #ffffff;
  --field-line: #dad7e5;
  --hover: #f1f0f7;
  --sel: #f5f0ff;
  --active: #eee6ff;
  --accent: #7c05fa;
  --accent-gradient: linear-gradient(135deg, #1f08cb 0%, #7c05fa 100%);
  --logo-ink: #16151f;
  --logo-accent: #7c05fa;
  --scroll: rgb(0 0 0 / .18);
  --scroll-hover: rgb(0 0 0 / .32);
  --accent-ink: #ffffff;
  --accent-soft: #f4ecff;
  --danger: #cc3b3b;
  --danger-soft: #fdecec;
  --ok: #1b7f4a;
  --ok-soft: #e5f5ec;
  --warn: #a8660b;
  --warn-soft: #fdf3e2;
  --shadow: 0 1px 3px rgb(31 8 203 / .05), 0 10px 30px rgb(124 5 250 / .08);
  --r: 10px;
  --r-lg: 14px;
  --side: 236px;
  --list: 384px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0c13; --panel: #13121b; --text: #ecebf5; --muted: #9e9cb5; --faint: #6e6b85; --line: #222030;
    --field: #191824; --field-line: #2e2b42; --hover: #1c1a29; --sel: #231c3d; --active: #2e2354;
    --accent: #9d5cfc; --accent-gradient: linear-gradient(135deg, #381ae6 0%, #9d5cfc 100%);
    --accent-ink: #ffffff; --logo-ink: #ecebf5; --logo-accent: #b385ff;
    --scroll: rgb(255 255 255 / .16); --scroll-hover: rgb(255 255 255 / .3); --accent-soft: #291a47;
    --danger: #ff7b7b; --danger-soft: #3a1f22; --ok: #5fd39a; --ok-soft: #173125; --warn: #f0b35c; --warn-soft: #362a17;
    --shadow: 0 1px 3px rgb(0 0 0 / .35), 0 12px 36px rgb(0 0 0 / .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0c13; --panel: #13121b; --text: #ecebf5; --muted: #9e9cb5; --faint: #6e6b85; --line: #222030;
  --field: #191824; --field-line: #2e2b42; --hover: #1c1a29; --sel: #231c3d; --active: #2e2354;
  --accent: #9d5cfc; --accent-gradient: linear-gradient(135deg, #381ae6 0%, #9d5cfc 100%);
  --accent-ink: #ffffff; --logo-ink: #ecebf5; --logo-accent: #b385ff;
  --scroll: rgb(255 255 255 / .16); --scroll-hover: rgb(255 255 255 / .3); --accent-soft: #291a47;
  --danger: #ff7b7b; --danger-soft: #3a1f22; --ok: #5fd39a; --ok-soft: #173125; --warn: #f0b35c; --warn-soft: #362a17;
  --shadow: 0 1px 3px rgb(0 0 0 / .35), 0 12px 36px rgb(0 0 0 / .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--panel); color: var(--text);
  font: 14px/1.45 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* Thin, quiet scrollbars (no arrow buttons) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 99px; border: 3px solid transparent; background-clip: padding-box; min-height: 40px; }
::-webkit-scrollbar-thumb:hover { background-color: var(--scroll-hover); }
@supports not selector(::-webkit-scrollbar) { * { scrollbar-width: thin; scrollbar-color: var(--scroll) transparent; } }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 6px; }

.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.sm { width: 14px; height: 14px; }
.i.lg { width: 22px; height: 22px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--hover); }
.btn.primary {
  background: var(--accent-gradient, var(--accent));
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: 0 2px 8px rgb(124 5 250 / .22);
}
.btn.primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 4px 14px rgb(124 5 250 / .35);
  transform: translateY(-0.5px);
}
.btn.primary:active { transform: translateY(0); filter: brightness(0.96); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn.block { width: 100%; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 9px; color: var(--muted);
  transition: background .15s, color .15s; position: relative;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--accent); }
.icon-btn[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; top: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--panel); font-size: 12px; padding: 3px 8px; border-radius: 6px; white-space: nowrap; z-index: 50; pointer-events: none;
}
@media (hover: none) { .icon-btn[data-tip]:hover::after { display: none; } }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.field small { color: var(--faint); font-size: 12px; }
.input, select.input, textarea.input {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--field-line); border-radius: 9px; background: var(--field);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 84px; padding: 9px 12px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 0; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 500; background: var(--hover); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- boot / auth ---------- */
.boot { height: 100dvh; display: grid; place-items: center; }
.logo-lg { width: auto; height: 56px; aspect-ratio: 143/191; animation: pulse 1.4s ease-in-out infinite; filter: drop-shadow(0 6px 18px rgb(124 5 250 / .35)); }
@keyframes pulse { 50% { opacity: .5; transform: scale(.94); } }
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 20px; margin: 14px 0 4px; letter-spacing: -.01em; }
.auth-card p { margin: 0 0 22px; color: var(--muted); }
.auth-card .logo { width: auto; height: 46px; aspect-ratio: 143/191; filter: drop-shadow(0 4px 12px rgb(124 5 250 / .25)); }
.auth-card .btn.primary { width: 100%; height: 40px; margin-top: 6px; }

/* ---------- shell ---------- */
.shell {
  height: 100dvh; display: grid; grid-template-columns: var(--side) var(--list) minmax(0, 1fr); overflow: hidden;
}
.side {
  background: var(--bg); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0;
  padding: calc(12px + var(--safe-t)) 10px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; font-weight: 650; letter-spacing: -.01em; }
.brand svg { width: auto; height: 28px; aspect-ratio: 143/191; flex: none; filter: drop-shadow(0 2px 6px rgb(124 5 250 / .2)); }
.brand small { display: block; font-weight: 400; color: var(--faint); font-size: 12px; margin-top: -2px; }
.compose-btn { width: 100%; height: 40px; margin-bottom: 14px; justify-content: flex-start; padding-left: 14px; box-shadow: 0 1px 2px rgb(0 0 0 / .06); }
.nav { overflow-y: auto; flex: 1; margin: 0 -4px; padding: 0 4px; }
.nav h6 { margin: 18px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 11px; height: 34px; padding: 0 10px; border-radius: 8px; color: var(--text);
  text-decoration: none; font-weight: 450; transition: background .12s;
}
.nav a .i { color: var(--muted); }
.nav a:hover { background: var(--hover); }
.nav a.active { background: var(--active); color: var(--accent); font-weight: 600; }
.nav a.active .i { color: var(--accent); }
.nav a .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a .n { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav a.active .n, .nav a .n.strong { color: var(--accent); font-weight: 600; }
.side-foot { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; display: flex; align-items: center; gap: 2px; }
.me { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; padding: 4px 6px; border-radius: 8px; text-align: left; }
.me:hover { background: var(--hover); }
.me .who { min-width: 0; line-height: 1.25; }
.me .who b { display: block; font-weight: 550; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .who span { display: block; font-size: 11.5px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- list pane ---------- */
.list-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); position: relative; }
.list-head { display: flex; align-items: center; gap: 6px; padding: calc(10px + var(--safe-t)) 12px 8px; }
.list-head h2 { font-size: 17px; margin: 0 0 0 4px; font-weight: 650; letter-spacing: -.01em; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-head .menu-btn { display: none; }
.search { position: relative; padding: 0 12px 8px; }
.search .i { position: absolute; left: 24px; top: 10px; color: var(--faint); pointer-events: none; }
.search input { padding-left: 36px; padding-right: 34px; background: var(--bg); border-color: transparent; height: 38px; }
.search input:focus { background: var(--panel); }
.search .clear { position: absolute; right: 16px; top: 3px; }
.chips { display: flex; gap: 6px; padding: 0 12px 10px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 11px; border-radius: 99px; border: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted); white-space: nowrap; transition: all .12s; flex: none;
}
.chip:hover { background: var(--hover); color: var(--text); }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 550; }
.chip .i { width: 14px; height: 14px; }
.bulkbar { display: flex; align-items: center; gap: 2px; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--sel); }
.bulkbar .count { flex: 1; font-weight: 600; padding-left: 6px; }

/* pull to refresh */
.list-pane { overflow: hidden; }
.ptr {
  position: absolute; left: 50%; top: var(--ptr-top, 120px); z-index: 4; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; background: var(--panel); color: var(--accent); opacity: 0; pointer-events: none;
  box-shadow: 0 2px 10px rgb(0 0 0 / .14), 0 0 0 1px var(--line); transform: translate(-50%, -44px);
}
.ptr > * { grid-area: 1 / 1; }
.ptr-ring { width: 34px; height: 34px; transform: rotate(-90deg); }
.ptr-ring circle { fill: none; stroke-width: 3; }
.ptr-track { stroke: var(--hover); }
.ptr-bar { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 87.96; stroke-dashoffset: 87.96; transition: stroke-dashoffset .08s linear; }
.ptr-arrow { width: 15px; height: 15px; stroke-width: 2.4; transition: transform .2s var(--ease), opacity .2s; }
.ptr.ready .ptr-arrow { transform: scale(1.15); }
.ptr.spinning .ptr-ring { animation: ptr-spin .8s linear infinite; }
.ptr.spinning .ptr-bar { transition: none; }
.ptr.spinning .ptr-arrow { opacity: 0; transform: scale(.6); }
@keyframes ptr-spin { from { transform: rotate(-90deg); } to { transform: rotate(270deg); } }
@media (prefers-reduced-motion: reduce) { .ptr.spinning .ptr-ring { animation-duration: 2s; } }

.list { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-bottom: calc(84px + var(--safe-b)); }
.item { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); touch-action: pan-y; user-select: none; }
.item-inner {
  display: flex; gap: 12px; padding: 12px 14px 12px 12px; background: var(--panel); position: relative; z-index: 1; cursor: pointer;
  transition: background .12s;
}
.item.swiping .item-inner { transition: none; }
.item:not(.swiping) .item-inner { transition: transform .25s var(--ease), background .12s; }
.item:hover .item-inner { background: var(--hover); }
.item.active .item-inner { background: var(--active); }
.item.selected .item-inner { background: var(--sel); }
.item.unread .item-inner::before { content: ""; position: absolute; left: 4px; top: 50%; width: 5px; height: 5px; margin-top: -2.5px; border-radius: 50%; background: var(--accent); }
.swipe-bg { position: absolute; inset: 0; display: flex; justify-content: space-between; align-items: center; padding: 0 22px; color: #fff; }
.swipe-bg.left { background: var(--ok); }
.swipe-bg.right { background: var(--accent); }
.swipe-bg span { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.av {
  --h: 220; width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 600; font-size: 14px; background: hsl(var(--h) 55% 90%); color: hsl(var(--h) 45% 32%); position: relative;
}
:root[data-theme="dark"] .av { background: hsl(var(--h) 25% 22%); color: hsl(var(--h) 60% 80%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .av { background: hsl(var(--h) 25% 22%); color: hsl(var(--h) 60% 80%); } }
.av .tick { position: absolute; inset: 0; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: none; place-items: center; }
.item.selected .av .tick { display: grid; }
.av-btn { display: block; border-radius: 50%; flex: none; align-self: flex-start; }
.av.sm { width: 28px; height: 28px; font-size: 12px; }
.av.lg { width: 40px; height: 40px; }
.item-main { flex: 1; min-width: 0; }
.r1, .r2, .r3 { display: flex; align-items: center; gap: 6px; min-width: 0; }
.r1 .who { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.r1 time { font-size: 12px; color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.r1 .i { color: var(--faint); }
.r2 .subj { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.r3 { margin-top: 1px; }
.r3 .snip { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 13px; }
.item.unread .who, .item.unread .subj { font-weight: 650; }
.item.unread time { color: var(--accent); font-weight: 600; }
.star { color: var(--faint); display: grid; place-items: center; width: 26px; height: 22px; margin-right: -4px; }
.star .i { width: 16px; height: 16px; }
.star.on { color: #e3a008; }
.star.on .i { fill: currentColor; }
.tag { font-size: 11px; padding: 0 6px; border-radius: 5px; background: var(--hover); color: var(--muted); white-space: nowrap; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.list-empty { text-align: center; padding: 64px 24px; color: var(--muted); }
.list-empty .i { width: 38px; height: 38px; color: var(--faint); stroke-width: 1.4; margin-bottom: 10px; }
.list-more { padding: 18px; text-align: center; color: var(--faint); font-size: 13px; }
.skeleton .item-inner { pointer-events: none; }
.sk { background: linear-gradient(90deg, var(--hover), var(--bg), var(--hover)); background-size: 200% 100%; animation: sk 1.2s linear infinite; border-radius: 6px; height: 11px; }
@keyframes sk { to { background-position: -200% 0; } }
.new-pill {
  position: absolute; top: 118px; left: 50%; transform: translateX(-50%); z-index: 5; background: var(--accent); color: var(--accent-ink);
  border-radius: 99px; padding: 6px 14px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow);
}

/* ---------- reader ---------- */
.reader { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.reader-empty { flex: 1; display: grid; place-items: center; color: var(--faint); text-align: center; }
.reader-empty .i { width: 46px; height: 46px; stroke-width: 1.2; margin-bottom: 8px; }
.r-bar { display: flex; align-items: center; gap: 2px; padding: calc(10px + var(--safe-t)) 12px 8px; border-bottom: 1px solid var(--line); }
.r-bar .spacer { flex: 1; }
.r-bar .back { display: none; }
.r-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 22px 28px calc(40px + var(--safe-b)); }
.r-subj { font-size: 21px; line-height: 1.3; margin: 0 0 8px; font-weight: 650; letter-spacing: -.015em; overflow-wrap: anywhere; }
.r-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.msg { border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: 12px; background: var(--panel); overflow: hidden; }
.msg-head { display: flex; gap: 12px; padding: 14px 16px; cursor: pointer; align-items: flex-start; }
.msg-head .meta { flex: 1; min-width: 0; }
.msg-head .from { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.msg-head .from b { font-weight: 600; }
.msg-head .from span { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.msg-head .to { color: var(--muted); font-size: 12.5px; margin-top: 1px; overflow-wrap: anywhere; }
.msg-head time { color: var(--faint); font-size: 12px; white-space: nowrap; }
.msg.collapsed .msg-body, .msg.collapsed .atts, .msg.collapsed .notice { display: none; }
.msg.collapsed .msg-head { padding-bottom: 12px; }
.msg .preview { display: none; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg.collapsed .preview { display: block; }
.msg.collapsed .to { display: none; }
.msg-body { padding: 0 16px 16px; }
.mail-frame { width: 100%; border: 0; display: block; min-height: 60px; background: #fff; border-radius: 8px; color-scheme: light; }
.plain { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; }
.notice { margin: 0 16px 12px; padding: 8px 12px; border-radius: 9px; font-size: 12.5px; display: flex; align-items: center; gap: 8px; background: var(--hover); color: var(--muted); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--danger-soft); color: var(--danger); }
.notice button { color: var(--accent); font-weight: 600; margin-left: auto; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 16px; }
.att {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  max-width: 260px; text-decoration: none; color: var(--text); transition: background .12s; background: var(--panel);
}
.att:hover { background: var(--hover); }
.att .ext { width: 32px; height: 32px; border-radius: 7px; display: grid; place-items: center; font-size: 10px; font-weight: 700; background: var(--accent-soft); color: var(--accent); text-transform: uppercase; flex: none; }
.att .nm { min-width: 0; line-height: 1.25; }
.att .nm b { display: block; font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att .nm span { font-size: 11.5px; color: var(--faint); }
.att .x { margin-left: 4px; color: var(--faint); }
.reply-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.reply-bar .btn { border-radius: 99px; }
.details { margin: 0 16px 14px; padding: 10px 12px; background: var(--bg); border-radius: 9px; font-size: 12px; overflow-x: auto; }
.details table { border-collapse: collapse; }
.details td { padding: 2px 10px 2px 0; vertical-align: top; overflow-wrap: anywhere; }
.details td:first-child { color: var(--faint); white-space: nowrap; }

/* ---------- compose ---------- */
.compose {
  position: fixed; right: 24px; bottom: 0; width: min(620px, calc(100vw - 48px)); height: min(640px, calc(100dvh - 60px));
  background: var(--panel); border: 1px solid var(--line); border-bottom: 0; border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: 0 -2px 40px rgb(0 0 0 / .16); display: flex; flex-direction: column; z-index: 60;
  animation: rise .22s var(--ease);
}
.compose.expanded { right: 50%; bottom: 50%; transform: translate(50%, 50%); width: min(900px, calc(100vw - 48px)); height: min(760px, calc(100dvh - 48px)); border-radius: var(--r-lg); border-bottom: 1px solid var(--line); animation: none; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.c-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.c-head b { flex: 1; font-weight: 600; }
.c-field { display: flex; align-items: center; gap: 8px; padding: 0 16px; border-bottom: 1px solid var(--line); min-height: 42px; position: relative; }
.c-field label { color: var(--faint); font-size: 13px; width: 48px; flex: none; }
.c-field input, .c-field select { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; height: 40px; }
.c-field select { cursor: pointer; }
.c-field .links button { color: var(--muted); font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.c-field .links button:hover { background: var(--hover); color: var(--text); }
.suggest { position: absolute; left: 64px; right: 16px; top: 100%; z-index: 5; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
.suggest button { display: flex; width: 100%; gap: 10px; align-items: center; padding: 8px 12px; text-align: left; }
.suggest button:hover, .suggest button.on { background: var(--hover); }
.suggest small { color: var(--faint); }
.toolbar { display: flex; gap: 2px; padding: 6px 10px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.toolbar .icon-btn { width: 32px; height: 32px; font-weight: 700; font-size: 14px; }
.toolbar .sep { width: 1px; background: var(--line); margin: 6px 4px; }
.editor { flex: 1; overflow-y: auto; padding: 14px 16px; outline: none; line-height: 1.6; overflow-wrap: anywhere; font-size: 14.5px; }
.editor:empty::before { content: attr(data-ph); color: var(--faint); pointer-events: none; }
.editor blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.editor img { max-width: 100%; height: auto; }
.editor table { max-width: 100% !important; width: auto !important; }
.editor .ym-quote, .editor .ym-fwd { overflow-x: auto; }
.c-atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; }
.c-atts .att { padding: 5px 8px; max-width: 220px; }
.c-atts .att .ext { width: 26px; height: 26px; font-size: 9px; }
.c-foot { display: flex; align-items: center; gap: 6px; padding: 10px 12px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); }
.c-foot .spacer { flex: 1; }
.c-foot .hint { font-size: 12px; color: var(--faint); }

/* ---------- sheet (settings) & menus ---------- */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .32); z-index: 40; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; inset: 0; margin: auto; width: min(860px, calc(100vw - 32px)); height: min(680px, calc(100dvh - 32px));
  background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--shadow); z-index: 70; display: grid;
  grid-template-columns: 200px 1fr; overflow: hidden; animation: pop .2s var(--ease); border: 1px solid var(--line);
}
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
.sheet-nav { background: var(--bg); border-right: 1px solid var(--line); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.sheet-nav h3 { margin: 4px 10px 12px; font-size: 16px; }
.sheet-nav a { display: flex; gap: 10px; align-items: center; height: 34px; padding: 0 10px; border-radius: 8px; color: var(--text); text-decoration: none; cursor: pointer; }
.sheet-nav a:hover { background: var(--hover); }
.sheet-nav a.active { background: var(--active); color: var(--accent); font-weight: 600; }
.sheet-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 14px 14px 14px 26px; border-bottom: 1px solid var(--line); flex: none; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.sheet-head .icon-btn[data-tip]:hover::after { top: auto; bottom: calc(100% + 4px); left: auto; right: 0; transform: none; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: 20px 20px 40px 26px; }
.sheet-body > p.lead { margin: 0 0 20px; color: var(--muted); }
.card { border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 16px; }
.card h4 { margin: 0 0 12px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.table { width: 100%; border-collapse: collapse; }
.table td, .table th { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; color: var(--faint); font-weight: 500; }
.urow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.urow .grow { flex: 1; min-width: 0; }
.urow .grow b { display: block; font-weight: 550; }
.urow .grow span { display: block; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.copy-field { display: flex; gap: 6px; }
.copy-field .input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { height: 30px; padding: 0 12px; border-radius: 7px; color: var(--muted); font-weight: 500; }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.stats { display: flex; gap: 22px; flex-wrap: wrap; }
.stats div b { display: block; font-size: 18px; font-weight: 650; }
.stats div span { font-size: 12px; color: var(--faint); }
/* compose: From = [local part] @domain */
.from-field select { flex: 1; }
.from-custom { flex: 1; min-width: 0; display: flex; align-items: center; }
.from-custom input { flex: 0 1 auto; width: 6ch; min-width: 3ch; max-width: 60%; padding: 0 1px; font-weight: 500; font-family: inherit; }
.from-custom input:focus { background: var(--accent-soft); border-radius: 6px; }
.at-domain, .from-custom select { color: var(--muted); font-weight: 500; white-space: nowrap; }
.from-custom select { flex: 0 1 auto; height: 40px; }
.sm-btn { width: 30px; height: 30px; margin-left: auto; }
.addr-input { display: flex; align-items: stretch; }
.addr-input .input { border-radius: 9px 0 0 9px; }
.addr-domain { display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--field-line); border-left: 0; border-radius: 0 9px 9px 0; background: var(--bg); color: var(--muted); white-space: nowrap; font-weight: 500; }

/* settings: connection check */
.checks { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.checks li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--bg); }
.checks li > div { min-width: 0; display: grid; gap: 2px; }
.checks li b { font-weight: 600; font-size: 13px; }
.checks li span { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.checks li em { font-style: normal; font-size: 12.5px; color: var(--text); overflow-wrap: anywhere; }
.checks li em::before { content: "Fix: "; font-weight: 600; }
.checks .ck { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none; margin-top: 1px; background: var(--hover); color: var(--muted); }
.checks .ok .ck { background: var(--ok-soft); color: var(--ok); }
.checks .warn .ck { background: var(--warn-soft); color: var(--warn); }
.checks .fail .ck { background: var(--danger-soft); color: var(--danger); }
.checks .fail { box-shadow: inset 3px 0 0 var(--danger); }
.checks .warn { box-shadow: inset 3px 0 0 var(--warn); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; margin: 4px 0 12px; }
.kv span { color: var(--muted); }
.kv b { font-weight: 500; overflow-wrap: anywhere; }
.bad-text { color: var(--danger); }
.persist-card { border-color: var(--danger); background: var(--danger-soft); }
.persist-card h4 { display: flex; align-items: center; gap: 8px; color: var(--danger); }
.persist-card code, .sheet-body code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: var(--hover); padding: 1px 5px; border-radius: 5px; }
.mini-list { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); display: grid; gap: 3px; }
.mini-list b { color: var(--text); font-weight: 500; }

.mb-picks { display: grid; gap: 2px; max-height: 180px; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; }

.menu {
  position: fixed; z-index: 90; min-width: 200px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 5px; animation: pop .14s var(--ease);
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .date-row { display: grid; gap: 8px; padding: 8px 10px; }

.fab { display: none; }

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: calc(22px + var(--safe-b)); transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; background: var(--text); color: var(--panel); padding: 10px 14px 10px 16px;
  border-radius: 11px; font-size: 13.5px; box-shadow: var(--shadow); animation: rise .2s var(--ease); max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: #fff; }
.toast button { color: inherit; font-weight: 700; opacity: .85; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  :root { --list: 340px; }
  .shell { grid-template-columns: var(--list) minmax(0, 1fr); }
  .side {
    position: fixed; inset: 0 auto 0 0; width: 272px; z-index: 50; transform: translateX(-100%); transition: transform .25s var(--ease);
    box-shadow: var(--shadow);
  }
  body.drawer .side { transform: none; }
  .list-head .menu-btn { display: inline-grid; }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .shell { grid-template-columns: 1fr; }
  .list-pane { border-right: 0; }
  .reader {
    position: fixed; inset: 0; z-index: 30; transform: translateX(100%); transition: transform .28s var(--ease); visibility: hidden;
  }
  body.reading .reader { transform: none; visibility: visible; }
  .r-bar .back { display: inline-grid; }
  .r-scroll { padding: 16px 14px calc(96px + var(--safe-b)); }
  .r-subj { font-size: 19px; }
  .msg { border-radius: 12px; margin: 0 -4px 10px; }
  .msg-head { padding: 12px; }
  .msg-body { padding: 0 12px 12px; }
  .atts { padding: 0 12px 12px; }
  .reply-bar .btn { flex: 1; }
  .item-inner { padding: 13px 14px 13px 12px; }
  .fab {
    display: inline-flex; position: fixed; right: 18px; bottom: calc(20px + var(--safe-b)); z-index: 20; height: 54px; padding: 0 20px 0 18px;
    border-radius: 18px; background: var(--accent); color: var(--accent-ink); align-items: center; gap: 10px; font-weight: 600;
    box-shadow: 0 6px 22px rgb(50 98 243 / .35); transition: transform .2s var(--ease);
  }
  .fab:active { transform: scale(.96); }
  body.scrolled .fab span { display: none; }
  body.scrolled .fab { padding: 0 16px; }
  .compose, .compose.expanded { inset: 0; width: 100%; height: 100dvh; border-radius: 0; border: 0; transform: none; animation: rise .22s var(--ease); }
  .c-head { padding-top: calc(8px + var(--safe-t)); }
  .compose .expand-btn { display: none; }
  .sheet { inset: 0; width: 100%; height: 100dvh; border-radius: 0; grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; border: 0; }
  .sheet-nav { order: 2; flex-direction: row; overflow-x: auto; padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--line); scrollbar-width: none; }
  .sheet-nav h3 { display: none; }
  .sheet-main { display: contents; }
  .sheet-head { order: 1; padding-top: calc(8px + var(--safe-t)); }
  .sheet-body { order: 3; }
  .sheet-nav a { flex: none; }
  .sheet-body { padding: 16px 16px calc(40px + var(--safe-b)); scrollbar-gutter: auto; }
  .sheet-head { padding: 8px 8px 8px 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .icon-btn { width: 40px; height: 40px; }
  #toasts { bottom: calc(88px + var(--safe-b)); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print {
  .side, .list-pane, .r-bar, .reply-bar, .fab { display: none !important; }
  .shell { display: block; height: auto; }
  .r-scroll { overflow: visible; }
}
