:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --ink: #1d1d1f;
  --ink-2: #424245;
  --muted: #86868b;
  --line: #e5e5ea;
  --line-2: #d2d2d7;
  --black: #111113;
  --green: #1f9d55;
  --green-bg: #e8f6ee;
  --amber: #b26a00;
  --amber-bg: #fff4e0;
  --red: #d70015;
  --red-bg: #fdecee;
  --blue: #0066cc;
  --blue-bg: #e8f1fb;
  --gray-bg: #f0f0f2;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 24px 16px;
  background: rgba(255,255,255,.7); backdrop-filter: blur(20px);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; padding: 0 8px 20px; }
.brand-lg { font-size: 22px; justify-content: center; padding-bottom: 8px; }
.logo {
  width: 30px; height: 30px; border-radius: 9px; background: var(--black); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  padding: 9px 12px; border-radius: var(--radius-sm); color: var(--ink-2); font-weight: 500;
}
.nav a:hover { background: var(--gray-bg); text-decoration: none; }
.nav a.active { background: var(--black); color: #fff; }
.sidebar-foot { margin-top: auto; padding: 0 8px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

.main { padding: 32px 40px 64px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 30px; letter-spacing: -.02em; margin: 0; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
h2 { font-size: 19px; margin: 0 0 14px; letter-spacing: -.01em; }

/* ---------- cards ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card, .section + .section { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 30px; font-weight: 600; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line-2); background: #fff; color: var(--ink); border-radius: 999px;
  padding: 9px 18px; font: 500 14px var(--font); cursor: pointer; transition: background .15s, opacity .15s;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.btn:hover { background: var(--gray-bg); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--black); color: #fff; border-color: var(--black); }
.btn-primary:hover { background: #2c2c2e; }
.btn-danger { color: var(--red); }
.btn-lg { padding: 12px 26px; font-size: 16px; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.link { background: none; border: 0; color: var(--blue); cursor: pointer; padding: 0; font: inherit; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--gray-bg); color: var(--ink-2); white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.plain::before { display: none; }
.pulse::before { animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- forms ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--ink-2); font-weight: 500; margin-bottom: 6px; }
label.field > small { display: block; color: var(--muted); font-size: 12px; margin-top: 5px; }
input[type=text], input[type=password], input[type=number], input[type=file], textarea, select {
  width: 100%; border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 10px 12px;
  font: 15px var(--font); color: var(--ink); background: #fff; outline: none;
}
input:focus, textarea:focus { border-color: var(--black); box-shadow: 0 0 0 3px rgba(0,0,0,.06); }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
input[type=file] { padding: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 42px; height: 26px; border-radius: 999px; background: var(--line-2); transition: .2s; position: relative; flex-shrink: 0; }
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .2s;
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { left: 19px; }

/* ---------- overview ---------- */
.run-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.run-card .state { font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.run-card .meta { color: var(--muted); margin-top: 4px; font-size: 14px; }
.acc-progress { width: 100%; border-collapse: collapse; }
.acc-progress td { padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.acc-progress tr:first-child td { border-top: 0; }
.acc-progress td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.log-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 12px; flex-wrap: wrap; }
.log {
  background: #0f0f10; color: #d6d6d8; border-radius: var(--radius-sm); padding: 14px 16px;
  font: 12.5px/1.6 var(--mono); height: 420px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}
.log .t { color: #6e6e73; margin-right: 8px; }
.log .ok { color: #5ad48b; }
.log .skip { color: #8e8e93; }
.log .warn { color: #ffb340; }
.log .err { color: #ff6961; }
.log .info { color: #d6d6d8; }
.log-empty { color: #6e6e73; }

/* ---------- accounts ---------- */
.acc-list { display: grid; gap: 12px; }
.acc { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; }
.acc-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 600; font-size: 16px; }
.acc-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.acc-stats { display: flex; gap: 20px; margin-top: 10px; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.acc-stats b { font-variant-numeric: tabular-nums; }
.acc-side { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.acc.disabled .acc-title, .acc.disabled .acc-stats { opacity: .5; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); margin: 0 0 6px; font-size: 18px; }
.help { background: var(--gray-bg); border-radius: var(--radius-sm); padding: 14px 16px; font-size: 14px; color: var(--ink-2); }
.help ol { margin: 6px 0 0; padding-left: 20px; }
.help li + li { margin-top: 4px; }

/* ---------- niches ---------- */
.niche { display: grid; gap: 12px; }
.niche-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.niche-head input[type=text] { max-width: 280px; font-weight: 600; }
.niche-head .spacer { flex: 1; }
.niche textarea { min-height: 110px; }
.sticky-bar {
  position: sticky; bottom: 16px; margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px;
  padding: 12px; background: rgba(255,255,255,.85); backdrop-filter: blur(16px);
  border-radius: 999px; box-shadow: var(--shadow); width: fit-content; margin-left: auto;
}

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 0 12px 10px 0; }
.table td { padding: 11px 12px 11px 0; border-top: 1px solid var(--line); vertical-align: top; }
.table td.num { font-variant-numeric: tabular-nums; }
.tabs { display: inline-flex; background: var(--gray-bg); border-radius: 999px; padding: 3px; margin-bottom: 16px; }
.tabs button { border: 0; background: none; padding: 7px 16px; border-radius: 999px; font: 500 14px var(--font); cursor: pointer; color: var(--ink-2); }
.tabs button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- modal & toasts ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .15s; }
.modal { background: #fff; border-radius: 20px; width: 100%; max-width: 520px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.2); max-height: 92vh; overflow-y: auto; }
.modal h2 { margin-bottom: 6px; }
.modal .body { display: grid; gap: 14px; margin: 16px 0 20px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 10px; }
@keyframes fade { from { opacity: 0; } }
.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--black); color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 14px; max-width: 360px; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: fade .2s; }
.toast.err { background: var(--red); }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn:not(.btn-primary) .spinner { border-color: var(--line-2); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: #fff; border-radius: 24px; box-shadow: var(--shadow); padding: 36px 32px; width: 100%; max-width: 380px; text-align: center; display: grid; gap: 14px; }
.login-card p { margin: 0; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: sticky; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; z-index: 10; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; }
  .brand { font-size: 0; gap: 0; }
  .nav { flex-direction: row; }
  .nav a { padding: 7px 11px; font-size: 14px; }
  .sidebar-foot { display: none; }
  .main { padding: 20px 16px 48px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .acc { grid-template-columns: 1fr; }
  .acc-side { justify-content: flex-start; }
  .page-head h1 { font-size: 24px; }
  .log { height: 340px; }
}
