* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0b0f17; --bg2: #111725; --bg3: #1a2234; --bg4: #232e47;
  --border: #232e47; --border2: #2f3d5c;
  --text: #e8ecf4; --muted: #7d8aa5; --muted2: #5a6580;
  --accent: #5b8cff; --accent2: #3f6ae0;
  --green: #34d399; --red: #f87171; --orange: #fbbf24; --purple: #a78bfa;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}
html, body { height: 100%; }
body {
  background: radial-gradient(1200px 800px at 80% -10%, #16203a 0%, var(--bg) 55%);
  color: var(--text);
  font: 14px/1.55 "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

svg.icon { width: 16px; height: 16px; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
  vertical-align: -3px; }

button {
  cursor: pointer; border: 1px solid var(--border2); background: var(--bg3); color: var(--text);
  padding: 7px 14px; border-radius: 9px; font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 7px;
  transition: border-color .15s, background .15s, transform .05s;
}
button:hover { border-color: var(--accent); background: var(--bg4); }
button:active { transform: translateY(1px); }
button.primary { background: linear-gradient(180deg, var(--accent), var(--accent2));
  border-color: transparent; color: #fff; }
button.primary:hover { filter: brightness(1.1); }
button.danger { color: var(--red); }
button.danger:hover { border-color: var(--red); background: rgba(248,113,113,.08); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--bg3); }
button.chip { border-radius: 999px; padding: 5px 14px; }
button.chip.active { background: linear-gradient(180deg, var(--accent), var(--accent2));
  border-color: transparent; color: #fff; }

input, select, textarea {
  background: var(--bg2); border: 1px solid var(--border2); color: var(--text);
  padding: 8px 12px; border-radius: 9px; font-size: 14px; outline: none; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,140,255,.15);
}
select { cursor: pointer; }

/* ---------- Login ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 18px;
  padding: 40px 36px; width: 360px; display: flex; flex-direction: column; gap: 16px;
  box-shadow: var(--shadow);
}
.login-logo { display: flex; align-items: center; justify-content: center; gap: 10px;
  font-weight: 700; font-size: 19px; margin-bottom: 6px; }
.login-logo svg.icon { width: 26px; height: 26px; color: var(--accent); }
.login-error { color: var(--red); font-size: 13px; text-align: center; min-height: 18px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; background: var(--bg2); border-right: 1px solid var(--border);
  padding: 22px 14px; display: flex; flex-direction: column; gap: 4px; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .logo { display: flex; align-items: center; gap: 9px; font-weight: 700;
  font-size: 15px; padding: 0 10px 20px; }
.sidebar .logo svg.icon { width: 21px; height: 21px; color: var(--accent); }
.sidebar a {
  color: var(--muted); text-decoration: none; padding: 9px 12px; border-radius: 9px;
  display: flex; align-items: center; gap: 10px; font-weight: 500;
  transition: background .15s, color .15s;
}
.sidebar a.active { background: linear-gradient(90deg, rgba(91,140,255,.18), rgba(91,140,255,.06));
  color: var(--text); }
.sidebar a:hover { background: var(--bg3); color: var(--text); }
.sidebar .spacer { flex: 1; }
.sidebar .lang-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  color: var(--muted); font-size: 13px; }
.sidebar .lang-row select { flex: 1; padding: 5px 8px; font-size: 13px; }

.content { flex: 1; padding: 28px 32px; max-width: 1200px; }
.content h2 { font-size: 19px; font-weight: 700; margin-bottom: 18px; letter-spacing: -.2px; }

/* ---------- Tables ---------- */
.table-card { background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); }
th { color: var(--muted2); font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .6px; background: rgba(255,255,255,.015); }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; transition: background .12s; }
tr.clickable:hover { background: var(--bg3); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px;
  border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.open { background: rgba(91,140,255,.13); color: var(--accent); }
.badge.pending { background: rgba(251,191,36,.13); color: var(--orange); }
.badge.in_review { background: rgba(167,139,250,.13); color: var(--purple); }
.badge.resolved { background: rgba(52,211,153,.13); color: var(--green); }
.badge.on { background: rgba(52,211,153,.13); color: var(--green); }
.badge.off { background: rgba(248,113,113,.13); color: var(--red); }

.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
  color: #fff; flex-shrink: 0; }
.user-cell { display: flex; align-items: center; gap: 11px; }

.toolbar { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; min-width: 180px; }
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap svg.icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted2); }
.search-wrap input { width: 100%; padding-left: 34px; }
.muted { color: var(--muted); }
.error-bar { background: rgba(248,113,113,.1); border: 1px solid rgba(248,113,113,.4);
  color: var(--red); padding: 9px 15px; border-radius: 10px; margin-bottom: 14px; display: none; }

