.site-mailbox-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 0;
  background: none;
  color: #2563eb;
  font: inherit;
  font-size: inherit;
  font-weight: 500;
  line-height: 1.35;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  vertical-align: middle;
}

.site-mailbox-link:hover:not(:disabled) {
  color: #2563eb;
  text-decoration: underline;
}

.site-mailbox-link:disabled {
  color: #94a3b8;
  cursor: not-allowed;
  opacity: 0.85;
}

.site-mailbox-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
}

.site-mailbox-badge[hidden] {
  display: none;
}

body.user-mailbox-open {
  overflow: hidden;
}

.user-mailbox-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.user-mailbox-modal[hidden] {
  display: none;
}

.user-mailbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.user-mailbox-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 28rem);
  max-height: min(85vh, 34rem);
  border-radius: 14px;
  border: 1px solid var(--theme-border);
  background: var(--theme-bg-elevated);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.2);
  overflow: hidden;
}

.user-mailbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--theme-border);
}

.user-mailbox-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--theme-text-heading);
}

.user-mailbox-close {
  border: 0;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--theme-text-muted);
  cursor: pointer;
}

.user-mailbox-chat {
  flex: 1;
  min-height: 12rem;
  max-height: 22rem;
  overflow-y: auto;
  padding: 0.85rem;
  background: var(--theme-bg, #f8fafc);
}

.user-mailbox-empty {
  margin: 0;
  text-align: center;
  color: var(--theme-text-muted);
  font-size: 0.85rem;
}

.user-mailbox-bubble-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.75rem;
  max-width: 92%;
}

.user-mailbox-bubble-row--mine {
  align-self: flex-end;
  align-items: flex-end;
}

.user-mailbox-bubble-row--theirs {
  align-self: flex-start;
  align-items: flex-start;
}

.user-mailbox-bubble-meta {
  margin-bottom: 0.2rem;
  font-size: 0.68rem;
  color: var(--theme-text-muted);
}

.user-mailbox-bubble {
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  font-size: 0.86rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.user-mailbox-bubble-row--mine .user-mailbox-bubble {
  background: #dbeafe;
  color: #1e3a8a;
  border-bottom-right-radius: 4px;
}

.user-mailbox-bubble-row--theirs .user-mailbox-bubble {
  background: var(--theme-bg-elevated);
  border: 1px solid var(--theme-border);
  color: var(--theme-text-secondary);
  border-bottom-left-radius: 4px;
}

.user-mailbox-compose {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--theme-border);
}

.user-mailbox-compose textarea {
  width: 100%;
  min-height: 4.5rem;
  resize: vertical;
  border: 1px solid var(--theme-border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  font-size: 0.86rem;
  background: var(--theme-bg);
  color: var(--theme-text);
}

.user-mailbox-compose-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.user-mailbox-msg {
  margin: 0;
  font-size: 0.78rem;
}

.btn-mailbox-send {
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  background: var(--theme-accent, #2563eb);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-mailbox-send:disabled {
  opacity: 0.6;
  cursor: wait;
}

html[data-theme="dark"] .user-mailbox-bubble-row--mine .user-mailbox-bubble {
  background: #1e3a8a;
  color: #dbeafe;
}

.admin-mailbox-shell {
  display: grid;
  grid-template-columns: minmax(12rem, 16rem) 1fr;
  gap: 1rem;
  min-height: 28rem;
}

.admin-mailbox-threads {
  border: 1px solid var(--theme-border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--theme-bg-elevated);
}

.admin-mailbox-thread-list {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 32rem;
  overflow-y: auto;
}

.admin-mailbox-thread-btn {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--theme-border);
  background: transparent;
  text-align: left;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  color: inherit;
}

.admin-mailbox-thread-btn.is-active,
.admin-mailbox-thread-btn:hover {
  background: var(--theme-bg-muted, #f1f5f9);
}

.admin-mailbox-thread-btn.has-unread {
  border-left: 3px solid #dc2626;
  animation: admin-mailbox-thread-blink 1.2s ease-in-out infinite;
}

@keyframes admin-mailbox-thread-blink {
  0%,
  100% {
    background: transparent;
  }
  50% {
    background: rgba(220, 38, 38, 0.08);
  }
}

.admin-mailbox-thread-name {
  display: block;
  font-size: 0.84rem;
  font-weight: 700;
}

.admin-mailbox-thread-preview {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.72rem;
  color: var(--theme-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-mailbox-thread-unread {
  display: inline-block;
  margin-left: 0.35rem;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1rem;
  text-align: center;
}

.admin-mailbox-chat-panel {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--theme-border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--theme-bg-elevated);
}

.admin-mailbox-chat-head {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--theme-border);
  font-size: 0.86rem;
  font-weight: 700;
}

.admin-mailbox-chat {
  flex: 1;
  min-height: 16rem;
  max-height: 24rem;
  overflow-y: auto;
  padding: 0.85rem;
  background: var(--theme-bg, #f8fafc);
}

.admin-mailbox-compose {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--theme-border);
}

.admin-mailbox-compose textarea {
  width: 100%;
  min-height: 4rem;
  resize: vertical;
  border: 1px solid var(--theme-border);
  border-radius: 8px;
  padding: 0.5rem;
  font: inherit;
  font-size: 0.84rem;
}

@media (max-width: 720px) {
  .admin-mailbox-shell {
    grid-template-columns: 1fr;
  }
}

.admin-feedback-reply-panel {
  width: min(100%, 34rem);
  max-height: min(88vh, 40rem);
}

.admin-feedback-reply-panel .user-mailbox-header {
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
}

.admin-feedback-reply-mailbox-link {
  margin-right: auto;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--theme-accent, #2563eb);
  text-decoration: none;
}

.admin-feedback-reply-mailbox-link:hover {
  text-decoration: underline;
}

.admin-feedback-reply-chat {
  min-height: 14rem;
  max-height: 22rem;
}

.btn-admin-feedback-reply {
  display: block;
  width: 100%;
  margin-bottom: 0.35rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--theme-accent, #2563eb);
  border-radius: 6px;
  background: var(--theme-accent, #2563eb);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-admin-feedback-reply:hover {
  filter: brightness(1.05);
}

body.user-mailbox-open .admin-feedback-reply-modal {
  z-index: 1300;
}
