/* Экран аналитики бота v4 — стили. Один файл, без внешних зависимостей. */
:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7785;
  --line: #e3e8ef;
  --accent: #3b6ef6;
  --tm: #3b6ef6;
  --op: #e8710a;
  --good: #1f9d55;
  --bad: #d64545;
  --warn: #b8860b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20,30,50,.06), 0 4px 16px rgba(20,30,50,.05);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
.muted { color: var(--muted); }
.hidden { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Топбар ── */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 700; font-size: 17px; }
.logout { color: var(--muted); }

/* ── Фильтры ── */
.filters {
  display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: end;
  padding: 14px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.filters label.chk { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 14px; }
.filters select, .filters input[type=date] {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  font-size: 14px; color: var(--ink); min-width: 130px;
}
button {
  cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font-size: 14px;
}
button.primary, button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
button:hover { filter: brightness(.98); }
/* «Применить» — зелёная, чтобы не сливаться с синими вкладками */
#f-apply { background: var(--good); border-color: var(--good); color: #fff; }
#f-apply:hover { filter: brightness(.95); }
.loading { align-self: center; color: var(--accent); font-size: 13px; }

/* ── Вкладки ── */
.tabs { display: flex; gap: 8px; padding: 14px 20px 0; }
.tabs button { border-radius: 8px 8px 0 0; }

/* ── Основная область ── */
main { padding: 18px 20px 40px; }
.section-title { font-size: 15px; font-weight: 700; margin: 26px 0 12px; }
.section-title:first-child { margin-top: 6px; }
.foot { padding: 16px 20px; font-size: 12px; border-top: 1px solid var(--line); }

/* ── Центрирование: весь контент выровнен по колонке макс. 1200px по центру экрana ── */
.topbar, .filters, .tabs, .click-hint, main, .foot {
  padding-inline: max(20px, calc((100% - 1200px) / 2));
}
.click-hint { max-width: none; margin-inline: 0; border-radius: 0; border-left: 0; border-right: 0; }

/* ── Плитки ── */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); cursor: pointer; transition: transform .05s;
}
.tile:hover { transform: translateY(-1px); border-color: #cdd7e5; }
.tile.na { cursor: default; opacity: .55; }
.tile .label { font-size: 13px; color: var(--muted); }
.tile .value { font-size: 30px; font-weight: 700; margin-top: 6px; }
.tile .delta { font-size: 13px; margin-top: 4px; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); } .delta.flat { color: var(--muted); }

/* ── Конверсии (Сводка) ── */
.conv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.conv { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; transition: border-color .1s, background .1s; }
.conv:hover { border-color: var(--accent); background: #f7f9fc; }
.conv-label { font-size: 13px; color: var(--muted); display: flex; align-items: center; }
.conv-pct { font-size: 34px; font-weight: 800; margin: 4px 0 2px; }
.conv-sub { font-size: 12px; color: var(--muted); }

/* ── Карточки-графики ── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* ── Значок «?» с подсказкой «как считается» ── */
.info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  background: #dfe6f0; color: #5a6b80; font-size: 11px; font-weight: 700;
  margin-left: 6px; cursor: help; position: relative; vertical-align: middle;
}
.info:hover { background: var(--accent); color: #fff; }
.info::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: #1c2430; color: #fff; padding: 9px 12px; border-radius: 8px;
  font-size: 12.5px; font-weight: 400; line-height: 1.45; text-align: left;
  width: max-content; max-width: 300px; white-space: normal; z-index: 30;
  opacity: 0; pointer-events: none; transition: opacity .12s;
  box-shadow: 0 6px 20px rgba(20,30,50,.28);
}
.info::before {  /* хвостик-треугольник */
  content: ""; position: absolute; bottom: calc(100% + 2px); left: 50%;
  transform: translateX(-50%); border: 6px solid transparent; border-top-color: #1c2430;
  opacity: 0; transition: opacity .12s; z-index: 30;
}
.info:hover::after, .info:hover::before { opacity: 1; }

/* ── Крупный индикатор загрузки ── */
.loader {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 70px 20px; text-align: center;
}
.loader .spinner {
  width: 48px; height: 48px; border: 5px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%;
  animation: fox-spin 0.8s linear infinite;
}
.loader .txt { font-size: 19px; font-weight: 700; color: var(--ink); }
.loader .sub { font-size: 13px; color: var(--muted); }
@keyframes fox-spin { to { transform: rotate(360deg); } }

/* ── Всплывающая подсказка на графике ── */
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
  background: #1c2430; color: #fff; font-size: 12px; white-space: nowrap;
  padding: 5px 9px; border-radius: 7px; border-bottom: 2px solid var(--accent);
  box-shadow: 0 4px 14px rgba(20,30,50,.25);
}

