/* ============================================================
   VinzMailServer 2.0 — modern professional UI
   Design system: dual theme (light/dark), fluid responsive,
   SVG icons, split-view reading, command palette.
   ============================================================ */

:root {
  --font: "Inter var", Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text",
          "Segoe UI Variable", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", SFMono-Regular, ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;

  --accent-1: #4f6df5;
  --accent-2: #7c4df5;
  --grad: linear-gradient(135deg, var(--accent-1), var(--accent-2));

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 9px;

  --t-fast: 140ms cubic-bezier(.4,0,.2,1);
  --t-med: 240ms cubic-bezier(.4,0,.2,1);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f8;
  --bg-grad: radial-gradient(1200px 600px at 85% -10%, rgba(124,77,245,.09), transparent 60%),
             radial-gradient(1000px 500px at -10% 110%, rgba(79,109,245,.08), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f7f8fd;
  --surface-3: #eff1fa;
  --ink: #16192b;
  --ink-2: #4a5069;
  --ink-3: #8a90a8;
  --line: #e4e7f2;
  --line-soft: #eef0f8;
  --hover: #f1f3fb;
  --active: #e8ecfd;
  --accent: #4f5ff0;
  --accent-ink: #3843d0;
  --accent-soft: #eceffe;
  --accent-softer: #f4f6ff;
  --danger: #dc3d43;
  --danger-soft: #fdeceb;
  --warn: #b96a00;
  --warn-soft: #fdf3e2;
  --ok: #1a7f4e;
  --ok-soft: #e6f6ec;
  --gold: #eab308;
  --shadow-1: 0 1px 2px rgba(22,25,43,.05), 0 2px 8px rgba(22,25,43,.05);
  --shadow-2: 0 4px 12px rgba(22,25,43,.08), 0 12px 32px rgba(22,25,43,.10);
  --shadow-3: 0 8px 24px rgba(22,25,43,.14), 0 24px 64px rgba(22,25,43,.18);
  --row-unread: #ffffff;
  --row-read: transparent;
  --scrollbar: #ccd1e2;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0f1a;
  --bg-grad: radial-gradient(1200px 600px at 85% -10%, rgba(124,77,245,.14), transparent 60%),
             radial-gradient(1000px 500px at -10% 110%, rgba(79,109,245,.10), transparent 60%);
  --surface: #141828;
  --surface-2: #191e31;
  --surface-3: #1f2439;
  --ink: #e7eaf6;
  --ink-2: #a7adc7;
  --ink-3: #6d7390;
  --line: #262c44;
  --line-soft: #1f2439;
  --hover: #1c2136;
  --active: #232a45;
  --accent: #7b8cff;
  --accent-ink: #9daaff;
  --accent-soft: #232a4d;
  --accent-softer: #1a1f38;
  --danger: #ff6b6e;
  --danger-soft: #3a1e24;
  --warn: #f0a848;
  --warn-soft: #35281a;
  --ok: #4ade80;
  --ok-soft: #16301f;
  --gold: #facc15;
  --shadow-1: 0 1px 2px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.35);
  --shadow-2: 0 4px 12px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.45);
  --shadow-3: 0 8px 24px rgba(0,0,0,.5), 0 24px 64px rgba(0,0,0,.6);
  --row-unread: #171c30;
  --row-read: transparent;
  --scrollbar: #333a58;
}

/* ---------------- base ---------------- */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#app { height: 100%; }
button { font-family: inherit; cursor: pointer; color: inherit; }
input, textarea, select { font-family: inherit; font-size: 14px; color: var(--ink); }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--accent-soft); }

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

.ic { flex: none; vertical-align: -3px; }

