:root {
  --bg: #ffffff;
  --panel: #f7f7f9;
  --hover: #f3f3f6;
  --active: #ececf1;
  --border: #ebebf0;
  --border-strong: #dcdce4;
  --text: #1d1d27;
  --text-2: #4a4a57;
  --muted: #8a8a97;
  --primary: #7b4ff0;
  --primary-hover: #6a3de0;
  --primary-soft: #f1ecfe;
  --primary-softer: #f8f5ff;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --ok: #17a34a;
  --ok-soft: #e9f8ef;
  --warn: #c27803;
  --warn-soft: #fff6e0;
  --star: #f5a524;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .04), 0 1px 4px rgba(20, 20, 40, .06);
  --shadow-lg: 0 18px 50px -12px rgba(30, 20, 70, .25);
  --font: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-brand: "Space Grotesk", "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

* { scrollbar-width: thin; scrollbar-color: #c9c9d3 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cfcfd8; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

.i {
  width: 16px; height: 16px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.spacer { flex: 1; }

/* ---------- Brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; flex-shrink: 0; }
.brand-text {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1;
}
.brand .w-light,
.brand .w-bold { font-weight: 700; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text);
  font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.soft { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.btn.soft:hover { background: #e7defd; }
.btn.outline { background: transparent; }
.btn.pill { border-radius: 999px; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn.lg { height: 42px; font-size: 14px; }
.danger-text { color: var(--danger) !important; }

.icon-btn {
  display: inline-grid; place-items: center; position: relative;
  width: 32px; height: 32px; border-radius: 8px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.icon-btn.active { background: var(--primary-soft); color: var(--primary); }
.icon-btn .dot { position: absolute; top: 6px; right: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input:disabled { background: var(--panel); color: var(--muted); }
input::placeholder, textarea::placeholder { color: #a5a5b1; }

.form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 550; font-size: 13px; color: var(--text); }
.field small { font-size: 12px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 15px; height: 15px; accent-color: var(--primary); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: end; }
.input-row { display: flex; gap: 8px; }

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 40px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border: 0; background: none; color: var(--text-2); cursor: pointer; display: grid; place-items: center; border-radius: 6px; }
.pw-toggle:hover { color: var(--text); }

.addr-input {
  display: flex; align-items: stretch;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg);
  overflow: hidden;
}
.addr-input:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.addr-input input { border: 0; box-shadow: none !important; flex: 1; min-width: 0; }
.addr-input .addr-domain {
  display: flex; align-items: center; padding: 0 12px; background: var(--panel);
  color: var(--muted); border-left: 1px solid var(--border-strong); white-space: nowrap;
}
.addr-input select { border: 0; border-left: 1px solid var(--border-strong); border-radius: 0; width: auto; background: var(--panel); box-shadow: none !important; }

/* ---------- Loading ---------- */
.boot { height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--primary-soft); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
.center-pad { padding: 48px; display: grid; place-items: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Auth pages ---------- */
.auth-page {
  position: relative; min-height: 100vh; display: flex; flex-direction: column;
  overflow: hidden; background: #fff;
}
.auth-page::before {
  content: ""; position: absolute; z-index: 0; pointer-events: none;
  width: 560px; height: 160vh; left: 50%; top: -30vh;
  transform: translateX(-20%) rotate(28deg);
  border-radius: 280px;
  background: linear-gradient(180deg, #f4effe 0%, #f8f5ff 55%, rgba(248, 245, 255, 0) 100%);
}
.auth-header {
  position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between;
  max-width: 1100px; width: 100%; margin: 0 auto; padding: 22px 32px;
}
.auth-lang { font-weight: 600; font-size: 13px; color: var(--text); display: flex; align-items: center; gap: 6px; }
.auth-main { position: relative; z-index: 1; flex: 1; display: flex; flex-direction: column; align-items: center; padding: 40px 16px; }
.auth-card {
  width: 100%; max-width: 388px; background: #fff;
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 24px -10px rgba(40, 20, 90, .14);
  padding: 28px 24px 22px;
}
.auth-card h1 { font-size: 19px; font-weight: 650; margin-bottom: 22px; }
.auth-card .form { gap: 18px; }
.auth-card .btn.primary { height: 40px; border-radius: 999px; font-size: 14px; }
.account-box {
  display: flex; align-items: center; gap: 12px; padding: 14px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.account-box .acc-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); flex-shrink: 0; }
.account-box .acc-icon .i { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.account-box .acc-email { font-size: 15px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.account-box > div { flex: 1; min-width: 0; }
.link-btn { border: 0; background: none; color: var(--primary); cursor: pointer; padding: 0; font-size: 12.5px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.link-btn:hover { text-decoration: underline; }
.link-btn .i { width: 13px; height: 13px; }
.auth-links { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; gap: 8px; }
.auth-foot { margin-top: 36px; color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- App shell ---------- */
.app {
  display: grid; grid-template-columns: 200px minmax(0, 1fr); grid-template-rows: 48px minmax(0, 1fr);
  height: 100vh;
}
.topbar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 12px;
  padding: 0 12px 0 14px; background: #fff; border-bottom: 1px solid var(--border);
}
.topbar .brand { width: 176px; flex-shrink: 0; }
.app-switch { display: flex; gap: 4px; margin-right: 24px; }
.menu-btn { display: none; }
.search {
  flex: 0 1 310px; display: flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 12px; border-radius: 999px; background: #fff;
  color: var(--text-2); border: 1px solid var(--border-strong); transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search input { border: 0; background: transparent; height: 100%; padding: 0; box-shadow: none !important; font-size: 13px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.top-pill { display: inline-flex; align-items: center; height: 26px; padding: 0 12px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-weight: 600; font-size: 12px; margin-right: 8px; white-space: nowrap; }
.top-pill:hover { background: #e7defd; text-decoration: none; }

.user-menu { position: relative; margin-left: 4px; }
.avatar-btn { border: 0; background: none; padding: 0; border-radius: 50%; cursor: pointer; display: grid; }
.avatar-btn:hover .avatar { box-shadow: 0 0 0 3px var(--primary-soft); }
.avatar {
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: 30px; height: 30px; border-radius: 50%; font-weight: 500; font-size: 13px;
  background: var(--primary-soft); color: var(--primary);
}
.avatar.sm { width: 26px; height: 26px; font-size: 12px; }
.avatar.lg { width: 40px; height: 40px; font-size: 15px; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; min-width: 250px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px;
}
.dropdown-head { display: flex; gap: 12px; align-items: center; padding: 10px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.dropdown-head > div { min-width: 0; }
.dropdown-head .small { overflow: hidden; text-overflow: ellipsis; }
.dropdown-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px;
  border: 0; background: none; border-radius: 6px; color: var(--text); cursor: pointer; text-align: left;
}
.dropdown-item:hover { background: var(--hover); text-decoration: none; }
.dropdown-item.checked { color: var(--primary); font-weight: 600; }
.dropdown-label { padding: 6px 10px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.sidebar {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 8px 12px;
  background: #fff; border-right: 1px solid var(--border); overflow-y: auto;
}
.compose-btn {
  height: 36px; border-radius: 999px; font-size: 13px; font-weight: 600; margin: 0 2px 12px;
  background: var(--primary); border-color: var(--primary);
}
.folders { display: grid; gap: 1px; }
.folder {
  display: flex; align-items: center; gap: 10px; height: 30px; padding: 0 8px 0 10px;
  border-radius: 6px; color: var(--text); font-size: 13px;
}
.folder .i { width: 15px; height: 15px; color: var(--text-2); }
.folder:hover { background: var(--hover); text-decoration: none; }
.folder.active { background: var(--active); font-weight: 500; }
.folder .badge { margin-left: auto; font-size: 11.5px; font-weight: 600; color: var(--primary); }
.folder .badge.gray { color: var(--muted); font-weight: 500; }
.nav-sep { height: 1px; background: var(--border); margin: 12px 4px; }
.nav-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 6px 10px; font-weight: 600; font-size: 13px; }
.sidebar-foot { margin-top: auto; padding: 14px 4px 0; border-top: 1px solid var(--border); }
.storage-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-weight: 600; }
.usage-bar { height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; margin-bottom: 6px; }
.usage-bar span { display: block; height: 100%; background: var(--primary); border-radius: 2px; min-width: 2px; }
.usage-bar.warn span { background: var(--danger); }
.usage-row { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-2); }
.scrim { display: none; }

.main { min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; background: #fff; }

/* ---------- Mail layout ---------- */
.mail-layout { display: grid; grid-template-columns: minmax(300px, 360px) minmax(0, 1fr); height: 100%; min-height: 0; }
.list-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: #fff; }
.list-toolbar {
  display: flex; align-items: center; gap: 2px; height: 46px; padding: 0 8px 0 12px; flex-shrink: 0;
}
.list-toolbar .title { font-weight: 600; font-size: 14px; margin-left: 4px; }
.pager-info { color: var(--muted); font-size: 11.5px; margin: 0 2px; white-space: nowrap; }
.bulk { display: flex; align-items: center; gap: 0; }
.filter-wrap { position: relative; }
.filter-wrap .dropdown { min-width: 190px; }
.search-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 12px; margin: 0 8px 6px; border-radius: 8px; background: var(--primary-softer); font-size: 12px;
}
.message-list { flex: 1; overflow-y: auto; padding: 0 6px 8px; }
.chk { display: inline-grid; place-items: center; width: 22px; height: 22px; cursor: pointer; flex-shrink: 0; }
.chk input { width: 14px; height: 14px; accent-color: var(--primary); cursor: pointer; margin: 0; }

.msg-row {
  position: relative; display: grid; grid-template-columns: 22px 32px minmax(0, 1fr); gap: 8px;
  align-items: center; padding: 9px 8px 9px 6px; border-radius: 8px; margin-bottom: 2px;
  cursor: pointer; transition: background .1s;
}
.msg-row:hover { background: var(--hover); }
.msg-row.selected { background: var(--primary-softer); }
.msg-row.active { background: var(--active); }
.msg-row .avatar { width: 32px; height: 32px; font-size: 14px; }
.msg-main { min-width: 0; }
.msg-top { display: flex; align-items: center; gap: 6px; }
.msg-from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12.5px; }
.msg-date { color: var(--text-2); font-size: 11px; white-space: nowrap; }
.msg-subject { display: flex; align-items: center; gap: 5px; overflow: hidden; white-space: nowrap; color: var(--text); font-size: 13px; margin-top: 1px; }
.msg-subject span { overflow: hidden; text-overflow: ellipsis; }
.msg-subject .i { width: 12px; height: 12px; color: var(--muted); }
.msg-snippet { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.msg-row.unread .msg-from { color: var(--text); font-weight: 700; }
.msg-row.unread .msg-from::before {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
  margin-right: 5px; vertical-align: 2px;
}
.msg-row.unread .msg-subject { font-weight: 600; }
.msg-row .row-star { color: var(--star); }
.msg-row .row-star .i { width: 12px; height: 12px; fill: currentColor; }
.msg-row .draft-tag { color: var(--danger); font-weight: 500; }

.empty {
  display: grid; place-items: center; align-content: center; text-align: center; gap: 4px; padding: 56px 24px; color: var(--muted);
}
.empty h3 { color: var(--text); font-size: 15px; font-weight: 600; }
.empty p { margin: 0; }
.empty-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--panel); margin-bottom: 8px; color: var(--muted); }
.empty-icon .i { width: 22px; height: 22px; }
.envelope-art { width: 50px; height: 40px; margin-bottom: 18px; }

/* ---------- Reader ---------- */
.reader-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #fff; }
.reader-toolbar {
  display: flex; align-items: center; gap: 2px; height: 46px; padding: 0 12px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.tb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 6px; }
.reader-scroll { flex: 1; overflow-y: auto; padding: 22px 28px 40px; }
.reader-subject { font-size: 19px; font-weight: 600; margin-bottom: 18px; overflow-wrap: anywhere; }
.reader-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 18px; }
.reader-from { flex: 1; min-width: 0; }
.reader-from .muted { overflow-wrap: anywhere; }
.reader-date { white-space: nowrap; color: var(--text-2); }
.reader-content { min-height: 60px; }
.mail-frame { width: 100%; border: 0; display: block; min-height: 80px; background: #fff; }
.plain { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; }
.attachments { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.attachments h4 { margin: 0 0 10px; font-size: 12px; color: var(--muted); font-weight: 600; }
.att-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.att {
  display: flex; align-items: center; gap: 10px; width: 230px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px; color: var(--text); background: #fff;
}
.att:hover { background: var(--hover); text-decoration: none; }
.att .att-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); flex-shrink: 0; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.att .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.att > div { min-width: 0; flex: 1; }
.reader-actions { display: flex; gap: 8px; margin-top: 26px; flex-wrap: wrap; }
.reader-actions .btn { border-radius: 999px; }
.reader-empty { flex: 1; }
.mobile-only { display: none; }

/* ---------- Compose ---------- */
.compose {
  position: fixed; right: 20px; bottom: 0; z-index: 40; width: 560px; max-width: calc(100vw - 32px);
  height: min(600px, calc(100vh - 70px)); display: flex; flex-direction: column;
  background: #fff; border: 1px solid var(--border); border-bottom: 0;
  border-radius: 12px 12px 0 0; box-shadow: var(--shadow-lg); overflow: hidden;
}
.compose.min { height: auto; }
.compose.min form { display: none; }
.compose.max { right: 50%; bottom: 50%; transform: translate(50%, 50%); width: min(940px, calc(100vw - 48px)); height: calc(100vh - 96px); border-radius: 12px; border-bottom: 1px solid var(--border); }
.compose-head {
  display: flex; align-items: center; gap: 2px; padding: 6px 8px 6px 16px; background: var(--panel);
  font-weight: 600; cursor: pointer; user-select: none; border-bottom: 1px solid var(--border);
}
.compose-head .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-head .icon-btn { width: 28px; height: 28px; }
.compose form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.c-row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); padding: 0 16px; }
.c-row > label { color: var(--muted); width: 40px; flex-shrink: 0; }
.c-row input, .c-row select { border: 0; height: 40px; padding: 0; box-shadow: none !important; background: transparent; }
.c-row select { width: auto; }
.c-row .link-btn { color: var(--muted); }
.editor {
  flex: 1; overflow-y: auto; padding: 14px 16px; outline: none; font-size: 14px; line-height: 1.6; min-height: 120px;
  overflow-wrap: anywhere;
}
.editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.editor blockquote { margin: 0 0 0 .8ex; border-left: 2px solid var(--border-strong); padding-left: 1ex; color: var(--muted); }
.editor-toolbar { display: flex; gap: 2px; padding: 4px 10px; border-top: 1px solid var(--border); }
.editor-toolbar .icon-btn { width: 30px; height: 30px; border-radius: 6px; font-weight: 700; font-size: 13px; }
.c-files { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; }
.c-files:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 260px; padding: 3px 4px 3px 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px; font-size: 12px;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); display: grid; place-items: center; padding: 2px; border-radius: 50%; }
.chip button:hover { background: var(--hover); color: var(--text); }
.chip .i { width: 13px; height: 13px; }
.compose-foot { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--border); }
.compose-foot .btn.primary { border-radius: 999px; padding: 0 22px; }

/* ---------- Pages (settings / admin) ---------- */
.page { flex: 1; min-width: 0; overflow-x: hidden; overflow-y: auto; padding: 28px 36px 64px; background: #ececf3; }
.page-inner { max-width: 1080px; width: 100%; min-width: 0; margin: 0 auto; display: grid; gap: 24px; align-content: start; }
.page-inner.narrow { max-width: 700px; }
#orgBody,
#adminBody {
  display: grid;
  gap: 20px;
  align-content: start;
  min-width: 0;
}
.page-head h1 { font-size: 21px; font-weight: 650; }
.page-head p { margin: 6px 0 0; line-height: 1.45; }
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  min-width: 0;
  max-width: 100%;
  box-shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 10px 28px -18px rgba(20, 20, 40, .18);
}
.card > h2:first-child { margin: 0 0 6px; font-size: 16px; font-weight: 650; }
.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: -4px 0 0;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 17px; }
.card-head + .note { margin-top: 16px; }
.card-head + .setup-steps,
.card > .note + .setup-steps { margin-top: 16px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 8px 20px -14px rgba(20, 20, 40, .14);
}
.stat .label { color: var(--muted); font-size: 12px; font-weight: 550; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-strong);
  margin-bottom: 2px;
}
.tab { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 16px -24px -24px;
  -webkit-overflow-scrolling: touch;
}
.table { width: 100%; border-collapse: collapse; table-layout: auto; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 22px; border-bottom: 1px solid var(--border); background: var(--panel); }
.table td { padding: 12px 22px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.cell-user { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.cell-user > div { min-width: 0; flex: 1; }
.cell-user .strong { overflow-wrap: anywhere; line-height: 1.35; }
.mini-bar { width: 120px; max-width: 100%; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; margin-bottom: 4px; }
.mini-bar span { display: block; height: 100%; background: var(--primary); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); font-size: 11px; font-weight: 600; margin-left: 6px; vertical-align: middle; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 12px; font-size: 11.5px; font-weight: 600; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--danger-soft); color: var(--danger); }
.inline-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin: 0; }
.card .inline-form { margin-top: 4px; }
.inline-form .addr-input { flex: 1 1 280px; }
.inline-form select { flex: 0 1 260px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 12px; }
.steps li::marker { font-weight: 700; color: var(--primary); }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; overflow-wrap: anywhere;
}
.dns-table td, .dns-table th { padding: 8px 12px; font-size: 12.5px; }
.dns-table td:first-child, .dns-table th:first-child { padding-left: 22px; }
.dns-table td:last-child, .dns-table th:last-child { padding-right: 22px; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--primary-soft); color: var(--primary); }
.head-pill { margin-left: 8px; vertical-align: middle; }
.card-intro { margin: 0 0 18px; line-height: 1.5; max-width: 56ch; }
.back-link { justify-self: start; font-size: 13px; }
.back-link .i { width: 15px; height: 15px; }
.error-text { color: var(--danger); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.dns-content { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; overflow-wrap: anywhere; }
.type-badge { display: inline-block; min-width: 46px; text-align: center; padding: 1px 6px; border-radius: 6px; background: var(--panel); border: 1px solid var(--border); font-size: 11px; font-weight: 700; }
.lock-tag { display: inline-flex; align-items: center; gap: 4px; background: var(--panel); color: var(--muted); }
.lock-tag .i, .tag .i { width: 11px; height: 11px; }
.empty.compact { padding: 28px 16px; }

.note { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: #7a4b00; margin-bottom: 14px; }
.note .i { flex: none; width: 16px; height: 16px; margin-top: 1px; }
.note.error { background: var(--danger-soft); color: #9b1c20; }
.modal .note { margin: 0; }

.domain-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setup-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.setup-steps li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 14px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.setup-steps li:first-child { border-top: 0; padding-top: 2px; }
.setup-steps li:last-child { padding-bottom: 2px; }
.setup-steps strong { font-weight: 600; font-size: 13.5px; }
.setup-steps p { margin: 4px 0 8px; }
.setup-steps p:last-child { margin-bottom: 0; }
.step-body { margin-top: 4px; color: var(--text-2); }
.step-dot { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--panel); border: 1px solid var(--border-strong); color: var(--muted); }
.step-dot .i { width: 13px; height: 13px; }
.setup-steps li.done .step-dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.setup-steps li.current .step-dot { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.setup-steps li.error .step-dot { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.ns-list { display: grid; gap: 6px; margin: 10px 0; }
.copy-row { display: flex; align-items: center; gap: 6px; }
.copy-row .code { font-size: 13px; padding: 4px 10px; }
.copy-row .icon-btn { width: 28px; height: 28px; }

.provider-list { display: grid; gap: 10px; }
.provider { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); cursor: pointer; }
.provider:has(input:checked) { border-color: var(--primary); background: var(--primary-softer); }
.provider input { margin-top: 3px; accent-color: var(--primary); }
.provider.disabled { opacity: .55; cursor: not-allowed; }

.search-spacer { flex: 1; display: flex; align-items: center; min-width: 0; }
.org-name { font-weight: 600; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth-sub { margin: -14px 0 20px; }
.auth-alt { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); text-align: center; color: var(--text-2); font-size: 12.5px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: rgba(20, 16, 40, .42); animation: fade .15s ease;
}
.modal {
  width: 100%; max-width: 460px; max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); animation: pop .18s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 6px 22px; }
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 8px 22px 18px; overflow-y: auto; display: grid; gap: 14px; }
.modal-body p { margin: 0; color: var(--text-2); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.modal-foot .btn { border-radius: 999px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 18px;
  background: #24212f; color: #fff; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500;
  animation: pop .2s ease; max-width: min(520px, calc(100vw - 32px));
}
.toast.error { background: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .mail-layout { grid-template-columns: minmax(280px, 320px) minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .top-pill, .app-switch { display: none; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 52px minmax(0, 1fr); }
  .topbar {
    padding: 0 max(8px, env(safe-area-inset-left)) 0 max(8px, env(safe-area-inset-right));
    gap: 6px;
  }
  .topbar .brand { width: auto; }
  .topbar .brand .brand-text { display: none; }
  .menu-btn { display: inline-grid; }
  .search { flex: 1; min-width: 0; }
  .hide-sm { display: none !important; }
  .sidebar {
    position: fixed; z-index: 60; top: 0; bottom: 0; left: 0; width: min(280px, 86vw);
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg);
  }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, .35); }
  .mail-layout { grid-template-columns: 1fr; }
  .mail-layout .reader-pane { display: none; }
  .mail-layout.reading .list-pane { display: none; }
  .mail-layout.reading .reader-pane { display: flex; }
  .list-pane { border-right: 0; }
  .mobile-only { display: inline-grid; }
  .reader-scroll { padding: 18px 16px calc(32px + env(safe-area-inset-bottom)); }
  .reader-subject { font-size: 17px; }
  .page {
    padding: 18px max(12px, env(safe-area-inset-left)) calc(48px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
  }
  .compose, .compose.max {
    right: 0; left: 0; bottom: 0; top: 0; transform: none; width: 100%; max-width: none; height: 100%;
    border-radius: 0; padding-bottom: env(safe-area-inset-bottom);
  }
  .grid2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
  #orgBody,
  #adminBody { gap: 16px; }
  .auth-header { padding: 16px max(16px, env(safe-area-inset-left)) 16px max(16px, env(safe-area-inset-right)); }
  .auth-main { padding: 24px 16px 32px; }
  .auth-card { padding: 22px 18px 18px; }
  .card { padding: 18px 16px; }
  .card-head { flex-wrap: wrap; gap: 10px; align-items: stretch; }
  .card-head > .btn,
  .card-head > a.btn { flex: 1 1 100%; justify-content: center; min-height: 40px; }
  .card-head h2 { flex: 1 1 100%; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex-shrink: 0; white-space: nowrap; }
  .table-wrap { margin: 14px 0 0; overflow: visible; }
  .table:not(.table-stack) th,
  .table:not(.table-stack) td { padding-left: 12px; padding-right: 12px; font-size: 12.5px; }
  .table.table-stack { display: block; width: 100%; }
  .table.table-stack thead { display: none; }
  .table.table-stack tbody { display: grid; gap: 12px; }
  .table.table-stack tr { display: block; padding: 14px 14px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--panel); }
  .table.table-stack td {
    display: grid;
    grid-template-columns: minmax(76px, 38%) minmax(0, 1fr);
    gap: 4px 12px;
    align-items: start;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
  }
  .table.table-stack tr:last-child td { border-bottom: 0; }
  .table.table-stack td:last-child { border-bottom: 0; padding-bottom: 0; }
  .table.table-stack td::before {
    content: attr(data-label);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-weight: 600;
    line-height: 1.4;
    padding-top: 2px;
  }
  .table.table-stack td[data-label=""]::before,
  .table.table-stack td:not([data-label])::before { display: none; }
  .table.table-stack td.col-primary {
    display: block;
    padding: 0 0 12px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-strong);
  }
  .table.table-stack td.col-primary::before { display: none; }
  .table.table-stack td.hide-sm { display: none; }
  .table.table-stack td.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    white-space: normal;
    padding-top: 12px;
    margin-top: 4px;
    border-bottom: 0;
    border-top: 1px dashed var(--border-strong);
  }
  .table.table-stack td.actions::before { display: none; }
  .table.table-stack td[colspan] { display: block; grid-column: 1 / -1; padding-top: 0; }
  .table.table-stack td[colspan]::before { display: none; }
  .table.table-stack .dns-content { max-width: none; white-space: normal; text-overflow: unset; overflow: visible; }
  .table.table-stack .mini-bar { width: 100%; max-width: 220px; }
  .page-head h1 { font-size: 19px; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form .btn { width: 100%; }
  .domain-title { flex-wrap: wrap; }
  .card-intro { flex-wrap: wrap; }
  .toasts { bottom: calc(16px + env(safe-area-inset-bottom)); }
}

