:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6a64;
  --faint: #9c978f;
  --line: #e7e3dc;
  --soft: #f8f6f2;
  --hover: #f1eee8;
  --sel: #fdecea;
  --accent: #ea4335;
  --accent-ink: #c5281b;
  --bar: #1f1f1f;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.primary { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; }
.primary:hover { background: var(--accent-ink); }
.primary:disabled { opacity: .55; cursor: default; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px; color: var(--ink); }
.ghost:hover { background: var(--hover); }
.icon { background: none; border: 0; padding: 6px; border-radius: 8px; display: inline-flex; color: inherit; }
.icon:hover { background: rgba(127,127,127,.14); }
.link { background: none; border: 0; color: var(--muted); padding: 0 4px; font-size: 13px; }
.link:hover { color: var(--ink); text-decoration: underline; }
.mobile-only { display: none; }

/* ---------- login ---------- */
.loginpage { display: grid; place-items: center; padding: 16px; }
.loginbox { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 14px; }
.loginbox .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.loginbox .lead { margin: -6px 0 4px; color: var(--muted); }
.loginbox label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.loginbox input { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 15px; color: var(--ink); background: var(--soft); }
.loginbox input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: #fff; }
.loginbox .primary { padding: 11px; margin-top: 4px; }
.err { color: var(--accent-ink); min-height: 1.2em; margin: 0; font-size: 13px; }

/* ---------- top bar ---------- */
.top { height: 56px; background: var(--bar); color: #fff; display: flex; align-items: center; gap: 16px; padding-inline: 16px; position: sticky; top: 0; z-index: 20; }
.top .brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .02em; min-width: 172px; }
.search { flex: 1; max-width: 560px; display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.1); border-radius: 9px; padding: 0 12px; color: rgba(255,255,255,.7); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: #fff; padding: 9px 0; }
.search input::placeholder { color: rgba(255,255,255,.55); }
.search:focus-within { background: rgba(255,255,255,.16); }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; color: rgba(255,255,255,.8); }
.who .ghost { color: #fff; border-color: rgba(255,255,255,.25); padding: 5px 10px; }
.who .ghost:hover { background: rgba(255,255,255,.1); }

/* ---------- three panes ---------- */
.shell { display: grid; grid-template-columns: 220px minmax(300px, 400px) 1fr; height: calc(100vh - 56px); height: calc(100dvh - 56px); }
.side { padding: 16px 12px; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
.compose-btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 11px; border-radius: 10px; }
.navgroup { display: grid; gap: 2px; }
.navgroup .cap { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); padding: 0 10px 6px; }
.navgroup button { display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; background: none; border: 0; border-radius: 8px; padding: 8px 10px; color: var(--ink); }
.navgroup button:hover { background: var(--hover); }
.navgroup button.on { background: var(--sel); color: var(--accent-ink); font-weight: 600; }
.navgroup .bx { display: grid; line-height: 1.25; min-width: 0; }
.navgroup .bx small { color: var(--muted); font-weight: 400; font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; }
.n { font-size: 12px; font-weight: 700; color: var(--accent-ink); }
.note { margin: auto 0 0; font-size: 12px; color: var(--muted); padding: 0 10px; }