/* ---------------- boot splash ---------------- */
.boot-splash { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.boot-name { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.boot-name span { font-weight: 400; color: var(--ink-3); }
.boot-spinner, .spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- loading bar ---------------- */
.loading-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 2.5px; z-index: 300;
  background: var(--grad); background-size: 200%;
  animation: lb 1s linear infinite; display: none;
}
.loading-bar.on { display: block; }
@keyframes lb { from { background-position: 0 0; } to { background-position: 200% 0; } }

/* ---------------- auth & setup ---------------- */
.auth-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 28px 16px; position: relative; }
.auth-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px;
  padding: 40px 42px 36px; width: 100%; max-width: 430px; box-shadow: var(--shadow-2);
  animation: rise .35s cubic-bezier(.2,.8,.3,1);
}
.auth-card.wide { max-width: 640px; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-brand .name { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.auth-brand .name span { font-weight: 400; color: var(--ink-3); }
.auth-title { font-size: 25px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 4px; }
.auth-sub { color: var(--ink-2); font-size: 14px; margin-bottom: 26px; line-height: 1.5; }
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; font-weight: 550; }
.field input, .field select {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: var(--r-sm);
  font-size: 14.5px; outline: none; background: var(--surface-2); color: var(--ink);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.field input:focus, .field select:focus {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--accent) 18%, transparent);
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }

.btn {
  border: none; border-radius: 10px; padding: 10px 20px; font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform var(--t-fast), box-shadow var(--t-fast), background var(--t-fast), opacity var(--t-fast);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 2px 10px color-mix(in srgb, var(--accent-1) 40%, transparent); }
.btn-primary:hover { box-shadow: 0 4px 16px color-mix(in srgb, var(--accent-1) 55%, transparent); }
.btn-primary:disabled { opacity: .55; cursor: default; box-shadow: none; }
.btn-ghost { background: transparent; color: var(--accent-ink); }
.btn-ghost:hover { background: var(--accent-softer); }
.btn-outline { background: var(--surface); color: var(--ink); border: 1.5px solid var(--line); }
.btn-outline:hover { border-color: var(--ink-3); background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 14px; font-size: 13px; border-radius: 8px; }

.auth-actions { display: flex; justify-content: flex-end; align-items: center; margin-top: 24px; gap: 10px; }
.auth-error {
  background: var(--danger-soft); color: var(--danger); border-radius: var(--r-sm);
  padding: 11px 14px; font-size: 13.5px; margin-bottom: 16px; display: none; line-height: 1.45;
}
.auth-error.show { display: block; }
.setup-section {
  font-size: 11.5px; font-weight: 700; color: var(--accent-ink); text-transform: uppercase;
  letter-spacing: .09em; margin: 26px 0 14px; display: flex; align-items: center; gap: 10px;
}
.setup-section::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; line-height: 1.5; }
.checkline { display: flex; gap: 9px; align-items: flex-start; font-size: 13px; color: var(--ink-2); line-height: 1.45; }
.checkline input { margin-top: 2px; accent-color: var(--accent); }
.corner-actions { position: absolute; top: 18px; right: 20px; display: flex; gap: 6px; }

/* ---------------- app shell ---------------- */
.shell {
  display: grid; height: 100%;
  grid-template-rows: 60px 1fr;
  grid-template-columns: 248px 1fr;
  grid-template-areas: "top top" "side main";
  transition: grid-template-columns var(--t-med);
}
.shell.nav-hidden { grid-template-columns: 0 1fr; }
.shell.nav-hidden .sidebar { opacity: 0; pointer-events: none; }

/* topbar */
.topbar { grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 16px 0 10px; min-width: 0; }
.iconbtn {
  background: none; border: none; border-radius: 10px; width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2);
  transition: background var(--t-fast), color var(--t-fast); position: relative; flex: none;
}
.iconbtn:hover { background: var(--hover); color: var(--ink); }
.iconbtn:disabled { opacity: .35; cursor: default; }
.iconbtn.active { color: var(--accent-ink); background: var(--accent-soft); }
.brand { display: flex; align-items: center; gap: 10px; margin-right: 14px; white-space: nowrap; user-select: none; }
.brand .name { font-size: 16.5px; font-weight: 700; letter-spacing: -.01em; }
.brand .name span { font-weight: 400; color: var(--ink-3); }

.searchbox {
  flex: 1; max-width: 640px; display: flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 0 6px 0 12px; height: 42px; min-width: 0;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.searchbox:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--accent) 15%, transparent); }
