/* ─────────────────────────────────────────────────────────────────────
   Lead Hunter CRM — дизайн-система
   Ориентир: нативные приложения iOS. Крупные заголовки, сгруппированные
   списки с волосяными разделителями, полупрозрачные панели, пружинная
   анимация. Тема: авто (из Telegram) / светлая / тёмная.
   ───────────────────────────────────────────────────────────────────── */

/* ── Токены ────────────────────────────────────────────────────────── */
:root {
  /* Светлая тема — база */
  --bg:            #f5f5f7;
  --bg-elevated:   #ffffff;
  --surface:       #ffffff;
  --surface-2:     #f5f5f7;
  --surface-press: #ebebef;

  --text:          #05050a;
  --text-2:        #5f5f6b;
  --text-3:        #9a9aa5;

  --hairline:      rgba(0, 0, 0, .08);
  --hairline-soft: rgba(0, 0, 0, .05);

  --accent:        #0a84ff;
  --accent-2:      #5e5ce6;
  --accent-soft:   rgba(10, 132, 255, .12);
  --accent-glow:   transparent;

  --green:  #34c759;
  --orange: #ff9f0a;
  --red:    #ff3b30;
  --purple: #af52de;
  --indigo: #5e5ce6;
  --teal:   #30b0c7;
  --gray:   #8e8e93;

  --panel-blur: saturate(180%) blur(20px);
  --panel-bg:   rgba(255, 255, 255, .72);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .05);
  --shadow-2: 0 8px 32px rgba(0, 0, 0, .10);

  /* Радиусы близки к «непрерывным» углам iOS */
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --r-pill: 999px;

  --pad: 16px;
  --tab-h: 56px;
  /* На широком экране (Telegram Desktop/Web) держим колонку телефонной ширины */
  --app-w: 460px;

  /* Пружина, как в переходах iOS */
  --spring: cubic-bezier(.32, .72, 0, 1);
  --fast: 180ms var(--spring);
}

:root[data-theme="dark"] {
  --bg:            #000005;
  --bg-elevated:   #0e0e13;
  --surface:       #14141b;
  --surface-2:     #1c1c25;
  --surface-press: #23232e;

  --text:          #f5f5f7;
  --text-2:        #9c9caa;
  --text-3:        #62626f;

  --hairline:      rgba(255, 255, 255, .09);
  --hairline-soft: rgba(255, 255, 255, .06);

  --accent:        #409cff;
  --accent-2:      #7d7aff;
  --accent-soft:   rgba(64, 156, 255, .16);
  --accent-glow:   rgba(64, 156, 255, .28);

  --green:  #32d74b;
  --orange: #ffb340;
  --red:    #ff453a;
  --purple: #bf5af2;
  --indigo: #7d7aff;
  --teal:   #40c8e0;
  --gray:   #8e8e93;

  --panel-bg: rgba(14, 14, 19, .74);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-2: 0 12px 40px rgba(0, 0, 0, .6);
}

/* ── База ──────────────────────────────────────────────────────────── */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 0 calc(var(--tab-h) + env(safe-area-inset-bottom) + 8px);
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
        Roboto, "Helvetica Neue", sans-serif;
  letter-spacing: -.01em;
  font-feature-settings: "tnum" 1, "cv06" 1;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  transition: background-color 280ms var(--spring), color 280ms var(--spring);
}

/* Едва заметное свечение сверху — «футуристичность» без шума */
body::before {
  content: "";
  position: fixed;
  inset: -40% 0 auto 0;
  height: 320px;
  background: radial-gradient(60% 100% at 50% 0%, var(--accent-glow), transparent 70%);
  pointer-events: none;
  opacity: .9;
  z-index: 0;
}

button, input, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }

/* ── Каркас экрана ─────────────────────────────────────────────────── */
.screen {
  position: relative;
  z-index: 1;
  max-width: var(--app-w);
  margin: 0 auto;
  padding: 8px var(--pad) 24px;
  animation: enter 420ms var(--spring);
}
@keyframes enter {
  from { opacity: 0; transform: translate3d(0, 10px, 0) scale(.99); }
  to   { opacity: 1; transform: none; }
}

.lg-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -.032em;
  line-height: 1.1;
  margin: 12px 0 2px;
}
.lg-sub { color: var(--text-2); font-size: 14px; margin-bottom: 18px; }

.sec-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 22px 4px 8px;
}

/* ── Сгруппированные списки в стиле iOS ────────────────────────────── */
.group {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: .5px solid var(--hairline-soft);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  margin-bottom: 14px;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  position: relative;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms ease;
}
.row:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 16px; right: 0; bottom: 0;
  height: .5px;
  background: var(--hairline);
}
.row.inset-sep:not(:last-child)::after { left: 60px; }
.row:active { background: var(--surface-press); }
.row.static { cursor: default; }
.row.static:active { background: none; }

