/* Мобильная вёрстка портала. Десктоп — то же самое, ограниченное по ширине. */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e3e5e9;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 14px;
  --tap: 46px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1d2026;
    --text: #eceef2;
    --muted: #9aa3b2;
    --line: #2c313a;
    --accent: #4f86ff;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- каркас ---------- */
.app { max-width: 680px; margin: 0 auto; padding-bottom: calc(64px + var(--safe-b)); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-top, 0px));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 650; letter-spacing: -0.01em; }
.topbar .who { font-size: 12px; color: var(--muted); text-align: right; line-height: 1.25; }
.iconbtn {
  min-width: var(--tap); height: var(--tap); border: 1px solid var(--line);
  background: transparent; border-radius: 11px; padding: 0 12px; font-size: 14px;
}
.iconbtn:active { background: var(--bg); }

/* ---------- фильтры ---------- */
.filters { padding: 12px 14px 0; }
.filters-head { display: flex; gap: 8px; align-items: center; }
.search {
  flex: 1; height: var(--tap); padding: 0 14px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--card);
}
.filters-body { display: none; margin-top: 10px; }
.filters-body.open { display: block; }
.field { margin-bottom: 10px; }
.field > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field select, .field input, .field textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--card);
}
.field textarea { min-height: 110px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap);
  font-size: 14px; margin-bottom: 6px; }
.check input { width: 20px; height: 20px; }
.lead.lost { opacity: .62; }
.chip.won { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.chip.lost { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.relates { margin: 10px 14px; }
.relates .lead { margin-top: 8px; }

.badge-count { font-size: 12px; color: var(--muted); padding: 10px 14px 0; }

/* ---------- список лидов ---------- */
.list { padding: 10px 14px 20px; display: flex; flex-direction: column; gap: 10px; }
.lead {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px; text-align: left; width: 100%; display: block;
}
.lead:active { transform: scale(0.995); }
.lead-top { display: flex; gap: 10px; align-items: baseline; }
.lead-title { font-weight: 600; flex: 1; overflow-wrap: anywhere; }
.lead-id { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.lead-meta { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  font-size: 12px; padding: 4px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent); white-space: nowrap;
}
.chip.grey { background: color-mix(in srgb, var(--muted) 15%, transparent); color: var(--muted); }
.lead-date { font-size: 12px; color: var(--muted); margin-left: auto; white-space: nowrap; }

.more { width: 100%; min-height: var(--tap); border-radius: 11px; border: 1px solid var(--line);
  background: var(--card); margin-top: 4px; }
.empty, .error { padding: 28px 16px; text-align: center; color: var(--muted); }
.error { color: var(--danger); }
.skeleton { height: 84px; border-radius: var(--radius); background: var(--card); opacity: .55;
  animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- карточка лида ---------- */
.screen {
  position: fixed; inset: 0; z-index: 40; background: var(--bg);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  transform: translateX(100%); transition: transform .22s ease;
}
.screen.open { transform: translateX(0); }
.screen-inner { max-width: 680px; margin: 0 auto; padding-bottom: calc(96px + var(--safe-b)); }
.kv { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  margin: 12px 14px; overflow: hidden; }
.kv div { display: flex; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv div:last-child { border-bottom: 0; }
.kv dt, .kv .k { color: var(--muted); flex: 0 0 42%; font-size: 13px; }
.kv .v { flex: 1; overflow-wrap: anywhere; }
.section-title { padding: 16px 16px 4px; font-size: 13px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; }
.comment { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  margin: 8px 14px; padding: 11px 13px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment .meta { color: var(--muted); font-size: 12px; margin-top: 6px; }

.actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: flex; gap: 8px; padding: 10px 14px calc(10px + var(--safe-b));
  background: var(--card); border-top: 1px solid var(--line);
}
.actions > * { flex: 1; }
.btn {
  min-height: var(--tap); border-radius: 11px; border: 1px solid var(--line);
  background: var(--card); font-size: 14px; font-weight: 550; padding: 0 10px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn:disabled { opacity: .5; }

/* ---------- шторка ---------- */
.sheet-bg { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: none; }
.sheet-bg.open { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-width: 680px; margin: 0 auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(16px + var(--safe-b));
  max-height: 88vh; overflow-y: auto;
  transform: translateY(100%); transition: transform .22s ease;
}
.sheet.open { transform: translateY(0); }
.grabber { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 12px; }
.sheet h2 { font-size: 16px; margin: 0 0 12px; }
.opt {
  width: 100%; min-height: var(--tap); text-align: left; padding: 12px 14px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 11px; background: transparent;
}
.opt.current { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ---------- нижние вкладки ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs button {
  flex: 1; min-height: 56px; border: 0; background: transparent; color: var(--muted);
  font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.tabs button.active { color: var(--accent); }
.tabs .glyph { font-size: 19px; line-height: 1; }

/* ---------- уведомление ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(78px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  z-index: 60; background: var(--text); color: var(--bg); padding: 11px 17px; border-radius: 11px;
  font-size: 14px; opacity: 0; transition: all .2s ease; pointer-events: none; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); color: #fff; }

/* ---------- вход ---------- */
.login { min-height: 100dvh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 24px; text-align: center; gap: 8px; }
.login h1 { font-size: 22px; margin: 0; }
.login p { color: var(--muted); margin: 0 0 18px; max-width: 340px; }
.login .btn { width: 100%; max-width: 320px; min-height: 52px; font-size: 16px; }
.login .note { font-size: 13px; color: var(--muted); margin-top: 18px; max-width: 340px; }
.login .alert { color: var(--danger); font-size: 14px; margin-bottom: 10px; }
