/* 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; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
[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 {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  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: 56px; height: 56px; margin: 0 auto 12px;
  display: grid; place-items: center;
  background: none; overflow: visible;   /* icon 已去底，唔要白磚 */
}
.gate-logo img { width: 56px; height: 56px; display: block; }
.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: 250px 320px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}
/* 唔好俾長字串（主旨／寄件人）撐爆 grid，撐爆就會「大過螢幕」 */
.app > *, .sidebar, .listpane, .reader, .reader-body { min-width: 0; }
.reader-head h1, .m-subject, .m-from, .gate-card h1 { overflow-wrap: anywhere; }

/* 側欄 */
.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: block; width: 24px; height: 24px; flex: 0 0 auto; }
.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; flex-direction: column; align-items: stretch;
  gap: 6px; padding: 10px 14px 6px; border-bottom: 1px solid var(--line);
}
.lh-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list-head h2 { font-size: 14px; letter-spacing: 0.02em; color: var(--muted); }

/* 工具列：全選／已讀／未讀／刪除（icon + hover 貼士） */
.list-tools { display: flex; align-items: center; gap: 2px; margin-left: -4px; }
.tool-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background .12s, color .12s;
}
.tool-btn:hover:not(:disabled) { background: var(--side); color: var(--text); }
.tool-btn:active:not(:disabled) { transform: translateY(1px); }
.tool-btn:disabled { opacity: .32; cursor: default; }
.tool-btn.danger:hover:not(:disabled) { background: #fdeaea; color: #c0392b; }
.tool-btn[aria-pressed="true"] { background: var(--sel); color: var(--accent); }
.tool-btn .tool-art { width: 24px; height: 24px; display: block; object-fit: contain; }
.btn .btn-art { width: 22px; height: 22px; display: inline-block; object-fit: contain; vertical-align: -4px; margin-right: 5px; }
.tool-btn[hidden] { display: none; }
.reader-tools .nav-btn { width: 28px; height: 28px; }
.reader-tools .nav-btn .tool-art { width: 22px; height: 22px; }
.tool-sep { width: 1px; height: 16px; background: var(--line); margin: 0 3px; }
.tool-count { font-size: 11.5px; color: var(--muted); margin-left: 6px; white-space: nowrap; }
/* 貼士（hover／focus 出現，唔靠 title 咁慢） */
.tool-btn::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 7px); left: 50%;
  transform: translateX(-50%) scale(.96);
  background: #1b1d22; color: #fff; font-size: 11.5px; line-height: 1.3;
  padding: 4px 8px; border-radius: 6px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .12s, transform .12s; z-index: 40;
}
.tool-btn:hover::after, .tool-btn:focus-visible::after { opacity: 1; transform: translateX(-50%) scale(1); }
.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: auto 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.selected { background: var(--sel); box-shadow: inset 3px 0 0 var(--accent); }
.m-chk { display: flex; align-items: center; justify-content: center; }
.m-chk input {
  width: 15px; height: 15px; margin: 0; cursor: pointer; accent-color: var(--accent);
  border-radius: 4px;
}
.m-chk input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.msg.unread .m-from, .msg.unread .m-subject { font-weight: 650; }
.msg.unread .chip-dot { display: none; }
/* 郵件列已讀／未讀狀態圖（/icons/boxes/{unread,read}-64.png） */
.m-state { width: 20px; height: 20px; object-fit: contain; margin-right: 5px; vertical-align: -3px; }
.msg:not(.unread) .m-state { opacity: .38; }   /* 已讀較淡，未讀先搶眼 */
.msg.unread .m-state { opacity: 1; }
.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; }
.empty-wrap { text-align: center; padding: 26px 16px 0; }
.empty-wrap[hidden] { display: none; }
.empty-art { width: 132px; height: 132px; object-fit: contain; opacity: .95; }

/* 提示條 */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px);
  background: #1b1d22; color: #fff; padding: 9px 14px; border-radius: 9px;
  font-size: 12.5px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  z-index: 80; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-art { width: 22px; height: 22px; object-fit: contain; margin-right: 7px; vertical-align: -4px; }
.toast.err { background: #c0392b; }

/* 讀信 */
.reader { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.reader-empty { margin: auto; text-align: center; }
.reader-art { font-size: 0; opacity: 1; margin-bottom: 10px; }
.reader-art-img { width: 140px; height: 140px; object-fit: contain; display: block; }
.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; }

/* ---------- 登入頁語言掣 ---------- */
.gate-lang { position: fixed; top: 14px; right: 14px; z-index: 5; }

/* ---------- 讀信區底部返回掣（手機單欄模式） ---------- */
.reader-foot {
  display: none;
  flex: 0 0 auto;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--card);
}
.reader-foot .back-btn { width: 100%; padding: 13px 16px; font-size: 15px; font-weight: 600; }

/* ---------- 響應式 ---------- */
/* iPad 直／橫（≤1024）：側欄打橫放頂，郵件列表同行並排 */
@media (max-width: 1024px) {
  .app { grid-template-columns: 300px 1fr; grid-template-rows: auto 1fr; }
  .sidebar {
    grid-column: 1 / -1;
    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; flex: 0 0 auto; }
  .sidebar { flex-wrap: wrap; row-gap: 6px; }
  .side-head { order: 1; }
  .side-foot { order: 2; margin-left: auto; }
  .accounts { display: flex; gap: 6px; overflow: auto; order: 3; flex: 1 0 100%; min-width: 0; }
  .acc { margin: 0; flex: 0 0 auto; min-width: 0; }
  .boxes { display: none; }
  .side-foot { border: 0; margin: 0; padding: 0; flex: 0 0 auto; flex-wrap: nowrap; }
  .listpane { border-right: 1px solid var(--line); }
  .grid2 { grid-template-columns: 1fr 1fr; }
}
/* 手機（≤640）：單欄，列表／讀信二選一，讀信底部有返回掣 */
@media (max-width: 768px) {
  /* iOS Safari：input 字細過 16px 一 focus 就自動放大，畫面變「大過螢幕」 */
  input, select, textarea { font-size: 16px !important; }
  body { overflow-x: hidden; }  /* 最後防線：任何殘留寬度都唔會令畫面闊過螢幕 */
}

@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { column-gap: 6px; padding: 8px 8px 6px; }
  .acc { padding: 6px 10px; }
  .acc-head { gap: 6px; }
  .acc-mail { display: none; }
  .acc-name { font-size: 12.5px; }
  .acc-del { opacity: 1; }
  .listpane { border-right: 0; }
  .app.reading .listpane { display: none; }
  .app:not(.reading) .reader { display: none; }
  .reader-foot { display: flex; }
  .grid2 { grid-template-columns: 1fr; }
  .reader-head { padding: 12px 14px 10px; }
  .reader-head h1 { font-size: 16px; }
  .reader-text { padding: 14px; }
  .list-head { padding: 8px 12px 4px; }
  .tool-btn { width: 34px; height: 34px; }
  .m-chk input { width: 17px; height: 17px; }
  .tool-btn::after { display: none; }  /* 手機冇 hover，靠 aria-label */
  .msg { padding: 10px 12px; }
}

/* ---------- 總電郵容器 ---------- */
.acc-unified { background: linear-gradient(180deg, var(--accent-soft), transparent 70%); border-color: var(--accent); }
.acc-unified .acc-head { align-items: center; }
.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-left: 6px; padding: 0 6px; line-height: 16px;
  font-size: 10.5px; font-weight: 700; color: #fff; background: var(--accent);
  border-radius: 999px; vertical-align: 1px;
}
.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; } }


/* ---------------- 戶口樹狀資料夾 ---------------- */
.acc-head { display: flex; align-items: center; gap: 6px; }
.chev {
  flex: 0 0 16px; width: 16px; height: 22px; padding: 0; border: 0; background: none;
  color: var(--muted); font-size: 10px; line-height: 22px; cursor: pointer; border-radius: 5px;
}
.chev:hover { background: var(--accent-soft); color: var(--accent); }
.chev.open { color: var(--accent); }
.boxes { display: flex; flex-direction: column; gap: 1px; padding: 1px 0 6px 20px; }
.box {
  display: flex; align-items: center; gap: 7px; width: 100%; padding: 5px 8px;
  border: 0; border-radius: 7px; background: none; color: var(--text);
  font: inherit; font-size: 12.5px; text-align: left; cursor: pointer;
}
.box:hover { background: var(--sel); }
.box.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.box.nosel { opacity: 0.55; }
.box-ico { font-size: 11px; line-height: 1; opacity: 0.9; }
.box-ico.box-art { width: 22px; height: 22px; flex: 0 0 auto; object-fit: contain; opacity: 1; }
.box-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box-empty { padding: 4px 8px; margin: 0; }

/* ---------------- 設定頁 ---------------- */
/* 設定頁用原生 <dialog> + showModal()：入 top layer，
   唔會再受 z-index／祖先 stacking context／Safari 重繪問題影響 */
