:root {
  color-scheme: light dark;
  --bg: #0f1419;
  --panel: #151c24;
  --card: #1a222c;
  --text: #e8eef5;
  --muted: #9aa7b5;
  --accent: #3d8bfd;
  --accent-text: #fff;
  --border: #2a3542;
  --unread: #3d8bfd;
  --urgent: #e85d5d;
  --badge: #2a3542;
  --hover: #1f2936;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef1f5;
    --panel: #f7f9fb;
    --card: #ffffff;
    --text: #1a222c;
    --muted: #5b6b7c;
    --border: #d5dde6;
    --badge: #e8eef5;
    --hover: #e8eef5;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
#app { height: 100%; }
.wrap-center {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
  max-width: 420px;
  width: 100%;
}
h1 { margin: 0 0 8px; font-size: 1.35rem; font-weight: 650; }
.muted { color: var(--muted); margin: 0; line-height: 1.45; }
.actions { margin-top: 20px; }
.btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  border: none;
  font: inherit;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.small { padding: 4px 10px; font-size: 12px; }

.shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar .title { font-weight: 650; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }
.search { display: flex; gap: 6px; align-items: center; flex: 0 1 640px; min-width: 260px; }
.search input[type="search"] {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.search select {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.search-head { padding: 8px 14px; border-bottom: 1px solid var(--border); font-size: 13px; display: grid; gap: 4px; }
.search-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.msg-item .snippet { font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
mark { background: #ffe066; color: #111; padding: 0 1px; border-radius: 2px; }

.accounts { padding: 8px 0; }
.acc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: inherit;
  width: 100%;
  text-align: left;
  font: inherit;
}
.acc-item:hover { background: var(--hover); }
.acc-item.active { background: var(--hover); font-weight: 600; }
.acc-item .email { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-item .count {
  min-width: 1.5em;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
}
.acc-item .count.has { color: var(--unread); font-weight: 650; }

.msg-list { padding: 0; }
.msg-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
}
.msg-item:hover { background: var(--hover); }
.msg-item.active { background: var(--hover); }
.msg-item.unread .subject { font-weight: 700; }
.msg-item .from { font-size: 13px; margin-bottom: 2px; }
.msg-item .subject {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.msg-item .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--badge);
  font-size: 11px;
  line-height: 1.4;
}
.badge.urgent { background: color-mix(in srgb, var(--urgent) 25%, var(--badge)); color: var(--urgent); }
.badge.deal { background: color-mix(in srgb, var(--accent) 20%, var(--badge)); color: var(--accent); }

.reader-empty {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--muted); padding: 24px;
}
.reader-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.pager {
  display: flex; gap: 8px; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted);
}
.warn {
  margin: 10px 0 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  font-size: 13px;
}
.tabs-section {
  border-top: 1px solid var(--border);
  padding: 8px 0 16px;
}
.tabs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 14px 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.important-toggle {
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.tab-item .email { font-size: 13px; }
/* Уровни дерева вкладок: отступ 14 + 12 на уровень (как было inline), подразделы ТО мельче и серее */
.tab-item.tab-depth-1 { padding-left: 26px; }
.tab-item.tab-depth-2 { padding-left: 38px; }
.tab-item.tab-depth-3 { padding-left: 50px; }
.tab-item.tab-depth-4 { padding-left: 62px; }
.tab-item.tab-depth-5 { padding-left: 74px; }
.tab-item.tab-depth-6 { padding-left: 86px; }
.tab-item.tab-sub .email { font-size: 12px; color: var(--muted); }
/* Туроператоры: фирменный цвет (--op-color ставит app.js под тему) и значок 16×16 */
.op-item .email { display: flex; align-items: center; gap: 6px; }
.op-item .op-name { overflow: hidden; text-overflow: ellipsis; color: var(--op-color, var(--text)); }
.op-icon { flex: none; width: 16px; height: 16px; border-radius: 3px; object-fit: contain; }
.op-letter {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--op-raw, var(--muted)); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 1;
}
.group-menu { position: relative; display: inline-block; }
.group-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  min-width: 220px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.group-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.group-dropdown button:hover { background: var(--hover); }
.group-current { font-size: 12px; margin-left: 6px; }

/* ---- Ч6: настройки ящиков и журнал ---- */
.acc-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-right: 6px;
  padding: 0 3px;
  border-radius: 5px;
  font-size: 12px;
  line-height: 1;
  vertical-align: -3px;
  background: var(--badge);
  color: #fff;
}
.settings-tabs { display: flex; gap: 4px; }
.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font: inherit;
  padding: 4px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.tab-btn.active { color: var(--text); border-color: var(--border); background: var(--card); }
