:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #16181d; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2f6fed; --accent-soft: #e8efff; --chip: #f1f3f6; --danger: #c0392b;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --panel: #171a21; --text: #e7e9ee; --muted: #9aa1ad; --line: #262a33;
    --accent: #6c9bff; --accent-soft: #1d2740; --chip: #20242d; --danger: #ff7b6b;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .small { font-size: 12px; }
button, select, input { font: inherit; color: inherit; }

/* вход */
.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 32px; width: 100%; max-width: 360px; text-align: center; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.widget { margin: 24px 0 12px; min-height: 48px; }
.err { color: var(--danger); }

/* шапка */
header { position: sticky; top: 0; z-index: 5; background: var(--panel);
  border-bottom: 1px solid var(--line); }
.bar { max-width: 1200px; margin: 0 auto; padding: 12px 16px; display: flex;
  align-items: center; gap: 12px; }
.bar h1 { font-size: 16px; margin: 0; flex: 1; }
.user { color: var(--muted); }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn[disabled] { opacity: .6; cursor: default; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* сводка */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px;
  margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow); }
.stat.active { border-color: var(--accent); background: var(--accent-soft); }
.stat b { display: block; font-size: 22px; }

/* фильтры */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 6px 12px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
.filters select, .filters input { border: 1px solid var(--line); background: var(--panel);
  border-radius: 8px; padding: 6px 10px; }
.filters input { flex: 1; min-width: 160px; }

/* таблица */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line);
  white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--accent-soft); }
tbody tr:last-child td { border-bottom: 0; }
.chip { display: inline-block; background: var(--chip); border-radius: 6px; padding: 1px 7px;
  margin: 1px 2px 1px 0; font-size: 12px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* карточка */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); z-index: 11;
  background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 20px; }
.drawer h2 { margin: 0 0 4px; font-size: 18px; }
.drawer h3 { font-size: 13px; color: var(--muted); margin: 20px 0 8px; text-transform: uppercase;
  letter-spacing: .03em; }
.drawer .close { float: right; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--muted); }
.partner { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.partner code { font-size: 12px; word-break: break-all; }
.warn { color: var(--danger); }

@media (max-width: 640px) {
  .bar h1 { font-size: 15px; }
  .user { display: none; }
  th.opt, td.opt { display: none; }
  .kv { grid-template-columns: 110px 1fr; }
}

/* иконки */
.ico { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; display: block;
  background: var(--chip); }
.ico.big { width: 64px; height: 64px; border-radius: 14px; }
td.ico-cell { width: 56px; padding-right: 0; }
.name-cell b { display: block; }

/* карточка v2 */
.card-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  background: var(--chip); }
.links { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 0; font-size: 13px; }
.section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.section h3 { margin: 0 0 10px; }
.check { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.check .st { width: 20px; text-align: center; }
.check .note { color: var(--muted); font-size: 12px; margin-left: auto; }
.idrow { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.idrow label { width: 100%; font-size: 12px; color: var(--muted); }
.idrow input { flex: 1; min-width: 200px; border: 1px solid var(--line); background: var(--bg);
  border-radius: 8px; padding: 7px 10px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.field { display: grid; grid-template-columns: 130px 1fr; gap: 8px; align-items: center;
  margin: 8px 0; }
.field > span { color: var(--muted); }
.field select, .field input[type=text] { border: 1px solid var(--line); background: var(--bg);
  border-radius: 8px; padding: 6px 10px; width: 100%; }
.toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.tg { border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 4px 10px; cursor: pointer; font-size: 12px; }
.tg.on { background: var(--accent-soft); border-color: var(--accent); }
.switch { position: relative; width: 42px; height: 24px; border-radius: 999px; background: var(--line);
  border: 0; cursor: pointer; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: left .15s; }
.switch.on { background: #2fb36a; }
.switch.on::after { left: 21px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 13px; }
.toast.err { background: var(--danger); color: #fff; }
details.raw { margin-top: 14px; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.raw pre { font-size: 11px; white-space: pre-wrap; word-break: break-all; background: var(--bg);
  border-radius: 8px; padding: 8px; }
@media (max-width: 640px) { .field { grid-template-columns: 1fr; } }

/* навигация */
.nav { display: flex; gap: 4px; flex: 1; align-items: center; }
.nav .brand { font-weight: 700; margin-right: 10px; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav a:hover { text-decoration: none; background: var(--chip); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger);
  color: #fff; font-size: 11px; line-height: 18px; text-align: center; margin-left: 4px; }

/* поддержка */
.sup { display: grid; grid-template-columns: 340px 1fr; gap: 12px; height: calc(100vh - 90px); }
.sup-list, .sup-chat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.sup-list .seg { margin: 10px; }
.tickets { overflow-y: auto; flex: 1; }
.tk { display: flex; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); cursor: pointer; }
.tk:hover { background: var(--chip); }
.tk.on { background: var(--accent-soft); }
.tk .ico { width: 36px; height: 36px; flex: none; }
.tk .body { min-width: 0; flex: 1; }
.tk .top { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); }
.tk .who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tk .prev { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tk.unread .who::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); margin-left: 6px; vertical-align: middle; }
.chat-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: center; }
.chat-head .grow { flex: 1; min-width: 0; }
.chat-head h2 { font-size: 15px; margin: 0; }
.chat-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.details { padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--bg); font-size: 13px; }
.details code { word-break: break-all; }
.msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 75%; padding: 8px 11px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { background: var(--chip); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.support { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.system { align-self: center; color: var(--muted); font-size: 12px; background: none; }
.msg .meta { font-size: 11px; opacity: .7; margin-top: 3px; }
.msg img { max-width: 260px; border-radius: 8px; display: block; margin-bottom: 4px; }
.composer { border-top: 1px solid var(--line); padding: 10px; }
.composer textarea { width: 100%; min-height: 64px; resize: vertical; border: 1px solid var(--line);
  background: var(--bg); border-radius: 10px; padding: 8px 10px; font: inherit; color: inherit; }
.composer .row { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; align-items: center; }
.composer .grow { flex: 1; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.placeholder { margin: auto; color: var(--muted); text-align: center; padding: 20px; }
.back-btn { display: none; }
@media (max-width: 760px) {
  .sup { grid-template-columns: 1fr; height: calc(100vh - 80px); }
  .sup.open .sup-list { display: none; }
  .sup:not(.open) .sup-chat { display: none; }
  .back-btn { display: inline-block; }
  .msg { max-width: 90%; }
}