/* ── Легенда графиков ── */
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }

/* ── Воронка ── */
.funnel-row { margin: 8px 0; cursor: pointer; }
.funnel-row:hover .funnel-bar { filter: brightness(.95); }
.funnel-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 3px; }
.funnel-head .cnt { font-weight: 700; }
.funnel-track { background: #eef2f8; border-radius: 6px; height: 26px; overflow: hidden; }
.funnel-bar { height: 100%; border-radius: 6px; display: flex; align-items: center; padding-left: 10px; color: #fff; font-size: 12px; }
.drop { color: var(--bad); font-size: 12px; }

/* ── Кликабельность: единый язык «синее и со стрелкой = можно нажать» ── */
.click { cursor: pointer; }

/* Подсказка-легенда под вкладками */
.click-hint {
  max-width: 1200px; margin: 10px 20px 0; padding: 8px 12px;
  background: #eef4ff; border: 1px solid #d6e2fb; border-radius: 8px;
  font-size: 12.5px; color: #33465e;
}
.click-hint b { color: var(--accent); }

/* Плитки: постоянная бледная стрелка → ярче при наведении */
.tile { position: relative; }
.tile:not(.na)::after {
  content: "→"; position: absolute; top: 14px; right: 15px;
  color: var(--accent); opacity: .35; font-size: 16px;
  transition: opacity .12s, transform .12s;
}
.tile:not(.na):hover::after { opacity: 1; transform: translateX(3px); }
.tile:not(.na):hover { border-color: var(--accent); }

/* Кликабельные числа в плитках-показателях (kv) — акцентный цвет + фон при наведении */
.kv > .click { border-radius: 8px; padding: 4px 8px; margin: -4px -8px; transition: background .12s; }
.kv > .click:hover { background: #eef2f8; }
.kv > .click .n { color: var(--accent); }
.kv > .click .n::after { content: " →"; font-size: .55em; vertical-align: middle; opacity: .6; }

/* Кликабельная крупная метрика (например, доля other_objection) */
.big-metric.clickable:hover { text-decoration: underline; }
.big-metric.clickable::after { content: " →"; font-size: .5em; vertical-align: middle; opacity: .55; }

/* Строки воронки: счётчик синеет и получает стрелку при наведении */
.funnel-row:hover .funnel-head .cnt { color: var(--accent); }
.funnel-row:hover .funnel-head .cnt::after { content: "  →"; }

/* ── Поиск по номеру сделки (вкладка «Сделки») ── */
.deals-searchbar { margin: 4px 0 14px; }
.deals-search {
  width: 320px; max-width: 100%; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px; color: var(--ink);
}
.deals-search:focus { outline: none; border-color: var(--accent); }

/* ── Таблицы ── */
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr.click { cursor: pointer; transition: background .1s; }
tr.click:hover { background: #eef4ff; }
tr.click:hover td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tr.click:hover td:first-child { color: var(--accent); font-weight: 600; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; background: #eef2f8; color: var(--muted); }
.pill.tm { background: #e7edfe; color: var(--tm); } .pill.op { background: #fdece0; color: var(--op); }
.pill.on { background: #e5f5ec; color: var(--good); } .pill.off { background: #fbe9e9; color: var(--bad); }

/* ── Метрика-выделение (доля other_objection) ── */
.big-metric { font-size: 40px; font-weight: 800; }
.big-metric.alert { color: var(--bad); }
.kv { display: flex; gap: 26px; flex-wrap: wrap; }
.kv > div { }
.kv .n { font-size: 24px; font-weight: 700; } .kv .k { font-size: 12px; color: var(--muted); }

/* ── Список / карточка ── */
.crumbs { font-size: 13px; margin-bottom: 12px; }
.chat { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 12px; font-size: 14px; white-space: pre-wrap; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.msg.client { align-self: flex-start; background: #eef2f8; border-bottom-left-radius: 3px; }
.msg.bot { align-self: flex-end; background: #e7edfe; border-bottom-right-radius: 3px; }
.msg.system { align-self: center; background: #fff6e0; color: var(--warn); max-width: 88%; font-size: 12px; text-align: center; }
.slots { display: flex; gap: 16px; flex-wrap: wrap; }
.slots div { background: #f4f6fa; border-radius: 8px; padding: 6px 12px; font-size: 13px; }

/* ── Вход ── */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px; width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { font-size: 19px; margin: 0; }
.login-card input { padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; }
.login-card button { background: var(--accent); color: #fff; border-color: var(--accent); padding: 10px; }
.login-error { background: #fbe9e9; color: var(--bad); padding: 8px 10px; border-radius: 8px; font-size: 13px; }