@media (max-width: 480px) {
  .auth-page::before { width: 120vw; opacity: .85; }
  .auth-card h1 { font-size: 18px; }
  .auth-links { flex-direction: column; align-items: stretch; gap: 12px; }
  .auth-foot { margin-top: 24px; padding: 0 8px; }
  .addr-input { flex-direction: column; align-items: stretch; }
  .addr-input input { min-height: 44px; }
  .addr-input .addr-domain,
  .addr-input select {
    border-left: 0;
    border-top: 1px solid var(--border-strong);
    width: 100%;
    justify-content: center;
    min-height: 44px;
    padding: 10px 12px;
  }
  .stats { grid-template-columns: 1fr; }
  .stat .value { font-size: 20px; }
  .modal { max-height: calc(100dvh - 24px); border-radius: 12px 12px 0 0; align-self: end; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .list-toolbar { flex-wrap: wrap; gap: 8px; }
  .msg-row { padding-left: 12px; padding-right: 12px; }
  .c-row { flex-wrap: wrap; padding: 0 12px; }
  .c-row > label { width: 100%; padding-top: 8px; }
  .compose-foot { flex-wrap: wrap; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .compose-foot .btn.primary { flex: 1 1 100%; min-height: 44px; }
  .provider-list .provider { padding: 14px 12px; }
}