.settings {
  position: fixed; inset: 0; z-index: 70; margin: 0; padding: 0;
  width: 100vw; height: 100vh; height: 100dvh;
  max-width: none; max-height: none; border: 0; border-radius: 0;
  background: var(--bg); color: var(--text); overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.settings::backdrop { background: var(--bg); }
.settings:not([open]) { display: none; }
.set-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-top)); padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.set-head h1 { margin: 0; font-size: 17px; }
.set-body { max-width: 720px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; min-width: 0; }
.set-card {
  display: grid; gap: 10px; padding: 14px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--card); min-width: 0;   /* grid item 預設 min-width:auto 會被長 email 撐爆 */
}
.set-card h2 { margin: 0; font-size: 12px; letter-spacing: 0.04em; color: var(--muted); }
.set-card .btn { justify-self: start; }
.set-accounts { display: grid; gap: 0; }
.set-acc { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.set-acc:last-child { border-bottom: 0; }
.set-acc > div { flex: 1; }
.set-acc .btn { flex: 0 0 auto; }
.set-acc-acts { display: flex; gap: 8px; flex: 0 0 auto; margin-left: auto; }
.lang-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------------- 設定 › 日曆同步 ---------------- */
#set-sync { gap: 12px; }
.sync-prov { display: grid; gap: 9px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: color-mix(in srgb, var(--card) 88%, var(--accent) 4%); }
.sync-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sync-name { font-size: 13.5px; font-weight: 650; color: var(--fg); }
.sync-badge { font-size: 11px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: transparent; }
.sync-badge.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); }
.sync-form { display: grid; gap: 9px; }
.sync-on { display: grid; gap: 8px; }
.sync-acc { margin: 0; font-size: 12.5px; color: var(--muted); word-break: break-all; }
.sync-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sync-row .btn { justify-self: start; }
.sync-pick { display: grid; gap: 10px; padding: 12px; border: 1px dashed var(--line); border-radius: 12px; }
.sync-check { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.sync-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
#sync-every, .sel-mini { flex: 0 0 auto; width: 84px; min-width: 84px; max-width: 84px; height: 30px; padding: 0 8px; }
.sync-check { gap: 8px; }
.sync-check #sync-every { margin-left: 2px; }
#sync-state:empty { display: none; }
@media (max-width: 640px) { .sync-prov, .sync-pick { padding: 10px; } }

.lang-row .btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

@media (max-width: 640px) {
  .set-body { padding: 12px; }
  .set-acc { gap: 8px; flex-wrap: wrap; row-gap: 6px; min-width: 0; }
  .set-acc > .acc-col { flex: 1 1 calc(100% - 24px); }
  .set-acc-acts { flex: 1 1 100%; justify-content: flex-end; margin-left: 0; }
  .set-acc > div { flex: 1 1 auto; min-width: 0; }
  .set-acc .acc-mail { display: block; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .set-acc .btn { padding: 4px 8px; font-size: 12px; flex: 0 0 auto; }
  .settings .set-card { padding: 12px; }
}

/* ---------------- 戶口／語言下拉 ---------------- */
.picker { display: flex; gap: 7px; padding: 0 8px 8px; }
.sel {
  flex: 1 1 auto; min-width: 0; max-width: 100%;
  appearance: none; -webkit-appearance: none;
  padding: 7px 26px 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%236b7280' stroke-width='1.6' stroke-linecap='round'/></svg>") no-repeat right 9px center;
  color: var(--text); font: inherit; font-size: 12.5px; text-overflow: ellipsis; cursor: pointer;
}
.sel:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sel-lang { flex: 0 0 78px; width: 78px; }
.side-foot { display: flex; align-items: center; gap: 6px; }
.foot-ico { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; }

@media (max-width: 1024px) {
  .picker { flex-wrap: nowrap; }
}
@media (max-width: 640px) {
  .side-head { order: 1; }
  .picker { order: 2; flex: 1 0 100%; padding: 0 0 7px; gap: 6px; }
  .side-foot { order: 3; margin-left: auto; gap: 4px; }
  .accounts { order: 4; flex: 1 0 100%; min-width: 0; }
  .foot-ico { width: 32px; height: 32px; }
}

@media (max-width: 640px) {
  /* 手機：戶口卡片只顯示目前揀嗰個（其餘用下拉揀），樹狀資料夾全闊 */
  .accounts { flex-direction: column; flex-wrap: nowrap; overflow: visible; }
  .accounts .acc:not(.active) { display: none; }
  .accounts .acc { flex: 0 0 auto; min-width: 0; width: 100%; }
  .boxes { padding-left: 16px; }
  .box { padding: 7px 8px; font-size: 13.5px; }
  /* icon 掣同品牌同一行 */
  .side-head { order: 1; flex: 0 1 auto; margin-right: auto; }
  .side-foot { order: 2; margin-left: auto; }
  .picker { order: 3; }
}

/* ---------------- 繁簡英 switch ---------------- */
.lang-sw {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  padding: 2px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  --i: 0;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, 0.04);
}
.lang-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: calc((100% - 4px) / 3);
  height: calc(100% - 4px);
  background: var(--accent);
  border-radius: 7px;
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateX(calc(var(--i) * 100%));
  pointer-events: none;
}
.lang-opt {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  min-width: 30px;
  padding: 5px 5px;
  background: none;
  border: 0;
  border-radius: 7px;
  font: inherit;
  font-size: 12px;
  line-height: 1.2;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.16s ease;
}
.lang-opt:hover { color: var(--text); }
.lang-opt.on { color: #fff; font-weight: 600; }

/* 桌面：側欄唔要戶口下拉（下面已有全部戶口按鈕），只留語言 switch */
@media (min-width: 641px) {
  #acc-select { display: none; }
  .picker { justify-content: flex-start; }
}

.r-atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 9px 22px; border-bottom: 1px solid var(--line); background: var(--card); }
.att-chip {
  display: inline-flex; align-items: center; gap: 4px;
  max-width: 100%; padding: 5px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text);
  font-size: 12px; text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.att-chip:hover { border-color: var(--accent); color: var(--accent); }
@media (max-width: 640px) { .r-atts { padding: 8px 14px; } .att-chip { font-size: 11.5px; } }

/* 舊瀏覽器（冇 <dialog>）後備疊層 */
.dlg-fallback {
  position: fixed; inset: 0; margin: auto; height: fit-content; max-height: 88vh;
  z-index: 95; display: block; width: min(620px, 94vw);
}
.dlg-backdrop { position: fixed; inset: 0; background: rgba(16, 18, 22, .45); z-index: 90; }

