/* Baffle Линии. Рамка и лист, цвет только на данных: зелёный = линия живая, янтарь = ждём привязки, красный = клиент ждёт ответа или линия упала. */
@font-face { font-family: "Commissioner"; font-weight: 400 600; font-display: swap; src: url(/fonts/commissioner-cyrillic-ext.woff2) format("woff2"); unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; }
@font-face { font-family: "Commissioner"; font-weight: 400 600; font-display: swap; src: url(/fonts/commissioner-cyrillic.woff2) format("woff2"); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Commissioner"; font-weight: 400 600; font-display: swap; src: url(/fonts/commissioner-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD, U+20B8; }
:root {
  --font: "Commissioner", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ground: #eceee9;
  --sheet: #ffffff;
  --sunk: #f5f6f3;
  --ink: #16181b;
  --ink-2: #4f555c;
  --ink-3: #6b7178;
  --line: #e1e4de;
  --line-2: #d3d7d0;
  --live: #1d7f52;
  --live-bg: #e2f3e8;
  --live-tick: #2f9e68;
  --wait: #9a5404;
  --wait-bg: #fdf1dc;
  --bad: #b42b22;
  --bad-bg: #fde9e6;
  --off: #50565c;
  --off-bg: #eceeee;
  --out-bubble: #def2e4;
  --in-bubble: #ffffff;
  --thread-bg: #f4f5f1;
  --focus: #1d7f52;
  --btn: #16181b;
  --btn-ink: #ffffff;

  --t-xs: 12px; --t-s: 13px; --t-m: 14px; --t-l: 16px; --t-xl: 20px; --t-xxl: 24px;
  --r-ctl: 10px; --r-card: 12px; --r-sheet: 14px;
  --gap: 8px;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --side: 264px;
  --ava-l: 88%;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #111315; --sheet: #191c1f; --sunk: #202327; --ink: #eceeef; --ink-2: #b4b9be; --ink-3: #9aa0a6;
    --line: #2a2e33; --line-2: #353a40; --live: #5fd398; --live-bg: #16301f; --live-tick: #3fbf7f;
    --wait: #f0b45c; --wait-bg: #33260f; --bad: #ff8a7d; --bad-bg: #3a1916; --off: #b4b9be; --off-bg: #262a2e;
    --out-bubble: #1d3527; --in-bubble: #23272b; --thread-bg: #15181a; --focus: #5fd398; --btn: #eceeef; --btn-ink: #111315; --ava-l: 30%;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font: 400 var(--t-m)/20px var(--font); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
::selection { background: var(--live-bg); color: var(--ink); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-underline-offset: 3px; }
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
[hidden] { display: none !important; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 14px; border-radius: var(--r-ctl);
  border: 1px solid var(--line-2); background: var(--sheet); color: var(--ink);
  font-weight: 500; font-size: var(--t-m); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, transform .12s var(--ease-out);
}
.btn:hover { background: var(--sunk); }
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .5; cursor: default; transform: none; }
.btn.primary { background: var(--btn); color: var(--btn-ink); border-color: var(--btn); }
.btn.primary:hover { opacity: .9; background: var(--btn); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--sunk); }
.btn svg { width: 16px; height: 16px; flex: none; }
.icon-btn { width: 40px; min-height: 40px; padding: 0; }
.field { display: grid; gap: 6px; }
.field label { font-size: var(--t-s); font-weight: 500; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: var(--t-xs); line-height: 16px; }
.input, textarea.input {
  width: 100%; min-height: 40px; padding: 9px 12px; border-radius: var(--r-ctl);
  border: 1px solid var(--line-2); background: var(--sheet); font-size: 16px; line-height: 20px;
}
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--live-bg); }
.input::placeholder { color: var(--ink-3); }

