/*
  ФАЙЛ: services/spine-webmail/public/styles.css
  НАЗНАЧЕНИЕ: оформление SPINE Webmail — темы (светлая/тёмная/авто/свой фон),
  плотность, размер шрифта, 3-панельный клиент, центр настроек.
  Тему ставит prefs.js через html[data-theme] и CSS-переменные.
*/
:root {
  --bg: #f6f8fb; --panel: #ffffff; --panel-2: #f0f3f8; --border: #e2e8f0;
  --text: #1a2332; --muted: #64748b; --accent: #3b5bdb; --accent-soft: rgba(59,91,219,.13);
  --unread: #eef2ff; --danger: #e03131; --ok: #2f9e44; --shadow: 0 1px 3px rgba(20,30,50,.08);
  --fs: 14px;
  /* плотность (переопределяется data-density) */
  --pad-msg: 12px 16px; --pad-folder: 9px 12px; --gap-msg: 3px;
}
:root[data-theme="dark"] {
  --bg: #0f141c; --panel: #161d28; --panel-2: #1c2532; --border: #26313f;
  --text: #e6edf6; --muted: #8b98a9; --accent-soft: rgba(92,124,250,.22);
  --unread: #17233b; --danger: #ff6b6b; --ok: #51cf66; --shadow: 0 1px 3px rgba(0,0,0,.3);
}
:root[data-density="compact"] { --pad-msg: 7px 14px; --pad-folder: 6px 12px; --gap-msg: 1px; }
:root[data-density="comfortable"] { --pad-msg: 16px 18px; --pad-folder: 12px 14px; --gap-msg: 5px; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #app { height: 100%; }
body {
  font: var(--fs)/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- свой фон (настройки → внешний вид) ---------- */
body.has-bg::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background: var(--bg-image) center / cover no-repeat fixed;
}
body.has-bg::after {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background: var(--bg); opacity: var(--bg-dim, .55);
}
body.has-bg .sidebar { background: color-mix(in srgb, var(--panel-2) 82%, transparent); backdrop-filter: blur(14px); }
body.has-bg .list-col, body.has-bg .view-col { background: color-mix(in srgb, var(--panel) 86%, transparent); backdrop-filter: blur(14px); }
body.has-bg .login-card { background: color-mix(in srgb, var(--panel) 90%, transparent); backdrop-filter: blur(14px); }

/* ---------- Логин ---------- */
.login-wrap { height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 36px; width: 100%; max-width: 380px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); margin-bottom: 24px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--panel-2);
}
.field input:focus { outline: none; border-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: 10px; background: var(--accent); color: #fff;
  font-weight: 600; width: 100%; transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.small { width: auto; padding: 7px 12px; font-weight: 500; font-size: 13px; }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- Каркас 3 панели (ширины настраиваются перетаскиванием) ---------- */
.mail { display: grid; grid-template-columns: var(--w-side, 232px) 5px var(--w-list, 340px) 5px 1fr; height: 100%; }
.col-resizer { cursor: col-resize; background: transparent; position: relative; z-index: 5; touch-action: none; }
.col-resizer:hover, body.resizing .col-resizer { background: var(--accent-soft); }
.col-resizer::after {
  content: ""; position: absolute; left: 2px; top: 0; bottom: 0; width: 1px; background: var(--border);
}
body.resizing { cursor: col-resize; user-select: none; }

/* свёрнутое меню: узкая полоса иконок */
body.side-collapsed .mail { grid-template-columns: 64px 5px var(--w-list, 340px) 5px 1fr; }
body.side-collapsed .brand-name, body.side-collapsed .folder span:not(.ico),
body.side-collapsed .folder .count, body.side-collapsed .side-sep,
body.side-collapsed .sidebar-foot .who, body.side-collapsed .side-txt,
body.side-collapsed .compose-btn .btn span { display: none; }
body.side-collapsed .side-ico-only { display: inline !important; }
body.side-collapsed .brand { justify-content: center; padding: 14px 6px 8px; }
body.side-collapsed .compose-btn { margin: 4px 8px 10px; }
body.side-collapsed .compose-btn .btn { padding: 11px 0; }
body.side-collapsed .folder { justify-content: center; padding: 11px 6px; }
body.side-collapsed .folder .ico { width: auto; font-size: 16px; }
body.side-collapsed .sidebar-foot { padding: 10px 6px; }
body.side-collapsed .sidebar-foot .row { flex-direction: column; }
body.side-collapsed .acc-item .acc-mail { display: none; }
.side-toggle { margin-left: auto; font-size: 12px; padding: 4px 7px; }
body.side-collapsed .side-toggle { margin: 0 auto; }
.sidebar { background: var(--panel-2); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.brand { padding: 18px 18px 12px; font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand .logo { font-size: 20px; }
.compose-btn { margin: 4px 14px 12px; }
.folders { flex: 1; overflow-y: auto; padding: 4px 8px; }
.folder {
  display: flex; align-items: center; gap: 10px; padding: var(--pad-folder); border-radius: 8px;
  color: var(--text); width: 100%; text-align: left; font-size: 13.5px;
}
.folder:hover { background: var(--panel); }
.folder.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folder .ico { width: 18px; text-align: center; }
.folder .count { margin-left: auto; font-size: 11px; color: var(--muted); background: var(--panel); padding: 1px 7px; border-radius: 20px; }
.folder.active .count { color: var(--accent); }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.sidebar-foot .who { color: var(--text); font-weight: 600; margin-bottom: 8px; word-break: break-all; }

/* ---------- Список писем ---------- */
.list-col { border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-width: 0; }
.list-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.list-head h2 { font-size: 15px; flex: 1; }
.icon-btn { padding: 7px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.search-row { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.search-row input {
  flex: 1; padding: 8px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--panel-2); font-size: 13px;
}
.search-row input:focus { outline: none; border-color: var(--accent); }
.list { flex: 1; overflow-y: auto; }
.msg {
  padding: var(--pad-msg); border-bottom: 1px solid var(--border); cursor: pointer;
  display: flex; flex-direction: column; gap: var(--gap-msg);
}
.msg:hover { background: var(--panel-2); }
.msg.active { background: var(--accent-soft); }
.msg.unread { background: var(--unread); }
.msg.unread .msg-from, .msg.unread .msg-subj { font-weight: 700; }
.msg-top { display: flex; align-items: baseline; gap: 8px; }
.msg-from { flex: 1; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-date { font-size: 11px; color: var(--muted); white-space: nowrap; }
.msg-subj { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* строк превью: 0 — спрятать, 2 — две строки */
:root[data-preview="0"] .msg-preview { display: none; }
:root[data-preview="2"] .msg-preview {
  white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.msg-badges { display: flex; gap: 5px; align-items: center; }
.star { color: var(--muted); }
.star.on { color: #f0a020; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Просмотр письма ---------- */
.view-col { background: var(--panel); display: flex; flex-direction: column; min-width: 0; }
.view-head { padding: 18px 24px; border-bottom: 1px solid var(--border); }
.view-subj { font-size: 19px; font-weight: 700; margin-bottom: 12px; }
.view-meta { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.view-meta .who { flex: 1; min-width: 0; }
.view-meta .who .name { font-weight: 600; }
.view-meta .who .addr { color: var(--muted); font-size: 12px; }
.view-meta .who .rcpt { color: var(--muted); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-actions { display: flex; gap: 6px; }
.view-body { flex: 1; overflow-y: auto; padding: 24px; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.att {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--border); font-size: 13px; color: var(--text);
}
.att:hover { border-color: var(--accent); color: var(--accent); }
.att .sz { color: var(--muted); font-size: 11px; }
.view-body pre { white-space: pre-wrap; word-wrap: break-word; font: inherit; }
.view-body iframe { width: 100%; border: none; min-height: 60vh; background: #fff; border-radius: 8px; }
.view-placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; }
.view-placeholder .big { font-size: 48px; opacity: .5; margin-bottom: 10px; }

/* ---------- Compose ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10,15,25,.45); display: grid; place-items: end center; z-index: 50; }
.compose {
  background: var(--panel); width: 100%; max-width: 640px; border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 30px rgba(0,0,0,.3); display: flex; flex-direction: column; max-height: 88vh;
}
.compose-head { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; align-items: center; }
.compose-head .x { margin-left: auto; }
.compose-body { padding: 6px 18px 14px; display: flex; flex-direction: column; overflow-y: auto; }
.compose-body .row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); padding: 8px 0; }
.compose-body .row label { color: var(--muted); font-size: 13px; width: 56px; }
.compose-body .row input { flex: 1; border: none; background: none; }
.compose-body .row input:focus { outline: none; }
.compose-body .row[hidden] { display: none; }
/* чип-ввод адресатов */
.chip-input {
  flex: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 5px;
  min-width: 0; cursor: text; padding: 2px 0;
}
.chip-input input { flex: 1; min-width: 140px; border: none; background: none; padding: 4px 0; }
.chip-input input:focus { outline: none; }
.chip-input .chips { display: contents; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; max-width: 100%;
  background: var(--accent-soft); color: var(--accent); border: 1px solid transparent;
  border-radius: 14px; padding: 2px 6px 2px 10px; font-size: 12.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden;
}
.chip.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.chip button { color: inherit; opacity: .65; padding: 0 3px; border-radius: 50%; font-size: 11px; }
.chip button:hover { opacity: 1; }

.cc-toggle {
  flex: none; font-size: 12px; color: var(--muted); padding: 4px 8px; border-radius: 6px;
}
.cc-toggle:hover { background: var(--panel-2); color: var(--accent); }
.compose-body textarea { border: none; background: none; resize: none; min-height: 220px; padding: 12px 0; }
.compose-body textarea:focus { outline: none; }
.compose-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.compose-foot .status { color: var(--muted); font-size: 12px; margin-left: auto; }

/* ---------- Центр настроек ---------- */
.settings-back { place-items: center; }
.settings {
  background: var(--panel); width: min(860px, 94vw); height: min(640px, 90vh);
  border-radius: 16px; box-shadow: 0 10px 50px rgba(0,0,0,.35); overflow: hidden;
  display: grid; grid-template-columns: 220px 1fr;
}
.settings-side {
  background: var(--panel-2); border-right: 1px solid var(--border);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 4px;
}
.settings-title { font-weight: 700; font-size: 15px; padding: 0 8px 12px; }
.settings-side nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.stab {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 8px;
  text-align: left; font-size: 13.5px; color: var(--text); width: 100%;
}
.stab:hover { background: var(--panel); }
.stab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.settings-main { padding: 22px 26px; overflow-y: auto; }
.settings-main h2 { font-size: 18px; margin-bottom: 14px; }
.set-block { margin-bottom: 22px; }
.set-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 10px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 13.5px; }
.set-row select, .set-row input[type="text"], .set-row input[type="datetime-local"] {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2);
}
.set-switch { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; cursor: pointer; }
.set-switch input { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--accent); cursor: pointer; }
.set-switch small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.theme-row { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 22px;
  border: 2px solid var(--border); border-radius: 12px; background: var(--panel-2); font-size: 13px;
}
.theme-card:hover { border-color: var(--muted); }
.theme-card.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.tc-ico { font-size: 22px; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent;
  box-shadow: inset 0 0 0 2px var(--panel);
}
.swatch.on { border-color: var(--text); }
.swatch.custom {
  display: grid; place-items: center; background: var(--panel-2); border: 1px dashed var(--border);
  cursor: pointer; font-size: 15px; position: relative; overflow: hidden;
}
.swatch.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.bg-row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.bg-preview {
  width: 180px; height: 105px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2) center / cover no-repeat; display: grid; place-items: center;
  color: var(--muted); font-size: 12px;
}
.bg-controls { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type="range"] { width: 180px; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg-btn { padding: 8px 16px; font-size: 13px; background: var(--panel-2); color: var(--muted); }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sig-text {
  width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel-2); resize: vertical; margin-top: 8px;
}
.sig-text:focus { outline: none; border-color: var(--accent); }
/* редактор подписи */
.sig-toolbar {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  border: 1px solid var(--border); border-bottom: none; border-radius: 10px 10px 0 0;
  background: var(--panel-2); padding: 6px 8px; margin-top: 10px;
}
.sig-toolbar button, .sig-toolbar .tb-btn, .sig-toolbar .sw-color {
  padding: 6px 9px; border-radius: 7px; font-size: 13px; cursor: pointer; color: var(--text);
  display: inline-flex; align-items: center; gap: 3px;
}
.sig-toolbar button:hover, .sig-toolbar .tb-btn:hover, .sig-toolbar .sw-color:hover { background: var(--panel); }
.sig-toolbar .tb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 5px; }
.sig-toolbar .sw-color { position: relative; overflow: hidden; }
.sig-toolbar .sw-color input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.sig-editor {
  min-height: 150px; border: 1px solid var(--border); border-radius: 0 0 10px 10px;
  background: var(--panel); padding: 14px; overflow-y: auto; max-height: 300px;
}
.sig-editor:focus { outline: none; border-color: var(--accent); }
.sig-editor img { max-height: 120px; max-width: 100%; }
.sig-preview {
  border-top: 1px dashed var(--border); margin-top: 4px; padding: 10px 0 4px; opacity: .85;
  background: #fff; border-radius: 8px; padding: 10px; margin-bottom: 6px; color: #333;
}
.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tpl-card {
  text-align: left; border: 2px solid var(--border); border-radius: 12px; padding: 10px 12px;
  background: var(--panel-2); display: flex; flex-direction: column; gap: 8px; cursor: pointer;
}
.tpl-card:hover { border-color: var(--accent); }
.tpl-prev {
  background: #fff; color: #333; border-radius: 8px; padding: 8px; font-size: 11px;
  overflow: hidden; max-height: 110px; pointer-events: none; zoom: .85;
}
@media (max-width: 640px) { .tpl-grid { grid-template-columns: 1fr; } }

/* мульти-аккаунт */
.login-div {
  display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted); font-size: 12px;
}
.login-div::before, .login-div::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.acc-item .acc-mail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.acc-mark {
  display: inline-block; width: 4px; height: 30px; border-radius: 3px; flex: none;
  margin-right: 2px; align-self: center;
}
.msg-top { align-items: center; }

/* ярлыки */
.lbl-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: -1px; }
.lbl-chip {
  display: inline-block; font-size: 10.5px; font-weight: 600; padding: 1px 8px; margin-right: 6px;
  border-radius: 10px; border: 1px solid; vertical-align: 1px;
}
.side-sep {
  margin: 12px 12px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted);
}
.label-picker {
  position: fixed; z-index: 70; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.25); padding: 6px; min-width: 190px;
}
.label-picker button {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 8px; font-size: 13.5px;
}
.label-picker button:hover { background: var(--panel-2); }
.label-picker .ck { margin-left: auto; color: var(--accent); font-weight: 700; }

/* автодополнение адресатов */
.ac-box {
  position: fixed; z-index: 80; min-width: 260px; max-width: 340px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.28); padding: 5px; overflow: hidden;
}
.ac-item {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 8px; font-size: 13px;
}
.ac-item:hover, .ac-item.sel { background: var(--accent-soft); }
.ac-ava { flex: none; }
.ac-main { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-email { color: var(--muted); }

/* раздел «Контакты» */
.ct-toolbar { display: flex; gap: 6px; padding: 10px 12px 6px; align-items: center; }
.ct-toolbar input {
  flex: 1; padding: 8px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--panel-2); font-size: 13px;
}
.ct-toolbar input:focus { outline: none; border-color: var(--accent); }
.ct-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 12px 10px; border-bottom: 1px solid var(--border); }
.ct-crumb { padding: 8px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.ct-list { flex: 1; overflow-y: auto; }
.ct-line { flex-direction: row !important; align-items: center; gap: 10px; }
.co-fav { border-radius: 6px; flex: none; object-fit: contain; }
.co-fallback {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; flex: none;
}
.ct-fields .set-row { border-bottom: 1px solid var(--border); }
.ac-grp {
  font-size: 10px; padding: 0 6px; border-radius: 8px; border: 1px solid var(--border);
  color: var(--muted); margin-left: 4px;
}

/* контакты */
.ct-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.ct-ava {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none;
}
.ct-ava.hist { background: var(--panel-2); }
.ct-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ct-main .muted { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* правила */
.rule-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.rule-row.off .rule-body { opacity: .5; }
.rule-row .rule-body { flex: 1; min-width: 0; }
.rule-toggle input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.cond-row { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }
.cond-row select, .cond-row input {
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2);
}
.cond-row .cv { flex: 1; min-width: 0; }
.danger-ghost { color: var(--danger); }
.danger-ghost:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.guide-body input, .guide-body select {
  padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2);
}

