/* ============================================================
   Design tokens (Gmail-inspired, Material 3)
   ============================================================ */
:root {
  --bg: #f6f8fc;
  --panel: #ffffff;
  --panel-2: #f1f4f9;
  --panel-3: #e7ecf4;
  --text: #1f1f1f;
  --muted: #5f6368;
  --icon: #444746;
  --icon-faint: #9aa0a6;
  --border: #e0e4ea;
  --border-soft: #eceff3;
  --outline: #747775;
  --primary: #0b57d0;
  --primary-2: #0842a0;
  --on-primary: #ffffff;
  --primary-soft: #d3e3fd;
  --accent: var(--primary);
  --warn: #d93025;
  --ok: #188038;
  --info: #1a73e8;
  --star: #f4b400;
  --hover: rgba(31, 31, 31, 0.07);
  --nav-active: #d3e3fd;
  --nav-active-fg: #001d35;
  --compose-bg: #c2e7ff;
  --compose-fg: #001d35;
  --search-bg: #e9eef6;
  --menu-bg: #e9eef6;
  --row-read: #f2f6fc;
  --row-unread: #ffffff;
  --row-selected: #c2dbff;
  --row-border: #eef0f3;
  --skel: #e8ebef;
  --skel-hi: #f4f6f8;
  --sidebar-w: 256px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 64px;
  --shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
  --shadow-lg: 0 4px 8px 3px rgba(60, 64, 67, 0.15), 0 1px 3px rgba(60, 64, 67, 0.3);
  --radius: 12px;
  --font: "Google Sans", Roboto, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

body.dark {
  color-scheme: dark;
  --bg: #0f1216;
  --panel: #1a1d22;
  --panel-2: #22262c;
  --panel-3: #2b3038;
  --text: #e3e3e3;
  --muted: #a3abb5;
  --icon: #c4c7c5;
  --icon-faint: #6f7680;
  --border: #30353d;
  --border-soft: #262a31;
  --outline: #8e918f;
  --primary: #8ab4f8;
  --primary-2: #a8c7fa;
  --on-primary: #0b1f3a;
  --primary-soft: #26384f;
  --warn: #ee675c;
  --ok: #34a853;
  --info: #4b8df8;
  --hover: rgba(232, 234, 237, 0.08);
  --nav-active: #004a77;
  --nav-active-fg: #c2e7ff;
  --compose-bg: #004a77;
  --compose-fg: #c2e7ff;
  --search-bg: #262a30;
  --menu-bg: #22262c;
  --row-read: #1a1d22;
  --row-unread: #23272e;
  --row-selected: #29436b;
  --row-border: #262a31;
  --skel: #262a30;
  --skel-hi: #2f343b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.6), 0 1px 3px 1px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 4px 8px 3px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* ============================================================
   Reset & base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

[hidden] { display: none !important; }

/* ============================================================
   App shell: fixed sidebar + sticky topbar + scrollable page
   ============================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  padding-bottom: 16px;
  transition: width 0.2s ease, transform 0.25s ease;
  scrollbar-width: thin;
}

.sb-head {
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--topbar-h);
  padding: 0 8px 0 12px;
  flex-shrink: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  font-size: 22px;
  color: var(--text);
  padding: 0 4px;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
/* Per-deployment product name (MAILAPP_BRAND_NAME): keep longer names inside the sidebar. */
.brand { min-width: 0; }
.brand-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.brand-txt--long { font-size: 17px; }
.brand-txt--xlong { font-size: 15px; }
.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4285f4 0%, #0b57d0 55%, #174ea6 100%);
  color: #fff;
  box-shadow: 0 2px 6px rgba(11, 87, 208, 0.35);
  flex-shrink: 0;
}
.brand-logo .brand-ic { width: 20px; height: 20px; }

.compose-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  align-self: flex-start;
  height: 56px;
  min-width: 56px;
  margin: 8px 0 16px 8px;
  padding: 0 24px 0 16px;
  border-radius: 16px;
  background: var(--compose-bg);
  color: var(--compose-fg);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: box-shadow 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}
.compose-btn:hover { text-decoration: none; box-shadow: var(--shadow); }
.compose-btn svg { width: 22px; height: 22px; }

.sb-nav { display: flex; flex-direction: column; }

.nav-section-title {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.08em;
  padding: 18px 26px 6px;
  white-space: nowrap;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 32px;
  padding: 0 12px 0 26px;
  margin-right: 12px;
  border-radius: 0 16px 16px 0;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  transition: background 0.12s ease;
}
.nav-link:hover { background: var(--hover); text-decoration: none; }
.nav-link.active { background: var(--nav-active); color: var(--nav-active-fg); font-weight: 700; }
.nav-link .nav-txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-ic { width: 20px; height: 20px; stroke-width: 2; flex-shrink: 0; }

.nav-badge {
  font-size: 12px;
  font-weight: 700;
  color: inherit;
  margin-left: auto;
  letter-spacing: 0.01em;
}

