/* Раздел «Поддержка» (#/support): чаты | переписка | клиент.
 * Цвета и элементы — из app.css (фиолетовый акцент админки, карточки, кнопки, чипы).
 * ≥1280px — три колонки; 900–1279px — две, сведения о клиенте выезжают поверх справа;
 * <900px — чаты и переписка отдельными экранами (data-view), сведения — поверх. */
body.route-support .main { padding-bottom: 16px; }
@media (min-width: 768px) { body.route-support .main { padding-top: 20px; padding-bottom: 20px; } }
body.route-support .main-in { max-width: 1480px; }

.spx {
  position: relative; display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px;
  height: calc(100dvh - 120px); min-height: 520px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden;
}
.spx .hidden { display: none !important; }
/* пока чат не выбран — без колонки клиента */
.spx:not(.has-dialog) { grid-template-columns: 320px minmax(0, 1fr); }
.spx:not(.has-dialog) .spx-info { display: none; }
.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ── Чаты ─────────────────────────────────────────────────────────────── */
.spx-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.spx-list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 14px 10px 18px; }
.spx-list-head .page-title { font-size: 22px; }
.spx-search { display: flex; align-items: center; gap: 8px; margin: 0 14px 10px; padding: 0 12px; height: 38px; border-radius: var(--radius); background: var(--input); color: var(--muted); border: 1px solid transparent; }
.spx-search:focus-within { border-color: var(--accent-border); box-shadow: 0 0 0 3px var(--ring); }
.spx-search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: none; color: var(--foreground); font: inherit; font-size: 14px; }
#sp-tabs { padding: 0 14px 10px; }
#sp-tabs .seg { width: 100%; }
#sp-tabs .seg-btn { flex: 1; }
.spx-conn { display: flex; align-items: center; gap: 8px; margin: 0 14px 8px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--warning-bg); color: var(--warning-fg); font-size: 13px; }
.spx-rows { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 10px; }
.spx-row {
  display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 10px; align-items: center;
  padding: 10px; border-radius: var(--radius); color: var(--foreground); text-decoration: none; transition: background-color .12s;
}
.spx-row:hover { background: var(--surface-3); text-decoration: none; }
.spx-row.on { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.spx-row:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.spx-row-main, .spx-row-top, .spx-row-bottom { min-width: 0; }
.spx-row-main { display: flex; flex-direction: column; gap: 2px; }
.spx-row-top, .spx-row-bottom { display: flex; align-items: center; gap: 8px; }
.spx-row-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spx-row-time { font-size: 12px; color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.spx-row-prev { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spx-row.unread .spx-row-name { font-weight: 800; }
.spx-row.unread .spx-row-prev { color: var(--foreground); font-weight: 500; }
.spx-row.unread .spx-row-time { color: var(--accent-text); font-weight: 600; }
.spx-row .count { background: var(--accent); color: var(--on-accent); }
.spx-more { padding: 6px 0; }

/* ── Переписка ────────────────────────────────────────────────────────── */
.spx-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--thread-bg); }
.spx-thread-loading { flex: 1; display: grid; place-items: center; padding: 24px; }
.spx-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card); border-bottom: 1px solid var(--border); }
.spx-head-main { min-width: 0; }
.spx-head-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spx-head-name a { color: inherit; }
.spx-head-sub { margin-top: 3px; font-size: 12.5px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.spx-back { display: none; }
.spx-banner { display: flex; align-items: center; gap: 10px; margin: 10px 14px 0; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--warning-bg); color: var(--warning-fg); border: 1px solid var(--warning-border); font-size: 13px; }

.spx-body { position: relative; flex: 1; min-height: 0; display: flex; }
.spx-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 18px 16px; overscroll-behavior: contain; }
.spx-feed { display: flex; flex-direction: column; }
.spx-day { display: flex; justify-content: center; margin: 14px 0 6px; }
.spx-day span { padding: 3px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--muted); }
.spx-unread { display: flex; align-items: center; gap: 10px; margin: 14px 0 4px; color: var(--accent-text); font-size: 12px; font-weight: 700; }
.spx-unread::before, .spx-unread::after { content: ""; flex: 1; height: 1px; background: var(--accent-border); }

