:root {
  --bg: #050506;
  --surface: #0e0e11;
  --surface-2: #15151a;
  --surface-3: #1c1c22;
  --line: #2a2a30;
  --line-2: #3a3a42;
  --text: #f1f1f3;
  --muted: #a6a6ad;
  --soft: #74747d;
  --accent: #26d391;
  --accent-2: #1fb87e;
  --accent-ink: #04130c;
  --danger: #ef4444;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang TC", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a2a30; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::selection { background: rgba(38,211,145,.3); }

.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); border-radius: 9px; padding: 7px 12px; font-size: 13px; }
.ghost:hover { border-color: var(--accent-2); color: var(--accent); }
.ghost.small { padding: 4px 9px; }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 9px; padding: 9px 18px; font-weight: 600; font-size: 14px; }
.primary:hover { background: var(--accent-2); }
.error { color: #ff8b8b; font-size: 13px; margin: 6px 0 0; }
.result { color: var(--muted); font-size: 13px; }

/* ---------- 登入 ---------- */
.login-screen { min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #101015 0%, var(--bg) 60%); padding: 20px; }
.login-card { width: 360px; max-width: 100%; background: linear-gradient(180deg, #141418, #0f0f12);
  border: 1px solid var(--line); border-radius: 18px; padding: 34px 30px; position: relative; overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.55); }
.brand-line { position: absolute; top: 0; left: 0; right: 0; height: 4px; background: linear-gradient(90deg, #005c4b, var(--accent)); }
.login-logo { width: 210px; height: 40px; display: block; margin: 6px 0 8px; }
.login-sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
#login-form label, .composer-body label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
input, .c-body { background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius); padding: 11px 13px; font-size: 14px; font-family: inherit; }
input:focus, .c-body:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(38,211,145,.22); }
#login-btn { width: 100%; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--radius);
  padding: 12px; font-weight: 700; font-size: 15px; margin-top: 4px; }
#login-btn:hover { background: var(--accent-2); }

/* ---------- 主框架 ---------- */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px;
  background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-logo { width: 180px; height: 36px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.who { color: var(--muted); font-size: 13px; }

.layout { flex: 1; display: grid; grid-template-columns: 230px 340px 1fr; min-height: 0; }
.folders { background: #0a0a0c; border-right: 1px solid var(--line); padding: 16px 12px; overflow-y: auto; }
.compose-btn { width: 100%; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--radius);
  padding: 11px; font-weight: 700; font-size: 14px; margin-bottom: 16px; }
.compose-btn:hover { background: var(--accent-2); }
.folder-list { display: flex; flex-direction: column; gap: 3px; }
.folder-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 11px;
  border-radius: 9px; color: var(--text); font-size: 14px; border: 1px solid transparent; }
.folder-item:hover { background: var(--surface-2); }
.folder-item.active { background: var(--surface-3); color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.folder-item .badge { background: var(--accent); color: var(--accent-ink); border-radius: 11px; padding: 0 7px; font-size: 11px; font-weight: 600; }

.list-pane { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.list-head strong { font-size: 15px; }
.message-list { flex: 1; overflow-y: auto; }
.msg-item { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; border-left: 3px solid transparent; }
.msg-item:hover { background: var(--surface-2); }
.msg-item.active { background: var(--surface-3); border-left-color: var(--accent); }
.msg-item.unread .msg-subject { color: #fff; font-weight: 600; }
.msg-item.unread::after { content: ""; }
.msg-row { display: flex; justify-content: space-between; gap: 8px; }
.msg-from { font-size: 13px; color: var(--text); }
.msg-item.unread .msg-from { color: #fff; font-weight: 600; }
.msg-date { font-size: 11px; color: var(--soft); white-space: nowrap; }
.msg-subject { font-size: 13px; margin-top: 2px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: middle; }
.empty { padding: 30px; text-align: center; color: var(--soft); font-size: 14px; }

.read-pane { overflow-y: auto; min-height: 0; }
.reader-empty { height: 100%; display: grid; place-items: center; color: var(--soft); }
.reader { padding: 22px 28px; }
.reader h1 { font-size: 21px; margin: 0 0 14px; }
.reader-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.reader-meta .from { font-size: 14px; }
.reader-meta .from b { color: var(--text); }
.reader-meta .addr { color: var(--muted); font-size: 12px; }
.reader-meta .date { color: var(--soft); font-size: 12px; }
.reader-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.reader-body { font-size: 14px; line-height: 1.75; color: var(--text); word-break: break-word; }
.reader-body iframe { width: 100%; border: 0; background: #fff; border-radius: 10px; }
.reader-attach { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.reader-attach .chip { display: inline-flex; gap: 6px; align-items: center; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; color: var(--text); margin: 0 8px 8px 0; }

/* ---------- 撰寫視窗 ---------- */
.composer { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.composer-box { width: 680px; max-width: 100%; max-height: 90vh; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.composer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px;
  border-bottom: 1px solid var(--line); background: var(--surface); }
.composer-body { padding: 16px 18px; overflow-y: auto; }
.composer-body label { margin-bottom: 12px; }
.c-toolbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0; background: var(--surface-2); }
.c-btn { min-width: 30px; height: 28px; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 6px; font-size: 13px; }
.c-btn:hover { border-color: var(--accent-2); }
.c-swatch { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(255,255,255,.2); padding: 0; }
.c-body { min-height: 220px; border-radius: 0 0 10px 10px; line-height: 1.7; overflow-y: auto; }
.composer-foot { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-top: 1px solid var(--line); }

@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .folders { display: flex; gap: 8px; align-items: center; overflow-x: auto; }
}

/* ===== v3：頂部導覽 / 路由視圖 / 搜尋 / 星標 / 設定 / 管理 ===== */
.shell { height: 100vh; display: flex; flex-direction: column; }
.topnav { display: flex; gap: 4px; margin-left: 24px; flex: 1; }
.nav-link { color: var(--muted); font-size: 14px; padding: 7px 14px; border-radius: 9px; text-decoration: none; cursor: pointer; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--surface-3); color: var(--accent); }

.view { min-height: 0; }
.main-view { flex: 1; display: grid; grid-template-columns: 230px 340px 1fr; min-height: 0; }
.page-view { flex: 1; overflow-y: auto; }
.page { max-width: 720px; margin: 0 auto; padding: 28px 24px; }
.page h1 { font-size: 24px; margin: 0 0 20px; }
.tag { font-size: 12px; background: var(--accent); color: var(--accent-ink); border-radius: 20px; padding: 2px 10px; font-weight: 600; vertical-align: middle; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.row.between { justify-content: space-between; }
textarea { width: 100%; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); border-radius: var(--radius); padding: 12px; font-family: inherit; font-size: 14px; resize: vertical; }
textarea:focus { outline: none; border-color: var(--accent); }
.danger { color: #ff8b8b; }
.danger:hover { border-color: #ef4444; color: #ff6b6b; }

.list-head { gap: 8px; }
.search-input { flex: 1; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); border-radius: 9px; padding: 8px 12px; font-size: 13px; }
.search-input:focus { outline: none; border-color: var(--accent); }
.star { background: none; border: 0; color: var(--soft); font-size: 14px; padding: 0 4px 0 0; cursor: pointer; }
.star.on { color: #f5b400; }
.load-more-wrap { text-align: center; padding: 12px; }
.addr { color: var(--soft); font-size: 11px; margin-top: 3px; }

.mailbox-list { margin-top: 14px; display: flex; flex-direction: column; gap: 4px; max-height: 420px; overflow-y: auto; }
.mbx-row { padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-family: ui-monospace, Menlo, monospace; color: var(--text); }
.primary.small { padding: 7px 13px; font-size: 13px; }

/* ============================================================
   v4：Gmail 級美化
   ============================================================ */
body { font-size: 14px; }
.topbar { padding: 8px 16px; gap: 16px; }
.topbar-logo { width: 168px; }
.topnav { margin-left: 8px; }
.who { display: inline-flex; align-items: center; gap: 8px; }
.who::before { content: attr(data-initials); }

/* 訊息列：頭像 | 內容 | 星 */
.msg-item { display: flex; align-items: flex-start; gap: 12px; padding: 11px 14px; transition: background .12s; }
.m-avatar, .avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; font-weight: 600; }
.m-main { flex: 1; min-width: 0; }
.msg-item .star { align-self: center; opacity: 0; transition: opacity .12s; }
.msg-item:hover .star, .msg-item .star.on { opacity: 1; }
.message-list { padding: 6px 6px; }
.msg-item { border-bottom: 0; border-radius: 12px; margin: 2px 0; }
.msg-item:hover { background: var(--surface-2); box-shadow: 0 1px 0 rgba(255,255,255,.02); }
.msg-item.active { background: var(--surface-3); border-left: 0; box-shadow: inset 0 0 0 1px rgba(38,211,145,.35); }

/* 搜尋列：Gmail 圓角 */
.search-input { border-radius: 22px; padding: 9px 16px; background: var(--surface-2); }
.search-input.full { width: 100%; margin: 12px 0; }
.list-head { padding: 10px 12px; }

/* 資料夾：圓角膠囊 */
.folder-item { border-radius: 0 20px 20px 0; padding-left: 16px; }
.folder-item.active { box-shadow: none; background: rgba(38,211,145,.14); color: var(--accent); }
.compose-btn { border-radius: 22px; box-shadow: 0 4px 14px rgba(38,211,145,.25); }

/* 讀信頭部加頭像 */
.reader-meta { align-items: flex-start; }
.reader .from { display: flex; gap: 12px; align-items: center; }

/* 撰寫：Gmail 右下停靠面板 */
.composer { position: fixed; inset: auto 24px 0 auto; background: transparent; display: block; z-index: 50; padding: 0; }
.composer-box { width: 540px; max-width: calc(100vw - 48px); max-height: 80vh; border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 40px rgba(0,0,0,.6); border-bottom: 0; }
.composer-head { background: var(--surface-3); padding: 12px 16px; }

/* 管理：使用者列表 */
.page.wide { max-width: 860px; }
.count-pill { font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 20px; padding: 2px 10px; margin-left: 6px; }
.user-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; max-height: 60vh; overflow-y: auto; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 12px; }
.user-row:hover { background: var(--surface-2); }
.user-meta { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-name { font-size: 14px; color: var(--text); }
.user-sub { font-size: 12px; color: var(--muted); }
.user-act { display: flex; align-items: center; gap: 8px; flex: none; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.mono.ok { color: var(--accent); }
.prov-input { width: 190px; padding: 7px 11px; font-size: 13px; border-radius: 8px; }

/* 共用微調 */
.ghost, .primary, .nav-link, .folder-item, .star, .msg-item { transition: all .12s ease; }
h1 { letter-spacing: -0.3px; }

/* ===== v5：多信箱 chips + SA 查看信箱檢視器 ===== */
.mbx-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.mbx-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 20px; padding: 3px 6px 3px 10px; }
.chip-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px 4px; border-radius: 50%; }
.chip-btn:hover { background: var(--surface-3); color: var(--text); }
.chip-btn.danger:hover { color: #ff6b6b; }
.user-act { flex-wrap: wrap; justify-content: flex-end; max-width: 460px; }

.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 60; padding: 24px; }
.viewer-box { width: 1040px; max-width: 100%; height: 84vh; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 30px 90px rgba(0,0,0,.65); }
.viewer-head { display: flex; align-items: center; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--line); background: var(--surface-3); }
.viewer-head strong { flex: 1; }
.ro-tag { font-size: 11px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); border-radius: 20px; padding: 2px 10px; }
.viewer-folders { display: flex; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.vf { background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); border-radius: 18px; padding: 5px 13px; font-size: 13px; white-space: nowrap; }
.vf.on { background: rgba(38,211,145,.14); color: var(--accent); border-color: transparent; }
.viewer-body { flex: 1; display: grid; grid-template-columns: 360px 1fr; min-height: 0; }
.viewer-list { border-right: 1px solid var(--line); overflow-y: auto; }
.viewer-reader { overflow-y: auto; }
