:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --green: #067647;
  --green-soft: #ecfdf3;
  --red: #b42318;
  --red-soft: #fef3f2;
  --amber: #b54708;
  --amber-soft: #fffaeb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .05);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 15px; }
p { margin: 0; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error-text { color: var(--red); font-size: 13px; min-height: 18px; }

/* ---------- Вход ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 10% 0%, #e0e7ff 0%, transparent 55%),
              radial-gradient(900px 500px at 100% 100%, #ede9fe 0%, transparent 50%),
              #f7f8fc;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.login-brand h1 { font-size: 18px; }
.login-brand p { color: var(--muted); font-size: 12px; }

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  box-shadow: 0 6px 16px rgba(99, 102, 241, .35);
  flex: none;
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 11px;
  border: 2px solid rgba(255, 255, 255, .9);
  border-radius: 4px;
}

/* ---------- Каркас ---------- */

.layout {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0b1220;
  color: #cbd5e1;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 11px; align-items: center; padding: 0 6px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { color: #fff; font-size: 14px; }
.brand-text span { font-size: 11px; color: #94a3b8; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #cbd5e1;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
}
.nav-item .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #475569;
  flex: none;
  transition: background .15s, box-shadow .15s;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active { background: rgba(99, 102, 241, .18); color: #fff; }
.nav-item.active .dot { background: #a5b4fc; box-shadow: 0 0 0 4px rgba(165, 180, 252, .15); }

.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.side-status {
  font-size: 12px;
  color: #94a3b8;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .06);
  border-radius: 10px;
  padding: 9px 11px;
  line-height: 1.4;
}
.side-status.is-running { color: #c7d2fe; }
.side-status.is-captcha { color: #fecaca; }
.side-status.is-error { color: #fca5a5; }
.user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #94a3b8;
  padding: 0 4px;
}
.link {
  background: none;
  border: 0;
  color: #a5b4fc;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}
.link:hover { text-decoration: underline; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px 8px;
  flex-wrap: wrap;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.content { padding: 12px 28px 40px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- Карточки и сетки ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.stat { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; }
.stat-label { color: var(--muted); font-size: 12px; }
.stat strong { font-size: 26px; font-weight: 680; letter-spacing: -.02em; }
.stat small { color: var(--muted); font-size: 11.5px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

/* ---------- Кнопки и поля ---------- */

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  background: #f2f4f7;
  color: var(--ink);
  white-space: nowrap;
}
.btn:hover { background: #e9ecf2; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.danger { background: var(--red-soft); color: var(--red); border-color: #fecdca; }
.btn.danger:hover { background: #fee4e2; }
.btn.ghost { background: #fff; border-color: var(--line); color: #344054; }
.btn.ghost:hover { background: #f9fafb; }
.btn.small { padding: 7px 11px; font-size: 12.5px; }
.btn.wide { width: 100%; padding: 11px; }
.btn.icon { padding: 6px 9px; }

input, select {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  min-width: 0;
}
input:focus { border-color: #a5b4fc; box-shadow: 0 0 0 3px rgba(99, 102, 241, .12); }
input::placeholder { color: #98a2b3; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 12.5px; color: #344054; font-weight: 550; }

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 220px; }

.hint { color: var(--muted); font-size: 12px; margin-top: 10px; line-height: 1.55; }
.empty { color: var(--muted); font-size: 13px; padding: 18px 4px; }

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0 12px;
  cursor: pointer;
  font-weight: 500;
}
.switch-row input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- Статусы ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .75;
}
.pill-idle { background: #f2f4f7; color: #475467; }
.pill-running { background: var(--accent-soft); color: #3538cd; }
.pill-running::before { animation: pulse 1.4s infinite; }
.pill-captcha { background: var(--red-soft); color: var(--red); }
.pill-captcha::before { animation: pulse 1s infinite; }
.pill-login { background: var(--amber-soft); color: var(--amber); }
.pill-error { background: var(--red-soft); color: var(--red); }
.pill-success { background: var(--green-soft); color: var(--green); }
.pill-cancelled { background: #f2f4f7; color: #475467; }

@keyframes pulse {
  0%, 100% { opacity: .4; }
  50% { opacity: 1; }
}

/* ---------- Ход работы ---------- */

.live-body { display: flex; flex-direction: column; gap: 8px; }
.live-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  padding: 3px 0;
}
.live-row span { color: var(--muted); }
.live-row strong { font-weight: 600; text-align: right; word-break: break-word; }

.progress {
  height: 8px;
  background: #eef0f5;
  border-radius: 999px;
  overflow: hidden;
  margin: 4px 0 6px;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  border-radius: 999px;
  transition: width .3s ease;
}

.live-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.shot-box { margin-top: 14px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #0b1220; }
.shot-box img { display: block; width: 100%; height: auto; cursor: zoom-in; }

.captcha {
  margin-top: 14px;
  border: 1px solid #fecdca;
  background: #fffbfa;
  border-radius: 12px;
  padding: 14px;
}
.captcha-head { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; }
.captcha img { display: block; max-width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.captcha-form { display: flex; gap: 8px; margin-top: 10px; }
.captcha-form input { flex: 1; }
.captcha-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* ---------- График ---------- */

.chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 190px;
  padding-top: 10px;
}
.chart-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 100%;
  justify-content: flex-end;
}
.chart-bar .bar {
  width: 100%;
  max-width: 38px;
  background: linear-gradient(180deg, #818cf8, #4f46e5);
  border-radius: 6px 6px 3px 3px;
  min-height: 2px;
  transition: height .3s ease;
}
.chart-bar .bar.zero { background: #e4e7ec; }
.chart-bar .val { font-size: 10.5px; color: var(--muted); }
.chart-bar .lbl { font-size: 10px; color: #98a2b3; white-space: nowrap; }

/* ---------- Списки ---------- */

.list { display: flex; flex-direction: column; gap: 2px; }
.list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px dashed #f0f2f6;
  font-size: 13px;
}
.list-row:last-child { border-bottom: 0; }
.list-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.list-bar {
  grid-column: 1 / -1;
  height: 4px;
  background: #f0f2f6;
  border-radius: 999px;
  overflow: hidden;
}
.list-bar > div { height: 100%; background: #c7d2fe; border-radius: 999px; }

.last-run { font-size: 13px; display: flex; flex-wrap: wrap; gap: 10px 26px; }
.last-run .item { display: flex; flex-direction: column; gap: 2px; }
.last-run .item span { color: var(--muted); font-size: 11.5px; }
.last-run .item strong { font-weight: 600; }

/* ---------- Таблицы ---------- */

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
.table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #98a2b3;
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  padding: 10px;
  border-bottom: 1px solid #f2f4f7;
  vertical-align: middle;
}
.table tbody tr:hover { background: #fafbff; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .w-check { width: 34px; }
.table .w-actions { width: 1%; white-space: nowrap; text-align: right; }
.table .num { font-variant-numeric: tabular-nums; }
.table .org-name { font-weight: 550; }
.table .sub { color: var(--muted); font-size: 11.5px; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #f2f4f7;
  color: #475467;
}
.badge.success { background: var(--green-soft); color: var(--green); }
.badge.error { background: var(--red-soft); color: var(--red); }
.badge.cancelled { background: #f2f4f7; color: #475467; }
.badge.running { background: var(--accent-soft); color: #3538cd; }
.badge.empty { background: var(--amber-soft); color: var(--amber); }
.badge.demo { background: #f4f3ff; color: #5925dc; }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 8px;
}
.icon-btn:hover { background: #f2f4f7; color: var(--ink); }

/* ---------- Модальные окна ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(16, 24, 40, .25);
  padding: 20px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
}
.modal-card.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.captcha-modal-img { display: block; max-width: 100%; margin: 12px 0; border: 1px solid var(--line); border-radius: 10px; }
.lightbox-card { max-width: 1100px; }
.lightbox-card img { display: block; width: 100%; height: auto; border-radius: 10px; }

.run-org-row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f2f4f7; font-size: 13px; }
.run-org-row:last-child { border-bottom: 0; }

/* ---------- Уведомления ---------- */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #101828;
  color: #fff;
  padding: 11px 15px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .25);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 380px;
  z-index: 80;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #912018; }

.kv { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.kv > div { display: flex; justify-content: space-between; gap: 14px; font-size: 12.5px; }
.kv span { color: var(--muted); }
.kv code { background: #f8f9fc; padding: 2px 7px; border-radius: 6px; word-break: break-all; text-align: right; }

/* ---------- Адаптив ---------- */

@media (max-width: 1180px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    overflow: hidden;
  }
  .brand { display: none; }
  .nav {
    flex-direction: row;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item { white-space: nowrap; }
  .sidebar-bottom { margin: 0 0 0 auto; flex-direction: row; align-items: center; flex: none; }
  .side-status { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
}

@media (max-width: 640px) {
  .cards { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1; }
  .table { min-width: 560px; }
  #user-name { display: none; }
}
