/* Mailer — Mac 風三欄郵件介面 */
:root {
  --bg: #f6f7f9;
  --side: #eceff4;
  --card: #ffffff;
  --line: #dfe3ea;
  --text: #1b1d22;
  --muted: #6b7280;
  --accent: #25539b;
  --accent-soft: #e6eefb;
  --danger: #b3251e;
  --sel: #e2ebfa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --side: #1b1d22;
    --card: #1f2228;
    --line: #2c3038;
    --text: #e9ecf1;
    --muted: #98a1ae;
    --accent: #6fa2ee;
    --accent-soft: #24303f;
    --danger: #ef6b62;
    --sel: #26313f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang HK", "Noto Sans HK", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0 0; }

/* ---------- 按鈕 ---------- */
.btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}
.btn:hover { background: var(--side); }
.btn:active { transform: scale(0.985); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted);
  font-size: 16px; width: 30px; height: 30px; border-radius: 7px; cursor: pointer;
}
.icon-btn:hover { background: rgba(127, 127, 127, 0.14); color: var(--text); }

/* ---------- 登入 ---------- */
.gate { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.gate-card {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 26px 22px;
  text-align: center;
}
.gate-logo {
  width: 52px; height: 52px; margin: 0 auto 12px;
  display: grid; place-items: center;
  font-size: 24px; border-radius: 14px;
  background: var(--accent); color: #fff;
}
.gate-card h1 { font-size: 20px; }
.gate-card .muted { font-size: 13px; margin: 6px 0 16px; }
.gate-card .field { text-align: left; }
.gate-card .btn { width: 100%; margin-top: 14px; padding: 10px; }

/* ---------- 主介面 ---------- */
.app {
  display: grid;
  grid-template-columns: 232px 320px 1fr;
  height: 100dvh;
  overflow: hidden;
}

/* 側欄 */
.sidebar {
  background: var(--side);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px 8px 8px;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 10px; }
.brand { display: flex; align-items: center; gap: 7px; font-weight: 650; }
.brand-mark { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--accent); color: #fff; font-size: 12px; }
.accounts { flex: 1; min-height: 0; overflow: auto; }
.acc {
  border-radius: 9px;
  padding: 8px;
  margin-bottom: 6px;
  background: var(--card);
  border: 1px solid var(--line);
}
.acc.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.acc-head { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.dot-color { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.acc-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-mail { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-del { margin-left: auto; opacity: 0; font-size: 12px; }
.acc:hover .acc-del { opacity: 1; }
.boxes { display: flex; flex-wrap: wrap; gap: 4px; margin: 7px 0 0 15px; }
.box {
  font-size: 11.5px; padding: 3px 8px; border-radius: 999px;
  background: transparent; border: 1px solid transparent; color: var(--muted); cursor: pointer;
}
.box:hover { background: rgba(127, 127, 127, 0.12); }
.box.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.box .badge { font-size: 10.5px; opacity: 0.85; margin-left: 4px; }
.side-foot { display: flex; gap: 5px; padding-top: 8px; border-top: 1px solid var(--line); margin-top: 8px; flex-wrap: wrap; }

/* 列表 */
.listpane { display: flex; flex-direction: column; background: var(--card); border-right: 1px solid var(--line); min-height: 0; }
.list-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.list-head h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.list-actions { display: flex; align-items: center; gap: 8px; }
.msglist { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; min-height: 0; }
.msg {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.msg:hover { background: var(--side); }
.msg.active { background: var(--sel); }
.msg.unread .m-from, .msg.unread .m-subject { font-weight: 650; }
.msg.unread .m-from::before { content: "●"; color: var(--accent); font-size: 8px; margin-right: 5px; vertical-align: 2px; }
.m-from { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-date { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.m-subject { grid-column: 1 / -1; font-size: 12.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-subject .snip { color: var(--muted); font-weight: 400; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; font-size: 13px; }

/* 讀信 */
.reader { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.reader-empty { margin: auto; text-align: center; }
.reader-art { font-size: 42px; opacity: 0.6; margin-bottom: 6px; }
.reader-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.reader-head { padding: 16px 22px 12px; border-bottom: 1px solid var(--line); background: var(--card); }
.reader-head h1 { font-size: 17px; line-height: 1.35; }
.reader-meta { color: var(--muted); font-size: 12.5px; margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.reader-tools { display: flex; gap: 6px; margin-top: 10px; }
.reader-frame { flex: 1; width: 100%; border: 0; background: var(--card); min-height: 0; }
.reader-text {
  flex: 1; margin: 0; padding: 18px 22px; overflow: auto; white-space: pre-wrap;
  font: 13.5px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--card);
}

/* 對話框 */
.dlg {
  border: 1px solid var(--line); border-radius: 14px; padding: 0;
  background: var(--card); color: var(--text); width: min(620px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
.dlg::backdrop { background: rgba(10, 14, 20, 0.42); backdrop-filter: blur(2px); }
.dlg form { padding: 18px 20px 14px; display: flex; flex-direction: column; gap: 10px; }
.dlg h2 { font-size: 16px; margin-bottom: 2px; }
.dlg.compose { width: min(720px, calc(100vw - 32px)); }
.compose-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin: 4px 0 0; padding: 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.field > span { color: var(--muted); }
.field.grow { flex: 1; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 120px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.adv { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 2px; }
.adv summary { cursor: pointer; font-size: 12.5px; color: var(--muted); }
.adv .grid2 { margin-top: 8px; }
.hint { font-size: 12px; margin: 2px 0 0; }

/* ---------- 響應式 ---------- */
@media (max-width: 1024px) {
  .app { grid-template-columns: 200px 280px 1fr; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; align-items: center; gap: 8px; overflow: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .side-head { padding: 0 4px; }
  .accounts { display: flex; gap: 6px; overflow: auto; }
  .acc { margin: 0; flex: 0 0 auto; }
  .boxes { display: none; }
  .side-foot { border: 0; margin: 0; padding: 0; }
  .listpane { border-right: 0; }
  .app.reading .listpane { display: none; }
  .app:not(.reading) .reader { display: none; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---------- 總電郵容器 ---------- */
.acc-unified { background: linear-gradient(180deg, var(--accent-soft), transparent 70%); border-color: var(--accent); }
.acc-unified .acc-head { align-items: flex-start; }
.uni-mark {
  display: grid; place-items: center; width: 20px; height: 20px; border-radius: 6px;
  background: var(--accent); color: #fff; font-size: 11px; flex: 0 0 auto;
}
.uni-badge {
  display: inline-block; margin-top: 3px; font-size: 10.5px; font-weight: 600;
  color: #fff; background: var(--accent); border-radius: 999px; padding: 0 6px;
}
.m-subject { display: flex; align-items: center; gap: 6px; min-width: 0; }
.m-subj-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto; }
.chip {
  flex: 0 0 auto; font-size: 10.5px; line-height: 1.6; padding: 0 6px; border-radius: 999px;
  background: rgba(127, 127, 127, 0.14); color: var(--muted); font-weight: 500; max-width: 96px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.msg-error { opacity: 0.6; }

/* ---------- 改密碼 ---------- */
.dlg.narrow { max-width: 420px; }
.ok { color: #0f766e; font-size: 13px; margin: 4px 0 0; }

/* ---------- 密碼欄：顯示／隱藏（眼睛掣） ---------- */
.pw-wrap { position: relative; display: block; }
.pw-wrap > input { width: 100%; padding-right: 44px; box-sizing: border-box; }
.pw-wrap > input::-ms-reveal, .pw-wrap > input::-ms-clear { display: none; }
.pw-eye {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 15px; line-height: 1; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.pw-eye:hover { background: var(--accent-soft); color: var(--accent); }
.pw-eye:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pw-eye[aria-pressed="true"] { color: var(--accent); }
@media (max-width: 640px) { .pw-eye { width: 44px; height: 44px; right: 0; font-size: 17px; } .pw-wrap > input { padding-right: 50px; } }