.keys-table { border-collapse: collapse; }
.keys-table td { padding: 7px 14px 7px 0; font-size: 13.5px; }
kbd {
  font: 12px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--panel-2); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 6px; padding: 4px 8px; white-space: nowrap;
}
.about-rows .set-row { border-bottom: 1px solid var(--border); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .93em; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { height: 100%; display: grid; place-items: center; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: 13px; z-index: 100; box-shadow: var(--shadow); }

/* кнопки «назад» и «меню» — только на узком экране */
.back-btn, .nav-btn { display: none; }

/* плашка «поставь как приложение» и инструкция установки */
.install-hint {
  position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 8px; z-index: 60;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 12px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.install-hint span { flex: 1; }
.guide {
  background: var(--panel); width: min(440px, 92vw); border-radius: 16px;
  box-shadow: 0 10px 50px rgba(0,0,0,.35); overflow: hidden; margin: auto;
}
.modal-back:has(.guide) { place-items: center; }
.guide-body { padding: 18px 22px 22px; }
.guide-body ol { padding-left: 22px; display: grid; gap: 10px; font-size: 14.5px; }
.guide-body p { margin-top: 14px; font-size: 13px; }
.kbd-ico { display: inline-block; transform: rotate(180deg); }

@media (max-width: 860px) {
  .mail, body.side-collapsed .mail { grid-template-columns: 1fr; }
  .col-resizer, .side-toggle { display: none; }
  /* iOS зумит страницу при фокусе на поле <16px — держим все поля ввода 16px */
  input, select, textarea { font-size: 16px !important; }
  /* по умолчанию на телефоне показываем СПИСОК писем */
  .sidebar { display: none; }
  .list-col { display: flex; }
  .view-col { display: none; }
  /* открыли письмо — показываем его, список прячем */
  .mail.show-view .list-col { display: none; }
  .mail.show-view .view-col { display: flex; }
  /* папки — выдвижная панель по кнопке «меню» */
  .mail.show-nav .sidebar {
    display: flex; position: fixed; inset: 0; z-index: 40; width: 100%;
    padding-top: env(safe-area-inset-top);
  }
  .back-btn, .nav-btn { display: inline-flex; }
  /* вырезы и «чёлки»: контент не заезжает под статус-бар и индикатор жестов */
  .list-head { padding: calc(12px + env(safe-area-inset-top)) 14px 12px; }
  .view-head { padding: calc(12px + env(safe-area-inset-top)) 16px 12px; }
  .sidebar-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .list { padding-bottom: env(safe-area-inset-bottom); }
  .view-body { padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  /* пальцам нужны крупные цели */
  .icon-btn { padding: 10px 12px; font-size: 16px; }
  .folder { padding: 12px 14px; font-size: 15px; }
  .msg { padding: 14px 16px; }
  .star { padding: 4px 6px; }
  .compose { max-width: 100%; border-radius: 0; max-height: 100dvh; height: 100dvh; }
  .compose-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .settings { grid-template-columns: 1fr; height: 100dvh; width: 100vw; border-radius: 0; }
  .settings-side { flex-direction: row; flex-wrap: wrap; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 10px 10px; border-right: none; border-bottom: 1px solid var(--border); }
  .settings-side nav { flex-direction: row; flex-wrap: wrap; }
  .stab { width: auto; padding: 8px 10px; font-size: 13px; }
  .settings-title { padding: 0 8px; }
  .settings-main { padding: 18px; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .theme-card { padding: 12px 16px; }
  .bg-preview { width: 140px; height: 84px; }
}
