/* Parent–teacher Mail Center - live messaging UI */

.mail-center-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.btn-mail {
  position: relative;
}

body.pmc-open {
  overflow: hidden;
}

.pmc-root {
  position: fixed;
  inset: 0;
  z-index: 14000;
  display: flex;
  background: rgba(15, 23, 42, 0.45);
}

.pmc-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: var(--color-surface, #f8fafc);
  color: var(--color-text, #0f172a);
}

.pmc-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
}

.pmc-title {
  margin: 0;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.02em;
}

.pmc-subtitle {
  margin: 4px 0 0;
  color: var(--color-text-muted, #64748b);
  font-size: 0.88rem;
}

.pmc-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pmc-close,
.pmc-back {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pmc-close:hover,
.pmc-back:hover {
  background: rgba(15, 23, 42, 0.06);
}

.pmc-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
}

.pmc-body--single {
  grid-template-columns: 1fr;
}

.pmc-sidebar {
  border-right: 1px solid rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(255, 255, 255, 0.55);
}

.pmc-sidebar-head {
  padding: 14px 16px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted, #64748b);
}

.pmc-thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 16px;
  -webkit-overflow-scrolling: touch;
}

.pmc-thread {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 10px;
  border: none;
  border-radius: 14px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: inherit;
  margin-bottom: 2px;
  transition: background 0.15s ease;
}

.pmc-thread:hover {
  background: rgba(15, 23, 42, 0.05);
}

.pmc-thread.is-active {
  background: rgba(14, 165, 233, 0.12);
}

.pmc-thread.has-unread .pmc-thread-name {
  font-weight: 700;
}

.pmc-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  color: var(--color-text-muted, #64748b);
}

.pmc-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pmc-thread-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.pmc-thread-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.pmc-thread-name {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pmc-thread-time {
  font-size: 0.72rem;
  color: var(--color-text-muted, #64748b);
  flex-shrink: 0;
}

.pmc-thread-preview {
  font-size: 0.82rem;
  color: var(--color-text-muted, #64748b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pmc-thread-unread {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.pmc-main {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}

.pmc-empty-state,
.pmc-empty,
.pmc-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 24px;
  color: var(--color-text-muted, #64748b);
  text-align: center;
  flex: 1;
}

.pmc-empty-state i,
.pmc-empty--chat i {
  font-size: 2rem;
  opacity: 0.45;
}

.pmc-chat,
.pmc-compose {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.pmc-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
}

.pmc-chat-header .pmc-back {
  display: none;
}

.pmc-chat-header h3 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.pmc-chat-hint {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--color-text-muted, #64748b);
}

.pmc-chat-feed {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.pmc-day-sep {
  display: flex;
  justify-content: center;
  margin: 10px 0 4px;
}

.pmc-day-sep span {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted, #64748b);
  background: rgba(255, 255, 255, 0.8);
  padding: 4px 10px;
  border-radius: 999px;
}

.pmc-msg {
  max-width: min(520px, 88%);
  display: flex;
  flex-direction: column;
  animation: pmc-msg-in 0.18s ease-out;
}

@keyframes pmc-msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.pmc-msg--mine {
  align-self: flex-end;
}

.pmc-msg--theirs {
  align-self: flex-start;
}

.pmc-msg-bubble {
  padding: 10px 12px 8px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  line-height: 1.45;
}

.pmc-msg--mine .pmc-msg-bubble {
  background: #0ea5e9;
  color: #fff;
  border-bottom-right-radius: 5px;
}

.pmc-msg--theirs .pmc-msg-bubble {
  border-bottom-left-radius: 5px;
}

.pmc-msg.is-sending .pmc-msg-bubble {
  opacity: 0.72;
}

.pmc-msg-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.pmc-msg-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
}

.pmc-msg-time {
  font-size: 0.68rem;
  opacity: 0.75;
}

.pmc-msg--mine .pmc-msg-time {
  color: rgba(255, 255, 255, 0.85);
}

.pmc-receipt {
  font-size: 0.72rem;
  line-height: 1;
  display: inline-flex;
}

.pmc-receipt--sent {
  opacity: 0.85;
}

.pmc-receipt--read {
  color: #fef08a;
}

.pmc-msg--theirs .pmc-receipt {
  display: none;
}

.pmc-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px 8px;
  font-size: 0.8rem;
  color: var(--color-text-muted, #64748b);
  flex-shrink: 0;
}

.pmc-typing.hidden {
  display: none;
}

.pmc-typing-dots {
  display: inline-flex;
  gap: 3px;
}

.pmc-typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  display: block;
  animation: pmc-dot 1.2s infinite ease-in-out;
}

.pmc-typing-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.pmc-typing-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pmc-dot {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.pmc-composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}

.pmc-input {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  padding: 11px 14px;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: #fff;
  color: inherit;
  font: inherit;
  line-height: 1.4;
}

.pmc-input:focus {
  outline: 2px solid rgba(14, 165, 233, 0.35);
  border-color: transparent;
}

.pmc-send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border-radius: 14px;
}

.pmc-compose-recipients {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
}

.pmc-compose-recipient-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.pmc-compose-count {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--color-text-muted, #64748b);
}

.pmc-compose-list {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 6px;
  align-content: start;
}

.pmc-compose-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.04);
  cursor: pointer;
  font-size: 0.92rem;
}

