/* Mail panel. Light and dark theme follow the system. One accent colour,
   neutral greys, 4px spacing grid, system font. Icons: Lucide (web/icons.js). */

:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --side: #f1f3f6;
  --hover: rgba(15, 23, 42, .045);
  --press: rgba(15, 23, 42, .08);
  --line: #e4e7ec;
  --line-strong: #cfd4dc;
  --text: #151a23;
  --text-2: #3a4251;
  --muted: #687284;
  --faint: #98a0ae;
  --accent: #2f5bd3;
  --accent-hover: #264bb4;
  --accent-soft: #e9effc;
  --accent-text: #2449ad;
  --danger: #c93636;
  --danger-soft: #fcebeb;
  --ok: #1d7a4b;
  --ok-soft: #e5f4ec;
  --warn: #9a5b06;
  --warn-soft: #fcf1de;
  --violet: #5e44c9;
  --violet-soft: #efebfc;
  --chip: #eef0f4;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-lg: 0 16px 48px rgba(16, 24, 40, .18), 0 2px 6px rgba(16, 24, 40, .08);
  --scrim: rgba(17, 22, 31, .4);
  --radius: 8px;
  --radius-lg: 12px;
  --side-w: 264px;
  --list-w: 384px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #171a1f;
    --side: #13151a;
    --hover: rgba(255, 255, 255, .05);
    --press: rgba(255, 255, 255, .09);
    --line: #262a31;
    --line-strong: #373c45;
    --text: #e7e9ee;
    --text-2: #c6cad3;
    --muted: #9298a5;
    --faint: #686e7a;
    --accent: #6f97ff;
    --accent-hover: #86a8ff;
    --accent-soft: rgba(111, 151, 255, .14);
    --accent-text: #a8c0ff;
    --danger: #f27474;
    --danger-soft: rgba(242, 116, 116, .13);
    --ok: #5fcf8f;
    --ok-soft: rgba(95, 207, 143, .12);
    --warn: #e8b05a;
    --warn-soft: rgba(232, 176, 90, .13);
    --violet: #ad9cff;
    --violet-soft: rgba(173, 156, 255, .14);
    --chip: #222630;
    --shadow-sm: none;
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .5), 0 0 0 1px var(--line);
    --scrim: rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }

.i { width: 16px; height: 16px; flex: none; display: block; }
.i.sm { width: 14px; height: 14px; }
.i.lg { width: 22px; height: 22px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 7px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 500; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--hover); }
.btn:active { background: var(--press); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:hover { background: var(--surface); }
.btn.ghost:disabled:hover { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0d1220; } .btn.danger-solid { color: #1f0b0b; } }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-solid:hover { filter: brightness(.95); }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--muted); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; border-radius: 6px; }
.btn.icon { width: 32px; padding: 0; }
.btn.icon.small { width: 28px; }
.btn.block { width: 100%; }

/* ---------- inputs ---------- */
input[type=text], input[type=password], input:not([type]), select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 7px;
  border: 1px solid var(--line-strong); background: var(--surface);
  transition: border-color .12s, box-shadow .12s;
}
select { padding-right: 28px; }
input:hover, select:hover { border-color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled { color: var(--muted); background: var(--bg); }
input[type=checkbox] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); flex: none; }
::placeholder { color: var(--faint); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; color: var(--text-2); font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.err { color: var(--danger); font-size: 13px; }
.err:empty { display: none; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > input { flex: 1; min-width: 0; }
.at { color: var(--muted); }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 32px 28px 28px; box-shadow: var(--shadow-sm);
}
.login-card .mark { margin-bottom: 18px; }
.login-card h1 { font-size: 20px; }
.login-card p { margin: 4px 0 24px; color: var(--muted); }
.login-card .btn { width: 100%; height: 38px; margin-top: 6px; }
.login-card .err { margin-top: 12px; }
.mark {
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: #fff;
}
@media (prefers-color-scheme: dark) { .mark { color: #0d1220; } }
.mark.sm { width: 28px; height: 28px; border-radius: 7px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; height: 100vh; height: 100dvh; overflow: hidden; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 10px 16px; }
.brand { font-weight: 650; font-size: 15px; flex: 1; }
.nav { flex: 1; overflow: auto; padding: 4px 8px 12px; }
.nav-section {
  display: flex; align-items: center; justify-content: space-between;
  margin: 18px 8px 6px; font-size: 11.5px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: var(--faint);
}
.nav-item {
  display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 8px; border-radius: 6px;
  color: var(--text-2); text-decoration: none; user-select: none; position: relative;
}
.nav-item:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 550; }
.nav-item > .i { color: var(--muted); }
.nav-item.active > .i { color: var(--accent-text); }
.nav-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .flag { color: var(--faint); display: inline-flex; }
.count {
  min-width: 20px; height: 18px; padding: 0 6px; border-radius: 9px; font-size: 11.5px; font-weight: 600;
  display: inline-grid; place-items: center; color: var(--muted); font-variant-numeric: tabular-nums;
}
.count:empty { display: none; }
.nav-item.active .count { color: var(--accent-text); }
.count.strong { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .count.strong { color: #0d1220; } }
.domain + .domain { margin-top: 2px; }
.domain > .nav-item { font-weight: 550; color: var(--text); }
.nav-item.mbox { height: 30px; padding-left: 34px; }
.mbox .at-dom { color: var(--faint); }
.btn.on > .i { color: var(--accent-text); } /* hide button of a hidden mailbox: "bring back" */
.nav-item.hidden-toggle { width: 100%; margin-top: 6px; border: 0; background: none; font: inherit; font-size: 12.5px; color: var(--muted); cursor: pointer; text-align: left; }
.alias {
  display: flex; align-items: baseline; gap: 5px; padding: 0 8px 5px 34px; margin-top: -4px;
  font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; cursor: default;
}
.alias-list { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.alias-more { flex: none; color: var(--muted); }
.side-note {
  margin: 10px 8px; padding: 10px 12px; border-radius: var(--radius); font-size: 12.5px;
  display: flex; gap: 8px; color: var(--danger); background: var(--danger-soft);
}
.side-note.plain { color: var(--muted); background: transparent; padding: 8px; }
.side-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.side-actions .btn:only-child { grid-column: 1 / -1; }
.side-foot { display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 14px; border-top: 1px solid var(--line); }
.who { flex: 1; min-width: 0; line-height: 1.25; }
.who-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-role { font-size: 12px; color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--surface); }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 0 20px; height: 60px; flex: none;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.title { min-width: 0; flex: 1; display: flex; align-items: baseline; gap: 10px; }
.title h2 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title .sub { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tools { display: flex; align-items: center; gap: 8px; flex: none; }
.content { flex: 1; overflow: auto; min-height: 0; background: var(--bg); }
.only-narrow { display: none !important; }
.scrim { display: none; }

/* ---------- mail ---------- */
.mail { display: grid; grid-template-columns: var(--list-w) 1fr; height: 100%; }
.mail-list { border-right: 1px solid var(--line); overflow: auto; background: var(--surface); }
.msg {
  display: flex; gap: 12px; padding: 12px 16px 12px 14px; cursor: pointer; position: relative;
  border-bottom: 1px solid var(--line); border-left: 2px solid transparent;
}
.msg:hover { background: var(--hover); }
.msg.active { background: var(--accent-soft); border-left-color: var(--accent); }
.msg:focus-visible { outline-offset: -2px; }
.msg-main { flex: 1; min-width: 0; }
.msg-row { display: flex; gap: 8px; align-items: baseline; }
.msg-from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.msg-date { color: var(--faint); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg-subj { margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.msg-prev { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.msg.unread .msg-from, .msg.unread .msg-subj { color: var(--text); font-weight: 650; }
.msg.unread .msg-date { color: var(--accent-text); font-weight: 600; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; align-self: center; margin-right: -2px; }
.to-badge {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%; margin-top: 6px;
  font-size: 11.5px; color: var(--text-2); background: var(--chip); border-radius: 5px; padding: 1px 7px;
}
.to-badge span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more { padding: 14px; text-align: center; }
/* folder bar on top of the letter list */
.folders {
  position: sticky; top: 0; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 6px 8px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.folder-btn {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 8px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap;
}
.folder-btn:hover { background: var(--hover); color: var(--text); }
.folder-btn.on { background: var(--accent-soft); color: var(--accent-text); }
.folder-btn .label { display: none; }
.folder-btn.on .label { display: inline; }
.folder-btn .count { min-width: 0; padding: 0 2px; }
.folder-btn.on .count { color: var(--accent-text); }
.folders .select-wrap { flex: none; margin-left: 4px; }
.folders .select-wrap select { height: 30px; max-width: 150px; font-size: 13px; padding-left: 30px; }
.folders .select-wrap select.on { border-color: var(--accent); background: var(--accent-soft); }
.folders .select-wrap > .i { left: 9px; }

.reader { overflow: auto; background: var(--surface); display: flex; flex-direction: column; min-width: 0; }
.reader-head { padding: 22px 28px 18px; border-bottom: 1px solid var(--line); }
.reader-bar { display: flex; align-items: center; gap: 8px; margin: -8px 0 8px; }
.reader-bar .mark-slot { margin-left: auto; }
.reader-head h1 { font-size: 20px; line-height: 1.3; margin-bottom: 16px; overflow-wrap: anywhere; }
.sender { display: flex; align-items: center; gap: 12px; }
.sender-text { flex: 1; min-width: 0; }
.sender-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-mail { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-date { color: var(--muted); font-size: 13px; white-space: nowrap; align-self: flex-start; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin-top: 14px; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; color: var(--text-2); overflow-wrap: anywhere; }
.reader-body { flex: 1; display: flex; flex-direction: column; }
/* Mail HTML is designed for a white page: keep it white in the dark theme. */
.reader-body iframe { border: 0; width: 100%; flex: 1; min-height: 420px; display: block; background: #fff; }
.reader-body pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; line-height: 1.6; padding: 22px 28px; margin: 0; max-width: 820px; }
.reader-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 28px; border-top: 1px solid var(--line); }
.att { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; color: var(--text-2); }
.att .size { color: var(--faint); }
.safe-note { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-left: auto; }

.avatar {
  --hue: 220;
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 600; font-size: 14px; color: hsl(var(--hue) 45% 32%); background: hsl(var(--hue) 55% 92%);
}
.avatar.sm { width: 28px; height: 28px; font-size: 12.5px; }
.avatar.lg { width: 40px; height: 40px; font-size: 16px; }
@media (prefers-color-scheme: dark) {
  .avatar { color: hsl(var(--hue) 70% 80%); background: hsl(var(--hue) 30% 22%); }
}

/* ---------- empty and loading states ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; padding: 48px 24px; color: var(--muted); height: 100%; min-height: 200px; }
.empty-ic { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--chip); color: var(--muted); margin-bottom: 6px; }
.empty-ic .i { width: 22px; height: 22px; }
.empty-title { color: var(--text-2); font-weight: 600; }
.empty-hint { font-size: 13px; max-width: 320px; }
.empty.compact { min-height: 0; height: auto; padding: 28px 16px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px; color: var(--muted); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.notice { display: flex; gap: 8px; align-items: flex-start; padding: 10px 14px; border-radius: var(--radius); font-size: 13px; color: var(--warn); background: var(--warn-soft); margin: 12px; }

/* ---------- pages, cards, tables ---------- */
.page { padding: 24px; max-width: 1120px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: 20px; box-shadow: var(--shadow-sm); overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h3 { font-size: 15px; flex: 1; }
.card-head .i { color: var(--muted); }
.card-body { padding: 16px 18px; color: var(--text-2); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 550; color: var(--muted); font-size: 12px; padding-top: 10px; padding-bottom: 10px; background: var(--bg); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--hover); }
td.actions { text-align: right; white-space: nowrap; width: 1%; }
td.actions .btn + .btn { margin-left: 6px; }
td.num { font-variant-numeric: tabular-nums; }
.cell-user { display: flex; align-items: center; gap: 12px; min-width: 180px; }
.cell-user .nm { font-weight: 550; }
.cell-mbox a { font-weight: 550; color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 5px;
  font-size: 12px; font-weight: 500; background: var(--chip); color: var(--text-2); white-space: nowrap;
}
.tag .i { width: 13px; height: 13px; }
.tag.owner { background: var(--warn-soft); color: var(--warn); }
.tag.agent { background: var(--violet-soft); color: var(--violet); }
.tag.off { background: var(--danger-soft); color: var(--danger); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.accent { background: var(--accent-soft); color: var(--accent-text); }
.tag.stale { text-decoration: line-through; opacity: .6; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
.info { display: flex; gap: 10px; align-items: flex-start; color: var(--muted); font-size: 13px; padding: 0 4px; max-width: 760px; }
.info .i { margin-top: 2px; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: var(--scrim); display: grid; place-items: center; z-index: 30; padding: 16px; animation: fade .12s ease-out; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); width: 480px; max-width: 100%;
  max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  animation: rise .14s ease-out;
}
.modal.wide { width: 720px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 4px 22px; }
.modal-head h3 { font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 14px 22px 8px; overflow: auto; }
.modal-body p { margin: 0 0 14px; color: var(--text-2); }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 14px 22px 18px; }
.modal-foot .err { margin-right: auto; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px) scale(.99); } }
.section-title { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 18px 0 10px; }
.section-title:first-child { margin-top: 4px; }
.checks { border: 1px solid var(--line); border-radius: var(--radius); max-height: 232px; overflow: auto; padding: 4px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 34px; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.check:hover { background: var(--hover); }
.check .sub { margin-left: auto; color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 8px; }
.check .txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.option { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; margin-bottom: 8px; }
.option:hover { background: var(--hover); }
.option input { margin-top: 2px; }
.option .t { font-weight: 550; }
.option .d { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.col-title { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.col-title .i { color: var(--muted); }
.list-edit { border: 1px solid var(--line); border-radius: var(--radius); padding: 4px; margin-bottom: 12px; }
.list-edit .row { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 4px 0 10px; border-radius: 6px; }
.list-edit .row:hover { background: var(--hover); }
.list-edit .row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list-edit .none { padding: 8px 10px; color: var(--muted); }

/* ---------- toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 40; }
.toast {
  display: flex; align-items: center; gap: 10px; max-width: 420px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--text); color: var(--surface); box-shadow: var(--shadow-lg); animation: rise .14s ease-out;
}
.toast .i { color: var(--ok); }
.toast.bad .i { color: var(--danger); }
@media (prefers-color-scheme: dark) { .toast { background: #2a2f38; color: var(--text); } }

/* ---------- segmented control ---------- */
.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: 8px; background: var(--chip); }
.seg-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 500;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .12); }
.select-wrap { position: relative; display: inline-flex; align-items: center; }
.select-wrap > .i { position: absolute; left: 10px; color: var(--muted); pointer-events: none; }
.select-wrap select { height: 32px; padding-left: 32px; width: auto; max-width: 220px; }
.select-wrap.active > .i { color: var(--accent); }
.select-wrap.active select { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- narrow screens ---------- */
@media (max-width: 1100px) {
  :root { --list-w: 320px; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 25;
    transform: translateX(-102%); transition: transform .18s ease-out; box-shadow: var(--shadow-lg);
  }
  .app.nav-open .side { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: var(--scrim); z-index: 24; }
  .only-narrow { display: inline-flex !important; }
  .hide-narrow { display: none !important; }
  .topbar { padding: 0 10px 0 6px; gap: 6px; height: 56px; }
  .title { flex-direction: column; gap: 0; align-items: flex-start; }
  .title h2 { font-size: 16px; max-width: 100%; }
  .title .sub { font-size: 12px; max-width: 100%; }
  .tools { gap: 4px; }
  .tools .btn .label { display: none; }
  .tools .btn:not(.icon) { width: 32px; padding: 0; }
  .select-wrap select { width: 44px; padding: 0 0 0 32px; color: transparent; }
  .select-wrap select option { color: var(--text); }
  .seg-btn .label { display: none; }
  .mail { grid-template-columns: 1fr; }
  .mail-list { border-right: 0; }
  .mail .reader { display: none; }
  .mail.reading .mail-list { display: none; }
  .mail.reading .reader { display: flex; }
  .reader-head { padding: 12px 16px 16px; }
  .reader-head .back { margin: 0 0 8px -8px; }
  .reader-head.only-narrow { display: block !important; padding-bottom: 4px; border-bottom: 0; }
  .reader-body pre { padding: 16px; }
  .reader-foot { padding: 12px 16px; }
  .page { padding: 12px; }
  th, td { padding: 10px 12px; }
  .row2 { grid-template-columns: 1fr; }
  .modal-head { padding-left: 18px; }
  .modal-body, .modal-foot { padding-left: 18px; padding-right: 18px; }
  .toasts { left: 12px; right: 12px; bottom: 12px; align-items: center; }
}

/* thin scrollbars that follow the theme */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.cell-mbox .muted .tag { margin-left: 6px; }

/* narrow: table rows become cards (first cell and actions on top, the rest below) */
@media (max-width: 820px) {
  table.stack thead { display: none; }
  table.stack tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 8px; padding: 12px; border-bottom: 1px solid var(--line); }
  table.stack tbody tr:last-child { border-bottom: 0; }
  table.stack td { display: block; padding: 0; border: 0; min-width: 0; }
  table.stack tbody tr:hover td { background: transparent; }
  table.stack td.actions { grid-column: 2; grid-row: 1; width: auto; align-self: center; }
  table.stack td:not(:first-child):not(.actions) { grid-column: 1 / -1; }
  table.stack td.num::before, table.stack td[data-label]::before { content: attr(data-label) " "; color: var(--muted); font-size: 12px; }
  table.stack .cell-user { min-width: 0; }
  table.stack td.empty-row { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .side { box-shadow: none; visibility: hidden; transition: transform .18s ease-out, visibility .18s; }
  .app.nav-open .side { box-shadow: var(--shadow-lg); visibility: visible; }
}

/* ---------- second factor (login page) ---------- */
.login-card .steps { margin: 0 0 16px; padding-left: 20px; color: var(--text-2); font-size: 13.5px; }
.login-card .steps li { margin-bottom: 4px; }
.qr { display: grid; place-items: center; margin: 0 0 12px; }
.qr img { width: 180px; height: 180px; image-rendering: pixelated; border-radius: var(--radius); background: #fff; padding: 8px; box-sizing: content-box; }
details.secret { margin-bottom: 16px; font-size: 13px; color: var(--muted); }
details.secret summary { cursor: pointer; }
details.secret .mono { margin-top: 8px; padding: 8px 10px; background: var(--chip); border-radius: var(--radius); color: var(--text); word-break: break-all; user-select: all; }
.recovery { margin: 4px 0 16px; }
.recovery .codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; padding: 12px 14px; background: var(--chip); border-radius: var(--radius); margin-bottom: 10px; color: var(--text); user-select: all; }
.login-card .recovery .btn, .login-card .login-alt .btn { width: auto; height: auto; margin-top: 0; }
.login-card .login-alt { margin-top: 14px; display: flex; justify-content: center; }
.login-card .option { margin: 0 0 12px; }
.login-card .info { padding: 0; margin-bottom: 16px; }
