*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg:          #16171a;
  --surface:     #1e2127;
  --surface-2:   #252830;
  --surface-3:   #2d3040;
  --border:      #2e3040;
  --border-soft: #252830;
  --text:        #dde1f0;
  --text-muted:  #6b6f85;
  --text-dim:    #4a4e62;
  --accent:      #2979ff;
  --accent-dim:  #1a3a6e;
  --green:       #22c55e;
  --green-dim:   #14532d;
  --orange:      #f59e0b;
  --orange-dim:  #78350f;
  --red:         #ef4444;
  --red-dim:     #7f1d1d;
  --blue:        #3b82f6;
  --sidebar-w:   200px;
  --header-h:    52px;
  --radius:      8px;
  --radius-sm:   5px;
}

html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }

/* ── Layout ────────────────────────────────────────────── */
.layout { display: flex; height: 100vh; }

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  left: 0; top: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 16px 18px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  letter-spacing: .02em;
}

.sidebar-nav { padding: 10px 8px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
  position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item svg { flex-shrink: 0; opacity: .8; }
.nav-item.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
}

.sidebar-bottom {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.sidebar-user { flex: 1; overflow: hidden; }
.sidebar-user-name {
  font-size: 12px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role { font-size: 11px; color: var(--text-muted); }
.sidebar-action {
  color: var(--text-muted); cursor: pointer; padding: 4px;
  border-radius: 4px; background: none; border: none;
}
.sidebar-action:hover { color: var(--text); background: var(--surface-2); }

/* ── Main content ──────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Page header ───────────────────────────────────────── */
.page-header {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  background: var(--surface);
  flex-shrink: 0;
}
.page-title { font-size: 16px; font-weight: 600; }
.page-header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ── Toolbar ───────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
  flex-shrink: 0;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  gap: 8px;
  max-width: 420px;
}
.search-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  padding: 6px 0;
}
.search-box input::placeholder { color: var(--text-muted); }
.search-box svg { color: var(--text-muted); flex-shrink: 0; }

.filter-tabs { display: flex; gap: 4px; margin-left: 4px; }
.ftab {
  padding: 5px 12px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: none;
  color: var(--text-muted);
  font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all .15s;
  text-decoration: none;
}
.ftab:hover { background: var(--surface-2); color: var(--text); }
.ftab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.ftab-count {
  display: inline-block;
  background: rgba(255,255,255,.15);
  border-radius: 8px;
  padding: 0 5px;
  font-size: 10px;
  margin-left: 4px;
}

/* ── Tickets list ──────────────────────────────────────── */
.tickets-list {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
.tickets-list::-webkit-scrollbar { width: 4px; }
.tickets-list::-webkit-scrollbar-track { background: transparent; }
.tickets-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.ticket-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background .12s;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}
.ticket-item:hover { background: var(--surface-2); }
.ticket-item.unread { border-left: 2px solid var(--accent); }

.ticket-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.ticket-body { flex: 1; min-width: 0; }
.ticket-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  flex-wrap: wrap;
}
.ticket-id { font-weight: 700; font-size: 12px; color: var(--text-muted); }
.ticket-user { font-weight: 600; font-size: 13px; }
.ticket-preview {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 500px;
}

.ticket-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
  min-width: 90px;
}
.ticket-time { font-size: 11px; color: var(--text-muted); }
.ticket-count {
  display: flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--text-muted);
}

.empty-state {
  display: flex; align-items: center; justify-content: center;
  height: 200px; color: var(--text-muted); flex-direction: column; gap: 8px;
}

/* ── Status / Tag badges ───────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .03em;
  white-space: nowrap;
}
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

.badge-new       { background: rgba(41,121,255,.15); color: #5b9eff; }
.badge-in_review { background: rgba(245,158,11,.15);  color: var(--orange); }
.badge-answered  { background: rgba(59,130,246,.15);  color: #93c5fd; }
.badge-published { background: rgba(34,197,94,.15);   color: var(--green); }
.badge-rejected  { background: rgba(100,116,139,.15); color: #94a3b8; }

.tag-sla { background: rgba(239,68,68,.15); color: var(--red); }

/* ── Detail / Chat page ────────────────────────────────── */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-header-left { display: flex; align-items: center; gap: 10px; }
.back-btn {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); cursor: pointer; text-decoration: none;
  transition: all .15s; flex-shrink: 0;
}
.back-btn:hover { background: var(--surface-3); color: var(--text); }

.chat-title { font-size: 14px; font-weight: 700; }
.chat-subtitle { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.chat-header-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 30px; height: 30px;
  border-radius: 6px;
  background: none;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); cursor: pointer;
  transition: all .15s; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.green { border-color: var(--green-dim); color: var(--green); }
.icon-btn.green:hover { background: var(--green-dim); }
.icon-btn.red { border-color: var(--red-dim); color: var(--red); }
.icon-btn.red:hover { background: var(--red-dim); }
.icon-btn.orange { border-color: var(--orange-dim); color: var(--orange); }
.icon-btn.orange:hover { background: var(--orange-dim); }

