:root {
  --bg: #f4f6fa; --panel: #fff; --text: #1d2433; --muted: #6b7486; --line: #e3e7ee;
  --accent: #1f5fd1; --accent-weak: #e8effc; --ok: #1d8a4e; --ok-weak: #e4f5ec;
  --warn: #a86400; --warn-weak: #fff3dc; --err: #c4352b; --err-weak: #fdeceb;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,30,50,.06), 0 1px 8px rgba(20,30,50,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.top { background: #142240; color: #fff; display: flex; align-items: center; gap: 4px; padding: 0 20px; height: 52px; position: sticky; top: 0; z-index: 10; }
.top .brand { font-weight: 700; margin-right: 20px; letter-spacing: .2px; }
.top a { color: #c9d4ea; padding: 6px 12px; border-radius: 7px; }
.top a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.top a.on { background: rgba(255,255,255,.14); color: #fff; }
.top .spacer { flex: 1; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 24px 20px 60px; }
.wide { max-width: none; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } .grid3 > div { grid-column: auto !important; } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }

label { display: block; font-weight: 600; font-size: 13px; margin: 10px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input:not([type]), select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd6e2; border-radius: 7px; font: inherit; background: #fff; color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
.helptext, .help { color: var(--muted); font-size: 12px; display: block; margin-top: 3px; }
.errorlist { color: var(--err); margin: 4px 0; padding-left: 18px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 7px; border: 1px solid #cfd6e2; background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f3f5f9; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a52b5; }
.btn.green { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--err); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: #eef1f6; color: var(--muted); }
.badge.running, .badge.sending { background: var(--accent-weak); color: var(--accent); }
.badge.finished, .badge.sent { background: var(--ok-weak); color: var(--ok); }
.badge.paused { background: var(--warn-weak); color: var(--warn); }
.badge.error { background: var(--err-weak); color: var(--err); }

.msgs { margin-bottom: 16px; }
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; background: var(--accent-weak); }
.msg.success { background: var(--ok-weak); color: #11542f; }
.msg.error { background: var(--err-weak); color: #7d1d16; }
.msg.warning { background: var(--warn-weak); color: #6b4000; }
.alert { padding: 10px 14px; border-radius: 8px; background: var(--warn-weak); color: #6b4000; margin-bottom: 12px; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

.stats { display: flex; gap: 22px; flex-wrap: wrap; }
.stat b { display: block; font-size: 22px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 12px; }
.progress { height: 6px; background: #eef1f6; border-radius: 4px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--ok); transition: width .4s; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { font: 12px/1 ui-monospace, Consolas, monospace; padding: 5px 8px; border-radius: 6px; background: var(--accent-weak); color: var(--accent); border: 0; cursor: pointer; }
.chip:hover { background: #d7e3fa; }
.chip.col { background: #eef1f6; color: #3b4558; }

.preview-img { width: 100%; border: 1px solid var(--line); border-radius: 6px; display: block; background: #fafbfc; min-height: 120px; }
.mail-preview { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.mail-preview .hdr { background: #f7f9fc; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13px; }
.mail-preview .body { padding: 14px; }
.attach { display: inline-block; margin-top: 10px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }

.map-row { display: grid; grid-template-columns: 140px 24px 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
.map-row code { background: var(--accent-weak); color: var(--accent); padding: 4px 8px; border-radius: 6px; }

.login { max-width: 380px; margin: 10vh auto; }
.login h1 { text-align: center; }
.field-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.field-card .grid3 label { margin-top: 0; }
.tabulator { font-size: 13px; border-radius: 8px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 260px; padding: 7px 10px; border: 1px solid #cfd6e2; border-radius: 7px; font: inherit; }
.toolbar select { width: auto; }
details summary { cursor: pointer; font-weight: 600; }
.tabulator-row .editable-cell { cursor: text; }
.tabulator-row .editable-cell:hover { box-shadow: inset 0 0 0 1px var(--accent); }

/* Форма ящика: сервер, порт и третий параметр SMTP и IMAP стоят в одной строке. */
.account-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0 16px; }
.account-grid > div { grid-column: span 3; }
.account-grid > .f-smtp_port, .account-grid > .f-imap_port { grid-column: span 1; }
.account-grid > .f-smtp_security, .account-grid > .f-sent_folder { grid-column: span 2; }
.account-grid > .f-enabled { grid-column: span 6; }
@media (max-width: 700px) { .account-grid > div { grid-column: 1 / -1 !important; } }

.segmented { display: inline-flex; border: 1px solid #cfd6e2; border-radius: 7px; overflow: hidden; }
.segmented label { margin: 0; font-weight: 500; font-size: 12px; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: 4px 12px; }
.segmented input:checked + span { background: var(--accent); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
textarea.code { font: 12px/1.45 ui-monospace, Consolas, monospace; white-space: pre; overflow: auto; min-height: 260px; }
.mail-frame { display: block; width: 100%; border: 0; min-height: 60px; background: #fff; }

.pdf-link { font-weight: 600; white-space: nowrap; }
.pv-wrap { position: relative; }
.pv-mark { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; border: 2px solid #fff; background: var(--err); box-shadow: 0 0 0 1px rgba(0,0,0,.4); pointer-events: none; }

.narrow { max-width: 1240px; margin-left: auto; margin-right: auto; }
.mode-banner { background: var(--warn-weak); color: #6b4000; padding: 8px 20px; font-size: 13px; text-align: center; border-bottom: 1px solid #f0dcb0; }

.modal { border: 0; border-radius: var(--radius); padding: 20px; width: min(1180px, 95vw); max-height: 90vh; box-shadow: 0 12px 48px rgba(20,30,50,.3); color: var(--text); }
.modal::backdrop { background: rgba(20,30,50,.45); }
.modal-small { width: min(560px, 95vw); }
.modal-scroll { overflow: auto; max-height: 55vh; border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 0; }
.import-table { border-collapse: collapse; font-size: 13px; }
.import-table th { background: #f7f9fc; padding: 8px; min-width: 180px; vertical-align: top; text-align: left; font-weight: 400; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); position: sticky; top: 0; z-index: 1; }
.import-table th select, .import-table th input { padding: 5px 8px; font-size: 13px; }
.import-table th input { margin-top: 6px; }
.import-table th.is-new { background: var(--accent-weak); }
.import-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); white-space: nowrap; }
.import-table .is-skip { opacity: .45; }
.col-line { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
