/* News Aggregator — админка. Один файл, без сборки.
   Тёмная тема по умолчанию, светлая — по системе или переключателю. */

:root {
  --bg: #0a0c11;
  --bg-glow: radial-gradient(1200px 600px at 10% -10%, rgba(124, 92, 255, .14), transparent 60%),
             radial-gradient(900px 500px at 110% 10%, rgba(34, 211, 238, .08), transparent 60%);
  --surface: #10131a;
  --surface-2: #151924;
  --surface-3: #1b2030;
  --border: #222839;
  --border-strong: #2e3550;
  --text: #e7eaf3;
  --text-2: #b4bccd;
  --muted: #7d879c;
  --accent: #8b6cff;
  --accent-2: #22d3ee;
  --accent-soft: rgba(139, 108, 255, .14);
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, .14);
  --warn: #f5a524;
  --warn-soft: rgba(245, 165, 36, .14);
  --err: #f43f5e;
  --err-soft: rgba(244, 63, 94, .14);
  --off: #64748b;
  --src-gnews: #6e8bff;
  --src-rbc_crypto: #f5a524;
  --src-tradingview: #22c3a6;
  --series-ok: #22c3a6;
  --series-rejected: #f43f5e;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 10px 30px -12px rgba(0,0,0,.6);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6fa;
    --bg-glow: radial-gradient(1200px 600px at 10% -10%, rgba(124, 92, 255, .10), transparent 60%),
               radial-gradient(900px 500px at 110% 10%, rgba(34, 211, 238, .08), transparent 60%);
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --surface-3: #eef0f6;
    --border: #e4e7ef;
    --border-strong: #d3d8e4;
    --text: #0f1424;
    --text-2: #3a4258;
    --muted: #6b7489;
    --accent: #6d4aff;
    --accent-soft: rgba(109, 74, 255, .10);
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .12);
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-glow: radial-gradient(1200px 600px at 10% -10%, rgba(124, 92, 255, .10), transparent 60%),
             radial-gradient(900px 500px at 110% 10%, rgba(34, 211, 238, .08), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-3: #eef0f6;
  --border: #e4e7ef;
  --border-strong: #d3d8e4;
  --text: #0f1424;
  --text-2: #3a4258;
  --muted: #6b7489;
  --accent: #6d4aff;
  --accent-soft: rgba(109, 74, 255, .10);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-glow);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01", "tnum";
}
a { color: inherit; text-decoration: none; }
a.link { color: var(--accent); }
a.link:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; letter-spacing: -.015em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; color: var(--text-2); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8;
        stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 15px; height: 15px; }

/* --- Каркас ---------------------------------------------------------------- */

