:root {
  --bg: #f3f4f6;
  --bg-soft: #f8fafc;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: #e8f0fe;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --border: #d9dee7;
  --border-soft: #e8ebf0;
  --rail: #20252d;
  --rail-hover: #2d333d;
  --shadow: 0 8px 22px rgba(31, 41, 55, .07);
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; }
h1, h2, h3 { margin-top: 0; letter-spacing: 0; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
p { line-height: 1.65; }
hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.navbar { display: none; }
.container { max-width: 1280px; margin: 0 auto; padding: 20px; }

.auth-body { background: #eef1f5; }
.auth-container { min-height: 100vh; display: grid; place-items: center; padding: 22px; }
.login-shell { width: 100%; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--border); }

.app-body { overflow: hidden; }
.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 64px var(--sidebar-width, 250px) 6px minmax(0, 1fr);
  background: #f3f4f6;
}
.app-rail {
  background: var(--rail);
  color: #d1d5db;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 14px;
  z-index: 4;
}
.rail-user {
  margin-top: auto;
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding-top: 8px;
}
.rail-user-avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  border-radius: 6px;
  background: #475569;
  border: 1px solid rgba(255,255,255,.10);
}
.rail-user-logout {
  width: 40px;
  height: 32px;
  display: grid;
  place-items: center;
  color: #aeb6c2;
  border-radius: 6px;
  font-size: 17px;
}
.rail-user-logout:hover { color: #fff; background: var(--rail-hover); }
.rail-logo {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  border-radius: 6px;
  background: #343b46;
  border: 1px solid rgba(255,255,255,.08);
}
.rail-nav { display: grid; gap: 8px; margin-top: 8px; }
.rail-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: #aeb6c2;
  border-radius: 6px;
  font-size: 17px;
  transition: background .15s ease, color .15s ease;
}
.rail-icon:hover, .rail-icon.active { color: #fff; background: var(--rail-hover); }
.rail-icon.active { box-shadow: inset 3px 0 0 #6b7280; }
.rail-bottom { margin-top: auto; }

.app-sidebar {
  background: #f7f8fa;
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}
.app-sidebar::-webkit-scrollbar,
.side-tree::-webkit-scrollbar,
.master-list::-webkit-scrollbar,
.reader-card::-webkit-scrollbar { width: 8px; height: 8px; }
.app-sidebar::-webkit-scrollbar-thumb,
.side-tree::-webkit-scrollbar-thumb,
.master-list::-webkit-scrollbar-thumb,
.reader-card::-webkit-scrollbar-thumb { background: #c7ced8; border-radius: 4px; }
.app-sidebar::-webkit-scrollbar-track,
.side-tree::-webkit-scrollbar-track,
.master-list::-webkit-scrollbar-track,
.reader-card::-webkit-scrollbar-track { background: transparent; }
.side-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.side-brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: #f9fafb;
  background: #374151;
  font-weight: 700;
}
.side-brand-name { font-size: 20px; font-weight: 700; }
.side-brand-subtitle { color: var(--muted); font-size: 12px; margin-top: 1px; }
.compose-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 40px;
  color: #fff;
  font-weight: 700;
  border-radius: 6px;
  background: #2563eb;
  border: 1px solid #1d4ed8;
  margin-bottom: 12px;
}
.compose-button:hover { color: #fff; background: #1d4ed8; }
.side-search { margin-bottom: 12px; }
.side-search input {
  padding-left: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23818b9a' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 11px center;
  background-size: 15px;
}
.side-tree { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; display: grid; align-content: start; gap: 8px; padding-right: 4px; }
.side-section {
  padding: 8px 0;
  border-top: 1px solid var(--border-soft);
}
.side-section:first-child { border-top: 0; }
.side-section-title {
  color: #8a93a0;
  font-size: 12px;
  font-weight: 700;
  margin: 6px 8px 6px;
}
.side-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 9px;
  color: #374151;
  border-radius: 5px;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.side-nav-item:hover { background: #edf0f5; color: #111827; }
.side-nav-item.active {
  color: #111827;
  background: #e5eaf3;
  box-shadow: inset 3px 0 0 #2563eb;
}
.side-nav-item.compact { font-weight: 500; font-size: 13px; padding: 7px 9px; }
.side-nav-item em {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #e5e7eb;
  color: #374151;
  font-style: normal;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.side-empty { padding: 7px 9px; color: var(--muted); font-size: 13px; }
.side-user {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--border-soft);
}
.avatar, .mail-avatar {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
  font-weight: 700;
  background: #64748b;
}
.side-user-text { display: grid; font-size: 13px; }
.side-user-text span { color: var(--muted); font-size: 12px; }
.ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.app-main {
  position: relative;
  min-width: 0;
  height: 100vh;
  overflow: auto;
  padding: 12px;
  background: #f3f4f6;
}
.app-main::before { display: none; }
.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
  padding: 16px 18px;
  border-radius: var(--radius);
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: none;
}
.page-heading h1 { margin: 0 0 5px; }
.page-heading p { margin: 0; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: none;
  margin-bottom: 16px;
}
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-6 { grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); }
.small { color: var(--muted); font-size: 13px; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.compact-actions { flex-wrap: nowrap; }

label { font-weight: 600; display: block; margin-bottom: 7px; color: #374151; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[type="date"], input[type="datetime-local"], input[type="search"], select, textarea {
  width: 100%;
  padding: 10px 11px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: #93a4bd; box-shadow: 0 0 0 3px rgba(37,99,235,.08); }
input[type="file"] { width: 100%; }
textarea { min-height: 140px; resize: vertical; }
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 5px;
  border: 1px solid #1d4ed8;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  box-shadow: none;
}
button:hover, .btn:hover { background: #1d4ed8; color: #fff; }
.btn-secondary { background: #4b5563; border-color: #4b5563; }
.btn-secondary:hover { background: #374151; }
.btn-danger { background: #dc2626; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-light { background: #fff; color: #374151; border-color: var(--border); }
.btn-light:hover { background: #f3f4f6; color: #111827; }
.icon-btn, .round-tool {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  color: #4b5563;
  border-radius: 5px;
  background: #fff;
  border: 1px solid var(--border);
}
.icon-btn:hover, .round-tool:hover { color: #111827; background: #f3f4f6; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--border-soft); text-align: left; vertical-align: top; }
th { color: #4b5563; font-size: 13px; background: #f8fafc; font-weight: 700; }
tr:hover td { background: #f9fafb; }
.badge { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; border: 1px solid transparent; }
.badge-draft { background: #f3f4f6; color: #374151; border-color: #e5e7eb; }
.badge-scheduled, .badge-pending { background: #eef2ff; color: #374151; border-color: #dbe3f4; }
.badge-running { background: #fff7ed; color: #92400e; border-color: #fed7aa; }
.badge-paused { background: #f5f3ff; color: #5b21b6; border-color: #ddd6fe; }
.badge-sent, .badge-completed { background: #ecfdf5; color: #166534; border-color: #bbf7d0; }
.badge-failed, .badge-completed_with_errors { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.badge-archived { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.flash-stack { display: grid; gap: 8px; margin-bottom: 12px; }
.flash { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 4px; border: 1px solid transparent; box-shadow: none; transition: opacity .18s ease, transform .18s ease; }
.flash-message { flex: 1; min-width: 0; }
.flash-close { width: 26px; height: 26px; border: 0; background: transparent; color: currentColor; cursor: pointer; font-size: 18px; line-height: 1; opacity: .65; }
.flash-close:hover { opacity: 1; background: rgba(15, 23, 42, .08); }
.flash-hiding { opacity: 0; transform: translateY(-4px); }
.flash-success { background: #ecfdf5; color: #166534; border-color: #bbf7d0; }
.flash-danger { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.flash-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

.stat { font-size: 32px; font-weight: 700; color: #111827; }
.metric-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.metric-row:last-child { border-bottom: none; }
.chart-row { display: grid; grid-template-columns: 110px 1fr 50px; gap: 10px; align-items: center; margin-bottom: 12px; }
.chart-label, .chart-value { font-size: 13px; color: var(--muted); }
.chart-bar, .mini-chart { width: 100%; height: 10px; background: #e5e7eb; border-radius: 4px; overflow: hidden; }
.chart-bar span, .mini-chart span { display: block; height: 100%; background: #64748b; border-radius: 4px; }
.mini-chart { max-width: 220px; margin-bottom: 6px; }
.mini-chart-danger span { background: #dc2626; }
.pagination { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.slim-pagination .btn { padding: 6px 10px; border-radius: 5px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }
.variable-palette { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 14px; }
.variable-pill { background: #f8fafc; border: 1px solid var(--border); color: #374151; padding: 5px 9px; border-radius: 5px; cursor: pointer; }
pre.code { background: #111827; color: #e5e7eb; padding: 12px; border-radius: 5px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
pre.code-light { background: #f8fafc; color: #111827; padding: 12px; border-radius: 5px; border: 1px solid var(--border); overflow-x: auto; white-space: pre-wrap; word-break: break-word; min-height: 48px; }
.preview-pane { min-height: 140px; border: 1px solid var(--border); border-radius: 5px; padding: 14px; background: #fff; }
.attachment-list, .reader-attachments { display: flex; gap: 8px; flex-wrap: wrap; }
.attachment-chip { display: inline-flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 5px; background: #f8fafc; border: 1px solid var(--border); color: #374151; }
.attachment-chip input { width: auto; }
.attachment-chip-removable { background: #fff7ed; }
.rich-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.rich-toolbar button { padding: 7px 10px; border-radius: 5px; background: #f3f4f6; color: #111827; border-color: var(--border); box-shadow: none; }
.rich-editor { min-height: 280px; border: 1px solid var(--border); border-radius: 5px; padding: 12px; background: #fff; overflow: auto; }
.rich-editor:focus { outline: 2px solid rgba(37,99,235,.16); border-color: #93a4bd; }
.rich-editor.small-editor { min-height: 220px; }
.subtle-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 5px; padding: 12px; }
.list-inline { display: flex; gap: 8px; flex-wrap: wrap; }
.mapping-row { align-items: stretch; }
.mapping-row .btn { align-self: stretch; }
.mapping-file-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 5px; padding: 12px 14px; }
.mapping-file-line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mapping-file-name { font-weight: 700; }
.mapping-file-upload { position: relative; overflow: hidden; }
.mapping-file-upload input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* Webmail split view */
.mail-client {
  height: calc(100vh - 24px);
  min-height: 0;
  display: grid;
  grid-template-columns: var(--mail-list-width, 340px) 6px minmax(0, 1fr);
  gap: 0;
}
.mail-list-panel, .mail-reader-panel {
  min-height: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: none;
  overflow: hidden;
}
.mail-list-panel { display: flex; flex-direction: column; min-height: 0; }
.mail-panel-header {
  padding: 14px 14px 11px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  border-bottom: 1px solid var(--border-soft);
  background: #fff;
}
.mail-panel-header h1 { margin: 0 0 4px; }
.mail-panel-header p { margin: 0; }
.mail-searchbar {
  padding: 10px;
  display: grid;
  grid-template-columns: 105px minmax(0, 1fr) auto;
  gap: 8px;
  border-bottom: 1px solid var(--border-soft);
  background: #f8fafc;
}
.mail-searchbar button { padding: 9px 13px; box-shadow: none; }
#mail-bulk-form { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; margin: 0; }
.master-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 0; gap: 0; display: grid; align-content: start; overscroll-behavior: contain; }
.mail-row-card {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 58px;
  gap: 9px;
  align-items: start;
  padding: 11px 10px;
  border-radius: 0;
  color: var(--text);
  border: 0;
  border-bottom: 1px solid var(--border-soft);
  transition: background .12s ease;
}
.mail-row-card:hover { background: #f8fafc; }
.mail-row-card.active {
  background: #eaf1ff;
  color: #111827;
  box-shadow: inset 3px 0 0 #2563eb;
}
.mail-row-card.active .small,
.mail-row-card.active .mail-row-subtitle,
.mail-row-card.active .mail-snippet,
.mail-row-card.active .mail-row-right,
.mail-row-card.active .mail-row-right em { color: #4b5563; }
.mail-row-card.unread::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2563eb;
  position: absolute;
  left: 6px;
  top: 17px;
}
.mail-row-card.active .mail-avatar { background: #475569; color: #fff; }
.mail-row-content { min-width: 0; }
.mail-row-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
.mail-row-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-row-subtitle { color: #4b5563; font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-snippet { color: var(--muted); margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.mail-row-right { text-align: right; color: #6b7280; font-size: 12px; display: grid; gap: 6px; justify-items: end; }
.mail-row-right em { max-width: 72px; color: #8a93a0; font-style: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.paperclip { opacity: .75; }
.mail-avatar.large { width: 42px; height: 42px; font-size: 18px; }
.mail-reader-panel { display: flex; flex-direction: column; min-height: 0; }
.reader-toolbar {
  height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-soft);
  background: #fff;
}
.reader-card { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 24px 30px 32px; background: #fff; overscroll-behavior: contain; }
.reader-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.reader-title-row h1 { margin: 0; font-size: 24px; line-height: 1.35; }
.account-pill {
  display: inline-flex;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 5px 8px;
  border-radius: 4px;
  color: #4b5563;
  background: #f3f4f6;
  border: 1px solid var(--border);
  font-size: 12px;
}
.reader-meta {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 13px 0 18px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 20px;
}
.reader-meta time { color: var(--muted); font-size: 13px; }
.reader-attachments { margin-bottom: 18px; }
.mail-body { background: #fff; border: 1px solid var(--border); border-radius: 5px; padding: 18px; overflow: auto; line-height: 1.75; }
.reader-body { border: none; padding: 0; background: transparent; font-size: 15px; }
.reader-empty, .empty-state {
  height: 100%;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 32px;
}
.empty-state { background: #fff; border-radius: 6px; }
.empty-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #f3f4f6;
  color: #6b7280;
  font-size: 24px;
  margin-bottom: 12px;
}

.mail-layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.mail-sidebar { position: sticky; top: 16px; }
.mail-side-link { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 5px; color: var(--text); }
.mail-side-link:hover { background: #f3f4f6; }
.mail-list { display: grid; }
.mail-row { display: grid; grid-template-columns: 1fr 210px; gap: 14px; padding: 14px; border: 1px solid var(--border); border-radius: 5px; background: #fff; color: var(--text); }
.mail-row:hover { border-color: #cbd5e1; background: #f8fafc; }
.mail-row.unread { border-left: 4px solid var(--primary); }
.mail-row-meta { text-align: right; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 58px var(--sidebar-width, 230px) 6px minmax(0,1fr); }
  .mail-client { grid-template-columns: var(--mail-list-width, 320px) 6px minmax(0,1fr); }
  .reader-title-row { flex-direction: column; }
}
@media (max-width: 980px) {
  .app-body { overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; grid-template-columns: 58px minmax(0, 1fr); }
  .shell-resizer, .mail-resizer { display: none; }
  .app-sidebar { display: none; }
  .app-main { height: auto; min-height: 100vh; overflow: visible; padding: 14px; }
  .mail-client { height: auto; min-height: 0; grid-template-columns: 1fr; }
  #mail-bulk-form { min-height: 360px; overflow: visible; }
  .master-list { max-height: none; overflow: visible; }
  .mail-reader-panel { min-height: 560px; }
  .grid-2, .grid-3, .grid-4, .grid-6 { grid-template-columns: 1fr; }
  .toolbar input, .toolbar select { width: 100%; min-width: 0; }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-rail { position: sticky; top: 0; height: 54px; flex-direction: row; justify-content: space-between; padding: 8px 12px; }
  .rail-nav { display: flex; margin: 0; }
  .rail-logo, .rail-icon { width: 36px; height: 36px; }
  .rail-user { margin: 0; width: auto; display: flex; align-items: center; gap: 6px; padding-top: 0; }
  .rail-user-avatar { width: 36px; height: 36px; }
  .rail-user-logout { width: 36px; height: 36px; }
  .mail-searchbar { grid-template-columns: 1fr; }
  .mail-row-card { grid-template-columns: 36px minmax(0, 1fr); }
  .mail-row-right { grid-column: 2; grid-row: 2; text-align: left; justify-items: start; display: flex; gap: 8px; }
  .reader-card { padding: 18px; }
  .reader-meta { grid-template-columns: auto 1fr; }
  .reader-meta time { grid-column: 2; }
  .page-heading { flex-direction: column; }
  .mapping-file-line { align-items: flex-start; }
}

/* Inline image preview and translation */
.image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin: -6px 0 18px;
}
.image-preview-grid.standalone { margin: 10px 0 16px; }
.image-preview-item {
  display: block;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: #374151;
  overflow: hidden;
  border-radius: 4px;
}
.image-preview-item img {
  display: block;
  width: 100%;
  height: 86px;
  object-fit: contain;
  background: #fff;
  border-bottom: 1px solid var(--border-soft);
}
.image-preview-item span {
  display: block;
  padding: 6px 7px;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.translate-panel {
  margin: 0 0 18px;
  border: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 4px;
}
.translate-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  flex-wrap: wrap;
}
.translate-row span { font-weight: 600; color: #374151; }
.translate-target { width: auto; min-width: 120px; padding: 7px 9px; }
.translate-result {
  border-top: 1px solid var(--border-soft);
  background: #fff;
  padding: 14px 16px;
  line-height: 1.75;
  max-height: 360px;
  overflow: auto;
  white-space: normal;
}
.translate-error { color: var(--danger); }

/* Mail account drawer */
.account-page { max-width: 1480px; margin: 0 auto; }
.account-page-head { justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.account-page-head h1 { margin-bottom: 4px; }
.account-page-head p { margin: 0; }
.account-table-wrap { border: 1px solid var(--border-soft); }
.account-table th, .account-table td { white-space: nowrap; }
.account-table td:first-child { min-width: 220px; }
.account-table td:nth-child(3), .account-table td:nth-child(4) { min-width: 180px; }
.account-error { max-width: 260px; white-space: normal; margin-top: 4px; }
.account-actions { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.account-actions .btn, .account-actions button { padding: 7px 9px; }
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(17, 24, 39, .20);
}
.account-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 21;
  width: min(720px, calc(100vw - 64px));
  height: 100vh;
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -10px 0 28px rgba(15, 23, 42, .12);
  display: flex;
  flex-direction: column;
}
.drawer-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.drawer-header h1 { margin: 0 0 5px; }
.drawer-header p { margin: 0; }
.drawer-form {
  padding: 18px 20px;
  overflow-y: auto;
  display: grid;
  gap: 14px;
}
.form-section-title {
  color: #4b5563;
  font-weight: 700;
  border-top: 1px solid var(--border-soft);
  padding-top: 14px;
}
.drawer-footer {
  position: sticky;
  bottom: -18px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 0 2px;
  background: #fff;
  border-top: 1px solid var(--border-soft);
}
@media (max-width: 760px) {
  .account-drawer { width: 100vw; }
  .account-actions { flex-wrap: wrap; }
  .account-table th, .account-table td { white-space: normal; }
}
.grid-span-2 { grid-column: 1 / -1; }


/* Resizable columns */
.shell-resizer,
.mail-resizer {
  width: 6px;
  min-width: 6px;
  cursor: col-resize;
  background: transparent;
  border-left: 1px solid var(--border-soft);
  border-right: 1px solid var(--border-soft);
}
.shell-resizer:hover,
.mail-resizer:hover,
body.is-resizing .shell-resizer,
body.is-resizing .mail-resizer { background: #e5e7eb; }
body.is-resizing { user-select: none; cursor: col-resize; }
.inline-form { display: inline-flex; margin: 0; }
.btn-compact { padding: 7px 10px; font-size: 13px; }
.mail-list-actions { gap: 6px; }
.mail-list-actions .btn-light { background: #fff; }
.mail-list-actions .btn-light:hover { background: #f3f4f6; }
@media (max-width: 980px) {
  .shell-resizer, .mail-resizer { display: none; }
}

/* Mail bulk actions and compact toolbar */
.icon-only {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 16px;
  line-height: 1;
}
.mail-bulk-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: #fff;
}
.mail-select-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #4b5563;
  font-size: 13px;
}
.mail-row-card {
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 0;
  padding: 0;
}
.mail-row-check {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 18px 0 0 8px;
  cursor: pointer;
}
.mail-row-check input { width: 14px; height: 14px; }
.mail-row-link {
  min-width: 0;
  color: inherit;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 58px;
  gap: 9px;
  align-items: start;
  padding: 11px 10px 11px 6px;
}
.mail-row-link:hover { color: inherit; }
.mail-row-card.unread::before { left: 30px; }
.status-chip {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  color: #4b5563;
  border: 1px solid #d1d5db;
  background: #f8fafc;
  padding: 1px 5px;
  border-radius: 4px;
}
.compose-card { max-width: 980px; }
#draft-save-status { min-height: 20px; align-self: center; }
@media (max-width: 720px) {
  .mail-row-link { grid-template-columns: 34px minmax(0, 1fr); }
  .mail-row-right { grid-column: 2; grid-row: 2; text-align: left; justify-items: start; display: flex; gap: 8px; }
}

.scheduler-mail-accounts .side-nav-item em { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 2026-07-04: pagination, account identity, unread state, and floating notices */
.flash-stack {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 1200;
  width: min(520px, calc(100vw - 36px));
  margin: 0;
  pointer-events: none;
}
.flash { pointer-events: auto; box-shadow: 0 8px 24px rgba(15, 23, 42, .12); }
.flash-hiding { opacity: 0; transform: translateY(-8px); }
.pagination-info {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  padding: 0 4px;
}
.account-pagination,
.mail-pagination {
  align-items: center;
  padding: 10px 0 0;
}
.mail-pagination {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-top: 1px solid var(--border-soft);
  background: #fff;
}
.mail-row-card.unread {
  background: #fff;
}
.mail-row-card.unread .mail-row-title strong {
  font-weight: 800;
  color: #111827;
}
.mail-row-card.unread .mail-row-subtitle,
.mail-row-card.unread .mail-snippet {
  color: #1f2937;
  font-weight: 600;
}
.mail-row-card.read .mail-row-title strong {
  font-weight: 600;
  color: #374151;
}
.mail-row-card.read .mail-row-subtitle,
.mail-row-card.read .mail-snippet {
  color: #6b7280;
  font-weight: 400;
}
.mail-row-card.read { background: #fff; }
.mail-row-card.read .mail-avatar { opacity: .82; }
.mail-row-card.active.read,
.mail-row-card.active.unread { background: #eaf1ff; }
.unread-chip {
  color: #1d4ed8;
  border-color: #bfdbfe;
  background: #eff6ff;
}
.read-chip {
  color: #6b7280;
  border-color: #e5e7eb;
  background: #f9fafb;
}
.mail-account-line {
  margin-top: 4px;
  display: inline-block;
  max-width: 100%;
  color: #1f2937;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}
.mail-row-right em { max-width: none; white-space: normal; overflow: visible; text-overflow: clip; }

.config-sync-status {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 20px;
  padding: 14px;
  border: 1px solid var(--border-soft);
  background: #f8fafc;
}
.config-sync-status > div {
  min-width: 0;
}
.config-sync-status span {
  display: block;
  margin-bottom: 4px;
}
.config-sync-status strong {
  display: block;
  color: #1f2937;
  font-size: 14px;
  word-break: break-all;
}
.sync-help-box {
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border-soft);
  background: #f8fafc;
}
.sync-error-inline {
  margin: 0 0 16px;
}
@media (max-width: 1200px) {
  .config-sync-status {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* 2026-07-04: pinned/common mailbox groups and accounts */
.side-pin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: center;
  gap: 4px;
}
.side-pin-row .side-nav-item { min-width: 0; }
.side-pin-row .side-nav-item small {
  flex: 0 0 auto;
  color: #6b7280;
  font-size: 11px;
  border: 1px solid #d1d5db;
  padding: 0 4px;
  border-radius: 3px;
  line-height: 16px;
}
.side-pin-row form { margin: 0; }
.pin-toggle {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.pin-toggle:hover { background: #edf0f5; color: #374151; }
.pin-toggle.active { color: #374151; }
.side-collapsible {
  margin-top: 4px;
}
.side-collapsible summary {
  list-style: none;
  cursor: pointer;
  padding: 6px 8px;
  color: #6b7280;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.side-collapsible summary:hover { background: #edf0f5; color: #374151; }
.side-collapsible summary::-webkit-details-marker { display: none; }
.side-collapsible summary::before {
  content: '›';
  margin-right: 4px;
  transition: transform .12s ease;
}
.side-collapsible[open] summary::before { transform: rotate(90deg); }
.side-collapsible summary span:not(.sr-only) {
  margin-left: 0;
  color: #6b7280;
  font-size: 12px;
  font-weight: 500;
}
.side-collapsible-list {
  max-height: none;
  overflow: visible;
  padding: 2px 0 4px;
}
.side-collapsible-list .side-nav-item { background: transparent; }
.side-collapsible-list .side-nav-item.active { background: #e5eaf3; }

/* Inline collapse controls for long account/group lists */
.side-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 8px 6px;
}
.side-section-heading .side-section-title {
  margin: 0;
}
.side-inline-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: 38px;
  height: 24px;
  padding: 0 5px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}
.side-inline-toggle:hover {
  background: #edf0f5;
  color: #374151;
}
.side-toggle-icon {
  display: inline-block;
  font-size: 16px;
  transform-origin: center;
  transition: transform .12s ease;
}
.side-inline-toggle.open .side-toggle-icon {
  transform: rotate(90deg);
}
.side-toggle-count {
  font-weight: 600;
  color: inherit;
}
.side-toggle-list.is-collapsed {
  display: none;
}
.side-toggle-list {
  margin-top: 2px;
}

/* System config and theme support */
.settings-config-grid { align-items: start; }
.settings-preview-card { border: 1px solid var(--border-soft); background: var(--bg-soft); padding: 14px; border-radius: 5px; }

body.theme-dark {
  --bg: #111827;
  --bg-soft: #1f2937;
  --card: #172033;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #60a5fa;
  --primary-soft: #1e3a5f;
  --border: #374151;
  --border-soft: #2b3444;
  --rail: #0b1220;
  --rail-hover: #1f2937;
}
body.theme-dark,
body.theme-dark .app-shell,
body.theme-dark .app-main,
body.theme-dark .app-sidebar { background: var(--bg); color: var(--text); }
body.theme-dark .app-sidebar { border-right-color: var(--border); }
body.theme-dark .card,
body.theme-dark .page-heading,
body.theme-dark .mail-list-panel,
body.theme-dark .mail-reader-panel,
body.theme-dark .mail-panel-header,
body.theme-dark .reader-toolbar,
body.theme-dark .reader-card,
body.theme-dark .mail-body,
body.theme-dark .preview-pane,
body.theme-dark .account-drawer,
body.theme-dark .drawer-footer,
body.theme-dark .empty-state,
body.theme-dark .login-card { background: var(--card); color: var(--text); border-color: var(--border); }
body.theme-dark input[type="text"],
body.theme-dark input[type="password"],
body.theme-dark input[type="email"],
body.theme-dark input[type="number"],
body.theme-dark input[type="date"],
body.theme-dark input[type="datetime-local"],
body.theme-dark input[type="search"],
body.theme-dark select,
body.theme-dark textarea,
body.theme-dark .rich-editor { background: #0f172a; color: var(--text); border-color: var(--border); }
body.theme-dark label,
body.theme-dark .side-nav-item,
body.theme-dark .mail-row-title strong,
body.theme-dark .stat,
body.theme-dark h1,
body.theme-dark h2,
body.theme-dark h3 { color: var(--text); }
body.theme-dark .side-nav-item:hover,
body.theme-dark .mail-row-card:hover,
body.theme-dark tr:hover td { background: #1f2937; }
body.theme-dark .side-nav-item.active,
body.theme-dark .mail-row-card.active { background: #1e3a5f; color: var(--text); }
body.theme-dark .mail-searchbar,
body.theme-dark .mail-bulk-row,
body.theme-dark .mail-pagination,
body.theme-dark th,
body.theme-dark .subtle-box,
body.theme-dark .settings-preview-card,
body.theme-dark .translate-panel,
body.theme-dark .attachment-chip,
body.theme-dark .account-pill { background: #111827; border-color: var(--border); color: var(--text); }
body.theme-dark table,
body.theme-dark .translate-result { background: var(--card); color: var(--text); }
body.theme-dark .btn-light,
body.theme-dark .icon-btn,
body.theme-dark .round-tool { background: #111827; border-color: var(--border); color: var(--text); }
body.theme-dark .btn-light:hover,
body.theme-dark .icon-btn:hover,
body.theme-dark .round-tool:hover { background: #1f2937; color: #fff; }
body.theme-dark .mail-row-card.unread { background: #172033; }
body.theme-dark .mail-row-card.unread .mail-row-title strong { color: #f8fafc; }
body.theme-dark .side-brand-mark,
body.theme-dark .rail-user-avatar,
body.theme-dark .mail-avatar { background: #475569; }

/* Custom in-app confirmation dialog, replacing browser-native confirm for key actions. */
.confirm-modal[hidden] { display: none; }
.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: grid;
  place-items: center;
}
.confirm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .42);
}
.confirm-dialog {
  position: relative;
  width: min(520px, calc(100vw - 40px));
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, .22);
  padding: 18px 18px 16px;
  transform: translateY(6px);
  opacity: 0;
  transition: transform .14s ease, opacity .14s ease;
}
.confirm-modal.open .confirm-dialog {
  transform: translateY(0);
  opacity: 1;
}
.confirm-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
}
.confirm-message {
  color: var(--text);
  line-height: 1.65;
  margin-bottom: 18px;
  white-space: pre-wrap;
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.confirm-input {
  width: 100%;
  margin: 0 0 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--text);
  font: inherit;
}
.confirm-textarea {
  min-height: 150px;
  resize: vertical;
}