.searchbox .ic { color: var(--ink-3); }
.searchbox input { flex: 1; border: none; background: transparent; outline: none; font-size: 14.5px; height: 100%; min-width: 0; color: var(--ink); }
.searchbox input::placeholder { color: var(--ink-3); }
.kbd-chip {
  font-size: 11px; font-family: var(--mono); color: var(--ink-3); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 7px; white-space: nowrap; user-select: none;
}
.top-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.lang-btn {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 9px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em; padding: 7px 10px; color: var(--ink-2);
}
.lang-btn:hover { border-color: var(--ink-3); color: var(--ink); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; border: none; color: #fff; font-weight: 650;
  font-size: 13.5px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--grad); flex: none; letter-spacing: .02em;
  transition: box-shadow var(--t-fast);
}
.avatar:hover { box-shadow: 0 0 0 4px var(--accent-soft); }

/* sidebar */
.sidebar {
  grid-area: side; padding: 10px 12px 24px; overflow-y: auto; overflow-x: hidden;
  transition: opacity var(--t-med); display: flex; flex-direction: column; gap: 2px;
}
.compose-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--grad); color: #fff; border: none; border-radius: 14px;
  padding: 13px 18px; font-size: 14px; font-weight: 650; margin: 4px 2px 16px;
  box-shadow: 0 3px 14px color-mix(in srgb, var(--accent-1) 42%, transparent);
  transition: box-shadow var(--t-fast), transform var(--t-fast);
}
.compose-btn:hover { box-shadow: 0 6px 20px color-mix(in srgb, var(--accent-1) 55%, transparent); transform: translateY(-1px); }
.compose-btn:active { transform: none; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%; border: none; background: none;
  text-align: left; padding: 8.5px 12px; border-radius: 11px; font-size: 13.5px; font-weight: 500;
  color: var(--ink-2); transition: background var(--t-fast), color var(--t-fast); min-height: 37px;
}
.nav-item .ic { color: var(--ink-3); transition: color var(--t-fast); }
.nav-item:hover { background: var(--hover); color: var(--ink); }
.nav-item:hover .ic { color: var(--ink-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 650; }
.nav-item.active .ic { color: var(--accent-ink); }
.nav-item .ni-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .ni-count {
  font-size: 11px; font-weight: 700; color: var(--accent-ink); background: var(--accent-soft);
  border-radius: 20px; padding: 2px 8px; min-width: 20px; text-align: center;
}
.nav-item.active .ni-count { background: var(--surface); }
.nav-head {
  font-size: 10.5px; color: var(--ink-3); padding: 16px 12px 6px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
}
.sidebar-foot { margin-top: auto; padding: 16px 12px 0; font-size: 11px; color: var(--ink-3); }

/* main area */
.main {
  grid-area: main; min-width: 0; min-height: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); margin: 0 14px 14px 2px; overflow: hidden;
  box-shadow: var(--shadow-1);
}

/* mail split grid */
.mailgrid { flex: 1; display: grid; grid-template-columns: 1fr; min-height: 0; position: relative; }
.listpane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.readerpane { display: none; min-width: 0; min-height: 0; border-left: 1px solid var(--line); background: var(--surface); }
@media (min-width: 1100px) {
  .mailgrid.reading { grid-template-columns: minmax(340px, 40%) 1fr; }
  .mailgrid.reading .readerpane { display: flex; flex-direction: column; }
  .mailgrid.reading .mrow.open { background: var(--active); }
}
@media (max-width: 1099.5px) {
  .mailgrid.reading .readerpane { display: flex; flex-direction: column; position: absolute; inset: 0; z-index: 5; border-left: none; }
}

/* toolbar */
.toolbar {
  display: flex; align-items: center; gap: 2px; padding: 8px 12px; border-bottom: 1px solid var(--line-soft);
  min-height: 52px; flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }
.pager { font-size: 12px; color: var(--ink-3); margin: 0 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.selinfo { font-size: 12.5px; font-weight: 600; color: var(--accent-ink); margin: 0 8px; white-space: nowrap; }

.checkwrap { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; }
input[type="checkbox"].vm-check {
  appearance: none; width: 17px; height: 17px; border: 1.7px solid var(--ink-3); border-radius: 5px;
  display: inline-grid; place-content: center; background: transparent; cursor: pointer; margin: 0;
  transition: background var(--t-fast), border-color var(--t-fast);
}
input[type="checkbox"].vm-check::before {
  content: ""; width: 9px; height: 9px; transform: scale(0); transition: transform 90ms ease-in-out;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  background: #fff;
}
input[type="checkbox"].vm-check:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"].vm-check:checked::before { transform: scale(1); }

/* message list */
.mlist { flex: 1; overflow-y: auto; min-height: 0; }
.mrow {
  display: flex; align-items: center; gap: 2px; padding: 0 14px 0 8px; height: 46px;
  cursor: pointer; position: relative; font-size: 13.5px; border-bottom: 1px solid var(--line-soft);
  background: var(--row-read); transition: background var(--t-fast);
}
.mrow:hover { background: var(--hover); }
.mrow.unread { background: var(--row-unread); }
.mrow.unread::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 22px; border-radius: 0 3px 3px 0; background: var(--grad);
}
.mrow.selected { background: var(--accent-softer); }
.mrow .checkwrap { width: 34px; height: 34px; }
.star-btn {
  background: none; border: none; width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink-3); opacity: .6;
  transition: color var(--t-fast), opacity var(--t-fast);
}
.star-btn:hover { opacity: 1; color: var(--ink-2); background: var(--surface-3); }
.star-btn.on { color: var(--gold); opacity: 1; }
.star-btn.on svg { fill: var(--gold); }
.mfrom { width: 190px; flex: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 640; padding-left: 6px; }
.mrow.read .mfrom { font-weight: 450; color: var(--ink-2); }
.msub { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 620; min-width: 0; display: flex; align-items: center; gap: 8px; }
.msub .draft-tag { color: var(--danger); font-weight: 650; }
.mrow.read .msub { font-weight: 400; color: var(--ink-2); }
.mclip { flex: none; color: var(--ink-3); display: inline-flex; }
.mdate { flex: none; min-width: 74px; text-align: right; font-size: 11.5px; font-weight: 650; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.mrow.read .mdate { font-weight: 450; color: var(--ink-3); }
.row-actions { display: none; align-items: center; gap: 2px; flex: none; margin-left: 4px; }
.row-actions .iconbtn { width: 32px; height: 32px; border-radius: 8px; }
@media (hover: hover) and (min-width: 768px) {
  .mrow:hover .mdate { display: none; }
  .mrow:hover .row-actions { display: inline-flex; }
}

/* skeleton */
.sk-row { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); }
.sk { background: var(--surface-3); border-radius: 6px; position: relative; overflow: hidden; }
.sk::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--ink) 5%, transparent), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* empty state */
.empty-state {
  text-align: center; color: var(--ink-3); padding: 72px 24px; font-size: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.empty-art {
  width: 84px; height: 84px; border-radius: 26px; background: var(--surface-3);
  display: flex; align-items: center; justify-content: center; color: var(--ink-3);
}
.empty-state .et { font-weight: 600; color: var(--ink-2); font-size: 15px; }

/* ---------------- reader ---------------- */
.readerpane .toolbar { border-bottom: 1px solid var(--line-soft); }
.reader-scroll { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 36px; }
.reader-subject {
  font-size: 19px; font-weight: 680; letter-spacing: -.01em; margin: 18px 26px 6px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; line-height: 1.35;
}
.pill {
  font-size: 10.5px; font-weight: 700; background: var(--surface-3); border-radius: 20px;
  padding: 4px 10px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; flex: none;
}
.reader-meta { display: flex; gap: 13px; padding: 12px 26px 14px; align-items: flex-start; border-bottom: 1px solid var(--line-soft); }
.avatar2 {
  width: 42px; height: 42px; border-radius: 14px; color: #fff; display: flex; align-items: center;
  justify-content: center; font-weight: 650; font-size: 16px; flex: none;
}
.rm-lines { flex: 1; min-width: 0; }
.rm-from { font-size: 14px; font-weight: 650; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.rm-from .addr { font-weight: 400; color: var(--ink-3); font-size: 12.5px; }
.rm-to { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; line-height: 1.5; }
.rm-date { font-size: 12px; color: var(--ink-3); white-space: nowrap; text-align: right; line-height: 1.5; }
.reader-body { padding: 18px 26px 6px; }
.reader-body iframe { width: 100%; border: none; min-height: 60px; border-radius: 10px; background: #fff; }
:root[data-theme="dark"] .reader-body iframe { background: #fff; }
.reader-text { white-space: pre-wrap; font-size: 14px; line-height: 1.65; word-wrap: break-word; color: var(--ink); }
.att-strip { display: flex; gap: 10px; flex-wrap: wrap; padding: 16px 26px 4px; }
.att-head { font-size: 12px; font-weight: 650; color: var(--ink-2); padding: 18px 26px 0; display: flex; align-items: center; gap: 8px; }
.att-chip {
  display: flex; align-items: center; gap: 10px; border: 1.5px solid var(--line); border-radius: var(--r-md);
  padding: 10px 14px; font-size: 13px; text-decoration: none; color: var(--ink); background: var(--surface);
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast); max-width: 280px;
}
.att-chip:hover { border-color: var(--accent); background: var(--accent-softer); text-decoration: none; transform: translateY(-1px); }
.att-chip .ext {
  background: var(--grad); color: #fff; font-size: 9.5px; border-radius: 7px; padding: 6px 7px;
  font-weight: 800; letter-spacing: .04em; min-width: 34px; text-align: center; flex: none;
}
.att-chip .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.att-chip .fsize { color: var(--ink-3); font-size: 11.5px; flex: none; }
.att-chip .dl { color: var(--ink-3); display: inline-flex; margin-left: 2px; }
.reader-actions { display: flex; gap: 10px; padding: 22px 26px; flex-wrap: wrap; }
.reader-placeholder {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--ink-3); font-size: 13.5px;
}

/* ---------------- compose ---------------- */
.compose {
  position: fixed; right: 28px; bottom: 0; width: 560px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--line); border-bottom: none;
  border-radius: 16px 16px 0 0; box-shadow: var(--shadow-3); z-index: 60;
  display: flex; flex-direction: column; max-height: min(80vh, 680px);
  animation: composein .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes composein { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.compose.minimized { height: 50px; overflow: hidden; }
.compose-head {
  padding: 12px 10px 12px 18px; display: flex; align-items: center; gap: 4px;
  font-size: 13.5px; font-weight: 650; border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2); border-radius: 16px 16px 0 0; cursor: default; user-select: none;
}
.compose-head .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-head .iconbtn { width: 30px; height: 30px; border-radius: 8px; }
.compose .crow { display: flex; align-items: center; border-bottom: 1px solid var(--line-soft); padding: 2px 18px; position: relative; gap: 8px; }
.compose .crow label { font-size: 12.5px; color: var(--ink-3); flex: none; min-width: 20px; }
.compose .crow input { flex: 1; border: none; outline: none; padding: 10px 0; font-size: 14px; background: transparent; min-width: 0; }
.cc-links { font-size: 12px; color: var(--ink-3); display: flex; gap: 10px; flex: none; }
.cc-links span { cursor: pointer; font-weight: 600; }
.cc-links span:hover { color: var(--accent-ink); }
.compose-body { flex: 1; overflow-y: auto; min-height: 170px; padding: 14px 18px; font-size: 14px; line-height: 1.6; outline: none; }
.compose-body:empty::before { content: attr(data-ph); color: var(--ink-3); pointer-events: none; }
.compose-atts { padding: 0 18px 6px; display: flex; flex-direction: column; gap: 6px; }
.catt {
  display: flex; align-items: center; gap: 10px; font-size: 12.5px;
  background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r-sm); padding: 7px 12px;
}
.catt .cname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.catt .csize { color: var(--ink-3); flex: none; }
.catt .iconbtn { width: 26px; height: 26px; border-radius: 7px; }
.compose-foot { display: flex; align-items: center; gap: 3px; padding: 12px 16px; border-top: 1px solid var(--line-soft); }
.send-btn {
  background: var(--grad); color: #fff; border: none; border-radius: 11px; padding: 10px 22px;
  font-weight: 650; font-size: 14px; display: inline-flex; gap: 8px; align-items: center;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--accent-1) 40%, transparent);
  transition: box-shadow var(--t-fast), opacity var(--t-fast);
}
.send-btn:hover { box-shadow: 0 4px 16px color-mix(in srgb, var(--accent-1) 55%, transparent); }
.send-btn:disabled { opacity: .55; box-shadow: none; }
.fmt-sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }

.suggest {
  position: absolute; top: calc(100% - 2px); left: 40px; right: 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-2);
  z-index: 70; overflow: hidden; padding: 5px;
}
.suggest .sg { padding: 9px 12px; font-size: 13px; cursor: pointer; border-radius: 8px; display: flex; gap: 8px; align-items: baseline; }
.suggest .sg:hover, .suggest .sg.hot { background: var(--hover); }
.suggest .sg b { font-weight: 620; }
.suggest .sg small { color: var(--ink-3); }

/* ---------------- admin ---------------- */
.admin-wrap { flex: 1; overflow-y: auto; padding: 26px 30px 64px; min-height: 0; }
.admin-title { font-size: 20px; font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.admin-title .btn { margin-left: auto; }
.admin-sub { color: var(--ink-3); font-size: 13px; margin: 6px 0 22px; line-height: 1.5; max-width: 640px; }
.table-card { border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; overflow-x: auto; background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
.table th {
  text-align: left; color: var(--ink-3); font-weight: 650; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .08em; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2);
  white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--hover); }
.rolebadge {
  font-size: 10px; font-weight: 750; border-radius: 20px; padding: 4px 10px;
  text-transform: uppercase; letter-spacing: .06em; white-space: nowrap;
}
.rolebadge.master { background: var(--accent-soft); color: var(--accent-ink); }
.rolebadge.user { background: var(--ok-soft); color: var(--ok); }
.rolebadge.none { background: var(--surface-3); color: var(--ink-3); }
.tbl-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.mini-btn {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 8px; font-size: 12px;
  font-weight: 550; padding: 6px 11px; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center;
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast); white-space: nowrap;
}
.mini-btn:hover { border-color: var(--ink-3); color: var(--ink); background: var(--surface-2); }
.mini-btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.mini-btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.filter-input {
  width: 240px; max-width: 100%; padding: 9px 13px; border: 1.5px solid var(--line); border-radius: 9px;
  background: var(--surface); outline: none; font-size: 13px; margin-bottom: 14px;
}
.filter-input:focus { border-color: var(--accent); }

