.msg-main {
  display: flex;
  flex-direction: column;
}

.msg-head {
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-end;
}

.msg-head h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 4vw, 2.9rem);
  font-weight: 500;
  letter-spacing: -0.03em;
}

.msg-head p {
  margin: 0;
  color: #6b7280;
  font-size: 1.05rem;
}

.theme-dark .msg-head h1,
.theme-dark .msg-head p {
  color: #ffffff;
}

.theme-dark .msg-head p {
  color: #9ca3af;
}

.msg-mark-btn {
  border: 1px solid rgba(229, 231, 235, 0.85);
  background: #fff;
  color: #374151;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 0.84rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.msg-mark-btn:hover {
  background: #f9fafb;
}

.theme-dark .msg-mark-btn {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: #d1d5db;
}

.theme-dark .msg-mark-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.msg-layout {
  flex: 1;
  min-height: 500px;
  margin-bottom: 4px;
  display: flex;
  gap: 24px;
}

.msg-threads {
  width: 33.333%;
  min-width: 330px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 24px;
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.03);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.theme-dark .msg-threads,
.theme-dark .msg-chat {
  background: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.05);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.msg-threads-head {
  padding: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.62);
}

.msg-search-wrap {
  position: relative;
  margin-bottom: 10px;
}

.msg-search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
}

.msg-search-wrap input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  background: rgba(255, 255, 255, 0.5);
  padding: 10px 12px 10px 38px;
  font-size: 0.86rem;
  color: #111827;
}

.theme-dark .msg-search-wrap input {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.08);
  color: #f3f4f6;
}

.msg-search-wrap input:focus {
  outline: none;
  border-color: rgba(45, 212, 191, 0.9);
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.1);
}

.msg-filter-row {
  display: flex;
  gap: 8px;
}

.msg-filter-row button {
  border: 1px solid rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.65);
  color: #4b5563;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
}

.msg-filter-row button.active {
  background: #f0fdfa;
  border-color: #ccfbf1;
  color: #0f766e;
}

.theme-dark .msg-filter-row button {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.08);
  color: #9ca3af;
}

.theme-dark .msg-filter-row button.active {
  background: rgba(20, 184, 166, 0.1);
  border-color: rgba(20, 184, 166, 0.3);
  color: #2dd4bf;
}

.msg-thread-list {
  padding: 10px;
  overflow-y: auto;
  display: grid;
  gap: 6px;
}

.msg-thread-item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  text-align: left;
  cursor: pointer;
  position: relative;
}

.msg-thread-item:hover {
  background: rgba(255, 255, 255, 0.42);
  border-color: rgba(255, 255, 255, 0.62);
}

.theme-dark .msg-thread-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
}

.msg-thread-item.active {
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(255, 255, 255, 1);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
}

.theme-dark .msg-thread-item.active {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.12);
}

.msg-thread-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 4px;
  border-radius: 999px;
  background: #14b8a6;
}

.msg-thread-avatar-wrap {
  width: 44px;
  height: 44px;
  position: relative;
  flex-shrink: 0;
}

.msg-thread-avatar,
.msg-thread-avatar-fallback {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  object-fit: cover;
}

.msg-thread-avatar-fallback {
  background: linear-gradient(135deg, #c7d2fe, #e9d5ff);
  color: #4338ca;
  display: grid;
  place-items: center;
  font-size: 0.84rem;
  font-weight: 600;
}

.msg-thread-online {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 2px solid #fff;
  background: #22c55e;
}

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

.msg-thread-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.msg-thread-row h3 {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 500;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-dark .msg-thread-row h3,
.theme-dark .msg-chat-head h2 {
  color: #ffffff;
}

.msg-thread-row span {
  font-size: 0.72rem;
  color: #9ca3af;
  flex-shrink: 0;
}

.msg-thread-content p {
  margin: 0;
  color: #6b7280;
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-dark .msg-thread-content p,
.theme-dark .msg-thread-content small,
.theme-dark .msg-thread-row span {
  color: #9ca3af;
}

.msg-thread-content p.unread {
  color: #1f2937;
  font-weight: 500;
}

.msg-thread-content small {
  margin-top: 2px;
  display: inline-block;
  color: #9ca3af;
  font-size: 0.72rem;
}

.msg-thread-unread {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #14b8a6;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.64rem;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-chat {
  width: 66.667%;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 24px;
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.03);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.msg-chat-head {
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.62);
  background: rgba(255, 255, 255, 0.3);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.theme-dark .msg-chat-head {
  background: rgba(255, 255, 255, 0.03);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.msg-chat-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  color: #111827;
}

.msg-chat-company {
  display: flex;
  align-items: center;
  gap: 12px;
}

.msg-mobile-back-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid rgba(229, 231, 235, 0.85);
  background: rgba(255, 255, 255, 0.75);
  color: #374151;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.msg-mobile-back-btn:hover {
  background: #ffffff;
  color: #111827;
}

.theme-dark .msg-mobile-back-btn {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  color: #d1d5db;
}

.msg-chat-company p {
  margin: 2px 0 0;
  color: #0f766e;
  font-size: 0.74rem;
  font-weight: 500;
}

.theme-dark .msg-chat-company p {
  color: #2dd4bf;
}

.msg-chat-avatar,
.msg-chat-avatar-fallback {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  object-fit: cover;
}

.msg-chat-avatar-fallback {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #c7d2fe, #e9d5ff);
  color: #4338ca;
  font-size: 0.84rem;
  font-weight: 600;
}

.msg-chat-actions {
  display: flex;
  gap: 8px;
}

.msg-chat-actions button {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  background: rgba(255, 255, 255, 0.55);
  color: #4b5563;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.theme-dark .msg-chat-actions button {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
  color: #9ca3af;
}

.msg-chat-actions button:hover {
  background: #fff;
}

.msg-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: grid;
  align-content: start;
  gap: 10px;
  background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.2));
}

