:root {
  --ink: #131820;
  --ink-soft: #5d6874;
  --line: #dde2e8;
  --line-soft: #eaeef2;
  --bg: #e9ecf0;
  --panel: #ffffff;
  --navy: #16233a;
  --navy-soft: #223354;
  --focus: #2563eb;
  --ok: #0d9488;
  --danger: #b42318;
  --radius: 10px;
  --font: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--ink-soft); }

/* ------------------------------------------------------------------ вход */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% -10%, #24344f 0%, var(--navy) 55%, #0d1420 100%);
}

.login__card {
  width: min(360px, 100%);
  background: var(--panel);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 24px 60px rgba(6, 12, 24, .45);
}

.login__mark { display: flex; gap: 6px; margin-bottom: 20px; }
.login__mark span { width: 26px; height: 6px; border-radius: 3px; }
.login__mark span:nth-child(1) { background: #2563eb; }
.login__mark span:nth-child(2) { background: #0d9488; }
.login__mark span:nth-child(3) { background: #c2410c; }

.login h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.01em; }
.login__hint { margin: 0 0 22px; color: var(--ink-soft); font-size: 14px; }
.login label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }

.login input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
}
.login input:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }

.login button {
  width: 100%;
  margin-top: 16px;
  padding: 11px;
  border: 0;
  border-radius: var(--radius);
  background: var(--navy);
  color: #fff;
  cursor: pointer;
}
.login button:hover { background: var(--navy-soft); }
.login__error { margin: 14px 0 0; color: var(--danger); font-size: 13px; }

/* --------------------------------------------------------------- каркас */

.app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  height: 56px;
  background: var(--navy);
  color: #e8edf5;
  flex-shrink: 0;
}