/* 全選：3D 漸層方框（照用戶提供 SVG），全選時顯示勾 */
#tb-selall { position: relative; }
#tb-selall .selall-img { display:none; width:24px; height:24px; object-fit:contain; }
#tb-selall[data-state="none"] .selall-img-off,
#tb-selall:not([data-state]) .selall-img-off,
#tb-selall[data-state="some"] .selall-img-mid,
#tb-selall[data-state="all"] .selall-img-on { display:block; }
#tb-selall .selall-art { display:block; overflow:visible; }


/* 線性 checkbox（SVG，2026-10）→ 3D 圖示（2026-10-31 由 Almon 提供外框＋已選圖） */
.m-chk input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent center/100% 100% no-repeat;
  background-image: url("/icons/ui/check-off-64.png");
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease;
}
.m-chk input[type="checkbox"]:hover { filter: brightness(1.06); }
.m-chk input[type="checkbox"]:active { transform: scale(.93); }
.m-chk input[type="checkbox"]:checked { background-image: url("/icons/ui/check-on-64.png"); }
.m-chk input[type="checkbox"]:indeterminate { background-image: url("/icons/ui/check-part-64.png"); }
.m-chk input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
@media (max-width: 720px) { .m-chk input[type="checkbox"] { width: 24px; height: 24px; } }


/* 側欄底部兩粒掣改用 3D 圖示（2026-10-31）
   注意：唔可以再加 #btn-xxx .foot-art 尺寸規則 —— ID 選擇器會蓋過呢條 class 規則，
   之前就係咁令 22px／手機 24px 全部失效、實際永遠 20px。 */
.foot-ico .foot-art { width: 26px; height: 26px; display: block; object-fit: contain; }
@media (max-width: 640px) { .foot-ico .foot-art { width: 28px; height: 28px; } }

/* 3D inline SVG UI 圖示（同相片級 icon 同一語言） */
.ui-art { width:24px; height:24px; display:block; overflow:visible; flex:0 0 auto; }
.btn .ui-art { width:22px; height:22px; margin-right:6px; }
.btn.back-btn .ui-art { margin-right:6px; }
.btn.ghost.small .ui-art, .btn.small .ui-art { margin-right:5px; }
.reader-art-svg { width:110px; height:110px; opacity:.95; }
.chip-ico { width:18px; height:18px; vertical-align:-2px; margin-right:4px; }
.box-art-svg { width:22px; height:22px; flex:0 0 auto; overflow:visible; }

/* 重新整理：按下時圖示轉一圈，俾用家見到有反應 */
@keyframes ui-spin { to { transform: rotate(360deg); } }
#btn-refresh.spinning svg.ui-art { animation: ui-spin 1s linear infinite; }
#btn-refresh.spinning { opacity:.9; }

/* ================= 檢視 switch：電郵 / 日曆 / 待辦 ================= */
.view-sw {
  position: relative; display: inline-flex; flex: 0 0 auto;
  padding: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 9px;
  --v: 0; box-shadow: inset 0 1px 2px rgba(16, 24, 40, 0.04);
}
.view-thumb {
  position: absolute; top: 2px; left: 2px;
  width: calc((100% - 4px) / 4); height: calc(100% - 4px);
  background: var(--accent); border-radius: 7px; pointer-events: none;
  transition: transform .22s cubic-bezier(.4, 0, .2, 1);
  transform: translateX(calc(var(--v) * 100%));
}
.view-opt {
  position: relative; z-index: 1; flex: 1 1 0; min-width: 30px; height: 28px;
  display: grid; place-items: center; padding: 0; background: none; border: 0;
  border-radius: 7px; cursor: pointer; color: var(--muted);
  -webkit-tap-highlight-color: transparent;
}
img.view-art { object-fit: contain; -webkit-user-drag: none; }
.view-art { width: 20px; height: 20px; display: block; overflow: visible; filter: grayscale(1) opacity(.5); transition: filter .16s, transform .16s; }
.view-opt:hover .view-art { filter: grayscale(.4) opacity(.85); }
.view-opt.on .view-art { filter: none; }
.view-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.view-badge {
  position: absolute; top: -4px; right: -4px; min-width: 15px; height: 15px; padding: 0 4px;
  border-radius: 999px; background: #e0384a; color: #fff; font-size: 10px; font-weight: 700;
  line-height: 15px; text-align: center; box-shadow: 0 1px 3px rgba(0, 0, 0, .28);
}
.lang-opt { min-width: 32px; }

/* ================= 日曆 / 待辦版面 ================= */
.planner { display: none; grid-column: 2 / -1; grid-row: 1; min-width: 0; min-height: 0; background: var(--bg); }
.app[data-view="calendar"], .app[data-view="todo"] { grid-template-columns: 250px minmax(0, 1fr); }
.app[data-view="calendar"] .listpane, .app[data-view="calendar"] .reader,
.app[data-view="todo"] .listpane, .app[data-view="todo"] .reader { display: none; }
.app[data-view="calendar"] .planner, .app[data-view="todo"] .planner { display: flex; }

