:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --border: #e3e6ec;
  --text: #1c2030;
  --muted: #6b7385;
  --primary: #2f6df6;
  --primary-ink: #ffffff;
  --primary-soft: #e8efff;
  --danger: #d6384b;
  --danger-soft: #fdeaec;
  --warn: #b7791f;
  --warn-soft: #fff6e0;
  --ok: #1f8a4c;
  --hover: #eef0f5;
  --shadow: 0 8px 30px rgba(20, 28, 55, 0.14);
  --radius: 10px;
  --topbar-h: 56px;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #0f1218;
  --panel: #171b24;
  --panel-2: #1d222d;
  --border: #2a3040;
  --text: #e6e9f2;
  --muted: #98a1b5;
  --primary: #5b8cff;
  --primary-ink: #0b1020;
  --primary-soft: #1f2a48;
  --danger: #ff6b7d;
  --danger-soft: #3a1b22;
  --warn: #f0b84d;
  --warn-soft: #3a2e14;
  --ok: #4cc27f;
  --hover: #222838;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  color: var(--text);
  background: var(--bg);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 通用元件 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text); line-height: 1.2; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); background: var(--primary); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; border: 0;
  background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; border-radius: 7px; }
svg.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.ico.sm { width: 15px; height: 15px; }

input[type='text'], input[type='email'], input[type='password'], input[type='url'], input[type='number'], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
textarea { resize: vertical; min-height: 70px; }
input[type='text'], input[type='email'], input[type='password'], input[type='url'], input[type='number'], select { min-height: 38px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
/* 勾選框欄位：框在左、文字在右（label.field 的 display:block 會蓋掉 .row，所以要明確指定） */
label.field.row { display: flex; align-items: center; gap: 8px; cursor: pointer; }
label.field.row > span { margin: 0; font-size: 14px; color: var(--text); }
label.field.row > input[type='checkbox'] { width: 16px; height: 16px; flex: none; margin: 0; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; line-height: 18px;
  background: var(--primary-soft); color: var(--primary); white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis;
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 700;
  display: inline-grid; place-items: center; overflow: hidden; flex: none; text-transform: uppercase;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 72px; height: 72px; font-size: 26px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.notice { padding: 9px 12px; border-radius: 8px; font-size: 13px; background: var(--warn-soft); color: var(--warn); }
.notice.danger { background: var(--danger-soft); color: var(--danger); }
.notice.info { background: var(--primary-soft); color: var(--primary); }

/* ---------- 版面 ---------- */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 14px; background: var(--panel);
  border-bottom: 1px solid var(--border); position: relative; z-index: 30; flex: none;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 18px; letter-spacing: .2px; min-width: 150px; }
.brand .mark { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--primary), #8b5cf6); display: grid; place-items: center; color: #fff; }
.brand .mark svg { width: 17px; height: 17px; }
.search-wrap { flex: 1; max-width: 640px; margin: 0 auto; position: relative; }
.search-box { display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 38px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); }
.search-box:focus-within { border-color: var(--primary); background: var(--panel); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.search-box input { border: 0; background: transparent; padding: 0; box-shadow: none !important; height: 100%; outline: none; }
.search-box svg { color: var(--muted); }
.search-pop {
  position: absolute; top: 44px; left: 0; right: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); max-height: min(70vh, 560px); overflow: auto; padding: 6px;
}
.search-sec-title { font-size: 11.5px; font-weight: 700; color: var(--muted); padding: 8px 10px 4px; display: flex; gap: 6px; align-items: center; letter-spacing: .3px; }
.search-divider { height: 1px; background: var(--border); margin: 6px 4px; }
.search-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: transparent; border-radius: 8px; }
.search-item:hover, .search-item.active { background: var(--hover); }
.search-item .s-subj { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-item .s-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-empty { padding: 8px 12px 10px; color: var(--muted); font-size: 12.5px; }
mark { background: color-mix(in srgb, #ffd54a 60%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

.top-actions { display: flex; align-items: center; gap: 4px; min-width: 150px; justify-content: flex-end; }
.pop {
  position: absolute; right: 0; top: 44px; width: 290px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 8px; z-index: 40;
}
.pop .pop-title { font-size: 11.5px; font-weight: 700; color: var(--muted); padding: 8px 10px 4px; }
.pop .menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: transparent; border-radius: 8px; text-align: left; }
.pop .menu-item:hover { background: var(--hover); }
.pop hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.seg { display: flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 3px; margin: 2px 6px 6px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 6px; border-radius: 7px; display: flex; gap: 6px; justify-content: center; align-items: center; }
.seg button.on { background: var(--panel); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); font-weight: 600; }
.acct-head { display: flex; gap: 10px; align-items: center; padding: 8px 10px; }
.acct-head .who { min-width: 0; }
.acct-head .who b, .acct-head .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-height: 0; display: grid; grid-template-columns: 224px 360px minmax(0, 1fr); }
body.has-bg .sidebar, body.has-bg .listpane, body.has-bg .preview, body.has-bg .topbar { background: color-mix(in srgb, var(--panel) 82%, transparent); backdrop-filter: blur(10px); }