.row .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
/* Не привязываем к .row: те же роли текста используются и вне списков */
.title { font-size: 16px; font-weight: 500; letter-spacing: -.015em; }
.sub   { font-size: 13px; line-height: 1.4; color: var(--text-2); }
.value { font-size: 15px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.chevron { flex: none; color: var(--text-3); opacity: .55; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Аватар ────────────────────────────────────────────────────────── */
.avatar {
  width: 40px; height: 40px; flex: none;
  border-radius: 13px;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 600; color: #fff;
  letter-spacing: -.02em;
  position: relative;
}
.avatar::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 .5px 0 rgba(255, 255, 255, .3);
}
.avatar.lg { width: 56px; height: 56px; border-radius: 18px; font-size: 19px; }

/* ── Плитки-показатели ─────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 6px; }
.tile {
  background: var(--surface);
  border: .5px solid var(--hairline-soft);
  border-radius: var(--r-md);
  padding: 14px 12px;
  box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; gap: 3px;
}
.tile b {
  font-size: 26px; font-weight: 700; letter-spacing: -.03em; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.tile span { font-size: 11px; color: var(--text-3); letter-spacing: .01em; }
.tile.accent b { color: var(--accent); }

/* ── Воронка ───────────────────────────────────────────────────────── */
.funnel { display: flex; flex-direction: column; gap: 8px; }
.stage {
  display: grid;
  grid-template-columns: 3px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 13px 16px 13px 13px;
  background: var(--surface);
  border: .5px solid var(--hairline-soft);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: transform var(--fast), background-color 120ms ease;
}
.stage:active { transform: scale(.985); background: var(--surface-press); }
.stage .mark { width: 3px; height: 26px; border-radius: 2px; background: currentColor; }
.stage .name { font-size: 15px; font-weight: 500; letter-spacing: -.015em; color: var(--text); }
.stage .meter {
  /* Без дорожки: видна только заполненная часть, иначе полоса
     читается как подчёркивание названия */
  grid-column: 2; height: 2px; margin-top: 8px;
}
.stage .meter i {
  display: block; height: 100%; border-radius: 1px;
  background: currentColor; opacity: .85;
  transform-origin: left;
  animation: grow 620ms var(--spring) both;
}
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.stage .count {
  font-size: 19px; font-weight: 600; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; color: var(--text);
}

/* ── Сегмент-контрол ───────────────────────────────────────────────── */
.segmented {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex: 1 0 auto;
  border: none;
  background: none;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--fast), color var(--fast), box-shadow var(--fast);
}
.segmented button.on {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-1);
}

/* ── Поиск ─────────────────────────────────────────────────────────── */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: .5px solid var(--hairline-soft);
  border-radius: var(--r-sm);
  padding: 0 12px;
  margin-bottom: 14px;
}
.search svg { color: var(--text-3); flex: none; }
.search input {
  flex: 1; border: none; background: none; outline: none;
  padding: 10px 0; font-size: 16px;
}
.search input::placeholder { color: var(--text-3); }

/* ── Бейджи ────────────────────────────────────────────────────────── */
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  font-size: 11px; font-weight: 600; letter-spacing: -.005em;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.green  { background: color-mix(in srgb, var(--green) 15%, transparent);  color: var(--green); }
.badge.orange { background: color-mix(in srgb, var(--orange) 17%, transparent); color: var(--orange); }
.badge.red    { background: color-mix(in srgb, var(--red) 15%, transparent);    color: var(--red); }
.badge.purple { background: color-mix(in srgb, var(--purple) 15%, transparent); color: var(--purple); }

/* ── Цитата запроса ────────────────────────────────────────────────── */
.quote {
  position: relative;
  padding: 10px 12px 10px 14px;
  margin: 10px 0;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.quote::before {
  content: "";
  position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 2.5px; border-radius: 2px;
  background: linear-gradient(var(--accent), var(--accent-2));
}

/* ── Кнопки ────────────────────────────────────────────────────────── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%;
  border: none;
  border-radius: var(--r-md);
  padding: 13px 16px;
  font-size: 16px; font-weight: 600; letter-spacing: -.015em;
  background: var(--accent); color: #fff;
  cursor: pointer;
  transition: transform var(--fast), opacity var(--fast);
}
.btn:active { transform: scale(.975); opacity: .85; }
.btn.ghost { background: var(--surface); color: var(--accent); border: .5px solid var(--hairline); box-shadow: var(--shadow-1); }
.btn.quiet { background: var(--surface-2); color: var(--text); }
.btn.danger { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.btn:disabled { opacity: .45; }
.btn-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }

/* ── Поля ──────────────────────────────────────────────────────────── */
.field { padding: 12px 16px; position: relative; }
.field:not(:last-child)::after {
  content: ""; position: absolute; left: 16px; right: 0; bottom: 0;
  height: .5px; background: var(--hairline);
}
.field label {
  display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-3); margin-bottom: 5px;
}
.field input, .field textarea {
  width: 100%; border: none; background: none; outline: none;
  font-size: 16px; resize: none; padding: 0;
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-3); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; }
.field-pair .field:first-child { border-right: .5px solid var(--hairline); }