.action-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all .15s; text-decoration: none;
}
.action-btn:hover { background: var(--surface-3); color: var(--text); }
.action-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.action-btn.primary:hover { background: #1a63d9; }

/* ── User info bar ─────────────────────────────────────── */
.user-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 7px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.user-bar-item { display: flex; align-items: center; gap: 5px; }
.user-bar-val { color: var(--text); font-weight: 500; }

/* ── Messages ──────────────────────────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 640px;
}
.msg-row.user    { align-self: flex-start; }
.msg-row.support { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-3);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  flex-shrink: 0; align-self: flex-end;
}
.msg-row.support .msg-avatar { background: var(--accent-dim); color: var(--accent); }

/* Wrapper that sizes to the bubble content — controls overall bubble width */
.msg-content {
  width: fit-content;
  max-width: 460px;
  min-width: 72px;
}

.msg-bubble {
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  width: 100%;
  box-sizing: border-box;
}
.msg-row.user .msg-bubble {
  background: var(--surface-2);
  border-radius: 2px 12px 12px 12px;
}
.msg-row.support .msg-bubble {
  background: #1a3a6e;
  border-radius: 12px 2px 12px 12px;
}
.msg-sender {
  font-size: 11px; font-weight: 600; color: var(--text-muted); margin-bottom: 3px;
}
.msg-row.support .msg-sender { color: #5b9eff; }
.msg-time { font-size: 10px; color: var(--text-dim); margin-top: 4px; text-align: right; }

.msg-attachment {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-3);
  border-radius: 6px; padding: 6px 10px;
  font-size: 11px; color: var(--text-muted);
  margin-top: 4px;
}

.date-divider {
  align-self: center;
  font-size: 11px; color: var(--text-dim);
  background: var(--surface-2);
  border-radius: 10px; padding: 2px 10px;
  margin: 4px 0;
}

/* ── Publish panel ─────────────────────────────────────── */
.publish-panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  max-height: 0;
  transition: max-height .25s ease;
}
.publish-panel.open { max-height: 240px; }
.publish-inner { padding: 12px 20px; }
.publish-inner label {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em; display: block; margin-bottom: 6px;
}
.publish-inner textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 13px; padding: 8px 10px; resize: none; outline: none;
  font-family: inherit; line-height: 1.5;
}
.publish-inner textarea:focus { border-color: var(--accent); }
.publish-actions { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-end; }

/* ── Reply bar ─────────────────────────────────────────── */
.reply-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  flex-shrink: 0;
}
.reply-form { display: flex; align-items: flex-end; gap: 8px; }
.reply-input-wrap {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  transition: border .15s;
}
.reply-input-wrap:focus-within { border-color: var(--accent); }
.reply-input-wrap textarea {
  width: 100%; background: none; border: none; outline: none;
  color: var(--text); font-size: 13px; resize: none;
  font-family: inherit; line-height: 1.5; min-height: 20px; max-height: 100px;
  overflow-y: auto;
}
.reply-input-wrap textarea::placeholder { color: var(--text-muted); }
.reply-hint { font-size: 10px; color: var(--text-dim); margin-top: 3px; }
.send-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); border: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; cursor: pointer; transition: background .15s; flex-shrink: 0;
}
.send-btn:hover { background: #1a63d9; }
.send-btn:disabled { background: var(--surface-3); cursor: default; color: var(--text-dim); }

/* ── Alerts ────────────────────────────────────────────── */
.toast {
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-size: 12px; margin: 8px 20px 0;
}
.toast-success { background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.25); color: var(--green); }
.toast-error   { background: rgba(239,68,68,.12);  border: 1px solid rgba(239,68,68,.25);  color: var(--red); }

/* ── Ban badge ─────────────────────────────────────────── */
.badge-banned { background: rgba(239,68,68,.18); color: var(--red); }
.badge-closed { background: rgba(100,116,139,.15); color: #94a3b8; }

/* ── Message checkbox ──────────────────────────────────── */
.msg-checkbox-wrap {
  display: flex; align-items: flex-end; padding-bottom: 4px;
  cursor: pointer; opacity: 0; transition: opacity .15s;
  flex-shrink: 0;
}
.msg-row.user:hover .msg-checkbox-wrap,
.msg-checkbox-wrap:has(:checked) { opacity: 1; }
.msg-checkbox-wrap input[type="checkbox"] {
  width: 15px; height: 15px; cursor: pointer; accent-color: var(--accent);
}
.msg-bubble.published {
  border: 1px solid rgba(34,197,94,.25);
  background: rgba(34,197,94,.06);
}
.pub-tag {
  font-size: 10px; color: var(--green); margin-left: 6px;
}

/* ── Broadcast layout ──────────────────────────────────── */
.bc-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 20px;
  padding: 20px;
  height: calc(100vh - 52px);
  overflow: auto;
}
@media (max-width: 900px) { .bc-layout { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card h2 {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-muted); margin-bottom: 16px;
}

.bc-compose { align-self: start; }

.field label {
  display: block; font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 5px;
}
.field input, .field textarea, .field select {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 13px; padding: 8px 10px; outline: none; font-family: inherit;
}
.field textarea { resize: vertical; min-height: 100px; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }

.btn-row-inputs {
  display: flex; gap: 8px; margin-bottom: 8px;
}
.btn-row-inputs input { flex: 1; }

/* Broadcast preview */
.bc-preview {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-top: 16px;
}
.bc-preview-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-dim); margin-bottom: 10px;
}
.bc-preview-bubble {
  background: var(--surface-2); border-radius: 10px;
  padding: 10px 13px; font-size: 13px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
  color: var(--text); margin-bottom: 8px;
}
.preview-btn {
  background: var(--surface-3); border-radius: 6px;
  padding: 6px 12px; font-size: 12px; color: var(--accent);
  text-align: center; margin-bottom: 4px; cursor: pointer;
}

