:root {
  --bg: #14161a; --panel: #1b1e24; --panel-2: #20242b; --line: #2a2f38; --text: #e6e8ec; --muted: #8b93a1;
  --green: #3fb950; --yellow: #d8a30a; --red: #e5534b; --blue: #4f8cc9; --accent: #6aa9ff;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 14px/1.5 -apple-system, "SF Pro Text", "Segoe UI", Roboto, Arial, sans-serif; }
/* !important обязателен: у .hidden и .modal одинаковый вес, без него display:flex ниже перебивает скрытие */
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
a { color: inherit; text-decoration: none; } a:hover { color: var(--accent); } a:visited { color: inherit; }
h2 { font-size: 13px; font-weight: 600; margin: 24px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

header { position: sticky; top: 0; z-index: 5; background: var(--panel); border-bottom: 1px solid var(--line);
         padding: 8px 20px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.brand { font-size: 15px; font-weight: 600; }
nav button, .seg button, .ghost {
  background: none; border: 1px solid transparent; color: var(--muted); padding: 5px 11px; border-radius: 6px;
  font: inherit; cursor: pointer; white-space: nowrap;
}
nav button:hover, .seg button:hover, .ghost:hover { color: var(--text); background: #262b34; }
nav button.active { color: var(--text); background: #2b3140; }
.controls { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; background: #191c22; border: 1px solid var(--line); border-radius: 7px; padding: 2px; gap: 2px; }
.seg button { padding: 4px 10px; border-radius: 5px; font-size: 13px; }
.seg button.on { color: var(--text); background: #2f3644; }
.custom-range { display: flex; align-items: center; gap: 6px; }
select, input[type=search], input[type=date] {
  background: #191c22; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; font: inherit;
}
input[type=search] { min-width: 280px; }
input[type=search]:focus, select:focus, input[type=date]:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.ghost { border-color: var(--line); font-size: 13px; }
main { padding: 4px 20px 60px; max-width: 1500px; }

/* Карточки-счётчики: компактные и кликабельные — клик включает соответствующий фильтр */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; margin-top: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; text-align: left; color: inherit; font: inherit; }
button.card { cursor: pointer; }
button.card:hover { border-color: #3d4553; background: var(--panel-2); }
button.card.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card .label { color: var(--muted); font-size: 11px; line-height: 1.3; }
.card .value { font-size: 19px; font-weight: 600; margin-top: 1px; letter-spacing: -.3px; line-height: 1.2; }
.card .hint { color: var(--muted); font-size: 10px; margin-top: 1px; line-height: 1.2; }
.v-green { color: var(--green); } .v-yellow { color: var(--yellow); } .v-red { color: var(--red); }

/* Панель фильтров */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-top: 14px; padding: 10px 12px;
           background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.group { display: inline-flex; align-items: center; gap: 8px; }
.group-label { color: var(--muted); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font: inherit; font-size: 12px;
        background: #22262f; color: var(--muted); border: 1px solid var(--line); border-radius: 20px; padding: 3px 10px; }
.chip:hover { color: var(--text); border-color: #3d4553; }
.chip.on { background: #2f3644; color: var(--text); border-color: #4a5468; }
.chip.flag { background: #2a1c1c; color: #e5867f; border-color: #4a2b2b; }
.chip.flag:hover { color: #f3a49d; border-color: #6b3a3a; }
.chip.flag.on { background: var(--red); color: #fff; border-color: var(--red); }
.chip-n { font-variant-numeric: tabular-nums; opacity: .75; font-weight: 600; }

/* Чаты */
.chat-list { display: flex; flex-direction: column; gap: 8px; }
.chat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 11px 14px; border-left: 3px solid #3a4150; }
.chat.good { border-left-color: var(--green); } .chat.mid { border-left-color: var(--yellow); } .chat.bad { border-left-color: var(--red); }
.chat-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.chat-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.chat-item { font-weight: 600; }
.chat-customer { color: var(--muted); }
.score { font-weight: 700; font-variant-numeric: tabular-nums; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--line); color: var(--muted); }
.badge.flag { color: var(--red); border-color: #4a2b2b; background: #2a1c1c; }
.badge.wait { color: var(--blue); border-color: #26364a; background: #1a222c; }
.badge.deal { color: var(--green); border-color: #24512f; background: #16341f; }
.chat p { margin: 7px 0 0; }
.chat .tip { color: #cfd6e4; border-left: 2px solid #3a4150; padding-left: 10px; }
.chat .tip b { color: var(--muted); font-weight: 600; }
.chat .actions { margin-top: 8px; display: flex; gap: 14px; }
.chat .actions a, .chat button.link { color: var(--accent); font-size: 13px; }
.chat button.link { background: none; border: 0; cursor: pointer; font: inherit; padding: 0; }
.chat button.link:hover, .chat .actions a:hover { text-decoration: underline; }
mark { background: #4a3d10; color: inherit; border-radius: 2px; padding: 0 1px; }

/* Переписка — пузыри в модальном окне: клиент слева, менеджер справа, системные по центру */
.msg-row { display: flex; margin-bottom: 8px; }
.msg-row.client { justify-content: flex-start; } .msg-row.manager { justify-content: flex-end; } .msg-row.system { justify-content: center; }
.bubble { max-width: 74%; border-radius: 12px; padding: 8px 12px; border: 1px solid transparent; }
.msg-row.client .bubble  { background: #1d2b3a; border-color: #274156; border-bottom-left-radius: 4px; }
.msg-row.manager .bubble { background: #1e2f26; border-color: #2b4a37; border-bottom-right-radius: 4px; }
.msg-row.system .bubble  { background: #202329; border-color: var(--line); max-width: 88%; text-align: center; }
.bubble.auto { background: #26252c; border-color: #3a3547; }
.bubble .meta { display: flex; gap: 8px; align-items: baseline; font-size: 11px; margin-bottom: 3px; }
.bubble .who { font-weight: 600; }
.msg-row.client .bubble .who { color: #79b8ff; } .msg-row.manager .bubble .who { color: #6fd18a; } .msg-row.system .bubble .who { color: var(--muted); }
.bubble .time { color: var(--muted); font-variant-numeric: tabular-nums; }
.bubble .auto-tag { color: #b08cff; border: 1px solid #3a3547; border-radius: 10px; padding: 0 6px; font-size: 10px; }
.bubble .text { white-space: pre-wrap; word-break: break-word; }

/* Таблицы */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; user-select: none; }
th.sortable { cursor: pointer; } th.sortable:hover { color: var(--text); }
th.sorted::after { content: " ▾"; color: var(--accent); } th.sorted.asc::after { content: " ▴"; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--panel-2); }
table.resizable { table-layout: fixed; } table.resizable th { position: relative; }
table.resizable td { overflow: hidden; text-overflow: ellipsis; }
.col-grip { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; user-select: none; }
.col-grip:hover { background: var(--accent); opacity: .5; }
.items-table td { vertical-align: middle; }
.items-table td.price { color: var(--muted); white-space: nowrap; }
.items-table td:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini { position: relative; height: 20px; min-width: 110px; background: #22262f; border-radius: 4px; overflow: hidden; }
.mini-bar { position: absolute; inset: 0 auto 0 0; background: #3a4a63; border-radius: 4px; }
.mini-bar.conv { background: #2f5d3f; }
.mini-val { position: relative; display: block; text-align: right; padding: 0 8px; line-height: 20px; font-size: 12px; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; min-width: 52px; text-align: center; padding: 2px 8px; border-radius: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pill.p-green { background: #16341f; color: #6fd18a; border: 1px solid #24512f; }
.pill.p-yellow { background: #33280d; color: #e0b341; border: 1px solid #4d3c13; }
.pill.p-red { background: #35191a; color: #f08a84; border: 1px solid #522527; }

/* Графики */
.chart { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart circle, .chart rect.bar { cursor: crosshair; }
.chart circle:hover { r: 5; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } input[type=search] { min-width: 0; width: 100%; } }
.bar-row { display: grid; grid-template-columns: 190px 1fr 46px; align-items: center; gap: 10px; margin-bottom: 6px; }
.bar-track { background: #22262f; border-radius: 4px; height: 16px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; }
.heat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; }
.heat table { width: auto; } .heat td, .heat th { padding: 3px 6px; border: 0; text-align: center; font-variant-numeric: tabular-nums; }
.heat td.cell { border-radius: 3px; min-width: 34px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 30px; z-index: 10; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px 22px; max-width: 900px; max-height: 84vh; overflow: auto; position: relative; width: 100%; }
.modal-box h3 { margin: 0 40px 12px 0; font-size: 15px; }
#modal-close { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
#modal-close:hover { color: var(--text); background: #2b3140; }
.empty { color: var(--muted); padding: 20px 0; }

/* Логи сервисов */
.toolbar .chips { margin-top: 0; }
.chip.warn { border-color: #5a4318; }
.chip-n.warn { color: var(--yellow); opacity: 1; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; cursor: pointer; user-select: none; }
.log-list { background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
            font: 12.5px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.log-row { display: grid; grid-template-columns: 118px 74px 76px 1fr; gap: 10px; padding: 4px 12px; border-bottom: 1px solid var(--line); align-items: start; }
.log-row:last-child { border-bottom: 0; }
.log-time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.log-svc { color: var(--muted); }
.log-level { font-weight: 600; }
.lvl-debug .log-level { color: var(--muted); } .lvl-info .log-level { color: #79b8ff; }
.lvl-warning .log-level { color: var(--yellow); } .lvl-error .log-level { color: var(--red); }
.lvl-warning { background: #1f1b12; } .lvl-error { background: #2a1717; }
.log-msg { white-space: pre-wrap; word-break: break-word; }
.log-msg .more { color: var(--accent); background: none; border: 0; cursor: pointer; font: inherit; padding: 0; }
.log-msg .more:hover { text-decoration: underline; }
.log-rest { margin: 4px 0 0; padding: 8px 10px; background: #111317; border-radius: 6px; white-space: pre-wrap; color: #cfd6e4; font: inherit; }
@media (max-width: 900px) { .log-row { grid-template-columns: 74px 1fr; } .log-svc, .log-level { display: none; } }

/* Вход: экран поверх всего, пока нет сессии */
.login { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 20px; }
.login-box { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
             padding: 26px 28px 24px; display: flex; flex-direction: column; gap: 12px; }
.login-box .brand { font-size: 18px; }
.login-box p { margin: -6px 0 4px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.field input, .field select { color: var(--text); background: #191c22; border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; font: inherit; width: 100%; }
.field input:focus, .field select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.field input:disabled, .field select:disabled { opacity: .6; }
.field-hint { font-size: 11px; color: var(--muted); }
.primary { background: var(--accent); color: #0e1117; border: 0; border-radius: 6px; padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.primary:hover { filter: brightness(1.1); } .primary:disabled { opacity: .6; cursor: default; }
.form-error { color: var(--red); font-size: 13px; }
.form { display: flex; flex-direction: column; gap: 12px; max-width: 440px; }
.form p { margin: 0; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.ghost.small { padding: 3px 8px; font-size: 12px; align-self: flex-start; }
.pw-once { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: #111317; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 8px 0 14px; }
.pw-once code { font: 15px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .5px; user-select: all; }

/* Учётная запись в шапке */
.user-menu { position: relative; }
.user-btn { color: var(--text); }
.pop { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--panel-2); border: 1px solid var(--line);
       border-radius: 8px; padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 6; }
.pop-head { padding: 6px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.pop-item { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 7px 10px; border-radius: 6px; font: inherit; cursor: pointer; }
.pop-item:hover { background: #2b3140; }
body:not(.is-admin) .admin-only { display: none !important; }

/* Пользователи */
.badge.ok { color: var(--green); border-color: #24512f; background: #16341f; }
.badge.off { color: var(--muted); background: #22262f; text-decoration: line-through; }
.badge.role-admin { color: #e0b341; border-color: #4d3c13; background: #33280d; }
.row-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.row-actions .link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; }
.row-actions .link:hover { text-decoration: underline; }
.row-actions .link.danger { color: #e5867f; }
.users-table td { vertical-align: middle; }

/* Вкладка «Звонки» (calls.js) */
.subtabs { margin-top: 12px; }
.calls-view { margin-top: 4px; }
.badge.dir { color: #a5b0c2; }
.badge.sig { color: #79b8ff; border-color: #26364a; background: #1a222c; }
.badge.risk-high { color: #f08a84; border-color: #522527; background: #35191a; }
.badge.risk-medium { color: #e0b341; border-color: #4d3c13; background: #33280d; }
.badge.risk-low { color: var(--muted); }
.pill.p-risk-high { background: #35191a; color: #f08a84; border: 1px solid #522527; }
.pill.p-risk-medium { background: #33280d; color: #e0b341; border: 1px solid #4d3c13; }
.pill.p-risk-low { background: #22262f; color: var(--muted); border: 1px solid var(--line); }
.chat .tip.praise { border-left-color: #2b4a37; }
.audio { display: block; width: 100%; margin: 8px 0 4px; }
.review-head { margin: 6px 0 10px; }
.modal-box h4 { margin: 16px 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.crit-table td { padding: 5px 8px; vertical-align: top; }
.crit-table td.comment { color: #cfd6e4; }
.crit-table td:first-child { white-space: nowrap; color: var(--muted); }
ul.flags, ul.tips { margin: 0; padding-left: 18px; }
ul.tips li { margin-bottom: 8px; }
ul.tips .better { color: #cfd6e4; border-left: 2px solid #2b4a37; padding-left: 10px; margin-top: 3px; }
.dialog { margin-top: 6px; }
.msg-row.mono { justify-content: flex-start; }
.msg-row.mono .bubble { background: #202329; border-color: var(--line); max-width: 88%; }
.msg-row.mono .bubble .who { color: var(--muted); }
.topics .bar-row { width: 100%; background: none; border: 1px solid transparent; color: inherit; font: inherit; cursor: pointer; text-align: left; border-radius: 6px; padding: 2px 4px; }
.topics .bar-row:hover { border-color: var(--line); background: var(--panel-2); }
.topics .bar-row.on { border-color: var(--accent); }
select.small { padding: 2px 6px; font-size: 12px; }
dl.inc { display: grid; grid-template-columns: 200px 1fr; gap: 6px 14px; margin: 10px 0; }
dl.inc dt { color: var(--muted); font-size: 12px; padding-top: 2px; }
dl.inc dd { margin: 0; white-space: pre-wrap; }
dl.inc ul { margin: 0; padding-left: 18px; }
@media (max-width: 900px) { dl.inc { grid-template-columns: 1fr; } }

/* Цепочка звонков одного клиента за день (вкладка «Звонки») */
.chat.chain { border-left-style: double; border-left-width: 5px; }
.badge.chain-n { color: var(--accent); border-color: #33507a; }
.chain-call { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; padding: 7px 0 0 12px; margin-top: 7px; border-top: 1px solid var(--line); }
.chain-call .sum { flex-basis: 100%; color: var(--muted); margin: 2px 0 0; }
.chain-call audio { flex-basis: 100%; margin-top: 6px; }
.chain-nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.chain-nav .link.on { color: var(--text); font-weight: 600; text-decoration: none; cursor: default; }

/* Карточка конфликта: все конфликтные звонки одного клиента плюс вся история его звонков */
.chat.incident { border-left-width: 5px; }
.chat.risk-left-high { border-left-color: var(--red); }
.chat.risk-left-medium { border-left-color: var(--yellow); }
.chat.risk-left-low { border-left-color: var(--blue); }
.inc-call { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; padding: 7px 0 0 12px; margin-top: 7px; border-top: 1px solid var(--line); }
.inc-call.is-inc { border-top: none; border-left: 2px solid var(--red); padding: 7px 0 7px 10px; margin-top: 8px; background: #241c1c; border-radius: 4px; }
.inc-call .sum { flex-basis: 100%; color: var(--muted); margin: 2px 0 0; }
.inc-call audio { flex-basis: 100%; margin-top: 6px; }

/* Настройки → Промпты (prompts.js) */
.prompt-info p { margin: 4px 0; }
.prompt-effect { color: #cfd6e4; border-left: 2px solid var(--accent); padding-left: 10px; }
.prompt-text { display: block; width: 100%; height: 62vh; min-height: 320px; margin-top: 10px; resize: vertical;
               background: #111317; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
               font: 12.5px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace; tab-size: 2; }
.prompt-text:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.prompt-text[readonly] { color: #cfd6e4; }
.prompt-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.prompt-bar input[type=text] { flex: 1 1 260px; background: #191c22; color: var(--text); border: 1px solid var(--line);
                               border-radius: 6px; padding: 6px 9px; font: inherit; }
.prompt-bar input[type=text]:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.prompt-bar .dirty { color: var(--yellow); }
.ghost:disabled { opacity: .45; cursor: default; background: none; color: var(--muted); }
.prompt-bar .primary:disabled { opacity: .3; }
#p-error { margin-top: 6px; }
.prompt-versions td { vertical-align: middle; }
.prompt-versions th:nth-child(1) { width: 120px; } .prompt-versions th:nth-child(2) { width: 130px; }
.prompt-versions th:nth-child(3) { width: 90px; } .prompt-versions th:nth-child(5) { width: 120px; }
.prompt-versions th:nth-child(6) { width: 80px; } .prompt-versions th:nth-child(7) { width: 240px; }
.prompt-versions td:nth-child(4) { white-space: normal; }
.prompt-view { white-space: pre-wrap; word-break: break-word; margin: 10px 0 0; padding: 10px 12px; background: #111317;
               border: 1px solid var(--line); border-radius: 8px; font: 12.5px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.diff { background: #111317; border: 1px solid var(--line); border-radius: 8px; padding: 6px 0; overflow-x: auto;
        font: 12px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.diff > div { white-space: pre-wrap; word-break: break-word; padding: 0 12px; }
.diff .same { color: var(--muted); }
.diff .add { background: #15291c; color: #a6e3b4; }
.diff .del { background: #2e1818; color: #f1a39d; }
.diff .add mark { background: #2b6a40; color: #eafff0; }
.diff .del mark { background: #7a2e2e; color: #fff0ef; }
.diff .gap { color: var(--muted); text-align: center; padding: 3px 12px; font-family: inherit; }
