/* RYX — единая дизайн-система панели.
 *
 * Один файл на все страницы. Раньше палитра была скопирована семь раз, и
 * одни и те же имена переменных значили на разных страницах разное; здесь
 * источник один. Правило простое: цвет берётся только из токена, ни один
 * цвет не объявляется внутри @media или [data-theme] — иначе он не
 * применится в состоянии «как в системе».
 *
 * Светлая палитра — в голом :root. Тёмная переопределяет ТОЛЬКО токены,
 * дважды: под prefers-color-scheme (для «как в системе») и под
 * [data-theme="dark"] (для ручного переключателя).
 */

:root {
  --ground: #EDF0F5;
  --surface: #FFFFFF;
  --surface-2: #F5F7FA;
  --surface-3: #EAEEF3;
  --ink: #0F1720;
  --ink-2: #46525F;
  --muted: #6C7A8A;
  --line: #D9E0E8;
  --line-soft: #E8EDF2;
  --accent: #2657D6;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(38, 87, 214, .10);
  --good: #0F7C52;
  --good-soft: rgba(15, 124, 82, .12);
  --warn: #A96A00;
  --warn-soft: rgba(169, 106, 0, .14);
  --bad: #B8392C;
  --bad-soft: rgba(184, 57, 44, .12);
  --shadow: 0 1px 2px rgba(16, 25, 40, .06), 0 8px 24px -12px rgba(16, 25, 40, .18);
  --shadow-pop: 0 12px 40px -12px rgba(16, 25, 40, .32);
  --r: 10px;
  --r-sm: 7px;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --side-w: 224px;
  --side-w-min: 62px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0D131B;
    --surface: #151D27;
    --surface-2: #1B2531;
    --surface-3: #202B39;
    --ink: #E7EEF7;
    --ink-2: #B3C0CE;
    --muted: #8494A6;
    --line: #26323F;
    --line-soft: #1F2A36;
    --accent: #7BA4FF;
    --accent-ink: #0D131B;
    --accent-soft: rgba(123, 164, 255, .14);
    --good: #4CC08C;
    --good-soft: rgba(76, 192, 140, .15);
    --warn: #E3AA45;
    --warn-soft: rgba(227, 170, 69, .15);
    --bad: #EE7A6D;
    --bad-soft: rgba(238, 122, 109, .15);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px -14px rgba(0, 0, 0, .7);
    --shadow-pop: 0 16px 44px -12px rgba(0, 0, 0, .8);
  }
}

:root[data-theme="dark"] {
  --ground: #0D131B;
  --surface: #151D27;
  --surface-2: #1B2531;
  --surface-3: #202B39;
  --ink: #E7EEF7;
  --ink-2: #B3C0CE;
  --muted: #8494A6;
  --line: #26323F;
  --line-soft: #1F2A36;
  --accent: #7BA4FF;
  --accent-ink: #0D131B;
  --accent-soft: rgba(123, 164, 255, .14);
  --good: #4CC08C;
  --good-soft: rgba(76, 192, 140, .15);
  --warn: #E3AA45;
  --warn-soft: rgba(227, 170, 69, .15);
  --bad: #EE7A6D;
  --bad-soft: rgba(238, 122, 109, .15);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px -14px rgba(0, 0, 0, .7);
  --shadow-pop: 0 16px 44px -12px rgba(0, 0, 0, .8);
}

