/* ---------- theme ---------- */
:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f2f6fc;
  --surface-3: #e9eef6;
  --hover: rgba(60, 64, 67, 0.08);
  --border: #e1e5ea;
  --text: #1f1f1f;
  --text-2: #444746;
  --text-3: #747775;
  --primary: #0b57d0;
  --primary-hover: #0a4cb8;
  --on-primary: #ffffff;
  --primary-soft: #d3e3fd;
  --on-primary-soft: #041e49;
  --compose: #c2e7ff;
  --on-compose: #001d35;
  --selected: #c2dbff;
  --row-read: #f2f6fc;
  --row-unread: #ffffff;
  --danger: #b3261e;
  --danger-soft: #fce8e6;
  --warn: #8a5300;
  --warn-soft: #fef3d6;
  --ok: #146c2e;
  --ok-soft: #e6f4ea;
  --shadow-1: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
  --shadow-2: 0 4px 8px 3px rgba(60, 64, 67, 0.15), 0 1px 3px rgba(60, 64, 67, 0.3);
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #1b1d22;
    --surface-2: #22252b;
    --surface-3: #2b2f36;
    --hover: rgba(232, 234, 237, 0.08);
    --border: #33373e;
    --text: #e3e3e3;
    --text-2: #c4c7c5;
    --text-3: #8e918f;
    --primary: #a8c7fa;
    --primary-hover: #c2d7fb;
    --on-primary: #062e6f;
    --primary-soft: #0842a0;
    --on-primary-soft: #d3e3fd;
    --compose: #004a77;
    --on-compose: #c2e7ff;
    --selected: #24375a;
    --row-read: #1b1d22;
    --row-unread: #23262c;
    --danger: #f2b8b5;
    --danger-soft: #49201d;
    --warn: #f6c76b;
    --warn-soft: #3d2e10;
    --ok: #8fd9a3;
    --ok-soft: #173a22;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5), 0 1px 3px 1px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 4px 8px 3px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111317;
  --surface: #1b1d22;
  --surface-2: #22252b;
  --surface-3: #2b2f36;
  --hover: rgba(232, 234, 237, 0.08);
  --border: #33373e;
  --text: #e3e3e3;
  --text-2: #c4c7c5;
  --text-3: #8e918f;
  --primary: #a8c7fa;
  --primary-hover: #c2d7fb;
  --on-primary: #062e6f;
  --primary-soft: #0842a0;
  --on-primary-soft: #d3e3fd;
  --compose: #004a77;
  --on-compose: #c2e7ff;
  --selected: #24375a;
  --row-read: #1b1d22;
  --row-unread: #23262c;
  --danger: #f2b8b5;
  --danger-soft: #49201d;
  --warn: #f6c76b;
  --warn-soft: #3d2e10;
  --ok: #8fd9a3;
  --ok-soft: #173a22;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5), 0 1px 3px 1px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 4px 8px 3px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.icon { display: inline-flex; width: 20px; height: 20px; flex: none; }
.icon svg { width: 100%; height: 100%; fill: currentColor; }
.icon.sm { width: 16px; height: 16px; }
.icon.lg { width: 24px; height: 24px; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--surface-3); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  height: 36px; padding: 0 18px; border-radius: 18px; border: 1px solid transparent;
  background: var(--primary); color: var(--on-primary); font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--primary-hover); box-shadow: var(--shadow-1); }