/* ---------- Bot card ---------- */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin-top: 22px; box-shadow: var(--shadow); }
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 14px; display: flex;
  align-items: center; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Chat ---------- */
.chat-header { display: flex; align-items: center; gap: 13px; margin-bottom: 16px; flex-wrap: wrap; }
.chat-header .back { display: inline-flex; align-items: center; gap: 4px;
  text-decoration: none; color: var(--muted); font-weight: 500; }
.chat-header .back:hover { color: var(--accent); }
.chat-header h2 { margin: 0; }
.chat-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; height: calc(100vh - 225px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow);
}
.msg { max-width: 68%; padding: 10px 14px; border-radius: 14px; position: relative; }
/* Hovered bubble rises above neighbors so the actions pill is never clipped
   behind an adjacent (short) message */
.msg:hover { z-index: 8; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 4px;
  display: flex; gap: 10px; align-items: center; }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-start; background: var(--bg3); border-bottom-left-radius: 4px; }
.msg.support { align-self: flex-end; border-bottom-right-radius: 4px;
  background: linear-gradient(180deg, #234a94, #1d3d7d); }
.msg.deleted .body { text-decoration: line-through; color: var(--muted); }

/* Message actions: translate + delete, as a single pill in the corner on hover */
.msg .msg-actions {
  position: absolute; top: -12px; right: 10px; display: none;
  align-items: center; gap: 2px; padding: 2px 3px; z-index: 9;
  background: var(--bg2); border: 1px solid var(--border2); border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
  white-space: nowrap;
}
/* Left-aligned (customer) bubbles anchor the pill on the LEFT so a short
   message ("?") can't push it past the chat box edge where it gets clipped */
.msg.user .msg-actions { right: auto; left: 10px; }
.msg:hover .msg-actions { display: inline-flex; }
.msg .msg-actions button {
  background: none; border: none; color: var(--muted);
  padding: 4px 6px; border-radius: 6px; display: inline-flex;
}
.msg .msg-actions button:hover { background: var(--bg4); }
.msg .msg-actions .tr-btn:hover { color: var(--accent); }
.msg .msg-actions .del-btn:hover { color: var(--red); }
.msg .msg-actions .reply-btn:hover,
.msg .msg-actions .edit-btn:hover { color: var(--accent); }

/* ---------- Detail layout: chat + right info panel ---------- */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 290px;
  gap: 16px; align-items: start; }
.detail-side { display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 14px; max-height: calc(100vh - 120px); overflow-y: auto; }
.side-card { background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.side-card h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 7px; text-transform: uppercase;
  letter-spacing: .4px; }
.info-row { display: flex; justify-content: space-between; gap: 10px;
  padding: 5px 0; font-size: 13px; border-bottom: 1px solid var(--border);
  align-items: center; }
.info-row:last-child { border-bottom: none; }
.info-row span { color: var(--muted); }
.info-row b { font-weight: 500; text-align: right; word-break: break-all; }
.info-row.info-edit input { flex: 1; min-width: 0; text-align: right;
  font-size: 13px; padding: 4px 8px; }
.info-row.info-edit button { background: none; border: 1px solid var(--border2);
  border-radius: 6px; color: var(--muted); padding: 4px 7px; display: inline-flex; }
.info-row.info-edit button:hover { color: var(--accent); border-color: var(--accent); }
.side-card textarea { width: 100%; resize: vertical; min-height: 110px;
  font-size: 13px; line-height: 1.5; margin-bottom: 9px; }
.side-card #notes-save { width: 100%; justify-content: center; display: inline-flex;
  align-items: center; gap: 6px; }