.theme-dark .msg-chat-body {
  background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.03));
}

.msg-day-sep {
  display: table;
  width: fit-content;
  margin: 0 auto;
  font-size: 0.72rem;
  color: #9ca3af;
  border: 1px solid rgba(255, 255, 255, 0.68);
  background: rgba(255, 255, 255, 0.52);
  padding: 3px 10px;
  border-radius: 999px;
}

.theme-dark .msg-day-sep {
  color: #9ca3af;
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
}

.msg-bubble-row {
  display: flex;
  gap: 8px;
  max-width: 75%;
}

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

.msg-mini-avatar,
.msg-mini-avatar-fallback {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  object-fit: cover;
  margin-top: auto;
}

.msg-mini-avatar-fallback {
  display: grid;
  place-items: center;
  background: #e5e7eb;
  color: #374151;
  font-size: 0.7rem;
  font-weight: 600;
}

.msg-bubble-wrap {
  display: grid;
  gap: 3px;
}

.msg-time {
  color: #9ca3af;
  font-size: 0.68rem;
}

.msg-bubble {
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 0.85);
  color: #374151;
  padding: 10px 12px;
  font-size: 0.84rem;
  line-height: 1.45;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.theme-dark .msg-bubble {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
}

.msg-bubble.mine {
  background: #14b8a6;
  border-color: #14b8a6;
  color: #fff;
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 6px;
}

.msg-input-area {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.62);
  background: rgba(255, 255, 255, 0.35);
}

.theme-dark .msg-input-area {
  border-top-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
}

.msg-input-wrap {
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
  padding: 6px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.theme-dark .msg-input-wrap {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
}

.theme-dark .msg-input-wrap textarea {
  color: #ffffff;
}

.msg-input-wrap > button {
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: #9ca3af;
  border-radius: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.msg-input-wrap > button:hover {
  color: #0f766e;
  background: #f0fdfa;
}

.msg-input-wrap textarea {
  flex: 1;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  padding: 8px;
  font-size: 0.84rem;
  color: #111827;
  max-height: 120px;
}

.msg-send-btn {
  min-width: 84px;
  width: auto;
  padding: 0 12px;
  border-radius: 10px;
  border: 0;
  background: #111827;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.msg-send-btn:hover {
  background: #1f2937;
}

@media (max-width: 1200px) {
  .msg-layout {
    flex-direction: column;
    min-height: 0;
  }

  .msg-threads,
  .msg-chat {
    width: 100%;
    min-width: 0;
  }

  .msg-threads {
    height: 360px;
  }

  .msg-chat {
    height: 500px;
  }
}

@media (max-width: 1000px) {
  .msg-layout {
    min-height: 0;
  }

  .msg-layout.mobile-threads .msg-threads,
  .msg-layout.mobile-chat .msg-chat {
    width: 100%;
    min-width: 0;
  }

  .msg-layout.mobile-threads .msg-threads {
    height: calc(100vh - 230px);
    min-height: 420px;
  }

  .msg-layout.mobile-chat .msg-chat {
    height: calc(100vh - 230px);
    min-height: 480px;
  }
}

@media (max-width: 860px) {
  .msg-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .msg-mark-btn {
    width: 100%;
    justify-content: center;
  }

  .msg-bubble-row {
    max-width: 88%;
  }
}
