/* «Библиотека рассылок» (Алекс 20.11.2026) — mailing-library.js (window.MLB), панель #mailLibTab.
   Цвет получателя: клиентам — бирюзовый, внутренние — фиолетовый, лидам продаж — янтарный; статус всегда с подписью.
   Метка слева у строк — ровная планка внутри (::before), не border-left: у скруглённой карточки она загибалась бы серпом. */
.mlb {
    --mlb-client: #0f766e; --mlb-client-bg: rgba(15, 118, 110, .1);
    --mlb-staff: #6246c7; --mlb-staff-bg: rgba(98, 70, 199, .1);
    --mlb-lead: #b45309; --mlb-lead-bg: rgba(217, 119, 6, .13);
    --mlb-ok: #15803d; --mlb-ok-bg: rgba(21, 128, 61, .1); --mlb-warn: #b45309; --mlb-warn-bg: rgba(217, 119, 6, .13);
    --mlb-err: #c62828; --mlb-err-bg: rgba(198, 40, 40, .09); --mlb-info: #0b63b5; --mlb-info-bg: rgba(11, 99, 181, .1);
    --mlb-line: var(--border-color); --mlb-soft: var(--surface-bg, #f8f9fa); --mlb-radius: 12px;
    flex: none; display: flex; flex-direction: column; gap: 14px; padding: 18px 22px 36px; max-width: 1500px; color: var(--text-color);
}
body[data-theme="dark"] .mlb {
    --mlb-client: #5eead4; --mlb-client-bg: rgba(94, 234, 212, .13);
    --mlb-staff: #b9a7f7; --mlb-staff-bg: rgba(185, 167, 247, .14);
    --mlb-lead: #fbbf24; --mlb-lead-bg: rgba(251, 191, 36, .14);
    --mlb-ok: #4ade80; --mlb-ok-bg: rgba(74, 222, 128, .13); --mlb-warn: #fbbf24; --mlb-warn-bg: rgba(251, 191, 36, .14);
    --mlb-err: #fca5a5; --mlb-err-bg: rgba(252, 165, 165, .13); --mlb-info: #93c5fd; --mlb-info-bg: rgba(147, 197, 253, .14);
    --mlb-soft: rgba(255, 255, 255, .04);
}
/* .main-content > .tab-panel.active режет переполнение — раздел прокручивается сам */
#mailLibTab.active { overflow-y: auto; min-height: 0; }

.mlb [data-slot="body"] { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.mlb [data-slot="body"] > :empty { display: none; }
.mlb-head { display: flex; align-items: center; justify-content: space-between; gap: 12px 18px; flex-wrap: wrap; }
.mlb-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mlb-title h2 { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.2; }
.mlb-title span:not(.mlb-logo) { display: block; max-width: 760px; font-size: 12.5px; line-height: 1.4; color: var(--text-muted); }
.mlb-logo { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 40px; height: 40px; border-radius: 11px; background: var(--mlb-client-bg); color: var(--mlb-client); }
.mlb-head-r { display: flex; align-items: center; gap: 8px; }
.mlb-tabs { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--mlb-line); border-radius: 11px; background: var(--card-bg); }
.mlb-tab { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 13px; border: 0; border-radius: 8px; background: none; color: var(--text-muted); font: inherit; font-size: 13px; cursor: pointer; }
.mlb-tab:hover { color: var(--text-color); }
.mlb-tab.on { background: var(--primary-color); color: #fff; font-weight: 600; }
.mlb-tab:focus-visible, .mlb-btn:focus-visible, .mlb-aud:focus-visible, .mlb-row-h:focus-visible, .mlb-sec-h:focus-visible, .mlb-ev:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; }

.mlb-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 13px; border: 1px solid var(--mlb-line); border-radius: 9px; background: var(--card-bg); color: var(--text-color); font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; transition: border-color .15s, color .15s; }
.mlb-btn:hover { border-color: var(--primary-color); color: var(--primary-color); }
.mlb-btn.icon { width: 36px; padding: 0; }
.mlb-btn.primary { background: var(--primary-color); border-color: var(--primary-color); color: #fff; font-weight: 600; }
.mlb-btn.primary:hover { color: #fff; filter: brightness(1.08); }
.mlb-btn:disabled { opacity: .6; cursor: default; }
.mlb-btn.is-busy svg { animation: mlb-spin 1s linear infinite; }
@keyframes mlb-spin { to { transform: rotate(360deg); } }

/* Кому: четыре плитки-переключателя со счётчиками */
.mlb-auds { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.mlb-aud { position: relative; display: flex; align-items: center; gap: 11px; min-width: 0; padding: 12px 14px 12px 16px; border: 1px solid var(--mlb-line); border-radius: var(--mlb-radius); background: var(--card-bg); color: inherit; font: inherit; text-align: left; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.mlb-aud::before { content: ''; position: absolute; left: 0; top: 24%; bottom: 24%; width: 4px; border-radius: 0 4px 4px 0; background: var(--mlb-c, var(--mlb-line)); }
.mlb-aud.a-client { --mlb-c: var(--mlb-client); --mlb-cbg: var(--mlb-client-bg); }
.mlb-aud.a-staff { --mlb-c: var(--mlb-staff); --mlb-cbg: var(--mlb-staff-bg); }
.mlb-aud.a-lead { --mlb-c: var(--mlb-lead); --mlb-cbg: var(--mlb-lead-bg); }
.mlb-aud.a-all { --mlb-c: var(--primary-color); --mlb-cbg: var(--primary-light); }
.mlb-aud:hover { border-color: var(--mlb-c); }
.mlb-aud.on { border-color: var(--mlb-c); box-shadow: 0 0 0 1px var(--mlb-c) inset; background: color-mix(in srgb, var(--mlb-cbg) 55%, var(--card-bg)); }
.mlb-aud-ic { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px; border-radius: 10px; background: var(--mlb-cbg); color: var(--mlb-c); }
.mlb-aud-t { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.mlb-aud-t b { font-size: 14px; font-weight: 700; }
.mlb-aud-t i { font-style: normal; font-size: 11.5px; line-height: 1.3; color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mlb-aud-n { flex: none; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--mlb-c); }

.mlb-bar { display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap; }
.mlb-search { display: inline-flex; align-items: center; gap: 8px; flex: 1 1 280px; max-width: 460px; height: 36px; padding: 0 12px; border: 1px solid var(--mlb-line); border-radius: 9px; background: var(--card-bg); color: var(--text-muted); }
.mlb-search:focus-within { border-color: var(--primary-color); }
.mlb-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text-color); font: inherit; font-size: 13px; }
.mlb-select { height: 36px; min-width: 220px; max-width: 340px; padding: 0 32px 0 12px; border: 1px solid var(--mlb-line); border-radius: 9px; background-color: var(--card-bg); color: var(--text-color); font: inherit; font-size: 13px; cursor: pointer; }
.mlb-check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-color); cursor: pointer; user-select: none; }
.mlb-bar-sum { margin-left: auto; font-size: 12.5px; color: var(--text-muted); }

.mlb-note { display: flex; align-items: flex-start; gap: 8px; padding: 10px 14px; border: 1px solid var(--mlb-line); border-radius: 10px; background: var(--mlb-soft); font-size: 12.5px; line-height: 1.45; color: var(--text-muted); }
.mlb-note + .mlb-note { margin-top: 8px; }
.mlb-note svg { flex: none; margin-top: 1px; color: var(--mlb-info); }
.mlb-note.warn { border-color: color-mix(in srgb, var(--mlb-warn) 40%, transparent); background: var(--mlb-warn-bg); color: var(--text-color); }
.mlb-note.warn svg { color: var(--mlb-warn); }

/* Раздел и строки */
.mlb-sec { margin-bottom: 14px; }
.mlb-sec-h { display: flex; align-items: center; gap: 8px; padding: 6px 4px; cursor: pointer; user-select: none; border-radius: 8px; }
.mlb-sec-h h3 { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.mlb-sec-h > i { font-style: normal; min-width: 22px; height: 20px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--mlb-soft); border: 1px solid var(--mlb-line); font-size: 11.5px; font-weight: 700; color: var(--text-muted); }
.mlb-sec-sum { margin-left: auto; font-size: 12px; color: var(--text-muted); }
.mlb-chev { display: inline-flex; color: var(--text-muted); transition: transform .15s; }
.mlb-sec.closed .mlb-sec-h .mlb-chev { transform: rotate(-90deg); }
.mlb-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }

