:root {
  color-scheme: light;
  --cms-red: #cf142b;
  --cms-red-hover: #b21024;
  --cms-blue: #155aa8;
  --cms-blue-hover: #0f4686;
  --cms-navy: #13233e;
  --cms-navy-deep: #0c172b;
  --navy: #13233e;
  --navy-deep: #0c172b;
  --ink: #293946;
  --ink-secondary: #415262;
  --muted: #768593;
  --line: #e7ebf0;
  --line-strong: #cfd8e3;
  --surface: #ffffff;
  --aside: #f3f5f8;
  --soft: #eaf2fc;
  --soft-hover: #dceafa;
  --red-soft: #fdecef;
  --blue: #155aa8;
  --blue-hover: #0f4686;
  --accent: #cf142b;
  --danger: #cf142b;
  --success: #0f7b4b;
  --warning: #b45309;
  --glass: rgba(255, 255, 255, 0.90);
  --shadow-sm: 0 1px 2px rgba(19, 35, 62, 0.05);
  --shadow-md: 0 8px 28px rgba(19, 35, 62, 0.11);
  --shadow-lg: 0 24px 64px rgba(12, 23, 43, 0.28);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --app-gap: 0px;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --navy: #0b1424;
  --navy-deep: #070e1a;
  --ink: #eef3f8;
  --ink-secondary: #c4d1df;
  --muted: #8ea0b4;
  --line: #202f46;
  --line-strong: #2d4160;
  --surface: #101c30;
  --aside: #14233b;
  --soft: #1b3152;
  --soft-hover: #223d66;
  --red-soft: #3a1924;
  --blue: #5fa2ef;
  --blue-hover: #7cb4f4;
  --cms-red: #e0364c;
  --cms-red-hover: #ef495e;
  --danger: #ff7a8a;
  --success: #4ade80;
  --warning: #fbbf24;
  --glass: rgba(16, 28, 48, 0.90);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.36);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.56);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--surface); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease; }
button:active:not(:disabled) { transform: scale(0.98); }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
button:disabled { opacity: 0.45; cursor: default; transform: none; }
a { color: var(--blue); }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
svg.lucide { width: 18px; height: 18px; flex-shrink: 0; stroke-width: 1.75; }

/* ── Sign-In Portal (CMS Workbench Header Style) ── */
.sign-in {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 14% 12%, rgba(207, 20, 43, 0.10), transparent 40%),
    radial-gradient(circle at 88% 88%, rgba(21, 90, 168, 0.13), transparent 44%),
    #f3f5f8;
  color: #293946;
  color-scheme: light;
}
.sign-in-card {
  width: min(420px, 100%);
  border: 1px solid rgba(19, 35, 62, 0.10);
  background: #ffffff;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 22px 54px rgba(19, 35, 62, 0.14);
}
.sign-in-brand {
  position: relative;
  overflow: hidden;
  background: linear-gradient(148deg, rgba(207, 20, 43, 0.94) 0 24%, rgba(21, 90, 168, 0.95) 25% 60%, #13233e 61% 100%);
  color: #ffffff;
  padding: 22px 24px 20px;
  border-bottom: 3px solid var(--cms-red);
}
.sign-in-brand::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(112deg, transparent 0 22%, rgba(255, 255, 255, 0.12) 23% 24%, transparent 25% 100%),
    linear-gradient(28deg, transparent 0 54%, rgba(255, 255, 255, 0.08) 55% 64%, transparent 65%);
  pointer-events: none;
}
.sign-in-brand-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}
.sign-in-logo {
  height: 38px;
  width: auto;
  max-width: 126px;
  padding: 4px 8px;
  object-fit: contain;
  flex: 0 0 auto;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14);
}
.sign-in-brand-copy { min-width: 0; }
.sign-in-brand-name {
  font-size: 20px;
  letter-spacing: -0.01em;
  font-weight: 700;
  line-height: 1.2;
}
.sign-in-brand-sub {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.84);
  font-weight: 500;
}
.sign-in-content { padding: 24px 24px 22px; }
.sign-in-content h1 { margin: 0 0 18px; font-size: 22px; font-weight: 700; color: #13233e; }
#signInForm label:not(.remember-row) {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #415262;
  margin-bottom: 6px;
}
#signInForm input[type="email"],
#signInForm input[type="password"],
#signInForm input[type="text"] {
  width: 100%;
  min-width: 0;
  background: #f3f5f8;
  border: 1px solid #cfd8e3;
  border-radius: 10px;
  font-size: 16px;
  padding: 11px 13px;
  color: #293946;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