.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 12px 10px; overflow: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: transparent; border-radius: 8px;
  text-align: left; color: var(--text);
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { font-size: 11.5px; color: var(--muted); }
.nav-item.active .count { color: var(--primary); }
.nav-item .count.unread { font-weight: 700; }
.nav-sep { font-size: 11.5px; font-weight: 700; color: var(--muted); padding: 14px 10px 4px; display: flex; align-items: center; }
.nav-sep .spacer { flex: 1; }

.listpane { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.list-head h2 { margin: 0; font-size: 16px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-banner { margin: 10px 12px; }
.list-banner:empty { display: none; }
.list-scroll { flex: 1; overflow: auto; }
.mail-item { display: flex; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; position: relative; }
.mail-item:hover { background: var(--hover); }
.mail-item.active { background: var(--primary-soft); }
.mail-item .body { min-width: 0; flex: 1; }
.mail-item .l1 { display: flex; gap: 8px; align-items: baseline; }
.mail-item .from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item .time { font-size: 11.5px; color: var(--muted); flex: none; }
.mail-item .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item .snip { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item .l4 { display: flex; gap: 5px; margin-top: 4px; flex-wrap: wrap; align-items: center; }
.mail-item.unread .from, .mail-item.unread .subj { font-weight: 700; }
.mail-item.unread::before { content: ''; position: absolute; left: 4px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--primary); }
.list-empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.list-more { padding: 12px; text-align: center; }
.purge-tag { font-size: 11.5px; color: var(--warn); }

.preview { background: var(--panel); min-width: 0; display: flex; flex-direction: column; min-height: 0; position: relative; }
.preview-empty { margin: auto; text-align: center; color: var(--muted); padding: 20px; }
.preview-empty svg { width: 54px; height: 54px; stroke-width: 1.2; opacity: .6; }
.mail-head { padding: 16px 20px 12px; border-bottom: 1px solid var(--border); }
.mail-head .subject-row { display: flex; gap: 12px; align-items: flex-start; }
.mail-head h1 { margin: 0; font-size: 20px; line-height: 1.35; flex: 1; overflow-wrap: anywhere; }
.mail-head .actions { display: flex; gap: 6px; flex: none; align-items: center; }
.btn.ai { background: linear-gradient(135deg, #7c5cff, #2f6df6); color: #fff; border: 0; font-weight: 600; }
.btn.ai:hover { filter: brightness(1.08); background: linear-gradient(135deg, #7c5cff, #2f6df6); }
.sender-row { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.sender-row .who { min-width: 0; flex: 1; }
.sender-row .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-row .who span { display: block; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-row .date { font-size: 12.5px; color: var(--muted); text-align: right; flex: none; }
.label-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.label-row .chip { padding-right: 4px; }
.label-row .chip button { border: 0; background: transparent; color: inherit; padding: 0 3px; line-height: 1; opacity: .7; }
.label-row .chip button:hover { opacity: 1; }
.mail-banner { margin: 10px 20px 0; }
.mail-body { flex: 1; min-height: 120px; padding: 12px 20px 16px; display: flex; }
.mail-body iframe { width: 100%; border: 1px solid var(--border); border-radius: 8px; background: #fff; flex: 1; }
.attach { padding: 12px 20px 16px; border-top: 1px solid var(--border); }
.attach h4 { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.attach-list { display: flex; flex-wrap: wrap; gap: 8px; }
.attach-item { display: inline-flex; align-items: center; gap: 8px; padding: 7px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); color: var(--text); text-decoration: none; max-width: 100%; }
.attach-item:hover { background: var(--hover); }
.attach-item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.attach-item .sz { color: var(--muted); font-size: 12px; }
.attach .hint { margin-top: 8px; }
.menu-pop { position: absolute; z-index: 50; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; min-width: 190px; max-height: 280px; overflow: auto; }
.menu-pop label { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.menu-pop label:hover { background: var(--hover); }

/* ---------- AI 聊天 ---------- */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.chat-head .t { flex: 1; min-width: 0; }
.chat-head .t b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .t span { font-size: 12px; color: var(--muted); }
.chat-scroll { flex: 1; overflow: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.chat-empty { margin: auto; text-align: center; font-size: 20px; font-weight: 700; color: var(--text); padding: 20px; }
.chat-empty small { display: block; font-size: 12.5px; font-weight: 400; color: var(--muted); margin-top: 8px; }
.bubble { max-width: min(680px, 88%); padding: 10px 14px; border-radius: 14px; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--primary); color: var(--primary-ink); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.bubble.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.assistant p { margin: 0 0 6px; }
.bubble.assistant p:last-child { margin-bottom: 0; }
.bubble.assistant ul, .bubble.assistant ol { margin: 4px 0 6px; padding-left: 20px; }
.bubble.err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.chat-foot { border-top: 1px solid var(--border); padding: 10px 14px 12px; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.quick button { border: 1px solid var(--border); background: var(--panel-2); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.quick button:hover:not(:disabled) { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.quick button:disabled { opacity: .5; cursor: not-allowed; }
.chat-input { display: flex; gap: 8px; }
.chat-input textarea { min-height: 42px; max-height: 120px; resize: none; }
.chat-note { font-size: 11.5px; color: var(--muted); margin-top: 6px; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8, 12, 24, .5); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: min(920px, 100%); max-height: min(88vh, 760px); display: flex; flex-direction: column; border: 1px solid var(--border); }
.modal.sm { width: min(460px, 100%); }
.modal.fixed { height: min(88vh, 760px); } /* 有分頁的設定視窗固定大小，切換分頁不會跳動 */
.modal-head, .tabs, .modal-foot { flex: none; }
.modal-body { min-height: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.modal-head { display: flex; align-items: center; padding: 14px 16px 6px 20px; gap: 8px; }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.tabs { display: flex; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.modal-body { padding: 18px 20px; overflow: auto; flex: 1; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid var(--border); }
.section-title { font-size: 13px; font-weight: 700; margin: 18px 0 10px; color: var(--muted); }
.section-title:first-child { margin-top: 0; }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; }
.list-rows > div { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.cond-wrap { margin-bottom: 10px; }
.cond-wrap .cond-row { margin-bottom: 4px; }
.sem-extra { margin: 0 0 6px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 10px; background: var(--panel-2); }
.sem-extra .row { gap: 10px; }
.sem-extra input[type='range'] { flex: 1; min-width: 120px; accent-color: var(--primary); }
.sem-preview { margin-top: 8px; display: grid; gap: 2px; }
.sem-item { display: flex; gap: 10px; align-items: center; padding: 3px 6px; border-radius: 6px; font-size: 13px; }
.sem-item.hit { background: var(--primary-soft); }
.sem-item .score { font-variant-numeric: tabular-nums; font-weight: 700; width: 36px; }
.sem-item .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cond-row { display: grid; grid-template-columns: 120px 120px 1fr 32px; gap: 8px; margin-bottom: 8px; }
.chk-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.chk-grid label { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; background: var(--panel-2); }
.chk-grid input:checked + .dot + span { font-weight: 600; }
.bar { height: 10px; border-radius: 999px; background: var(--hover); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.radio-card { display: flex; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; margin-bottom: 8px; background: var(--panel-2); }
.radio-card.on { border-color: var(--primary); background: var(--primary-soft); }
.radio-card input { margin-top: 3px; }
.sub-form { margin: 0 0 14px 28px; }
.bgprev { width: 100%; height: 70px; border-radius: 8px; background: var(--panel-2) center/cover; border: 1px dashed var(--border); margin: 4px 0 8px; }

.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1c2030; color: #fff; padding: 9px 16px; border-radius: 999px; box-shadow: var(--shadow); font-size: 13.5px; max-width: 90vw; }
.toast.err { background: var(--danger); }

.menu-btn { display: none; }
.back-btn { display: none; }

/* ---------- 登入頁 ---------- */
.login-page { min-height: 100%; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--primary) 18%, transparent), transparent), radial-gradient(900px 500px at 100% 110%, color-mix(in srgb, #8b5cf6 16%, transparent), transparent), var(--bg); }
.login-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px 26px; box-shadow: var(--shadow); }
.login-card .brand { justify-content: center; font-size: 24px; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 20px; }
.login-card .btn.primary { width: 100%; justify-content: center; padding: 10px; margin-top: 4px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 20px; margin: 4px 0 8px; }

#emailSplit .row { gap: 6px; }
#emailSplit input { flex: 1; min-width: 0; }
#emailSplit select { flex: 1.3; min-width: 0; }

/* ---------- 響應式 ---------- */
@media (max-width: 1100px) { .main { grid-template-columns: 200px 320px minmax(0, 1fr); } }
@media (max-width: 860px) {
  .main { display: block; position: relative; }
  .sidebar { position: absolute; z-index: 20; top: 0; bottom: 0; left: 0; width: 250px; transform: translateX(-102%); transition: transform .2s; box-shadow: var(--shadow); }
  .nav-open .sidebar { transform: none; }
  .listpane, .preview { position: absolute; inset: 0; width: 100%; }
  [data-pane='list'] .preview { display: none; }
  [data-pane='preview'] .listpane { display: none; }
  .menu-btn, .back-btn { display: inline-grid; }
  .brand .name { display: none; }
  .brand, .top-actions { min-width: 0; }
  .cond-row { grid-template-columns: 1fr 1fr; } .cond-row > :nth-child(3) { grid-column: 1 / -1; order: 4; }
  .mail-head .subject-row { flex-wrap: wrap; }
  .mail-head h1 { flex: 1 1 0; min-width: 0; font-size: 17px; }
  .mail-head .actions { flex-basis: 100%; justify-content: flex-end; }
  .overlay { padding: 0; align-items: end; } .modal, .modal.sm { width: 100%; max-height: 92vh; border-radius: 14px 14px 0 0; }
  .modal.fixed { height: 92vh; }
  .grid2 { grid-template-columns: 1fr; }
}
