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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #1a1a1a;
  height: 100vh;
}

/* Login */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: #f0f2f5;
}

.login-form {
  background: #fff;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  width: 340px;
}

.login-form h1 {
  font-size: 20px;
  margin-bottom: 24px;
  text-align: center;
  color: #2c3e50;
}

.login-form input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
}

.login-form input:focus { border-color: #5b9bd5; }

.login-form button {
  width: 100%;
  padding: 10px;
  background: #5b9bd5;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}

.login-form button:hover { background: #4a8bc4; }

.login-error {
  color: #e74c3c;
  font-size: 13px;
  margin-top: 8px;
  text-align: center;
}

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

/* Sidebar */
.sidebar {
  width: 340px;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 14px;
  border-bottom: 1px solid #e0e0e0;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
}

.operator-label {
  font-size: 11px;
  color: #999;
}

.search-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.sidebar-header input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

.sidebar-header input:focus { border-color: #5b9bd5; }

/* Chat list */
.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.15s;
}

.chat-item:hover { background: #f5f7fa; }
.chat-item.active { background: #e8f0fe; }

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #5b9bd5;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  margin-right: 10px;
}

.chat-avatar.vk { background: #5b9bd5; }
.chat-avatar.telegram { background: #0088cc; }

.chat-info {
  flex: 1;
  min-width: 0;
}

.chat-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 2px;
}

.chat-preview {
  font-size: 12px;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-preview .preview-sender {
  color: #5b9bd5;
  font-weight: 500;
}

.chat-meta {
  text-align: right;
  flex-shrink: 0;
  margin-left: 8px;
}

.chat-time {
  font-size: 11px;
  color: #999;
}

.chat-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  margin-top: 3px;
  color: #fff;
}

.chat-badge.vk { background: #5b9bd5; }
.chat-badge.telegram { background: #0088cc; }

/* Chat area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.chat-header-left .user-name-link {
  font-weight: 600;
  font-size: 14px;
  color: #2c3e50;
  border-bottom: 1px dashed #aaa;
}

.chat-header-left .user-name-link:hover {
  color: #5b9bd5;
  border-bottom-color: #5b9bd5;
}

.channel-tag {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 3px;
  color: #fff;
}

.channel-tag.vk { background: #5b9bd5; }
.channel-tag.telegram { background: #0088cc; }

.chat-header .placeholder {
  color: #999;
  font-weight: 400;
  font-size: 14px;
}

.toggle-bot-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}

.toggle-bot-btn:hover { background: #f5f5f5; }

.toggle-bot-btn.paused {
  border-color: #e74c3c;
  background: #fdf0ef;
}

.toggle-bot-btn.paused .bot-status { color: #e74c3c; }
.toggle-bot-btn.active .bot-status { color: #27ae60; }

.bot-icon { font-size: 16px; }

/* Chat body (messages + panel) */
.chat-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f7f8fa;
  display: flex;
  flex-direction: column;
}

.empty-state {
  text-align: center;
  color: #999;
  margin-top: 40%;
  font-size: 14px;
}

.msg-row {
  display: flex;
  margin-bottom: 3px;
}

.msg-row.in { justify-content: flex-start; }
.msg-row.out { justify-content: flex-end; }

.message {
  max-width: 55%;
  padding: 6px 10px 5px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.3;
  white-space: pre-wrap;
  word-wrap: break-word;
  text-align: left;
  display: inline-block;
}

.message .msg-text {
  margin: 0;
}

/* Date separator */
.date-separator {
  text-align: center;
  margin: 12px 0 8px;
  font-size: 12px;
  color: #999;
  position: relative;
}

.date-separator span {
  background: #f7f8fa;
  padding: 0 10px;
  position: relative;
  z-index: 1;
}

.date-separator::before {
  content: '';
  position: absolute;
  left: 20%;
  right: 20%;
  top: 50%;
  height: 1px;
  background: #e0e0e0;
}

.message.in {
  background: #e8f0fe;
  border-bottom-left-radius: 3px;
}

.message.out {
  border-bottom-right-radius: 3px;
}

.message.out.bot {
  background: #dcf8c6;
}

.message.out.operator {
  background: #fff3cd;
}

.message .msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 1px;
}

.message .msg-time {
  font-size: 10px;
  color: #999;
}

.message .msg-sender {
  font-size: 10px;
  color: #5b9bd5;
  font-weight: 500;
}

/* User panel */
.user-panel {
  width: 280px;
  border-left: 1px solid #e0e0e0;
  padding: 16px;
  background: #fff;
  overflow-y: auto;
}

.user-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.user-panel-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.close-panel {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
  padding: 0 4px;
}

.close-panel:hover { color: #333; }

.user-panel-links a {
  display: block;
  padding: 8px 0;
  color: #5b9bd5;
  text-decoration: none;
  font-size: 13px;
  border-bottom: 1px solid #f0f0f0;
}

.user-panel-links a:hover { color: #3a7bc8; }

/* Reply form */
.reply-form {
  display: flex;
  padding: 8px 14px;
  border-top: 1px solid #e0e0e0;
  background: #fff;
  gap: 8px;
  align-items: stretch;
}

.reply-form textarea {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  resize: none;
  min-height: 38px;
  max-height: 120px;
  font-family: inherit;
  line-height: 1.4;
}

.reply-form textarea:focus { border-color: #5b9bd5; }

.reply-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.reply-form button {
  padding: 8px 14px;
  background: #5b9bd5;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}

.reply-form button:hover { background: #4a8bc4; }

.enter-toggle {
  font-size: 10px;
  color: #999;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.enter-toggle:hover { color: #5b9bd5; }

/* Search results */
.search-result {
  padding: 8px 14px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
}

.search-result:hover { background: #f5f7fa; }

.search-result .sr-name {
  font-weight: 600;
  font-size: 12px;
}

.search-result .sr-text {
  font-size: 12px;
  color: #555;
  margin-top: 2px;
}

.search-result mark {
  background: #fff3a8;
  padding: 0 2px;
  border-radius: 2px;
}

/* Tags */
.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
  color: #fff;
  margin-right: 3px;
  margin-top: 2px;
}

/* Header tags (next to username) */
.header-tags {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

/* Chat tags in list */
.chat-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 2px;
}

/* User panel tags */
.user-panel-tags {
  margin-top: 16px;
}

.user-panel-tags h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.panel-tag-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  cursor: pointer;
  font-size: 12px;
}

.panel-tag-check {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 2px solid #ddd;
  flex-shrink: 0;
}

.panel-tag-check.checked {
  border-color: transparent;
  position: relative;
}

.panel-tag-check.checked::after {
  content: '✓';
  color: #fff;
  font-size: 10px;
  position: absolute;
  top: -1px;
  left: 1px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  width: 360px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 { font-size: 15px; }

.tag-manage-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
}

.tag-manage-item .tag-preview {
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  color: #fff;
  font-weight: 500;
}

.tag-manage-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.tag-manage-item .tag-btn {
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 14px;
  padding: 2px;
}

.tag-manage-item .tag-btn:hover { color: #333; }
.tag-manage-item .tag-btn.tag-del:hover { color: #e74c3c; }

.tag-edit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
}

.tag-edit-row input[type="text"] {
  flex: 1;
  padding: 4px 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 11px;
  outline: none;
}


.tag-edit-row .tag-save {
  padding: 3px 8px;
  background: #5b9bd5;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}

/* Filter bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  position: relative;
}

.filter-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.filter-icon-btn:hover { background: #f5f5f5; }
.filter-icon-btn.has-filter { border-color: #5b9bd5; background: #eef4fb; }

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  flex: 1;
}

.active-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
  color: #fff;
  cursor: pointer;
}

.active-filter-chip .chip-x {
  font-size: 12px;
  opacity: 0.7;
}

.active-filter-chip:hover .chip-x { opacity: 1; }

/* Filter popup */
.filter-popup {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 50;
  padding: 16px;
  margin-top: 4px;
}

.filter-popup h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

.fp-label {
  font-size: 12px;
  font-weight: 500;
  color: #555;
  margin-bottom: 4px;
}

.fp-select {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 10px;
  cursor: pointer;
}

.fp-select-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #333;
}

.fp-select-header .fp-arrow { color: #999; font-size: 10px; }

.fp-options {
  margin-top: 6px;
  display: none;
}

.fp-select.open .fp-options { display: block; }
.fp-select.open { border-color: #5b9bd5; }

.fp-option {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  cursor: pointer;
  font-size: 12px;
}

.fp-option:hover { color: #5b9bd5; }

.fp-check {
  width: 14px;
  height: 14px;
  border: 1.5px solid #ccc;
  border-radius: 3px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #fff;
}

.fp-check.checked {
  background: #5b9bd5;
  border-color: #5b9bd5;
}

.fp-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.fp-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.fp-btn {
  flex: 1;
  padding: 8px;
  border-radius: 6px;
  border: none;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}

.fp-btn.primary { background: #5b9bd5; color: #fff; }
.fp-btn.primary:hover { background: #4a8bc4; }
.fp-btn.secondary { background: #f0f0f0; color: #666; }
.fp-btn.secondary:hover { background: #e5e5e5; }

.fp-options-list {
  padding: 4px 0;
}

.fp-manage-link {
  display: block;
  font-size: 11px;
  color: #5b9bd5;
  cursor: pointer;
  margin-top: 6px;
  text-align: center;
}

.fp-manage-link:hover { text-decoration: underline; }

.add-tag-form {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  align-items: center;
}

.add-tag-form input[type="text"] {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 12px;
  outline: none;
}

.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.color-preview {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid #ddd;
  flex-shrink: 0;
}

.add-tag-form input.hex-input,
.tag-edit-row input.hex-input {
  width: 70px;
  padding: 4px 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
  outline: none;
}

.add-tag-form button {
  padding: 6px 12px;
  background: #5b9bd5;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.add-tag-form button:hover { background: #4a8bc4; }

/* Operators */
.operators-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0.6;
}

.operators-btn:hover { opacity: 1; background: #f0f0f0; }

.op-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
}

.op-item:last-child { border-bottom: none; }

.op-info { display: flex; flex-direction: column; gap: 2px; }
.op-info strong { font-size: 13px; }
.op-email { font-size: 11px; color: #999; }

.op-edit-name {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
  margin-right: 6px;
}

.op-edit-name:focus { border-color: #5b9bd5; }