/* Collapsed (desktop) sidebar */
body.sb-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sb-collapsed .brand-txt,
body.sb-collapsed .compose-txt,
body.sb-collapsed .nav-txt,
body.sb-collapsed .nav-badge { display: none; }
body.sb-collapsed .brand { display: none; }
body.sb-collapsed .compose-btn { padding: 0; justify-content: center; width: 56px; }
body.sb-collapsed .nav-link {
  justify-content: center;
  padding: 0;
  margin: 0 8px;
  width: 56px;
  border-radius: 16px;
}
body.sb-collapsed .nav-section-title {
  font-size: 0;
  padding: 0;
  margin: 10px 18px;
  border-top: 1px solid var(--border);
}
body.sb-collapsed .main-col { margin-left: var(--sidebar-w-collapsed); }

/* ---- Main column ---- */
.main-col {
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  flex: 1;
  min-width: 0;
  transition: margin-left 0.2s ease;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 12px 0 0;
  background: var(--bg);
}
.topbar > .form-row { flex-shrink: 0; flex-wrap: nowrap; }

.topbar-title {
  font-weight: 400;
  font-size: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.topbar .right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

.topbar-search { flex: 1 1 auto; max-width: 720px; min-width: 0; }
.topbar.has-search .topbar-title { display: none; }

/* ---- Search bar ---- */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  height: 48px;
  padding: 0 4px;
  border-radius: 24px;
  background: var(--search-bg);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.search-bar:focus-within { background: var(--panel); box-shadow: var(--shadow); }
.search-bar input[type="search"] {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  font-size: 16px;
  padding: 0 6px;
  border-radius: 0;
  color: var(--text);
}
.search-bar input[type="search"]:focus { border: 0; box-shadow: none; }
.search-bar input[type="search"]::-webkit-search-cancel-button { display: none; }

.search-opts {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 18px 22px;
  z-index: 120;
}
.search-opts-title { font-size: 14px; font-weight: 500; margin-bottom: 12px; }
.search-opts-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px 14px;
  align-items: center;
}
.search-opts-grid label { font-size: 13px; color: var(--muted); }
.search-opts-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---- Icon buttons, avatars, account menu ---- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--icon);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s ease;
}
.icon-btn:hover { background: var(--hover); filter: none; }
.icon-btn:active { transform: none; }
.icon-btn:disabled { opacity: 0.38; cursor: default; background: transparent; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn svg.icon-md { width: 24px; height: 24px; }
.icon-btn.spinning svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  flex-shrink: 0;
  user-select: none;
  text-transform: uppercase;
}
.avatar-lg { width: 40px; height: 40px; font-size: 17px; }
.avatar-xl { width: 80px; height: 80px; font-size: 34px; }

.avatar-btn {
  padding: 4px;
  border-radius: 50%;
  background: transparent;
  margin-left: 4px;
}
.avatar-btn:hover { background: var(--hover); filter: none; }

.account { position: relative; }
.account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 340px;
  max-width: calc(100vw - 24px);
  background: var(--menu-bg);
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  padding: 16px;
  text-align: center;
  z-index: 130;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.am-email { font-size: 13px; color: var(--text); font-weight: 500; word-break: break-all; }
.am-hello { font-size: 22px; font-weight: 400; }
.am-manage { border-radius: 100px; margin-top: 2px; }
.am-list {
  width: 100%;
  background: var(--panel);
  border-radius: 18px;
  overflow: hidden;
  margin-top: 6px;
}
.am-item {
  width: 100%;
  justify-content: flex-start;
  gap: 14px;
  padding: 14px 22px;
  border-radius: 0;
  background: transparent;
  font-size: 14px;
}
.am-item + .am-item { border-top: 2px solid var(--menu-bg); }
.am-item:hover { background: var(--hover); filter: none; }

/* ---- Content surface ---- */
main.content {
  flex: 1;
  background: var(--panel);
  border-radius: 16px;
  margin: 0 16px 16px 0;
  padding: 24px 28px 40px;
  min-height: calc(100vh - var(--topbar-h) - 16px);
  min-width: 0;
}
main.content.content-flush { padding: 0; }

/* ============================================================
   Auth pages (login / register — no sidebar)
   ============================================================ */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background: linear-gradient(140deg, var(--panel-3) 0%, var(--bg) 60%);
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.auth-card h1 { font-size: 22px; margin-bottom: 6px; }

/* ============================================================
   User chip & role pills
   ============================================================ */
.user-chip { font-size: 13px; color: var(--muted); }