/* ---------------- modal ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: color-mix(in srgb, #05070f 55%, transparent);
  backdrop-filter: blur(3px); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 18px;
  animation: fadein .15s ease-out;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 26px 28px;
  width: 100%; max-width: 440px; box-shadow: var(--shadow-3); max-height: 90vh; overflow-y: auto;
  animation: rise .22s cubic-bezier(.2,.8,.3,1);
}
.modal h3 { margin: 0 0 20px; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ---------------- menus ---------------- */
.menu {
  position: fixed; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-2); z-index: 95; min-width: 230px; padding: 6px;
  animation: menuin .14s cubic-bezier(.2,.8,.3,1);
}
@keyframes menuin { from { transform: translateY(-6px); opacity: 0; } to { transform: none; opacity: 1; } }
.menu button {
  display: flex; gap: 11px; align-items: center; width: 100%; background: none; border: none;
  text-align: left; padding: 9px 12px; font-size: 13.5px; color: var(--ink); border-radius: 9px; font-weight: 500;
}
.menu button .ic { color: var(--ink-3); }
.menu button:hover { background: var(--hover); }
.menu .msep { height: 1px; background: var(--line-soft); margin: 5px 8px; }
.menu .mhead { padding: 10px 12px 12px; border-bottom: 1px solid var(--line-soft); margin-bottom: 5px; }
.menu .mhead .em { font-weight: 650; font-size: 13.5px; }
.menu .mhead .sm { font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.menu .seg { display: flex; gap: 4px; padding: 6px 8px; }
.menu .seg button {
  flex: 1; justify-content: center; padding: 7px 4px; border: 1.5px solid var(--line);
  border-radius: 8px; font-size: 12px; gap: 6px;
}
.menu .seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }

/* ---------------- command palette ---------------- */
.palette-mask {
  position: fixed; inset: 0; background: color-mix(in srgb, #05070f 45%, transparent);
  backdrop-filter: blur(2px); z-index: 110; display: flex; justify-content: center;
  padding: 12vh 18px 18px; animation: fadein .12s ease-out;
}
.palette {
  width: 100%; max-width: 560px; height: fit-content; max-height: 62vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow-3); overflow: hidden; animation: rise .18s cubic-bezier(.2,.8,.3,1);
}
.palette .pinput {
  display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line-soft);
}
.palette .pinput .ic { color: var(--ink-3); }
.palette input { flex: 1; border: none; outline: none; background: transparent; font-size: 15.5px; color: var(--ink); }
.palette .plist { overflow-y: auto; padding: 7px; }
.palette .pitem {
  display: flex; align-items: center; gap: 12px; padding: 10px 13px; border-radius: 10px;
  font-size: 13.5px; cursor: pointer; color: var(--ink-2);
}
.palette .pitem .ic { color: var(--ink-3); }
.palette .pitem.hot { background: var(--accent-soft); color: var(--accent-ink); }
.palette .pitem.hot .ic { color: var(--accent-ink); }
.palette .pitem .pk { margin-left: auto; }
.palette .pempty { padding: 26px; text-align: center; color: var(--ink-3); font-size: 13.5px; }
.palette .phint {
  display: flex; gap: 14px; padding: 10px 16px; border-top: 1px solid var(--line-soft);
  font-size: 11px; color: var(--ink-3);
}

/* ---------------- toast ---------------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 26px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 14px; padding: 13px 18px; font-size: 13.5px; font-weight: 550; z-index: 200;
  box-shadow: var(--shadow-2); display: flex; gap: 14px; align-items: center;
  animation: toastin .2s cubic-bezier(.2,.8,.3,1); max-width: min(90vw, 480px);
}
.toast .tdot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.toast.err .tdot { background: var(--danger); }
.toast button { background: none; border: none; color: var(--accent-ink); font-weight: 700; font-size: 13px; white-space: nowrap; }
@keyframes toastin { from { transform: translate(-50%, 14px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------------- shortcuts modal ---------------- */
.sc-grid { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; align-items: center; font-size: 13.5px; color: var(--ink-2); }
.sc-keys { display: flex; gap: 4px; }
.kbd {
  font-family: var(--mono); font-size: 11.5px; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 6px; padding: 3px 8px; background: var(--surface-2); color: var(--ink); min-width: 20px; text-align: center;
}

/* ---------------- FAB (mobile compose) ---------------- */
.fab {
  display: none; position: fixed; right: 18px; bottom: 20px; width: 56px; height: 56px;
  border: none; border-radius: 18px; background: var(--grad); color: #fff; z-index: 45;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent-1) 50%, transparent);
  align-items: center; justify-content: center;
}

/* ---------------- responsive ---------------- */
@media (max-width: 920px) {
  .shell { grid-template-columns: 0 1fr; grid-template-areas: "top top" "main main"; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 84vw); background: var(--surface);
    z-index: 80; transform: translateX(-105%); transition: transform var(--t-med), opacity var(--t-med);
    box-shadow: var(--shadow-3); padding-top: 14px; border-right: 1px solid var(--line); opacity: 1;
  }
  .shell.nav-open .sidebar { transform: none; }
  .nav-scrim { position: fixed; inset: 0; background: color-mix(in srgb, #05070f 45%, transparent); z-index: 75; animation: fadein .15s; }
  .main { margin: 0 8px 8px; border-radius: 14px; }
  .brand .name { display: none; }
  .kbd-chip { display: none; }
  .mfrom { width: 118px; }
  .fab { display: inline-flex; }
  .compose-btn { display: flex; }
  .toolbar { padding: 6px 8px; }
  .reader-subject { margin: 14px 18px 6px; font-size: 17px; }
  .reader-meta, .reader-body, .reader-actions { padding-left: 18px; padding-right: 18px; }
  .att-strip, .att-head { padding-left: 18px; padding-right: 18px; }
}
@media (max-width: 640px) {
  .compose { right: 0; left: 0; bottom: 0; width: 100%; max-width: none; max-height: 100dvh; height: 100dvh; border-radius: 0; border: none; }
  .compose-head { border-radius: 0; }
  .compose.minimized { height: 50px; bottom: 0; top: auto; }
  .mdate { min-width: 60px; }
  .mfrom { width: 96px; }
  .searchbox { height: 38px; }
  .topbar { padding: 0 8px; gap: 6px; }
  .lang-btn { display: none; }
  .auth-card { padding: 30px 24px; border-radius: 20px; }
  .admin-wrap { padding: 18px 14px 60px; }
}

/* print */
@media print {
  .topbar, .sidebar, .toolbar, .reader-actions, .compose, .fab { display: none !important; }
  .main { border: none; box-shadow: none; margin: 0; }
}
