:root {
  --bg: #f6f3ef; --card: #ffffff; --ink: #231f1b; --muted: #766c62; --line: #e4ddd4;
  --brand: #5b4636; --brand-2: #8a5a3c; --accent: #c8772e;
  --good: #1f8a4c; --good-bg: #e3f4ea; --warn: #b7791f; --warn-bg: #fdf1d8; --bad: #c0392b; --bad-bg: #fbe4e1;
  --info: #2f6f9f; --info-bg: #e2eef7; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1815; --card: #26221e; --ink: #f1ebe4; --muted: #a3978a; --line: #3a342e;
    --brand: #d9b99b; --brand-2: #e0a46f; --accent: #e0a46f;
    --good: #5fd18e; --good-bg: #1e3a2a; --warn: #f0b95a; --warn-bg: #3d3018; --bad: #ff8a7a; --bad-bg: #432522;
    --info: #7fb8e6; --info-bg: #1f3445;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand-2); text-decoration: none; } a:hover { text-decoration: underline; }
header.top { background: var(--brand); color: #fff; display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 52px; position: sticky; top: 0; z-index: 10; }
@media (prefers-color-scheme: dark) { header.top { background: #2d2620; color: #f1ebe4; border-bottom: 1px solid var(--line); } }
header.top .logo { font-weight: 700; letter-spacing: .02em; }
header.top nav { display: flex; gap: 4px; flex: 1; }
header.top nav a { color: inherit; opacity: .8; padding: 6px 12px; border-radius: 8px; }
header.top nav a:hover, header.top nav a.on { opacity: 1; background: rgba(255,255,255,.14); text-decoration: none; }
header.top .who { font-size: 13px; opacity: .9; display: flex; gap: 12px; align-items: center; }
header.top .who a { color: inherit; opacity: .8; }
main { max-width: 1480px; margin: 0 auto; padding: 18px 20px 60px; }
h1 { font-size: 20px; margin: 4px 0 14px; } h2 { font-size: 15px; margin: 0 0 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.bar label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 7px 14px; border-radius: 8px; cursor: pointer; }
button:hover, .btn:hover { border-color: var(--brand-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
button.small { padding: 3px 9px; font-size: 12px; }
.spacer { flex: 1; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 26px; font-weight: 700; } .kpi .l { color: var(--muted); font-size: 12px; }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.good { background: var(--good-bg); color: var(--good); } .chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); } .chip.info { background: var(--info-bg); color: var(--info); }
.chip.muted { background: var(--line); color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 12px; }
.sum { max-width: 420px; } .err { color: var(--bad); font-size: 13px; max-width: 360px; }
audio { height: 32px; width: 220px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--warn-bg); color: var(--warn); }
.login { max-width: 360px; margin: 12vh auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } header.top { flex-wrap: wrap; height: auto; padding: 8px 14px; gap: 8px; } }
.result { padding: 9px 10px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 6px; }
.result:hover, .result.on { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.tl { display: flex; flex-direction: column; gap: 8px; }
.ev { border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; background: var(--card); }
.ev.call { border-left: 4px solid var(--accent); } .ev.wa-in { border-left: 4px solid var(--info); } .ev.wa-out { border-left: 4px solid var(--good); }
.ev .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.ev .txt { white-space: pre-wrap; word-break: break-word; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
dl.facts dt { color: var(--muted); } dl.facts dd { margin: 0; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button.on { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }

.ev .err { max-width: none; }
a[href^="tel:"], td a[href^="/client?phone"] { white-space: nowrap; }

/* Talk Time: выполнение дневного плана */
.plan { height: 8px; min-width: 120px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.plan-fill { height: 100%; border-radius: 999px; }
.plan-fill.good { background: var(--good); } .plan-fill.warn { background: var(--warn); } .plan-fill.bad { background: var(--bad); }
.kpi .sub { font-size: 12px; margin-top: 4px; }
.ext { display: inline-block; font-size: 11px; padding: 0 6px; margin-right: 3px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kpi.main .v { color: var(--brand-2); }

/* Виджет «Сегодня в разговоре» в шапке */
.today-w { background: rgba(255,255,255,.14); padding: 4px 10px; border-radius: 999px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.today-w .sep { opacity: .5; margin: 0 2px; }
.today-w b.lvl-bad { color: #ffb4a8; } .today-w b.lvl-warn { color: #ffd98a; } .today-w b.lvl-good { color: #a8f0c4; }

/* Быстрые фильтры-чипсы */
.fchips { display: flex; flex-wrap: wrap; gap: 6px; }
.fchip { font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; white-space: nowrap; }
.fchip:hover { border-color: var(--brand-2); }
.fchip.on { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.fchip .n { opacity: .75; margin-left: 2px; font-variant-numeric: tabular-nums; }
.fchip.nodata { opacity: .6; }

/* Комбинированная карточка «Почему звонить и что предложить» */
.card3 { display: flex; flex-direction: column; gap: 3px; }
.card3 .ln { padding-left: 22px; position: relative; }
.card3 .ln::before { position: absolute; left: 0; top: 0; }
.card3 .b::before { content: "🔴"; } .card3 .m::before { content: "🟡"; } .card3 .c::before { content: "🟢"; }
.card3 .b { color: var(--bad); font-weight: 600; } .card3 .lbl { color: var(--muted); font-size: 12px; margin-right: 4px; }
.leak { background: var(--bad-bg); color: var(--bad); }

/* Действия по карточке */
.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; min-width: 230px; }
.acts button { padding: 4px 8px; font-size: 12px; text-align: left; white-space: nowrap; }
tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--bad); }

/* Модальное окно */
.modal-wrap { position: fixed; inset: 0; background: rgba(20,16,12,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 8vh 16px 16px; overflow-y: auto; }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 12px; width: min(520px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head, .modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; }
.modal-head { border-bottom: 1px solid var(--line); } .modal-foot { border-top: 1px solid var(--line); }
.modal-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-body label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.modal-body label.opt { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.modal-body label.opt:has(input:checked) { border-color: var(--brand-2); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.modal-body [data-form], .modal-body [data-ref] { display: flex; flex-direction: column; gap: 12px; }
.modal-body [data-ref][hidden], .modal-body [hidden] { display: none; }
.modal-body .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
button.x { border: none; background: none; font-size: 16px; padding: 2px 6px; margin-left: auto; color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* Выезжающая панель досье */
.drawer-wrap { position: fixed; inset: 0; background: rgba(20,16,12,0); z-index: 40; transition: background .2s; }
.drawer-wrap.open { background: rgba(20,16,12,.35); }
.drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(920px, 96vw); background: var(--bg); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .22s ease-out; display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(0,0,0,.18); }
.drawer-wrap.open .drawer { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.drawer-head button.x { margin-left: 0; }
.drawer-body { overflow-y: auto; padding: 14px 16px 40px; }
@media (max-width: 700px) { .acts { grid-template-columns: 1fr; min-width: 0; } .modal-body [data-form], .modal-body [data-ref] { display: flex; flex-direction: column; gap: 12px; }
.modal-body [data-ref][hidden], .modal-body [hidden] { display: none; }
.modal-body .row2 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- Проекты (сделки) */
.modal.wide { width: min(760px, 100%); }
.modal.wide .modal-body > .card { margin-bottom: 0; }
.kan { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.kcol { background: color-mix(in srgb, var(--line) 35%, transparent); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.kcol h3 { font-size: 13px; margin: 0 0 2px; } .kcol .ksum { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.kcol.win h3 { color: var(--good); }
.kcard { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; cursor: pointer; }
.kcard:hover { border-color: var(--brand-2); }
.kcard.stale { border-left: 3px solid var(--bad); } .kcard.due { border-left: 3px solid var(--warn); }
.kcard .t { font-weight: 600; } .kcard .s { font-size: 12px; color: var(--muted); margin-top: 3px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
tr.pj-row { cursor: pointer; } tr.pj-row:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.kpi .v.lvl-warn { color: var(--warn); } .kpi .v.lvl-bad { color: var(--bad); }
.pick-list { display: flex; flex-direction: column; max-height: 260px; overflow-y: auto; }
.pick-list .result:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.pick-sel { border: 1px solid var(--brand-2); border-radius: 8px; padding: 8px 10px; background: color-mix(in srgb, var(--accent) 6%, transparent); }
.kcard[draggable="true"] { cursor: grab; } .kcard.dragging { opacity: .45; }
.kcol.over { border-color: var(--brand-2); background: color-mix(in srgb, var(--accent) 12%, transparent); }
#sg-t select { width: 100%; font-size: 13px; padding: 4px 6px; }

/* ---------------------------------------------------------------- WhatsApp: «Входящие» (19.10.2026) */
.nbadge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.nbadge[hidden] { display: none; }
.ibox { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .ibox { grid-template-columns: 1fr; } }
.ilist { max-height: calc(100vh - 250px); overflow-y: auto; padding: 0; }
.ith { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ith:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.ith.on { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.ith.un { box-shadow: inset 3px 0 0 var(--bad); }
.ith .t { display: flex; gap: 6px; align-items: baseline; } .ith .t b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ith .p { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.chat { display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 400px); min-height: 200px; overflow-y: auto; padding: 4px 2px 10px; }
.msg { max-width: 78%; padding: 7px 11px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.msg.in { align-self: flex-start; border-bottom-left-radius: 3px; }
.msg.out { align-self: flex-end; border-bottom-right-radius: 3px; background: color-mix(in srgb, var(--good) 10%, var(--card)); }
.msg.call { align-self: center; max-width: 92%; font-size: 12px; color: var(--muted); background: transparent; border-style: dashed; }
.msg .txt { white-space: pre-wrap; word-break: break-word; } .msg .m { font-size: 11px; color: var(--muted); margin-top: 3px; }
.reply { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 6px; }
.reply .bar select { max-width: 260px; }