.topbar__brand { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.brand-mark {
  width: 20px; height: 20px; border-radius: 6px;
  background: linear-gradient(135deg, #2563eb 0%, #0d9488 100%);
}
.brand-name { font-weight: 600; letter-spacing: .02em; }

.accounts { display: flex; gap: 8px; overflow-x: auto; flex: 1; min-width: 0; }

.acc {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .16);
  background: transparent;
  color: #cbd6e6;
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
}
.acc:hover { background: rgba(255, 255, 255, .07); }
.acc.is-active { background: #fff; color: var(--navy); border-color: #fff; }
.acc__dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.acc__count {
  min-width: 20px; padding: 0 6px; border-radius: 999px;
  background: #ef4444; color: #fff; font-size: 11px; line-height: 17px;
  text-align: center; font-variant-numeric: tabular-nums;
}
.acc.is-broken { border-color: #ef4444; color: #ffb4ab; }

.topbar__tools { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

#search {
  width: 240px; padding: 7px 11px;
  border-radius: 8px; border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .08); color: #fff;
}
#search::placeholder { color: #93a2b8; }
#search:focus { outline: 2px solid #5b8bf0; outline-offset: 0; }

.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #cbd6e6; cursor: pointer; }

.btn-ghost {
  border: 1px solid rgba(255, 255, 255, .18);
  background: transparent; color: #cbd6e6;
  padding: 6px 11px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.btn-ghost:hover { background: rgba(255, 255, 255, .08); }
.btn-ghost.is-on { background: #fff; color: var(--navy); border-color: #fff; }

.sync { font-size: 12px; color: #93a2b8; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sync.is-error { color: #ffb4ab; }

.workspace { flex: 1; display: grid; grid-template-columns: minmax(300px, 380px) 1fr; min-height: 0; }

/* ------------------------------------------------------------ список чатов */

.list {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
}

.list__empty { padding: 28px 20px; color: var(--ink-soft); font-size: 14px; }

.chat {
  display: grid;
  grid-template-columns: 4px 40px 1fr;
  gap: 0 11px;
  padding: 11px 14px 11px 0;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  align-items: start;
}
.chat:hover { background: #f6f8fa; }
.chat.is-active { background: #eef3fb; }

.chat__stripe { height: 100%; min-height: 42px; border-radius: 0 3px 3px 0; }

.chat__avatar {
  width: 40px; height: 40px; border-radius: 9px;
  background: #e6eaef; object-fit: cover;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 600; color: #64748b;
  overflow: hidden;
}
.chat__avatar img { width: 100%; height: 100%; object-fit: cover; }

.chat__body { min-width: 0; }
.chat__top { display: flex; align-items: baseline; gap: 8px; }
.chat__name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat__time { margin-left: auto; font-size: 11px; color: var(--ink-soft); white-space: nowrap; font-variant-numeric: tabular-nums; }

.tag {
  font-size: 11px; padding: 1px 7px; border-radius: 5px;
  color: #fff; white-space: nowrap; flex-shrink: 0;
}

.chat__item { font-size: 12px; color: var(--ink-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat__last { font-size: 13px; color: #46505c; margin-top: 3px; display: flex; gap: 6px; align-items: center; }
.chat__last span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat__unread {
  margin-left: auto; flex-shrink: 0;
  min-width: 19px; height: 19px; padding: 0 6px; border-radius: 999px;
  background: #ef4444; color: #fff; font-size: 11px; line-height: 19px; text-align: center;
}
.chat.is-unread .chat__name { font-weight: 700; }
.chat.is-unread .chat__last { color: var(--ink); font-weight: 500; }

/* ------------------------------------------------------------------ диалог */

.thread { display: flex; flex-direction: column; min-height: 0; background: #f2f4f7; }
.thread__placeholder { margin: auto; text-align: center; color: var(--ink-soft); padding: 24px; }
.thread__inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.thread__head {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0;
}
.thread__head h2 { margin: 0; font-size: 16px; }
.thread__head .item { font-size: 13px; color: var(--ink-soft); }
.thread__head a { color: var(--focus); text-decoration: none; }
.thread__head a:hover { text-decoration: underline; }
.thread__head-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.thread__messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }

.day { align-self: center; font-size: 11px; color: var(--ink-soft); background: #e2e6eb; padding: 3px 10px; border-radius: 999px; margin: 8px 0; }

.msg {
  max-width: min(62%, 620px);
  padding: 9px 13px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  align-self: flex-start;
}
.msg--out { align-self: flex-end; background: #dbeafe; border-color: #c3d9fb; }
.msg--system { align-self: center; background: transparent; border: 0; color: var(--ink-soft); font-size: 12px; max-width: 80%; text-align: center; }
.msg__meta { margin-top: 4px; font-size: 11px; color: var(--ink-soft); text-align: right; font-variant-numeric: tabular-nums; }

.composer {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 12px 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "text btn" "from from";
  gap: 8px 12px;
  flex-shrink: 0;
}
.composer textarea {
  grid-area: text;
  resize: none;
  max-height: 160px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
}
.composer textarea:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }
.composer button {
  grid-area: btn;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius);
  background: var(--navy);
  color: #fff;
  cursor: pointer;
  height: 42px;
  align-self: end;
}
.composer button:hover { background: var(--navy-soft); }
.composer button:disabled { opacity: .5; cursor: default; }
.composer__from { grid-area: from; font-size: 12px; color: var(--ink-soft); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); z-index: 50;
}
.toast.is-error { background: var(--danger); }

/* ---------------------------------------------------------------- мобильный */

@media (max-width: 860px) {
  html, body { height: 100dvh; overflow: hidden; }
  .workspace { grid-template-columns: 1fr; }
  .thread { display: none; }
  .app.is-thread .list { display: none; }
  .app.is-thread .thread { display: flex; }
  .app.is-thread .topbar { display: none; }

  .topbar {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 12px 10px;
    gap: 8px;
  }
  .topbar__brand { display: none; }
  .accounts { order: 2; width: 100%; padding-bottom: 2px; }
  .acc { padding: 8px 14px; font-size: 14px; }
  .topbar__tools { order: 1; width: 100%; gap: 8px; }
  #search { flex: 1; min-width: 0; width: auto; padding: 9px 12px; }
  .toggle, .sync { font-size: 12px; }
  #logout-btn { display: none; }

  .chat { padding: 13px 14px 13px 0; grid-template-columns: 4px 44px 1fr; }
  .chat__avatar { width: 44px; height: 44px; }

  .thread__head {
    padding: 10px 14px;
    position: sticky; top: 0; z-index: 5;
  }
  .thread__messages { padding: 14px 12px; }
  .msg { max-width: 88%; font-size: 15px; }

  .composer {
    padding: 10px 12px;
    grid-template-areas: "from from" "text btn";
  }
  .composer textarea { font-size: 16px; }  /* меньше 16px — iOS/Android зумят страницу */
  .composer button { height: 44px; padding: 0 18px; }
  .composer__from { font-size: 11px; }

  .media--image img, .media--video video, .media--video iframe { width: 100%; }
  .viewer { padding: 12px; }
}

/* Установленное приложение: своя строка состояния */
@media (display-mode: standalone) {
  .topbar { padding-top: 10px; }
}

@media (prefers-reduced-motion: no-preference) {
  .chat, .btn-ghost, .acc { transition: background-color .12s ease; }
}

/* ------------------------------------------------------------- вложения */

.msg:has(.media) { padding: 6px 6px 8px; }
.msg__text { padding: 3px 7px 0; }

.media { display: block; margin-bottom: 4px; }

.media--image img,
.media--video video,
.media--video img {
  display: block;
  max-width: 100%;
  width: 320px;
  max-height: 340px;
  border-radius: 8px;
  background: #dfe4ea;
  object-fit: cover;
}
.media--image img { cursor: zoom-in; }
.media--video video { object-fit: contain; background: #000; }
.media--video iframe {
  display: block;
  width: 340px;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 8px;
  background: #000;
}

.media--voice { display: flex; align-items: center; gap: 8px; padding: 2px 4px; }
.media--voice audio { height: 34px; max-width: 260px; }

.media--card {
  display: flex; gap: 10px; align-items: center;
  padding: 7px; border-radius: 8px;
  background: rgba(15, 23, 42, .05);
  text-decoration: none; color: inherit;
  max-width: 320px;
}
.media--card:hover { background: rgba(15, 23, 42, .09); }
.media--card img { width: 46px; height: 46px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.media__card-title { font-size: 13px; font-weight: 600; line-height: 1.3; }
.media__note { font-size: 11px; color: var(--ink-soft); padding: 3px 4px 0; }
.media__link { display: inline-block; padding: 3px 4px; color: var(--focus); font-size: 13px; }

.viewer {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 12, 20, .88);
  display: grid; place-items: center;
  padding: 32px; cursor: zoom-out;
}
.viewer img { max-width: 100%; max-height: 100%; border-radius: 6px; }

/* ================================================================ СДЕЛКИ */

.views { display: flex; gap: 4px; flex-shrink: 0; }
.view-tab {
  border: 0; background: transparent; color: #cbd6e6;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.view-tab:hover { background: rgba(255, 255, 255, .08); }
.view-tab.is-active { background: rgba(255, 255, 255, .16); color: #fff; font-weight: 600; }

.whoami { font-size: 12px; color: #93a2b8; white-space: nowrap; }
.app.is-deals .accounts,
.app.is-deals #search,
.app.is-deals #unread-only,
.app.is-deals .toggle:not(.toggle--dark) { display: none; }

/* Поиск и фильтры в шапке относятся к чатам с Avito — в переписке
   с сотрудниками у списка свой поиск, а аккаунты Avito ни при чём */
.app.is-staff .accounts,
.app.is-staff #search,
.app.is-staff #unread-only,
.app.is-staff .toggle:not(.toggle--dark) { display: none; }

.deals-view { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--panel); }

.deals-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: #f7f9fb;
  flex-shrink: 0;
}
.deals-bar select, .deals-bar input[type="search"] {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  font-size: 13px;
}
.deals-bar input[type="search"] { flex: 1; min-width: 200px; }
.deals-stats { margin-left: auto; font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.toggle--dark { color: var(--ink-soft); }

.btn-primary {
  border: 0; background: var(--navy); color: #fff;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
.btn-primary:hover { background: var(--navy-soft); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-plain {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
.btn-plain:hover { background: #f1f4f8; }

.deals-scroll { flex: 1; overflow: auto; min-height: 0; }

.deals-table { border-collapse: separate; border-spacing: 0; font-size: 13px; width: max-content; min-width: 100%; }
.deals-table th {
  position: sticky; top: 0; z-index: 3;
  background: #eef1f5; text-align: left; font-weight: 600; font-size: 12px;
  padding: 8px 9px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line-soft);
  white-space: nowrap;
}
.deals-table td {
  padding: 6px 9px; border-bottom: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft); vertical-align: top;
  max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.deals-table tr:hover td { background: #f7f9fc; }
.deals-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.deals-table td.editable { cursor: text; }
.deals-table td.editable:focus { outline: 2px solid var(--focus); outline-offset: -2px; }
.deal-empty { padding: 28px; text-align: center; color: var(--ink-soft); }
.cell-empty { color: #9aa4b2; }

.chip {
  display: inline-block; padding: 2px 9px; border-radius: 5px;
  font-size: 12px; line-height: 18px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip--button { border: 0; cursor: pointer; }

.cell-input {
  width: 100%; min-width: 90px; padding: 3px 5px; font-size: 13px;
  border: 1px solid var(--focus); border-radius: 4px; background: #fff;
}

.col-actions { white-space: nowrap; width: 1%; }
.row-btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  padding: 3px 8px; border-radius: 6px; cursor: pointer; font-size: 12px; margin-right: 4px;
}
.row-btn:hover { background: #eef2f7; color: var(--ink); }
.row-btn--danger:hover { background: #fee2e2; color: var(--danger); border-color: #fca5a5; }

/* Кнопка-значок: квадратная, чтобы значки в столбце стояли ровно.
   Смысл каждой — в подсказке и aria-label, они заданы в разметке. */
.row-btn--icon {
  width: 26px; height: 24px; padding: 0;
  font-size: 13px; line-height: 1; text-align: center;
}

.linked-deals { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; margin-top: 6px; }

/* ------------------------------------------------------------ модальные */

.modal {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(8, 12, 20, .5);
  display: grid; place-items: center; padding: 20px;
}
.modal__card {
  background: var(--panel); border-radius: 12px; padding: 22px;
  width: min(720px, 100%); max-height: 90vh; overflow-y: auto;
  box-shadow: 0 24px 60px rgba(6, 12, 24, .35);
}
.modal__card--narrow { width: min(460px, 100%); }
.modal__card h2 { margin: 0 0 14px; font-size: 18px; }
.modal__note {
  background: #eff6ff; border-radius: 8px; padding: 8px 11px;
  font-size: 12px; color: #1e40af; margin-bottom: 14px;
}
.modal__footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-soft); }
.form-field.wide { grid-column: 1 / -1; }
.form-field input, .form-field select, .form-field textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fbfcfd; font-size: 14px; color: var(--ink); resize: vertical;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent;
}

.log-list { display: flex; flex-direction: column; gap: 10px; max-height: 50vh; overflow-y: auto; }
.log-row { border-left: 3px solid var(--line); padding-left: 10px; }
.log-when { font-size: 11px; color: var(--ink-soft); }
.log-what { font-size: 13px; }

/* ------------------------------------------------------------ настройки */

.settings-view { flex: 1; overflow-y: auto; background: var(--bg); min-height: 0; }
.settings-inner { max-width: 900px; margin: 0 auto; padding: 24px 20px 60px; }
.settings-inner h2 { font-size: 18px; margin: 26px 0 6px; }
.settings-inner > .muted { font-size: 13px; margin: 0 0 14px; }

.settings-block {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 16px; margin-bottom: 14px;
}
.settings-block h3 { margin: 0 0 12px; font-size: 15px; }
.settings-block .muted { font-size: 12px; margin: 10px 0 0; }

.dict-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.dict-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dict-row.is-hidden-item { opacity: .55; }
.dict-row input[type="color"] { width: 38px; height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.dict-name { flex: 1; min-width: 150px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; }
.dict-phone { width: 140px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; }

.dict-add, .user-add { display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.dict-add input:not([type="color"]), .user-add input, .user-add select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px;
}
.dict-add input:not([type="color"]) { flex: 1; min-width: 140px; }
.user-add input { flex: 1; min-width: 120px; }
.user-who { flex: 1; min-width: 160px; font-size: 13px; }
#user-list { display: flex; flex-direction: column; gap: 8px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
#user-list select { padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; }

@media (max-width: 860px) {
  .views { order: 0; width: 100%; }
  .view-tab { flex: 1; }
  .whoami { display: none; }
  .deals-bar { padding: 8px 10px; }
  .deals-bar input[type="search"] { min-width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field.half { grid-column: auto; }
  .modal__card { padding: 16px; }
  .deals-table td { max-width: 220px; }
}


/* ------------------------------------------- вкладки сделок и подсветка */

.scope-tabs {
  display: flex; gap: 2px; padding: 8px 14px 0;
  background: #f7f9fb; border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.scope-tab {
  border: 1px solid transparent; border-bottom: 0;
  background: transparent; color: var(--ink-soft);
  padding: 8px 16px; border-radius: 8px 8px 0 0;
  cursor: pointer; font-size: 14px; position: relative; top: 1px;
}
.scope-tab:hover { background: #eef2f7; color: var(--ink); }
.scope-tab.is-active {
  background: var(--panel); color: var(--ink); font-weight: 600;
  border-color: var(--line); border-bottom: 1px solid var(--panel);
}
.scope-count {
  display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 4px;
  background: #dde3ea; color: #46505c; border-radius: 999px;
  font-size: 11px; line-height: 17px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.scope-tab.is-active .scope-count { background: var(--navy); color: #fff; }

.deals-bar--dates { background: #fbfcfd; border-bottom: 1px solid var(--line-soft); }
.deals-bar--dates input[type="date"] {
  padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px;
  font-size: 13px; background: #fff;
}
.bar-label { font-size: 12px; color: var(--ink-soft); }

.chip-btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 13px;
  white-space: nowrap;
}
.chip-btn:hover { background: #eef2f7; color: var(--ink); }
.chip-btn.is-active { background: var(--navy); color: #fff; border-color: var(--navy); }
.chip-btn--warn { color: #b42318; border-color: #fecaca; }
.chip-btn--warn:hover { background: #fef2f2; color: #b42318; }
.chip-btn--warn.is-active { background: #b42318; color: #fff; border-color: #b42318; }
.chip-btn--warn.is-empty { color: var(--ink-soft); border-color: var(--line); }

/* Сегодняшние выезды — зелёным, просроченные — красным */
.deals-table td.is-today {
  background: #dcfce7;
  font-weight: 600;
  color: #14532d;
  box-shadow: inset 2px 0 0 #16a34a;
}
.deals-table td.is-overdue {
  background: #fee2e2;
  color: #991b1b;
  font-weight: 600;
  box-shadow: inset 2px 0 0 #dc2626;
}
.deals-table tr.row-today td { background: #f0fdf4; }
.deals-table tr.row-today td.is-today { background: #dcfce7; }
.deals-table tr.row-overdue td { background: #fef6f6; }
.deals-table tr.row-overdue td.is-overdue { background: #fee2e2; }
.deals-table tr.row-today:hover td,
.deals-table tr.row-overdue:hover td { filter: brightness(0.97); }

@media (max-width: 860px) {
  .scope-tabs { padding: 6px 8px 0; overflow-x: auto; }
  .scope-tab { padding: 8px 12px; font-size: 13px; white-space: nowrap; }
  .deals-bar--dates { gap: 6px; }
  .deals-bar--dates .bar-label { display: none; }
}

.final-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--ink-soft); cursor: pointer; white-space: nowrap;
}
.dict-new-name { min-width: 140px; }

/* -------------------------------------------------- отчёт по деньгам */

.finance-report {
  padding: 14px; background: #f7f9fb; border-bottom: 1px solid var(--line);
  flex-shrink: 0; max-height: 46vh; overflow-y: auto;
}
.finance-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.finance-head h3 { margin: 0; font-size: 15px; }
.finance-switch { display: flex; gap: 6px; margin-left: auto; }

.finance-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.finance-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px;
}
.finance-card--accent { border-color: #93c5fd; background: #eff6ff; }
.finance-card--profit { border-color: #86efac; background: #f0fdf4; }
.finance-card__title { font-size: 12px; color: var(--ink-soft); }
.finance-card__value { font-size: 20px; font-weight: 600; margin-top: 3px; font-variant-numeric: tabular-nums; }
.finance-card__note { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }

.finance-table { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 13px; background: var(--panel); }
.finance-table th {
  text-align: left; font-size: 12px; color: var(--ink-soft); font-weight: 600;
  padding: 7px 10px; border-bottom: 1px solid var(--line);
}
.finance-table td { padding: 6px 10px; border-bottom: 1px solid var(--line-soft); }
.finance-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.finance-table th:not(:first-child) { text-align: right; }

.form-grid--money { grid-template-columns: 1fr; }
.field-hint { font-size: 11px; color: var(--ink-soft); }
.profit-field input { font-weight: 600; }
.profit-field.is-mismatch input { border-color: #f59e0b; background: #fffbeb; }

/* ------------------------------------------------------------ права ролей */

.perm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.perm-table th {
  text-align: center; font-size: 12px; font-weight: 600; padding: 8px 6px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.perm-table th.perm-name, .perm-table td.perm-name { text-align: left; }
.perm-table td { padding: 7px 6px; border-bottom: 1px solid var(--line-soft); }
.perm-cell { text-align: center; }
.perm-cell input { width: 17px; height: 17px; cursor: pointer; }
.perm-table tr:hover td { background: #f7f9fc; }
#perm-matrix { overflow-x: auto; margin-bottom: 12px; }

@media (max-width: 860px) {
  .finance-report { max-height: 40vh; }
  .finance-cards { grid-template-columns: repeat(2, 1fr); }
  .perm-table { font-size: 12px; }
}

/* ------------------------------------ исполнитель: мастер или бригада */

.executor { display: inline-flex; align-items: baseline; gap: 5px; max-width: 100%; }
.executor__name { font-weight: 500; }
.executor__spec {
  font-size: 11px; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip__car { margin-left: 4px; font-size: 12px; }
.chip--brigade { background: #e0e7ff; color: #312e81; font-weight: 500; }

/* --------------------------------- длинный текст: раскрытие по кнопке */

.deals-table td.cell-long {
  position: relative;
  padding-right: 26px;          /* место под кнопку, строка не растёт */
}
.cell-long__text {
  display: block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell-more {
  position: absolute; top: 4px; right: 4px;
  width: 18px; height: 18px; padding: 0;
  border: 1px solid var(--line); border-radius: 4px;
  background: #fff; color: var(--ink-soft);
  font-size: 12px; line-height: 1; cursor: pointer;
}
.cell-more:hover { background: var(--navy); color: #fff; border-color: var(--navy); }
.deals-table tr:hover .cell-more { border-color: #c3ccd6; }

.popover {
  position: fixed; z-index: 80;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(8, 12, 20, .22);
  padding: 10px 12px 12px;
}
.popover__head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.popover__title { font-size: 11px; color: var(--ink-soft); }
.popover__close {
  margin-left: auto; border: 0; background: transparent; cursor: pointer;
  font-size: 18px; line-height: 1; color: var(--ink-soft); padding: 0 2px;
}
.popover__close:hover { color: var(--ink); }
.popover__text {
  font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
  max-height: 340px; overflow-y: auto;
}
.popover__area {
  width: 100%; font-size: 13px; line-height: 1.5; resize: vertical;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfd;
}
.popover__area:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }
.popover__footer { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.popover__hint { font-size: 11px; color: var(--ink-soft); }
.popover__footer .btn-primary, .popover__footer .btn-plain { margin-left: auto; }
.popover__footer .popover__hint + .btn-primary { margin-left: auto; }

@media (max-width: 860px) {
  .popover { left: calc(12px + var(--safe-left)) !important; right: calc(12px + var(--safe-right)); width: auto !important; }
  .executor__spec { display: none; }
}

/* ------------------------------------------ мастера и бригады в настройках */

.dict-spec { width: 150px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; }
.car-toggle, .member-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--ink-soft); cursor: pointer; white-space: nowrap;
}
.member-toggle {
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; background: #fff; color: var(--ink);
}
.member-toggle:hover { background: #f1f4f8; }
.member-toggle:has(input:checked) { background: #e0e7ff; border-color: #a5b4fc; color: #312e81; }

.dict-row--brigade { align-items: flex-start; }
.brigade-members { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 200px; }

/* ------------------------------------------------------------ города */

.city-bar {
  display: flex; gap: 6px; align-items: center;
  padding: 8px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line-soft);
  overflow-x: auto; flex-shrink: 0;
}
.city-tab {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
  font-size: 13px; white-space: nowrap;
}
.city-tab:hover { background: #f1f4f8; color: var(--ink); }
.city-tab.is-active {
  background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 500;
}
.city-tab__dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.city-tab__count {
  min-width: 18px; padding: 0 5px; border-radius: 999px;
  background: #e7ebf0; color: #46505c; font-size: 11px; line-height: 16px;
  text-align: center; font-variant-numeric: tabular-nums;
}
.city-tab.is-active .city-tab__count { background: rgba(255, 255, 255, .22); color: #fff; }

.final-toggle--reject span { color: #b42318; }
.final-toggle--reject input:disabled + span { color: var(--ink-soft); opacity: .5; }
.dict-city { padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; }

@media (max-width: 860px) {
  .city-bar { padding: 6px 10px; }
  .city-tab { padding: 7px 12px; }
}

/* ------------------------------------------ боковая панель новой заявки */

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 90;
  width: min(430px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -10px 0 34px rgba(8, 12, 20, .18);
  display: flex; flex-direction: column;
}

.drawer__head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  background: #f7f9fb; flex-shrink: 0;
}
.drawer__head h2 { margin: 0; font-size: 16px; }
.drawer__close {
  margin-left: auto; border: 0; background: transparent; cursor: pointer;
  font-size: 24px; line-height: 1; color: var(--ink-soft); padding: 0 4px;
}
.drawer__close:hover { color: var(--ink); }

.drawer__body { flex: 1; overflow-y: auto; padding: 16px 18px; min-height: 0; }
.drawer__note {
  background: #eff6ff; border-radius: 8px; padding: 8px 11px;
  font-size: 12px; color: #1e40af; margin-bottom: 14px;
}
.drawer__footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 18px; border-top: 1px solid var(--line);
  background: #f7f9fb; flex-shrink: 0;
}
.drawer .form-grid { grid-template-columns: 1fr 1fr; }

/* Таблица ужимается, чтобы панель её не перекрывала */
body.has-drawer .deals-scroll { padding-right: min(430px, 100%); }

@media (max-width: 860px) {
  .drawer { width: 100%; }
  body.has-drawer .deals-scroll { padding-right: 0; }
  .drawer .form-grid { grid-template-columns: 1fr; }
}

/* ------------------------------------------------ сворачивание отчёта */

.finance-toggle {
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  width: 24px; height: 24px; border-radius: 6px; cursor: pointer;
  font-size: 12px; line-height: 1; padding: 0; flex-shrink: 0;
}
.finance-toggle:hover { background: var(--navy); color: #fff; border-color: var(--navy); }
.finance-short { font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.finance-report.is-collapsed { padding: 8px 14px; }
.finance-report.is-collapsed .finance-head { margin-bottom: 0; }

/* ------------------------------------------ оплата и завершение за день */

.deals-table td.is-paid {
  background: #dcfce7;
  color: #14532d;
  font-weight: 600;
  box-shadow: inset -2px 0 0 #16a34a;
}
.deals-table tr.row-finished td:first-child { box-shadow: inset 3px 0 0 #94a3b8; }
.deals-table tr.row-finished { opacity: .78; }
.deals-table tr.row-finished:hover { opacity: 1; }
.deals-table tr.row-finished td.is-paid { background: #dcfce7; }

.popover--pay { width: 300px !important; }
.popover--pay .form-field { margin-bottom: 10px; }
.pay-toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fbfcfd; cursor: pointer; font-size: 14px;
}
.pay-toggle:has(input:checked) { background: #dcfce7; border-color: #86efac; color: #14532d; font-weight: 500; }
.final-toggle--long span { color: #6d28d9; }

.version {
  font-size: 11px; color: #6b7c95; white-space: nowrap;
  padding: 2px 7px; border: 1px solid rgba(255, 255, 255, .14); border-radius: 999px;
}
.login__version { margin: 14px 0 0; font-size: 11px; color: var(--ink-soft); text-align: center; }

@media (max-width: 860px) { .version { display: none; } }

/* ------------------------------------------------ заявки с сайтов */

.scope-tab--leads.has-new { color: #b45309; font-weight: 600; }
.scope-tab--leads.has-new .scope-count { background: #f59e0b; color: #fff; }
.scope-tab--leads.is-active.has-new { color: var(--ink); }

.deals-table tr.row-lead td:first-child { box-shadow: inset 3px 0 0 #f59e0b; }
.row-btn--accept { border-color: #86efac; color: #15803d; }
.row-btn--accept:hover { background: #16a34a; color: #fff; border-color: #16a34a; }

.source-card {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; margin-bottom: 10px; background: #fbfcfd;
}
.source-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.source-url { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.source-url__input {
  flex: 1; min-width: 220px; padding: 7px 10px; font-size: 12px;
  border: 1px solid var(--line); border-radius: 7px; background: #fff;
  font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--ink-soft);
}
.source-stats { font-size: 12px; color: var(--ink-soft); margin-top: 8px; }
.source-warn {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px;
}

/* ------------------------------------------------ раздел заявок с сайтов */

.tab-count {
  display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 5px;
  background: #f59e0b; color: #fff; border-radius: 999px;
  font-size: 11px; line-height: 17px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.view-tab.has-new { color: #fff; }

.leads-view { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.leads-scroll { flex: 1; overflow-y: auto; padding: 16px; min-height: 0; }
.leads-list {
  display: grid; gap: 12px; max-width: 1100px; margin: 0 auto;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}
.lead-empty { padding: 40px 20px; text-align: center; color: var(--ink-soft); }
.lead-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn__count {
  margin-left: 6px; padding: 0 5px; border-radius: 999px;
  background: rgba(15, 23, 42, .1); font-size: 11px;
}
.chip-btn.is-active .chip-btn__count { background: rgba(255, 255, 255, .25); }

.lead-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; gap: 7px;
}
.lead-card--new { border-color: #fbbf24; box-shadow: inset 3px 0 0 #f59e0b; }
.lead-card--converted { opacity: .72; }
.lead-card--rejected { opacity: .6; }
.lead-card--callback { border-color: #93c5fd; box-shadow: inset 3px 0 0 #3b82f6; }

.lead-card__head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lead-card__city { font-size: 12px; color: var(--ink-soft); }
.lead-card__time { margin-left: auto; font-size: 11px; color: var(--ink-soft); white-space: nowrap; }
.lead-card__name { font-size: 16px; font-weight: 600; }
.lead-card__phone {
  font-size: 15px; color: var(--focus); text-decoration: none;
  font-variant-numeric: tabular-nums; width: fit-content;
}
.lead-card__phone:hover { text-decoration: underline; }
.lead-card__text { font-size: 13px; line-height: 1.5; white-space: pre-wrap; color: #46505c; }
.lead-card__mark { font-size: 11px; color: var(--ink-soft); }
.lead-card__note {
  font-size: 12px; background: #fffbeb; border-radius: 7px;
  padding: 6px 9px; color: #92400e;
}
.lead-card__actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

@media (max-width: 860px) {
  .leads-list { grid-template-columns: 1fr; }
  .leads-scroll { padding: 10px; }
}

.cell-phone { color: var(--focus); text-decoration: none; font-variant-numeric: tabular-nums; }
.cell-phone:hover { text-decoration: underline; }
.lead-card__nophone {
  font-size: 13px; color: #b42318; background: #fef2f2;
  border-radius: 6px; padding: 4px 8px; width: fit-content;
}
.msg--missed { border-color: #fca5a5; background: #fef2f2; color: #991b1b; }

.source-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.source-table th {
  text-align: left; font-size: 12px; color: var(--ink-soft); font-weight: 600;
  padding: 7px 9px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.source-table td { padding: 7px 9px; border-bottom: 1px solid var(--line-soft); }
.source-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.source-table tr.source-idle td { color: var(--ink-soft); }
.settings-block code {
  background: #eef2f7; border-radius: 4px; padding: 1px 5px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px;
}

/* ------------------------------------------- вкладки: цвет и вид события */

/* Цвет вкладки задаётся в настройках и виден полоской у активной */
.scope-tab.is-active { border-top: 2px solid var(--tab-color, var(--navy)); }

.kind-switch { display: inline-flex; gap: 2px; margin-right: 6px; }

.kind-chip {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; line-height: 18px; white-space: nowrap;
}
.kind-chip--visit { background: #dbeafe; color: #1e40af; }
.kind-chip--call  { background: #fef3c7; color: #92400e; }

/* ------------------------------------------------- редактор вкладок */

.tab-list { display: flex; flex-direction: column; gap: 10px; }

.tab-row {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; background: #fbfcfd;
}
.tab-row.is-hidden-item { opacity: .55; }

.tab-row__head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tab-row__head .dict-name { flex: 1 1 150px; min-width: 120px; }
.tab-row__head select { flex: 0 1 auto; min-width: 0; }
.tab-row__head .row-btn[disabled] { opacity: .3; cursor: default; }

.tab-order { max-width: 200px; }

/* Счётчик и «Удалить» — одной группой справа: при переносе строки
   они уезжают вместе, а не кнопка отдельно от всего */
.tab-row__right {
  margin-left: auto; display: flex; gap: 8px; align-items: center;
}
.tab-count-hint {
  color: var(--ink-soft); font-size: 12px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

.tab-rules {
  margin-top: 10px; padding-top: 10px;
  border-top: 1px dashed var(--line);
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
}
.tab-rules__head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tab-rules__empty { color: var(--ink-soft); font-size: 13px; font-style: italic; }

.rule-row {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  width: 100%;
}
.rule-field { min-width: 180px; }
.rule-op { min-width: 130px; }
.rule-value { min-width: 150px; }
.rule-value--none { min-width: 0; }

/* Значения справочника — галочками: виден весь набор сразу */
.rule-picks {
  display: flex; gap: 6px; flex-wrap: wrap; flex: 1;
  padding: 4px 6px; background: #fff;
  border: 1px solid var(--line); border-radius: 8px;
}

.tab-diag {
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line-soft);
  display: flex; gap: 12px; flex-wrap: wrap; align-items: center; font-size: 13px;
}
.tab-diag__counts { color: var(--ink-soft); }
.tab-diag__ok { color: #15803d; }
.tab-diag__lost {
  color: #b42318; font-weight: 600;
  background: #fee2e2; border-radius: 6px; padding: 2px 8px;
}

/* ------------------------------------------- переписка между сотрудниками */

.staff-side { display: flex; flex-direction: column; min-height: 0; }

.staff-side__tools {
  display: flex; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  flex-shrink: 0;
}
.staff-side__tools select {
  flex: 1; min-width: 0; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.staff-side__search {
  margin: 10px 12px; padding: 7px 11px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  flex-shrink: 0;
}
.staff-list { flex: 1; overflow-y: auto; min-height: 0; }

.staff-room {
  width: 100%; display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 0 11px; align-items: start;
  padding: 11px 14px;
  border: 0; border-bottom: 1px solid var(--line-soft);
  background: transparent; text-align: left; cursor: pointer;
}
.staff-room:hover { background: #f6f8fa; }
.staff-room.is-active { background: #eef4ff; }

.staff-room__avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: #dbeafe; color: #1e40af; font-weight: 600;
}
.staff-room__avatar--group { background: #ddd6fe; color: #5b21b6; }

.staff-room__body { min-width: 0; }
.staff-room__head { display: flex; align-items: baseline; gap: 8px; }
.staff-room__title {
  font-weight: 600; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.staff-room__time { font-size: 11px; color: var(--ink-soft); flex-shrink: 0; }
.staff-room__last {
  font-size: 13px; color: var(--ink-soft); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.staff-room__meta { font-size: 11px; color: var(--ink-soft); margin-top: 3px; }
.staff-room.has-new .staff-room__title { font-weight: 700; }
.staff-room.has-new .staff-room__last { color: var(--ink); font-weight: 500; }
.staff-room__badge {
  align-self: center;
  min-width: 20px; padding: 0 6px; border-radius: 999px;
  background: #ef4444; color: #fff;
  font-size: 11px; line-height: 19px; text-align: center;
  font-variant-numeric: tabular-nums;
}

.staff-head { flex-wrap: wrap; align-items: baseline; row-gap: 4px; }
.staff-head__title { font-size: 16px; font-weight: 600; flex: 1; min-width: 0; }
/* Состав группы уезжает на свою строку: иначе список имён и кнопки
   делят одну строку, и от имён остаётся «Участники: Ад…» */
.staff-head__meta {
  order: 3; flex-basis: 100%;
  font-size: 13px; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.staff-head__actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

.staff-msg {
  max-width: min(62%, 620px);
  padding: 9px 13px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 14px; line-height: 1.45;
  white-space: pre-wrap; word-wrap: break-word;
  align-self: flex-start;
}
.staff-msg--mine { align-self: flex-end; background: #dcfce7; border-color: #bbf7d0; }
.staff-msg__author { font-size: 12px; font-weight: 600; color: #1e40af; margin-bottom: 3px; }
.staff-msg__time {
  margin-top: 4px; font-size: 11px; color: var(--ink-soft);
  text-align: right; font-variant-numeric: tabular-nums;
}
.staff-system {
  align-self: center; max-width: 80%; text-align: center;
  font-size: 12px; color: var(--ink-soft);
}

/* На широком экране список и переписка видны разом — кнопка не нужна */
.staff-head__back { display: none; }

@media (max-width: 860px) {
  .staff-head__actions { width: 100%; margin-left: 0; }
  .staff-head__back { display: inline-block; }
}


/* 2.2: читаемая таблица, управление столбцами и компактные экраны */
.topbar { height: auto; min-height: 56px; flex-wrap: wrap; gap: 10px 16px; padding-top: 10px; padding-bottom: 10px; }
.topbar__tools { flex-wrap: wrap; min-width: 0; }
.views { min-width: 0; }
.view-tab { white-space: nowrap; }
.deals-view { min-width: 0; }
.city-bar, .scope-tabs { overflow-x: auto; }
.scope-tab { white-space: nowrap; flex-shrink: 0; }
.deals-bar select { max-width: 230px; min-width: 125px; }
.deals-bar input, .deals-bar select, .deals-bar button { min-height: 36px; }
.table-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--line); color: var(--ink-soft); font-size: 12px; flex-shrink: 0; }
.table-tools button { padding: 4px 9px; font-size: 12px; }
.deals-scroll { scrollbar-gutter: stable; overscroll-behavior: contain; }
.deals-table th { background: #f0f4f8; padding: 10px; vertical-align: top; }
.column-title { display: block; width: 100%; border: 0; background: transparent; text-align: left; font: inherit; padding: 5px 0; cursor: pointer; }
.column-title:active { cursor: grabbing; }
.deals-table th[aria-sort="ascending"], .deals-table th[aria-sort="descending"] { background: #dce9ff; color: #163e84; }
.deals-table td { padding: 9px 10px; vertical-align: middle; }
.deals-table tbody tr:nth-child(even):not(.row-today):not(.row-overdue):not(.row-finished) td:not(.is-today):not(.is-overdue) { background: #fafbfd; }
.deals-table tbody tr:hover td { box-shadow: inset 0 0 0 999px rgba(37,99,235,.035); }
.deals-table .col-actions { background: #fff; min-width: 142px; }
.deals-table th.col-actions { background: #f0f4f8; }
.row-btn { min-height: 30px; }
.row-btn--icon { width: 30px; }
.utility-card { width: min(620px, 100%); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; gap: 14px; overflow: auto; }
.utility-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.utility-heading h2 { margin: 0; font-size: 19px; }
.utility-card > p { margin: 0; font-size: 13px; line-height: 1.5; }
.utility-card > .btn-plain { align-self: flex-start; }
.column-order-list, .link-results { overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 7px; }
.column-order-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line-soft); border-radius: 8px; background: #f8fafc; }
.column-order-row > span { flex: 1; font-size: 14px; }
.column-order-row button { width: 40px; min-height: 36px; padding: 4px; }
.utility-card button:disabled { opacity: .45; cursor: default; }
.link-search { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; }
.link-result { padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: #fff; text-align: left; display: flex; flex-direction: column; gap: 6px; cursor: pointer; overflow-wrap: anywhere; }
.link-result:not(:disabled):hover { border-color: var(--focus); background: #f5f8ff; }
.link-result .muted { font-size: 12px; }
.thread__head-right { flex-wrap: wrap; }
button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (max-width: 860px) {
  .topbar .views { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 3px; }
  .view-tab { flex: 0 0 auto; min-height: 40px; padding: 8px 12px; }
  .topbar__tools { gap: 6px; }
  #logout-btn { display: inline-block; }
  .app.is-deals .topbar__tools { justify-content: flex-end; }
  .app.is-deals .sync { display: none; }
  .deals-view { overflow-y: auto; display: block; }
  .deals-scroll { overflow: auto; max-height: 68dvh; min-height: 240px; }
  .deals-bar { gap: 7px; }
  .deals-bar > input[type="search"] { order: -1; min-width: 0; flex: 1 0 100%; width: 100%; }
  .deals-bar select { flex: 1 1 120px; min-width: 0; max-width: 100%; }
  .deals-bar--dates { align-items: center; }
  .deals-bar--dates .deals-stats { margin-left: 0; white-space: normal; flex-basis: 100%; line-height: 1.6; }
  .deals-bar input, .deals-bar select, .deals-bar button { min-height: 40px; }
  .table-tools { align-items: flex-start; flex-wrap: wrap; padding: 9px 10px; }
  .table-tools button { min-height: 36px; }
  .column-title { min-height: 40px; }
  .deals-table td { max-width: 250px; padding: 10px; }
  .row-btn { min-height: 36px; }
  .row-btn--icon { width: 36px; }
  .utility-modal { padding: 10px; }
  .utility-card { max-height: calc(100dvh - 20px); border-radius: 12px; gap: 12px; }
  .utility-heading h2 { font-size: 17px; }
  .utility-card button { min-height: 42px; }
  .link-search, .form-field input, .form-field select, .form-field textarea { font-size: 16px; }
  .thread__head { gap: 10px; flex-wrap: wrap; }
  .thread__head-right { gap: 6px; }
  .thread__head-right button { min-height: 38px; }
  .settings-inner { padding: 14px 10px 40px; }
  .settings-block { padding: 12px; overflow-x: auto; }
}

.mobile-only { display: none; }
@media (max-width: 860px) {
  .mobile-only { display: inline-block; }
  .deals-view:not(.mobile-filters-open) .deals-bar > select,
  .deals-view:not(.mobile-filters-open) .deals-bar--dates { display: none; }
  .deals-scroll { max-height: 74dvh; }
}

/* 2.2.1: безопасная область — часть всего приложения, в том числе без шапки в чате. */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}
html, body { height: 100%; height: 100dvh; overflow: hidden; }
.app { padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left); background: var(--navy); }
.login { height: 100%; overflow-y: auto; padding: calc(24px + var(--safe-top)) calc(24px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(24px + var(--safe-left)); }
.drawer { top: var(--safe-top); right: var(--safe-right); bottom: var(--safe-bottom); max-width: calc(100% - var(--safe-left) - var(--safe-right)); }
.modal, .utility-modal, .viewer {
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}
.modal__card, .utility-card { max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 32px); }
.toast { bottom: calc(24px + var(--safe-bottom)); }
