/* ===== tokens ===== */
:root {
  --bg:          #0c1017;
  --surface:     #151c2a;
  --surface-2:   #1b2333;
  --surface-3:   #232d42;
  --border:      #2e3a52;
  --border-soft: #253046;
  --text:        #f2f6fd;
  --text-2:      #becada;
  --text-3:      #93a1b8;
  --accent:      #3ddc97;
  --accent-ink:  #06301f;
  --hot:         #ff8464;
  --warn:        #f5b544;
  --info:        #5b9dff;
  --violet:      #a78bfa;
  --danger:      #f2555a;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px;
  --sidebar-w: 236px;
  --shadow: 0 12px 40px rgba(0,0,0,.45);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любой display в этом файле.
   Без !important правило .modal-scrim{display:grid} перебивает [hidden]
   и оверлей висит поверх страницы, блокируя клики. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ===== auth ===== */
.auth-body { display: grid; place-items: center; min-height: 100dvh;
  background: radial-gradient(900px 500px at 50% -10%, #16203300, #0a0d13 70%), var(--bg); padding: var(--s-4); }
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl);
  padding: var(--s-6) var(--s-5) var(--s-5); box-shadow: var(--shadow); }
.auth-logo { color: var(--accent); display: flex; justify-content: center; margin-bottom: var(--s-3); }
.auth-title { margin: 0; font-size: 24px; font-weight: 650; letter-spacing: -.02em; text-align: center; }
.auth-sub { margin: var(--s-1) 0 var(--s-5); color: var(--text-3); font-size: 14px; text-align: center; }

/* ===== primitives ===== */
.field { margin-bottom: var(--s-4); }
.label { display: block; font-size: 13px; font-weight: 550; color: var(--text-2); margin-bottom: 6px; }
.hint { font-size: 12.5px; color: var(--text-3); margin-top: 5px; line-height: 1.45; }
.input, .select, .textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 11px 13px; color: var(--text);
  transition: border-color .16s ease, background .16s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: #2e3b55; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); background: var(--surface-3); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.select { appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%236f7d95' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 12px; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 40px; padding: 0 15px; border-radius: var(--r-sm); border: 1px solid transparent;
  background: var(--surface-3); color: var(--text); font-weight: 550; font-size: 14px;
  transition: background .16s ease, border-color .16s ease, opacity .16s ease; white-space: nowrap; }
