.messages-shell,
.inspection-shell {
  width: calc(100% - 2rem);
  margin: 0 auto;
  padding: 1rem 0 2rem;
}

.messages-header,
.inspection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.messages-header h1,
.inspection-header h1,
.messages-header p,
.inspection-header p {
  margin: 0;
}

.messages-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.messages-eyebrow {
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.messages-muted {
  color: var(--muted);
}

.privacy-notice,
.inspection-warning {
  margin-bottom: 1rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--warning);
  border-radius: 1rem;
  background: color-mix(in srgb, var(--warning) 10%, var(--surface));
}

.privacy-notice h2,
.privacy-notice p,
.inspection-warning h2,
.inspection-warning p {
  margin: 0;
}

.privacy-notice p,
.inspection-warning p {
  margin-top: 0.35rem;
  line-height: 1.5;
}

/* The conversation has a bounded height, so only its message list scrolls and
   the composer stays at the bottom of it however long the history grows. The
   header and privacy notice keep their natural size above it. */
.messages-layout {
  display: grid;
  height: 85vh;
  height: 85dvh;
  min-height: 24rem;
  grid-template-columns: minmax(16rem, 22rem) minmax(0, 1fr);
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.conversation-sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
}

.conversation-sidebar h2 {
  margin: 0;
  font-size: 1rem;
}

.compact-search {
  gap: 0.55rem;
}

.dm-user-results,
.conversation-list,
.inspection-user-results {
  display: grid;
  gap: 0.45rem;
}

.conversation-list {
  min-height: 0;
  overflow-y: auto;
}

.dm-user-button,
.conversation-button,
.inspection-user-button {
  display: grid;
  width: 100%;
  gap: 0.2rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--bg);
  color: var(--text);
  text-align: left;
}

.dm-user-button:hover,
.conversation-button:hover,
.inspection-user-button:hover,
.conversation-button.active {
  border-color: var(--accent);
}

.conversation-button.active {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface-2));
}

.conversation-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.conversation-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-badge {
  display: inline-grid;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  place-items: center;
  font-size: 0.72rem;
  font-weight: 800;
}

.conversation-preview {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.conversation-header {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}

.conversation-header h2,
.conversation-header p {
  margin: 0;
}

.dm-empty-state {
  display: grid;
  padding: 2rem;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.dm-message-list,
.inspection-message-list {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 0.7rem;
  padding: 1rem 1.2rem;
  overflow-y: auto;
}

.dm-message {
  display: grid;
  max-width: min(42rem, 84%);
  gap: 0.25rem;
  align-self: flex-start;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.9rem 0.9rem 0.9rem 0.25rem;
  background: var(--surface-2);
}

.dm-message.outgoing {
  align-self: flex-end;
  border-radius: 0.9rem 0.9rem 0.25rem 0.9rem;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
}

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

.dm-message-meta {
  color: var(--muted);
  font-size: 0.72rem;
}

.dm-message-actions {
  display: flex;
  justify-content: flex-end;
}

.dm-message.deleted .dm-message-actions {
  display: none;
}

.dm-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  padding: 1rem 1.2rem;
  border-top: 1px solid var(--border);
}

.dm-composer textarea {
  min-height: 3.5rem;
  max-height: 12rem;
  resize: vertical;
}

#dm-load-older,
#inspection-load-older {
  align-self: center;
}

.inspection-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
}

.inspection-form .full-width {
  grid-column: 1 / -1;
}

.selected-user {
  min-height: 2.8rem;
  padding: 0.7rem;
  border: 1px dashed var(--border);
  border-radius: 0.75rem;
  color: var(--muted);
}

.selected-user.has-user {
  border-style: solid;
  color: var(--text);
  font-weight: 700;
}

.inspection-results {
  min-height: 24rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
  overflow: hidden;
}

.inspection-results-header {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}

.inspection-results-header h2,
.inspection-results-header p {
  margin: 0;
}

@media (max-width: 48rem) {
  .messages-layout {
    height: auto;
    grid-template-columns: 1fr;
  }

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

  .conversation-main {
    height: 85vh;
    height: 85dvh;
    min-height: 24rem;
  }

  .inspection-form {
    grid-template-columns: 1fr;
  }

  .inspection-form .full-width {
    grid-column: auto;
  }
}

@media (max-width: 34rem) {
  .messages-shell,
  .inspection-shell {
    width: 100%;
    padding: 0;
  }

  .messages-header,
  .inspection-header,
  .privacy-notice,
  .inspection-warning,
  .messages-layout,
  .inspection-form,
  .inspection-results {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .messages-header,
  .inspection-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .messages-header-actions {
    width: 100%;
  }

  .messages-header-actions .secondary-button {
    flex: 1 1 auto;
    text-align: center;
  }

  .dm-message {
    max-width: 94%;
  }
}

/* Where the viewport is tall enough to fit everything, the page is exactly one
   viewport tall and the conversation takes the height left below the notice. */
@media (min-width: 48.0625rem) and (min-height: 56rem) {
  .messages-shell {
    display: flex;
    height: 100vh;
    height: 100dvh;
    flex-direction: column;
    padding-bottom: 1rem;
  }

  .messages-shell > * {
    flex-shrink: 0;
  }

  .messages-layout {
    flex: 1 1 0;
    height: auto;
  }
}
