:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e8ecf3;
  --muted: #97a1b3;
  --accent: #4f8cff;
  --ok: #3ecf8e;
  --warn: #ffb020;
  --danger: #ff5c5c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}

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

header.top {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.brand { font-weight: 700; font-size: 17px; }
.brand span { color: var(--muted); font-weight: 400; }
nav { display: flex; gap: 6px; flex-wrap: wrap; }
nav a {
  padding: 7px 13px;
  border-radius: 8px;
  color: var(--muted);
}
nav a:hover { background: var(--panel-2); text-decoration: none; }
nav a.active { background: var(--accent); color: #fff; }
.spacer { flex: 1; }

main { padding: 24px; max-width: 1200px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 17px; margin: 26px 0 12px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
}
.card .label { color: var(--muted); font-size: 13px; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 6px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-top: 18px;
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: rgba(62, 207, 142, .4); }
.badge.warn { color: var(--warn); border-color: rgba(255, 176, 32, .4); }
.badge.danger { color: var(--danger); border-color: rgba(255, 92, 92, .4); }

input, select, textarea, button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(79, 140, 255, .45); }
textarea { width: 100%; min-height: 80px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.field input, .field select { width: 100%; }

button, .btn {
  cursor: pointer;
  background: var(--accent);
  border: 1px solid transparent;
  color: #fff;
  font-weight: 600;
}
/* ссылки-кнопки не наследуют отступы полей формы — задаём их явно */
.btn {
  display: inline-block;
  padding: 9px 13px;
  border-radius: 9px;
  font-size: 14px;
  line-height: 1.2;
}
button:hover, .btn:hover { filter: brightness(1.1); text-decoration: none; }
button.ghost { background: var(--panel-2); color: var(--text); border-color: var(--line); font-weight: 500; }
button.danger { background: transparent; color: var(--danger); border-color: rgba(255, 92, 92, .4); font-weight: 500; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

.muted { color: var(--muted); }
.right { text-align: right; }
.money { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.screenshot { max-width: 100%; border-radius: 12px; border: 1px solid var(--line); }
.note {
  background: rgba(79, 140, 255, .1);
  border: 1px solid rgba(79, 140, 255, .3);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-box { width: 100%; max-width: 360px; }
.err { color: var(--danger); font-size: 14px; margin-bottom: 12px; }

details summary { cursor: pointer; padding: 10px 0; font-weight: 600; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input[type="text"] { min-width: 220px; }

/* ------------------------------------------------------------ анимации */

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes pop-in {
  0%   { opacity: 0; transform: scale(.94); }
  60%  { transform: scale(1.02); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(255, 176, 32, .45); }
  70%  { box-shadow: 0 0 0 8px rgba(255, 176, 32, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 176, 32, 0); }
}
@keyframes draw-line {
  from { stroke-dashoffset: var(--len, 1600); }
  to   { stroke-dashoffset: 0; }
}
@keyframes stripe-move {
  from { background-position: 0 0; }
  to   { background-position: 28px 0; }
}

.fade-in { animation: fade-up .38s cubic-bezier(.22, .8, .3, 1) both; }

.card, .panel { animation: fade-up .42s cubic-bezier(.22, .8, .3, 1) both; }
.cards .card:nth-child(2) { animation-delay: .04s; }
.cards .card:nth-child(3) { animation-delay: .08s; }
.cards .card:nth-child(4) { animation-delay: .12s; }
.cards .card:nth-child(5) { animation-delay: .16s; }
.cards .card:nth-child(6) { animation-delay: .2s; }

.card {
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.card:hover {
  transform: translateY(-3px);
  border-color: rgba(79, 140, 255, .45);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .35);
}
.card .value { transition: color .2s ease; }
.card:hover .value { color: var(--accent); }

.stagger { animation: fade-up .34s ease both; animation-delay: calc(var(--i, 0) * 28ms); }

tbody tr { transition: background .16s ease, transform .16s ease; }
tbody tr:hover { transform: translateX(2px); }

nav a { transition: background .18s ease, color .18s ease, transform .18s ease; }
nav a:hover { transform: translateY(-1px); }

button, .btn { transition: filter .15s ease, transform .12s ease, box-shadow .15s ease; }
button:hover, .btn:hover { box-shadow: 0 6px 18px rgba(79, 140, 255, .25); }
button:active, .btn:active { transform: scale(.97); }

input, select, textarea { transition: border-color .15s ease, box-shadow .15s ease; }

a { transition: color .15s ease; }

.dot-badge {
  display: inline-block;
  min-width: 18px;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  animation: pop-in .3s ease both;
}
.badge.pulse { animation: pulse-ring 2s ease-out infinite; }

/* ------------------------------------------------------------ графики */

.chart-panel { position: relative; }
.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.chart-title { font-weight: 600; font-size: 15px; }
.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--c);
  flex: none;
  margin-top: 4px;
}
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart-line {
  /* --len приходит из charts.py: реальная длина ломаной */
  stroke-dasharray: var(--len, 1600);
  animation: draw-line 1s cubic-bezier(.4, 0, .2, 1) both;
}
.chart-area { animation: fade-up .7s ease .25s both; }
.chart-dot, .chart-label { animation: pop-in .35s ease .85s both; }
.chart-hit { cursor: crosshair; transition: fill .15s ease; }
.chart-hit:hover { fill: rgba(255, 255, 255, .04); }
.chart-cross { transition: opacity .15s ease; pointer-events: none; }
.chart-tip {
  position: absolute;
  transform: translateX(-50%);
  padding: 6px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
  animation: pop-in .16s ease both;
}

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg a { padding: 7px 13px; color: var(--muted); font-size: 13px; }
.seg a:hover { background: var(--panel-2); text-decoration: none; }
.seg a.on { background: var(--accent); color: #fff; }

/* ------------------------------------------------------------ чат */

.chat-log {
  max-height: 62vh;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.bubble.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.out {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: rgba(79, 140, 255, .16);
  border-color: rgba(79, 140, 255, .35);
}
.bubble-text { white-space: pre-wrap; word-break: break-word; }
.bubble-meta { margin-top: 5px; font-size: 11px; color: var(--muted); }
.bubble-media {
  max-width: 100%;
  max-height: 320px;
  border-radius: 10px;
  margin-bottom: 6px;
  display: block;
  transition: transform .2s ease;
}
.bubble-media:hover { transform: scale(1.01); }

.file-btn {
  display: inline-block;
  margin: 0;
  padding: 9px 13px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease;
}
.file-btn:hover { border-color: var(--accent); background: var(--panel-2); }
.file-name { font-size: 13px; }

/* ------------------------------------------------------------ рассылка */

.progress {
  height: 7px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--ok));
  transition: width .5s cubic-bezier(.3, .8, .3, 1);
}
tr[data-status="running"] .progress-bar {
  background-image: linear-gradient(
    45deg,
    rgba(255, 255, 255, .18) 25%, transparent 25%,
    transparent 50%, rgba(255, 255, 255, .18) 50%,
    rgba(255, 255, 255, .18) 75%, transparent 75%
  );
  background-size: 28px 28px;
  animation: stripe-move .8s linear infinite;
}

.ok-note { background: rgba(62, 207, 142, .1); border-color: rgba(62, 207, 142, .35); }
.danger-note { background: rgba(255, 92, 92, .1); border-color: rgba(255, 92, 92, .35); }

/* ------------------------------------------------------------ доступность */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .chart-line { stroke-dasharray: none; }
  tbody tr:hover, .card:hover, nav a:hover { transform: none; }
}
.inline-form input[type="number"] { width: 100px; }
