:root {
  --bg: #0e1116;
  --bg2: #12161d;
  --card: #171c25;
  --card2: #1e2531;
  --line: #2a3342;
  --text: #e8edf4;
  --muted: #93a0b1;
  --accent: #4a9eff;
  --accent2: #2f7fe0;
  --green: #37b26c;
  --amber: #d99a2b;
  --red: #d9534f;
  --radius: 14px;
  --nav: 62px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 calc(var(--nav) + env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 10px;
  background: linear-gradient(var(--bg) 70%, rgba(14, 17, 22, 0));
}

.brand { font-weight: 700; font-size: 19px; letter-spacing: .2px; }
.brand span { color: var(--accent); }
.who { color: var(--muted); font-size: 12px; text-align: right; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { flex: 1; padding: 0 12px; }
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.denied { padding: 40px 16px; }
.denied-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.denied-card h2 { margin: 0 0 8px; font-size: 18px; }
.denied-card p { color: var(--muted); margin: 8px 0; }
.muted { color: var(--muted); }

.filters {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 52px;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.input {
  width: 100%;
  min-width: 0;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
.input:focus { border-color: var(--accent2); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.row.between { align-items: center; justify-content: space-between; gap: 10px; }
.row.between > * { flex: none; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
}
.chip.on { background: rgba(74, 158, 255, .16); border-color: var(--accent2); color: var(--accent); }

.switch { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; white-space: nowrap; cursor: pointer; }
.switch input { accent-color: var(--accent2); width: 16px; height: 16px; }

.hint { color: var(--muted); font-size: 12.5px; padding: 10px 4px 6px; }

.list { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }

.lead {
  display: flex;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
  transition: border-color .15s;
}
.lead:active { border-color: var(--accent2); }
.lead-photo {
  width: 62px;
  height: 62px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg2);
  flex: none;
}
.lead-photo.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; text-align: center; }
.lead-main { min-width: 0; flex: 1; }
.lead-title { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.lead-meta { display: flex; gap: 8px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.lead-phone { color: var(--text); font-variant-numeric: tabular-nums; }
.lead-phone.none { color: var(--amber); }

.tag { font-size: 11px; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tag.hot { color: #f0a5a3; border-color: rgba(217, 83, 79, .5); background: rgba(217, 83, 79, .12); }
.tag.warm { color: #f0cc8a; border-color: rgba(217, 154, 43, .5); background: rgba(217, 154, 43, .12); }
.tag.cold { color: #9fc6f5; border-color: rgba(74, 158, 255, .4); background: rgba(74, 158, 255, .1); }

.more {
  width: 100%;
  margin: 12px 0 4px;
  background: var(--card2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  cursor: pointer;
}

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  gap: 2px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: rgba(14, 17, 22, .92);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.tabs button {
  flex: 1;
  max-width: 160px;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 10px;
  padding: 9px 4px;
  font-size: 12.5px;
  cursor: pointer;
}
.tabs button.on { color: var(--accent); background: rgba(74, 158, 255, .1); }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet-card {
  width: 100%;
  max-width: 720px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg2);
  border-radius: 18px 18px 0 0;
  padding: 12px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease;
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-close { display: block; margin: 0 0 8px auto; background: transparent; color: var(--muted); border: 0; font-size: 13px; cursor: pointer; }

.detail-photo { width: 100%; height: 170px; object-fit: cover; border-radius: 12px; background: var(--bg); margin-bottom: 10px; }
.detail h2 { margin: 4px 0 2px; font-size: 19px; }
.detail .sub { color: var(--muted); font-size: 13px; }
.detail .facts { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; font-size: 14px; }
.detail .facts b { color: var(--muted); font-weight: 500; display: inline-block; min-width: 96px; }
.detail a { color: var(--accent); text-decoration: none; }

.outcomes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.outcomes button {
  background: var(--card2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px 8px;
  font-size: 13px;
  cursor: pointer;
}
.outcomes button.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.outcomes button.wide { grid-column: 1 / -1; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 12px; }

.block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.block h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.mini { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.mini:last-child { border-bottom: 0; }

.user-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }
.user-row .nm { font-size: 14px; }
.user-row .role { color: var(--muted); font-size: 12px; }
.user-row button { background: var(--card2); border: 1px solid var(--line); color: var(--text); border-radius: 9px; padding: 7px 10px; font-size: 12.5px; cursor: pointer; }

.assign-form { display: flex; flex-direction: column; gap: 8px; }
.assign-form .row { flex-wrap: nowrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav) + 18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  background: #26303f;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  max-width: 86vw;
  text-align: center;
}
.toast[hidden] { display: none; }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; font-size: 14px; }

@media (min-width: 520px) {
  .lead-photo { width: 72px; height: 72px; }
}