/* ---------- статус ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: var(--t-xs); font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-connected { background: var(--live-bg); color: var(--live); }
.s-qr, .s-connecting { background: var(--wait-bg); color: var(--wait); }
.s-disconnected, .s-logged_out { background: var(--bad-bg); color: var(--bad); }
.s-new, .s-stopped { background: var(--off-bg); color: var(--off); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--off); }
.dot.s-connected { background: var(--live-tick); }
.dot.s-qr, .dot.s-connecting { background: var(--wait); }
.dot.s-disconnected, .dot.s-logged_out { background: var(--bad); }
.dot.s-connecting { animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; height: 100dvh; }
.side { display: flex; flex-direction: column; min-height: 0; padding: 12px 8px 12px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.brand b { font-size: var(--t-l); font-weight: 600; letter-spacing: -.01em; }
.brand span { display: block; font-size: var(--t-xs); color: var(--ink-3); line-height: 14px; }
.nav { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.nav a {
  display: grid; grid-template-columns: 8px 1fr auto; align-items: center; gap: 10px;
  min-height: 44px; padding: 6px 10px; border-radius: var(--r-ctl); text-decoration: none; color: var(--ink-2);
}
.nav a:hover { background: color-mix(in srgb, var(--sheet) 55%, transparent); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--sheet); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.nav a .nm { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a .ph { display: block; font-size: var(--t-xs); color: var(--ink-3); line-height: 15px; }
.nav .all { grid-template-columns: 1fr auto; }
.nav h3 { margin: 14px 10px 4px; font-size: var(--t-xs); font-weight: 500; color: var(--ink-3); }
.count { min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px; font-size: var(--t-xs); font-weight: 600; display: inline-grid; place-items: center; background: var(--bad); color: #fff; }
.side-foot { display: grid; gap: 8px; padding: 10px 4px 0; }
.who { display: flex; align-items: center; justify-content: space-between; font-size: var(--t-s); color: var(--ink-3); padding: 0 6px; }

.sheet {
  margin: 8px 8px 8px 0; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-sheet);
  min-height: 0; overflow: hidden; display: flex; flex-direction: column;
}
.top { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.top h1 { margin: 0; font-size: var(--t-xl); line-height: 26px; font-weight: 600; letter-spacing: -.01em; }
.top .sub { color: var(--ink-3); font-size: var(--t-s); }
.top .grow { flex: 1; }
.back { display: none; }
.tabs { display: flex; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { position: relative; padding: 12px 8px; text-decoration: none; color: var(--ink-3); font-weight: 500; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--ink); }
.tabs a[aria-current="page"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--ink); border-radius: 2px; }
.body { flex: 1; min-height: 0; overflow-y: auto; }
.pad { padding: 20px; }

/* ---------- обзор ---------- */
.summary { margin: 0; color: var(--ink-2); font-size: var(--t-l); line-height: 24px; max-width: 70ch; }
.summary b { color: var(--ink); font-weight: 600; }
.summary .bad { color: var(--bad); }
table.lines { width: 100%; border-collapse: collapse; margin-top: 16px; }
.lines th { text-align: left; font-size: var(--t-xs); font-weight: 500; color: var(--ink-3); padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.lines td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; height: 60px; }
.lines tr[data-href] { cursor: pointer; }
.lines tr[data-href]:hover td { background: var(--sunk); }
.lines .num { text-align: right; white-space: nowrap; }
.lines .nm { font-weight: 600; }
.lines .ph { color: var(--ink-3); font-size: var(--t-s); }
.muted { color: var(--ink-3); }
.waiting { color: var(--bad); font-weight: 600; }

/* пульс: входящие по часам за сутки */
.pulse { display: flex; align-items: flex-end; gap: 2px; height: 24px; width: 122px; }
.pulse i { flex: 1; min-height: 2px; border-radius: 1px; background: var(--line-2); }
.pulse i.on { background: var(--live-tick); }
.pulse.dead i.on { background: var(--ink-3); }
.pulse-cap { font-size: var(--t-xs); color: var(--ink-3); margin-top: 3px; }

.empty { display: grid; place-items: center; text-align: center; gap: 10px; padding: 64px 20px; color: var(--ink-3); }
.empty h2 { margin: 0; color: var(--ink); font-size: var(--t-l); font-weight: 600; }
.empty p { margin: 0; max-width: 46ch; }

/* ---------- чаты ---------- */
.inbox { display: grid; grid-template-columns: 340px 1fr; height: 100%; min-height: 0; }
.chatlist { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chat-tools { display: grid; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 2px; border-radius: var(--r-ctl); background: var(--sunk); }
.seg button { min-height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-3); font-weight: 500; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--sheet); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.chats { flex: 1; overflow-y: auto; }
.chat {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 4px 12px; align-items: center;
  padding: 10px 12px; text-decoration: none; border-bottom: 1px solid var(--line); min-height: 64px;
}
.chat:hover { background: var(--sunk); }
.chat[aria-current="page"] { background: var(--sunk); box-shadow: inset 2px 0 0 var(--ink); }
.ava { grid-row: span 2; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: var(--t-s); color: var(--ink); }
.chat .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat .w { font-size: var(--t-xs); color: var(--ink-3); text-align: right; white-space: nowrap; }
.chat .w.bad { color: var(--bad); font-weight: 600; }
.chat .p { color: var(--ink-3); font-size: var(--t-s); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat .p.unans { color: var(--ink-2); }
.chat .u { justify-self: end; }
.more { display: block; width: calc(100% - 24px); margin: 12px; }

.thread { display: flex; flex-direction: column; min-height: 0; background: var(--thread-bg); }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--sheet); border-bottom: 1px solid var(--line); min-height: 60px; }
.thread-head .t { font-weight: 600; }
.thread-head .ph { font-size: var(--t-s); color: var(--ink-3); }
.msgs { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; margin: 12px 0 6px; padding: 3px 10px; border-radius: 999px; background: var(--sheet); border: 1px solid var(--line); font-size: var(--t-xs); color: var(--ink-3); }
.msg { max-width: min(560px, 78%); padding: 7px 10px 5px; border-radius: 12px; background: var(--in-bubble); border: 1px solid var(--line); align-self: flex-start; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--out-bubble); border-color: transparent; }
.msg .tx { white-space: pre-wrap; }
.msg .meta { display: flex; justify-content: flex-end; gap: 6px; margin-top: 2px; font-size: 11px; line-height: 14px; color: var(--ink-3); }
.msg .by { color: var(--live); font-weight: 600; }
.msg.new { animation: msgin .22s var(--ease-out); }
@keyframes msgin { from { opacity: 0; transform: translateY(6px); } }
.msg img, .msg video { display: block; max-width: 100%; max-height: 360px; border-radius: 8px; margin-bottom: 4px; }
.msg audio { width: 260px; max-width: 100%; display: block; margin-bottom: 2px; }
.att { display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--sunk); text-decoration: none; font-weight: 500; margin-bottom: 4px; }
.loadmedia { border: 1px dashed var(--line-2); background: transparent; border-radius: 8px; padding: 8px 10px; cursor: pointer; color: var(--ink-2); margin-bottom: 4px; }
.compose { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: end; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--sheet); border-top: 1px solid var(--line); }
.compose textarea { resize: none; max-height: 160px; }
.compose .file-chip { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: var(--t-s); color: var(--ink-2); }
.compose-note { padding: 12px 16px; background: var(--sheet); border-top: 1px solid var(--line); color: var(--ink-3); font-size: var(--t-s); }