.spx-msg { display: flex; flex-direction: column; max-width: min(78%, 620px); margin-top: 2px; animation: spx-in .25s ease-out; }
.spx-msg.first { margin-top: 10px; }
.spx-msg.in { align-self: flex-start; align-items: flex-start; }
.spx-msg.out { align-self: flex-end; align-items: flex-end; }
@keyframes spx-in { from { opacity: 0; transform: scale(.985); } }
.spx-author { margin: 0 6px 3px; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.spx-bubble { position: relative; max-width: 100%; padding: 8px 12px 7px; border-radius: 16px; font-size: 14.5px; line-height: 1.45; overflow-wrap: anywhere; word-break: break-word; }
.in .spx-bubble { background: var(--card); border: 1px solid var(--border); color: var(--foreground); border-bottom-left-radius: 5px; }
.in:not(.first) .spx-bubble { border-top-left-radius: 5px; }
.out .spx-bubble { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 5px; }
.out:not(.first) .spx-bubble { border-top-right-radius: 5px; }
.spx-msg.failed .spx-bubble { opacity: .7; }
.spx-text { white-space: pre-wrap; }
.spx-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.spx-meta { float: right; display: inline-flex; align-items: center; gap: 3px; margin: 7px -2px -3px 10px; font-size: 11px; line-height: 1; color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.out .spx-meta { color: rgba(255, 255, 255, .72); }
.spx-st { display: inline-flex; }
.spx-st.read { color: #fff; }
.ic-xs { width: 13px; height: 13px; }

.spx-gallery { display: grid; gap: 3px; margin: -4px -8px 6px; border-radius: 12px; overflow: hidden; }
.spx-gallery.n1 { grid-template-columns: minmax(0, 260px); }
.spx-gallery.n2, .spx-gallery.n3, .spx-gallery.n4 { grid-template-columns: repeat(2, minmax(0, 150px)); }
.spx-img { display: block; width: 100%; padding: 0; border: 0; background: var(--surface-3); cursor: zoom-in; overflow: hidden; }
.spx-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.n1 .spx-img img { height: auto; max-height: 300px; min-height: 80px; }
.n2 .spx-img, .n3 .spx-img, .n4 .spx-img { aspect-ratio: 1; }
.spx-img.gone { cursor: default; min-height: 60px; display: grid; place-items: center; color: var(--muted); font-size: 12.5px; }
.spx-img.gone span { display: inline-flex; align-items: center; gap: 6px; padding: 10px; }
.spx-doc { display: flex; align-items: center; gap: 10px; min-width: 220px; margin: 2px 0 6px; padding: 8px 10px; border-radius: 10px; color: inherit; text-decoration: none; background: rgba(127, 127, 127, .12); }
.spx-doc:hover { background: rgba(127, 127, 127, .2); text-decoration: none; }
.spx-doc-name { display: block; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.spx-doc-size { display: block; font-size: 12px; opacity: .7; }
.spx-fail { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 12.5px; font-weight: 600; color: var(--danger); }
.spx-fail button { border: 0; background: none; padding: 2px 0 2px 6px; font: inherit; font-weight: 700; color: var(--foreground); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.spx-jump { position: absolute; right: 18px; bottom: 14px; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--border); background: var(--card); color: var(--foreground); box-shadow: var(--shadow-md); cursor: pointer; }
.spx-jump .count { position: absolute; top: -6px; right: -4px; background: var(--accent); color: var(--on-accent); }
.spx-drop { position: absolute; inset: 10px; z-index: 2; display: grid; place-items: center; border-radius: var(--radius-lg); border: 2px dashed var(--accent); background: var(--accent-soft); color: var(--accent-text); font-weight: 700; pointer-events: none; }

.spx-compose { padding: 10px 14px 12px; background: var(--card); border-top: 1px solid var(--border); }
.spx-bar { display: flex; align-items: flex-end; gap: 8px; }
.spx-input { flex: 1; min-height: 42px; max-height: 180px; padding: 10px 12px; resize: none; line-height: 1.4; overflow-y: hidden; }
.spx-send { width: 42px; height: 42px; flex: none; }
.spx-closed-note { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); }
.spx-tray { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; }
.spx-tray-item { position: relative; flex: none; width: 64px; height: 64px; border-radius: var(--radius); overflow: hidden; background: var(--surface-3); border: 1px solid var(--border); }
.spx-tray-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.spx-tray-item.uploading img { opacity: .6; }
.spx-tray-item.error { border-color: var(--danger); }
.spx-tray-doc { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 100%; padding: 4px; color: var(--muted); font-size: 10.5px; font-weight: 600; }
.spx-tray-doc span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spx-tray-bar { position: absolute; left: 6px; right: 6px; bottom: 6px; height: 4px; border-radius: 4px; background: rgba(0, 0, 0, .2); overflow: hidden; }
.spx-tray-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.spx-tray-err { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: var(--block-veil); color: var(--danger); }
.spx-tray-err button { border: 0; background: none; padding: 0; font: inherit; font-size: 11px; font-weight: 700; color: var(--foreground); text-decoration: underline; cursor: pointer; }
.spx-tray-x { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: rgba(17, 24, 39, .72); color: #fff; cursor: pointer; }

/* ── Клиент ───────────────────────────────────────────────────────────── */
.spx-info { min-height: 0; overflow-y: auto; padding: 16px; border-left: 1px solid var(--border); background: var(--card); }
.spx-info-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.spx-info-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.spx-info-close { display: none; }
.spx-client { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.spx-facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 14px; font-size: 13px; }
.spx-facts dt { color: var(--muted); }
.spx-facts dd { margin: 0; text-align: right; min-width: 0; overflow-wrap: anywhere; }
.spx-profile { width: 100%; justify-content: center; }
.spx-info-sub { display: flex; justify-content: space-between; margin: 20px 0 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.spx-orders { display: flex; flex-direction: column; gap: 6px; }
.spx-order { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--border); color: var(--foreground); text-decoration: none; transition: border-color .12s, background-color .12s; }
.spx-order:hover { border-color: var(--accent-border); background: var(--accent-soft); text-decoration: none; }
.spx-order-top, .spx-order-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.spx-order-product { font-size: 12.5px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spx-order-bottom .faint { font-size: 12px; }
.spx-all-orders { display: block; margin-top: 10px; font-size: 13px; font-weight: 600; }
.spx-scrim { display: none; }

@media (max-width: 1279px) {
  .spx { grid-template-columns: 300px minmax(0, 1fr); }
  .spx-info { position: absolute; top: 0; right: 0; bottom: 0; z-index: 5; width: min(320px, 92%); box-shadow: var(--shadow-pop); transform: translateX(105%); transition: transform .25s ease; }
  .spx.info-open .spx-info { transform: none; }
  .spx.info-open .spx-scrim { display: block; position: absolute; inset: 0; z-index: 4; background: var(--scrim); }
  .spx-info-close { display: inline-flex; }
}
@media (max-width: 899px) {
  .spx { grid-template-columns: minmax(0, 1fr); height: calc(100dvh - 112px); border-radius: var(--radius); }
  .spx:not(.has-dialog) { grid-template-columns: minmax(0, 1fr); }
  .spx[data-view="list"] .spx-main { display: none; }
  .spx[data-view="thread"] .spx-list { display: none; }
  .spx-list { border-right: 0; }
  .spx-back { display: inline-flex; }
  .spx-msg { max-width: 88%; }
  .spx-scroll { padding: 8px 12px 14px; }
  .spx-head { padding: 10px; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) { .spx *, .spx-info { animation: none !important; transition: none !important; } }

/* ── Ответ на сообщение ─────────────────────────────────────────────────── */
.spx-line { display: flex; align-items: center; gap: 4px; max-width: 100%; min-width: 0; }
.out .spx-line { flex-direction: row-reverse; }
.spx-line .spx-bubble { min-width: 0; }
.spx-reply { flex: none; width: 30px; height: 30px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .15s, background-color .15s; }
.spx-msg:hover .spx-reply, .spx-reply:focus-visible { opacity: 1; }
.spx-reply:hover { background: var(--surface-3); color: var(--foreground); }
.spx-reply:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
@media (hover: none) { .spx-reply { opacity: 1; } }
.spx-quote {
  display: flex; flex-direction: column; width: 100%; max-width: 320px; margin: 0 0 6px; padding: 5px 9px;
  border: 0; border-left: 3px solid currentColor; border-radius: 8px; background: rgba(127, 127, 127, .14);
  color: inherit; text-align: left; font: inherit; font-size: 13px; line-height: 1.3; cursor: pointer;
}
.in .spx-quote { border-left-color: var(--accent); }
.spx-quote b { font-size: 12.5px; font-weight: 700; }
.spx-quote-text { opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spx-quote.missing { cursor: default; opacity: .7; }
@keyframes spx-flash { 0%, 100% { box-shadow: none; } 20%, 60% { box-shadow: 0 0 0 3px var(--ring); } }
.spx-msg.flash .spx-bubble { animation: spx-flash 1.5s ease; }
.spx-replybar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; padding: 6px 4px 6px 10px; border-left: 3px solid var(--accent); border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-text); }
.spx-replybar-main { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.spx-replybar-main b { font-size: 12.5px; color: var(--foreground); }
.spx-replybar-main span { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
