/* Оформление админки и виджета. Без внешних шрифтов и CDN:
   сервер за рубежом, клиенты в России — лишние внешние запросы
   означают долгую загрузку или пустые квадраты вместо шрифта. */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1b1f24;
  --muted: #6b7480;
  --line: #e3e6ea;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --ok: #1a7f37;
  --warn: #bf8700;
  --bad: #cf222e;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
button {
  font: inherit; cursor: pointer; border: 1px solid var(--line);
  background: #fff; color: var(--ink); padding: 7px 13px; border-radius: 8px;
}
button:hover { border-color: #c8ccd2; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #1a5fd0; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); width: 100%;
}
textarea { resize: vertical; font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
           font-size: 13px; line-height: 1.6; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 140px; }
.row > .narrow { flex: 0 0 auto; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
         padding: 16px; margin-bottom: 16px; }
.hidden { display: none !important; }

/* ------------------------------------------------------------ каркас */
.layout { display: flex; min-height: 100vh; }
.side { width: 210px; flex: 0 0 210px; background: #fff; border-right: 1px solid var(--line);
        padding: 16px 12px; }
.side .brand { font-weight: 600; padding: 0 8px 14px; }
.side .brand small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.side nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink);
              margin-bottom: 2px; }
.side nav a:hover { background: var(--bg); text-decoration: none; }
.side nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.side .foot { position: sticky; top: 100vh; padding: 10px 8px 0; font-size: 12px;
              color: var(--muted); }
.main { flex: 1; padding: 20px 24px; max-width: 1300px; }
.topbar { display: flex; justify-content: space-between; align-items: baseline;
          margin-bottom: 16px; gap: 16px; }

/* ------------------------------------------------------------ карточки KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
       padding: 14px; }
.kpi .v { font-size: 26px; font-weight: 600; line-height: 1.2; }
.kpi .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ------------------------------------------------------------ таблицы */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line);
         vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 500; white-space: nowrap; }
tbody tr:hover { background: #fafbfc; }
tr.clickable { cursor: pointer; }
.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted);
        margin-top: 4px; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------ бейджи */
.badge { display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: 11px;
         border: 1px solid var(--line); background: #fff; white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: #b6e0c0; background: #f0fbf3; }
.badge.warn { color: var(--warn); border-color: #eedfaa; background: #fdf8e9; }
.badge.bad { color: var(--bad); border-color: #f0c0c4; background: #fdf1f2; }
.badge.info { color: var(--accent); border-color: #bcd6fb; background: var(--accent-soft); }

/* ------------------------------------------------------------ графики */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; }
.bars .col { flex: 1; display: flex; flex-direction: column-reverse; min-width: 4px; }
.bars .seg { width: 100%; }
.seg.resolved { background: #7cc48c; }
.seg.escalated { background: #f0c674; }
.seg.dropped { background: #d8dce1; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px;
            margin-right: 5px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: 190px 1fr 90px; gap: 10px; align-items: center;
        margin-bottom: 6px; font-size: 13px; }
.hbar .track { background: var(--bg); border-radius: 4px; height: 18px; overflow: hidden;
               display: flex; }
.hbar .fill { background: #8fb8f0; height: 100%; }
.hbar .fill.esc { background: #f0c674; }
.heat td { padding: 0; border: none; }
.heat i { display: block; width: 100%; height: 18px; border-radius: 2px; }
.heat th { padding: 2px 4px; font-size: 10px; }
.funnel .step { display: grid; grid-template-columns: 170px 1fr 80px; gap: 10px;
                align-items: center; margin-bottom: 6px; }
.funnel .track { background: var(--bg); border-radius: 4px; height: 22px; }
.funnel .fill { background: #8fb8f0; height: 100%; border-radius: 4px; }

/* ------------------------------------------------------------ чат */
.chat { display: flex; flex-direction: column; height: 560px; background: #fff;
        border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.chat .log { flex: 1; overflow-y: auto; padding: 16px; }
.msg { max-width: 78%; width: fit-content; padding: 9px 13px; border-radius: 14px;
       margin-bottom: 10px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { background: var(--accent); color: #fff; margin-left: auto;
            border-bottom-right-radius: 4px; }
.msg.bot { background: var(--bg); border-bottom-left-radius: 4px; }
.msg.sys { background: #fdf8e9; border: 1px solid #eedfaa; color: #7a5b00; font-size: 12px;
           max-width: 100%; width: auto; text-align: center; border-radius: 8px; }
.msg .tools { display: block; margin-top: 6px; font-size: 11px; opacity: .7;
              font-family: ui-monospace, Consolas, monospace; }
.chat .bar { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat .bar input { flex: 1; }

/* ------------------------------------------------------------ модалка */
.overlay { position: fixed; inset: 0; background: rgba(20,24,30,.45); display: flex;
           justify-content: center; align-items: flex-start; padding: 40px 20px; z-index: 50;
           overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 860px; padding: 20px;
         box-shadow: 0 12px 40px rgba(0,0,0,.2); }
.modal .head { display: flex; justify-content: space-between; align-items: flex-start;
               margin-bottom: 14px; gap: 12px; }

/* ------------------------------------------------------------ переписка */
.transcript { max-height: 420px; overflow-y: auto; border: 1px solid var(--line);
              border-radius: 8px; padding: 12px; background: #fcfcfd; }
.tmsg { margin-bottom: 12px; }
.tmsg .who { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.tmsg .body { white-space: pre-wrap; }
.tmsg.tool .body { font-family: ui-monospace, Consolas, monospace; font-size: 11px;
                   color: var(--muted); background: #f4f5f7; padding: 6px 8px;
                   border-radius: 6px; max-height: 130px; overflow: auto; }
.tmsg .mark { font-size: 11px; margin-top: 3px; }

/* ------------------------------------------------------------ вход */
.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.login-box { width: 340px; background: #fff; border: 1px solid var(--line);
             border-radius: 12px; padding: 26px; }
.err { color: var(--bad); font-size: 13px; margin-top: 10px; min-height: 18px; }
.toast { position: fixed; right: 20px; bottom: 20px; background: #1b1f24; color: #fff;
         padding: 11px 16px; border-radius: 8px; font-size: 13px; z-index: 100;
         box-shadow: 0 6px 20px rgba(0,0,0,.25); }