.role-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.role-pill.admin   { background: var(--primary); color: var(--on-primary); }
.role-pill.manager { background: var(--info);    color: #fff; }

/* ============================================================
   Cards, forms, typography
   ============================================================ */
.page-title    { font-size: 22px; font-weight: 400; margin-bottom: 4px; }
.page-subtitle { font-size: 13px; color: var(--muted); margin-bottom: 20px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card h3 { font-size: 16px; font-weight: 500; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-head h3 { margin-bottom: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 500; }

.muted { color: var(--muted); font-size: 13px; }
.tb-spacer { flex: 1 1 auto; }

/* ============================================================
   Inputs
   ============================================================ */
/* :where() keeps specificity at plain `input` so page-level styles still win. */
input:where(:not([type="checkbox"]):not([type="radio"]):not([type="file"])), textarea, select {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
input:where(:not([type="checkbox"]):not([type="radio"]):not([type="file"])):focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
input:disabled, textarea:disabled, select:disabled { opacity: 0.65; }
input[type="file"] { font-family: inherit; font-size: 13px; color: var(--muted); }
textarea { resize: vertical; }

input[type="checkbox"], input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
  vertical-align: middle;
  margin: 0 4px 0 0;
}
body.dark input[type="date"] { color-scheme: dark; }

/* ============================================================
   Buttons
   ============================================================ */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 20px;
  padding: 9px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  background: var(--panel-2);
  color: var(--text);
  transition: filter 0.15s, background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  line-height: 1.2;
}
button:hover, .btn:hover { filter: brightness(0.96); text-decoration: none; }
button:disabled, .btn:disabled { opacity: 0.55; cursor: default; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-2); filter: none; box-shadow: var(--shadow); }
.btn-warn  { background: var(--warn);  color: #fff; }
.btn-ok    { background: var(--ok);    color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--hover); filter: none; }
a.btn-ghost { text-decoration: none; color: inherit; }
.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--outline);
  height: 40px;
  padding: 0 22px;
}
.btn-outline:hover { background: var(--hover); filter: none; }
.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: 16px; }
.btn-block { width: 100%; }
.btn-send { height: 40px; padding: 0 20px 0 24px; }

.link-btn {
  background: none;
  border: 0;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
}
.link-btn:hover { background: var(--hover); filter: none; text-decoration: none; }

/* ============================================================
   Status pills & chips
   ============================================================ */