.mlb-row { position: relative; border: 1px solid var(--mlb-line); border-radius: var(--mlb-radius); background: var(--card-bg); transition: border-color .15s, box-shadow .15s; }
.mlb-row::before { content: ''; position: absolute; left: 0; top: 14px; height: 34px; width: 4px; border-radius: 0 4px 4px 0; background: var(--mlb-c, var(--mlb-line)); }
.mlb-row.a-client { --mlb-c: var(--mlb-client); }
.mlb-row.a-staff { --mlb-c: var(--mlb-staff); }
.mlb-row.a-lead { --mlb-c: var(--mlb-lead); }
.mlb-row:hover, .mlb-row.open { border-color: color-mix(in srgb, var(--mlb-c) 55%, var(--mlb-line)); box-shadow: var(--shadow); }
.mlb-row.is-off::before { background: var(--mlb-line); }
.mlb-row.is-off .mlb-row-main > b { color: var(--text-muted); }
.mlb-row-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 12px 14px 12px 18px; cursor: pointer; border-radius: var(--mlb-radius); }
.mlb-row-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.mlb-row-main > b { font-size: 14px; font-weight: 600; line-height: 1.3; }
.mlb-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.mlb-chip { display: inline-flex; align-items: center; gap: 4px; height: 21px; padding: 0 8px; border-radius: 6px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--mlb-soft); border: 1px solid var(--mlb-line); color: var(--text-muted); }
.mlb-chip.a-client { background: var(--mlb-client-bg); border-color: transparent; color: var(--mlb-client); }
.mlb-chip.a-staff { background: var(--mlb-staff-bg); border-color: transparent; color: var(--mlb-staff); }
.mlb-chip.a-lead { background: var(--mlb-lead-bg); border-color: transparent; color: var(--mlb-lead); }
.mlb-chip.k-auto { background: var(--mlb-info-bg); border-color: transparent; color: var(--mlb-info); }
.mlb-chip.s-on { background: var(--mlb-ok-bg); border-color: transparent; color: var(--mlb-ok); }
.mlb-chip.s-off { background: var(--mlb-err-bg); border-color: transparent; color: var(--mlb-err); }
.mlb-when, .mlb-chan { display: flex; align-items: flex-start; gap: 6px; margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--text-muted); }
.mlb-when svg, .mlb-chan svg { flex: none; margin-top: 2px; }
.mlb-when span { color: var(--text-color); }
.mlb-row-side { display: flex; align-items: center; gap: 12px; flex: none; padding-top: 1px; }
.mlb-row-stat { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.mlb-row-stat b { color: var(--text-color); font-variant-numeric: tabular-nums; }
.mlb-row.open .mlb-row-h .mlb-chev { transform: rotate(180deg); }

.mlb-detail { display: flex; flex-direction: column; gap: 10px; padding: 2px 14px 14px 18px; }
.mlb-text { padding: 12px 14px; border-radius: 10px; background: var(--mlb-soft); border: 1px solid var(--mlb-line); font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 860px; }
.mlb-text mark { padding: 1px 4px; border-radius: 4px; background: var(--mlb-info-bg); color: var(--mlb-info); font-weight: 600; }
.mlb-part > b { display: block; margin-bottom: 5px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.mlb-tnote { display: flex; align-items: flex-start; gap: 7px; margin: 0; max-width: 860px; font-size: 12.5px; line-height: 1.5; color: var(--text-muted); }
.mlb-tnote svg { flex: none; margin-top: 2px; color: var(--mlb-info); }
.mlb-vars { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.mlb-vars code { padding: 2px 6px; border-radius: 5px; background: var(--mlb-soft); border: 1px solid var(--mlb-line); font-family: inherit; font-size: 12px; color: var(--text-color); }
.mlb-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.mlb-from { font-size: 12px; color: var(--text-muted); }

.mlb-skel { display: flex; flex-direction: column; gap: 12px; }
.mlb-skel i { display: block; height: 84px; border-radius: var(--mlb-radius); background: linear-gradient(90deg, var(--mlb-soft), var(--hover-bg, #f1f3f4), var(--mlb-soft)); background-size: 200% 100%; animation: mlb-shine 1.2s linear infinite; }
@keyframes mlb-shine { to { background-position: -200% 0; } }
.mlb-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 48px 20px; text-align: center; color: var(--text-muted); border: 1px dashed var(--mlb-line); border-radius: var(--mlb-radius); }
.mlb-empty.compact { padding: 26px 16px; }
.mlb-empty b { color: var(--text-color); font-size: 15px; }
.mlb-empty span { max-width: 560px; font-size: 13px; line-height: 1.5; }
.mlb-empty.is-err svg { color: var(--mlb-err); }

/* «По дням» */
.mlb-days { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.mlb-days-col > h3 { display: flex; align-items: center; gap: 7px; margin: 0 0 10px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.mlb-day { margin-bottom: 12px; }
.mlb-day-h { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.mlb-day-h i { font-style: normal; padding: 1px 7px; border-radius: 6px; background: var(--primary-light); color: var(--primary-color); font-size: 11.5px; font-weight: 600; }
.mlb-day-evs { display: flex; flex-direction: column; gap: 6px; }
.mlb-ev { position: relative; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 9px 12px 9px 16px; border: 1px solid var(--mlb-line); border-radius: 10px; background: var(--card-bg); cursor: pointer; transition: border-color .15s; }
.mlb-ev::before { content: ''; position: absolute; left: 0; top: 24%; bottom: 24%; width: 3px; border-radius: 0 3px 3px 0; background: var(--mlb-line); }
.mlb-ev.s-ok::before { background: var(--mlb-ok); }
.mlb-ev.s-info::before { background: var(--mlb-info); }
.mlb-ev.s-warn::before { background: var(--mlb-warn); }
.mlb-ev.s-err::before { background: var(--mlb-err); }
.mlb-ev:hover { border-color: var(--primary-color); }
.mlb-ev time { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.mlb-ev-t { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.mlb-ev-t b { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mlb-ev-t span { font-size: 11.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mlb-ev-n { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mlb-pill { display: inline-flex; align-items: center; height: 21px; padding: 0 8px; border-radius: 6px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--mlb-soft); border: 1px solid var(--mlb-line); color: var(--text-muted); }
.mlb-pill.p-ok { background: var(--mlb-ok-bg); border-color: transparent; color: var(--mlb-ok); }
.mlb-pill.p-info { background: var(--mlb-info-bg); border-color: transparent; color: var(--mlb-info); }
.mlb-pill.p-warn { background: var(--mlb-warn-bg); border-color: transparent; color: var(--mlb-warn); }
.mlb-pill.p-err { background: var(--mlb-err-bg); border-color: transparent; color: var(--mlb-err); }

@media (max-width: 1180px) {
    .mlb-auds { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mlb-days { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
    .mlb { padding: 14px 12px 28px; }
    .mlb-head-r { width: 100%; justify-content: space-between; }
    .mlb-auds { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
    .mlb-aud { padding: 10px 10px 10px 13px; gap: 8px; }
    .mlb-aud-ic { display: none; }
    .mlb-aud-t i { display: none; }
    .mlb-aud-n { font-size: 18px; }
    .mlb-search { flex-basis: 100%; max-width: none; }
    .mlb-select { flex: 1 1 100%; max-width: none; min-width: 0; }
    .mlb-bar-sum { margin-left: 0; flex-basis: 100%; }
    .mlb-sec-h { flex-wrap: wrap; }
    .mlb-sec-sum { flex-basis: 100%; margin-left: 23px; }
    .mlb-row-h { flex-direction: column; gap: 8px; padding: 12px 12px 12px 16px; }
    .mlb-row-side { width: 100%; justify-content: space-between; }
    .mlb-row-stat { white-space: normal; }
    .mlb-detail { padding: 2px 12px 12px 16px; }
    .mlb-ev { grid-template-columns: 40px minmax(0, 1fr) auto; }
    .mlb-ev .mlb-pill { grid-column: 2 / -1; justify-self: start; }
}