.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px;
  padding: 20px 14px; border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 10px 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 20px -6px var(--accent);
}
.brand-name { font-weight: 700; letter-spacing: -.02em; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
             padding: 14px 12px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: var(--text-2);
  font-weight: 500; transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav a.active svg { color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 8px 4px 0; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border);
      border-radius: 12px; background: var(--surface-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
          font-size: 12px; color: #fff; background: linear-gradient(135deg, #f472b6, var(--accent)); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 14px; padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(12px);
}
.topbar .crumbs { color: var(--muted); font-size: 13px; }
.content { padding: 28px 32px 60px; display: flex; flex-direction: column; gap: 22px; max-width: 1480px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* --- Карточки -------------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-body { padding: 18px 20px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 18px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1200px) { .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-main { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .nav-label, .sidebar-foot .me { display: none; }
  .g-2, .g-3, .g-4 { grid-template-columns: 1fr; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}

.kpi { padding: 18px 20px; position: relative; overflow: hidden; }
.kpi::after {
  content: ""; position: absolute; inset: auto -40px -60px auto; width: 140px; height: 140px; border-radius: 50%;
  background: radial-gradient(closest-side, var(--kpi-glow, var(--accent-soft)), transparent);
}
.kpi .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .value { font-size: 30px; font-weight: 700; letter-spacing: -.03em; margin-top: 8px; }
.kpi .sub { margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.kpi .icon-bubble { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
                    background: var(--surface-3); color: var(--text-2); }

/* --- Значки, точки --------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 550; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.src { border-color: transparent; color: var(--src); background: color-mix(in srgb, var(--src) 15%, transparent); }
.src-gnews { --src: var(--src-gnews); }
.src-rbc_crypto { --src: var(--src-rbc_crypto); }
.src-tradingview { --src: var(--src-tradingview); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
.dot.error { background: var(--err); box-shadow: 0 0 0 4px var(--err-soft); }
.dot.live { animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px transparent; } }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
        border: 1px solid var(--border); background: var(--surface); font-size: 12.5px; color: var(--text-2); }

/* --- Таблицы --------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 16px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600;
     background: var(--surface-2); position: sticky; top: 0; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.title-cell { max-width: 620px; }
td.title-cell a { font-weight: 550; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
tr.dim td { opacity: .62; }
.row-link { cursor: pointer; }

/* --- Формы, кнопки --------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  font: 550 13px var(--font); cursor: pointer; transition: transform .06s, background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { border-color: transparent; color: #fff;
               background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent-2)));
               box-shadow: 0 8px 22px -10px var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--border)); background: var(--err-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { width: 36px; padding: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--text-2); font-weight: 550; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search],
input[type=datetime-local], select, textarea {
  height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); font: 14px var(--font); outline: none; transition: border-color .15s, box-shadow .15s; width: 100%;
}
textarea { height: auto; min-height: 76px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); align-items: end; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { width: 280px; }
.toolbar select { width: auto; min-width: 150px; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 550; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-strong);
                 position: relative; transition: background .2s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
                        background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .track { background: var(--accent); border-color: transparent; }
.switch input:checked + .track::after { transform: translateX(16px); }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 550; font-size: 13px; }
.segmented a.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }

/* --- Флэш, ключ ------------------------------------------------------------ */

.flash { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px; font-weight: 550;
         border: 1px solid transparent; animation: slide .25s ease-out; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--err-soft); color: var(--err); }
@keyframes slide { from { transform: translateY(-6px); opacity: 0; } }
.key-reveal {
  border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--border)); border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-soft), transparent); padding: 18px 20px;
}
.key-box { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.key-box code { flex: 1; padding: 11px 14px; border-radius: 10px; background: var(--surface); border: 1px dashed var(--border-strong);
                font-size: 13.5px; overflow-x: auto; white-space: nowrap; user-select: all; }

/* --- Полоски прогресса ----------------------------------------------------- */

.meter { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; min-width: 90px; }
.meter > span { display: block; height: 100%; border-radius: inherit;
                background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.meter.warn > span { background: var(--warn); }
.meter.err > span { background: var(--err); }
.meter-line { display: flex; align-items: center; gap: 10px; }
.meter-line .meter { flex: 1; }

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

.chart { width: 100%; height: 190px; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 3 4; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart rect.seg { transition: opacity .15s; }
.chart g.bar:hover rect.seg { opacity: .78; }
.chart g.bar rect.hit { fill: transparent; }
.chart g.bar:hover rect.hit { fill: color-mix(in srgb, var(--text) 5%, transparent); }
.s-gnews { fill: var(--src-gnews); } .s-rbc_crypto { fill: var(--src-rbc_crypto); } .s-tradingview { fill: var(--src-tradingview); }
.s-ok { fill: var(--series-ok); } .s-rejected { fill: var(--series-rejected); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart-empty { height: 190px; display: grid; place-items: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 12px; }

/* --- Источники ------------------------------------------------------------- */

.source-card { display: flex; flex-direction: column; gap: 14px; }
.source-top { display: flex; align-items: center; gap: 12px; }
.source-logo { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; font-size: 14px;
               color: #fff; background: var(--src); box-shadow: 0 8px 20px -10px var(--src); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.stat b { display: block; font-size: 17px; letter-spacing: -.02em; }
.stat span { font-size: 11.5px; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.err-text { color: var(--err); font-size: 12.5px; font-family: var(--mono); overflow-wrap: anywhere; }

/* --- Новость --------------------------------------------------------------- */

.article { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr) 340px; }
@media (max-width: 1100px) { .article { grid-template-columns: 1fr; } }
.article h1 { font-size: 24px; line-height: 1.3; }
.article .lead { font-size: 15.5px; color: var(--text-2); }
.article .body { white-space: pre-wrap; line-height: 1.7; color: var(--text-2); }
.article img.cover { width: 100%; max-height: 340px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); }
pre.json { margin: 0; padding: 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border);
           overflow: auto; max-height: 420px; font: 12px/1.55 var(--mono); color: var(--text-2); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- Пагинация, пустое ----------------------------------------------------- */

.pager { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 12px 16px;
         border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 36px; height: 36px; opacity: .5; margin-bottom: 8px; }

/* --- Список «последние» ---------------------------------------------------- */

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.feed li:last-child { border-bottom: 0; }
.feed li:hover { background: var(--surface-2); }
.feed .t { font-weight: 550; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.feed .m { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; align-items: center; }

/* --- Логин ----------------------------------------------------------------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; padding: 32px; }
.login-card .brand { padding: 0 0 22px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }

details.more summary { cursor: pointer; color: var(--muted); font-size: 12.5px; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }
