:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #1c1f2e;
  --muted: #6b7085;
  --line: #e4e6ef;
  --primary: #4f46e5;
  --primary-2: #4338ca;
  --primary-soft: #eef0ff;
  --danger: #dc2645;
  --green: #12a150;
  --amber: #d98a00;
  --blue: #2b6fe0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 4px 16px rgba(20, 24, 50, .05);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; }
h3 { font-size: 16px; margin-bottom: 12px; }
code, kbd { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85em; background: #eef0f6; padding: 1px 5px; border-radius: 4px; }
kbd { border: 1px solid #d6d9e4; border-bottom-width: 2px; background: #fff; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; margin: 4px 0; }
.grow { flex: 1; }
.pad { padding: 20px; }
[hidden] { display: none !important; }

/* buttons & inputs */
.btn { border: 1px solid transparent; border-radius: 8px; padding: 9px 16px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; background: #eef0f6; color: var(--text); transition: background .15s, transform .05s; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-2); }
.btn.ghost { background: #fff; border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { background: var(--primary-soft); border-color: #c9ccf5; }
.btn.danger { background: #fff; color: var(--danger); border-color: #f3c6cf; }
.btn.danger:hover { background: #fff0f3; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { display: block; width: 100%; margin-top: 8px; }
.icon-btn { border: 0; background: transparent; font-size: 18px; cursor: pointer; padding: 6px 8px; border-radius: 8px; color: inherit; }
.icon-btn:hover { background: rgba(0, 0, 0, .06); }
input, select, textarea { font: inherit; font-size: 14px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7c9fb; border-color: var(--primary); }
textarea { resize: vertical; }
label { display: block; font-size: 13px; font-weight: 600; color: #3b3f52; margin-bottom: 12px; }
label > input, label > select, label > textarea, label > .prefix { margin-top: 5px; }
.prefix { display: flex; align-items: stretch; }
.prefix span { padding: 9px 10px; background: #eef0f6; border: 1px solid var(--line); border-right: 0; border-radius: 8px 0 0 8px; color: var(--muted); }
.prefix input { margin: 0; border-radius: 0 8px 8px 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: #e3e6f3; color: #44496a; flex: none; }
.avatar.small { width: 30px; height: 30px; font-size: 11px; }
.avatar.staff { background: #dff6e8; color: #0c7a3c; }
.avatar.admin { background: #ffe9d1; color: #a85a00; }
.badge { background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 7px; margin-left: auto; min-width: 20px; text-align: center; }
.tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--primary); background: var(--primary-soft); padding: 2px 6px; border-radius: 4px; margin-left: 6px; vertical-align: middle; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; text-transform: capitalize; padding: 3px 9px; border-radius: 20px; background: #eef0f6; color: #555b73; }
.pill-open, .pill-active { background: #e3eeff; color: var(--blue); }
.pill-pending, .pill-waiting, .pill-medium { background: #fff3d6; color: #9b6400; }
.pill-resolved, .pill-low { background: #ddf5e7; color: #0c7a3c; }
.pill-high { background: #ffe5d4; color: #b54a00; }
.pill-urgent, .pill-disabled { background: #ffe0e6; color: var(--danger); }
.pill-admin { background: #ffe9d1; color: #a85a00; }
.pill-staff { background: #dff6e8; color: #0c7a3c; }
.pill-user { background: #e9e8ff; color: var(--primary); }

/* login */
.login-page { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #e4e3ff, transparent 40%), radial-gradient(circle at 90% 90%, #dff4ff, transparent 40%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: #fff; padding: 32px; border-radius: 16px; box-shadow: 0 20px 60px rgba(40, 40, 90, .12); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; }
.brand img { width: 30px; height: 30px; }
.brand.big { font-size: 22px; margin-bottom: 6px; }
.brand.big img { width: 38px; height: 38px; }

/* shell */
.shell { display: flex; height: 100vh; }
.sidebar { width: 240px; background: #161a2d; color: #c9cce0; display: flex; flex-direction: column; padding: 18px 12px; flex: none; }
.sidebar .brand { color: #fff; padding: 4px 8px 20px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: #c9cce0; font-size: 14px; font-weight: 500; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .ico { width: 20px; text-align: center; }
.me { display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, .08); }
.me-info { flex: 1; min-width: 0; }
.me-info b { display: block; color: #fff; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-info small { text-transform: capitalize; color: #8e93ad; }
.me .icon-btn { color: #c9cce0; }
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: #fff; border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 19px; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.menu-btn { display: none; }
#view { flex: 1; overflow: auto; }
#view.fill { overflow: hidden; display: flex; }
.page { padding: 24px; max-width: 1200px; margin: 0 auto; }
.page.narrow { max-width: 680px; display: grid; gap: 18px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.empty { padding: 50px 20px; text-align: center; color: var(--text); margin: auto; }
.empty-ico { font-size: 40px; margin-bottom: 8px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 320px; flex: 1; }
.toolbar select { width: auto; }
.toolbar p { margin: 0; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 0 10px; }
.section-title:first-child { margin-top: 0; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; color: var(--text); box-shadow: var(--shadow); border-left: 4px solid #c9ccd9; transition: transform .1s; }
.stat:hover { transform: translateY(-2px); }
.stat span { display: block; color: var(--muted); font-size: 13px; font-weight: 600; }
.stat b { font-size: 30px; }
.stat.green { border-left-color: var(--green); }
.stat.blue { border-left-color: var(--blue); }
.stat.amber { border-left-color: var(--amber); }

/* tabs & table */
.tabs { display: inline-flex; background: #e9ebf3; border-radius: 9px; padding: 3px; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; border-radius: 7px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.tabs button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fafbfd; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.cell-user { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ticket list */
.ticket-list { display: grid; gap: 10px; }
.ticket-row { display: flex; gap: 16px; align-items: center; padding: 14px 18px; color: var(--text); transition: border-color .15s; }
.ticket-row:hover { border-color: #c2c5f2; }
.ticket-row.unread { border-left: 4px solid var(--primary); }
.t-main { flex: 1; min-width: 0; }
.t-top { display: flex; align-items: center; gap: 8px; }
.t-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-top .badge { margin-left: 4px; }
.t-num { color: var(--muted); font-weight: 600; font-size: 13px; }
.t-preview { font-size: 13px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }

/* conversation */
.conversation-layout { display: flex; gap: 16px; padding: 16px; flex: 1; min-height: 0; min-width: 0; }
.conversation { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.conv-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.conv-head > div:nth-child(2) { flex: 1; min-width: 0; }
.conv-head h2 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-pills { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.back { font-size: 20px; color: var(--muted); padding: 0 4px; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; background: #fafbfe; }
.msg { display: flex; gap: 10px; max-width: 78%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble { background: #fff; border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 9px 13px; min-width: 0; }
.msg.mine .bubble { background: var(--primary); border-color: var(--primary); color: #fff; border-radius: 14px 4px 14px 14px; }
.msg.mine .meta, .msg.mine .meta time { color: rgba(255, 255, 255, .8); }
.msg.mine .tag { background: rgba(255, 255, 255, .2); color: #fff; }
.msg.agent:not(.mine) .bubble { background: #f1f2ff; border-color: #dfe1fb; }
.meta { font-size: 12px; margin-bottom: 3px; }
.meta time { color: var(--muted); margin-left: 8px; }
.text { white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 1.5; }
.msg.system { align-self: center; max-width: 90%; font-size: 12px; color: var(--muted); background: #eef0f6; padding: 5px 12px; border-radius: 20px; gap: 8px; }
.day-sep { text-align: center; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.typing { font-size: 12px; color: var(--muted); padding: 4px 18px; font-style: italic; background: #fafbfe; }

/* composer + quick reply picker */
.composer { position: relative; border-top: 1px solid var(--line); padding: 12px 14px; background: #fff; }
.modal .composer { border: 1px solid var(--line); border-radius: 10px; }
.composer textarea { border: 0; padding: 4px; outline: none; resize: none; min-height: 60px; }
.composer textarea:focus { outline: none; }
.composer-bar { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.composer-bar .hint { flex: 1; font-size: 12px; color: var(--muted); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-pop { position: absolute; left: 12px; right: 12px; bottom: calc(100% - 6px); max-height: 280px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(20, 24, 50, .15); z-index: 20; padding: 6px; }
.qr-item { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 7px; cursor: pointer; font: inherit; font-size: 14px; }
.qr-item small { grid-column: 2; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qr-item.active, .qr-item:hover { background: var(--primary-soft); }
.qr-short { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--primary); background: var(--primary-soft); padding: 2px 7px; border-radius: 5px; font-weight: 700; align-self: start; }
.qr-empty { padding: 12px; font-size: 13px; color: var(--muted); }

/* ticket side panel */
.side { width: 290px; flex: none; padding: 18px; overflow-y: auto; }
.side dl { margin: 0 0 16px; font-size: 14px; }
.side dt { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 10px; }
.side dd { margin: 2px 0 0; }

/* chat */
.chat-layout { display: flex; gap: 16px; padding: 16px; flex: 1; min-height: 0; min-width: 0; }
.chat-list { width: 320px; flex: none; display: flex; flex-direction: column; overflow: hidden; }
.chat-list-head { padding: 14px; border-bottom: 1px solid var(--line); }
#chat-items { overflow-y: auto; flex: 1; padding: 6px; }
.group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 12px 10px 6px; }
.group-label span { background: #eef0f6; border-radius: 8px; padding: 0 6px; margin-left: 4px; }
.chat-item { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 9px; color: var(--text); }
.chat-item:hover { background: #f4f5fb; }
.chat-item.active { background: var(--primary-soft); }
.chat-item.unread b { color: var(--primary); }
.ci-main { flex: 1; min-width: 0; }
.ci-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.ci-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-sub { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.online { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #b9bccb; flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px #d4f3e1; }

/* quick replies page */
.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.qr-grid .empty { grid-column: 1 / -1; }
.qr-card { padding: 16px; display: flex; flex-direction: column; }
.qr-card-head { display: flex; gap: 8px; align-items: center; }
.qr-body { white-space: pre-wrap; font-size: 14px; color: #44495e; flex: 1; margin: 10px 0 14px; max-height: 140px; overflow: hidden; }

/* forms, modal, switch */
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.form-actions.left { justify-content: flex-start; }
.modal-back { position: fixed; inset: 0; background: rgba(15, 18, 35, .45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 480px; max-height: 92vh; overflow: auto; box-shadow: 0 24px 70px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 640px; }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 20px; }
.switch { display: flex; align-items: center; gap: 12px; font-weight: 500; font-size: 14px; cursor: pointer; }
.switch input { display: none; }
.switch span { width: 40px; height: 22px; background: #cfd2df; border-radius: 20px; position: relative; transition: background .15s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(18px); }

/* toasts */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 100; max-width: 360px; }
.toast { background: #1c1f2e; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); font-size: 14px; display: flex; flex-direction: column; gap: 3px; animation: slide .2s; border-left: 4px solid var(--primary); transition: opacity .3s, transform .3s; }
.toast.clickable { cursor: pointer; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--amber); }
.toast.hide { opacity: 0; transform: translateX(20px); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* responsive */
@media (max-width: 900px) {
  .side { display: none; }
  .chat-layout .chat-list { width: 100%; }
  .chat-layout #chat-pane { display: none; }
  .chat-layout.has-chat .chat-list { display: none; }
  .chat-layout.has-chat #chat-pane { display: flex; }
}
@media (max-width: 720px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vw rgba(0, 0, 0, .4); }
  .menu-btn { display: inline-block; }
  .topbar { padding: 10px 14px; }
  .page, .conversation-layout, .chat-layout { padding: 12px; }
  .msg { max-width: 92%; }
  .form .row { grid-template-columns: 1fr; }
  .composer-bar .hint { display: none; }
  .ticket-row { flex-direction: column; align-items: stretch; }
  .t-meta { align-items: flex-start; flex-direction: row; flex-wrap: wrap; }
}

/* attachments */
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.att-img { border: 1px solid var(--line); background: #fff; padding: 0; border-radius: 10px; overflow: hidden; cursor: zoom-in; max-width: 260px; }
.att-img img { display: block; max-width: 260px; max-height: 200px; object-fit: cover; }
.att-loading { display: grid; place-items: center; width: 160px; height: 100px; font-size: 13px; color: var(--muted); }
.att-file { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 10px; padding: 8px 12px; cursor: pointer; font: inherit; text-align: left; max-width: 300px; }
.att-file:hover { border-color: #c2c5f2; background: #fafaff; }
.att-ico { font-size: 22px; flex: none; }
.att-info { min-width: 0; display: flex; flex-direction: column; }
.att-info b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-info small { color: var(--muted); font-size: 12px; }
.att-dl { color: var(--primary); font-weight: 700; }
.msg.mine .att-file, .msg.mine .att-img { border-color: rgba(255, 255, 255, .4); }
.attach-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 2px; }
.chip { display: flex; align-items: center; gap: 8px; background: #f3f4fa; border: 1px solid var(--line); border-radius: 9px; padding: 5px 6px 5px 6px; max-width: 260px; font-size: 13px; }
.chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; flex: none; }
.chip .att-ico { font-size: 20px; }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chip small { color: var(--muted); flex: none; }
.chip-x { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.chip-x:hover { background: #e4e6ef; color: var(--danger); }
.drop-hint { display: none; position: absolute; inset: 4px; border: 2px dashed var(--primary); border-radius: 10px; background: rgba(238, 240, 255, .92); color: var(--primary); font-weight: 700; place-items: center; z-index: 10; pointer-events: none; }
.composer.dragging .drop-hint { display: grid; }
.lightbox img { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto 12px; border-radius: 8px; }
.lightbox .form-actions { align-items: center; }

/* reply to messages */
.msg { position: relative; align-items: flex-start; }
.msg-reply { align-self: center; border: 1px solid var(--line); background: #fff; color: var(--muted); border-radius: 50%; width: 30px; height: 30px; cursor: pointer; opacity: 0; transition: opacity .15s; flex: none; font-size: 15px; }
.msg:hover .msg-reply, .msg-reply:focus { opacity: 1; }
.msg-reply:hover { color: var(--primary); border-color: #c2c5f2; }
.quotes { display: flex; flex-direction: column; gap: 4px; margin: 2px 0 6px; }
.quote { display: block; text-align: left; font: inherit; font-size: 12px; border: 0; border-left: 3px solid var(--primary); background: rgba(79, 70, 229, .07); color: inherit; padding: 5px 9px; border-radius: 4px 8px 8px 4px; cursor: pointer; max-width: 420px; }
.quote b { display: block; font-size: 11px; color: var(--primary); }
.quote span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
.msg.mine .quote { background: rgba(255, 255, 255, .16); border-left-color: #fff; }
.msg.mine .quote b { color: #fff; }
.msg.flash .bubble { animation: flash 1.6s; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px #ffd75e; } 100% { box-shadow: 0 0 0 0 transparent; } }
.reply-bar { border: 1px solid var(--line); border-left: 3px solid var(--primary); border-radius: 8px; background: #f7f7ff; padding: 6px 8px; margin-bottom: 6px; font-size: 13px; }
.reply-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
.reply-item { display: flex; align-items: center; gap: 6px; padding: 2px 0; min-width: 0; }
.reply-item b { flex: none; }
.reply-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.link-btn { border: 0; background: none; color: var(--primary); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 2px 4px; }
.link-btn:hover { text-decoration: underline; }
.msg.system a { font-weight: 700; margin-left: 4px; }

/* select messages */
.select-box { display: none; width: 20px; height: 20px; border: 2px solid #b9bccb; border-radius: 6px; background: #fff; align-self: center; flex: none; }
.messages.selecting .msg:not(.system) { cursor: pointer; max-width: 100%; width: 100%; padding: 4px 8px; border-radius: 10px; }
.messages.selecting .msg:not(.system):hover { background: rgba(79, 70, 229, .05); }
.messages.selecting .select-box { display: block; }
.messages.selecting .msg-reply { display: none; }
.messages.selecting .msg.mine { flex-direction: row-reverse; }
.messages.selecting .msg.mine .select-box { order: 3; margin-right: auto; }
.messages.selecting .msg.selected { background: rgba(79, 70, 229, .1); }
.messages.selecting .msg.selected .select-box { background: var(--primary); border-color: var(--primary); position: relative; }
.messages.selecting .msg.selected .select-box::after { content: "✓"; color: #fff; font-size: 13px; font-weight: 800; position: absolute; inset: 0; display: grid; place-items: center; }
.messages.selecting .msg * { pointer-events: none; }
.select-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--primary-soft); border-top: 1px solid #d9dbfa; flex-wrap: wrap; }
.select-bar b { color: var(--primary); }
#c-select.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.convert-preview { max-height: 150px; overflow-y: auto; background: #f7f8fb; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 12px; display: grid; gap: 4px; }
.convert-preview div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* message actions: reply / edit / delete */
.msg-actions { display: flex; gap: 4px; align-self: center; opacity: 0; transition: opacity .15s; flex: none; }
.msg:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.msg-actions button { opacity: 1; border: 1px solid var(--line); background: #fff; color: var(--muted); border-radius: 50%; width: 30px; height: 30px; cursor: pointer; font-size: 13px; display: grid; place-items: center; padding: 0; }
.msg-actions button:hover { color: var(--primary); border-color: #c2c5f2; }
.msg-actions .msg-delete:hover { color: var(--danger); border-color: #f3c6cf; }
.messages.selecting .msg-actions { display: none; }
.edited { font-size: 11px; margin-left: 6px; opacity: .7; }
.receipt { font-size: 11px; margin-left: 8px; opacity: .75; }
.receipt.seen { opacity: 1; font-weight: 700; }
.msg.mine .receipt.seen { color: #c8f7d6; }
.edit-box textarea { min-width: 260px; margin-top: 4px; color: var(--text); }
.edit-actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 6px; }
.edit-actions small { flex: 1; }
.msg.mine .edit-actions small { color: rgba(255, 255, 255, .8); }
.msg.deleted .bubble { background: transparent !important; border: 1px dashed #c9ccd9 !important; color: var(--muted) !important; font-style: italic; }
.msg.deleted .meta, .msg.deleted .meta time { color: var(--muted) !important; }

/* internal notes */
.msg.internal .bubble, .msg.mine.internal .bubble { background: #fff8e1; border: 1px solid #f1d58a; color: var(--text); }
.msg.mine.internal .meta, .msg.mine.internal .meta time { color: #7a5b00; }
.internal-tag { background: #ffe9a8 !important; color: #7a5b00 !important; }
.msg.system.internal { background: #fff3cd; color: #7a5b00; }
.composer.internal { background: #fffbea; border-top-color: #f1d58a; }
.composer.internal textarea { background: transparent; }
.internal-btn.on { background: #ffe9a8; border-color: #e6c25c; color: #6b4f00; }

/* tags */
.tag-editor { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px; margin: 5px 0 12px; cursor: text; background: #fff; }
.tag-editor input { border: 0; padding: 3px; flex: 1; min-width: 80px; width: auto; }
.tag-editor input:focus { outline: none; }
.tag-chip { display: inline-flex; align-items: center; gap: 4px; background: #eef0ff; color: var(--primary); border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.tag-chip::before { content: "#"; opacity: .6; }
.tag-chip button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 2px; font-size: 11px; opacity: .7; }
.tag-chip button:hover { opacity: 1; color: var(--danger); }
.tag-chip.small { font-size: 11px; padding: 1px 6px; }
.t-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }

/* notices, merge */
.notice { background: #eef0ff; border: 1px solid #d9dbfa; color: #2e2a8f; padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 12px; }
.notice.merged { margin: 0; border-radius: 0; border-width: 0 0 1px; }
.merge-list { display: grid; gap: 6px; max-height: 340px; overflow-y: auto; }
.merge-item { display: flex; align-items: center; gap: 10px; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 10px 12px; cursor: pointer; font: inherit; font-size: 14px; }
.merge-item b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merge-item:hover { border-color: var(--primary); background: #fafaff; }

/* quick reply tabs, snippet */
.qr-tabs { margin-bottom: 16px; }
.qr-tabs span, .tabs button span { background: rgba(0, 0, 0, .07); border-radius: 8px; padding: 0 6px; margin-left: 4px; font-size: 11px; }
.snippet { background: #161a2d; color: #d7dbff; padding: 12px 14px; border-radius: 8px; font-size: 12px; white-space: pre-wrap; word-break: break-all; }

/* help center */
.kb-hero { background: linear-gradient(135deg, #4f46e5, #7c3aed); color: #fff; border-radius: 16px; padding: 32px 28px; margin-bottom: 20px; }
.kb-hero h2 { font-size: 24px; margin-bottom: 14px; }
.kb-hero input { max-width: 560px; padding: 13px 16px; font-size: 15px; border: 0; box-shadow: 0 4px 14px rgba(0, 0, 0, .15); }
.kb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.kb-card { padding: 16px; color: var(--text); display: flex; flex-direction: column; gap: 6px; transition: border-color .15s; }
.kb-card:hover { border-color: #c2c5f2; }
.kb-card p { margin: 0; font-size: 13px; }
.kb-cta { display: flex; gap: 10px; align-items: center; margin-top: 24px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: 4px; font-weight: 600; }
.kb-article h1 { font-size: 26px; margin: 10px 0 16px; }
.kb-meta { display: flex; gap: 8px; align-items: center; }
.md { font-size: 15px; line-height: 1.65; color: #2a2e40; }
.md h2, .md h3, .md h4 { margin: 20px 0 8px; }
.md p { margin: 0 0 12px; }
.md ul, .md ol { padding-left: 22px; margin: 0 0 12px; }
.md blockquote { margin: 0 0 12px; padding: 8px 14px; border-left: 4px solid var(--primary); background: #f6f6ff; border-radius: 0 8px 8px 0; }
.md pre { background: #161a2d; color: #e4e6ff; padding: 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; color: inherit; }
.kb-feedback, .kb-admin { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kb-preview { border: 1px dashed var(--line); border-radius: 8px; padding: 12px 16px; margin-bottom: 12px; max-height: 300px; overflow-y: auto; }
.kb-suggest { border: 1px solid #f1d58a; background: #fffbea; border-radius: 10px; padding: 8px; margin: -4px 0 12px; }
.kb-suggest-head { font-size: 12px; font-weight: 700; color: #7a5b00; padding: 2px 4px 6px; }
.kb-suggest-item { display: block; width: 100%; text-align: left; border: 0; background: #fff; border-radius: 7px; padding: 8px 10px; margin-top: 4px; cursor: pointer; font: inherit; font-size: 13px; }
.kb-suggest-item small { display: block; color: var(--muted); }
.kb-suggest-item:hover { background: var(--primary-soft); }

/* command palette + shortcuts */
.palette-modal { max-width: 620px; align-self: start; margin-top: 10vh; }
.palette input { font-size: 16px; padding: 12px 14px; }
.palette-list { max-height: 50vh; overflow-y: auto; margin-top: 8px; display: grid; gap: 2px; }
.palette-item { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; text-align: left; padding: 9px 10px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 14px; }
.palette-item .pi-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item small { color: var(--muted); text-transform: capitalize; }
.palette-item.active, .palette-item:hover { background: var(--primary-soft); }
.pi-ico { width: 20px; text-align: center; color: var(--muted); }
.palette-foot { display: flex; gap: 14px; font-size: 12px; color: var(--muted); padding-top: 10px; border-top: 1px solid var(--line); margin-top: 8px; }
.shortcut-list { display: grid; gap: 8px; }
.shortcut-list div { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; }
.shortcut-list small { color: var(--muted); text-align: right; }
.kb-focus { outline: 2px solid var(--primary); outline-offset: 2px; }

/* embedded chat widget mode (/?embed=1) */
html.embed body { background: #fff; }
html.embed .topbar { padding: 10px 12px; }
html.embed .topbar .brand { flex: 1; font-size: 15px; }
html.embed .topbar .brand img { width: 24px; height: 24px; }
html.embed .chat-layout { padding: 0; gap: 0; }
html.embed .chat-layout .card { border: 0; border-radius: 0; box-shadow: none; }
html.embed .composer-bar .hint { display: none; }
html.embed .composer-bar .btn.small { padding: 5px 8px; }
html.embed .login-card { box-shadow: none; padding: 20px; }
html.embed .login-page { background: #fff; align-items: start; }
html.embed #toasts { left: 10px; right: 10px; bottom: 10px; max-width: none; }
html.embed .msg { max-width: 92%; }