.btn:disabled { opacity: 0.55; cursor: default; box-shadow: none; }
.btn.outline { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn.outline:hover { background: var(--hover); box-shadow: none; }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.ghost:hover { background: var(--hover); box-shadow: none; }
.btn.danger { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn.danger { color: #3a0907; }
.btn.small { height: 30px; padding: 0 12px; font-size: 13px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border-radius: 50%; border: 0; background: transparent; color: var(--text-2); cursor: pointer;
  position: relative;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:disabled { opacity: 0.38; cursor: default; background: transparent; }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.active { color: var(--primary); }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--text-2); font-weight: 500; }
.input, .textarea, .select {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px;
  border-radius: 11px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.info { background: var(--primary-soft); color: var(--on-primary-soft); }

/* ---------- login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
}
.login-card {
  width: 100%; max-width: 420px; background: var(--surface); border-radius: 28px;
  padding: 40px 36px 32px; box-shadow: var(--shadow-1);
}
.login-card .brand { margin-bottom: 24px; }
.login-card h1 { font-size: 26px; font-weight: 500; margin: 0 0 4px; }
.login-card p { margin: 0 0 24px; color: var(--text-2); }
.login-card .btn { width: 100%; height: 42px; margin-top: 8px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 0; }

.brand { display: flex; align-items: center; gap: 10px; font-size: 21px; color: var(--text-2); text-decoration: none; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px; background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center;
}
.brand-logo .icon { width: 22px; height: 22px; }

/* ---------- shell ---------- */
.shell {
  display: grid; height: 100vh;
  grid-template-columns: 256px minmax(0, 1fr);
  grid-template-rows: 64px minmax(0, 1fr);
  grid-template-areas: "top top" "side main";
}
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 8px; min-width: 0;
}
.topbar .brand { width: 228px; flex: none; padding-left: 4px; }
.search {
  flex: 1; max-width: 720px; height: 48px; display: flex; align-items: center; gap: 4px;
  background: var(--surface-3); border-radius: 24px; padding: 0 6px; min-width: 0;
}
.search:focus-within { background: var(--surface); box-shadow: var(--shadow-1); }
.search input {
  flex: 1; border: 0; background: transparent; outline: none; height: 100%; font-size: 15px; min-width: 0;
}
.topbar .spacer { flex: 1; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: #fff; font-weight: 600; font-size: 14px; text-transform: uppercase; user-select: none;
}
.avatar.lg { width: 40px; height: 40px; font-size: 17px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.live-dot.on { background: #1e8e3e; box-shadow: 0 0 0 3px rgba(30, 142, 62, 0.18); }

.menu {
  position: absolute; z-index: 50; min-width: 240px; padding: 8px 0; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow-2); border: 1px solid var(--border);
}
.menu .menu-head { padding: 10px 16px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu .menu-head strong { display: block; }
.menu .menu-head small { color: var(--text-2); }
.menu button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 16px; border: 0;
  background: none; cursor: pointer; text-align: left;
}
.menu button:hover { background: var(--hover); }

.sidebar { grid-area: side; padding: 8px 12px 16px 8px; overflow-y: auto; display: flex; flex-direction: column; }
.compose-btn {
  display: inline-flex; align-items: center; gap: 12px; height: 56px; padding: 0 22px 0 16px;
  border-radius: 16px; border: 0; background: var(--compose); color: var(--on-compose);
  font-weight: 600; font-size: 14px; cursor: pointer; margin: 0 0 16px; align-self: flex-start;
}
.compose-btn:hover { box-shadow: var(--shadow-1); }
.nav { display: grid; gap: 1px; }
.nav a {
  display: flex; align-items: center; gap: 16px; height: 34px; padding: 0 14px 0 20px;
  border-radius: 0 17px 17px 0; color: var(--text-2); text-decoration: none; font-size: 14px;
  margin-left: -8px;
}
.nav a:hover { background: var(--hover); }
.nav a.active { background: var(--primary-soft); color: var(--on-primary-soft); font-weight: 700; }
.nav a .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a .count { font-size: 12px; font-weight: 700; }
.nav a.has-unread { font-weight: 700; color: var(--text); }
.nav a.active.has-unread { color: var(--on-primary-soft); }
.nav-sep { height: 1px; background: var(--border); margin: 10px 8px 10px 12px; }
.sidebar-foot { margin-top: auto; padding: 16px 8px 0 12px; font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 8px; }

.main {
  grid-area: main; background: var(--surface); border-radius: var(--radius); margin: 0 16px 16px 0;
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}

/* ---------- list view ---------- */
.toolbar {
  display: flex; align-items: center; gap: 2px; min-height: 48px; padding: 4px 8px 4px 12px;
  border-bottom: 1px solid var(--border); flex: none; flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }
.toolbar .range { color: var(--text-2); font-size: 12px; padding: 0 8px; white-space: nowrap; }
.toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }
.select-all { width: 40px; height: 40px; display: grid; place-items: center; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; margin: 0; }

.folder-note {
  padding: 10px 20px; font-size: 13px; color: var(--text-2); background: var(--surface-2);
  border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.scroll { flex: 1; overflow-y: auto; min-height: 0; }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; align-items: center; cursor: pointer; position: relative;
  grid-template-columns: 40px 32px minmax(120px, 200px) minmax(0, 1fr) auto;
  gap: 0 8px; height: 40px; padding: 0 16px 0 12px;
  background: var(--row-read); border-bottom: 1px solid var(--border);
}
.row.unread { background: var(--row-unread); }
.row.unread .sender, .row.unread .subject, .row.unread time { font-weight: 700; color: var(--text); }
.row:hover { box-shadow: inset 1px 0 0 var(--border), inset -1px 0 0 var(--border), 0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15); z-index: 1; }
.row.selected { background: var(--selected); }
.row.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh { 0% { background: var(--primary-soft); } 100% { background: var(--row-unread); } }
.row .cb { display: grid; place-items: center; height: 40px; }
.row .star { color: var(--text-3); }
.row .star.on, .star-btn.on { color: #f4b400; }
.row .sender { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.row .line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-3); display: flex; gap: 6px; align-items: center; min-width: 0; }
.row .subject { color: var(--text-2); flex: none; max-width: 70%; overflow: hidden; text-overflow: ellipsis; }
.row .snippet { overflow: hidden; text-overflow: ellipsis; }
.row .meta { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 12px; justify-content: flex-end; }
.row time { min-width: 56px; text-align: right; color: var(--text-2); }
.row .hover-actions { display: none; gap: 0; }
.row:hover .hover-actions { display: flex; }
.row:hover time { display: none; }

.empty { padding: 64px 24px; text-align: center; color: var(--text-2); }
.empty .icon { width: 64px; height: 64px; color: var(--surface-3); margin-bottom: 12px; }
.empty h3 { margin: 0 0 4px; font-weight: 500; color: var(--text); }
.loading-bar { height: 3px; background: linear-gradient(90deg, transparent, var(--primary), transparent); background-size: 50% 100%; animation: loadbar 1s linear infinite; background-repeat: no-repeat; }
@keyframes loadbar { from { background-position: -50% 0; } to { background-position: 150% 0; } }

/* ---------- reading view ---------- */
.reader { padding: 8px 24px 40px 72px; max-width: 1100px; }
.reader-subject { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 12px 0 16px; }
.reader-subject h1 { font-size: 22px; font-weight: 400; margin: 0; word-break: break-word; }
.banner {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: 12px;
  margin: 0 0 12px; font-size: 13px; background: var(--surface-2); color: var(--text-2);
}
.banner .icon { margin-top: 1px; }
.banner strong { display: block; color: inherit; margin-bottom: 2px; }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner .btn { margin-left: auto; flex: none; }
.banner ul { margin: 4px 0 0; padding-left: 18px; }

.sender-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: start; margin-bottom: 16px; margin-left: -56px; }
.sender-row .who { min-width: 0; }
.sender-row .who strong { font-weight: 700; }
.sender-row .who .addr { color: var(--text-2); font-size: 12px; }
.sender-row .to-line { color: var(--text-2); font-size: 12px; display: inline-flex; align-items: center; gap: 2px; cursor: pointer; background: none; border: 0; padding: 0; }
.sender-row .when { color: var(--text-2); font-size: 12px; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.auth-badges { display: inline-flex; gap: 4px; margin-left: 6px; vertical-align: middle; flex-wrap: wrap; }

.details {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin: -6px 0 16px;
  display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; font-size: 12px;
}
.details dt { color: var(--text-3); text-align: right; }
.details dd { margin: 0; word-break: break-word; }

.body-frame { width: 100%; border: 0; min-height: 80px; display: block; background: #fff; border-radius: 8px; }
.attachments { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.attachments h4 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.att-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.att {
  width: 200px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  background: var(--surface-2); display: flex; flex-direction: column;
}
.att .thumb { height: 96px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-3); overflow: hidden; }
.att .thumb img { width: 100%; height: 100%; object-fit: cover; }
.att .thumb .icon { width: 40px; height: 40px; }
.att .att-body { padding: 8px 10px; display: grid; gap: 4px; }
.att .name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .sub { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--text-3); }
.att .actions { display: flex; gap: 2px; }
.att.blocked { background: var(--danger-soft); border-color: transparent; }
.att.blocked .thumb { background: transparent; color: var(--danger); }
.att .why { font-size: 11px; color: var(--danger); line-height: 1.3; }
.att .why.warn { color: var(--warn); }

.delivery { margin-top: 24px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.delivery h4 { margin: 0; padding: 10px 16px; font-size: 13px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.delivery-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.delivery-row:last-child { border-bottom: 0; }
.delivery-row .err { grid-column: 1 / -1; color: var(--text-3); font-size: 12px; font-family: var(--mono); word-break: break-word; }

.reply-bar { display: flex; gap: 10px; margin-top: 28px; flex-wrap: wrap; }

/* ---------- compose ---------- */
.compose {
  position: fixed; right: 24px; bottom: 0; z-index: 40; width: 560px; max-width: calc(100vw - 32px);
  height: min(620px, calc(100vh - 80px)); background: var(--surface); border-radius: 12px 12px 0 0;
  box-shadow: var(--shadow-2); display: flex; flex-direction: column; overflow: hidden;
}
.compose.min { height: 44px; width: 320px; }
.compose.full { inset: 5vh 8vw; width: auto; height: auto; max-width: none; border-radius: 12px; }
.compose.dragover::after {
  content: "Drop files to attach"; position: absolute; inset: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--primary-soft) 85%, transparent); color: var(--on-primary-soft);
  font-size: 18px; font-weight: 600; border: 2px dashed var(--primary); border-radius: inherit;
}
.compose-head {
  display: flex; align-items: center; gap: 2px; height: 44px; padding: 0 6px 0 16px; flex: none;
  background: var(--surface-3); cursor: pointer; font-weight: 600;
}
.compose-head .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-head .icon-btn { width: 30px; height: 30px; }
.compose-fields { flex: none; padding: 0 16px; }
.compose-field { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); min-height: 40px; position: relative; }
.compose-field label { color: var(--text-3); min-width: 32px; }
.compose-field input { flex: 1; border: 0; outline: none; background: transparent; height: 38px; min-width: 0; }
.compose-field .toggles { display: flex; gap: 8px; }
.compose-field .toggles button { background: none; border: 0; color: var(--text-2); cursor: pointer; padding: 4px; }
.compose-field .toggles button:hover { text-decoration: underline; }
.suggest {
  position: absolute; top: 100%; left: 32px; right: 0; z-index: 5; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-2); padding: 4px 0;
}
.suggest button { display: flex; gap: 10px; align-items: center; width: 100%; border: 0; background: none; padding: 6px 12px; text-align: left; cursor: pointer; }
.suggest button.active, .suggest button:hover { background: var(--hover); }
.suggest small { color: var(--text-3); }
.editor {
  flex: 1; overflow-y: auto; padding: 12px 16px; outline: none; min-height: 80px;
  font: 14px/1.5 Arial, Helvetica, sans-serif; word-break: break-word;
}
.editor:empty::before { content: attr(data-placeholder); color: var(--text-3); }
.editor blockquote { margin: 0 0 0 0.8ex; border-left: 2px solid var(--border); padding-left: 1ex; color: var(--text-2); }
.editor .sig { color: var(--text-2); }
.compose-files { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; flex: none; max-height: 110px; overflow-y: auto; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 260px; height: 30px; padding: 0 4px 0 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: 12px;
}
.file-chip .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--primary); }
.file-chip .s { color: var(--text-3); flex: none; }
.file-chip .icon-btn { width: 24px; height: 24px; }
.compose-foot { display: flex; align-items: center; gap: 4px; padding: 8px 12px 12px 16px; flex: none; flex-wrap: wrap; }
.compose-foot .spacer { flex: 1; }
.format-bar { display: flex; gap: 0; padding: 0 8px; flex: none; border-top: 1px solid var(--border); flex-wrap: wrap; }
.format-bar .icon-btn { width: 32px; height: 32px; }
.progress { height: 3px; background: var(--surface-3); flex: none; }
.progress > div { height: 100%; width: 0; background: var(--primary); transition: width 0.15s; }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 24px; bottom: 24px; z-index: 100; display: grid; gap: 8px; max-width: min(480px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 16px; border-radius: 8px;
  background: #303134; color: #e8eaed; box-shadow: var(--shadow-2); font-size: 14px;
  animation: toast-in 0.2s ease-out;
}
:root[data-theme="dark"] .toast { background: #e3e3e3; color: #1f1f1f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast { background: #e3e3e3; color: #1f1f1f; } }
.toast .msg { flex: 1; min-width: 0; }
.toast .msg small { display: block; opacity: 0.75; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast.danger { border-left: 4px solid #f28b82; }
.toast button { background: none; border: 0; color: #8ab4f8; font-weight: 600; cursor: pointer; padding: 6px 8px; border-radius: 4px; }
:root[data-theme="dark"] .toast button { color: #0b57d0; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast button { color: #0b57d0; } }
.toast button:hover { background: rgba(255, 255, 255, 0.08); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- dialogs ---------- */
dialog {
  border: 0; border-radius: 24px; padding: 0; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-2); width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog-body { padding: 24px; overflow-y: auto; max-height: calc(100vh - 140px); }
.dialog-body h2 { margin: 0 0 16px; font-size: 22px; font-weight: 400; }
.dialog-body h3 { font-size: 14px; margin: 20px 0 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 24px 20px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 18px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 7px 14px; cursor: pointer; }
.seg button.on { background: var(--primary-soft); color: var(--on-primary-soft); font-weight: 600; }

/* ---------- admin ---------- */
.admin { padding: 8px 24px 40px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 -24px 20px; padding: 0 16px; overflow-x: auto; }
.tabs a { padding: 12px 16px; text-decoration: none; color: var(--text-2); border-bottom: 3px solid transparent; font-weight: 600; white-space: nowrap; }
.tabs a.on { color: var(--primary); border-bottom-color: var(--primary); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 24px; }
.card { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: var(--surface-2); }
.card small { color: var(--text-3); display: block; margin-bottom: 4px; font-size: 12px; }
.card .v { font-size: 15px; font-weight: 600; word-break: break-word; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 20px; overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-head h3 { margin: 0; font-size: 15px; flex: 1; }
.panel-body { padding: 16px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; color: var(--text-2); padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.dns-value { display: flex; gap: 6px; align-items: flex-start; }
.dns-value code { flex: 1; font-family: var(--mono); font-size: 12px; word-break: break-all; background: var(--surface-3); padding: 6px 8px; border-radius: 6px; max-height: 84px; overflow: auto; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { margin: 0; flex: 1; min-width: 160px; }
.steps { margin: 0; padding-left: 20px; color: var(--text-2); }
.steps li { margin-bottom: 6px; }
.steps code, .help code { font-family: var(--mono); font-size: 12px; background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--text-3); }

/* ---------- responsive ---------- */
.menu-btn { display: none; }
.scrim { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .menu-btn { display: inline-grid; }
  .topbar .brand { width: auto; }
  .topbar .brand .brand-name { display: none; }
  .sidebar {
    position: fixed; z-index: 60; top: 0; bottom: 0; left: 0; width: 280px; background: var(--surface);
    box-shadow: var(--shadow-2); transform: translateX(-105%); transition: transform 0.2s; padding-top: 16px;
  }
  .shell.drawer .sidebar { transform: none; }
  .shell.drawer .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, 0.35); }
  .main { margin: 0 8px 8px; }
  .row { grid-template-columns: 32px minmax(0, 1fr) auto; grid-template-rows: auto auto; height: auto; padding: 8px 12px 8px 8px; gap: 2px 8px; }
  .row .cb { grid-row: 1 / 3; height: auto; }
  .row .star { display: none; }
  .row .sender { grid-column: 2; }
  .row .line { grid-column: 2 / 4; grid-row: 2; }
  .row .meta { grid-column: 3; grid-row: 1; }
  .row:hover .hover-actions { display: none; }
  .row:hover time { display: block; }
  .reader { padding: 8px 16px 32px; }
  .sender-row { margin-left: 0; }
  .compose, .compose.full { inset: 0; width: auto; height: auto; max-width: none; border-radius: 0; }
  .compose.min { inset: auto 8px 0 auto; width: 260px; height: 44px; border-radius: 12px 12px 0 0; }
  .toasts { left: 16px; right: 16px; bottom: 16px; }
  .admin { padding: 8px 16px 32px; }
  .tabs { margin: 0 -16px 16px; }
}
@media (max-width: 560px) {
  .search { height: 42px; }
  .topbar { gap: 4px; }
  .topbar .live-dot, .topbar .top-settings, .topbar .brand, .topbar .spacer { display: none; }
  .toolbar .range { display: none; }
  .att { width: 100%; }
}
