/* CRM DDC: одна таблица стилей для компьютера и телефона (Т-11.2). */
:root {
  --ink: #1c2733;
  --muted: #66727f;
  --line: #dfe4ea;
  --bg: #f4f6f8;
  --card: #ffffff;
  --brand: #123b5e;
  --brand-2: #1f6fb2;
  --ok: #1d7a46;
  --warn: #9a6200;
  --warn-bg: #fff6e0;
  --bad: #b3261e;
  --bad-bg: #fdecea;
  --radius: 8px;
  --gap: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
code { background: #eef1f4; padding: 1px 4px; border-radius: 4px; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
td.num { text-align: right; white-space: nowrap; }
.overdue { color: var(--bad); font-weight: 600; }
.done { color: var(--muted); text-decoration: line-through; }
.tag { display: inline-block; padding: 0 6px; border-radius: 10px; background: var(--bad-bg); color: var(--bad); font-size: 12px; }
.pad { padding: 12px; }
[hidden] { display: none !important; }

/* Шапка */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--brand); color: #fff;
}
.top a { color: #dbe7f3; }
.top .brand { font-weight: 800; letter-spacing: .5px; color: #fff; font-size: 18px; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { padding: 6px 10px; border-radius: 6px; }
.top nav a.on, .top nav a:hover { background: rgba(255,255,255,.15); color: #fff; text-decoration: none; }
.top .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.top .btn { background: rgba(255,255,255,.15); color: #fff; }
.top .link { color: #dbe7f3; }

/* Раскладка страницы */
main.page { max-width: 1200px; margin: 0 auto; padding: var(--gap); }
main.wide { padding: var(--gap); }
main.narrow { max-width: 420px; margin: 40px auto; padding: var(--gap); }
main.narrow-wide { max-width: 860px; margin: 0 auto; padding: var(--gap); }
.bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--gap); align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: var(--gap); }
.side-col .card { padding: 12px; }

/* Кнопки */
.btn {
  white-space: nowrap;
  display: inline-block; border: 0; border-radius: 6px; padding: 8px 14px;
  background: var(--brand-2); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.secondary { background: #e7edf3; color: var(--brand); }
button.link { background: none; border: 0; padding: 0; color: var(--brand-2); cursor: pointer; font: inherit; }
form.inline { display: inline; }
.buttons { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.buttons.sticky { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; }

/* Сообщения */
.messages { margin-bottom: 12px; }
.msg { padding: 10px 12px; border-radius: 6px; margin: 0 0 8px; background: #e8f3ec; color: var(--ok); }
.msg.warning { background: var(--warn-bg); color: var(--warn); }
.msg.error { background: var(--bad-bg); color: var(--bad); }
.msg.info { background: #e8f0fb; color: var(--brand); }

/* Формы */
.form label, .form legend { font-weight: 600; font-size: 13px; color: #3c4854; }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea,
.filters input, .filters select, .stage-form select, .reply textarea, .note-form textarea,
main.narrow input:not([type=checkbox]) {
  width: 100%; padding: 7px 9px; border: 1px solid #c9d1da; border-radius: 6px;
  font: inherit; background: #fff; color: var(--ink);
}
.form textarea { resize: vertical; }
.form > div, .form .field { margin-bottom: 10px; }
.form .helptext, .form .help { display: block; color: var(--muted); font-size: 12px; }
.form ul.errorlist, ul.errorlist { list-style: none; padding: 0; margin: 2px 0; color: var(--bad); font-size: 13px; }
.form fieldset { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); margin: 0 0 12px; padding: 10px 14px; }
.deal-form fieldset { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 14px; }
.deal-form legend { padding: 0 6px; font-size: 14px; color: var(--brand); }
.form.compact > div { margin-bottom: 6px; }
.form.compact { margin-top: 8px; }
.form ul { list-style: none; padding: 0; margin: 4px 0; }
.form ul li label { font-weight: 400; }
.cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0 14px; margin-top: 12px; }
label.check { display: flex; gap: 6px; align-items: center; margin: 8px 0; font-weight: 600; }
details { margin-top: 8px; }
details summary { cursor: pointer; color: var(--brand-2); }
main.narrow label { display: block; margin-bottom: 10px; font-weight: 600; }
main.narrow .btn { width: 100%; margin-top: 6px; }
.qr { display: flex; justify-content: center; margin: 10px 0; }
.qr svg { width: 220px; height: 220px; }
.stage-form { display: flex; gap: 8px; align-items: center; }
.stage-form select { min-width: 200px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.filters > div { min-width: 160px; }
.filters label { display: block; font-size: 12px; color: var(--muted); }
.filters input[type=search] { max-width: 360px; }

/* Таблицы и списки */
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { background: #f0f3f6; font-size: 12px; color: var(--muted); font-weight: 600; }
table.list tr.attention td:first-child { box-shadow: inset 4px 0 0 var(--bad); }
table.mini { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0; }
table.mini td { padding: 3px 0; border-bottom: 1px dashed var(--line); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 5px 0; border-bottom: 1px dashed var(--line); }
ul.plain li:last-child { border-bottom: 0; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; }

/* Вкладки */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a { padding: 6px 10px; border-radius: 6px; background: #e7edf3; color: var(--brand); font-size: 14px; }
.tabs a.on { background: var(--brand); color: #fff; }
.tabs.small a { padding: 3px 8px; font-size: 12px; }

/* Доска воронки */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.column { flex: 0 0 270px; background: #e9edf1; border-radius: var(--radius); padding: 8px; max-height: calc(100vh - 170px); display: flex; flex-direction: column; }
.column.closed { opacity: .85; }
.column h3 { display: flex; justify-content: space-between; padding: 2px 4px 8px; }
.column .count { color: var(--muted); font-weight: 400; }
.cards { min-height: 60px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.deal-card {
  display: flex; flex-direction: column; gap: 2px; padding: 9px 10px; border-radius: 6px;
  background: var(--card); border: 1px solid var(--line); color: var(--ink); font-size: 13px; cursor: grab;
}
.deal-card:hover { text-decoration: none; border-color: var(--brand-2); }
.deal-card.attention { border-left: 4px solid var(--bad); }
.deal-card .num { color: var(--muted); font-size: 12px; }
.deal-card .meta { color: var(--muted); font-size: 12px; }
.sortable-ghost { opacity: .4; }
.sortable-chosen { box-shadow: 0 4px 14px rgba(0,0,0,.15); }

/* Переписка: список, диалог, клиент */
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; gap: 12px; height: calc(100vh - 90px); }
.inbox:not(.has-selected) { grid-template-columns: minmax(0, 520px); }
.conv-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.conv-list .tabs { padding: 8px; border-bottom: 1px solid var(--line); }
.convs { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.convs li a { display: flex; flex-direction: column; gap: 1px; padding: 9px 12px; border-bottom: 1px solid var(--line); color: var(--ink); }
.convs li a:hover { background: #f3f6f9; text-decoration: none; }
.convs li.on a { background: #e8f0fb; }
.convs li.unread strong::before { content: "● "; color: var(--brand-2); }
.convs .ch { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.convs .meta { font-size: 12px; color: var(--muted); }
.thread { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.thread-head { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.thread-head h2 { margin: 0; }
.thread-head p { margin: 2px 0 0; font-size: 13px; }
.thread .back { display: none; font-size: 13px; }
.messages-list { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; background: #f7f9fb; }
.bubble { max-width: 78%; padding: 8px 11px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); }
.bubble.out { align-self: flex-end; background: #e3effb; border-color: #c7dcf2; }
.bubble.note { align-self: center; background: var(--warn-bg); border-color: #f1dca6; max-width: 90%; }
.bubble .who { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.bubble .text { white-space: normal; word-break: break-word; }
.reply, .note-form { padding: 10px 14px; border-top: 1px solid var(--line); }
.note-form { display: flex; gap: 8px; align-items: flex-start; }
.note-form textarea { flex: 1; }
.client-panel { overflow-y: auto; }

/* Телефон и узкий экран */
@media (max-width: 1000px) {
  .grid { grid-template-columns: 1fr; }
  .inbox, .inbox:not(.has-selected) { grid-template-columns: 1fr; height: auto; }
  .inbox.has-selected .conv-list { display: none; }
  .inbox .thread { min-height: 70vh; }
  .thread .back { display: inline-block; margin-bottom: 4px; }
  .bubble { max-width: 92%; }
}
@media (max-width: 700px) {
  main.page, main.wide, main.narrow-wide { padding: 10px; }
  .top { gap: 8px; padding: 8px 10px; }
  .top nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .top nav a { white-space: nowrap; }
  .column { flex-basis: 82vw; max-height: none; }
  table.list { display: block; overflow-x: auto; white-space: nowrap; }
  .stage-form { width: 100%; }
  .stage-form select { min-width: 0; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dt { margin-top: 6px; }
}
