/* ── Messages / Communication Dashboard ─────────────────────────────────── */

.msg-page {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

/* Flash */
.msg-page .flash {
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 20px;
}
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error   { background: var(--danger-bg);  color: var(--danger); }

/* Header */
.msg-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.msg-kicker {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brand);
  margin-bottom: 4px;
}
.msg-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.msg-lead {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
}
.msg-header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Buttons */
.msg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.msg-btn-primary {
  background: var(--brand);
  color: #fff;
}
.msg-btn-primary:hover { background: #2e7fc0; }
.msg-btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
}
.msg-btn-secondary:hover { background: var(--card-soft); }
.msg-btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(139,58,74,0.15);
}
.msg-btn-danger:hover { background: #ecdbe0; }

/* Tags */
.msg-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.msg-tag-closed {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Empty state */
.msg-empty {
  text-align: center;
  padding: 60px 20px;
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--line);
}
.msg-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}
.msg-empty p {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 18px;
}

/* Thread list */
.msg-thread-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
}
.msg-thread-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  text-decoration: none;
  color: inherit;
  transition: background 0.12s ease;
  border-bottom: 1px solid var(--line);
}
.msg-thread-item:last-child { border-bottom: none; }
.msg-thread-item:hover { background: var(--card-soft); }
.msg-thread-item.unread { background: rgba(58,143,212,0.04); }
.msg-thread-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.msg-thread-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--card-soft);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--brand);
  flex-shrink: 0;
}
.msg-thread-info { min-width: 0; }
.msg-thread-subject {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.unread .msg-thread-subject { color: var(--brand); }
.msg-thread-meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}
.msg-thread-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.msg-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.msg-chevron {
  font-size: 20px;
  color: var(--muted);
  opacity: 0.5;
}

/* New thread form */
.msg-form {
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 28px;
}
.msg-field {
  margin-bottom: 20px;
}
.msg-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}
.msg-field input,
.msg-field textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--ink);
  resize: vertical;
  transition: border-color 0.15s ease;
}
.msg-field input:focus,
.msg-field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(58,143,212,0.12);
}
.msg-form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Conversation / thread messages */
.msg-conversation {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 20px;
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--line);
  margin-bottom: 20px;
}
.msg-bubble {
  max-width: 80%;
  padding: 14px 18px;
  border-radius: 14px;
  position: relative;
}
.msg-bubble-mine {
  align-self: flex-end;
  background: var(--brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-bubble-other {
  align-self: flex-start;
  background: var(--card-soft);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.msg-bubble-staff.msg-bubble-other {
  background: linear-gradient(135deg, #f0f7fc, #e4f3f9);
  border-color: rgba(42,125,156,0.2);
}
.msg-bubble-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.msg-bubble-mine .msg-bubble-header { color: rgba(255,255,255,0.85); }
.msg-bubble-other .msg-bubble-header { color: var(--muted); }
.msg-bubble-header strong {
  font-size: 12.5px;
}
.msg-bubble-mine .msg-bubble-header strong { color: #fff; }
.msg-bubble-other .msg-bubble-header strong { color: var(--ink); }
.msg-role-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.msg-bubble-mine .msg-role-badge {
  background: rgba(255,255,255,0.2);
  color: #fff;
}
.msg-bubble-other .msg-role-badge {
  background: var(--success-bg);
  color: var(--success);
}
.msg-bubble-time {
  font-size: 11px;
  opacity: 0.7;
}
.msg-bubble-body {
  font-size: 14px;
  line-height: 1.55;
}

/* Reply form */
.msg-reply-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.msg-reply-input {
  flex: 1;
  padding: 12px 14px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  resize: vertical;
  min-height: 48px;
}
.msg-reply-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(58,143,212,0.12);
}

/* Closed notice */
.msg-closed-notice {
  text-align: center;
  padding: 16px;
  font-size: 13.5px;
  color: var(--muted);
  background: var(--card-soft);
  border-radius: 10px;
  border: 1px solid var(--line);
}

/* Nav badge (reuse from other pages) */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  margin-left: 4px;
}

/* Login required */
.msg-login-required {
  text-align: center;
  padding: 80px 24px;
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--line);
  margin-top: 40px;
}
.msg-login-icon {
  font-size: 52px;
  margin-bottom: 16px;
}
.msg-login-required h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}
.msg-login-required p {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 24px;
}
.msg-login-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .msg-page { padding: 16px 10px 40px; }
  .msg-header { flex-direction: column; gap: 12px; }
  .msg-title { font-size: 18px; }
  .msg-thread-item { padding: 12px 14px; }
  .msg-bubble { max-width: 92%; }
  .msg-conversation { max-height: 50vh; padding: 14px; }
  .msg-reply-form { flex-direction: column; }
  .msg-reply-form .msg-btn { width: 100%; justify-content: center; }
  .msg-form { padding: 20px; }
}
