﻿:root {
  --chat-primary: #0d9488;
  --chat-primary-strong: #0f766e;
  --chat-surface: #ffffff;
  --chat-surface-soft: #f5f7fb;
  --chat-border: #e2e8f0;
  --chat-text: #0f172a;
  --chat-text-muted: #64748b;
  --chat-bubble-me: #0d9488;
  --chat-bubble-other: #ffffff;
  --chat-radius: 18px;
  --chat-shadow: 0 16px 40px rgba(15, 23, 42, 0.15);
}

.chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-strong));
  box-shadow: 0 12px 28px rgba(13, 148, 136, 0.38);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 10040;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-fab:hover {
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 16px 34px rgba(13, 148, 136, 0.45);
}

.chat-badge {
  position: absolute;
  top: -5px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
}

.chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: none;
  z-index: 10030;
}

.chat-overlay.is-visible {
  display: block;
}

.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 95px;
  width: min(440px, calc(100vw - 24px));
  height: min(78vh, 650px);
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 10035;
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
}

.chat-panel.hidden {
  display: none !important;
}

.chat-header {
  min-height: 64px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--chat-border);
  background: linear-gradient(120deg, #f0fdfa 0%, #f8fafc 70%);
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--chat-text);
  font-size: 15px;
  font-weight: 700;
  min-width: 0;
}

.chat-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #d1fae5;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-header-actions {
  display: flex;
  gap: 4px;
}

.chat-header-actions button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--chat-text-muted);
  font-size: 17px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-header-actions button:hover {
  border-color: #dbe4ef;
  background: rgba(255, 255, 255, 0.8);
  color: var(--chat-text);
}

.chat-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-surface-soft);
}

.nav-btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px;
  color: var(--chat-text-muted);
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.nav-btn:hover {
  border-color: #d7e4ef;
  background: #fff;
}

.nav-btn.active {
  border-color: #bfe7e2;
  background: #fff;
  color: var(--chat-primary-strong);
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.14);
}

.nav-badge {
  position: absolute;
  right: 11px;
  top: 9px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  font-size: 10px;
  color: #fff;
  background: #ef4444;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.chat-body-container {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #f8fafc;
}

.chat-view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: translateX(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-view.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.messages-list,
.users-list,
.conversations-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 14px;
}

.msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 90%;
  margin-bottom: 12px;
}

.msg-row.me {
  margin-left: auto;
  flex-direction: row-reverse;
}

.avatar-wrapper {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
  cursor: pointer;
  border: 1px solid #dbe4ef;
}

.avatar-wrapper img,
.msg-avatar,
.list-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.msg-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.msg-name {
  font-size: 12px;
  color: var(--chat-text-muted);
  font-weight: 700;
}

.msg-bubble {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #dde5ef;
  background: var(--chat-bubble-other);
  color: var(--chat-text);
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.me .msg-bubble {
  background: var(--chat-bubble-me);
  border-color: transparent;
  color: #fff;
}

.msg-meta {
  font-size: 11px;
  color: #8fa0b4;
}

.msg-row.me .msg-meta,
.msg-row.me .msg-name {
  text-align: right;
}

.user-item,
.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px;
  border-radius: 12px;
  cursor: pointer;
  border: 1px solid transparent;
  background: #fff;
  margin-bottom: 7px;
  transition: all 0.2s ease;
}

.user-item:hover,
.conv-item:hover {
  border-color: #d8e4f0;
  transform: translateY(-1px);
}

.user-item.offline {
  opacity: 0.68;
}

.user-status-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #10b981;
  right: 0;
  bottom: 0;
}

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

.item-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--chat-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-preview {
  font-size: 12px;
  color: var(--chat-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-footer {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-top: 1px solid var(--chat-border);
  background: #fff;
}

#chat-input {
  border: 1px solid #d6e1ed;
  border-radius: 999px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  min-width: 0;
}

#chat-input:focus {
  border-color: #8fd8d0;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.1);
}

#chat-form button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid #d6e1ed;
  background: #fff;
  color: var(--chat-primary-strong);
  cursor: pointer;
  display: grid;
  place-items: center;
}