.settings-page { overflow: auto; padding: 16px; }
.settings-grid {
  display: grid;
  grid-template-columns: minmax(320px, 560px) minmax(280px, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) { .settings-grid { grid-template-columns: 1fr; } }
.settings-form, .settings-preview {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; }
.field > span { font-weight: 600; font-size: 13px; }
.field.inline, label.inline { flex-direction: row; align-items: center; gap: 6px; font-weight: normal; }
.field-row { display: grid; grid-template-columns: 90px 1fr 140px; gap: 12px; }
.field input[type="text"], .field input[type="number"], .field select, .audit-filters select {
  font: inherit;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}
.field input:disabled, .field select:disabled { opacity: 0.7; }
.color-row { display: flex; align-items: center; gap: 8px; }
.color-row input[type="color"] { width: 44px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; }
.sig-toolbar { display: flex; gap: 4px; flex-wrap: wrap; }
.sig-editor {
  min-height: 110px;
  max-height: 320px;
  overflow: auto;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  line-height: 1.45;
}
.sig-editor[contenteditable="false"] { opacity: 0.8; }
.sig-editor img { max-width: 100%; height: auto; }
.settings-actions { display: flex; align-items: center; gap: 12px; }
.acc-state {
  border: 1px solid var(--border);
  border-left: 4px solid #3fb950;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0 0 14px;
}
.acc-state.warn { border-left-color: #d29922; }
.acc-state.error { border-left-color: var(--urgent); }
.acc-state-text { font-weight: 600; }
.acc-state ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); }
.preview-head { font-weight: 600; margin-bottom: 8px; }
.preview-letter { color: var(--muted); margin-bottom: 6px; }
.sig-preview { width: 100%; min-height: 220px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.audit-filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.audit-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
.audit-table th, .audit-table td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.audit-table th { font-size: 12px; color: var(--muted); font-weight: 600; }
.audit-table td { word-break: break-word; }
.nowrap { white-space: nowrap; }

/* ---- Ч7: окно письма ---- */
.compose-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40;
}
.compose-panel {
  position: fixed; z-index: 41;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.compose-head, .compose-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.compose-foot { border-bottom: none; border-top: 1px solid var(--border); }
.compose-head .btn, .compose-foot .btn { margin: 0; }
.compose-head strong { flex: 1; }
.compose-fields { overflow: auto; padding: 10px 14px; flex: 1; }
.compose-row {
  display: grid; grid-template-columns: 72px 1fr; gap: 8px;
  align-items: center; margin-bottom: 8px;
}
.compose-row span { color: var(--muted); font-size: 13px; }
.compose-row input, .compose-row select {
  font: inherit; padding: 6px 8px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text); width: 100%;
}
.compose-row-actions { display: flex; gap: 12px; align-items: center; margin: 0 0 8px 80px; }
.compose-editor-wrap { margin-left: 0; }
.compose-editor {
  min-height: 180px; max-height: 40vh; overflow: auto;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); line-height: 1.45;
}
.compose-sig-preview {
  margin-top: 8px; padding: 8px 10px; border-top: 1px dashed var(--border); font-size: 13px;
}
.compose-sig-line { color: var(--muted); }
.compose-attach { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.compose-file-list { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.compose-file-list .badge button {
  background: none; border: none; color: inherit; cursor: pointer; padding: 0 2px; font: inherit;
}

/* Вкладки корневого и группового уровня: цвет текста и значок 16×16 (Lucide, ISC — icons/LICENSE-lucide.txt).
   Значок — маска в цвет текста; всё классами, без inline style (CSP style-src 'self'). */
.tabc .email, .acc-head .email { display: flex; align-items: center; gap: 6px; }
.tabc .op-name, .acc-head .op-name { overflow: hidden; text-overflow: ellipsis; }
.tab-ic {
  flex: none; width: 16px; height: 16px; background: currentColor;
  -webkit-mask: var(--ic) center / 16px no-repeat; mask: var(--ic) center / 16px no-repeat;
}
.ic-all { --ic: url(/icons/inbox.svg); }
.ic-urgent { --ic: url(/icons/flame.svg); }
.ic-outgoing { --ic: url(/icons/send.svg); }
.ic-operators { --ic: url(/icons/plane.svg); }
.ic-work { --ic: url(/icons/briefcase.svg); }
.ic-wg-bank { --ic: url(/icons/landmark.svg); }
.ic-wg-state_tax_edo { --ic: url(/icons/file-text.svg); }
.ic-wg-receipts { --ic: url(/icons/receipt.svg); }
.ic-wg-visa_gov { --ic: url(/icons/stamp.svg); }
.ic-wg-services { --ic: url(/icons/wrench.svg); }
.ic-wg-travel_platforms { --ic: url(/icons/globe.svg); }
.ic-wg-airlines { --ic: url(/icons/plane-takeoff.svg); }
.ic-wg-marketplace_ads { --ic: url(/icons/newspaper.svg); }
.ic-wg-hr { --ic: url(/icons/user-check.svg); }
.ic-wg-other { --ic: url(/icons/folder.svg); }
.ic-events { --ic: url(/icons/calendar.svg); }
.ic-promo { --ic: url(/icons/megaphone.svg); }
.ic-spam { --ic: url(/icons/ban.svg); }
.ic-unclear { --ic: url(/icons/circle-help.svg); }
.ic-chev { --ic: url(/icons/chevron-right.svg); }
.ic-reply { --ic: url(/icons/reply.svg); }
.ic-reply-all { --ic: url(/icons/reply-all.svg); }
.ic-forward { --ic: url(/icons/forward.svg); }
.ic-mail { --ic: url(/icons/mail.svg); }
.ic-star { --ic: url(/icons/star.svg); }
.ic-trash { --ic: url(/icons/trash-2.svg); }
.ic-more { --ic: url(/icons/ellipsis.svg); }
.ic-back { --ic: url(/icons/arrow-left.svg); }
.ic-close { --ic: url(/icons/x.svg); }
.ic-menu { --ic: url(/icons/menu.svg); }
.ic-prev { --ic: url(/icons/chevron-up.svg); }
.ic-next { --ic: url(/icons/chevron-down.svg); }
.ic-attach { --ic: url(/icons/paperclip.svg); }
.ic-compose { --ic: url(/icons/pen.svg); }
.acc-head.open .ic-chev { --ic: url(/icons/chevron-down.svg); }
.acc-head { font-weight: 600; }
.tabc-all .email { color: #6ea8fe; }
.tabc-urgent .email { color: #ff7b7b; }
.tabc-outgoing .email { color: #3dd6c3; }
.tabc-operators .email { color: #ffb547; }
.tabc-work .email { color: #7fb2ff; }
.tabc-events .email { color: #c49bff; }
.tabc-promo .email { color: #ff8fb8; }
.tabc-spam .email { color: #9aa7b5; }
.tabc-unclear .email { color: #f2c94c; }
@media (prefers-color-scheme: light) {
  .tabc-all .email { color: #1f5fd1; }
  .tabc-urgent .email { color: #c62828; }
  .tabc-outgoing .email { color: #00796b; }
  .tabc-operators .email { color: #a35200; }
  .tabc-work .email { color: #1d4ed8; }
  .tabc-events .email { color: #6d28d9; }
  .tabc-promo .email { color: #b0105a; }
  .tabc-spam .email { color: #5b6b7c; }
  .tabc-unclear .email { color: #7a5d00; }
}

/* ===== Оформление «как Яндекс Почта» (только вид: шрифт, плотность, кнопки, панели).
   Логика, разметка и порядок не меняются. Шрифт — системный (YS Text не распространяется). ===== */
:root {
  --bg: #1f1f22;
  --panel: #1f1f22;
  --card: #2a2a2e;
  --text: #f0f0f2;
  --muted: #9b9ba3;
  --border: #34343a;
  --hover: #2c2c31;
  --badge: #34343a;
  --unread: #f0f0f2;
  --ya-active: #38383f;
  --ya-field: #2c2c31;
  --ya-yellow: #fc3;
  --ya-yellow-hover: #f5be00;
  --ya-btn: #34343a;
  --ya-btn-hover: #3d3d44;
  --ya-link: #6aa8ff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 14px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --panel: #ffffff;
    --card: #ffffff;
    --text: #000000;
    --muted: #7f7f85;
    --border: #e7e8ea;
    --hover: #f2f3f5;
    --badge: #f0f1f3;
    --unread: #000000;
    --ya-active: #e8ebf0;
    --ya-field: #f0f1f3;
    --ya-btn: #f0f1f3;
    --ya-btn-hover: #e4e6e9;
    --ya-link: #0b5bd3;
  }
}
html, body { -webkit-font-smoothing: antialiased; }

/* Кнопки: вторичные — серые плашки, главная («Написать») — жёлтая */
.btn {
  padding: 8px 16px; border-radius: 8px; font-size: 14px; line-height: 20px; font-weight: 500;
  background: var(--ya-btn); color: var(--text); border: none;
  transition: background-color .12s ease;
}
.btn:hover { filter: none; background: var(--ya-btn-hover); }
.btn.ghost { background: var(--ya-btn); border: none; color: var(--text); }
.btn.ghost:hover { background: var(--ya-btn-hover); }
.btn.small { padding: 6px 12px; font-size: 13px; line-height: 18px; border-radius: 8px; }
.btn[disabled] { opacity: .45; cursor: default; }
#open-compose, #fab-compose, .rm-tools [data-act="reply"] {
  background: var(--ya-yellow); color: #000; font-weight: 500;
}
#open-compose:hover, #fab-compose:hover, .rm-tools [data-act="reply"]:hover { background: var(--ya-yellow-hover); }
#open-compose { padding: 9px 22px; font-size: 14px; line-height: 20px; border-radius: 10px; }

/* Верхняя панель и поиск */
.topbar { padding: 10px 20px; gap: 14px; border-bottom: none; background: var(--panel); min-height: 60px; }
.topbar .title { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.topbar .who { font-size: 13px; }
.search { gap: 8px; }
.search input[type="search"], .search select {
  border: none; background: var(--ya-field); border-radius: 10px; color: var(--text);
}
.search input[type="search"] { padding: 10px 14px; font-size: 14px; line-height: 20px; }
.search input[type="search"]:focus { outline: 2px solid var(--ya-yellow); outline-offset: 0; background: var(--panel); }
.search select { padding: 10px 10px; font-size: 13px; }

/* Левая панель: пункты 32px, скруглённая подсветка активного, счётчики справа */
#col-accounts { padding: 4px 8px 12px; border-right: none; }
.accounts { padding: 4px 0; }
.acc-item {
  min-height: 32px; padding: 6px 12px; gap: 10px; border-radius: 8px;
  font-size: 14px; line-height: 20px;
}
.acc-item:hover { background: var(--hover); }
.acc-item.active { background: var(--ya-active); font-weight: 500; }
.acc-item .count { font-size: 13px; color: var(--muted); }
.acc-item .count.has { color: var(--text); font-weight: 600; }
.tab-item .email { font-size: 14px; }
.tab-item.tab-sub .email { font-size: 13px; }
.acc-head { font-weight: 600; }
.tabs-section { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; }
.tabs-head { padding: 8px 12px 4px; font-size: 12px; letter-spacing: .02em; }

/* Список писем: плотные строки, жирное — непрочитанное */
.msg-item {
  padding: 9px 20px 9px 22px; border-bottom: 1px solid var(--border); position: relative;
  font-size: 14px; line-height: 20px;
}
.msg-item:hover { background: var(--hover); }
.msg-item.active { background: var(--ya-active); }
.msg-item .from { font-size: 14px; margin-bottom: 1px; color: var(--text); }
.msg-item.unread .from { font-weight: 700; }
.msg-item.unread .subject { font-weight: 700; }
.msg-item.unread::before {
  content: ""; position: absolute; left: 8px; top: 15px; width: 7px; height: 7px; border-radius: 50%; background: var(--ya-link);
}
.msg-item .subject { margin-bottom: 2px; }
.msg-item .meta { font-size: 12px; }
.badge { border-radius: 6px; padding: 1px 7px; font-size: 12px; }
.pager { padding: 10px 20px; font-size: 13px; }

/* Строка письма в одну линию, как в Яндекс Почте: отправитель | тема, серый фрагмент и метки | дата справа.
   Порядок в разметке прежний (отправитель · дата, тема, фрагмент, метки) — места задаёт сетка. */
.msg-item {
  display: grid; grid-template-columns: minmax(96px, 168px) minmax(0, 1fr) auto; grid-template-areas: "from main when";
  align-items: center; column-gap: 16px; padding-top: 8px; padding-bottom: 8px; min-height: 40px;
}
.msg-item .from { grid-area: from; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item .sep { display: none; }
.msg-item .when { grid-area: when; font-size: 13px; color: var(--muted); white-space: nowrap; }
.msg-item.unread .when { color: var(--text); font-weight: 600; }
.msg-item .main { grid-area: main; display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; }
.msg-item .subject { flex: 1 1 auto; min-width: 150px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-item .snippet { flex: 1 1 0; min-width: 0; margin: 0; display: block; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; -webkit-line-clamp: unset; }
.msg-item .meta { flex: 0 1 auto; min-width: 0; flex-wrap: nowrap; overflow: hidden; gap: 4px; }
.msg-item .meta .badge { white-space: nowrap; max-width: 118px; min-width: 28px; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.msg-item.unread::before { top: 50%; margin-top: -3.5px; }
.msg-item .when { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; }
.msg-item .when .tab-ic { width: 14px; height: 14px; -webkit-mask-size: 14px; mask-size: 14px; color: var(--muted); }
/* ===== Макет. Слева папки (сворачиваются в полосу значков), справа список писем.
   Письмо открывается окном на весь экран (адрес /m/<id>), прокрутка одна — страницы. ===== */
.cols { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 0; height: 100%; }
.col { overflow: auto; background: var(--panel); min-height: 0; }
.col.side { border-right: 1px solid var(--border); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 36px; height: 36px; border: none; border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer; font: inherit;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn[disabled] { opacity: .35; cursor: default; background: transparent; }
.icon-btn.on { color: #d9a400; }
.icon-btn.danger:hover { background: rgba(217, 48, 37, .12); color: #d93025; }
.tab-ic.lg { width: 20px; height: 20px; -webkit-mask-size: 20px; mask-size: 20px; }
.fab, .drawer-backdrop { display: none; }

/* Папки в узкой полосе (только компьютер) */
@media (min-width: 801px) {
  .cols.collapsed { grid-template-columns: 56px minmax(0, 1fr); }
  .cols.collapsed #col-accounts { padding: 4px 6px 12px; }
  .cols.collapsed .side .acc-item { justify-content: center; padding: 6px; }
  .cols.collapsed .side .op-name, .cols.collapsed .side .count, .cols.collapsed .side .tabs-head,
  .cols.collapsed .side .tab-item.tab-sub { display: none; }
  .cols.collapsed .side .acc-item .email { flex: none; justify-content: center; }
  .cols.collapsed .side .acc-mark { margin-right: 0; }
}

/* Письмо на весь экран */
body.modal-open { overflow: hidden; }
.reader-modal {
  position: fixed; inset: 0; z-index: 30; overflow-x: hidden; overflow-y: auto;
  background: var(--bg); -webkit-overflow-scrolling: touch;
}
.reader-modal[hidden] { display: none; }
.rm-bar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 4px;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.rm-grow { flex: 1; }
.rm-tools { display: flex; align-items: center; gap: 2px; }
.rm-tools [data-act="reply"] { width: auto; padding: 0 12px; }
.rm-nav { display: flex; gap: 2px; margin-left: 10px; }
.rm-tools .group-dropdown { left: auto; right: 0; }
.menu-narrow { display: none; }
.menu-title { padding: 8px 10px 4px; font-size: 12px; color: var(--muted); }
.rm-page { max-width: 980px; margin: 16px auto 32px; padding: 22px 32px 40px; background: var(--panel); border-radius: 12px; }
.rm-subject {
  margin: 0 0 10px; font-size: 19px; line-height: 26px; font-weight: 650; letter-spacing: -.01em;
  overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.rm-from { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.rm-meta { font-size: 13px; margin: 2px 0 8px; }
.rm-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.reader-body { margin-top: 14px; }
.reader-iframe { display: block; width: 100%; height: 240px; border: 0; border-radius: 8px; background: #fff; }
.reader-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: 15px; line-height: 1.55; }
.reader-skeleton { height: 260px; border-radius: 8px; background: var(--hover); animation: skeleton-pulse 1.2s ease-in-out infinite; }
@keyframes skeleton-pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .reader-skeleton { animation: none; } }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 6px 10px;
  border-radius: 8px; background: var(--ya-btn); color: var(--text); text-decoration: none; font-size: 13px;
}
.chip:hover { background: var(--ya-btn-hover); }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.thread { margin-top: 20px; padding-top: 10px; border-top: 1px solid var(--border); }
.thread h3 { margin: 0 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.thread button {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  color: inherit; padding: 6px 0; cursor: pointer; font: inherit; font-size: 13px;
}
.thread button:hover { color: var(--ya-link); }
.thread button.active { font-weight: 650; }

/* Телефон: один экран за раз; папки — выезжающая панель; действия письма — полоса внизу */
@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; min-height: 0; }
  .topbar .title { font-size: 18px; flex: 1; }
  .topbar .spacer, .topbar .who, #open-compose { display: none; }
  .topbar .search { order: 10; flex: 1 1 100%; min-width: 0; }
  .search { min-width: 0; }
  .search input[type="search"] { flex: 1 1 0; min-width: 0; width: auto; }
  .search select { flex: 0 1 auto; max-width: 40%; min-width: 0; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .cols { grid-template-columns: minmax(0, 1fr); }
  .msg-item { min-width: 0; }
  .col.side {
    position: fixed; z-index: 26; top: 0; bottom: 0; left: 0; width: min(300px, 86vw);
    transform: translateX(-104%); transition: transform .18s ease; box-shadow: 0 0 24px rgba(0, 0, 0, .3);
  }
  .cols.drawer-open .col.side { transform: none; }
  .drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .4);
    opacity: 0; pointer-events: none; transition: opacity .18s ease;
  }
  .drawer-backdrop.show { opacity: 1; pointer-events: auto; }
  .fab {
    display: flex; align-items: center; justify-content: center; position: fixed; z-index: 20;
    right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border: none;
    border-radius: 50%; background: var(--ya-yellow); color: #000; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); cursor: pointer;
  }
  .msg-item {
    grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "from when" "main main";
    row-gap: 2px; padding: 10px 14px 10px 22px;
  }
  .msg-item.unread::before { top: 17px; margin-top: 0; }
  .msg-item .main { flex-wrap: wrap; white-space: normal; row-gap: 3px; }
  .msg-item .subject { flex: 1 1 100%; min-width: 0; }
  .msg-item .snippet { flex: 1 1 100%; }
  .msg-item .meta { flex: 1 1 100%; flex-wrap: wrap; }
  .msg-item .meta .badge { max-width: none; }
  .rm-nav { display: none; }
  .rm-tools {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; justify-content: space-around;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border);
  }
  .rm-tools .wide { display: none; }
  .rm-tools [data-act="reply"] { width: 44px; padding: 0; }
  .rm-tools .icon-btn { width: 44px; height: 44px; }
  .rm-tools .group-dropdown { top: auto; bottom: 100%; margin-bottom: 6px; }
  .menu-narrow { display: block; }
  .rm-page { margin: 0; padding: 14px 14px calc(84px + env(safe-area-inset-bottom)); border-radius: 0; min-height: 100%; box-sizing: border-box; }
  .rm-subject { font-size: 17px; line-height: 23px; }
}

/* Запасной размер значка табло для страниц, собранных из старых скриптов в кэше браузера. */
.bd-logo { width: 26px; height: 26px; }