/* ---------- основа ---------- */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.015em; text-wrap: balance; }
h1 { font-size: 21px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.eyebrow {
  font: 500 11px/1 var(--mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { margin-left: auto; }
[hidden] { display: none !important; }

/* ---------- каркас страницы ---------- */

.app {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  min-height: 100vh;
}
/* Свёрнутое меню: остаются только значки. Подписи прячутся целиком, а не
   переносятся — ради этого они и обёрнуты в .nav-label. Ширина колонки
   тоже сжимается, иначе значки повисли бы в пустоте. Выбор запоминается. */
body.side-min .app { grid-template-columns: var(--side-w-min) 1fr; }
body.side-min .side { padding: 16px 8px; }
body.side-min .brand { justify-content: center; padding: 2px 0; }
body.side-min .brand > div:last-child,
body.side-min .navlabel,
body.side-min .nav-label,
body.side-min .side-foot,
body.side-min .side-collapse span:not(.nav-ico) { display: none; }
body.side-min .nav {
  position: relative; justify-content: center; padding: 11px 0; gap: 0;
}
body.side-min .nav-ico { width: auto; font-size: 15px; }
body.side-min .nav-count {
  position: absolute; top: 3px; right: 6px; margin: 0;
  padding: 1px 5px; font-size: 9.5px; line-height: 1.4;
}
body.side-min .side-collapse { justify-content: center; padding: 10px 0; }
body.side-min .side-collapse .nav-ico { transform: rotate(180deg); }

.side {
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 8px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  font: 600 13px/1 var(--mono);
}
.brand b { display: block; font-size: 14px; font-weight: 600; }
.brand span { display: block; font: 400 11px/1.3 var(--mono); color: var(--muted); }

.navgroup { display: flex; flex-direction: column; gap: 2px; }
.navlabel {
  font: 500 10px/1 var(--mono);
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); padding: 0 8px 7px;
}
.nav {
  display: flex; align-items: center; gap: 9px;
  padding: 9px; border-radius: var(--r-sm);
  color: var(--ink-2); font-size: 14px; text-decoration: none;
}
.nav:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.nav.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-ico { width: 18px; text-align: center; font-size: 13px; color: var(--muted); flex-shrink: 0; }
.nav.on .nav-ico { color: var(--accent); }
.nav-count {
  margin-left: auto; font: 500 11px/1 var(--mono);
  background: var(--line-soft); color: var(--muted);
  padding: 3px 7px; border-radius: 999px;
}
.nav.on .nav-count { background: var(--surface); color: var(--accent); }
.nav-count.hot { background: var(--bad-soft); color: var(--bad); }
.side-foot {
  margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line);
  font: 400 11.5px/1.7 var(--mono); color: var(--muted);
}
.side-foot b { color: var(--ink-2); font-weight: 500; }

.colmain { min-width: 0; display: flex; flex-direction: column; }
.main { min-width: 0; padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 18px; }
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
}
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.topbar-tools { display: flex; align-items: center; gap: 8px; }

/* мобильная шапка и нижняя навигация */
.mobilebar, .tabbar, .side-mask { display: none; }

/* ---------- компоненты ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
}
.card-pad-0 { padding: 0; }
.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.card-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.sec { display: flex; flex-direction: column; gap: 10px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font: 500 12px/1 var(--sans);
  padding: 5px 9px; border-radius: var(--r-sm);
  background: var(--surface-3); color: var(--ink-2);
  white-space: nowrap;
}
.tag-good { background: var(--good-soft); color: var(--good); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-bad  { background: var(--bad-soft);  color: var(--bad); }
.tag-info { background: var(--accent-soft); color: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.dot-idle { background: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: 500 14px/1 var(--sans);
  padding: 10px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--line); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { color: var(--accent-ink); filter: brightness(1.08); }
.btn-danger { color: var(--bad); border-color: var(--line); }
.btn-danger:hover { border-color: var(--bad); color: var(--bad); }
.btn-sm { padding: 7px 11px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--line-soft); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .flabel { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.fhint { font-size: 12.5px; color: var(--muted); }
input[type=text], input[type=number], input[type=password], input[type=search],
input[type=date], select, textarea {
  font: 400 14px/1.4 var(--sans);
  padding: 10px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
  width: 100%;
  min-height: 40px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--muted); }
.input-num { font-family: var(--mono); text-align: right; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 18px, calc(100% - 10px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 40px; height: 23px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--line);
  position: relative; transition: background .15s;
  flex-shrink: 0;
}
.switch-track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow);
  transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(17px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar { height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }

.figure { display: flex; align-items: baseline; gap: 7px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.figure b { font-size: 30px; font-weight: 600; letter-spacing: -.02em; line-height: 1; }
.figure span { font-size: 14px; color: var(--muted); }

.kpis {
  display: grid; gap: 1px; background: var(--line-soft);
  border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.kpi { background: var(--surface); padding: 13px 15px; }
.kpi-k { font-size: 12.5px; color: var(--muted); }
.kpi-v { font: 600 21px/1.3 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi-v em { font-style: normal; font-size: 13px; color: var(--muted); font-weight: 400; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th {
  font: 500 11px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); text-align: left; padding: 0 10px 10px; font-weight: 500;
}
table.tbl th:first-child, table.tbl td:first-child { padding-left: 0; }
table.tbl th:last-child, table.tbl td:last-child { padding-right: 0; }
table.tbl td { padding: 11px 10px; border-top: 1px solid var(--line-soft); vertical-align: middle; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl td.n { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; color: var(--ink-2); }
.tbl-wrap { overflow-x: auto; }

.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0; border-top: 1px solid var(--line-soft);
  color: inherit; text-decoration: none;
}
.list-item:first-child { border-top: 0; }
.list-item:hover { text-decoration: none; }
.avatar {
  width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font: 600 12px/1 var(--sans);
}
.empty { padding: 22px 8px; text-align: center; color: var(--muted); font-size: 13.5px; }

.logbox {
  font: 400 12.5px/1.7 var(--mono);
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--r-sm); padding: 10px 12px;
  max-height: 260px; overflow-y: auto;
  color: var(--ink-2);
  white-space: pre-wrap; word-break: break-word;
}

/* модальные окна */
.modal-mask {
  position: fixed; inset: 0; background: rgba(9, 14, 22, .55);
  backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center;
  padding: 20px; z-index: 400;
}
/* Окно показывается только когда его открыли: класс .open ставит скрипт,
   атрибут hidden — вариант для окон, которые прячутся без класса. */
