:root {
  --bg: #0E1116;
  --panel: #161B23;
  --panel-2: #1D242F;
  --line: #2A3340;
  --text: #E8ECF1;
  --muted: #8A94A6;
  --signal: #FF5C39;
  --cool: #7FB4FF;
  --ok: #69D58C;
  --warn: #E5B95C;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--cool); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono { font-family: var(--mono); }

/* ---------------------------------------------------------------- топбар */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 22px;
  padding: 0 20px; height: 56px;
  background: rgba(14, 17, 22, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: var(--mono); font-weight: 700; letter-spacing: 0.14em;
  font-size: 15px; display: flex; align-items: center; gap: 9px;
  color: var(--text); white-space: nowrap;
}
.brand .rec {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--signal); box-shadow: 0 0 0 0 rgba(255, 92, 57, 0.6);
}
.brand.live .rec { animation: pulse 1.8s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 92, 57, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(255, 92, 57, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 92, 57, 0); }
}
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  padding: 7px 12px; border-radius: 7px; color: var(--muted);
  font-size: 14px; font-weight: 500;
}
.nav a:hover { color: var(--text); background: var(--panel); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--panel-2); }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.chip-next {
  font-family: var(--mono); color: var(--muted); font-size: 12px;
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 20px;
  white-space: nowrap;
}
.chip-next.run { color: var(--signal); border-color: rgba(255, 92, 57, 0.4); }
.chip-ai { font-size: 12px; color: var(--muted); }
.chip-ai b { color: var(--cool); font-weight: 600; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 22px 20px 60px; }

/* ---------------------------------------------------------------- flash */
.flash {
  padding: 11px 15px; border-radius: var(--radius); margin-bottom: 18px;
  font-size: 14px; border: 1px solid var(--line);
}
.flash.ok { background: rgba(105, 213, 140, 0.08); border-color: rgba(105, 213, 140, 0.35); }
.flash.err { background: rgba(255, 92, 57, 0.08); border-color: rgba(255, 92, 57, 0.4); }
.banner-warn {
  padding: 9px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px;
  background: rgba(229, 185, 92, 0.08); border: 1px solid rgba(229, 185, 92, 0.3);
  color: var(--warn);
}

/* ---------------------------------------------------------------- KPI */
.kpi-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px;
}
.kpi {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.kpi .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin-bottom: 7px;
}
.kpi .value { font-family: var(--mono); font-size: 25px; font-weight: 600; }
.kpi .value.signal { color: var(--signal); }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- панели */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
.panel + .panel { margin-top: 16px; }
.section-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); margin: 0 0 14px;
}

/* ---------------------------------------------------------------- фильтры */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
  margin-bottom: 18px; padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
select, input[type="text"], input[type="number"], input[type="password"], textarea {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 8px 10px; font-size: 14px; font-family: var(--sans);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(127, 180, 255, 0.5); outline-offset: -1px; border-color: var(--cool);
}
.field.check { flex-direction: row; align-items: center; gap: 7px; }
.filters .grow { flex: 1; min-width: 150px; }