.side-card #summary-btn { width: 100%; justify-content: center; display: inline-flex;
  align-items: center; gap: 6px; }
.summary-text { white-space: pre-wrap; font-size: 12.5px; line-height: 1.55;
  color: var(--text); background: var(--bg3); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 9px 11px; margin-bottom: 10px; }

/* ---------- Payments modal ---------- */
.pay-open-btn { width: 100%; margin-top: 10px; display: inline-flex;
  align-items: center; justify-content: center; gap: 7px;
  background: var(--bg3); border: 1px solid var(--border2); color: var(--text); }
.pay-open-btn:hover { border-color: var(--accent); color: var(--accent); }
#pay-modal { position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.65); display: flex;
  align-items: center; justify-content: center; padding: 3vh 3vw; }
#pay-panel { width: 94%; height: 92%; max-width: 1280px; display: flex;
  flex-direction: column; background: var(--bg2);
  border: 1px solid var(--border2); border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0,0,0,.6); overflow: hidden; }
.pay-head { display: flex; align-items: center; gap: 10px;
  padding: 13px 18px; border-bottom: 1px solid var(--border);
  background: var(--bg3); }
.pay-head .pay-uid { color: var(--accent); font-weight: 600; }
.pay-head .pay-stats { flex: 1; text-align: right; color: var(--muted);
  font-size: 12.5px; padding-right: 8px; }
.pay-head #pay-close { background: none; border: none; color: var(--muted);
  font-size: 17px; cursor: pointer; padding: 3px 9px; border-radius: 7px; }
.pay-head #pay-close:hover { color: var(--red); background: var(--bg4); }
.pay-pager { display: inline-flex; align-items: center; gap: 7px;
  color: var(--muted); font-size: 12.5px; margin-left: 6px; }
.pay-pager button { background: var(--bg4); border: 1px solid var(--border2);
  border-radius: 6px; color: var(--text); padding: 2px 11px; font-size: 15px;
  cursor: pointer; }
.pay-pager button:disabled { opacity: .35; cursor: default; }
.pay-pager button:not(:disabled):hover { border-color: var(--accent);
  color: var(--accent); }
.pay-toolbar #pay-field { font-family: ui-monospace, monospace; font-size: 12.5px; }
.pay-toolbar #pay-apply { padding: 6px 16px; font-size: 12.5px; }
.pay-uid-cell { font-family: ui-monospace, monospace; font-size: 12px;
  color: var(--accent); }
.pay-watch-btn { padding: 4px 11px; font-size: 12px; white-space: nowrap; }
.pay-watch-btn:disabled { opacity: .6; cursor: default; }
.pay-toolbar { display: flex; align-items: center; gap: 9px;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
  background: var(--bg2); flex-wrap: wrap; }
.pay-toolbar #pay-search { flex: 1; min-width: 200px; font-size: 13px;
  padding: 7px 11px; }
.pay-toolbar select, .pay-toolbar input[type="datetime-local"] { font-size: 13px;
  padding: 6px 9px; }
.pay-toolbar input[type="datetime-local"] { color-scheme: dark; }
.pay-toolbar #pay-clear { background: none; border: 1px solid var(--border2);
  border-radius: 7px; color: var(--muted); padding: 6px 12px; font-size: 12.5px; }
.pay-toolbar #pay-clear:hover { color: var(--red); border-color: var(--red); }
.pay-body { flex: 1; overflow: auto; padding: 0; }
.pay-body > .muted, .pay-error { padding: 22px; }
.pay-error { color: var(--red); }
.pay-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pay-table th { position: sticky; top: 0; background: var(--bg3);
  text-align: left; padding: 10px 14px; color: var(--muted); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .4px; z-index: 2; }
