:root {
  /* Messages card palette from platform.html. */
  --module-primary: #376e9d;
  --module-primary-dark: color-mix(in srgb, var(--module-primary) 78%, #000000);
  --module-primary-light: #e8f0f7;
  --module-on-light: var(--module-primary);
  --module-primary-border: color-mix(in srgb, var(--module-primary) 30%, #ffffff);
  --module-focus: var(--module-primary);
  --brand-green: var(--module-on-light);
  --brand-green-dark: var(--module-primary-dark);
  --brand-green-soft: var(--module-primary-light);
  --brand-green-border: var(--module-primary-border);
  --cream: #f7f3e8;
  --white: #ffffff;
  --text: #17211d;
  --muted: #66726b;
  --border: #d8ded9;
  --error: #b42318;
  --error-soft: #fff0ef;
  --shadow: 0 18px 48px color-mix(in srgb, var(--module-primary) 10%, transparent);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, #f7f3e8 0%, var(--module-primary-light) 100%);
}

button,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.nav {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand-logo {
  display: block;
  width: auto;
  height: 60px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.nav-links a {
  color: var(--brand-green);
  text-decoration: none;
  font-size: 14px;
  font-weight: 800;
}

.nav-links a.active {
  border-bottom: 2px solid var(--brand-green);
}

.logout-button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  color: var(--white);
  background: var(--brand-green);
  font-weight: 800;
  cursor: pointer;
}

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 42px 24px 72px;
}

.messages-hero {
  min-height: 210px;
  padding: 36px 40px;
  border-radius: 30px;
  color: var(--white);
  background: var(--brand-green);
  box-shadow: 0 24px 60px color-mix(in srgb, var(--module-primary) 20%, transparent);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  font-weight: 900;
}

.eyebrow {
  color: var(--module-primary-light);
}

.messages-hero h1 {
  margin: 0;
  font-size: clamp(36px, 5vw, 58px);
  line-height: 1;
}

.messages-hero p:not(.eyebrow) {
  max-width: 760px;
  margin: 16px 0 0;
  color: rgba(255, 255, 255, 0.92);
  line-height: 1.6;
}

.hero-link,
.primary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 900;
}

.hero-link {
  flex: 0 0 auto;
  padding: 12px 18px;
  border-radius: 999px;
  color: var(--brand-green);
  background: var(--white);
}

.notice {
  margin-top: 20px;
  padding: 13px 16px;
  border: 1px solid var(--module-primary-border);
  border-radius: 14px;
  color: var(--brand-green);
  background: var(--module-primary-light);
  font-size: 14px;
  font-weight: 700;
}

.notice.error {
  border-color: #efc3c0;
  color: var(--error);
  background: var(--error-soft);
}

.chat-shell {
  min-height: 640px;
  margin-top: 24px;
  display: grid;
  grid-template-columns: minmax(270px, 340px) minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--brand-green-border);
  border-radius: 28px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.conversation-sidebar {
  min-width: 0;
  border-right: 1px solid var(--border);
  background: #fbfcfa;
}

.sidebar-heading {
  min-height: 96px;
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-kicker {
  color: var(--muted);
}

.sidebar-heading h2 {
  margin: 0;
  color: var(--brand-green);
  font-size: 22px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--brand-green-border);
  border-radius: 50%;
  color: var(--brand-green);
  background: var(--brand-green-soft);
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
}

.icon-button:hover {
  background: color-mix(in srgb, var(--module-primary) 15%, #ffffff);
}

.conversations-list {
  max-height: 650px;
  overflow-y: auto;
}

.loading-copy,
.empty-list-copy {
  margin: 0;
  padding: 28px 20px;
  color: var(--muted);
  line-height: 1.55;
}

.conversation-item {
  width: 100%;
  padding: 16px 18px;
  border: 0;
  border-bottom: 1px solid #e8ece9;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
}

.conversation-item:hover {
  background: color-mix(in srgb, var(--module-primary-light) 55%, #ffffff);
}

.conversation-item.active {
  background: var(--brand-green-soft);
  box-shadow: inset 4px 0 0 var(--brand-green);
}

.sidebar-avatar,
.contact-avatar {
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--white);
  background: var(--brand-green);
  font-weight: 900;
}

.sidebar-avatar img,
.contact-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: inherit;
}

.sidebar-avatar {
  width: 46px;
  height: 46px;
  font-size: 14px;
}

.conversation-copy {
  min-width: 0;
}

.conversation-title-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.conversation-title {
  margin: 0;
  overflow: hidden;
  color: var(--brand-green-dark);
  font-size: 15px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
}

.conversation-preview {
  margin: 6px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-panel {
  min-width: 0;
  min-height: 640px;
  background: var(--white);
}

.empty-conversation-state {
  min-height: 640px;
  padding: 48px 28px;
  text-align: center;
  display: grid;
  place-content: center;
  justify-items: center;
}

.empty-icon {
  width: 76px;
  height: 76px;
  margin-bottom: 18px;
  border-radius: 50%;
  background: var(--brand-green-soft);
  display: grid;
  place-items: center;
  font-size: 34px;
}

.empty-conversation-state h2 {
  margin: 0;
  color: var(--brand-green);
}

.empty-conversation-state p {
  max-width: 480px;
  margin: 12px 0 20px;
  color: var(--muted);
  line-height: 1.6;
}

.primary-link {
  padding: 11px 17px;
  border-radius: 999px;
  color: var(--white);
  background: var(--brand-green);
}

.active-conversation {
  min-height: 640px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.conversation-header {
  min-height: 96px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.98);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.contact-summary {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.contact-avatar {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
}

.contact-summary h2 {
  margin: 0;
  color: var(--brand-green-dark);
  font-size: 20px;
}

.contact-summary p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.contact-email {
  display: inline-block;
  margin-top: 5px;
  color: var(--brand-green);
  font-size: 13px;
  font-weight: 800;
  word-break: break-all;
}

.connection-block {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.connection-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #9aa49e;
}

.connection-block.connected .connection-dot {
  background: #1d8f48;
  box-shadow: 0 0 0 4px rgba(29, 143, 72, 0.12);
}

.connection-block.connecting .connection-dot {
  background: #c08a13;
}

.connection-block.offline .connection-dot {
  background: var(--error);
}

.messages-list {
  min-height: 0;
  max-height: 500px;
  padding: 24px;
  overflow-y: auto;
  background:
    radial-gradient(circle at 10% 20%, color-mix(in srgb, var(--module-primary) 3.5%, transparent), transparent 28%),
    #f8faf8;
}

.message-history-control {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: -8px 0 16px;
  padding: 8px;
  display: flex;
  justify-content: center;
  background: linear-gradient(to bottom, rgba(248, 250, 248, 0.98), rgba(248, 250, 248, 0.82), transparent);
}

.message-history-control.loading,
.message-history-control.history-start {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.load-older-button {
  border: 1px solid var(--brand-green-border);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--brand-green);
  background: var(--white);
  font: inherit;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 16px color-mix(in srgb, var(--module-primary) 8%, transparent);
}

.load-older-button:hover {
  background: var(--brand-green-soft);
}

.load-older-button:focus-visible {
  outline: 3px solid var(--module-focus);
  outline-offset: 2px;
}

.messages-empty {
  min-height: 100%;
  padding: 50px 20px;
  color: var(--muted);
  text-align: center;
  display: grid;
  place-content: center;
}

.message-row {
  margin-bottom: 12px;
  display: flex;
}

.message-row.mine {
  justify-content: flex-end;
}

.message-bubble {
  max-width: min(72%, 620px);
  padding: 11px 14px 9px;
  border: 1px solid var(--border);
  border-radius: 18px 18px 18px 5px;
  background: var(--white);
  box-shadow: 0 6px 18px rgba(23, 33, 29, 0.05);
}

.message-row.mine .message-bubble {
  border-color: var(--brand-green);
  border-radius: 18px 18px 5px 18px;
  color: var(--white);
  background: var(--brand-green);
}

.message-sender {
  margin: 0 0 5px;
  color: var(--brand-green);
  font-size: 11px;
  font-weight: 900;
}

.message-row.mine .message-sender {
  color: rgba(255, 255, 255, 0.75);
}

.message-body {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.48;
}

.message-time {
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  text-align: right;
}

.message-row.mine .message-time {
  color: rgba(255, 255, 255, 0.7);
}

.message-composer {
  padding: 16px 18px 18px;
  border-top: 1px solid var(--border);
  background: var(--white);
}

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

.composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
}

#messageInput {
  width: 100%;
  min-height: 48px;
  max-height: 150px;
  padding: 13px 14px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text);
  background: #fbfcfa;
  outline: none;
  line-height: 1.45;
}

#messageInput:focus {
  border-color: var(--brand-green);
  box-shadow: 0 0 0 3px var(--module-focus);
}