/* 日曆 */
.cal-pane { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 14px 16px 16px; gap: 8px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; row-gap: 8px; }
.cal-nav { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 auto; }
.cal-nav h2 { margin: 0; font-size: 16px; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-arrow { flex: 0 0 auto; width: 30px; height: 30px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 9px; background: var(--card); color: var(--text); cursor: pointer; }
.cal-arrow svg { width: 20px; height: 20px; display: block; }
.cal-arrow:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.cal-arrow:active { transform: scale(.94); }
@media (max-width: 640px) {
  .cal-head { justify-content: flex-end; }
  .cal-nav { flex: 1 1 100%; }
}
.cal-year { flex: 0 0 auto; width: auto; min-width: 74px; height: 30px; padding: 0 24px 0 8px; font-size: 12.5px; border-radius: 9px; font-variant-numeric: tabular-nums; }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow span { text-align: center; font-size: 11.5px; color: var(--muted); padding: 2px 0 4px; }
.cal-dow span.we { color: #b4443f; }
.cal-grid { flex: 1 1 auto; display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: 1fr; gap: 6px; min-height: 0; }
.cal-cell {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 6px 7px; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  cursor: pointer; text-align: left; color: var(--text); font: inherit; overflow: hidden; min-width: 0;
  transition: border-color .12s, box-shadow .12s, background .12s;
}
.cal-cell:hover { border-color: var(--accent); background: var(--accent-soft); }
.cal-cell.out { opacity: .45; }
.cal-cell.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.cal-num { font-size: 12.5px; font-weight: 600; line-height: 1.1; }
.cal-cell.today .cal-num { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11.5px; }
.cal-marks { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-top: auto; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.cal-dot.todo { background: #e0a021; }
.cal-dot.done { background: #9aa4b2; }
.cal-note { width: 100%; font-size: 10.5px; color: var(--muted); line-height: 1.35; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cal-count { font-size: 10px; color: var(--muted); }

/* 當日時間表 */
.day-allday { display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); }
.allday-label { flex: 0 0 auto; padding-top: 6px; font-size: 11px; color: var(--muted); letter-spacing: .03em; }
.allday-list { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.tl-scroll { flex: 1 1 auto; overflow: auto; min-height: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.tl { display: flex; flex-direction: column; }
.tl-row { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 8px; min-height: 46px; border-bottom: 1px solid var(--line); }
.tl-row:last-child { border-bottom: 0; }
.tl-h { padding: 6px 4px 0 0; text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-slot { display: flex; flex-direction: column; gap: 4px; padding: 4px 6px 4px 0; min-width: 0; }
.tl-slot:hover { background: var(--accent-soft); }
.tl-add { align-self: flex-start; width: 22px; height: 22px; display: grid; place-items: center; padding: 0; border: 1px dashed var(--line); border-radius: 6px; background: none; color: var(--muted); font: inherit; font-size: 14px; line-height: 1; cursor: pointer; opacity: 0; }
.tl-slot:hover .tl-add, .tl-add:focus-visible { opacity: .85; }
.tl-add:hover { border-color: var(--accent); color: var(--accent); }
.tl-ev { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; box-sizing: border-box; padding: 5px 8px; border: 1px solid transparent; border-left: 3px solid var(--accent); border-radius: 6px; background: var(--accent-soft); color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.tl-ev:hover { border-color: var(--accent); }
.tl-ev.all { border-left-color: #7a9bd6; background: #eef3fb; }
.tl-time { font-size: 10.5px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.tl-sum { font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.tl-loc { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.tl-row.now-hour .tl-h { color: #c0392b; font-weight: 700; }
.tl-row.now-hour .tl-slot { background: rgba(192, 57, 43, .06); }

/* 揀時段：右欄顯示該時段內容 */
.tl-slot { cursor: pointer; }
.tl-row.sel .tl-h { color: var(--accent); font-weight: 700; }
.tl-row.sel .tl-slot { box-shadow: inset 3px 0 0 var(--accent); }
.tl-row.sel .tl-ev { border-left-color: var(--accent); }
.day-back { margin-left: auto; }

/* 星期日紅色 */
.mini-dow span.sun { color: #c0392b; font-weight: 600; }
.mini-day.sun { color: #c0392b; }
.mini-day.sun.out { color: #e0a7a3; }
.mini-day.today.sun { color: #fff; }

/* 當日面板 */
.day-pane {
  flex: 0 0 336px; width: 336px; display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--line); background: var(--card); padding: 14px; gap: 8px; overflow: auto;
}
.day-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.day-head h3 { margin: 0; font-size: 15px; }
.day-label { font-size: 11.5px; color: var(--muted); letter-spacing: .03em; }
.day-note {
  width: 100%; min-height: 130px; resize: vertical; box-sizing: border-box;
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg);
  color: var(--text); font: inherit; font-size: 13px; line-height: 1.55;
}
.day-note:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.day-note-foot { display: flex; justify-content: flex-end; margin-top: -4px; }
.day-todos { display: flex; flex-direction: column; gap: 6px; min-height: 0; margin-top: 6px; }
.day-todos h4 { margin: 0; font-size: 12px; color: var(--muted); letter-spacing: .03em; }

/* 待辦清單（兩處共用） */
.todo-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.todo-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 8px;
  padding: 7px 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg);
}
.todo-row:hover { border-color: var(--accent); }
.todo-check { width: 18px; height: 18px; margin: 0; cursor: pointer; accent-color: var(--accent); flex: 0 0 auto; }
.todo-text { font-size: 13px; line-height: 1.45; cursor: text; overflow-wrap: anywhere; min-width: 0; }
.todo-row.done .todo-text { color: var(--muted); text-decoration: line-through; }
.todo-row.overdue .due-chip { background: #fdeaea; color: #c0392b; border-color: #f6cfcf; }
.due-chip { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.due-chip.today { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.todo-del { width: 26px; height: 26px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 7px; background: none; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; }
.todo-del:hover { background: #fdeaea; color: #c0392b; }
.todo-edit { width: 100%; box-sizing: border-box; font: inherit; font-size: 13px; padding: 4px 6px; border: 1px solid var(--accent); border-radius: 6px; background: var(--card); color: var(--text); }
.todo-empty { margin: 6px 2px; font-size: 12.5px; color: var(--muted); }
.todo-add { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.todo-add input[type="text"] { flex: 1 1 auto; min-width: 120px; width: auto; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; font-size: 13px; }
.todo-add input[type="date"] { flex: 0 0 148px; width: 148px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; font-size: 12.5px; }
.todo-add .btn { flex: 0 0 auto; }

/* 待辦總覽 */
.todo-pane { display: none; flex: 1 1 auto; flex-direction: column; min-width: 0; min-height: 0; padding: 16px 20px 18px; gap: 10px; }
.app[data-view="todo"] .todo-pane { display: flex; }
.app[data-view="todo"] .cal-pane, .app[data-view="todo"] .day-pane,
.app[data-view="calendar"] .todo-pane { display: none; }
.todo-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.todo-sum h2 { margin: 0; font-size: 17px; }
.todo-sum p { margin: 3px 0 0; }
.todo-filters { display: flex; gap: 4px; padding: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 9px; }
.todo-filter { padding: 5px 11px; border: 0; border-radius: 7px; background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap; }
.todo-filter:hover { color: var(--text); }
.todo-filter.on { background: var(--accent); color: #fff; font-weight: 600; }
.todo-add-wide { padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--card); margin-top: 0; }
.todo-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; padding-right: 2px; }
.todo-list-wide .todo-row { padding: 9px 11px; }
.todo-list-wide .todo-text { font-size: 13.5px; }
.todo-sec { margin: 10px 2px 4px; font-size: 11.5px; color: var(--muted); letter-spacing: .04em; }
.todo-sec:first-child { margin-top: 0; }


/* ---------- 聯絡人 ---------- */
.app[data-view="contacts"] { grid-template-columns: 250px minmax(0, 1fr); }
.app[data-view="contacts"] .listpane,
.app[data-view="contacts"] .reader { display: none; }
.app[data-view="contacts"] .contacts { display: flex; }
.contacts {
  display: none; grid-column: 2 / -1; grid-row: 1;
  min-width: 0; min-height: 0; flex-direction: column;
  background: var(--bg);
}
.c-head { padding: 14px 16px 9px; border-bottom: 1px solid var(--line); }
.c-head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.c-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.c-actions { display: flex; align-items: center; gap: 8px; }
.c-syncline { margin: 6px 0 0; }
.c-syncline.warn { color: #b45309; }
.c-body { flex: 1 1 auto; display: flex; min-height: 0; }
.c-list-wrap { width: 300px; flex: 0 0 300px; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.c-search-wrap { padding: 10px 12px 6px; }
.c-search {
  width: 100%; height: 34px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-size: 13px;
}
.c-search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.c-list { list-style: none; margin: 0; padding: 4px 6px 12px; overflow: auto; flex: 1 1 auto; }
.c-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 9px;
  cursor: pointer; border: 1px solid transparent; min-width: 0;
}
.c-item:hover { background: var(--card); border-color: var(--line); }
.c-item.on { background: var(--sel); border-color: transparent; }
.c-avatar {
  width: 34px; height: 34px; flex: 0 0 auto; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 650;
  letter-spacing: .02em; user-select: none;
}
.c-avatar-lg { width: 46px; height: 46px; font-size: 17px; }
.c-item-txt { min-width: 0; flex: 1 1 auto; }
.c-item-fn { font-size: 13.5px; font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-item-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-empty { margin: 18px 12px; color: var(--muted); font-size: 13px; text-align: center; }

.c-detail { flex: 1 1 auto; min-width: 0; overflow: auto; padding: 18px 22px 28px; }
.c-detail-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; height: 100%; min-height: 240px; color: var(--muted);
}
.c-detail-empty img { opacity: .92; }
.c-form { display: block; max-width: 640px; }
.c-form-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.c-form-title { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.c-input {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-size: 13.5px;
}
.c-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.c-input-fn { height: 40px; font-size: 17px; font-weight: 620; }
.c-input-sub { height: 34px; font-size: 13px; }
.c-note { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.c-del { flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 9px; cursor: pointer; }
.c-del:hover { color: var(--danger); border-color: var(--danger); }
.c-back { display: none; width: 32px; height: 32px; flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 9px; font-size: 20px; line-height: 1; cursor: pointer; padding: 0 0 3px; }
.c-sec { margin-top: 18px; }
.c-sec-label { display: block; font-size: 11.5px; color: var(--muted); letter-spacing: .05em; margin: 0 0 7px; }
.c-field { display: block; margin-bottom: 14px; }
.c-rows { display: flex; flex-direction: column; gap: 8px; }
.c-row { display: flex; align-items: center; gap: 8px; }
.c-row .sel, .c-row select { width: 96px; min-width: 96px; max-width: 96px; height: 36px; flex: 0 0 96px; }
.c-row .c-input { flex: 1 1 auto; }
.c-row-del { flex: 0 0 auto; width: 30px; height: 30px; border: 0; background: none; color: var(--muted); border-radius: 8px; cursor: pointer; font-size: 16px; line-height: 1; }
.c-row-del:hover { background: #fdeaea; color: #c0392b; }
.c-add {
  margin-top: 8px; width: 100%; padding: 8px 10px; border: 1px dashed var(--line);
  background: none; color: var(--accent); border-radius: 9px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.c-add:hover { border-color: var(--accent); background: var(--accent-soft); }
.c-save-line { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin: 22px 0 0; }

/* 側欄：通訊錄清單 */
#c-books .side-filter { width: 100%; }

/* 窄螢幕：日曆上下排 */
@media (max-width: 1024px) {
  .app[data-view="calendar"], .app[data-view="todo"], .app[data-view="contacts"] { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .planner, .contacts { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 860px) {
  .planner { flex-direction: column; overflow: auto; }
  .c-body { position: relative; }
  .c-list-wrap { width: auto; flex: 1 1 auto; border-right: 0; }
  .c-detail { display: none; }
  .contacts.show-detail .c-list-wrap { display: none; }
  .contacts.show-detail .c-detail { display: block; padding: 14px 14px 26px; }
  .c-back { display: grid; place-items: center; }
  #side-contacts { display: none !important; }
  .c-head { padding: 12px 12px 8px; }
  .c-head h2 { font-size: 14px; }
  .cal-pane { flex: 0 0 auto; min-height: 58vh; padding: 10px 12px 12px; }
  .day-pane { width: auto; flex: 0 0 auto; border-left: 0; border-top: 1px solid var(--line); padding: 12px; }
  .todo-pane { flex: 0 0 auto; padding: 12px; }
  .todo-scroll { overflow: visible; }
  .cal-cell { padding: 4px 5px; border-radius: 8px; }
  .cal-note { display: none; }
}
@media (max-width: 640px) {
  .picker { gap: 5px; }
  .view-opt { min-width: 32px; height: 26px; }
  .view-art { width: 18px; height: 18px; }
  .lang-opt { min-width: 28px; padding: 5px 5px; font-size: 11.5px; }
  .cal-grid, .cal-dow { gap: 4px; }
  .cal-cell { padding: 3px 4px; gap: 2px; }
  .cal-num { font-size: 11.5px; }
  .todo-head { align-items: flex-start; }
  .todo-filters { width: 100%; overflow: auto; }
  .todo-add-wide { flex-wrap: wrap; }
  .todo-add-wide input[type="text"] { flex: 1 1 100%; }
}

/* ================= 行程（VEVENT） ================= */
.day-events { display: flex; flex-direction: column; gap: 5px; padding-bottom: 8px; margin-bottom: 2px; border-bottom: 1px dashed var(--line); }
.day-events h4 { margin: 0; font-size: 12px; color: var(--muted); letter-spacing: .03em; }
.ev-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.ev-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 7px;
  padding: 6px 8px; border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; background: var(--bg);
}
.ev-time { font-size: 11px; font-weight: 600; color: var(--accent); white-space: nowrap; padding-top: 1px; font-variant-numeric: tabular-nums; }
.ev-main { min-width: 0; }
.ev-sum { font-size: 12.5px; line-height: 1.4; overflow-wrap: anywhere; }
.ev-meta { font-size: 10.5px; color: var(--muted); overflow-wrap: anywhere; }
.ev-del { width: 24px; height: 24px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1; }
.ev-del:hover { background: #fdeaea; color: #c0392b; }
.ev-add { display: flex; flex-direction: column; gap: 5px; margin-top: 4px; }
.ev-add input[type="text"] { height: 34px; padding: 0 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; font-size: 12.5px; }
.ev-times { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.ev-times input[type="time"] { height: 34px; padding: 0 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; font-size: 12px; }
.ev-allday { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--muted); height: 34px; white-space: nowrap; }
.ev-allday input { margin: 0; }
.ev-add .btn { align-self: flex-start; height: 34px; }
.cal-ev { display: flex; align-items: center; gap: 3px; font-size: 9.5px; line-height: 1.3; color: var(--accent);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-ev i { flex: 0 0 auto; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-ev.all i { background: #2f7d5f; }
.cal-cell.sel .cal-ev { color: var(--accent); }

/* 電郵內建邀請提示條 */
.ics-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0 0 8px; padding: 8px 10px; border: 1px solid var(--accent); border-radius: 10px;
  background: var(--accent-soft); font-size: 12.5px; color: var(--text);
}
.ics-bar strong { font-weight: 600; }
.ics-bar .btn { margin-left: auto; height: 30px; }
.ics-bar.done { border-color: #2f7d5f; background: #eef7f2; }

@media (max-width: 860px) {
  .ev-add { position: sticky; bottom: 0; background: var(--card); padding-bottom: 2px; }
}

/* ================= 側欄：日曆／待辦 ================= */
.side-view { display: none; flex: 1 1 auto; min-height: 0; overflow: auto; }
.app[data-view="mail"] #side-mail { display: flex; flex-direction: column; }
.app[data-view="calendar"] #side-cal { display: flex; flex-direction: column; }
.app[data-view="todo"] #side-todo { display: flex; flex-direction: column; }
.app[data-view="contacts"] #side-contacts { display: flex; flex-direction: column; }

.mini-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 2px 2px 6px; }
.mini-title { font-size: 12.5px; font-weight: 600; }
.mini-nav { width: 24px; height: 24px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: var(--card); color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1; }
.mini-nav:hover { color: var(--accent); border-color: var(--accent); }
.mini-dow, .mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.mini-dow span { font-size: 9.5px; color: var(--muted); text-align: center; padding-bottom: 2px; }
.mini-day { position: relative; height: 26px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 7px; background: none; color: var(--text); font: inherit; font-size: 11px; cursor: pointer; font-variant-numeric: tabular-nums; }
.mini-day:hover { background: var(--accent-soft); }
.mini-day.out { color: #c3c9d3; }
.mini-day.today { background: var(--accent); color: #fff; font-weight: 700; }
.mini-day.sel { box-shadow: inset 0 0 0 1.5px var(--accent); }
.mini-day.has::after { content: ""; position: absolute; bottom: 3px; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }
.mini-day.today.has::after { background: #fff; }
.side-link { margin: 8px 2px 2px; align-self: flex-start; padding: 4px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); color: var(--muted); font: inherit; font-size: 11.5px; cursor: pointer; }
.side-link:hover { color: var(--accent); border-color: var(--accent); }
.side-block { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.side-label { margin: 0 2px 6px; font-size: 10.5px; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }
.side-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.side-item { display: flex; gap: 6px; align-items: baseline; padding: 4px 6px; border-radius: 7px; font-size: 12px; line-height: 1.35; }
.side-item:hover { background: var(--accent-soft); }
.side-item .t { font-variant-numeric: tabular-nums; color: var(--accent); font-size: 10.5px; flex: 0 0 auto; }
.side-item.done { color: var(--muted); text-decoration: line-through; }
.side-empty { margin: 4px 2px; font-size: 11.5px; color: var(--muted); }
.side-filters { display: flex; flex-direction: column; gap: 2px; }
.side-filter { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; border: 0; border-radius: 8px; background: none; color: var(--text); font: inherit; font-size: 12.5px; cursor: pointer; text-align: left; }
.side-filter:hover { background: var(--accent-soft); }
.side-filter.on { background: var(--accent); color: #fff; font-weight: 600; }
.side-filter .n { font-size: 11px; opacity: .75; font-variant-numeric: tabular-nums; }

/* 平板／手機：側欄變頂欄，檢視面板排喺品牌列之後 */
@media (max-width: 1024px) {
  .side-view { order: 3; flex: 1 0 100%; min-width: 0; overflow: visible; }
  .side-head { order: 1; }
  .side-foot { order: 2; }
  .mini-head, .mini-dow, .mini-grid { max-width: 340px; }
  .side-block { margin-top: 8px; padding-top: 6px; }
  .side-filters { flex-direction: row; flex-wrap: wrap; }
  .side-filter { border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; font-size: 12px; }
  .side-filter.on { border-color: var(--accent); }
}
@media (max-width: 640px) {
  .mini-day { height: 24px; font-size: 10.5px; }
  .tl-row { grid-template-columns: 46px minmax(0, 1fr); min-height: 42px; gap: 6px; }
  .tl-sum { font-size: 12.5px; }
  .tl-add { opacity: .7; }
  .side-list { flex-direction: row; flex-wrap: wrap; }
  .side-item { background: var(--accent-soft); }
}

/* 日曆同步：連接但攞唔到清單時嘅提醒 */
.sync-warn { color: #b45309; margin: 6px 0 0; }
@media (prefers-color-scheme: dark) { .sync-warn { color: #fbbf24; } }

/* 收件人：聯絡人自動完成 */
.ac-wrap { position: relative; }
.ac-pop {
  position: absolute;
  z-index: 90;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 264px;
  overflow: auto;
  padding: 4px;
}
.ac-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.ac-item:hover, .ac-item[data-on="1"] { background: var(--accent-soft); }
.ac-item .ac-n { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.ac-item .ac-e { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 58%; }
.c-row-mail {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.c-row-mail:hover { background: var(--accent-soft); }

/* ---------------- 資料夾管理（戶口「＋」／資料夾「✕」） ---------------- */
.acc-add { margin-left: auto; opacity: .55; font-size: 15px; font-weight: 700; line-height: 1; }
.acc:hover .acc-add, .acc:focus-within .acc-add { opacity: 1; }
.acc-add + .acc-del { margin-left: 0; }
.box-del {
  flex: 0 0 auto; width: 18px; height: 18px; margin-left: 2px; border-radius: 5px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--muted); opacity: .32; cursor: pointer; transition: opacity .12s;
}
.box:hover .box-del, .box:focus-within .box-del { opacity: .8; }
.box-del:hover, .box-del:focus { background: rgba(214, 69, 69, .16); color: #d64545; opacity: 1; }
#dlg-folder { width: min(92vw, 400px); }
#dlg-folder .field select { width: 100%; }
@media (max-width: 767px) {
  .acc-add { opacity: 1; }
  .box-del { opacity: .6; }
}