.pay-table td { padding: 9px 14px; border-top: 1px solid var(--border); }
.pay-row { cursor: pointer; }
.pay-row:hover { background: var(--bg3); }
.pay-detail td { background: var(--bg1, #0d1117); padding: 12px 18px; }
.pay-detail-grid { display: grid; gap: 8px 26px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.pay-detail-grid div { display: flex; flex-direction: column; gap: 1px;
  min-width: 0; }
.pay-detail-grid span { color: var(--muted2); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .4px; }
.pay-detail-grid b { font-weight: 500; word-break: break-all;
  user-select: all; }
.pay-detail-grid a { color: var(--accent); word-break: break-all; }
.pay-detail-block { margin-top: 12px; padding: 10px 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 9px; }

/* ---------- Payment watch ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.ps-chip { display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; }
.ps-waiting { background: rgba(255,170,60,.15); color: var(--orange, #e8a33d);
  border: 1px solid rgba(255,170,60,.4); }
.ps-success { background: rgba(70,200,120,.14); color: #4bcf83;
  border: 1px solid rgba(70,200,120,.4); }
.ps-canceled { background: rgba(255,255,255,.07); color: var(--muted);
  border: 1px solid var(--border2); }
.ps-uid { cursor: pointer; user-select: all; }
.ps-uid:hover { color: var(--accent); }
.ps-row { display: flex; align-items: center; gap: 8px; padding: 6px 0;
  border-bottom: 1px solid var(--border); font-size: 12.5px; }
.ps-row:last-of-type { border-bottom: none; margin-bottom: 8px; }
.ps-row code { flex: 1; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; cursor: pointer; }
.ps-row code:hover { color: var(--accent); }
.ps-row .ps-cancel { background: none; border: none; color: var(--muted);
  cursor: pointer; padding: 2px 6px; border-radius: 5px; }
.ps-row .ps-cancel:hover { color: var(--red); background: var(--bg4); }
#ps-list { margin-bottom: 10px; }


.pay-detail-heading { color: var(--accent); font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: 8px; }
@media (max-width: 1100px) {
  .detail-grid { grid-template-columns: 1fr; }
  .detail-side { position: static; max-height: none; }
}

/* ---------- Quote (replied-to message) ---------- */
.quoted { display: flex; flex-direction: column; gap: 1px; margin-bottom: 6px;
  padding: 5px 10px; border-left: 3px solid var(--accent);
  background: rgba(255,255,255,.06); border-radius: 6px; font-size: 12px;
  cursor: pointer; max-width: 100%; overflow: hidden; }
.quoted b { color: var(--accent); font-weight: 600; }
.quoted span { color: var(--muted); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.quoted[data-target]:hover { background: rgba(255,255,255,.1); }
.msg.flash { animation: msg-flash 1.6s ease; }
@keyframes msg-flash {
  0%, 60% { box-shadow: 0 0 0 2px var(--accent); }
  100% { box-shadow: none; }
}

/* ---------- Reply target bar ---------- */
.reply-target-chip { display: flex; align-items: center; gap: 8px;
  margin-top: 10px; padding: 7px 12px; font-size: 12.5px;
  background: var(--bg3); border: 1px solid var(--border2);
  border-left: 3px solid var(--accent); border-radius: 8px; }
.reply-target-chip b { color: var(--accent); }
.reply-target-chip span { color: var(--muted); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.reply-target-chip button { background: none; border: none; color: var(--muted);
  cursor: pointer; padding: 2px 6px; border-radius: 5px; }
.reply-target-chip button:hover { color: var(--red); background: var(--bg4); }

/* ---------- Inline message editing ---------- */
.edit-area { margin-top: 4px; }
.edit-area textarea { width: 100%; min-width: 240px; resize: vertical;
  font-size: 13.5px; line-height: 1.45; }
.edit-buttons { display: flex; gap: 8px; margin-top: 7px; justify-content: flex-end; }
.edit-buttons button { padding: 5px 14px; font-size: 12.5px;
  display: inline-flex; align-items: center; gap: 5px; }
.media-tag { display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,.07); border-radius: 6px; padding: 2px 8px;
  font-size: 12px; color: var(--muted); margin-bottom: 4px; }
/* ---------- Media ---------- */
.media-box { margin: 2px 0 6px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.media-box[data-kind="image"] { display: block; }
.media-actions { margin-top: 4px; }
.media-actions button, .media-modal, .media-tab {
  font-size: 12px; padding: 5px 9px; }

/* Lightbox */
#lightbox { position: fixed; inset: 0; z-index: 300; background: rgba(4,7,13,.9);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px); animation: toast-in .15s ease; }
#lb-content { max-width: 92vw; max-height: 90vh; border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6); }
img#lb-content { object-fit: contain; }
iframe#lb-content { width: 86vw; height: 90vh; border: none; background: #fff; }
video#lb-content { max-width: 92vw; max-height: 90vh; }
#lb-close, #lb-tab { position: fixed; top: 16px; z-index: 301; }
#lb-close { right: 18px; padding: 8px 11px; }
#lb-tab { right: 70px; }
.media-img { max-width: 280px; max-height: 320px; border-radius: 10px; cursor: zoom-in;
  display: block; border: 1px solid var(--border2); }
.media-video { max-width: 340px; max-height: 300px; border-radius: 10px; display: block; }
.media-box audio { max-width: 300px; display: block; }
.media-load { font-size: 12px; padding: 5px 11px; }

.translation { margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--border2);
  font-size: 13px; color: #b8c4dd; font-style: italic; white-space: pre-wrap;
  word-break: break-word; }
.translation svg.icon { color: var(--accent); font-style: normal; }
.reply-bar { display: flex; gap: 10px; margin-top: 14px; position: relative; }
.reply-bar textarea { flex: 1; resize: none; height: 62px; }
.reply-bar button { align-self: stretch; padding: 0 22px; }
.reply-bar #attach-btn, .reply-bar #emoji-btn { padding: 0 14px; color: var(--muted); }
.reply-bar #attach-btn:hover, .reply-bar #emoji-btn:hover { color: var(--accent); }

/* ---------- Emoji picker ---------- */
#emoji-picker {
  position: absolute; bottom: calc(100% + 10px); left: 0;
  width: 340px; max-height: 264px; overflow-y: auto;
  background: var(--bg2); border: 1px solid var(--border2); border-radius: 12px;
  padding: 8px; display: none; grid-template-columns: repeat(9, 1fr); gap: 2px;
  box-shadow: 0 12px 34px rgba(0,0,0,.55); z-index: 20;
}
#emoji-picker.open { display: grid; }
.emoji-item { background: none; border: none; font-size: 21px; line-height: 1;
  padding: 5px 0; border-radius: 7px; cursor: pointer; }
.emoji-item:hover { background: var(--bg4); }

/* Emoji-only messages are shown large */
.msg .body.big-emoji { font-size: 36px; line-height: 1.25; }

/* ---------- Quick reply picker ---------- */
#quick-picker {
  position: absolute; bottom: calc(100% + 10px); left: 0;
  width: 380px; max-height: 280px; overflow-y: auto;
  background: var(--bg2); border: 1px solid var(--border2); border-radius: 12px;
  padding: 6px; display: none; flex-direction: column; gap: 2px;
  box-shadow: 0 12px 34px rgba(0,0,0,.55); z-index: 20;
}
#quick-picker.open { display: flex; }
.quick-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background: none; border: none; text-align: left; padding: 8px 12px;
  border-radius: 8px; cursor: pointer; color: var(--text); }
.quick-item:hover { background: var(--bg4); }
.quick-item b { color: var(--accent); font-size: 13px; }
.quick-item span { color: var(--muted); font-size: 12px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 340px; }

/* Quick reply form (multi-part) */
.qm-parts { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.qm-part-row { display: flex; gap: 8px; align-items: flex-start; }
.qm-part-row textarea { flex: 1; resize: vertical; min-height: 48px; }
.qm-part-row button { background: none; border: 1px solid var(--border2);
  border-radius: 6px; color: var(--muted); padding: 5px 9px; }
.qm-part-row button:hover { color: var(--red); border-color: var(--red); }
.qm-media-row { align-items: center; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }
#qm-form.dragover { outline: 2px dashed var(--accent); outline-offset: 8px;
  border-radius: 8px; }
.qm-file-label { font-size: 13px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 220px; }
.qm-caption { flex: 1; font-size: 13px; padding: 5px 9px; }

/* ---------- AI suggestion card ---------- */
.ai-card { margin-top: 12px; padding: 12px 15px;
  background: var(--bg2); border: 1px solid var(--border2);
  border-left: 3px solid var(--accent); border-radius: 10px; }
.ai-card .ai-ru { white-space: pre-wrap; font-size: 14px; line-height: 1.5; }
.ai-card .ai-tr { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border);
  color: var(--muted); font-size: 12.5px; white-space: pre-wrap; }