/* History */
.bc-history { overflow-y: auto; max-height: calc(100vh - 130px); }
.bc-history-list { display: flex; flex-direction: column; gap: 10px; }
.bc-history-item {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px;
}
.bc-history-top { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.bc-history-text { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.bc-history-stats {
  display: flex; align-items: center; gap: 10px; font-size: 12px; flex-wrap: wrap;
}

.bc-status {
  display: inline-block; padding: 1px 8px; border-radius: 10px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.bc-status-pending { background: rgba(100,116,139,.15); color: #94a3b8; }
.bc-status-running { background: rgba(245,158,11,.15);  color: var(--orange); }
.bc-status-done    { background: rgba(34,197,94,.15);   color: var(--green); }
.bc-status-failed  { background: rgba(239,68,68,.15);   color: var(--red); }

.bc-progress-wrap {
  flex: 1; min-width: 80px; height: 4px;
  background: var(--surface-3); border-radius: 2px; overflow: hidden;
}
.bc-progress-bar {
  height: 100%; background: var(--accent);
  border-radius: 2px; transition: width .5s ease;
}
.bc-live-label { font-size: 11px; color: var(--text-muted); }

/* ── Login ─────────────────────────────────────────────── */
.login-page {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
}
.login-logo { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.login-sub  { font-size: 12px; color: var(--text-muted); margin-bottom: 28px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11px; font-weight: 600; color: var(--text-muted);
               text-transform: uppercase; letter-spacing: .06em; margin-bottom: 5px; }
.field input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 13px; padding: 8px 12px; outline: none; font-family: inherit;
}
.field input:focus { border-color: var(--accent); }
.login-btn {
  width: 100%; margin-top: 8px; padding: 9px;
  background: var(--accent); border: none; border-radius: var(--radius-sm);
  color: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.login-btn:hover { background: #1a63d9; }

/* ── Media in chat ─────────────────────────────────────────── */
.msg-media {
  max-width: 100%; max-height: 260px;
  border-radius: 8px; display: block; margin-top: 6px;
  cursor: pointer; background: var(--surface-3);
}
video.msg-media { max-height: 200px; width: 100%; }

/* ── Message action buttons (broadcast + copy) ─────────────── */
.msg-actions {
  display: flex; gap: 5px; margin-top: 5px;
  flex-wrap: wrap;
  opacity: 0; transition: opacity .15s;
}
.msg-row.user:hover .msg-actions { opacity: 1; }

.msg-bc-btn {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; color: var(--accent);
  background: none; border: 1px solid var(--accent-dim);
  border-radius: 4px; padding: 2px 7px;
  cursor: pointer; font-family: inherit;
  transition: background .15s;
}
.msg-bc-btn:hover { background: var(--accent-dim); }

.copy-fid-btn {
  display: inline-flex; align-items: center; gap: 3px;
  background: none; border: 1px solid var(--border);
  border-radius: 4px; color: var(--text-dim); cursor: pointer;
  font-size: 10px; padding: 2px 7px; font-family: inherit;
  transition: all .15s;
}
.copy-fid-btn:hover { color: var(--text); background: var(--surface-3); }

/* ── Broadcast extra statuses ──────────────────────────────── */
.bc-status-paused    { background: rgba(245,158,11,.15); color: var(--orange); }
.bc-status-scheduled { background: rgba(59,130,246,.15);  color: var(--blue); }

/* ── Pause/Resume button in broadcast history ──────────────── */
.bc-ctrl-btn {
  background: none; border: 1px solid var(--border);
  border-radius: 4px; color: var(--text-muted);
  font-size: 10px; padding: 2px 8px; cursor: pointer;
  margin-left: auto; font-family: inherit;
  transition: all .15s;
}
.bc-ctrl-btn:hover { background: var(--surface-3); color: var(--text); }
.bc-ctrl-btn:disabled { opacity: .5; cursor: default; }
