:root {
  --bg: #f4f6fa;
  --surface: #fff;
  --ink: #1b2333;
  --ink-2: #3a4458;
  --muted: #5b6577;
  --line: #e3e7ef;
  --line-2: #eef1f6;
  --hover: #e6ebf5;
  --accent: #2f4fc7;
  --accent-dark: #1e3a9e;
  --accent-soft: #d9e2ff;
  --accent-ink: #14215c;
  --selected: #e8eeff;
  --read-row: #f8f9fc;
  --star: #c46a00;
  --danger: #b42318;
  --radius: 16px;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shared ---------- */
.boot { height: 100vh; display: flex; align-items: center; justify-content: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--ink-2); flex: none; }
.icon-btn:hover:not(:disabled) { background: var(--hover); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 22px; border-radius: 22px; border: 1px solid #c9d0dd; background: var(--surface); font-weight: 500; color: var(--ink); }
.btn:hover:not(:disabled) { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn.wide { width: 100%; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { background: var(--hover); }
.logo { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.avatar { border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; flex: none; text-transform: uppercase; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 20px; padding: 36px 32px; box-shadow: 0 1px 3px rgba(20,30,60,.06), 0 8px 32px rgba(20,30,60,.06); display: flex; flex-direction: column; }
.login-card .brand { margin-bottom: 28px; }
.login-card h1 { margin: 0 0 6px; font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.login-card p.muted { margin: 0 0 24px; }
.login-card label { font-size: 13px; font-weight: 500; margin: 0 0 6px; color: var(--ink-2); }
.login-card input { height: 46px; border: 1px solid #c9d0dd; border-radius: 10px; padding: 0 14px; margin-bottom: 16px; font-size: 15px; background: #fff; }
.login-card input:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
.login-error { background: #fdecea; color: var(--danger); border-radius: 10px; padding: 10px 14px; margin: 0 0 16px; font-size: 13px; }
.setup-box { background: #fff7e6; color: #7a4b00; border-radius: 10px; padding: 12px 14px; margin: 0 0 16px; font-size: 13px; }
.setup-box ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- app shell ---------- */
.shell { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 16px 8px 20px; flex: none; }
.menu-btn { display: none; }
.topbar .brand { min-width: 204px; }
.search { flex: 1 1 320px; max-width: 720px; display: flex; align-items: center; gap: 10px; background: var(--hover); border-radius: 24px; padding: 0 6px 0 18px; height: 46px; color: var(--ink-2); }
.search:focus-within { background: var(--surface); box-shadow: 0 1px 4px rgba(20,30,60,.15); }
.search input { border: 0; background: transparent; outline: none; font-size: 15px; flex: 1; min-width: 0; height: 100%; }
.search input::-webkit-search-cancel-button { display: none; }
.search input:placeholder-shown + .clear-search { visibility: hidden; }
.account { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-email { font-size: 13px; color: var(--muted); }
.account-btn { border: 0; padding: 0; background: none; border-radius: 50%; }

.main { flex: 1; min-height: 0; display: flex; gap: 12px; padding: 0 16px 16px 0; }
.sidebar { width: 248px; flex: none; display: flex; flex-direction: column; overflow-y: auto; padding-bottom: 12px; }
.compose-btn { display: inline-flex; align-items: center; gap: 12px; align-self: flex-start; margin: 4px 0 14px 12px; height: 56px; padding: 0 24px 0 20px; border: 0; border-radius: 16px; background: var(--accent-soft); color: var(--accent-ink); font-size: 15px; font-weight: 600; box-shadow: 0 1px 2px rgba(20,30,60,.08); }
.compose-btn:hover { box-shadow: 0 2px 8px rgba(20,30,60,.18); }
.folders { list-style: none; margin: 0; padding: 0 12px 0 0; }
.folder { width: 100%; display: flex; align-items: center; gap: 14px; height: 36px; padding: 0 16px 0 24px; border: 0; border-radius: 0 18px 18px 0; background: transparent; text-align: left; color: var(--ink-2); }
.folder:hover { background: var(--hover); }
.folder.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.folder.has-unread { font-weight: 600; color: var(--ink); }
.folder.active.has-unread { color: var(--accent-ink); }
.fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-size: 12px; font-weight: 600; }

/* ---------- message list ---------- */
.list-pane { width: 420px; flex: none; background: var(--surface); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; overflow-y: auto; overflow-x: hidden; position: relative; }
.list-toolbar .icon-btn { width: 36px; height: 36px; }
.list-top { position: sticky; top: 0; z-index: 2; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; }
.list-head { display: flex; align-items: baseline; gap: 8px; padding: 16px 20px 2px; min-width: 0; }
.list-head h1 { margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; }
.list-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-toolbar { display: flex; align-items: center; gap: 2px; padding: 4px 8px 4px 12px; border-bottom: 1px solid var(--line); min-height: 50px; }
.check-all { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; }
.check-all:hover { background: var(--hover); }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.spacer { flex: 1; min-width: 4px; }
.check-all { flex: none; }
.range { font-size: 12px; color: var(--muted); padding: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: flex-start; border-bottom: 1px solid var(--line-2); background: var(--read-row); position: relative; }
.row.unread { background: var(--surface); }
.row:hover { box-shadow: inset 0 -1px 0 var(--line), 0 1px 4px rgba(20,30,60,.08); z-index: 1; }
.row.selected { background: var(--selected); }
.row.checked { background: #eef2ff; }
.row-check { padding: 22px 0 0 14px; }
.row-main { flex: 1; min-width: 0; display: flex; gap: 12px; align-items: flex-start; border: 0; background: transparent; text-align: left; padding: 13px 4px 13px 12px; color: var(--ink); }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-top { display: flex; align-items: baseline; gap: 6px; color: var(--muted); }
.row-from { flex: 1; min-width: 0; font-size: 14px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-date { font-size: 12px; white-space: nowrap; }
.row-top svg { align-self: center; }
.row-subject { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-snippet { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .row-from, .row.unread .row-subject, .row.unread .row-date { font-weight: 700; color: var(--ink); }
.star { border: 0; background: transparent; width: 40px; height: 40px; margin: 10px 6px 0 0; border-radius: 50%; color: #8a93a6; display: flex; align-items: center; justify-content: center; flex: none; }
.star:hover { background: var(--hover); }
.star.on { color: var(--star); }
.empty { padding: 56px 24px; text-align: center; color: var(--muted); display: flex; justify-content: center; }
.list-more { padding: 16px; display: flex; justify-content: center; }

/* ---------- reader ---------- */
.reader { flex: 1; min-width: 0; background: var(--surface); border-radius: var(--radius); overflow-y: auto; display: flex; flex-direction: column; }
.reader-empty { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--muted); padding: 40px; text-align: center; }
.reader-empty svg { color: #b6bdcb; }
.reader-toolbar { position: sticky; top: 0; z-index: 2; background: var(--surface); display: flex; align-items: center; gap: 2px; padding: 6px 16px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; border-radius: var(--radius) var(--radius) 0 0; }
.back-btn { display: none; }
.tbtn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2); font-size: 13px; }
.tbtn:hover { background: var(--hover); }
.tbtn.on svg { color: var(--star); fill: currentColor; }
.reader-body { padding: 20px 32px 32px; display: flex; flex-direction: column; gap: 18px; }
.reader-body h2 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; overflow-wrap: anywhere; }
.sender { display: flex; gap: 12px; align-items: flex-start; }
.sender-info { flex: 1; min-width: 0; }
.sender-line { font-size: 14px; overflow-wrap: anywhere; }
.sender-line strong { font-weight: 600; }
.sender-meta { font-size: 12px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.sender-date { font-size: 12px; color: var(--muted); white-space: nowrap; padding-top: 2px; }
.img-banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--bg); border-radius: 10px; padding: 8px 8px 8px 14px; font-size: 13px; color: var(--ink-2); }
.mail-frame { width: 100%; border: 0; display: block; height: 40px; }
.plain { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; color: #273043; }
.attachments { border-top: 1px solid var(--line-2); padding-top: 16px; }
.att-title { font-size: 13px; font-weight: 600; margin-bottom: 10px; color: var(--ink-2); }
.att-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.att { display: flex; flex-direction: column; width: 180px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; text-decoration: none; color: var(--ink); background: var(--surface); }
.att:hover { border-color: #b8c2d6; box-shadow: 0 1px 6px rgba(20,30,60,.1); color: var(--ink); }
.att img { width: 100%; height: 100px; object-fit: cover; background: var(--bg); display: block; }
.att-icon { height: 100px; display: flex; align-items: center; justify-content: center; background: var(--bg); color: #c2410c; }
.att-meta { display: flex; flex-direction: column; padding: 8px 10px; gap: 2px; }
.att-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: 12px; color: var(--muted); }
.reply-bar { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 4px; }

/* ---------- compose ---------- */
.compose { position: fixed; right: 24px; bottom: 0; z-index: 50; width: min(560px, calc(100vw - 48px)); height: min(620px, calc(100vh - 80px)); background: var(--surface); border-radius: 14px 14px 0 0; box-shadow: 0 8px 40px rgba(20,30,60,.28); display: flex; flex-direction: column; overflow: hidden; }
.compose.min { height: auto; }
.compose.min > :not(.compose-head) { display: none; }
.compose-head { display: flex; align-items: center; background: var(--ink); color: #fff; padding: 0 6px 0 16px; height: 44px; flex: none; cursor: pointer; }
.compose-head span { flex: 1; font-size: 14px; font-weight: 500; }
.compose-head .icon-btn { color: #fff; width: 36px; height: 36px; }
.compose-head .icon-btn:hover { background: rgba(255,255,255,.12); }
.cfield { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line-2); padding: 0 12px 0 16px; min-height: 42px; flex: none; }
.cfield label { font-size: 14px; color: var(--muted); min-width: 28px; }
.cfield input { flex: 1; border: 0; outline: none; font-size: 14px; min-width: 0; height: 40px; background: transparent; }
.cc-toggle { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.cc-toggle:hover { background: var(--hover); color: var(--ink); }
.editor { flex: 1; overflow-y: auto; padding: 14px 16px; outline: none; font-size: 14px; line-height: 1.5; min-height: 120px; overflow-wrap: anywhere; }
.editor blockquote { margin: 0 0 0 .8ex; border-left: 2px solid #ccd3e0; padding-left: 1ex; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; flex: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border-radius: 8px; padding: 4px 4px 4px 10px; font-size: 12px; max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .icon-btn { width: 26px; height: 26px; }
.chip label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; padding-right: 6px; }
.compose-foot { display: flex; align-items: center; gap: 4px; padding: 10px 12px 12px 16px; border-top: 1px solid var(--line-2); flex: none; flex-wrap: wrap; }
.fmt { display: flex; gap: 0; margin-left: 6px; }
.fmt .icon-btn { width: 34px; height: 34px; border-radius: 8px; font-weight: 700; font-size: 14px; }

/* ---------- menus, modal, toast ---------- */
.menu { position: fixed; z-index: 80; min-width: 200px; max-height: 60vh; overflow-y: auto; background: var(--surface); border-radius: 12px; box-shadow: 0 4px 24px rgba(20,30,60,.2); padding: 6px 0; }
.menu-item { width: 100%; display: flex; align-items: center; gap: 12px; border: 0; background: none; text-align: left; padding: 10px 16px; font-size: 14px; color: var(--ink); }
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); outline: none; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.menu-label { padding: 8px 16px 4px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.modal-backdrop { position: fixed; inset: 0; z-index: 90; background: rgba(20,28,45,.45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--surface); border-radius: 18px; padding: 24px; width: 100%; max-width: 460px; max-height: calc(100vh - 40px); overflow-y: auto; box-shadow: 0 12px 48px rgba(20,30,60,.3); }
.modal h2 { margin: 0 0 12px; font-size: 18px; font-weight: 600; }
.modal p { margin: 0 0 8px; color: var(--ink-2); line-height: 1.5; }
.modal label { display: block; font-size: 13px; font-weight: 500; margin: 14px 0 6px; color: var(--ink-2); }
.modal input, .modal textarea { width: 100%; border: 1px solid #c9d0dd; border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.modal textarea { min-height: 110px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: 13px; }
.shortcuts dt { font-weight: 600; }
.shortcuts dt kbd { display: inline-block; min-width: 24px; text-align: center; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font-family: inherit; }
.shortcuts dd { margin: 0; color: var(--ink-2); }
.toast { position: fixed; left: 24px; bottom: 24px; z-index: 100; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.2); transform: translateY(150%); opacity: 0; transition: transform .2s, opacity .2s; max-width: calc(100vw - 48px); pointer-events: none; }
.toast.show { transform: none; opacity: 1; }
.scrim, .fab { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .list-pane { width: 360px; }
  .sidebar { width: 220px; }
  .topbar .brand { min-width: 0; }
}
@media (max-width: 899px) {
  .menu-btn, .back-btn { display: inline-flex; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .topbar .brand, .user-email { display: none; }
  .search { flex: 1 1 0; min-width: 0; padding-left: 14px; }
  .account { margin-left: 0; }
  .fab { display: inline-flex; position: fixed; right: 16px; bottom: 20px; z-index: 30; align-items: center; gap: 10px; height: 56px; padding: 0 22px 0 18px; border: 0; border-radius: 18px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; font-size: 15px; box-shadow: 0 3px 12px rgba(20,30,60,.25); }
  body.reading .fab { display: none; }
  .rows { padding-bottom: 88px; }
  .main { padding: 0; }
  .sidebar { position: fixed; z-index: 60; top: 0; bottom: 0; left: 0; width: 272px; background: var(--bg); padding-top: 16px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 24px rgba(0,0,0,.15); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(20,28,45,.4); }
  .list-pane { width: auto; flex: 1; border-radius: 0; }
  .list-top { border-radius: 0; }
  .reader { display: none; }
  body.reading .reader { display: flex; position: fixed; inset: 0; z-index: 40; border-radius: 0; }
  .reader-toolbar { border-radius: 0; padding: 6px 8px; }
  .tbtn .tlabel { display: none; }
  .reader-body { padding: 16px 16px 32px; }
  .compose { right: 0; width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; }
  .toast { left: 12px; bottom: 12px; }
}