.modal-mask.open, .modal-mask:not([hidden]).shown { display: flex; }
.modal-mask[hidden] { display: none !important; }
.modal {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow-pop);
  width: 100%; max-width: 560px; max-height: 88vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot {
  padding: 14px 18px; border-top: 1px solid var(--line);
  display: flex; gap: 8px; justify-content: flex-end;
}
.x-btn {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 20px; line-height: 1; padding: 4px 8px; border-radius: var(--r-sm);
}
.x-btn:hover { background: var(--line-soft); color: var(--ink); }

/* уведомления */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 500; }
.toast {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--r-sm); box-shadow: var(--shadow-pop);
  padding: 11px 14px; font-size: 13.5px; max-width: 330px;
}
.toast-bad { border-left-color: var(--bad); }
.toast-good { border-left-color: var(--good); }

/* переключатель темы */
.themetoggle {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
}
.themetoggle button {
  font: 500 12px/1 var(--sans); color: var(--muted);
  background: none; border: 0; border-radius: 999px;
  padding: 7px 11px; cursor: pointer;
}
.themetoggle button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

/* ---------- карточка лида, этапы, напоминания ---------- */

.stg-pill, .st-pill {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font: 500 12px var(--sans); padding: 4px 9px; border-radius: 999px;
  background: var(--surface-3); color: var(--ink-2);
}
/* Состояние лида. Имена классов приходят с сервера (_STATUS_KEYS):
   st-q — в очереди, st-s — написали, st-r — ответил, st-x — нет в WhatsApp. */
.sd { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.st-q { background: var(--surface-3); color: var(--ink-2); }
.sd-q { background: var(--muted); }
.st-s { background: var(--accent-soft); color: var(--accent); }
.sd-s { background: var(--accent); }
.st-r { background: var(--good-soft); color: var(--good); }
.sd-r { background: var(--good); }
.st-x { background: var(--bad-soft); color: var(--bad); }
.sd-x { background: var(--bad); }

/* Этап воронки (PIPELINE_STAGE_META). */
.stg-new { background: var(--accent-soft); color: var(--accent); }
.stg-contacted { background: var(--surface-3); color: var(--ink-2); }
.stg-responded { background: var(--good-soft); color: var(--good); }
.stg-meeting { background: var(--accent-soft); color: var(--accent); }
.stg-registered { background: var(--good-soft); color: var(--good); }
.stg-lost { background: var(--bad-soft); color: var(--bad); }
.stg-paused { background: var(--warn-soft); color: var(--warn); }

/* Источник лида (_CATEGORY_CSS): три цвета по кругу. */
.t-rent { background: var(--accent-soft); color: var(--accent); }
.t-taxi { background: var(--warn-soft); color: var(--warn); }
.t-comm { background: var(--good-soft); color: var(--good); }


/* карточка лида — выезжает справа, на телефоне снизу на весь экран */
.drawer-mask { position: fixed; inset: 0; background: rgba(9,14,22,.5); z-index: 380; opacity: 0; pointer-events: none; transition: opacity .2s; }
.drawer-mask.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%);
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-pop); z-index: 390;
  transform: translateX(100%); transition: transform .2s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-title { font-size: 17px; font-weight: 600; }
