/* Uzum Analytics — тёмная «data-console» тема.
   Палитра: глубокий слейт + электрический циан-акцент, моноширинные числа. */

:root {
  --bg:            #0a0e14;
  --bg-grid:       #0e131b;
  --surface:       #11171f;
  --surface-2:     #151c26;
  --surface-hover: #1a2330;
  --border:        #1f2937;
  --border-soft:   #161e29;
  --text:          #c7d2de;
  --text-dim:      #8493a5;
  --text-faint:    #5b6877;
  --accent:        #22d3ee;
  --accent-dim:    #0e7490;
  --accent-glow:   rgba(34, 211, 238, 0.16);
  --ok:            #34d399;
  --err:           #f87171;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --radius: 8px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px),
    radial-gradient(900px 500px at 80% -10%, var(--accent-glow), transparent 60%);
  background-size: 32px 32px, 32px 32px, 100% 100%;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Топбар ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 20px;
  background: rgba(10, 14, 20, 0.78);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text);
}
.brand::before {
  content: "";
  width: 11px; height: 11px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 10px 1px var(--accent-glow);
}
.brand small {
  color: var(--text-faint);
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 10px;
}
.logout {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  text-decoration: none;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: all 0.15s ease;
}
.logout:hover { color: var(--accent); border-color: var(--accent-dim); }

/* ---------- Навигация в топбаре ---------- */
.topnav { display: flex; gap: 4px; margin-right: auto; margin-left: 22px; }
.topnav a {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  text-decoration: none;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}
.topnav a:hover { color: var(--text); background: var(--surface-2); }
.topnav a.active { color: var(--accent); border-color: var(--accent-dim); background: var(--surface-2); }

/* ---------- Контейнер ---------- */
.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.page-head h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.muted { color: var(--text-dim); margin: 4px 0; font-size: 13px; }
.muted b { color: var(--text); font-variant-numeric: tabular-nums; }
.muted code {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* ---------- Тулбар ---------- */
.toolbar {
  position: sticky;
  top: 52px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 0;
  padding: 14px 0;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
}
#tree-filter {
  flex: 1;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 13px 9px 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235b6877' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#tree-filter::placeholder { color: var(--text-faint); }
#tree-filter:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 13px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.toggle-pill:hover { color: var(--text); border-color: var(--accent-dim); }
.toggle-pill:has(input:checked) { color: var(--accent); border-color: var(--accent-dim); background: var(--surface-2); }
.toggle-pill input { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; cursor: pointer; }

#save-btn {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #04181d;
  background: var(--accent);
  border: none;
  border-radius: 7px;
  padding: 9px 18px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.15s, background 0.15s;
}
#save-btn:hover:not(:disabled) { box-shadow: 0 0 16px var(--accent-glow); background: #38dcf0; }
#save-btn:active { transform: translateY(1px); }
#save-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#save-status, .save-status { font-family: var(--mono); font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.save-status--ok { color: var(--ok); }
.save-status--error { color: var(--err); }

/* ---------- Дерево ---------- */
#tree {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 6px;
  max-height: calc(100vh - 230px);
  overflow: auto;
}
#tree ul, .tree-root, .tree-children { list-style: none; margin: 0; padding: 0; }
.tree-children {
  margin-left: 19px;
  border-left: 1px solid var(--border-soft);
  padding-left: 4px;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: default;
  user-select: none;
}
.tree-row:hover { background: var(--surface-hover); }

.tree-toggle {
  flex: none;
  width: 18px; height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: var(--text-faint);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.12s, background 0.12s;
}
.tree-toggle:hover { color: var(--accent); background: var(--surface-2); }
.tree-toggle--leaf { cursor: default; pointer-events: none; }
.tree-toggle--leaf::before {
  content: "";
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--border);
}

.tree-cb {
  flex: none;
  width: 15px; height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}