.send-button {
  min-width: 92px;
  min-height: 48px;
  padding: 11px 18px;
  border: 0;
  border-radius: 999px;
  color: var(--white);
  background: var(--brand-green);
  font-weight: 900;
  cursor: pointer;
}

.send-button:hover:not(:disabled) {
  background: var(--brand-green-dark);
}

.send-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.composer-help {
  margin: 8px 4px 0;
  color: var(--muted);
  font-size: 11px;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .messages-hero {
    align-items: flex-start;
    flex-direction: column;
  }

  .chat-shell {
    grid-template-columns: 1fr;
  }

  .conversation-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .conversations-list {
    max-height: 290px;
  }

  .conversation-panel,
  .active-conversation,
  .empty-conversation-state {
    min-height: 560px;
  }

  .messages-list {
    max-height: 430px;
  }
}

@media (max-width: 640px) {
  .nav {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand-logo {
    height: 48px;
  }

  .page {
    padding: 26px 14px 50px;
  }

  .messages-hero {
    padding: 28px 24px;
    border-radius: 24px;
  }

  .chat-shell {
    border-radius: 22px;
  }

  .conversation-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .message-bubble {
    max-width: 88%;
  }

  .composer-row {
    grid-template-columns: 1fr;
  }

  .send-button {
    width: 100%;
  }
}

/* ============================================================
   MESSAGE DELIVERY / READ RECEIPTS
   ============================================================ */

.message-meta {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.message-meta .message-time {
  margin-top: 0;
}

.message-read-status {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.message-row.mine .message-read-status.sent {
  color: rgba(255, 255, 255, 0.64);
}

.message-row.mine .message-read-status.read {
  color: rgba(255, 255, 255, 0.96);
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--module-focus);
  outline-offset: 3px;
}