.drawer-sub { font: 400 12.5px var(--mono); color: var(--muted); margin-top: 3px; }
.drawer-close { background: none; border: 0; font-size: 19px; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: var(--r-sm); }
.drawer-close:hover { background: var(--line-soft); color: var(--ink); }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px 40px; }
.section-title {
  font: 500 11px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin: 22px 0 9px;
}
.drawer-body > div:first-child > .section-title:first-child { margin-top: 0; }
.btn-mini {
  font: 500 12.5px var(--sans); padding: 7px 11px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
}
.btn-mini:hover { border-color: var(--accent); color: var(--accent); }
.btn-mini.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-mini.btn-danger:hover { border-color: var(--bad); color: var(--bad); }
.stage-actions, .status-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.assign-toggle { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; }
.assign-toggle button { border: 0; background: none; border-radius: 999px; padding: 7px 13px; font: 500 12.5px var(--sans); color: var(--muted); cursor: pointer; }
.assign-toggle button.on { background: var(--accent); color: var(--accent-ink); }
.status-big { display: flex; align-items: center; gap: 12px; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r); padding: 12px 14px; }
.status-big-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface); font-size: 16px; }
.status-big-label { font-size: 14.5px; font-weight: 600; }
.status-big-sub { font-size: 12.5px; color: var(--muted); }
.phones-list { display: flex; flex-direction: column; gap: 6px; }
.kv-grid { display: grid; grid-template-columns: 128px 1fr; gap: 8px 12px; font-size: 13.5px; }
.kv-k { color: var(--muted); }
.kv-v { color: var(--ink); word-break: break-word; }
.history-list { display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; }
.edit-form { display: flex; flex-direction: column; gap: 12px; }
.edit-error { color: var(--bad); font-size: 13px; min-height: 18px; }

/* напоминание о задаче */
.notify-mask { position: fixed; inset: 0; background: rgba(9,14,22,.55); display: none; align-items: center; justify-content: center; z-index: 420; padding: 20px; }
.notify-mask.open { display: flex; }
.notify-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-pop); padding: 22px; max-width: 380px; text-align: center; }
.notify-icon { font-size: 28px; }
.notify-title { font-size: 16px; font-weight: 600; margin-top: 8px; }
.notify-sub { color: var(--muted); font-size: 13.5px; margin-top: 6px; }
.notify-actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }

.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.modal-footer { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.modal-msg { font-size: 13px; color: var(--bad); margin-right: auto; }


@media (max-width: 880px) {
  .drawer { width: 100%; top: auto; height: 92dvh; border-radius: 14px 14px 0 0;
            border-left: 0; transform: translateY(100%); }
  .drawer.open { transform: none; }
  .kv-grid { grid-template-columns: 108px 1fr; }
}

/* ---------- поля, списки и мелочи внутри карточек ---------- */

.field-label { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.field-input, .field-select, .field-area,
.form-input, .form-select {
  font: 400 14px/1.4 var(--sans); padding: 10px 11px; min-height: 40px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); color: var(--ink); width: 100%;
}
.field-area { min-height: 78px; resize: vertical; }
.edit-row { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); }
.edit-row span { font-weight: 500; }
.req { color: var(--bad); font-size: 11.5px; margin-left: 6px; }

.phone-row {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--r-sm); padding: 8px 11px; font-size: 13.5px;
}
.phone-num { font-family: var(--mono); flex: 1; min-width: 0; word-break: break-all; }
.phone-act, .phone-del {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: var(--r-sm);
  display: grid; place-items: center; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; text-decoration: none; font-size: 13px;
  color: var(--ink-2);
}
.phone-act:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.phone-del:hover { border-color: var(--bad); color: var(--bad); }