/* ---------- подключение ---------- */
.connect { display: grid; grid-template-columns: 1fr 340px; gap: 32px; align-items: start; max-width: 880px; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 14px; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 28px 1fr; gap: 12px; line-height: 22px; }
.steps li::before { content: counter(s); width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line-2); display: grid; place-items: center; font-size: var(--t-s); font-weight: 600; }
.steps b { font-weight: 600; }
.qrbox { position: relative; width: 340px; aspect-ratio: 1; border: 1px solid var(--line); border-radius: var(--r-card); display: grid; place-items: center; background: #fff; overflow: hidden; }
.qrbox img { width: 300px; height: 300px; image-rendering: pixelated; transition: opacity .2s; }
.qrbox .state { padding: 24px; text-align: center; color: #4f555c; display: grid; gap: 12px; justify-items: center; }
.qrbox .ok { color: #1d7f52; }
.qrbox .ok svg { width: 56px; height: 56px; }
.qrbox .ok svg path { stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw .5s .1s var(--ease-out) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.pair { font-size: 32px; line-height: 40px; letter-spacing: .08em; font-weight: 600; color: #16181b; }
.section { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--line); max-width: 880px; }
.section h2 { margin: 0 0 6px; font-size: var(--t-l); font-weight: 600; }
.section p { margin: 0 0 12px; color: var(--ink-2); max-width: 70ch; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.linkbox { display: flex; gap: 8px; }
.linkbox .input { font-size: var(--t-s); }
.events { list-style: none; margin: 0; padding: 0; font-size: var(--t-s); }
.events li { display: grid; grid-template-columns: 120px 1fr; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.events time { color: var(--ink-3); }
.form { display: grid; gap: 16px; max-width: 560px; }
.note-box { padding: 12px 14px; border-radius: var(--r-card); background: var(--sunk); color: var(--ink-2); font-size: var(--t-s); line-height: 20px; max-width: 70ch; }

/* ---------- вход ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-sheet); padding: 28px; display: grid; gap: 16px; }
.login h1 { margin: 0; font-size: var(--t-xl); font-weight: 600; }
.login .err { color: var(--bad); font-size: var(--t-s); min-height: 20px; margin: -4px 0; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; background: var(--ink); color: var(--sheet); padding: 10px 16px; border-radius: var(--r-ctl); font-weight: 500; transition: opacity .2s, transform .25s var(--ease-out); z-index: 10; max-width: calc(100vw - 32px); }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- планшет и телефон ---------- */
@media (max-width: 1100px) {
  .inbox { grid-template-columns: 300px 1fr; }
  .connect { grid-template-columns: 1fr; }
  .lines .hide-m { display: none; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .shell:not(.at-home) .side { display: none; }
  .shell.at-home .sheet { display: none; }
  .side { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); height: 100dvh; }
  .sheet { margin: 0; border: 0; border-radius: 0; height: 100dvh; }
  .back { display: inline-flex; }
  .top { padding: 8px 12px; min-height: 56px; gap: 8px; }
  .top h1 { font-size: var(--t-l); }
  .pad { padding: 16px; }
  .inbox { grid-template-columns: 1fr; }
  .shell.in-chat .top, .shell.in-chat .tabs { display: none; }
  .inbox.has-chat .chatlist { display: none; }
  .inbox:not(.has-chat) .thread { display: none; }
  .msgs { padding: 12px; }
  .msg { max-width: 86%; }
  .qrbox { width: 100%; max-width: 340px; }
  .qrbox img { width: 86%; height: auto; }
  .events li { grid-template-columns: 1fr; gap: 0; }
  table.lines thead { display: none; }
  table.lines, .lines tbody, .lines tr, .lines td { display: block; }
  .lines tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .lines td { padding: 0; border: 0; height: auto; }
  .lines .num { text-align: left; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
