:root {
  --bg: #f5f6fa; --panel: #ffffff; --panel-2: #f9fafc; --line: #e6e8ef; --line-2: #eef0f5;
  --text: #171a23; --muted: #667085; --faint: #98a2b3;
  --accent: #4f46e5; --accent-2: #0ea5e9; --accent-soft: #eef0ff; --accent-text: #3730a3;
  --danger: #dc2626; --ok: #059669; --star: #f59e0b;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 8px 24px rgba(16,24,40,.06);
  --shadow-lg: 0 20px 50px rgba(16,24,40,.18);
  --radius: 12px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
[data-theme="dark"] {
  --bg: #0c0f17; --panel: #131722; --panel-2: #171c29; --line: #232a3a; --line-2: #1c2231;
  --text: #e6e9f2; --muted: #9aa3b8; --faint: #6b7489;
  --accent: #818cf8; --accent-2: #38bdf8; --accent-soft: #1e2140; --accent-text: #c7d2fe;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  --shadow-lg: 0 20px 50px rgba(0,0,0,.5);
}
* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body { font: 14px/1.45 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }
.boot { height: 100%; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { position: relative; overflow: hidden; color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(1200px 600px at -10% -20%, #6366f1 0%, transparent 60%), radial-gradient(900px 600px at 110% 120%, #0ea5e9 0%, transparent 55%), #111536; }
.login-art h1 { font-size: 40px; line-height: 1.1; letter-spacing: -.02em; margin: 0 0 14px; max-width: 520px; }
.login-art p { color: #c7cbe8; max-width: 460px; font-size: 16px; margin: 0; }
.login-art .feat { display: grid; gap: 14px; margin-top: 36px; }
.login-art .feat div { display: flex; gap: 12px; align-items: center; color: #dfe3ff; }
.login-art .feat svg { width: 20px; height: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.brand small { display: block; font-weight: 500; opacity: .7; font-size: 12px; }
.login-side { display: grid; place-items: center; padding: 32px; background: var(--panel); }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 26px; margin: 0 0 6px; letter-spacing: -.02em; }
.login-card .sub { color: var(--muted); margin: 0 0 28px; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input { width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.input.bad { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 15%, transparent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-weight: 600; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, var(--accent-2))); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.block { width: 100%; height: 44px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn.icon { width: 36px; padding: 0; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.form-err { color: var(--danger); min-height: 20px; font-size: 13px; margin: 4px 0 12px; }
.login-foot { margin-top: 28px; color: var(--faint); font-size: 12px; }

/* ---------- app shell ---------- */
.app { height: 100%; display: grid; grid-template-columns: 252px minmax(320px, 400px) 1fr; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 18px 16px 12px; }
.side .compose { margin: 6px 12px 12px; height: 42px; }
.nav { overflow: auto; padding: 0 8px 12px; flex: 1; }
.nav h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin: 18px 10px 6px; display: flex; justify-content: space-between; align-items: center; }
.nav h4 button { border: 0; background: none; color: var(--accent); font-size: 11px; text-transform: none; letter-spacing: 0; padding: 0; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 9px; text-align: left; color: var(--text); }
.nav-item:hover { background: var(--line-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-item .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .cnt { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-item.active .cnt, .nav-item .cnt.unread { color: var(--accent-text); font-weight: 700; }
.nav-item .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.addr-filter { padding: 0 6px 8px; }
.addr-filter .input { height: 34px; font-size: 13px; }
.side-foot { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; align-items: center; gap: 8px; }
.me { flex: 1; min-width: 0; }
.me b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me span { font-size: 12px; color: var(--muted); }

.list-pane { background: var(--panel-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.list-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
.list-title { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.list-title h2 { font-size: 18px; margin: 0; letter-spacing: -.01em; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 11px; color: var(--faint); }
.search .input { padding-left: 36px; height: 40px; background: var(--panel-2); }
.chips { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; height: 28px; padding: 0 11px; font-size: 12px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.chip .x { border: 0; background: none; padding: 0; color: inherit; line-height: 1; font-size: 15px; }
.list { overflow: auto; flex: 1; }
.row { display: grid; grid-template-columns: 38px 1fr; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); cursor: pointer; position: relative; background: var(--panel-2); }
.row:hover { background: var(--panel); }
.row.sel { background: var(--accent-soft); }
.row.unread::before { content: ""; position: absolute; left: 4px; top: 22px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.row .top { display: flex; gap: 8px; align-items: baseline; }
.row .who { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .who, .row.unread .subj { font-weight: 700; }
.row .when { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.row .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.row .meta { display: flex; gap: 6px; align-items: center; margin-top: 5px; min-width: 0; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; background: var(--line-2); color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag.to { background: color-mix(in srgb, var(--accent-2) 14%, transparent); color: color-mix(in srgb, var(--accent-2) 70%, var(--text)); }
.row .meta svg { width: 14px; height: 14px; color: var(--faint); }
.row .star { color: var(--star); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; flex: none; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--faint); margin-bottom: 8px; }
.more { padding: 12px; text-align: center; }

.read-pane { background: var(--panel); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; gap: 4px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar .sp { flex: 1; }
.toolbar select { height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); padding: 0 8px; }
.reader { overflow: auto; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.msg-head { padding: 22px 26px 16px; }
.msg-head h1 { font-size: 21px; line-height: 1.3; margin: 0 0 16px; letter-spacing: -.01em; word-break: break-word; }
.sender { display: flex; gap: 12px; align-items: flex-start; }
.sender .who { flex: 1; min-width: 0; }
.sender .who b { font-size: 15px; }
.sender .who .addr { color: var(--muted); font-size: 13px; word-break: break-all; }
.sender .who .lines { color: var(--muted); font-size: 13px; margin-top: 4px; word-break: break-word; }
.sender .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.delivered { margin-top: 12px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.banner { margin: 0 26px 12px; padding: 9px 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; display: flex; gap: 10px; align-items: center; }
.banner .sp { flex: 1; }
.body-text { padding: 4px 26px 26px; white-space: pre-wrap; word-break: break-word; font-size: 14.5px; line-height: 1.6; }
.body-frame { flex: 1; min-height: 420px; margin: 0 18px 18px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.body-frame iframe { width: 100%; height: 100%; min-height: 420px; border: 0; display: block; border-radius: 10px; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 26px 18px; }
.att { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--text); max-width: 280px; background: var(--panel-2); }
.att:hover { border-color: var(--accent); }
.att b { font-size: 13px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att span { font-size: 12px; color: var(--muted); }
.att > div { min-width: 0; }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px; }
.placeholder svg { width: 56px; height: 56px; color: var(--line); margin-bottom: 10px; }
.back { display: none; }

/* ---------- compose ---------- */
.compose-overlay { position: fixed; inset: 0; background: rgba(10,12,20,.35); display: flex; align-items: flex-end; justify-content: flex-end; padding: 24px; z-index: 30; }
.compose-box { width: 640px; max-width: 100%; max-height: calc(100vh - 48px); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden; }
.compose-top { display: flex; align-items: center; padding: 12px 14px 12px 18px; border-bottom: 1px solid var(--line); }
.compose-top h3 { margin: 0; font-size: 15px; flex: 1; }
.compose-body { overflow: auto; padding: 6px 18px 12px; }
.c-row { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 8px; border-bottom: 1px solid var(--line-2); min-height: 44px; }
.c-row label { color: var(--muted); font-size: 13px; font-weight: 600; }
.c-row input { border: 0; outline: none; background: transparent; height: 42px; width: 100%; }
.c-row .toggles button { border: 0; background: none; color: var(--muted); font-weight: 600; font-size: 12px; padding: 4px 6px; border-radius: 6px; }
.c-row .toggles button:hover { background: var(--line-2); }
.from-wrap { display: flex; align-items: center; gap: 6px; min-width: 0; }
.from-wrap input.addr { flex: 1.4; }
.from-wrap input.nm { flex: 1; border-left: 1px solid var(--line-2); padding-left: 10px; }
.from-hint { font-size: 12px; color: var(--muted); padding: 6px 0 2px 72px; }
.from-hint.bad { color: var(--danger); }
.from-hint.good { color: var(--ok); }
.recent { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 0 8px 72px; }
.recent button { border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; font-size: 12px; padding: 3px 10px; color: var(--muted); }
.recent button:hover { color: var(--accent-text); border-color: var(--accent); }
.compose-body textarea { width: 100%; min-height: 260px; border: 0; outline: none; resize: vertical; background: transparent; padding: 14px 0; line-height: 1.55; font-size: 14.5px; }
.files { display: flex; flex-wrap: wrap; gap: 6px; }
.file { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 12px; background: var(--panel-2); max-width: 260px; }
.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file button { border: 0; background: none; color: var(--muted); padding: 0 2px; font-size: 15px; line-height: 1; }
.compose-foot { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.compose-foot .sp { flex: 1; }
.kbd { font-size: 11px; color: var(--faint); }

#toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; animation: up .2s ease-out; }
.toast.err { background: var(--danger); }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .app { grid-template-columns: 220px minmax(300px, 360px) 1fr; }
}
@media (max-width: 860px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .app.nav-open .side { transform: none; }
  .app.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .read-pane { display: none; }
  .app.reading .list-pane { display: none; }
  .app.reading .read-pane { display: flex; height: 100%; }
  .back, .menu-btn { display: inline-flex; }
  .msg-head { padding: 18px 16px 12px; }
  .body-text, .atts { padding-left: 16px; padding-right: 16px; }
  .body-frame { margin: 0 8px 8px; }
  .compose-overlay { padding: 0; }
  .compose-box { width: 100%; height: 100%; max-height: none; border-radius: 0; }
  .c-row { grid-template-columns: 52px 1fr auto; }
  .from-wrap { flex-wrap: wrap; }
  .from-wrap input.nm { border-left: 0; padding-left: 0; border-top: 1px solid var(--line-2); }
  .from-hint, .recent { padding-left: 0; }
}
@media (min-width: 861px) { .menu-btn { display: none; } }