.hist-row { font-size: 13px; color: var(--ink-2); padding: 7px 0; border-top: 1px solid var(--line-soft); }
.hist-row:first-child { border-top: 0; }
.history-empty { font-size: 13px; color: var(--muted); padding: 8px 0; }
.msg { padding: 9px 0; border-top: 1px solid var(--line-soft); }
.msg:first-child { border-top: 0; }
.msg-meta { font: 400 11.5px var(--mono); color: var(--muted); }
.msg-text { font-size: 13.5px; margin-top: 3px; white-space: pre-wrap; word-break: break-word; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.ph { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.ph .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.btn-p { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-p:hover { color: var(--accent-ink); filter: brightness(1.08); }
.btn-s { }
.modal-close, .x-btn {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 19px; line-height: 1; padding: 4px 8px; border-radius: var(--r-sm);
}
.modal-close:hover, .x-btn:hover { background: var(--line-soft); color: var(--ink); }
.modal-err, .modal-msg { font-size: 13px; color: var(--bad); margin-right: auto; }
.modal-msg.ok { color: var(--good); }
.flash-ico { color: var(--good); }
.act-call, .act-wa { text-decoration: none; }
.status-big-text { min-width: 0; }

/* напоминания о задачах — всплывают поверх страницы */
.reminder-stack {
  position: fixed; right: 16px; bottom: 16px; z-index: 450;
  display: flex; flex-direction: column; gap: 8px; max-width: 340px;
}
.reminder-banner {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--warn); border-radius: var(--r);
  box-shadow: var(--shadow-pop); padding: 13px 15px;
}
.rb-head { display: flex; align-items: center; gap: 8px; }
.rb-tag { font: 500 11px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--warn); }
.rb-close { margin-left: auto; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 15px; }
.rb-close:hover { color: var(--ink); }
.rb-title { font-size: 14.5px; font-weight: 500; margin-top: 5px; }
.rb-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.rb-actions { display: flex; gap: 7px; margin-top: 10px; flex-wrap: wrap; }

/* сортируемые заголовки и ячейки таблиц — нужны и на «Лидах», и в «Воронке» */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink-2); }
th.sortable .arrow::after { content: ''; opacity: .5; margin-left: 5px; }
th.sort-asc .arrow::after { content: '↑'; opacity: 1; }
th.sort-desc .arrow::after { content: '↓'; opacity: 1; }
.co { font-weight: 500; }
.co-sub { font: 400 12px var(--mono); color: var(--muted); }
.cell-mono { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }

@media (max-width: 880px) {
  .reminder-stack { left: 12px; right: 12px; bottom: 78px; max-width: none; }
}

/* ---------- мобильный ---------- */

@media (max-width: 880px) {
  body { font-size: 15px; }
  .app { grid-template-columns: 1fr; }

  .side {
    position: fixed; top: 0; left: 0; bottom: 0; width: 272px;
    z-index: 320; transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-pop);
    height: 100dvh;
  }
  body.side-open .side { transform: none; }
  .side-mask {
    display: block; position: fixed; inset: 0;
    background: rgba(9, 14, 22, .5); z-index: 310;
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  body.side-open .side-mask { opacity: 1; pointer-events: auto; }

  .mobilebar {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 300;
    padding: 10px 14px;
    background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .mobilebar .brand-mark { width: 26px; height: 26px; }
  .mobilebar-title { font-size: 15px; font-weight: 600; }

  .main { padding: 14px 14px 84px; gap: 14px; }
  .topbar h1 { font-size: 19px; }

  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 300;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tab {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 2px; border-radius: var(--r-sm);
    color: var(--muted); font-size: 11px; text-decoration: none; position: relative;
  }
  .tab:hover { text-decoration: none; }
  .tab .tab-ico { font-size: 17px; line-height: 1; }
  .tab.on { color: var(--accent); }
  .tab-dot {
    position: absolute; top: 4px; right: 50%; margin-right: -16px;
    min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
    background: var(--bad); color: #fff;
    font: 600 10px/16px var(--mono); text-align: center;
  }

  /* Таблица-матрица (дни × источники) карточками не читается: ей нужен
     горизонтальный сдвиг внутри своей рамки. */
  table.tbl.tbl-plain, table.tbl.tbl-plain tbody, table.tbl.tbl-plain tr { display: table; width: auto; }
  table.tbl.tbl-plain thead { display: table-header-group; }
  table.tbl.tbl-plain tr { display: table-row; background: none; border: 0; padding: 0; margin: 0; }
  table.tbl.tbl-plain td { display: table-cell; padding: 9px 10px; border-top: 1px solid var(--line-soft); }
  table.tbl.tbl-plain td::before { content: none; }
  .card { padding: 14px; border-radius: var(--r); }
  .kpis { grid-template-columns: 1fr 1fr; }
  .figure b { font-size: 26px; }
  .btn { min-height: 42px; }
  .modal-mask { padding: 0; align-items: flex-end; }
  .modal { max-width: none; max-height: 92vh; border-radius: 14px 14px 0 0; }
  .toasts { left: 12px; right: 12px; bottom: 78px; }
  .toast { max-width: none; }
  table.tbl { font-size: 13.5px; }
}

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