/* ---------------------------------------------------------------- кнопки */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 8px 14px; font-size: 14px; font-weight: 500;
  font-family: var(--sans);
}
.btn:hover { background: #232c38; text-decoration: none; }
.btn.primary { background: var(--signal); border-color: var(--signal); color: #1a0d08; font-weight: 600; }
.btn.primary:hover { background: #ff6e4f; }
.btn.cool { background: rgba(127, 180, 255, 0.12); border-color: rgba(127, 180, 255, 0.4); color: var(--cool); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- карточки */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px; display: flex; flex-direction: column; gap: 11px; position: relative;
}
.card.alert { border-left: 3px solid var(--signal); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag {
  font-family: var(--mono); font-size: 11px; padding: 2px 7px; border-radius: 5px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.tag.tiktok { color: #9be7ff; }
.tag.instagram { color: #ffa8d2; }
.tag.alert { color: var(--signal); border-color: rgba(255, 92, 57, 0.4); }
.time { font-size: 12px; color: var(--muted); white-space: nowrap; }

.alpha {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 58px; padding: 6px 4px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.alpha .num { font-family: var(--mono); font-size: 24px; font-weight: 700; line-height: 1; }
.alpha .cap { font-size: 9px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-top: 3px; }
.alpha.hot { border-color: rgba(255, 92, 57, 0.5); }
.alpha.hot .num { color: var(--signal); }

.author { font-weight: 600; font-size: 14px; }
.author .followers { color: var(--muted); font-weight: 400; font-size: 12px; }
.caption { font-size: 13px; color: #c5cdda; max-height: 40px; overflow: hidden; }

.metrics { display: flex; flex-wrap: wrap; gap: 6px; }
.metric {
  font-family: var(--mono); font-size: 12px; padding: 3px 8px; border-radius: 5px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
}
.metric b { color: var(--muted); font-weight: 400; }
.metric.hi { color: var(--signal); border-color: rgba(255, 92, 57, 0.3); }

.sound {
  font-size: 12px; color: var(--muted); font-family: var(--mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.spark { width: 100%; height: 30px; display: block; }

.card-actions { display: flex; gap: 8px; margin-top: 2px; flex-wrap: wrap; }
.ai-box {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 11px 13px; font-size: 13px; white-space: pre-wrap; line-height: 1.55;
  color: #d4dbe6;
}

/* ---------------------------------------------------------------- таблицы */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
td.mono, .num-cell { font-family: var(--mono); }
tr:hover td { background: rgba(255, 255, 255, 0.02); }

.status-pill { font-family: var(--mono); font-size: 12px; padding: 2px 9px; border-radius: 20px; }
.status-pill.ok { color: var(--ok); background: rgba(105, 213, 140, 0.1); }
.status-pill.err { color: var(--signal); background: rgba(255, 92, 57, 0.1); }
.status-pill.run { color: var(--warn); background: rgba(229, 185, 92, 0.1); }

.run-log {
  font-family: var(--mono); font-size: 12px; white-space: pre-wrap; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; margin-top: 8px; max-height: 320px; overflow: auto;
}
details summary { cursor: pointer; color: var(--cool); font-size: 13px; }

/* ---------------------------------------------------------------- формы настроек */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-row label { font-size: 13px; color: var(--muted); }
.form-row .hint { font-size: 12px; color: var(--muted); }
.wc-block {
  border: 1px solid var(--line); border-radius: 9px; padding: 14px;
  margin-bottom: 12px; background: var(--panel-2);
}
.wc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 13px; }
.full { width: 100%; }

/* ---------------------------------------------------------------- логин */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 30px;
}
.login-card .brand { justify-content: center; margin-bottom: 6px; font-size: 18px; }
.login-card .tagline { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-card .form-row { margin-bottom: 16px; }
.login-card .btn { width: 100%; justify-content: center; }
.login-err {
  background: rgba(255, 92, 57, 0.1); border: 1px solid rgba(255, 92, 57, 0.4);
  color: var(--signal); padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 16px;
}

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 17px; color: var(--text); margin-bottom: 8px; }

/* digest */
.digest-body { font-size: 15px; line-height: 1.65; }
.digest-body h2 { font-size: 20px; margin: 22px 0 10px; }
.digest-body h3 { font-size: 16px; margin: 18px 0 8px; color: var(--cool); }
.digest-body h4 { font-size: 14px; margin: 14px 0 6px; }
.digest-body ul { padding-left: 20px; }
.digest-body li { margin-bottom: 5px; }
.digest-body a { word-break: break-all; }

@media (max-width: 760px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .nav { order: 3; width: 100%; }
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 12px; }
  .grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .brand.live .rec { animation: none; }
  * { scroll-behavior: auto !important; }
}
