:root {
    --bg: #0f0a1a; --panel: #160e25; --panel-2: #1f1534; --line: #2b1f42;
    --text: #efe9f7; --muted: #a596bd; --violet: #b84fd6; --violet-2: #7c3aed;
    --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }

.sx { display: grid; grid-template-columns: 340px minmax(0, 1fr) 300px; height: 100dvh; }
.sx-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.sx-brand { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 16px 12px; }
.sx-logo { text-decoration: none; font-weight: 800; font-size: 17px; letter-spacing: .02em; }
.sx-logo b { color: var(--violet); }
.sx-me { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sx-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 0 12px; }
.sx-tabs button { position: relative; height: 34px; border: 0; border-radius: 10px; background: none; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 700; }
.sx-tabs button[aria-selected="true"] { background: var(--panel-2); color: var(--text); }
.sx-tabs i { font-style: normal; margin-left: 2px; color: var(--warn); }
.sx-search { padding: 10px 12px; }
.sx-search input { width: 100%; height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); outline: none; }
.sx-search input:focus { border-color: var(--violet); }
.sx-items { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.sx-item { display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 12px; margin-bottom: 2px; border: 1px solid transparent; border-radius: 12px; background: none; text-align: left; cursor: pointer; }
.sx-item:hover { background: rgba(255, 255, 255, .03); }
.sx-item.on { background: rgba(184, 79, 214, .14); border-color: rgba(184, 79, 214, .4); }
.sx-item-top { display: flex; align-items: center; gap: 8px; }
.sx-item-top b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.sx-item-top time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.sx-item small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sx-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--violet); flex: none; box-shadow: 0 0 0 3px rgba(184, 79, 214, .25); }
.sx-tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: rgba(255, 255, 255, .06); color: var(--muted); }
.sx-tag.tg { background: rgba(56, 189, 248, .12); color: #7dd3fc; }
.sx-tag.order { background: rgba(251, 191, 36, .12); color: var(--warn); }
.sx-empty { padding: 30px 16px; text-align: center; color: var(--muted); }

.sx-chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.sx-placeholder { margin: auto; text-align: center; max-width: 380px; padding: 20px; color: var(--muted); }
.sx-placeholder h2 { color: var(--text); margin: 10px 0 6px; font-size: 20px; }
.sx-ph-ico { font-size: 44px; }
.sx-thread { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.sx-thread-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: rgba(15, 10, 26, .9); }
.sx-thread-title { flex: 1; min-width: 0; }
.sx-thread-title h1 { margin: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sx-thread-title span { font-size: 12px; color: var(--muted); }
.sx-thread-actions { display: flex; gap: 8px; flex: none; }
.sx-btn { height: 38px; padding: 0 16px; border: 0; border-radius: 10px; cursor: pointer; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--violet), var(--violet-2)); white-space: nowrap; }
.sx-btn:disabled { opacity: .5; cursor: wait; }
.sx-ghost { background: var(--panel-2); border: 1px solid var(--line); }
.sx-icon { width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; }
.sx-back, .sx-info-btn { display: none; }
.sx-feed { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.sx-msg { max-width: min(72%, 640px); padding: 10px 14px; border-radius: 16px; word-break: break-word; }
.sx-msg.client { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 5px; }
.sx-msg.staff { align-self: flex-end; background: linear-gradient(135deg, var(--violet), var(--violet-2)); border-bottom-right-radius: 5px; }
.sx-msg .who { font-size: 12px; font-weight: 700; margin-bottom: 2px; opacity: .8; }
.sx-msg time { display: block; text-align: right; font-size: 11px; opacity: .55; margin-top: 4px; }
.sx-msg img { display: block; max-width: 100%; max-height: 300px; border-radius: 10px; margin-top: 4px; }
.sx-sys { align-self: center; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; }
.sx-day { align-self: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.sx-quick { display: flex; gap: 6px; overflow-x: auto; padding: 8px 14px 0; scrollbar-width: none; }
.sx-quick button { flex: none; height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); cursor: pointer; font-size: 12px; }
.sx-quick button:hover { color: var(--text); border-color: #3d2c5c; }
.sx-reply { display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px; }
.sx-reply textarea { flex: 1; min-height: 42px; max-height: 160px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); resize: none; outline: none; }
.sx-reply textarea:focus { border-color: var(--violet); }
.sx-closed { margin: 0 14px 14px; padding: 12px 14px; border-radius: 12px; background: var(--panel); color: var(--muted); font-size: 13px; }

.sx-info { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 18px; }
.sx-info h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 700; }
.sx-kv { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid rgba(255, 255, 255, .04); font-size: 13px; }
.sx-kv span { color: var(--muted); }
.sx-kv b { text-align: right; word-break: break-word; }
.sx-card { padding: 14px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
.sx-st { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.sx-st.PAID, .sx-st.PENDING { background: rgba(251, 191, 36, .14); color: var(--warn); }
.sx-st.SENT { background: rgba(94, 234, 212, .14); color: #5eead4; }
.sx-st.CONFIRMED { background: rgba(74, 222, 128, .14); color: var(--ok); }
.sx-st.ROLLED_BACK { background: rgba(248, 113, 113, .14); color: var(--bad); }
.sx-link { display: inline-block; margin-top: 10px; color: #d59bf0; font-size: 13px; }
.sx-info .sx-close-info { display: none; }

.sx-toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 50; padding: 12px 18px; border-radius: 12px; background: #2b1e45; border: 1px solid #4a3470; font-weight: 600; box-shadow: 0 16px 40px rgba(0, 0, 0, .45); max-width: 92vw; }
.sx-toast.bad { background: #3a1620; border-color: #7f1d1d; }
.sx-gate { margin: auto; text-align: center; padding: 30px; max-width: 420px; }
.sx-gate a { color: #d59bf0; }

@media (max-width: 1200px) {
    .sx { grid-template-columns: 320px minmax(0, 1fr); }
    .sx-info { position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, 92vw); z-index: 40; transform: translateX(100%); transition: transform .25s; box-shadow: -20px 0 50px rgba(0, 0, 0, .5); }
    .sx-info.open { transform: none; }
    .sx-info-btn { display: grid; }
    .sx-info .sx-close-info { display: block; align-self: flex-end; }
}
@media (max-width: 760px) {
    body { overflow: auto; }
    .sx { grid-template-columns: 1fr; }
    .sx-chat { display: none; }
    .sx.chat-open .sx-list { display: none; }
    .sx.chat-open .sx-chat { display: flex; height: 100dvh; }
    .sx-back { display: grid; }
    .sx-thread-head { padding: calc(10px + env(safe-area-inset-top)) 12px 10px; flex-wrap: wrap; }
    .sx-thread-actions { width: 100%; }
    .sx-thread-actions .sx-btn { flex: 1; }
    .sx-msg { max-width: 88%; }
    .sx-reply { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
    .sx-reply textarea, .sx-search input { font-size: 16px; }
    .sx-tabs button { font-size: 11px; }
}