.status-pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--muted);
  white-space: nowrap;
}
.status-pill.configured    { background: var(--ok);   color: #fff; }
.status-pill.configuring   { background: var(--info); color: #fff; }
.status-pill.error         { background: var(--warn); color: #fff; }
.status-pill.not_configured { background: var(--panel-3); color: var(--muted); }
.status-pill.active   { background: var(--ok);   color: #fff; }
.status-pill.inactive { background: var(--warn); color: #fff; }
.status-pill.failed   { background: var(--warn); color: #fff; }

.chip {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  margin-right: 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  background: var(--panel-3);
  color: var(--muted);
  vertical-align: 1px;
}
.chip-danger { background: #fce8e6; color: #c5221f; }
body.dark .chip-danger { background: #5c2b29; color: #f6aea9; }

/* ============================================================
   Table
   ============================================================ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { background: var(--panel-2); font-weight: 500; white-space: nowrap; color: var(--muted); }
tr:last-child td { border-bottom: none; }
td select { min-width: 96px; }
td .btn-sm { padding: 6px 12px; }

/* ============================================================
   Legacy mail rows
   ============================================================ */
.mail-row {
  padding: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  margin-bottom: 8px;
  transition: background 0.15s;
}
.mail-row:hover { background: var(--panel-2); }
.mail-row .subject { font-weight: 600; font-size: 14px; }
.mail-row .preview { color: var(--muted); font-size: 12.5px; }

/* ============================================================
   Log / code blocks
   ============================================================ */
.log-line {
  font-family: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 12px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-all;
}
.log-line.error { color: var(--warn); }

.dns-block {
  font-family: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
  background: var(--panel-2);
  padding: 12px;
  border-radius: 10px;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px dashed var(--border);
}

.kbd {
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  background: var(--panel-2);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12px;
}

/* ============================================================
   Toast (Gmail-style snackbar)
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 24px;
  max-width: min(480px, calc(100vw - 48px));
  background: #303134;
  color: #e8eaed;
  padding: 14px 20px;
  border-radius: 6px;
  box-shadow: 0 3px 5px -1px rgba(0, 0, 0, 0.2), 0 6px 10px rgba(0, 0, 0, 0.14), 0 1px 18px rgba(0, 0, 0, 0.12);
  font-size: 14px;
  z-index: 500;
  animation: slideUp 0.2s ease;
  border-left: 4px solid transparent;
  display: flex;
  align-items: center;
  gap: 18px;
}
.toast-msg { flex: 1; min-width: 0; }
.toast-action {
  margin: -6px -10px -6px auto;
  padding: 6px 10px;
  border-radius: 4px;
  background: none;
  color: #8ab4f8;
  font-size: 14px;
  font-weight: 500;
}
.toast-action:hover { background: rgba(255, 255, 255, 0.08); filter: none; }
body.dark .toast-action { color: #0b57d0; }
body.dark .toast-action:hover { background: rgba(0, 0, 0, 0.06); }
body.dark .toast { background: #e3e3e3; color: #1f1f1f; }
.toast.error { border-left-color: #f28b82; }
.toast.ok    { border-left-color: #81c995; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Mobile sidebar overlay
   ============================================================ */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--icon);
  padding: 0;
}
.mobile-menu-btn:hover { background: var(--hover); filter: none; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

.fab-compose { display: none; }

/* ---- Lucide icon sizing ---- */
.icon-xs { width: 14px; height: 14px; stroke-width: 2; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; stroke-width: 2; flex-shrink: 0; }
.icon-md { width: 22px; height: 22px; stroke-width: 2; flex-shrink: 0; }
.brand-ic { width: 20px; height: 20px; }
svg.lucide { vertical-align: middle; }

/* ============================================================
   Mailbox: list panel
   ============================================================ */
.mail-panel { min-height: inherit; display: flex; flex-direction: column; }

.list-toolbar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 48px;
  padding: 4px 12px 4px 16px;
  background: var(--panel);
  border-radius: 16px 16px 0 0;
  border-bottom: 1px solid var(--border-soft);
}
.tb-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
}
.tb-check:hover { background: var(--hover); }
.tb-check input { margin: 0; }
.tb-idle { display: flex; align-items: center; gap: 2px; min-width: 0; }
.bulk { display: flex; align-items: center; gap: 2px; margin-left: 4px; }

/* All / Unread / Read filter */
.seg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 8px;
  padding: 2px;
  border-radius: 18px;
  background: var(--panel-2);
  flex-shrink: 0;
}
.seg button {
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: 15px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.seg button:hover { background: var(--hover); color: var(--text); filter: none; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
body.dark .seg button.on { background: var(--panel-3); }
.seg-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.bulk-count { font-size: 13px; color: var(--muted); margin: 0 8px 0 4px; white-space: nowrap; }
.page-info { font-size: 12px; color: var(--muted); padding: 0 8px; white-space: nowrap; }

.search-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--muted);
  background: var(--panel-2);
  border-bottom: 1px solid var(--border-soft);
}
.search-banner span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mail-list { flex: 1; }

.mrow {
  position: relative;
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 16px 0 10px;
  background: var(--row-read);
  border-bottom: 1px solid var(--row-border);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  outline: none;
}
.mrow:hover {
  z-index: 2;
  box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0, 0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
}
body.dark .mrow:hover { box-shadow: inset 1px 0 0 #3c4043, inset -1px 0 0 #3c4043, 0 1px 3px rgba(0, 0, 0, 0.6); }
.mrow:focus-visible { box-shadow: inset 3px 0 0 var(--primary); }
.mrow.unread { background: var(--row-unread); }
/* Clear unread marker in addition to bold text */
.mrow.unread::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}
.mrow.unread .mrow-from,
.mrow.unread .mrow-subject,
.mrow.unread .mrow-date { font-weight: 700; color: var(--text); }
.mrow.selected { background: var(--row-selected); }
.mrow.removing { opacity: 0.35; pointer-events: none; transition: opacity 0.2s; }

.mrow-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  cursor: pointer;
}
.mrow-check:hover { background: var(--hover); }
.mrow-check input { margin: 0; }

.mrow-star, .mrow-star-pad {
  width: 32px;
  height: 32px;
  flex: none;
}
.mrow-star {
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--icon-faint);
}
.mrow-star:hover { background: var(--hover); color: var(--icon); filter: none; }
.mrow-star.on, .msg-star.on { color: var(--star); }
.mrow-star.on svg, .msg-star.on svg { fill: var(--star); }
.mrow-star svg { width: 18px; height: 18px; }

.mrow-avatar, .mrow-avatar-wrap { display: none; }
.mrow-avatar-check {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
}
.mrow-avatar-check svg { width: 22px; height: 22px; stroke-width: 3; }

.mrow-from {
  flex: none;
  width: 200px;
  padding: 0 24px 0 6px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mrow-main {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.mrow-subject { color: var(--text); }
.mrow-snippet { color: var(--muted); }

.mrow-meta {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 84px;
  padding-left: 12px;
  font-size: 12px;
  color: var(--muted);
}
.mrow-clip { color: var(--icon-faint); }
.mrow-date { white-space: nowrap; }

.mrow-hover {
  position: absolute;
  right: 10px;
  top: 0;
  bottom: 0;
  display: none;
  align-items: center;
  gap: 0;
  padding-left: 12px;
  background: inherit;
}
.mrow:hover .mrow-hover { display: flex; }
.mrow-hover .icon-btn { width: 34px; height: 34px; }
.mrow-hover .icon-btn svg { width: 18px; height: 18px; }

/* Pagination bar (mail lists + tables) */
.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 10px 12px 10px 20px;
  border-top: 1px solid var(--border-soft);
  font-size: 13px;
  color: var(--muted);
}
.pager-size { display: inline-flex; align-items: center; gap: 8px; margin-right: auto; white-space: nowrap; }
.pager-size select { width: auto; padding: 5px 8px; font-size: 13px; border-radius: 8px; }
.pager-info { white-space: nowrap; font-variant-numeric: tabular-nums; }
.pager-nav { display: flex; align-items: center; gap: 2px; }
.pager-nav .icon-btn { width: 34px; height: 34px; }
.pager-nav .icon-btn svg { width: 18px; height: 18px; }
.pager-pages { display: inline-flex; align-items: center; gap: 2px; margin: 0 4px; }
.pager-num {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: 17px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.pager-num:hover { background: var(--hover); filter: none; }
.pager-num.active { background: var(--nav-active); color: var(--nav-active-fg); font-weight: 700; cursor: default; }
.pager-gap { min-width: 20px; text-align: center; user-select: none; }
.pager-compact { display: none; white-space: nowrap; padding: 0 6px; }
.card > .pager-slot .pager { margin: 4px -20px -20px; border-radius: 0 0 var(--radius) var(--radius); }

.table-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.table-toolbar h3 { margin: 0 auto 0 0; }
.table-search {
  display: flex;
  align-items: center;
  gap: 6px;
  width: min(340px, 100%);
  height: 38px;
  padding: 0 4px 0 12px;
  border-radius: 19px;
  background: var(--search-bg);
  color: var(--icon);
}
.table-search:focus-within { background: var(--panel); box-shadow: var(--shadow); }
.table-search input[type="search"] { border: 0; background: transparent; padding: 0; height: 100%; box-shadow: none !important; }
.table-count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.table-empty td { text-align: center; color: var(--muted); padding: 28px 12px; }

/* Skeleton loading */
.skel {
  display: block;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--skel) 0%, var(--skel-hi) 50%, var(--skel) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.mrow-skel { cursor: default; gap: 14px; }
.mrow-skel:hover { box-shadow: none; }
.mrow-skel .skel { height: 12px; }
.mrow-skel .skel-sq { width: 16px; height: 16px; border-radius: 4px; flex: none; margin-left: 8px; }
.mrow-skel .skel-from { width: 150px; flex: none; margin-left: 6px; }
.mrow-skel .skel-line { flex: none; }
.mrow-skel .skel-date { width: 48px; flex: none; margin-left: auto; }

/* Empty / error states */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 72px 24px;
  color: var(--muted);
}
.empty-state h3 { font-size: 20px; font-weight: 400; color: var(--text); }
.empty-state p { max-width: 440px; font-size: 14px; line-height: 1.6; margin-bottom: 8px; }
.empty-ic {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 8px;
}
.empty-ic svg { width: 44px; height: 44px; stroke-width: 1.5; }
.empty-ic.danger { background: #fce8e6; color: #c5221f; }
body.dark .empty-ic.danger { background: #5c2b29; color: #f6aea9; }

/* ============================================================
   Mailbox: reader
   ============================================================ */
.reader-body { padding: 20px 28px 40px 24px; }
.reader-skel { padding: 8px 0 0 56px; }
.reader-skel .skel { display: block; }

.reader-subject-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 22px 56px;
}
.reader-subject {
  font-size: 22px;
  font-weight: 400;
  line-height: 1.35;
  color: var(--text);
  word-break: break-word;
}
.box-chip {
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 4px;
  background: var(--panel-3);
  color: var(--muted);
}

.msg-head { display: flex; align-items: flex-start; gap: 16px; }
.msg-who { flex: 1; min-width: 0; padding-top: 1px; }
.msg-from { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.msg-name { font-weight: 700; font-size: 14px; color: var(--text); }
.msg-email { font-size: 12px; color: var(--muted); }
.msg-to {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 0;
  border-radius: 4px;
  background: none;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-to:hover { color: var(--text); filter: none; }
.msg-meta { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.msg-date { font-size: 12px; color: var(--muted); white-space: nowrap; margin-right: 6px; }
.msg-rel { color: var(--muted); }

.msg-details {
  margin: 8px 0 0 56px;
  padding: 12px 16px;
  max-width: 560px;
  font-size: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px;
}
.msg-details > div { display: grid; grid-template-columns: 64px 1fr; gap: 8px; }
.msg-details > div > span:first-child { color: var(--muted); text-align: right; }
.msg-details > div > span:last-child { word-break: break-all; }

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 16px 0 0 56px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #fef7e0;
  color: #594300;
  font-size: 13px;
}
.notice-danger { background: #fce8e6; color: #a50e0e; }
body.dark .notice { background: #3e3214; color: #fde293; }
body.dark .notice-danger { background: #5c2b29; color: #f6aea9; }

.msg .mail-body-slot { margin: 20px 0 0 56px; }

.att-section {
  margin: 28px 0 0 56px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}
.att-head { font-size: 14px; font-weight: 500; margin-bottom: 12px; }
.att-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.att-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 232px;
  height: 56px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
  font-weight: 400;
}
.att-card:hover { box-shadow: var(--shadow); filter: none; }
.att-static { cursor: default; }
.att-ic {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #e8eaed;
  color: #5f6368;
}
.att-ic svg { width: 18px; height: 18px; }
.att-ic[data-kind="pdf"] { background: #fce8e6; color: #d93025; }
.att-ic[data-kind="image"] { background: #e6f4ea; color: #188038; }
.att-ic[data-kind="sheet"] { background: #e6f4ea; color: #137333; }
.att-ic[data-kind="doc"] { background: #e8f0fe; color: #1a73e8; }
.att-ic[data-kind="archive"] { background: #fef7e0; color: #b06000; }
.att-ic[data-kind="video"], .att-ic[data-kind="audio"] { background: #f3e8fd; color: #9334e6; }
.att-ic[data-kind="code"] { background: #e8eaed; color: #3c4043; }
body.dark .att-ic { filter: saturate(0.9) brightness(0.9); }
.att-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.att-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: 12px; color: var(--muted); }
.att-dl { color: var(--icon); opacity: 0; transition: opacity 0.12s; }
.att-card:hover .att-dl { opacity: 1; }

.reader-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 32px 0 0 56px; }

/* Inline reply / forward composer */
.inline-composer {
  margin: 24px 0 0 56px;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.ic-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}
.ic-line, .compose-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-soft);
}
.ic-line label, .compose-line label { width: 58px; flex: none; font-size: 14px; color: var(--muted); }
.ic-line input:not([type="checkbox"]), .compose-line input:not([type="checkbox"]) {
  border: 0;
  border-radius: 0;
  padding: 11px 0;
  background: transparent;
  font-size: 14px;
}
.ic-line input:focus, .compose-line input:focus { box-shadow: none !important; }
.inline-composer textarea, .compose-body {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  background: transparent;
  resize: vertical;
}
.inline-composer textarea:focus, .compose-body:focus { box-shadow: none !important; }
.fwd-quote { padding: 0 16px 12px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.check-line { display: flex; align-items: center; gap: 6px; padding: 0 16px 12px; font-size: 13px; color: var(--muted); cursor: pointer; }
.ic-foot, .compose-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px 12px 16px;
}
.ic-status { font-size: 13px; color: var(--muted); margin-left: 6px; }
label.icon-btn { cursor: pointer; }

.file-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px; }
.file-chips:empty { display: none; }
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 280px;
  height: 32px;
  padding: 0 4px 0 10px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 13px;
}
.fc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; color: var(--primary); }
.fc-size { color: var(--muted); font-size: 12px; white-space: nowrap; }
.fc-x { width: 24px; height: 24px; padding: 0; border-radius: 50%; background: transparent; color: var(--icon); }
.fc-x:hover { background: var(--hover); filter: none; }

/* ============================================================
   Compose page
   ============================================================ */
.compose-main { display: flex; }
.compose {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.compose-head {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 8px 0 20px;
  background: var(--panel-2);
  border-radius: 16px 16px 0 0;
}
.compose-head h1 { font-size: 15px; font-weight: 500; }
.draft-status { font-size: 12px; color: var(--muted); }
.compose .compose-line { padding: 0 20px; }
.compose .compose-line .link-btn { flex: none; }
.compose-subject { font-size: 15px !important; }
.compose-body {
  flex: 1;
  min-height: 320px;
  padding: 18px 20px !important;
  font-size: 15px !important;
  resize: none !important;
}
.signature-preview {
  margin: 0 20px 14px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 13px;
  color: var(--muted);
  white-space: pre-wrap;
}
.compose .file-chips { padding: 0 20px 12px; }
.compose-foot {
  padding: 12px 16px 16px 20px;
  border-top: 1px solid var(--border-soft);
  position: sticky;
  bottom: 0;
  background: var(--panel);
  border-radius: 0 0 16px 16px;
}
.compose-hint { font-size: 12px; color: var(--muted); margin-left: 6px; }
.drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed var(--primary);
  border-radius: 16px;
  background: color-mix(in srgb, var(--primary-soft) 85%, transparent);
  color: var(--primary);
  font-size: 18px;
  font-weight: 500;
  z-index: 10;
  pointer-events: none;
}

/* ============================================================
   Dashboard
   ============================================================ */
.dash-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.dash-date { font-size: 13px; color: var(--muted); font-weight: 500; letter-spacing: 0.02em; margin-bottom: 2px; }
.dash-greet { font-size: 28px; font-weight: 400; line-height: 1.25; }
.dash-hero .page-subtitle { margin: 4px 0 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 18px 16px;
  border-radius: 16px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid transparent;
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}
.stat-card:hover { text-decoration: none; box-shadow: var(--shadow); transform: translateY(-1px); border-color: var(--border); }
.stat-ic {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  background: var(--panel);
  color: var(--primary);
}
.stat-ic svg { width: 20px; height: 20px; }
.stat-num { font-size: 28px; font-weight: 500; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 13px; color: var(--muted); }
.stat-card.stat-primary { background: var(--primary); color: var(--on-primary); }
.stat-card.stat-primary .stat-lbl { color: var(--on-primary); opacity: 0.85; }
.stat-card.stat-primary .stat-ic { background: rgba(255, 255, 255, 0.18); color: var(--on-primary); }
.stat-ic.c-star { color: #e37400; }
.stat-ic.c-sent { color: #188038; }
.stat-ic.c-trash { color: #d93025; }
.stat-ic.c-inbox { color: #9334e6; }
body.dark .stat-ic.c-star { color: #fdd663; }
body.dark .stat-ic.c-sent { color: #81c995; }
body.dark .stat-ic.c-trash { color: #f28b82; }
body.dark .stat-ic.c-inbox { color: #d7aefb; }

.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 16px;
  align-items: start;
}
.dash-grid .card { margin-bottom: 16px; }
.recent-list { margin: 4px -8px 0; }
.recent-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 10px;
  color: var(--text);
}
.recent-item:hover { background: var(--hover); text-decoration: none; }
.recent-item + .recent-item { border-top: 1px solid var(--border-soft); }
.recent-main { flex: 1; min-width: 0; }
.recent-top { display: flex; align-items: baseline; gap: 10px; }
.recent-from { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.recent-line { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-line b { color: var(--text); font-weight: 400; }
.recent-item.unread .recent-from,
.recent-item.unread .recent-line b,
.recent-item.unread .recent-date { font-weight: 700; color: var(--text); }
.recent-item.unread .recent-from::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  margin-right: 8px;
  vertical-align: 1px;
}
.recent-empty { padding: 28px 8px; text-align: center; color: var(--muted); }

.quick-list { display: flex; flex-direction: column; gap: 2px; margin: 0 -8px; }
.quick-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 10px;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
}
.quick-item:hover { background: var(--hover); text-decoration: none; }
.quick-ic {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  flex-shrink: 0;
}
.quick-ic svg { width: 18px; height: 18px; }
.quick-sub { display: block; font-size: 12px; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 13px; margin: 12px 0 16px; }
.kv dt { color: var(--muted); }
.kv dd { word-break: break-all; }
.server-err { margin-bottom: 14px; padding: 10px 12px; border-radius: 8px; background: #fce8e6; color: #a50e0e; font-size: 12.5px; }
body.dark .server-err { background: #5c2b29; color: #f6aea9; }
.shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; font-size: 13px; color: var(--muted); align-items: center; }

/* ============================================================
   Mail body rendering (HTML paper / plain text)
   ============================================================ */
.mail-body-slot {
  min-height: 0;
  margin-top: 10px;
}

.mail-body-preview {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
  color: var(--muted);
  font-size: 13px;
  word-break: break-word;
}

.mail-body-html {
  line-height: 1.6;
  font-size: 14px;
  color: var(--text);
  overflow-x: auto;
  overflow-wrap: break-word;
  max-width: 100%;
}

/* HTML mail is designed for a light canvas (Gmail-style). Isolate it so
   sender colors never inherit the app theme. */
.mail-body-html.mail-body-paper {
  padding: 0;
  background: #ffffff;
  color: #202124;
  color-scheme: light;
  overflow: hidden;
  border-radius: 8px;
}
body.dark .mail-body-html.mail-body-paper { padding: 12px; }

.mail-body-frame {
  display: block;
  width: 100%;
  border: 0;
  background: #ffffff;
  color-scheme: light;
  min-height: 60px;
}

.mail-body-html.mail-body-plain { color: var(--text); }

.mail-body-html img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.mail-body-html a {
  color: var(--primary);
  word-break: break-word;
}

.mail-body-html table {
  border-collapse: collapse;
  max-width: 100%;
}

.mail-body-html .mail-body-fallback {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.mail-body-html .mail-body-plain-rich {
  font-size: 14px;
  line-height: 1.65;
}

.mail-body-plain-rich a { word-break: break-word; }

/* Admin mail monitor: list sits inside a card */
.card.monitor-list { padding: 0; overflow: visible; }
.card.monitor-list .list-toolbar { top: var(--topbar-h); border-radius: var(--radius) var(--radius) 0 0; }
.card.monitor-list .mail-list .mrow:last-child { border-radius: 0 0 var(--radius) var(--radius); }

/* Legacy helpers kept for other pages */
.mailbox-toolbar { margin-bottom: 18px; }
.mailbox-toolbar-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}
.mailbox-toolbar .field-grow { flex: 1 1 220px; min-width: 160px; }
.mailbox-toolbar .field-date { flex: 0 1 150px; min-width: 130px; }
.mailbox-toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; flex: 1 1 100%; }
@media (min-width: 700px) {
  .mailbox-toolbar-actions { flex: 0 0 auto; align-self: flex-end; }
}
.mail-card-focused { outline: 2px solid var(--primary); outline-offset: 3px; border-radius: 12px; }
.mail-unread { border-left: 4px solid var(--primary); }
.mail-actions { flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.attach-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.table-dense table { font-size: 12.5px; }
.table-dense th, .table-dense td { padding: 6px 10px; }
.input-inline {
  width: 100%;
  max-width: 200px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
}
.input-inline.input-grow { max-width: min(100%, 260px); min-width: 140px; }
.mono { font-family: ui-monospace, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1200px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .sidebar {
    width: 280px !important;
    background: var(--panel);
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-overlay.open { display: block; }
  body.sb-collapsed .brand-txt,
  body.sb-collapsed .compose-txt,
  body.sb-collapsed .nav-txt,
  body.sb-collapsed .nav-badge { display: initial; }
  body.sb-collapsed .brand { display: inline-flex; }
  body.sb-collapsed .compose-btn { padding: 0 24px 0 16px; width: auto; justify-content: flex-start; }
  body.sb-collapsed .nav-link { justify-content: flex-start; padding: 0 12px 0 26px; margin: 0 12px 0 0; width: auto; border-radius: 0 16px 16px 0; }
  body.sb-collapsed .nav-section-title { font-size: 11px; padding: 18px 26px 6px; margin: 0; border: 0; }
  .main-col, body.sb-collapsed .main-col { margin-left: 0; }
  .mobile-menu-btn { display: inline-flex; }
  .topbar { padding: 0 8px; gap: 6px; }
  .topbar.has-search .topbar-title { display: none; }
  .search-bar { height: 44px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  main.content { margin: 0 8px 8px; padding: 18px 16px 32px; border-radius: 14px; }
  main.content.content-flush { padding: 0; }
  #notifyBtn { display: none; }

  .fab-compose {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    position: fixed;
    right: 16px;
    bottom: 20px;
    height: 56px;
    padding: 0 20px 0 16px;
    border-radius: 16px;
    background: var(--compose-bg);
    color: var(--compose-fg);
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 80;
  }
  .fab-compose:hover { text-decoration: none; }
  .fab-compose svg { width: 22px; height: 22px; }
  body.mb-reading .fab-compose { display: none; }
  #mbListPanel { padding-bottom: 76px; }
  .toast { left: 12px; right: 12px; bottom: 88px; max-width: none; }
}

@media (max-width: 720px) {
  .list-toolbar { top: var(--topbar-h); padding: 4px 6px 4px 8px; border-radius: 14px 14px 0 0; }
  .mrow {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    grid-template-areas: "av from meta" "av main star";
    column-gap: 12px;
    row-gap: 0;
    height: auto;
    padding: 10px 14px 10px 12px;
    align-items: start;
    background: var(--row-unread);
    border-bottom: 0;
  }
  .mrow:hover { box-shadow: none; background: var(--hover); }
  .mrow.selected { background: var(--row-selected); }
  .mrow-check, .mrow-star-pad, .mrow-hover, .tb-check { display: none !important; }
  .mrow-avatar { display: inline-flex; grid-area: av; width: 40px; height: 40px; font-size: 17px; }
  .mrow-avatar-wrap { display: inline-flex; grid-area: av; position: relative; width: 40px; height: 40px; cursor: pointer; }
  .mrow.selected .mrow-avatar-check { display: flex; }
  .seg { margin-left: 2px; }
  .seg button { padding: 0 9px; }
  .mrow-from { grid-area: from; width: auto; padding: 0; font-size: 15px; line-height: 22px; }
  .mrow-meta { grid-area: meta; min-width: 0; padding-left: 8px; line-height: 22px; }
  .mrow-main {
    grid-area: main;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.45;
  }
  .mrow-subject { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mrow-dash { display: none; }
  .mrow-star { grid-area: star; align-self: end; margin: -4px -6px -4px 0; }
  .mrow-skel { display: flex; height: 64px; }
  .mrow-skel .skel-from { width: 30%; }

  .reader-body { padding: 16px 16px 32px; }
  .reader-skel { padding-left: 0; }
  .reader-subject-row,
  .msg-details,
  .notice,
  .msg .mail-body-slot,
  .att-section,
  .reader-actions,
  .inline-composer { margin-left: 0; }
  .reader-subject { font-size: 20px; }
  .msg-head { flex-wrap: wrap; gap: 12px; }
  .msg-meta { width: 100%; order: 3; justify-content: flex-end; margin-top: -6px; }
  .msg-date { margin-right: auto; }
  .att-card { width: 100%; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-num { font-size: 24px; }
  .dash-greet { font-size: 24px; }
  .compose-hint { display: none; }
  .compose-body { min-height: 240px; }
  .page-info { display: none; }
  .pager { justify-content: space-between; gap: 8px; padding: 10px 8px 10px 14px; }
  .pager-size { margin-right: 0; }
  .pager-info, .pager-pages { display: none; }
  .pager-compact { display: inline; }
}

@media (max-width: 480px) {
  .topbar .right .icon-btn#themeToggle { display: none; }
}

/* ============================================================
   Print (reader)
   ============================================================ */
@media print {
  .sidebar, .topbar, .list-toolbar, .reader-actions, #mbComposer, .fab-compose, .toast, .sidebar-overlay { display: none !important; }
  .main-col { margin: 0 !important; }
  main.content { margin: 0; padding: 0; box-shadow: none; }
  body { background: #fff; color: #000; }
}

/* ============================================================
   Login / 3D motion
   ============================================================ */
.login-body {
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}
.login-scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  perspective: 1200px;
  overflow: hidden;
}
.login-orbit {
  position: absolute;
  width: 140vmax;
  height: 140vmax;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%) rotateX(72deg) rotateZ(0deg);
  background: radial-gradient(ellipse at center, rgba(41, 82, 227, 0.18), transparent 55%);
  animation: orbit-drift 22s linear infinite;
  border-radius: 50%;
}
.login-glow {
  position: absolute;
  width: 400px;
  height: 400px;
  right: -80px;
  top: -80px;
  background: radial-gradient(circle, rgba(41, 82, 227, 0.35), transparent 70%);
  filter: blur(40px);
  animation: glow-pulse 8s ease-in-out infinite alternate;
}
@keyframes orbit-drift {
  to { transform: translate(-50%, -50%) rotateX(72deg) rotateZ(360deg); }
}
@keyframes glow-pulse {
  from { opacity: 0.7; transform: scale(1); }
  to   { opacity: 1;   transform: scale(1.08); }
}
.login-shell {
  position: relative;
  z-index: 1;
}
.login-card {
  max-width: 420px;
  margin: 0 auto;
  transform-style: preserve-3d;
  animation: card-float 6s ease-in-out infinite alternate;
  box-shadow: var(--shadow), 0 24px 60px rgba(15, 30, 60, 0.15);
}
@keyframes card-float {
  from { transform: translateY(0) rotateX(0deg); }
  to   { transform: translateY(-6px) rotateX(2deg); }
}
.login-brand h1 { font-size: 1.55rem; margin-top: 8px; }
.login-tagline { color: var(--muted); font-size: 0.95rem; margin-top: 4px; }
.login-ssb {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 16px 0 8px;
  line-height: 1.45;
  text-align: center;
}
.login-logo-wrap {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--primary), var(--primary-2));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 28px rgba(41, 82, 227, 0.35);
  transform: rotateY(-12deg);
}
.login-logo-icon { width: 28px; height: 28px; color: #fff; stroke-width: 2; }

@media (prefers-reduced-motion: reduce) {
  .login-orbit, .login-glow, .login-card { animation: none; }
  .skel, .icon-btn.spinning svg { animation: none; }
}