#chat-form button:hover {
  background: #f0fdfa;
  border-color: #b4ebe4;
}

.emoji-trigger {
  font-size: 19px;
}

.search-bar {
  padding: 12px;
  border-bottom: 1px solid var(--chat-border);
  background: #fff;
}

.search-bar input {
  width: 100%;
  border: 1px solid #d6e1ed;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}

.search-bar input:focus {
  border-color: #8fd8d0;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.1);
}

.empty-state {
  color: #94a3b8;
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
}

.unread-badge {
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--chat-primary-strong);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.emoji-picker {
  position: absolute;
  left: 10px;
  bottom: 62px;
  width: min(360px, calc(100vw - 40px));
  max-width: calc(100vw - 20px);
  height: min(360px, 56vh);
  background: #fff;
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  box-shadow: 0 22px 40px rgba(2, 6, 23, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10060;
}

.emoji-picker,
.emoji-picker * {
  box-sizing: border-box;
}

.emoji-search-container {
  padding: 10px;
  border-bottom: 1px solid var(--chat-border);
  background: #f8fafc;
  max-width: 100%;
  overflow-x: hidden;
}

.emoji-search-input {
  width: 100%;
  border: 1px solid #d6e1ed;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}

.emoji-search-input:focus {
  border-color: #8fd8d0;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
}

.emoji-scroll-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  max-width: 100%;
}

.emoji-section + .emoji-section {
  margin-top: 12px;
}

.emoji-section {
  max-width: 100%;
  overflow-x: hidden;
}

.emoji-category-title {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7c8da3;
  margin: 0 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  overflow-x: hidden;
}

.emoji-btn {
  border: 0;
  background: transparent;
  font-size: 21px;
  border-radius: 10px;
  cursor: pointer;
  height: 34px;
  width: 100%;
  min-width: 0;
  line-height: 1;
}

.emoji-btn:hover {
  background: #eef2ff;
}

.emoji-empty {
  text-align: center;
  color: #94a3b8;
  font-size: 13px;
  margin-top: 16px;
}

.chat-notification-container {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10070;
}

.chat-toast {
  width: min(320px, calc(100vw - 30px));
  background: #fff;
  border: 1px solid var(--chat-border);
  border-left: 4px solid var(--chat-primary);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.16);
  cursor: pointer;
}

.chat-toast.fade-out {
  opacity: 0;
  transform: translateX(20px);
  transition: all 0.2s ease;
}

.toast-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.toast-content {
  min-width: 0;
  flex: 1;
}

.toast-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--chat-text);
}

.toast-msg {
  font-size: 12px;
  color: var(--chat-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast-close {
  border: 0;
  background: transparent;
  color: #94a3b8;
  font-size: 16px;
  cursor: pointer;
}

.chat-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10080;
}

.chat-modal.is-visible {
  display: flex;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.58);
  backdrop-filter: blur(1px);
}

.modal-content {
  position: relative;
  z-index: 1;
  width: min(360px, calc(100vw - 34px));
  max-height: min(500px, calc(100vh - 60px));
  border-radius: 14px;
  border: 1px solid var(--chat-border);
  background: #fff;
  padding: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-content img {
  width: 100%;
  max-height: calc(min(500px, calc(100vh - 60px)) - 20px);
  border-radius: 10px;
  object-fit: contain;
}

.modal-close {
  position: absolute;
  top: -38px;
  right: 2px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(15, 23, 42, 0.62);
  color: #fff;
  cursor: pointer;
}

.online-status {
  display: none;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .chat-panel {
    right: 14px;
    bottom: 82px;
    width: min(420px, calc(100vw - 20px));
    height: min(74vh, 620px);
  }
}

@media (max-width: 640px) {
  .chat-panel {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: 0;
  }

  .chat-fab {
    right: 14px;
    bottom: 14px;
    width: 54px;
    height: 54px;
  }

  .chat-footer {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .emoji-picker {
    left: 8px;
    right: 8px;
    width: auto;
    height: min(320px, 52vh);
  }

  .chat-notification-container {
    left: 10px;
    right: 10px;
  }

  .chat-toast {
    width: 100%;
  }
}