.ai-card .ai-label { color: var(--muted2); font-weight: 600; text-transform: uppercase;
  font-size: 10.5px; letter-spacing: .4px; }
.ai-card .ai-actions { display: flex; gap: 8px; margin-top: 10px; }
.ai-card .ai-actions button { padding: 6px 14px; font-size: 12.5px;
  display: inline-flex; align-items: center; gap: 5px; }
.reply-bar #quick-btn, .reply-bar #ai-btn { padding: 0 14px; color: var(--muted); }
.reply-bar #quick-btn:hover, .reply-bar #ai-btn:hover { color: var(--accent); }

/* ---------- Message reactions ---------- */
.reactions { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.reaction-chip { display: inline-flex; align-items: center; font-size: 15px;
  padding: 2px 9px; border-radius: 12px; background: rgba(255,255,255,.1);
  border: 1px solid transparent; line-height: 1.3; }
.reaction-chip.support { border-color: var(--accent); }
.react-bar { position: absolute; bottom: calc(100% + 6px); right: 0; z-index: 15;
  display: flex; gap: 2px; padding: 5px 7px; flex-wrap: wrap; max-width: 300px;
  background: var(--bg2); border: 1px solid var(--border2); border-radius: 22px;
  box-shadow: 0 8px 26px rgba(0,0,0,.5); }
.react-item { background: none; border: none; font-size: 19px; line-height: 1;
  padding: 4px 5px; border-radius: 50%; cursor: pointer; }
.react-item:hover { background: var(--bg4); transform: scale(1.18); }
.react-item.active { background: var(--bg4); box-shadow: 0 0 0 1.5px var(--accent); }

/* Attachments pending send */
#pending-files { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
#pending-files:empty { display: none; }
.pending-chip { display: inline-flex; align-items: center; gap: 7px;
  background: var(--bg3); border: 1px solid var(--border2); border-radius: 9px;
  padding: 5px 9px; font-size: 12px; max-width: 240px; }
.pending-chip img { width: 30px; height: 30px; object-fit: cover; border-radius: 5px; }
.pending-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-chip button { background: none; border: none; color: var(--muted);
  padding: 0 2px; font-size: 13px; }
.pending-chip button:hover { color: var(--red); }

/* Drag & drop */
.chat-box { position: relative; }
.chat-wrap { position: relative; }
.scroll-bottom {
  position: absolute; right: 18px; bottom: 18px; z-index: 5;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg3); border: 1px solid var(--border2); color: var(--muted);
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.45); cursor: pointer;
  opacity: 0; transform: translateY(6px);
  transition: opacity .18s ease, transform .18s ease;
}
.scroll-bottom.show { display: inline-flex; opacity: 1; transform: none; }
.scroll-bottom:hover { color: var(--accent); border-color: var(--accent); background: var(--bg4); }
.drop-overlay { display: none; position: sticky; bottom: 0; left: 0; right: 0;
  padding: 14px; text-align: center; color: var(--accent); font-weight: 600;
  background: rgba(91,140,255,.1); border: 2px dashed var(--accent);
  border-radius: 10px; pointer-events: none; }
