:root{
  --bg:#f6f7f9; --surface:#ffffff; --surface-2:#f0f2f5;
  --text:#111418; --text-2:#5b6472; --text-3:#8b94a3;
  --line:#e3e7ec; --accent:#2563eb; --danger:#dc2626;
  --radius:14px; --tap:44px;
  --safe-t:env(safe-area-inset-top); --safe-b:env(safe-area-inset-bottom);
  --shadow:0 1px 2px rgba(16,24,40,.06),0 8px 24px rgba(16,24,40,.08);
  color-scheme:light;
}
@media (prefers-color-scheme:dark){
  :root{
    --bg:#0b0d10; --surface:#14181d; --surface-2:#1b2027;
    --text:#e9edf2; --text-2:#a3adba; --text-3:#7b8695;
    --line:#252b33; --accent:#5b91ff; --danger:#f87171;
    --shadow:0 1px 2px rgba(0,0,0,.4),0 8px 24px rgba(0,0,0,.45);
    color-scheme:dark;
  }
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{height:100%}
body{
  margin:0;background:var(--bg);color:var(--text);
  font:15px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",sans-serif;
  overscroll-behavior-y:none;
}
.hidden{display:none!important}
.muted{color:var(--text-2)}
button,input,textarea,select{font:inherit;color:inherit}
button{border:0;background:none;cursor:pointer}

/* ── sign in ─────────────────────────────── */
.lock{position:fixed;inset:0;display:grid;place-items:center;padding:24px;background:var(--bg)}
.lock-card{width:100%;max-width:340px;text-align:center}
.lock-mark{width:64px;height:64px;margin:0 auto 18px;border-radius:18px;background:var(--accent);
  color:#fff;display:grid;place-items:center;font-size:30px;box-shadow:var(--shadow)}
.lock h1{margin:0 0 4px;font-size:24px;letter-spacing:-.02em}
.lock p{margin:0 0 22px;font-size:14px}
#password{width:100%;height:var(--tap);padding:0 14px;margin-bottom:10px;border:1px solid var(--line);
  border-radius:12px;background:var(--surface)}
.primary{background:var(--accent);color:#fff;border-radius:12px;height:var(--tap);padding:0 18px;font-weight:600}
.primary:active{filter:brightness(.92)}
.block{width:100%;display:block}
.error{min-height:18px;margin:10px 0 0;color:var(--danger);font-size:13px}

/* ── top bar ─────────────────────────────── */
.topbar{position:sticky;top:0;z-index:30;padding:calc(var(--safe-t) + 8px) 12px 8px;
  background:color-mix(in srgb,var(--surface) 88%,transparent);
  backdrop-filter:saturate(180%) blur(14px);-webkit-backdrop-filter:saturate(180%) blur(14px);
  border-bottom:1px solid var(--line)}
.segmented{display:flex;gap:4px;padding:3px;background:var(--surface-2);border-radius:12px}
.segmented button{flex:1;min-height:38px;border-radius:9px;font-size:14px;font-weight:600;
  color:var(--text-2);display:flex;align-items:center;justify-content:center;gap:6px;
  transition:background .16s,color .16s;padding:0 8px;overflow:hidden}
.segmented button .name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.segmented button[aria-selected="true"]{background:var(--surface);color:var(--text);box-shadow:var(--shadow)}
.segmented button[aria-selected="true"] .dot{background:var(--acc,#2563eb)}
.dot{width:7px;height:7px;border-radius:50%;background:var(--text-3);flex:0 0 auto}
.badge{min-width:19px;height:19px;padding:0 5px;border-radius:10px;background:var(--accent);color:#fff;
  font-size:11px;font-weight:700;display:grid;place-items:center;flex:0 0 auto}

.topbar-row{display:flex;align-items:center;gap:8px;margin-top:8px}
.chip{height:34px;padding:0 10px 0 12px;border-radius:10px;background:var(--surface-2);
  display:flex;align-items:center;gap:4px;font-size:14px;font-weight:600;flex:0 0 auto}
.caret{width:14px;height:14px}
.search-wrap{position:relative;flex:1;min-width:0}
.search-icon{position:absolute;left:9px;top:50%;transform:translateY(-50%);width:16px;height:16px;color:var(--text-3)}
#search{width:100%;height:34px;padding:0 10px 0 30px;border:0;border-radius:10px;background:var(--surface-2)}
#search::-webkit-search-cancel-button{-webkit-appearance:none}
.icon-btn{width:34px;height:34px;border-radius:10px;display:grid;place-items:center;color:var(--text-2)}
.icon-btn svg{width:19px;height:19px}
.icon-btn:active{background:var(--surface-2)}
.icon-btn.danger{color:var(--danger)}
.icon-btn.on{color:var(--accent)}

/* ── folder sheet ────────────────────────── */
.sheet{position:absolute;top:calc(var(--safe-t) + 96px);left:12px;z-index:40;margin:0;padding:6px;
  list-style:none;background:var(--surface);border:1px solid var(--line);border-radius:14px;
  box-shadow:var(--shadow);min-width:180px}
.sheet li{padding:11px 14px;border-radius:10px;font-size:15px}
.sheet li[aria-selected="true"]{background:var(--surface-2);font-weight:600}

/* ── list ────────────────────────────────── */
.pane{padding-bottom:calc(var(--safe-b) + 90px)}
.pull{height:0;overflow:hidden;text-align:center;font-size:12px;color:var(--text-3);transition:height .2s}
.pull.armed{height:34px;line-height:34px}
.list{list-style:none;margin:0;padding:0}
.row{display:flex;gap:11px;padding:12px 14px 12px 20px;border-bottom:1px solid var(--line);
  background:var(--surface);align-items:flex-start;position:relative}
.row:active{background:var(--surface-2)}
.avatar{width:38px;height:38px;border-radius:50%;flex:0 0 auto;display:grid;place-items:center;
  color:#fff;font-weight:700;font-size:14px;letter-spacing:.02em}
.row-main{min-width:0;flex:1}
.row-top{display:flex;align-items:baseline;gap:8px}
.sender{font-weight:600;font-size:15px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1}
.when{font-size:12px;color:var(--text-3);flex:0 0 auto}
.subject{font-size:14px;margin-top:1px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.snippet{font-size:13px;color:var(--text-2);margin-top:2px;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.row.unread .sender,.row.unread .subject{font-weight:700}
.row.unread::before{content:"";position:absolute;left:8px;top:50%;transform:translateY(-50%);
  width:6px;height:6px;border-radius:50%;background:var(--accent)}
.clip{width:12px;height:12px;color:var(--text-3);vertical-align:-1px;margin-right:3px}
.star{color:#f59e0b}
.state{padding:38px 20px;text-align:center;color:var(--text-3);font-size:14px}
.more{display:block;width:calc(100% - 28px);margin:14px;height:var(--tap);border-radius:12px;
  background:var(--surface);border:1px solid var(--line);font-weight:600;color:var(--text-2)}
.skel{height:70px;border-bottom:1px solid var(--line);background:
  linear-gradient(90deg,var(--surface) 25%,var(--surface-2) 37%,var(--surface) 63%);
  background-size:400% 100%;animation:sh 1.2s ease infinite}
@keyframes sh{0%{background-position:100% 0}100%{background-position:-100% 0}}

/* ── fab ─────────────────────────────────── */
.fab{position:fixed;right:18px;bottom:calc(var(--safe-b) + 18px);z-index:35;
  width:56px;height:56px;border-radius:18px;background:var(--accent);color:#fff;
  display:grid;place-items:center;box-shadow:var(--shadow)}
.fab svg{width:24px;height:24px}
.fab:active{transform:scale(.94)}

/* ── overlays ────────────────────────────── */
.overlay{position:fixed;inset:0;z-index:50;background:var(--bg);display:flex;flex-direction:column;
  transform:translateX(100%);transition:transform .26s cubic-bezier(.32,.72,0,1);visibility:hidden}
.overlay.open{transform:none;visibility:visible}
.overlay-bar{display:flex;align-items:center;justify-content:space-between;gap:10px;
  padding:calc(var(--safe-t) + 10px) 12px 10px;border-bottom:1px solid var(--line);
  background:var(--surface);position:sticky;top:0}
.overlay-bar strong{font-size:15px}
.overlay-actions{display:flex;gap:2px}
.link-btn{color:var(--accent);font-size:15px;display:flex;align-items:center;gap:2px;min-height:34px}
.link-btn.small{font-size:13px;padding:2px 4px}
#cc-toggle{margin:8px 16px;align-self:flex-start}
.chev{width:18px;height:18px}
.send-btn{color:var(--accent);font-weight:700;font-size:15px;min-height:34px}
.overlay-body{flex:1;overflow-y:auto;-webkit-overflow-scrolling:touch;padding:16px 16px 30px;background:var(--surface)}

.msg-head{margin-bottom:14px}
.msg-subject{font-size:20px;font-weight:700;line-height:1.3;letter-spacing:-.01em;margin:0 0 10px}
.msg-meta{display:flex;gap:11px;align-items:center}
.msg-meta .avatar{width:40px;height:40px}
.msg-from{font-weight:600}
.msg-to{font-size:13px;color:var(--text-2)}
.msg-date{font-size:12px;color:var(--text-3);margin-left:auto;flex:0 0 auto;text-align:right}
.msg-body{border-top:1px solid var(--line);padding-top:14px;overflow-x:auto;word-break:break-word}
.msg-body img{max-width:100%;height:auto}
.msg-body table{max-width:100%}
.msg-body a{color:var(--accent)}
.msg-body pre,.plain{white-space:pre-wrap;font:inherit;margin:0}
.img-notice{display:flex;align-items:center;justify-content:space-between;gap:10px;
  background:var(--surface-2);border-radius:10px;padding:9px 12px;font-size:13px;margin-bottom:12px}
.att-list{list-style:none;margin:16px 0 0;padding:0;display:flex;flex-wrap:wrap;gap:8px}
.att-list a{display:flex;align-items:center;gap:7px;padding:9px 12px;border:1px solid var(--line);
  border-radius:11px;background:var(--surface);font-size:13px;text-decoration:none;color:var(--text);max-width:100%}
.att-list .fname{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.att-list .fsize{color:var(--text-3);font-size:12px;flex:0 0 auto}

.reader-foot{display:flex;gap:8px;padding:10px 12px calc(var(--safe-b) + 10px);
  border-top:1px solid var(--line);background:var(--surface)}
.reader-foot .primary{flex:1}
.ghost{height:var(--tap);padding:0 14px;border-radius:12px;background:var(--surface-2);
  color:var(--text);font-weight:600;font-size:14px}

/* ── composer ────────────────────────────── */
.compose{flex:1;display:flex;flex-direction:column;overflow-y:auto;padding-bottom:calc(var(--safe-b) + 16px)}
.field{display:flex;align-items:center;gap:10px;padding:11px 16px;border-bottom:1px solid var(--line);
  background:var(--surface)}
.field span{width:56px;flex:0 0 auto;color:var(--text-3);font-size:14px}
.field input,.field output{flex:1;min-width:0;border:0;background:none;outline:none;font-size:15px}
#c-body{flex:1;min-height:220px;border:0;background:var(--surface);outline:none;resize:none;
  padding:16px;font-size:16px;line-height:1.5}
.attach-row{padding:12px 16px;background:var(--surface);border-top:1px solid var(--line)}
.file-label{display:inline-flex;align-items:center;justify-content:center}
.file-list{list-style:none;margin:10px 0 0;padding:0;display:flex;flex-wrap:wrap;gap:6px}
.file-list li{font-size:12px;background:var(--surface-2);border-radius:8px;padding:5px 9px}

/* ── toast ───────────────────────────────── */
.toast{position:fixed;left:50%;bottom:calc(var(--safe-b) + 86px);transform:translate(-50%,14px);
  z-index:80;background:#111418;color:#fff;padding:11px 16px;border-radius:12px;font-size:14px;
  opacity:0;pointer-events:none;transition:opacity .2s,transform .2s;max-width:88vw;text-align:center}
@media (prefers-color-scheme:dark){.toast{background:#e9edf2;color:#0b0d10}}
.toast.show{opacity:1;transform:translate(-50%,0)}

.sig-hint{padding:6px 16px 10px;background:var(--surface);font-size:12px;color:var(--text-3)}