.tree-label {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  cursor: pointer;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-count {
  flex: none;
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 1px 7px;
}

/* верхний уровень — крупнее и заметнее */
#tree > ul > .tree-node > .tree-row,
#tree > .tree-root > .tree-node > .tree-row { padding: 5px 8px; }
#tree > ul > .tree-node > .tree-row > .tree-label,
#tree > .tree-root > .tree-node > .tree-row > .tree-label { font-weight: 600; letter-spacing: -0.01em; }

/* фильтр */
.tree-node--hidden { display: none; }
.tree-node--match > .tree-row > .tree-label { color: var(--accent); }

.tree-loading, .tree-error {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-dim);
  padding: 24px;
  text-align: center;
}
.tree-error { color: var(--err); }

/* скроллбар */
#tree::-webkit-scrollbar { width: 10px; }
#tree::-webkit-scrollbar-track { background: transparent; }
#tree::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; border: 2px solid var(--surface); }
#tree::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

.empty {
  font-family: var(--mono);
  color: var(--text-dim);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  margin-top: 20px;
}

/* ---------- Логин ---------- */
.login-box {
  max-width: 360px;
  margin: 14vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
  box-shadow: 0 20px 60px -20px rgba(0,0,0,0.6), 0 0 0 1px var(--border-soft);
}
.login-box h1 {
  font-family: var(--mono);
  font-size: 19px;
  letter-spacing: 0.02em;
  margin: 0 0 22px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.login-box h1::before {
  content: "";
  width: 12px; height: 12px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 12px 2px var(--accent-glow);
}
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form input {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-form input:focus { border-color: var(--accent-dim); box-shadow: 0 0 0 3px var(--accent-glow); }
.login-form button {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 14px;
  color: #04181d;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 11px;
  cursor: pointer;
  transition: box-shadow 0.15s, background 0.15s;
}
.login-form button:hover { box-shadow: 0 0 16px var(--accent-glow); background: #38dcf0; }
.error { color: var(--err); font-size: 13px; margin: 4px 0 0; font-family: var(--mono); }

/* ---------- Статус краулера ---------- */
.crawl-status {
  margin-top: 12px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-faint);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: center;
}
.crawl-status.cs-active { border-left-color: var(--accent); box-shadow: 0 0 14px var(--accent-glow); }
.cs-live { color: var(--accent); font-weight: 600; }
.cs-idle { color: var(--text-faint); }
.cs-frontier, .cs-last { font-family: var(--mono); color: var(--text-dim); }
.cs-sep { color: var(--border); }

/* ---------- Метка парсинга у узла дерева ---------- */
.tree-listing { display: inline-flex; gap: 6px; align-items: center; margin-left: 8px; }
.ls-chip {
  font-size: 11px; padding: 1px 6px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-dim); background: var(--surface-2);
}
.ls-crawled  { color: var(--ok);     border-color: var(--ok); }
.ls-expanded { color: var(--accent); border-color: var(--accent-dim); }
.ls-capped   { color: var(--err);    border-color: var(--err); }
.ls-pending  { color: var(--text-faint); }
.ls-date { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }
.ls-expanded-icon { color: var(--accent); font-size: 13px; cursor: help; }
.ls-running { color: var(--accent); border-color: var(--accent); background: var(--accent-glow); }
/* Значок «идёт парсинг» — три бегущие друг за другом точки. На каждом узле
   активной ветки (текущий + предки), чтобы видеть, где сейчас сбор. */
.crawl-dots { display: inline-flex; gap: 3px; align-items: center; margin-left: 8px; vertical-align: middle; }
.crawl-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); display: inline-block; animation: crawl-dot 1.2s infinite ease-in-out; }
.crawl-dots i:nth-child(2) { animation-delay: 0.2s; }
.crawl-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes crawl-dot { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.7); } 40% { opacity: 1; transform: scale(1); } }

/* ---------- Длительность парсинга разделов ---------- */
.section-durations { margin-top: 8px; font-size: 13px; }
.section-durations > summary { cursor: pointer; color: var(--text-dim); user-select: none; }
.sd-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 4px 16px;
}
.sd-row { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; border-bottom: 1px solid var(--border-soft); }
.sd-row.sd-running { color: var(--accent); }
.sd-title { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sd-dur { font-family: var(--mono); color: var(--ok); }
.sd-running .sd-dur { color: var(--accent); }
.sd-when { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }

