:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --text: #1f1f1f;
  --text-2: #444746;
  --text-3: #5f6368;
  --line: #e3e6ea;
  --hover: #eef1f6;
  --nav-active: #d3e3fd;
  --nav-active-text: #041e49;
  --compose: #c2e7ff;
  --compose-hover: #b3dcf7;
  --search: #eaf1fb;
  --row-read: #f2f6fc;
  --row-sel: #c2dbff;
  --primary: #0b57d0;
  --primary-text: #ffffff;
  --gold: #cfac5d;
  --star: #f4b400;
  --danger: #b3261e;
  --shadow: 0 4px 8px 3px rgba(60,64,67,.15), 0 1px 3px rgba(60,64,67,.3);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --surface: #1b1e23; --text: #e3e3e3; --text-2: #c4c7c5; --text-3: #9aa0a6;
    --line: #2c3036; --hover: #262a30; --nav-active: #004a77; --nav-active-text: #c2e7ff;
    --compose: #004a77; --compose-hover: #005a91; --search: #23272d; --row-read: #16191d; --row-sel: #0b3a66;
    --primary: #a8c7fa; --primary-text: #062e6f; --shadow: 0 4px 12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 Roboto, "Segoe UI", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.ms { font-family: 'Material Symbols Outlined'; font-size: 20px; line-height: 1; font-weight: normal; font-style: normal; display: inline-block; -webkit-font-feature-settings: 'liga'; font-feature-settings: 'liga'; user-select: none; }
.ms.fill { font-variation-settings: 'FILL' 1; }
.muted { color: var(--text-3); }
.grow { flex: 1; }

.icon-btn { width: 40px; height: 40px; border: 0; background: none; border-radius: 50%; display: inline-grid; place-items: center; cursor: pointer; color: var(--text-2); flex: none; }
.icon-btn:hover { background: var(--hover); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm .ms { font-size: 18px; }
.btn { border: 0; border-radius: 999px; padding: 0 22px; height: 36px; font-weight: 500; cursor: pointer; background: var(--hover); }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.08); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.btn.outline { background: none; border: 1px solid var(--text-3); color: var(--text-2); display: inline-flex; align-items: center; gap: 8px; }
.btn.outline:hover { background: var(--hover); }
.link { border: 0; background: none; color: var(--text-2); cursor: pointer; padding: 0 4px; white-space: nowrap; }
.link:hover { text-decoration: underline; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-size: 21px; color: var(--text-2); white-space: nowrap; }
.brand b { font-weight: 500; color: var(--text); }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--gold); display: grid; place-items: center; color: #fff; }
.brand-mark .ms { font-size: 20px; }
.brand.big { font-size: 26px; justify-content: center; }
.brand.big .brand-mark { width: 40px; height: 40px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border-radius: 28px; padding: 40px 36px; width: min(400px, 100%); display: grid; gap: 14px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.login-card input { height: 52px; border-radius: 6px; border: 1px solid var(--text-3); background: none; padding: 0 16px; outline: none; }
.login-card input:focus { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.login-card .btn { height: 44px; }
.err { color: var(--danger); min-height: 1em; margin: 0; }

/* layout */
.app { display: grid; grid-template-columns: 256px 1fr; grid-template-rows: 64px 1fr; height: 100vh; height: 100dvh; }
.app.collapsed { grid-template-columns: 72px 1fr; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 12px; }
.top .brand { width: 200px; }
.search { flex: 1; max-width: 720px; height: 48px; display: flex; align-items: center; gap: 4px; background: var(--search); border-radius: 24px; padding: 0 4px; margin-left: 16px; }
.search:focus-within { background: var(--surface); box-shadow: 0 1px 1px rgba(65,69,73,.3), 0 1px 3px 1px rgba(65,69,73,.15); }
.search input { flex: 1; border: 0; background: none; outline: none; height: 100%; font-size: 16px; min-width: 0; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.demo-badge { font-size: 11px; font-weight: 700; letter-spacing: .06em; color: #8a5a00; background: #fde7b3; padding: 4px 8px; border-radius: 6px; }

/* sidebar */
.side { overflow-y: auto; padding: 8px 16px 16px 8px; }
.compose-btn { display: inline-flex; align-items: center; gap: 12px; height: 56px; padding: 0 24px 0 18px; border-radius: 16px; border: 0; background: var(--compose); color: var(--nav-active-text); font-weight: 500; cursor: pointer; margin: 0 0 16px; transition: box-shadow .15s; }
.compose-btn:hover { box-shadow: 0 1px 3px rgba(0,0,0,.2); background: var(--compose-hover); }
.compose-btn .ms { font-size: 24px; }
.nav-item { display: flex; align-items: center; gap: 16px; height: 32px; padding: 0 12px 0 18px; border-radius: 0 16px 16px 0; cursor: pointer; color: var(--text-2); white-space: nowrap; user-select: none; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--nav-active); color: var(--nav-active-text); font-weight: 700; }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-item .count { font-size: 12px; font-weight: 700; }
.nav-item .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; margin: 0 5px; }
.nav-item .warn { color: var(--danger); font-size: 18px; }
.side-label { margin: 18px 0 4px 18px; font-size: 14px; font-weight: 500; color: var(--text-2); }
.app.collapsed .side { padding: 8px 4px; }
.app.collapsed .compose-btn { padding: 0; width: 56px; justify-content: center; }
.app.collapsed .compose-btn span:last-child, .app.collapsed .nav-item .label, .app.collapsed .nav-item .count, .app.collapsed .side-label { display: none; }
.app.collapsed .nav-item { border-radius: 16px; padding: 0; justify-content: center; width: 56px; }
.scrim { display: none; }
.fab { display: none; }

/* main */
.main { margin: 0 16px 16px 0; background: var(--surface); border-radius: 16px; overflow: hidden; display: grid; grid-template-columns: minmax(380px, 40%) 1fr; min-height: 0; }
.list-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.toolbar { display: flex; align-items: center; gap: 2px; height: 48px; padding: 0 8px; flex: none; border-bottom: 1px solid var(--line); }
.bulk { display: inline-flex; }
.range { font-size: 12px; color: var(--text-3); padding: 0 8px; white-space: nowrap; }
.check { width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; border-radius: 50%; flex: none; }
.check:hover { background: var(--hover); }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check span { width: 18px; height: 18px; border: 2px solid var(--text-3); border-radius: 2px; display: grid; place-items: center; }
.check input:checked + span { background: var(--text-2); border-color: var(--text-2); }
.check input:checked + span::after { content: ''; width: 5px; height: 10px; border: solid var(--surface); border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); }
.filter-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; font-size: 13px; color: var(--text-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chip-x { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 10px; border-radius: 8px; background: var(--hover); }
.chip-x button { border: 0; background: none; cursor: pointer; display: grid; color: var(--text-3); }

.rows { overflow-y: auto; flex: 1; }
.row { display: grid; grid-template-columns: 40px 32px 1fr auto; grid-template-rows: auto auto auto; column-gap: 4px; padding: 8px 16px 10px 8px; border-bottom: 1px solid var(--line); cursor: pointer; background: var(--row-read); position: relative; }
.row.unread { background: var(--surface); }
.row:hover { box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0, 0 1px 2px 0 rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15); z-index: 1; }
.row.selected { background: var(--row-sel); }
.row.open { box-shadow: inset 4px 0 0 var(--primary); }
.row .check { grid-row: 1 / 3; align-self: start; margin-top: -10px; }
.row .star { grid-row: 1 / 3; align-self: start; margin-top: -10px; width: 32px; height: 40px; border: 0; background: none; cursor: pointer; color: var(--text-3); display: grid; place-items: center; }
.row .star.on { color: var(--star); }
.row .who { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--text-2); }
.row .who .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .who, .row.unread .subj, .row.unread .when { color: var(--text); font-weight: 700; }
.row .when { font-size: 12px; color: var(--text-3); white-space: nowrap; padding-left: 8px; display: flex; align-items: center; gap: 4px; }
.row .when .ms { font-size: 16px; }
.row .subj { grid-column: 3 / 5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.row .snip { grid-column: 3 / 5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-3); font-size: 13px; }
.acct-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 500; padding: 1px 7px 1px 6px; border-radius: 4px; white-space: nowrap; flex: none; color: var(--text-2); background: var(--hover); }
.acct-chip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.empty { padding: 48px 24px; text-align: center; color: var(--text-3); }
.empty .ms { font-size: 48px; display: block; margin: 0 auto 8px; opacity: .5; }

/* reading */
.read-pane { overflow-y: auto; min-width: 0; }
.empty-read { height: 100%; display: grid; place-content: center; text-align: center; color: var(--text-3); }
.empty-read .ms { font-size: 64px; opacity: .35; }
.read-bar { position: sticky; top: 0; background: var(--surface); display: flex; align-items: center; gap: 2px; height: 48px; padding: 0 8px; border-bottom: 1px solid var(--line); z-index: 2; }
.read-bar .back { display: none; }
.msg { padding: 20px 24px 32px 24px; }
.msg h1 { font-size: 22px; font-weight: 400; margin: 0 0 16px 56px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.msg-head { display: grid; grid-template-columns: 40px 1fr auto; gap: 16px; align-items: start; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 500; font-size: 18px; }
.msg-from b { font-weight: 700; }
.msg-from .addr { color: var(--text-3); font-size: 12px; }
.msg-to { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.msg-meta { display: flex; align-items: center; gap: 2px; color: var(--text-3); font-size: 12px; white-space: nowrap; }
.msg-body { margin: 12px 0 0 56px; }
.msg-body iframe { width: 100%; border: 0; display: block; min-height: 60px; background: #fff; border-radius: 4px; }
.msg-body pre { white-space: pre-wrap; font: inherit; margin: 0; }
.atts { margin: 20px 0 0 56px; display: flex; flex-wrap: wrap; gap: 12px; }
.att { width: 180px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; }
.att:hover { background: var(--hover); }
.att .ms { color: var(--danger); font-size: 28px; }
.att .n { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .s { font-size: 11px; color: var(--text-3); }
.reply-row { margin: 28px 0 0 56px; display: flex; gap: 12px; flex-wrap: wrap; }

/* compose */
#composeHost { position: fixed; right: 16px; bottom: 0; display: flex; gap: 16px; align-items: flex-end; z-index: 20; pointer-events: none; }
.compose { pointer-events: auto; width: 540px; height: min(560px, calc(100dvh - 80px)); background: var(--surface); border-radius: 12px 12px 0 0; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.compose.min { height: 40px; width: 280px; }
.compose.min .compose-body, .compose.min .compose-foot { display: none; }
.compose.max { position: fixed; inset: 5vh 8vw; width: auto; height: auto; border-radius: 12px; }
.compose-head { height: 40px; display: flex; align-items: center; padding: 0 8px 0 16px; background: var(--hover); cursor: pointer; flex: none; }
.compose-title { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-body { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 16px; }
.field { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); min-height: 40px; color: var(--text-3); }
.field input, .field select { flex: 1; border: 0; outline: none; background: none; height: 38px; color: var(--text); min-width: 0; }
.field select { cursor: pointer; }
.editor { flex: 1; overflow-y: auto; outline: none; padding: 12px 0; line-height: 1.5; min-height: 80px; }
.editor blockquote { margin: 0 0 0 .8ex; border-left: 1px solid #ccc; padding-left: 1ex; color: var(--text-3); }
.files { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 8px; }
.files span { background: var(--hover); border-radius: 6px; padding: 4px 6px 4px 10px; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.files button { border: 0; background: none; cursor: pointer; color: var(--text-3); display: grid; }
.compose-foot { display: flex; align-items: center; gap: 2px; padding: 10px 12px 12px 16px; flex: none; }
.compose-foot .send { margin-right: 8px; }

.toast { position: fixed; left: 24px; bottom: 24px; background: #303030; color: #f2f2f2; padding: 14px 20px; border-radius: 6px; box-shadow: var(--shadow); z-index: 40; display: flex; gap: 16px; align-items: center; }
.toast button { background: none; border: 0; color: #a8c7fa; font-weight: 500; cursor: pointer; }

.status-list { padding: 8px 0; }
.status-list div { display: flex; gap: 8px; align-items: center; padding: 4px 0; }

/* medium: list only, reading replaces list */
@media (max-width: 1100px) {
  .main { grid-template-columns: minmax(0, 1fr); }
  .main .read-pane { display: none; }
  .main.reading .list-pane { display: none; }
  .main.reading .read-pane { display: block; }
  .read-bar .back { display: inline-grid; }
}
/* phone */
@media (max-width: 760px) {
  .app, .app.collapsed { grid-template-columns: minmax(0, 1fr); grid-template-rows: 56px 1fr; }
  .top { padding: 0 4px; gap: 2px; }
  .top .brand { display: none; }
  .search { margin-left: 0; height: 44px; }
  .top-right #statusBtn { display: none; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; background: var(--surface); z-index: 30; transform: translateX(-100%); transition: transform .2s; padding-top: 16px; }
  .app.drawer .side { transform: none; }
  .app.drawer .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .app.collapsed .compose-btn span:last-child, .app.collapsed .nav-item .label, .app.collapsed .nav-item .count, .app.collapsed .side-label { display: revert; }
  .main { margin: 0; border-radius: 0; }
  .fab { display: inline-flex; position: fixed; right: 16px; bottom: 16px; z-index: 15; align-items: center; gap: 12px; height: 56px; padding: 0 20px 0 16px; border-radius: 16px; border: 0; background: var(--compose); color: var(--nav-active-text); font-weight: 500; box-shadow: var(--shadow); cursor: pointer; }
  .fab .ms { font-size: 24px; }
  .msg { padding: 16px; }
  .msg h1, .msg-body, .atts, .reply-row { margin-left: 0; }
  .msg-head { grid-template-columns: 40px 1fr; }
  .msg-meta { grid-column: 2; }
  #composeHost { left: 0; right: 0; }
  .compose, .compose.max { position: fixed; inset: 0; width: auto; height: auto; border-radius: 0; }
  .compose.min { inset: auto 0 0 0; height: 40px; }
}