.chat-box.dragover .drop-overlay { display: block; }
.chat-box.dragover { border-color: var(--accent); }
.reply-hint { font-size: 11px; color: var(--muted2); margin-top: 6px; }

/* ---------- Toast notifications ---------- */
#toasts { position: fixed; top: 18px; right: 18px; display: flex;
  flex-direction: column; gap: 8px; z-index: 100; }
.toast { display: flex; align-items: center; gap: 9px; background: var(--bg3);
  border: 1px solid var(--border2); border-left: 3px solid var(--green);
  padding: 10px 15px; border-radius: 10px; box-shadow: var(--shadow);
  max-width: 360px; font-size: 13px; animation: toast-in .25s ease; }
.toast svg.icon { color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.error svg.icon { color: var(--red); }
.toast.out { opacity: 0; transform: translateX(12px); transition: all .35s; }
@keyframes toast-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; } }

/* ---------- Filter counters / awaiting indicator ---------- */
.chip .count { background: rgba(255,255,255,.1); border-radius: 999px;
  padding: 0 7px; font-size: 11px; }
.chip.active .count { background: rgba(255,255,255,.25); }
.await-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--orange); margin-right: 7px; vertical-align: 1px;
  animation: pulse 2s infinite; }
.unread-badge { display: inline-block; min-width: 19px; text-align: center;
  background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #fff;
  border-radius: 999px; padding: 1px 6px; font-size: 11px; font-weight: 700;
  margin-right: 7px; animation: pulse-blue 2s infinite; }
