:root {
  /* Чёрно-белая тема */
  --bg: #050505;
  --surface: rgba(16, 16, 16, .86);
  --surface-2: rgba(255, 255, 255, .05);
  --border: rgba(255, 255, 255, .10);
  --border-strong: rgba(255, 255, 255, .22);
  --text: #ededed;
  --muted: #9a9a9a;
  --accent: #f2f2f2;
  --accent-hover: #ffffff;
  --accent-soft: rgba(255, 255, 255, .10);
  --accent-text: #0a0a0a;
  --danger: #ffffff;
  --danger-soft: rgba(255, 255, 255, .14);
  --warn: #cfcfcf;
  --warn-soft: rgba(255, 255, 255, .08);
  --info: #e0e0e0;
  --info-soft: rgba(255, 255, 255, .10);
  --teal: #d6d6d6;
  --teal-soft: rgba(255, 255, 255, .12);
  --gray-soft: rgba(255, 255, 255, .07);
  --purple: #ffffff;
  --purple-soft: rgba(255, 255, 255, .20);
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 30px rgba(0,0,0,.45);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: #000 linear-gradient(rgba(0,0,0,.62), rgba(0,0,0,.78)) center / cover fixed; color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* ---------- Кнопки и поля ---------- */
button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; line-height: 1.3; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { background: var(--accent-hover); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
button.danger:hover { background: var(--danger-soft); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.small { padding: 4px 10px; font-size: 13px; }
button.big { padding: 14px 28px; font-size: 16px; border-radius: 12px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; border-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.field > span { font-weight: 500; }
label.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 12px; }

/* ---------- Каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; white-space: nowrap; position: relative; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .count { background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 10px; margin-left: 4px; }
.usermenu { display: flex; align-items: center; gap: 8px; }
.usermenu .who { text-align: right; line-height: 1.2; }
.usermenu .who small { color: var(--muted); display: block; font-size: 12px; }
main { max-width: 1280px; margin: 0 auto; padding: 22px 20px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }

/* ---------- Вход ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { justify-content: center; margin-bottom: 6px; font-size: 18px; }
.login-card .brand img { width: 36px; height: 36px; }
.login-card p { text-align: center; margin: 0 0 20px; }
.error-box { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 8px 12px; font-size: 13px; }

/* ---------- Плитки ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile.alert .value { color: var(--danger); }
.tile.good .value { color: var(--accent); }

/* ---------- Рабочее место ---------- */
.work { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
.empty-work { text-align: center; padding: 60px 20px; }
.empty-work p { margin: 8px 0 22px; }
.kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--muted); }
.phone-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 14px; }
.phone-big { font-size: 28px; font-weight: 700; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.call-btn { background: var(--accent); color: var(--accent-text); border: none; font-weight: 600; padding: 10px 18px; border-radius: 10px; }
.call-btn:hover { background: var(--accent-hover); text-decoration: none; }
.lead-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.fields .wide { grid-column: 1 / -1; }
.history { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.history ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.history li { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; }
.history .when { color: var(--muted); font-size: 12px; }
.history .note { grid-column: 2; white-space: pre-wrap; }

.status-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.status-btn { justify-content: space-between; padding: 10px 12px; border-radius: 9px; font-weight: 500; }
.status-btn.on { border-color: currentColor; box-shadow: inset 0 0 0 1px currentColor; }
.status-btn.c-amber.on { background: var(--warn-soft); color: var(--warn); }
.status-btn.c-blue.on { background: var(--info-soft); color: var(--info); }
.status-btn.c-teal.on { background: var(--teal-soft); color: var(--teal); }
.status-btn.c-green.on { background: var(--accent-soft); color: var(--accent); }
.status-btn.c-red.on { background: var(--danger-soft); color: var(--danger); }
.status-btn.c-purple.on { background: var(--purple-soft); color: var(--purple); }
.status-btn.c-gray.on { background: var(--gray-soft); color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 20px; }
.sticky-side { position: sticky; top: 72px; }

/* ---------- Бейджи ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-slate { background: var(--gray-soft); color: var(--text); }
.b-amber { background: var(--warn-soft); color: var(--warn); }
.b-blue { background: var(--info-soft); color: var(--info); }
.b-teal { background: var(--teal-soft); color: var(--teal); }
.b-green { background: var(--accent-soft); color: var(--accent); }
.b-red { background: var(--danger-soft); color: var(--danger); }
.b-purple { background: var(--purple-soft); color: var(--purple); }
.b-gray { background: var(--gray-soft); color: var(--muted); }
.overdue { color: var(--danger); font-weight: 600; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { display: block; color: var(--muted); font-size: 12px; }
.filters { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--accent-soft); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; }
.bulkbar select { width: auto; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* ---------- Базы и секции ---------- */
.progress { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; margin: 10px 0 6px; }
.progress span { display: block; height: 100%; background: var(--accent); }
.sections { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin: 16px 0; }
.section-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px; }
.section-card .sec-num { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.section-card.empty-sec { opacity: .55; }

/* ---------- Импорт ---------- */
.dropzone { display: block; border: 2px dashed var(--border-strong); border-radius: 12px; padding: 40px 20px; text-align: center; cursor: pointer; transition: .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { display: block; font-size: 16px; margin-bottom: 4px; }
.map-table select { min-width: 140px; }
.map-table td { font-size: 13px; }
.result-ok { background: var(--accent-soft); border-radius: var(--radius); padding: 16px; }

/* ---------- Статистика ---------- */
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 70px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 14px; background: var(--surface-2); border-radius: 4px; overflow: hidden; display: flex; }
.bar-fill { height: 100%; background: var(--accent); opacity: .35; }
.bar-fill.strong { opacity: 1; }
.conv { display: inline-flex; align-items: center; gap: 8px; }
.conv .mini { width: 60px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.conv .mini span { display: block; height: 100%; background: var(--accent); }
.periods { display: flex; gap: 4px; flex-wrap: wrap; }
.periods button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }

/* ---------- Модалки и уведомления ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 14, 8, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.25); width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; padding: 22px; }
.modal h2 { font-size: 17px; margin-bottom: 16px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); border-radius: 10px; padding: 11px 14px; box-shadow: var(--shadow); font-size: 13px; animation: pop .18s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
.toast.remind { background: var(--info); color: #fff; cursor: pointer; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Адаптив ---------- */
@media (max-width: 960px) {
  .work, .two-col { grid-template-columns: 1fr; }
  .sticky-side { position: static; }
  .filters { grid-template-columns: 1fr 1fr; }
  .usermenu .who { display: none; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .brand span { display: none; }
  main { padding: 16px 16px 60px; }
  .fields, .status-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  .phone-big { font-size: 22px; }
}

#rqOps, #opPick { padding-left: 26px; gap: 8px; }


/* ---------- ЧБ тема: фон и детали ---------- */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: url("/bg.jpg") center / cover no-repeat; filter: grayscale(1); }
body::after { content: ""; position: fixed; inset: 0; z-index: -1; background: radial-gradient(ellipse at 50% 40%, rgba(0,0,0,.55), rgba(0,0,0,.85)); }
.topbar { background: rgba(8, 8, 8, .88); backdrop-filter: blur(10px); }
.card, .tile, .table-wrap, .section-card, .modal { backdrop-filter: blur(8px); }
.modal { background: #111; }
th { background: rgba(255,255,255,.04); }
input, select, textarea { background: rgba(0,0,0,.55); }
select option { background: #111; color: #eee; }
button, .btn { background: rgba(255,255,255,.04); }
button.primary { background: #f2f2f2; border-color: #f2f2f2; color: #0a0a0a; }
button.primary:hover { background: #fff; }
.call-btn { background: #f2f2f2; color: #0a0a0a; }
.call-btn:hover { background: #fff; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.nav .count { background: #fff; color: #000; }
.toast { background: #f2f2f2; color: #0a0a0a; }
.toast.error { background: #fff; color: #000; border-left: 4px solid #000; font-weight: 600; }
.toast.remind { background: #111; color: #fff; border: 1px solid #fff; }
.overdue { color: #fff; font-weight: 700; text-decoration: underline; text-decoration-thickness: 2px; }
.tile.alert .value { color: #fff; text-decoration: underline; }
.tile.good .value { color: #fff; }
.error-box { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.3); }
.bulkbar { background: rgba(255,255,255,.08); }
.result-ok { background: rgba(255,255,255,.08); }
.login-card { background: rgba(12,12,12,.88); }
.brand img { filter: grayscale(1) brightness(1.6); }

/* статусы: оттенки серого, «Успех» — белый, «Отказ» — чёрный с рамкой */
.b-slate { background: rgba(255,255,255,.10); color: #e6e6e6; }
.b-amber { background: rgba(255,255,255,.06); color: #b5b5b5; border: 1px dashed rgba(255,255,255,.35); }
.b-blue  { background: transparent; color: #f0f0f0; border: 1px solid rgba(255,255,255,.7); }
.b-teal  { background: rgba(255,255,255,.22); color: #fff; }
.b-purple{ background: rgba(255,255,255,.35); color: #fff; }
.b-green { background: #f2f2f2; color: #000; }
.b-red   { background: #000; color: #d0d0d0; border: 1px solid rgba(255,255,255,.45); }
.b-gray  { background: rgba(255,255,255,.04); color: #777; text-decoration: line-through; }
.status-btn.on { background: #f2f2f2 !important; color: #0a0a0a !important; border-color: #f2f2f2; box-shadow: none; }
.bar-fill { background: #fff; }
.conv .mini span, .progress span { background: #f2f2f2; }