.pmc-compose-item:hover {
  background: rgba(15, 23, 42, 0.07);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 800px) {
  .pmc-body {
    grid-template-columns: 1fr;
  }

  .pmc-sidebar {
    min-height: 0;
  }

  .pmc-shell.pmc-thread-open .pmc-sidebar,
  .pmc-shell.pmc-thread-open .pmc-header-text,
  .pmc-shell.pmc-thread-open .pmc-compose-btn {
    display: none;
  }

  .pmc-shell:not(.pmc-thread-open) .pmc-main {
    display: none;
  }

  .pmc-chat-header .pmc-back {
    display: inline-flex;
  }

  .pmc-header {
    flex-wrap: wrap;
  }

  .pmc-msg {
    max-width: 92%;
  }

  .pmc-send span {
    display: none;
  }

  .pmc-send {
    width: 44px;
    justify-content: center;
    padding-inline: 0;
  }
}

html[data-theme="dark"] .pmc-shell,
:root:not([data-theme="light"]) .pmc-shell {
  background: #0b1220;
  color: #e2e8f0;
}

html[data-theme="dark"] .pmc-header,
html[data-theme="dark"] .pmc-chat-header,
html[data-theme="dark"] .pmc-composer,
html[data-theme="dark"] .pmc-sidebar,
:root:not([data-theme="light"]) .pmc-header,
:root:not([data-theme="light"]) .pmc-chat-header,
:root:not([data-theme="light"]) .pmc-composer,
:root:not([data-theme="light"]) .pmc-sidebar {
  background: rgba(15, 23, 42, 0.88);
}

html[data-theme="dark"] .pmc-main,
:root:not([data-theme="light"]) .pmc-main {
  background: linear-gradient(180deg, #0b1220 0%, #111827 100%);
}

html[data-theme="dark"] .pmc-input,
:root:not([data-theme="light"]) .pmc-input {
  background: #0f172a;
  border-color: rgba(148, 163, 184, 0.25);
  color: #e2e8f0;
}

html[data-theme="dark"] .pmc-msg--theirs .pmc-msg-bubble,
:root:not([data-theme="light"]) .pmc-msg--theirs .pmc-msg-bubble {
  background: #1e293b;
  color: #e2e8f0;
}

html[data-theme="dark"] .pmc-msg--mine .pmc-msg-bubble,
:root:not([data-theme="light"]) .pmc-msg--mine .pmc-msg-bubble {
  background: #0284c7;
}

html[data-theme="dark"] .pmc-thread.is-active,
:root:not([data-theme="light"]) .pmc-thread.is-active {
  background: rgba(14, 165, 233, 0.18);
}

html[data-theme="dark"] .pmc-day-sep span,
:root:not([data-theme="light"]) .pmc-day-sep span {
  background: rgba(30, 41, 59, 0.9);
}

html[data-theme="dark"] .pmc-compose-item,
:root:not([data-theme="light"]) .pmc-compose-item {
  background: rgba(148, 163, 184, 0.08);
}