@keyframes pulse-blue {
  0% { box-shadow: 0 0 0 0 rgba(91,140,255,.45); }
  70% { box-shadow: 0 0 0 7px rgba(91,140,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(91,140,255,0); }
}
tr.unread .last-msg-cell { color: var(--text); font-weight: 600; }
.seen-tick { color: var(--muted2); margin-right: 6px; }
.seen-tick svg.icon { vertical-align: -2px; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(251,191,36,.45); }
  70% { box-shadow: 0 0 0 7px rgba(251,191,36,0); }
  100% { box-shadow: 0 0 0 0 rgba(251,191,36,0); }
}

/* ---------- Chat date separator ---------- */
.date-sep { display: flex; align-items: center; gap: 12px; color: var(--muted2);
  font-size: 12px; margin: 10px 0 2px; }
.date-sep::before, .date-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }

input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.card p { line-height: 1.5; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  /* Sidebar becomes a sticky, horizontally scrollable top bar */
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 40;
    flex-direction: row; align-items: center; gap: 2px;
    padding: 8px 10px; overflow-x: auto; overflow-y: hidden;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .sidebar .logo { display: none; }
  .sidebar a { padding: 8px 10px; font-size: 12.5px; white-space: nowrap; flex-shrink: 0; }
  .sidebar .lang-row { padding: 0 4px; flex-shrink: 0; }
  .sidebar .lang-row select { width: 74px; }

  .content { padding: 14px 10px; max-width: none; }
  .content h2 { font-size: 17px; margin-bottom: 12px; }

  /* Wide tables scroll inside their card instead of breaking the page */
  .table-card { overflow-x: auto; }
  .table-card table { min-width: 640px; }

  .chat-header { gap: 8px; }
  .chat-header h2 { font-size: 15px; }
  .chat-box { height: calc(100dvh - 340px); padding: 12px; }
  .msg { max-width: 90%; }

  /* Reply bar: textarea on its own row, buttons underneath */
  .reply-bar { flex-wrap: wrap; }
  .reply-bar textarea { flex: 1 1 100%; order: -1; height: 54px; }
  .reply-bar button { padding: 8px 12px; align-self: auto; }
  .reply-bar button.primary { flex: 1; justify-content: center; }

  #emoji-picker, #quick-picker { width: min(340px, calc(100vw - 26px)); }
  #emoji-picker { grid-template-columns: repeat(8, 1fr); }

  #pay-modal { padding: 1vh 1vw; }
  #pay-panel { width: 100%; height: 98%; border-radius: 10px; }
  .pay-head { flex-wrap: wrap; row-gap: 6px; padding: 10px 12px; }
  .pay-head .pay-stats { flex-basis: 100%; text-align: left; order: 9; padding-right: 0; }

  .login-box { width: min(360px, 92vw); padding: 30px 22px; }
  .detail-side { position: static; max-height: none; }
  .side-card { padding: 12px 13px; }
  #lb-content { max-width: 96vw; }
}

/* Touch devices have no hover: tapping a bubble toggles its actions pill */
@media (hover: none) {
  .msg.show-actions .msg-actions { display: inline-flex; }
}