/* ── Переписка ─────────────────────────────────────────────────────── */
.chat { display: flex; flex-direction: column; gap: 6px; padding-bottom: 64px; }
.bubble {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 19px;
  font-size: 15px;
  line-height: 1.38;
  white-space: pre-wrap;
  word-break: break-word;
  animation: pop 320ms var(--spring) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.97); } to { opacity: 1; transform: none; } }
.bubble .at { display: block; font-size: 10px; margin-top: 4px; opacity: .6; font-variant-numeric: tabular-nums; }
.bubble.user { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 6px; box-shadow: var(--shadow-1); }
.bubble.assistant { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.bubble.operator {
  align-self: flex-end; color: #fff; border-bottom-right-radius: 6px;
  background: linear-gradient(135deg, var(--indigo), var(--purple));
}

.composer {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom) / 3);
  padding-inline: max(12px, calc((100% - var(--app-w)) / 2 + 12px));
  background: var(--panel-bg);
  backdrop-filter: var(--panel-blur);
  -webkit-backdrop-filter: var(--panel-blur);
  border-top: .5px solid var(--hairline);
  z-index: 20;
}
.composer textarea {
  flex: 1; border: .5px solid var(--hairline); border-radius: 19px;
  padding: 9px 14px; background: var(--surface); outline: none;
  max-height: 96px; font-size: 16px;
}
.composer .send {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  border: none; background: var(--accent); color: #fff;
  display: grid; place-items: center; cursor: pointer;
  transition: transform var(--fast), opacity var(--fast);
}
.composer .send:active { transform: scale(.9); }
.composer .send:disabled { opacity: .4; }

/* ── Нижняя навигация ──────────────────────────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-inline: max(0px, calc((100% - var(--app-w)) / 2));
  background: var(--panel-bg);
  backdrop-filter: var(--panel-blur);
  -webkit-backdrop-filter: var(--panel-blur);
  border-top: .5px solid var(--hairline);
}
.tab {
  position: relative;
  border: none; background: none; cursor: pointer;
  color: var(--text-3);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10px; font-weight: 500; letter-spacing: -.005em;
  transition: color var(--fast);
}
.tab svg { transition: transform var(--fast); }
.tab.on { color: var(--accent); }
.tab.on svg { transform: translateY(-1px) scale(1.06); }
.tab:active svg { transform: scale(.9); }
.tab .dot {
  position: absolute; top: 6px; left: 50%; margin-left: 5px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--red); color: #fff;
  font-size: 10px; font-weight: 600; line-height: 16px; text-align: center;
}

/* ── Шапка: тема и статус ──────────────────────────────────────────── */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.icon-btn {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  border: .5px solid var(--hairline); background: var(--surface);
  color: var(--text-2); display: grid; place-items: center; cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: transform var(--fast), color var(--fast);
}
.icon-btn:active { transform: scale(.9); }
.icon-btn.on { color: var(--accent); }

.live { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-3); font-weight: 500; }
.live .led { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); transition: background var(--fast); }
.live.on { color: var(--green); }
.live.on .led { background: var(--green); animation: pulse 2.4s ease-out infinite; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 55%, transparent); }
  70%  { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ── Всплывающее уведомление ───────────────────────────────────────── */
.toast {
  position: fixed; left: 14px; right: 14px;
  max-width: calc(var(--app-w) - 28px); margin-inline: auto;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 60;
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--panel-bg);
  backdrop-filter: var(--panel-blur);
  -webkit-backdrop-filter: var(--panel-blur);
  border: .5px solid var(--hairline);
  box-shadow: var(--shadow-2);
  color: var(--text);
  font-size: 14px; font-weight: 500; text-align: center;
  opacity: 0; transform: translateY(12px) scale(.97);
  transition: opacity 260ms var(--spring), transform 260ms var(--spring);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

/* ── Пустые состояния и загрузка ───────────────────────────────────── */
.empty { text-align: center; padding: 56px 24px; color: var(--text-3); }
.empty svg { opacity: .35; margin-bottom: 14px; }
.empty .t { font-size: 16px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.empty .d { font-size: 14px; }

.skeleton {
  height: 68px; border-radius: var(--r-md); margin-bottom: 10px;
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 180% 0; } to { background-position: -40% 0; } }

/* ── Полоса конверсии ──────────────────────────────────────────────── */
.bars { display: flex; flex-direction: column; gap: 14px; padding: 16px; }
.bar-row .head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.bar-row .head span { font-size: 14px; color: var(--text-2); }
.bar-row .head b { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-track { height: 6px; border-radius: 3px; background: var(--hairline); overflow: hidden; }
.bar-track i {
  display: block; height: 100%; border-radius: 3px;
  transform-origin: left; animation: grow 700ms var(--spring) both;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