.list { background: var(--panel); border-left: 1px solid var(--line); border-right: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.listhead { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; position: sticky; top: 0; background: var(--panel); z-index: 2; border-bottom: 1px solid var(--line); }
.listhead h2 { margin: 0; font-size: 16px; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { padding: 11px 16px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; gap: 2px; position: relative; }
.row:hover { background: var(--soft); }
.row.on { background: var(--sel); }
.row.unread::before { content: ""; position: absolute; left: 6px; top: 17px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.row .r1 { display: flex; justify-content: space-between; gap: 10px; }
.row .from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .from, .row.unread .subj { font-weight: 700; }
.row .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.row .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.row .snip { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { font-size: 10.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); background: var(--hover); border-radius: 5px; padding: 1px 6px; flex: none; }
.clip { color: var(--muted); flex: none; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; margin: 0; }
.more { margin: 14px auto 20px; }

.reader { overflow-y: auto; background: var(--bg); }
.placeholder { height: 100%; display: grid; place-content: center; justify-items: center; color: var(--faint); gap: 6px; }
.placeholder p { margin: 0; }
.msg { max-width: 900px; margin: 0 auto; padding: 16px 24px 40px; }
.msgbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.acts { display: flex; gap: 6px; flex-wrap: wrap; }
.acts .ghost { background: var(--panel); font-size: 13px; }
.acts .ghost:hover { background: var(--hover); }
.msg h1 { font-size: 21px; line-height: 1.3; margin: 0 0 14px; word-break: break-word; }
.mhead { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--bar); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.mwho { flex: 1; min-width: 0; }
.mwho .addr { color: var(--muted); font-size: 13px; word-break: break-all; }
.mto { color: var(--muted); font-size: 13px; word-break: break-word; }
.mwhen { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.att { display: inline-flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; color: var(--ink); text-decoration: none; font-size: 13px; max-width: 100%; }
.att:hover { background: var(--hover); }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att small { color: var(--muted); flex: none; }
.bodywrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
#mBody { display: block; width: 100%; border: 0; min-height: 200px; background: #fff; }

/* ---------- compose ---------- */
.compose { position: fixed; right: 24px; bottom: 0; width: min(640px, calc(100vw - 48px)); height: min(640px, calc(100dvh - 72px)); background: var(--panel); border: 1px solid var(--line); border-bottom: 0; border-radius: 12px 12px 0 0; box-shadow: 0 10px 40px rgba(0,0,0,.18); display: flex; flex-direction: column; z-index: 40; }
.chead { display: flex; align-items: center; gap: 10px; background: var(--bar); color: #fff; padding: 8px 8px 8px 16px; border-radius: 12px 12px 0 0; }
.chead .cfrom { font-size: 12px; color: rgba(255,255,255,.65); margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cfield { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding: 0 14px; }
.cfield label { width: 56px; color: var(--muted); font-size: 13px; flex: none; }
.cfield input { flex: 1; min-width: 0; border: 0; outline: 0; padding: 10px 0; background: none; }
.tools { display: flex; gap: 2px; padding: 6px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tools button { background: none; border: 0; border-radius: 6px; padding: 4px 8px; font-size: 13px; color: var(--muted); }
.tools button:hover { background: var(--hover); color: var(--ink); }
.cbody { flex: 1; overflow-y: auto; padding: 14px 16px; outline: 0; line-height: 1.55; word-wrap: break-word; }
.cbody blockquote { margin: 0 0 0 .8ex; border-left: 2px solid var(--line); padding-left: 1ex; color: #555; }
.cbody .sig { color: var(--muted); }
.catts { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px; }
.catts:not(:empty) { padding-bottom: 8px; }
.catts .att button { background: none; border: 0; color: var(--muted); padding: 0 2px; }
.cfoot { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); }
.attach { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.cstate { color: var(--muted); font-size: 13px; flex: 1; min-width: 0; }
.cstate.bad { color: var(--accent-ink); }
.suggest { position: fixed; z-index: 60; list-style: none; margin: 0; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.14); max-height: 240px; overflow-y: auto; min-width: 260px; }
.suggest li { padding: 7px 10px; border-radius: 7px; cursor: pointer; display: grid; line-height: 1.3; }
.suggest li small { color: var(--muted); }
.suggest li.on, .suggest li:hover { background: var(--hover); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--bar); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 80; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px); }

/* ---------- narrower screens ---------- */
@media (max-width: 1100px) {
  .shell { grid-template-columns: 200px minmax(280px, 340px) 1fr; }
}
@media (max-width: 820px) {
  .mobile-only { display: inline-flex; }
  .top { gap: 8px; padding-inline: 8px 12px; }
  .top .brand { min-width: 0; }
  .top .brand span, .who span { display: none; }
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; top: 56px; bottom: 0; left: 0; width: 260px; background: var(--bg); z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  body.menu .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .scrim { position: fixed; inset: 56px 0 0; background: rgba(0,0,0,.25); z-index: 25; display: none; }
  body.menu .scrim { display: block; }
  .list { border: 0; }
  .reader { display: none; }
  body.reading .list { display: none; }
  body.reading .reader { display: block; }
  .msg { padding: 12px 16px 32px; }
  .compose { inset: 0; width: auto; height: auto; border-radius: 0; }
  .chead { border-radius: 0; }
}
