:root {
  --bg: #EDEFEA;
  --surface: #FFFFFF;
  --ink: #1C2321;
  --muted: #5B6863;
  --line: #D5DAD3;
  --side: #1E2A27;
  --side-ink: #DCE4DF;
  --accent: #0F6E5A;
  --accent-hover: #0B5847;
  --accent-soft: #DCEEE7;
  --warn: #9A6412;
  --warn-soft: #FBEFD9;
  --err: #B3261E;
  --err-soft: #F8E1DF;
  --queued: #C9D1CB;
  --font: "Golos Text", "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
h1 { font-size: 26px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 14px; font-weight: 600; }
code { background: #F1F3EF; border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 13px; }
pre { background: #F1F3EF; border: 1px solid var(--line); border-radius: 6px; padding: 12px; overflow-x: auto; font-size: 13px; margin: 8px 0 16px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.err { color: var(--err); }
:focus-visible { outline: 3px solid #6FB8A4; outline-offset: 2px; }

/* Каркас */
.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.layout > * { min-width: 0; }
.side {
  background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; padding: 22px 0;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 18px; padding: 0 22px 22px; color: #fff; display: flex; align-items: center; gap: 10px; }
.brand svg { flex: none; }
.side nav { display: flex; flex-direction: column; }
.side nav a {
  color: var(--side-ink); text-decoration: none; padding: 10px 22px;
  border-left: 3px solid transparent;
}
.side nav a:hover { background: rgba(255,255,255,0.05); }
.side nav a.active { border-left-color: #5FC3A6; background: rgba(255,255,255,0.08); color: #fff; font-weight: 600; }
.logout { margin-top: auto; background: none; border: 0; color: #9FB0A9; font: inherit; text-align: left; padding: 10px 22px; cursor: pointer; }
.logout:hover { color: #fff; }

.main { padding: 32px 40px 64px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.back { display: inline-block; font-size: 14px; margin-bottom: 6px; text-decoration: none; }
.back:hover { text-decoration: underline; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 22px 24px; margin-bottom: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { margin: 0; }

/* Формы */
label, .field { display: block; margin-bottom: 16px; }
label > input, label > select, label > textarea, .field textarea {
  display: block; width: 100%; margin-top: 6px;
}
.lbl { display: block; margin-bottom: 6px; }
input, select, textarea {
  font: inherit; color: inherit; background: #fff;
  border: 1px solid #BCC5BE; border-radius: 6px; padding: 9px 11px;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); outline-offset: 0; }
input[type=number] { width: 90px; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset:disabled { opacity: 0.6; }
.check { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; cursor: pointer; }
.inline { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.inline label { margin: 0; }
.inline input[type=email], .inline input[type=search] { min-width: 260px; flex: 1; }
.sm { display: flex; align-items: center; gap: 6px; }
.sm input { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 16px; }
.grid4 input { width: 100%; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.btn {
  font: inherit; font-weight: 500; cursor: pointer;
  border: 1px solid #BCC5BE; background: #fff; color: var(--ink);
  border-radius: 6px; padding: 9px 16px; text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; color: var(--accent); padding-left: 8px; padding-right: 8px; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); }
.btn.small { padding: 5px 10px; font-size: 14px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.note { background: var(--accent-soft); border-radius: 6px; padding: 10px 14px; margin: 0 0 16px; }
.note.warn { background: var(--warn-soft); color: #5B3B07; }
.note.bad { background: var(--err-soft); color: #6E1712; }

/* Таблицы */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 0 12px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px 11px 0; border-bottom: 1px solid #E7EAE5; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td .bar { margin-top: 7px; }
td.num, th.num { text-align: right; }
td .sub { display: block; color: var(--muted); font-size: 13px; }
td.err-text { color: var(--err); font-size: 13px; max-width: 360px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.empty { color: var(--muted); padding: 8px 0; }

/* Статусы */
.badge { display: inline-block; font-size: 13px; font-weight: 500; padding: 3px 10px; border-radius: 20px; background: #E7EAE5; color: var(--muted); white-space: nowrap; }
.st-running, .st-sent, .st-on { background: var(--accent-soft); color: var(--accent); }
.st-paused, .st-queued, .st-sending { background: var(--warn-soft); color: var(--warn); }
.st-failed, .st-off { background: var(--err-soft); color: var(--err); }
.worker { font-size: 14px; display: inline-flex; align-items: center; gap: 8px; }
.worker::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.worker.bad { color: var(--err); }
.worker.bad::before { background: var(--err); }

/* Лента прогресса — главный элемент рассылки */
.bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--queued); min-width: 120px; }
.bar span { display: block; height: 100%; transition: width .6s ease; }
.bar .s-sent { background: var(--accent); }
.bar .s-failed { background: var(--err); }
.bar .s-skipped { background: #8E9993; }
.bar-big {
  height: 22px; border-radius: 4px;
  background: repeating-linear-gradient(135deg, #D7DDD8 0 8px, #CBD2CC 8px 16px);
}
.progress-figs { display: flex; gap: 36px; flex-wrap: wrap; margin: 18px 0 18px; }
.progress-figs div { display: flex; flex-direction: column; }
.progress-figs b { font-size: 30px; line-height: 1.1; font-weight: 600; }
.progress-figs span { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.progress-figs i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.i-sent { background: var(--accent); } .i-failed { background: var(--err); } .i-skipped { background: #8E9993; } .i-queued { background: var(--queued); }
.progress-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; margin-bottom: 12px; }
.progress-head p { margin: 0; }

.figures { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: 10px; background: var(--surface); margin-bottom: 20px; }
.figures div { padding: 18px 22px; border-left: 1px solid var(--line); }
.figures div:first-child { border-left: 0; }
.figures b { display: block; font-size: 30px; font-weight: 600; line-height: 1.15; }
.figures span { color: var(--muted); font-size: 14px; }

.steps ol { margin: 0; padding-left: 22px; }
.steps li { margin-bottom: 6px; }
.steps li.done { color: var(--muted); }
.steps li.done a { color: var(--muted); text-decoration: line-through; }

.events { list-style: none; margin: 0; padding: 0; }
.events li { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 7px 0; border-bottom: 1px solid #E7EAE5; font-size: 14px; }
.events li:last-child { border-bottom: 0; }
.events time { color: var(--muted); }
.events .error { color: var(--err); }

.vars { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { font: inherit; font-size: 13px; background: #F1F3EF; border: 1px solid var(--line); border-radius: 4px; padding: 2px 8px; cursor: pointer; color: var(--ink); }
.chip:hover { border-color: var(--accent); color: var(--accent); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { font: inherit; font-size: 14px; background: none; border: 1px solid transparent; border-radius: 6px; padding: 5px 10px; cursor: pointer; color: var(--muted); }
.tabs button[aria-pressed=true] { border-color: var(--line); background: #F1F3EF; color: var(--ink); font-weight: 500; }

.files { list-style: none; padding: 0; margin: 0 0 14px; }
.files li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid #E7EAE5; }

.preview-frame { width: 100%; height: 520px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.preview-meta { margin: 0 0 12px; }

.result { margin-top: 14px; }

/* Окна */
.modal { border: 0; border-radius: 10px; padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); color: var(--ink); }
.modal::backdrop { background: rgba(20, 28, 26, 0.45); }
.modal form, .modal .modal-body { padding: 24px; }
.modal h2 { font-size: 20px; }
.token-box { font-size: 14px; word-break: break-all; background: #F1F3EF; border: 1px solid var(--line); padding: 12px; border-radius: 6px; user-select: all; }

/* Вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 32px; width: min(400px, 100%); }
.login-box h1 { font-size: 22px; margin-bottom: 22px; }
.login-box .btn { width: 100%; padding: 11px; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 6px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--err); }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 0; overflow-x: auto; }
  .brand { padding: 14px 16px; }
  .side nav { flex-direction: row; }
  .side nav a { border-left: 0; border-bottom: 3px solid transparent; padding: 14px 12px; white-space: nowrap; }
  .side nav a.active { border-bottom-color: #5FC3A6; }
  .logout { margin: 0; padding: 14px 16px; white-space: nowrap; }
  .main { padding: 22px 16px 48px; }
  .grid2, .grid4 { grid-template-columns: 1fr; }
  .figures { grid-template-columns: 1fr 1fr; }
  .figures div:nth-child(3) { border-left: 0; }
  .figures div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .events li { grid-template-columns: 1fr; gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