#signInForm input:focus {
  background: #ffffff;
  border-color: #155aa8;
  box-shadow: 0 0 0 3px rgba(21, 90, 168, 0.12);
  outline: none;
}
#loginEmail { margin-bottom: 14px; }
.password-field { position: relative; }
.password-field input { padding-right: 48px !important; }
.password-field button {
  position: absolute;
  right: 4px;
  top: 3px;
  bottom: 3px;
  color: #64748b;
}
#loginStatus { min-height: 20px; color: var(--cms-red); font-size: 12px; margin: 6px 0 4px; font-weight: 500; }
.sign-in-submit { width: 100%; min-height: 46px; font-size: 15px; border-radius: 11px; }
.sign-in-submit[aria-busy="true"] { opacity: 0.92; }
.sign-in-foot {
  margin-top: 14px;
  text-align: center;
  font-size: 11.5px;
  color: #768593;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── App Shell & Topbar (CMS Brand Header) ── */
.mail-app { width: 100%; height: var(--app-h, 100dvh); display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  position: relative;
  overflow: hidden;
  flex: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: linear-gradient(148deg, rgba(207, 20, 43, 0.94) 0 24%, rgba(21, 90, 168, 0.95) 25% 60%, #13233e 61% 100%);
  color: #ffffff;
  height: calc(60px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 18px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.topbar::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(112deg, transparent 0 22%, rgba(255, 255, 255, 0.11) 23% 24%, transparent 25% 100%),
    linear-gradient(28deg, transparent 0 54%, rgba(255, 255, 255, 0.07) 55% 64%, transparent 65%);
  pointer-events: none;
}
.brand, .topright { position: relative; z-index: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-lockup { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo {
  height: 30px;
  width: auto;
  max-width: 96px;
  padding: 3px 6px;
  border-radius: 8px;
  background: #ffffff;
  object-fit: contain;
  flex: 0 0 auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.14);
}
.brand-text { min-width: 0; }
.brand strong {
  display: block;
  font-weight: 700;
  font-size: 16px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand span {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.80);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account {
  position: relative;
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: linear-gradient(135deg, #1b4c8c, #13233e);
  color: #ffffff;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
  padding: 0;
}
.presence-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #13233e;
}
.ooo-banner {
  flex: none;
  background: #fef3c7;
  color: #78350f;
  border-bottom: 1px solid #fde68a;
  padding: 7px 16px;
  font-size: 12px;
}
:root[data-theme="dark"] .ooo-banner {
  background: #3b2a0c;
  color: #fde68a;
  border-bottom-color: #5c4213;
}
.ooo-banner-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 1200px;
  margin: auto;
}
.ooo-banner-inner svg { width: 15px; height: 15px; }
.ooo-banner-inner span { flex: 1; font-weight: 500; }

/* ── Buttons ── */
.primary, .secondary, .tool, .link {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  border-radius: 9px;
  min-height: 38px;
  font-weight: 600;
}
.primary {
  background: var(--cms-red);
  color: #ffffff;
  border: 1px solid var(--cms-red);
  padding: 0 15px;
  box-shadow: 0 3px 10px rgba(207, 20, 43, 0.22);
}
.primary:hover { background: var(--cms-red-hover); border-color: var(--cms-red-hover); }
.secondary {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  padding: 0 13px;
}
.secondary:hover, .tool:hover, .link:hover { background: var(--aside); }
.tool, .link { background: transparent; border: 0; padding: 0 8px; }
.tool { min-width: 38px; color: var(--muted); }
.tool:hover { color: var(--ink); }
.topbar .tool { color: rgba(255, 255, 255, 0.90); }
.topbar .tool:hover { background: rgba(255, 255, 255, 0.14); color: #ffffff; }
.link { color: var(--blue); font-size: 12px; min-height: 30px; padding: 0 6px; }

/* ── Desktop 3-Pane Layout ── */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 224px minmax(330px, 400px) minmax(0, 1fr);
}
.sidebar, .mailbox, .reader { min-width: 0; min-height: 0; }
.sidebar {
  background: var(--aside);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 16px;
  overflow: auto;
}
.compose-new { margin: 0 2px 20px; min-height: 44px; border-radius: 11px; white-space: nowrap; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.section-label {
  padding: 12px 10px 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 0 10px;
  min-height: 38px;
  text-align: left;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-secondary);
  font-size: 13.5px;
}
.nav-item span:not(.dot) { flex: 1; overflow-wrap: anywhere; }
.nav-item:hover { background: rgba(21, 90, 168, 0.06); }
.nav-item.active { background: var(--soft); color: var(--blue); font-weight: 700; }
.nav-item b {
  font-size: 11px;
  font-weight: 700;
  background: var(--red-soft);
  color: var(--cms-red);
  padding: 1px 7px;
  border-radius: 999px;
}
.nav-item.active b { background: var(--blue); color: #ffffff; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #155aa8; flex-shrink: 0; }
.dot.blue { background: #155aa8; }
.dot.red { background: #cf142b; }
.dot.purple { background: #7c5ac2; }
.dot.green { background: #169c65; }
.dot.amber { background: #d97706; }
.sidebar-bottom { padding: 18px 10px 0; margin-top: auto; }
.sidebar-bottom a { display: flex; align-items: center; gap: 8px; color: var(--muted); text-decoration: none; font-size: 12px; }

/* ── Mail List ── */
.mailbox { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); }
.list-head { padding: 16px 18px 10px; border-bottom: 1px solid var(--line); }
.folder-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.folder-title h1 { font-size: 22px; line-height: 1.2; font-weight: 700; color: var(--ink); }
.folder-title p { font-size: 12px; color: var(--muted); margin-top: 3px; }
.folder-actions { display: flex; align-items: center; gap: 4px; }
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--aside);
  color: var(--muted);
  border-radius: 10px;
  padding: 0 8px 0 11px;
  transition: border-color 0.15s, background 0.15s;
}
.search input { background: none; border: 0; width: 100%; min-height: 38px; min-width: 0; font-size: 13.5px; color: var(--ink); }
.search:focus-within { border-color: var(--blue); background: var(--surface); box-shadow: 0 0 0 3px rgba(21, 90, 168, 0.08); }
.search input:focus { outline: 0; }
.search-clear { min-width: 28px; min-height: 28px; padding: 0; border-radius: 50%; }
.filters { display: flex; justify-content: space-between; align-items: center; margin: 10px 0 0; gap: 6px; }
.filter-pills { display: flex; gap: 5px; overflow: auto; scrollbar-width: none; }
.filter-pills::-webkit-scrollbar { display: none; }
.filter {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.filter:hover { background: var(--aside); color: var(--ink); }
.filter.active { background: var(--blue); border-color: var(--blue); color: #ffffff; }
.sort-btn { min-width: 32px; min-height: 32px; }
.batch {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 600;
}

.mail-list {
  overflow: auto;
  flex: 1;
  overscroll-behavior: contain;
  padding: 6px 8px max(14px, env(safe-area-inset-bottom));
}
.mail-row {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 28px;
  gap: 10px;
  align-items: start;
  border-radius: 12px;
  padding: 11px 10px;
  margin-bottom: 2px;
  transition: background 0.14s ease, transform 0.18s ease;
  touch-action: pan-y;
}
:root[data-density="compact"] .mail-row { padding: 7px 10px; }
.mail-row::after {
  content: "";
  position: absolute;
  left: 62px;
  right: 10px;
  bottom: 0;
  height: 1px;
  background: var(--line);
  opacity: 0.7;
}
.mail-row:hover { background: var(--aside); }
.mail-row.selected { background: var(--soft); }
.mail-row.selected::after { opacity: 0; }
.mail-row.pinned { background: rgba(21, 90, 168, 0.035); }
.mail-row.unread .row-sender,
.mail-row.unread .row-subject { font-weight: 700; color: var(--ink); }

.row-avatar-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  margin-top: 2px;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.row-avatar-btn.checked {
  background: var(--blue) !important;
  box-shadow: 0 2px 8px rgba(21, 90, 168, 0.35);
}
.row-avatar-btn svg { width: 17px; height: 17px; }
.row-open {
  padding: 0;
  min-width: 0;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
}
.row-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row-sender-wrap { display: flex; align-items: center; gap: 5px; min-width: 0; }
.row-sender, .row-subject, .snippet { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sender { font-size: 13.5px; color: var(--ink-secondary); font-weight: 550; }
.row-time { font-size: 11px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.mail-row.unread .row-time { color: var(--cms-red); font-weight: 650; }
.row-subject { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--ink-secondary); margin: 2px 0; }
.row-subject span { overflow: hidden; text-overflow: ellipsis; }
.thread-count {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--aside);
  border: 1px solid var(--line);
  color: var(--muted);
}
.snippet { display: block; font-size: 12px; color: var(--muted); }
.row-tags { display: flex; align-items: center; gap: 5px; margin-top: 5px; flex-wrap: wrap; }
.mini-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--aside);
  color: var(--ink-secondary);
  border: 1px solid var(--line);
  max-width: 100%;
  overflow-wrap: anywhere;
}
.mini-pill svg { width: 11px; height: 11px; }
.unread-mark {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cms-red);
  flex-shrink: 0;
}
.pin-icon { width: 12px; height: 12px; color: var(--blue); flex-shrink: 0; }
.row-star {
  border: 0;
  background: none;
  padding: 0;
  width: 28px;
  height: 36px;
  color: var(--muted);
  display: grid;
  place-items: center;
}
.row-star svg { width: 16px; height: 16px; }
.starred { color: #d97706; }
.starred svg { fill: #f59e0b; stroke: #d97706; }

/* ── Reader Pane & Threads ── */
.reader { overflow: auto; overscroll-behavior: contain; background: var(--surface); }
.reader-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.reader-bar .tool { color: var(--muted); font-size: 12.5px; }
.reader-bar .tool:hover { color: var(--ink); }
.reader-bar .tool.active-state { color: var(--blue); background: var(--soft); }
.message-content { padding: clamp(20px, 3.5vw, 44px); max-width: 860px; margin: auto; }
.message-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--soft);
  color: var(--blue);
  font-size: 11px;
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 600;
}
.message-content h2 {
  font-size: clamp(19px, 2.3vw, 26px);
  line-height: 1.3;
  margin: 0 0 18px;
  overflow-wrap: anywhere;
}
.thread-history { display: grid; gap: 10px; margin-bottom: 18px; }
.thread-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--aside);
  overflow: hidden;
}
.thread-card summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  font-size: 13px;
}
.thread-card summary::-webkit-details-marker { display: none; }
.thread-card-body {
  padding: 0 14px 14px 56px;
  white-space: pre-wrap;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--ink-secondary);
}
.avatar {
  background: var(--blue);
  color: #ffffff;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
}
.avatar.sm { width: 32px; height: 32px; font-size: 11px; }
.from {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.from-text { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.from strong { display: block; font-size: 14px; }
.from small, .from time { font-size: 12px; color: var(--muted); display: block; }
.body-copy {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14.5px;
  line-height: 1.78;
  margin: 22px 0;
  color: var(--ink);
}
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.file-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--aside);
  max-width: 100%;
  padding: 10px 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  overflow-wrap: anywhere;
}
.file-card:hover { border-color: var(--blue); background: var(--soft); }
.file-card small { display: block; color: var(--muted); font-size: 11px; }
.response-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }

/* Inline Quick Reply */
.quick-reply {
  margin-top: 22px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--aside);
  padding: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.quick-reply:focus-within {
  border-color: var(--blue);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(21, 90, 168, 0.10);
}
.quick-reply textarea {
  width: 100%;
  border: 0;
  background: transparent;
  resize: none;
  min-height: 54px;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
}
.quick-reply-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.quick-reply-hint { font-size: 11.5px; color: var(--muted); }

/* ── Bottom Navigation ── */
.bottom-nav {
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: 5px max(8px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
.tab-inner { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 540px; margin: auto; }
.tab-inner button {
  background: transparent;
  border: 0;
  min-height: 50px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 550;
  border-radius: 10px;
}
.tab-inner button[aria-current] { color: var(--blue); font-weight: 700; }
.tab-icon {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 46px;
  height: 28px;
  border-radius: 14px;
  transition: background 0.15s;
}
.tab-inner button[aria-current] .tab-icon { background: var(--soft); }
.tab-icon b {
  position: absolute;
  right: 4px;
  top: -1px;
  background: var(--cms-red);
  color: #ffffff;
  font-size: 9.5px;
  line-height: 15px;
  min-width: 15px;
  text-align: center;
  padding: 0 4px;
  border-radius: 999px;
}

/* ── Calendar & People Workspaces ── */
.workspace-view { min-height: 0; flex: 1; overflow: auto; background: var(--aside); }
.workspace-inner { width: min(760px, 100%); margin: auto; padding: 22px 20px 32px; }
.workspace-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.workspace-inner h1 { font-size: 24px; font-weight: 700; }
.workspace-caption { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.day-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 16px; }
.day-controls strong { font-size: 14px; text-align: center; }
.day-controls .secondary { min-height: 34px; padding: 0 11px; font-size: 12.5px; }
.workspace-list { display: grid; gap: 10px; }
.workspace-item {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
  min-width: 0;
  box-shadow: var(--shadow-sm);
}
.workspace-item:hover { border-color: var(--blue); background: var(--soft); }
.workspace-item strong, .workspace-item small { display: block; overflow-wrap: anywhere; }
.workspace-item small { color: var(--muted); font-size: 12px; margin-top: 2px; }
.workspace-info { flex: 1; min-width: 0; }
.workspace-time { flex: none; font-size: 12px; font-weight: 700; color: var(--blue); min-width: 82px; }
.rsvp-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.rsvp-pill.accepted { background: #dcfce7; color: #166534; }
.rsvp-pill.tentative { background: #fef3c7; color: #92400e; }
.rsvp-pill.declined { background: #fee2e2; color: #991b1b; }
.rsvp-pill.pending { background: var(--soft); color: var(--blue); }
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; }
.status-dot.busy { background: #ef4444; }
.status-dot.away { background: #f59e0b; }

/* ── Empty State & Dialogs ── */
.empty { padding: 54px 18px; text-align: center; color: var(--muted); }
.empty svg { width: 30px; height: 30px; margin-bottom: 10px; opacity: 0.7; }
.empty h2 { color: var(--ink); font-size: 17px; margin-bottom: 5px; }

dialog {
  max-width: calc(100% - 24px);
  max-height: calc(100dvh - 28px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(12, 23, 43, 0.45); backdrop-filter: blur(4px); }
#composeDialog, #eventDialog { width: 640px; }
#panel { width: 440px; }
.dialog-head, .dialog-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.dialog-head h2 { font-size: 17px; font-weight: 700; }
.dialog-foot {
  justify-content: flex-start;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.save { margin-left: auto; }
.compose-fields { padding: 4px 18px 0; }
.compose-fields label, .sender-line {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  border-bottom: 1px solid var(--line);
  min-height: 42px;
  color: var(--muted);
  font-size: 12.5px;
}
.sender-line { grid-template-columns: 64px minmax(0, 1fr) auto; }
.sender-line strong { overflow-wrap: anywhere; font-weight: 550; color: var(--ink); }
.compose-fields input, .compose-fields select, #composer textarea, #eventForm textarea {
  border: 0;
  padding: 9px 6px;
  background: transparent;
  min-width: 0;
  color: var(--ink);
  font-size: 15px;
  outline: none;
}
#composer textarea, #eventForm textarea {
  width: 100%;
  resize: vertical;
  min-height: clamp(120px, 24dvh, 250px);
  padding: 16px 18px;
  vertical-align: top;
}
.compose-files { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 18px 8px; }
.compose-file {
  display: flex;
  align-items: center;
  gap: 5px;
  padding-left: 10px;
  font-size: 11.5px;
  background: var(--soft);
  border-radius: 8px;
  overflow-wrap: anywhere;
  max-width: 100%;
}
.error { color: var(--danger); font-size: 12px; margin: 4px 18px 10px; }

#panelBody { padding: 18px; overflow-wrap: anywhere; max-height: 75dvh; overflow-y: auto; }
#panelBody .panel-items { display: grid; gap: 8px; margin: 14px 0 4px; }
#panelBody .panel-items button { justify-content: flex-start; text-align: left; }
.setting-group { padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting-group:last-child { border-bottom: 0; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.setting-row strong { display: block; font-size: 13.5px; }
.setting-row small { display: block; color: var(--muted); font-size: 11.5px; }
#panelBody select {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  padding: 4px 10px;
  font-size: 13px;
}
#panelBody textarea {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--aside);
  padding: 10px;
  font-size: 13px;
  min-height: 78px;
  resize: vertical;
}
#panelBody pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 45dvh;
  overflow: auto;
  font-size: 12.5px;
  background: var(--aside);
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.rsvp-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.rsvp-actions button.active { background: var(--blue); border-color: var(--blue); color: #ffffff; }
.directory-hero { display: flex; align-items: center; gap: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.directory-facts { display: grid; gap: 8px; margin: 14px 0; font-size: 13px; }
.directory-facts div { display: flex; justify-content: space-between; gap: 12px; }
.directory-facts span { color: var(--muted); flex: 0 0 auto; }
.directory-facts strong { text-align: right; }

/* ── Toast ── */
.toast {
  position: fixed;
  z-index: 10;
  bottom: max(68px, calc(62px + env(safe-area-inset-bottom) - var(--app-gap)));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--navy);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  max-width: calc(100% - 24px);
  font-size: 13px;
}
.toast button { color: #9ec8fa; background: none; border: 0; min-height: 28px; font-weight: 700; }

.mobile-only, .shade { display: none; }

@media (max-width: 1050px) and (min-width: 761px) {
  .layout { grid-template-columns: 185px minmax(280px, 34%) minmax(0, 1fr); }
  .reader-bar .action-text { display: none; }
}

@media (max-width: 760px) {
  :root { --content-left: max(14px, env(safe-area-inset-left, 0px)); --content-right: max(14px, env(safe-area-inset-right, 0px)); }
  /* iOS 27 独立模式避坑：锁死 html/body 根滚动并精确撑满 --app-h（严禁给 html 加 position: fixed） */
  html, body { height: var(--app-h, 100dvh); min-height: 0; overflow: hidden; overscroll-behavior: none; }
  .sign-in { min-height: var(--app-h, 100dvh); height: var(--app-h, 100dvh); overflow-y: auto; }
  .mail-app { height: var(--app-h, 100dvh); }
  .mobile-only { display: inline-flex; }
  .topbar {
    height: calc(56px + env(safe-area-inset-top));
    padding-inline: max(8px, env(safe-area-inset-left, 0px)) var(--content-right);
    gap: 6px;
  }
  .brand, .brand-lockup { min-width: 0; }
  .topbar-logo { height: 26px; padding: 2px 5px; border-radius: 7px; }
  .topright { flex-shrink: 0; gap: 6px; }
  .brand strong { font-size: 15px; }
  .brand span { font-size: 10px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    display: none;
    position: fixed;
    z-index: 5;
    left: 0;
    inset-block: 0 calc(-1 * var(--app-gap));
    width: min(290px, 84vw);
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    box-shadow: var(--shadow-lg);
  }
  .layout.nav-open .sidebar { display: flex; }
  .layout.nav-open .shade:not([hidden]) {
    display: block;
    position: fixed;
    z-index: 4;
    inset: 0 0 calc(-1 * var(--app-gap));
    border: 0;
    background: rgba(12, 23, 43, 0.46);
    backdrop-filter: blur(2px);
  }
  .mailbox { border-right: 0; }
  .reader { display: none; }
  .layout.reading .mailbox { display: none; }
  .layout.reading .reader { display: block; animation: slideIn 0.2s ease-out; }
  @keyframes slideIn { from { opacity: 0.4; transform: translateX(18px); } to { opacity: 1; transform: none; } }
  .list-head { padding: 14px var(--content-right) 8px var(--content-left); }
  .mail-list { padding-inline: max(6px, env(safe-area-inset-left, 0px)) max(6px, env(safe-area-inset-right, 0px)); }
  .folder-title h1 { font-size: 20px; }
  .quick-compose { background: var(--red-soft); color: var(--cms-red); border-radius: 10px; }
  .reader-bar { padding: 6px 8px; gap: 2px; }
  .reader-bar .action-text { display: none; }
  .message-content { padding: 18px var(--content-right) max(26px, env(safe-area-inset-bottom)) var(--content-left); }
  .search input, dialog input, dialog textarea { font-size: 16px; }
  .mail-app:has(.layout.reading:not([hidden])) .bottom-nav { display: none; }
  .workspace-inner { padding: 18px var(--content-right) 28px var(--content-left); }
  html.is-ios-standalone .bottom-nav { padding-bottom: calc(5px + max(24px, env(safe-area-inset-bottom, 0px))); }

  /* Mobile Bottom-Sheet Dialogs */
  #composeDialog, #eventDialog {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner, .layout.reading .reader { animation: none; }
  button { transition: none; }
}