.btn:hover { background: #253150; }
.btn:active { transform: translateY(.5px); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #55e8a9; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; border-color: #4a2530; color: #ff8a8e; }
.btn-danger:hover { background: #2a151a; }
.btn-sm { min-height: 34px; padding: 0 11px; font-size: 13px; }
.btn-icon { width: 40px; padding: 0; }
.btn-block { width: 100%; }
.btn-wa { background: #1f9d5b; color: #fff; }
.btn-wa:hover { background: #24b168; }

.alert { padding: 11px 13px; border-radius: var(--r-sm); font-size: 13.5px; margin-bottom: var(--s-4); }
.alert-error { background: #2a151a; border: 1px solid #4a2530; color: #ff9a9d; }
.alert-warn { background: #2a2313; border: 1px solid #4a3f1e; color: #f5cf7f; }
.alert-info { background: #142033; border: 1px solid #22375c; color: #9dc2ff; }

.chip { display: inline-flex; align-items: center; gap: 5px; height: 23px; padding: 0 9px;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.chip-new    { background: rgba(91,157,255,.14);  color: #8fbaff; }
.chip-sent   { background: rgba(245,181,68,.14);  color: #f3c674; }
.chip-replied{ background: rgba(167,139,250,.16); color: #c1acff; }
.chip-call   { background: rgba(61,220,151,.13);  color: #6fe7b4; }
.chip-deal   { background: var(--accent); color: var(--accent-ink); }
.chip-skip   { background: #1c2334; color: var(--text-3); }
.chip-kz     { background: rgba(61,220,151,.1);  color: #6fe7b4; }
.chip-il     { background: rgba(91,157,255,.12); color: #8fbaff; }
.chip-ru, .chip-us { background: #1c2334; color: var(--text-2); }

.score { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--surface-3); color: var(--text-3); flex: 0 0 30px; }
.score.s-hi  { background: rgba(255,107,74,.16); color: #ff9878; }
.score.s-mid { background: rgba(245,181,68,.14); color: #f3c674; }
.score.s-lo  { background: #1c2334; color: var(--text-3); }

/* ===== shell ===== */
.shell { display: flex; min-height: 100dvh; }
.sidebar { width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: var(--surface);
  border-right: 1px solid var(--border-soft); display: flex; flex-direction: column;
  padding: var(--s-4) var(--s-3); position: sticky; top: 0; height: 100dvh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px var(--s-5); }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: rgba(61,220,151,.12); color: var(--accent); }
.brand-name { font-weight: 650; letter-spacing: -.015em; font-size: 15.5px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 42px;
  padding: 0 11px; border: 0; border-radius: 10px; background: transparent; color: var(--text-2);
  font-size: 14.5px; font-weight: 500; text-align: left; transition: background .15s, color .15s; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--surface-3); color: var(--text); font-weight: 600; }
.nav-item.is-active svg { color: var(--accent); }
.nav-badge { margin-left: auto; font-style: normal; font-size: 11.5px; font-weight: 700;
  min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center;
  border-radius: 999px; background: var(--hot); color: #2a0a02; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--s-2); padding-top: var(--s-4); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; background: var(--surface-2); }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; }
.user-name { font-size: 13.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); padding: var(--s-3) var(--s-5); background: rgba(12,16,23,.9);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--border-soft); min-height: 62px; }
.page-title { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -.02em; }
.topbar-right { display: flex; align-items: center; gap: var(--s-2); }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2);
  border: 1px solid var(--border-soft); border-radius: 10px; }
.seg-btn { min-height: 30px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent;
  color: var(--text-3); font-size: 13px; font-weight: 600; transition: background .15s, color .15s; }
.seg-btn:hover { color: var(--text-2); }
.seg-btn.is-active { background: var(--surface-3); color: var(--text); }
.content { padding: var(--s-5); flex: 1; }

/* ===== layout bits ===== */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: var(--s-3); margin-bottom: var(--s-5); }
.kpi { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--r-md); padding: var(--s-4); }
.kpi-label { font-size: 12.5px; color: var(--text-2); font-weight: 550; margin-bottom: 7px; }
.kpi-value { font-size: 27px; font-weight: 680; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-value.accent { color: var(--accent); }
.kpi-value.hot { color: var(--hot); }
.kpi-sub { font-size: 12px; color: var(--text-3); margin-top: 5px; }

.grid2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: var(--s-4); margin-bottom: var(--s-4); }
.card { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--r-md); padding: var(--s-4) var(--s-5) var(--s-5); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.card-title { margin: 0; font-size: 14.5px; font-weight: 620; letter-spacing: -.01em; }
.card-note { font-size: 12.5px; color: var(--text-3); }
.kpi-sub { color: var(--text-3); }

.funnel { display: flex; flex-direction: column; gap: 11px; }
.frow { display: grid; grid-template-columns: 118px 1fr 44px; align-items: center; gap: var(--s-3); }
.fname { font-size: 13.5px; color: var(--text); }
.ftrack { height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.fbar { display: block; height: 100%; border-radius: 999px; transition: width .5s cubic-bezier(.4,0,.2,1); }
.fval { font-size: 13.5px; font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; }

.legend { display: flex; flex-direction: column; gap: 9px; }
.lrow { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.ldot { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 9px; }
.lname { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lval { margin-left: auto; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ===== table ===== */
.toolbar { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; margin-bottom: var(--s-4); }
.search { position: relative; flex: 1; min-width: 200px; max-width: 340px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 36px; }

.tablewrap { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--r-md); overflow: hidden; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-3); padding: 11px var(--s-4); border-bottom: 1px solid var(--border-soft); background: var(--surface-2); white-space: nowrap; }
.tbl td { padding: 12px var(--s-4); border-bottom: 1px solid var(--border-soft); font-size: 14px; vertical-align: middle; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: var(--surface-2); cursor: pointer; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.cell-need { max-width: 400px; }
.cell-need b { display: block; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-need small { display: block; color: var(--text-3); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.cell-src { color: var(--text-2); font-size: 13px; white-space: nowrap; }
.cell-date { color: var(--text-3); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: var(--s-7) var(--s-4); color: var(--text-3); }
.empty svg { color: var(--surface-3); margin-bottom: var(--s-3); }
.empty h3 { margin: 0 0 6px; font-size: 16px; color: var(--text-2); font-weight: 600; }
.empty p { margin: 0 auto; max-width: 400px; font-size: 13.5px; line-height: 1.55; }

/* ===== items ===== */
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s-3); }
.item { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--r-md); padding: var(--s-4); }
.item-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-2); margin-bottom: 9px; }
.item-name { font-weight: 600; font-size: 14.5px; }
.item-meta { font-size: 12.5px; color: var(--text-3); line-height: 1.55; }
.item-actions { display: flex; gap: 6px; margin-top: var(--s-3); }
.item.is-off { opacity: .5; }

/* ===== drawer ===== */
.drawer-scrim { position: fixed; inset: 0; background: rgba(4,6,10,.62); z-index: 60; animation: fade .2s ease; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 61;
  background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto;
  animation: slidein .24s cubic-bezier(.32,.72,0,1); }
@keyframes slidein { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.dr-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); padding: var(--s-4) var(--s-5); background: var(--surface); border-bottom: 1px solid var(--border-soft); }
.dr-body { padding: var(--s-5); display: flex; flex-direction: column; gap: var(--s-5); }
.dr-sec-title { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); margin: 0 0 9px; }
.raw { background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--r-sm);
  padding: 13px; font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
  max-height: 240px; overflow-y: auto; color: var(--text-2); }
.kv { display: grid; grid-template-columns: 116px 1fr; gap: 9px var(--s-3); font-size: 13.5px; margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; color: var(--text); word-break: break-word; }
.dr-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.timeline { display: flex; flex-direction: column; gap: 11px; }
.tl { display: grid; grid-template-columns: 8px 1fr; gap: var(--s-3); font-size: 13px; }
.tl-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-3); margin-top: 6px; }
.tl-body b { font-weight: 600; }
.tl-body span { color: var(--text-3); font-size: 12px; display: block; margin-top: 1px; }

/* ===== modal ===== */
.modal-scrim { position: fixed; inset: 0; background: rgba(4,6,10,.66); z-index: 70;
  display: grid; place-items: center; padding: var(--s-4); animation: fade .18s ease; overflow-y: auto; }
.modal { width: 100%; max-width: 520px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow); animation: pop .2s cubic-bezier(.32,.72,0,1); }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--border-soft); }
.modal-title { margin: 0; font-size: 16px; font-weight: 630; }
.modal-body { padding: var(--s-5); max-height: 68vh; overflow-y: auto; }
.modal-foot { display: flex; gap: var(--s-2); justify-content: flex-end; padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--border-soft); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.check { display: flex; align-items: center; gap: 9px; cursor: pointer; min-height: 24px; }

/* ===== toasts ===== */
.toasts { position: fixed; right: var(--s-4); bottom: var(--s-4); z-index: 90;
  display: flex; flex-direction: column; gap: var(--s-2); max-width: 340px; }
.toast { display: flex; align-items: flex-start; gap: 9px; padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--surface-3); border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 13.5px; animation: pop .2s ease; }
.toast.ok { border-color: #1f5c42; }
.toast.ok svg { color: var(--accent); flex: 0 0 17px; }
.toast.err { border-color: #4a2530; }
.toast.err svg { color: var(--danger); flex: 0 0 17px; }

.mobilenav { display: none; }

@media (max-width: 1080px) { .grid2 { grid-template-columns: 1fr; } }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { padding: var(--s-4) var(--s-3) 92px; }
  .topbar { padding: var(--s-3) var(--s-3); }
  .hide-sm { display: none; }
  .page-title { font-size: 17px; }
  .mobilenav { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0;
    z-index: 50; background: rgba(17,22,33,.95); backdrop-filter: blur(14px);
    border-top: 1px solid var(--border-soft); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .mnav-item { display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 50px;
    justify-content: center; border: 0; background: transparent; color: var(--text-3); font-size: 10.5px; font-weight: 550;
    border-radius: 10px; }
  .mnav-item.is-active { color: var(--accent); }
  .kpi-value { font-size: 23px; }
  .tbl th:nth-child(3), .tbl td:nth-child(3),
  .tbl th:nth-child(6), .tbl td:nth-child(6) { display: none; }
  .kv { grid-template-columns: 100px 1fr; }
  .row2 { grid-template-columns: 1fr; }
  .toasts { left: var(--s-3); right: var(--s-3); bottom: 78px; max-width: none; }
  .frow { grid-template-columns: 92px 1fr 38px; }
}

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