/* AI OS readability layer for the pinned LibreChat v0.8.7 client. */
:root {
  --aios-readability-release: 'librechat-typography-20260908-r3';
  --aios-reading-width: 48rem;
}

/*
 * The locked v0.8.7 layout marks maximize mode with max-w-full and parallel
 * answers with sibling-content-group. Keep both native wide layouts intact.
 */
@media (min-width: 768px) {
  .message-render:not(.max-w-full):not(:has(.sibling-content-group)) {
    max-width: var(--aios-reading-width);
  }
  .message-render:not(.max-w-full):not(:has(.sibling-content-group)):has(.agent-turn table) {
    max-width: 60rem;
  }
}

.message-content {
  min-width: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: calc(var(--markdown-font-size, 1rem) * 0.9375);
  line-height: 1.5;
  letter-spacing: normal;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

.message-content.markdown > :first-child {
  margin-top: 0;
}

.message-content.markdown > :last-child {
  margin-bottom: 0;
}

.message-content.markdown p,
.message-content.markdown ul,
.message-content.markdown ol,
.message-content.markdown blockquote,
.message-content.markdown .markdown-table-wrapper,
.message-content.markdown pre {
  margin-top: 0.68em;
  margin-bottom: 0.68em;
}

.message-content.markdown li + li {
  margin-top: 0.22em;
}

.message-content.markdown h1,
.message-content.markdown h2,
.message-content.markdown h3,
.message-content.markdown h4 {
  margin-top: 1.15em;
  margin-bottom: 0.45em;
  line-height: 1.28;
  text-wrap: balance;
}

.message-content.markdown h1 {
  font-size: 1.5em;
}

.message-content.markdown h2 {
  font-size: 1.25em;
}

.message-content.markdown h3 {
  font-size: 1.18em;
}

.message-content.markdown h4 {
  font-size: 1em;
}

.message-content.markdown blockquote {
  border-inline-start: 3px solid var(--border-medium);
  color: var(--text-secondary);
  padding-inline-start: 1em;
}

.message-content.markdown a {
  text-underline-offset: 0.16em;
  overflow-wrap: anywhere;
}

.message-content pre,
.message-content pre code {
  line-height: 1.5;
  overflow-wrap: normal;
  word-break: normal;
}

.message-content pre {
  max-width: 100%;
  overflow-x: auto;
}

.markdown-table-wrapper {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.message-content.markdown table {
  width: 100%;
  min-width: 100%;
  max-width: none;
  margin: 0;
  table-layout: auto;
  border-collapse: collapse;
  border-spacing: 0;
  border: 0;
  background: transparent;
  font-size: 0.95em;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.message-content.markdown table :is(th, td) {
  border: 0;
  border-bottom: 1px solid var(--border-light);
  border-radius: 0;
  background: transparent;
  color: var(--text-primary);
  padding: 0.6rem 0.9rem;
  vertical-align: top;
  overflow-wrap: normal;
  word-break: normal;
  white-space: normal;
  min-width: 12ch;
  max-width: 36ch;
}

/* Markdown's explicit numeric alignment must not split a value and its unit. */
.message-content.markdown table :is(th, td):is([align='right'], [style*='text-align: right'], [style*='text-align:right']) {
  white-space: nowrap;
}

.message-content.markdown table th {
  border-bottom-color: var(--border-medium);
  font-weight: 600;
  padding-block: 0.55rem;
}

.message-content.markdown table :is(th, td):first-child {
  padding-inline-start: 0;
}

.message-content.markdown table :is(th, td):last-child {
  padding-inline-end: 0;
}

.message-content.markdown table tr:last-child td {
  border-bottom: 0;
}

.message-content.markdown :is(strong, b, h1, h2, h3, h4) {
  color: var(--text-primary);
  font-weight: 600;
}

.message-content.markdown li > p {
  margin-block: 0.3em;
}

.message-content.markdown table :is(p, ul, ol) {
  margin-block: 0.25em;
}

.m-auto.justify-center:has(> .message-render) {
  padding-block: 0.375rem;
}

.message-render:has(> .user-turn):not(:has(.sibling-content-group)) {
  justify-content: flex-end;
}

.message-render:not(:has(.sibling-content-group)) > .user-turn {
  flex: 0 1 auto;
  width: fit-content;
  max-width: 72%;
  min-width: 0;
  border-radius: 1rem;
  background: var(--surface-secondary);
  padding: 0.5rem 0.75rem 0.4rem;
}

.message-render:not(:has(.sibling-content-group)) > .agent-turn {
  padding-inline-start: 0;
  box-shadow: none;
}

.message-render:not(:has(.sibling-content-group)) > .user-turn > h2,
.message-render:not(:has(.sibling-content-group)) > .agent-turn > h2 {
  margin-bottom: 0;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  line-height: 1.25;
}

@media (hover: hover) and (pointer: fine) {
  .hover-button {
    opacity: 0.45;
    transition:
      opacity 140ms ease,
      background-color 140ms ease,
      color 140ms ease;
  }

  .message-render:hover .hover-button,
  .hover-button:hover,
  .hover-button:focus-visible {
    opacity: 1;
  }
}

.hover-button:focus-visible {
  outline: 2px solid var(--border-medium);
  outline-offset: 2px;
}

@media (max-width: 767px) {
  .message-render {
    gap: 0.6rem;
  }

  .message-content {
    font-size: max(1rem, var(--markdown-font-size, var(--font-size-base)));
    line-height: 1.5;
  }

  .message-render:not(:has(.sibling-content-group)) > .user-turn {
    max-width: 88%;
    padding: 0.5rem 0.7rem 0.4rem;
  }

  .message-render:not(:has(.sibling-content-group)) > .agent-turn {
    padding-inline-start: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hover-button {
    transition: none;
  }
}
