/*
  v6.5.34 Message card color, text wrapping, code wrapping, and mobile width guard.
  Narrow preservation patch. Loads after the prior Focus, Messenger, and Admin fixes.
*/

:root {
  --ab-message-atticus-bg: linear-gradient(135deg, rgba(20, 35, 32, .86), rgba(7, 12, 11, .82));
  --ab-message-atticus-line: color-mix(in srgb, var(--sage, #a5b5a5) 44%, transparent);
  --ab-message-user-bg: linear-gradient(135deg, rgba(54, 36, 22, .88), rgba(13, 9, 7, .82));
  --ab-message-user-line: color-mix(in srgb, var(--amber, #c77a4b) 58%, transparent);
  --ab-message-card-shadow: 0 14px 36px rgba(0, 0, 0, .22), inset 0 1px 0 rgba(255, 255, 255, .035);
}

/* -----------------------------
   Messenger and Focus cards: user and Atticus now read as real cards, not the same dark background.
   ----------------------------- */
body .stage > section.view.page-view.is-active[data-view="messenger"] .thread-body .message,
body .stage > section.view.focus-view.is-active[data-view="focus"] .response-content .focus-thread-slice .message,
body .stage > section.view.focus-view.is-active[data-view="focus"] .focus-message {
  min-width: 0 !important;
  max-width: min(900px, 86%) !important;
  box-shadow: var(--ab-message-card-shadow) !important;
}

body .stage > section.view.page-view.is-active[data-view="messenger"] .thread-body .message:not(.user),
body .stage > section.view.page-view.is-active[data-view="messenger"] .thread-body .message[data-message-role="assistant"],
body .stage > section.view.focus-view.is-active[data-view="focus"] .response-content .focus-thread-slice .message:not(.user),
body .stage > section.view.focus-view.is-active[data-view="focus"] .response-content .focus-thread-slice .message[data-message-role="assistant"],
body .stage > section.view.focus-view.is-active[data-view="focus"] .focus-message:not(.user),
body .stage > section.view.focus-view.is-active[data-view="focus"] .focus-message[data-message-role="assistant"] {
  border-color: color-mix(in srgb, var(--sage, #a5b5a5) 22%, transparent) !important;
  border-left: 2px solid var(--ab-message-atticus-line) !important;
  border-right: 1px solid color-mix(in srgb, var(--sage, #a5b5a5) 18%, transparent) !important;
  background: var(--ab-message-atticus-bg) !important;
}

body .stage > section.view.page-view.is-active[data-view="messenger"] .thread-body .message.user,
body .stage > section.view.focus-view.is-active[data-view="focus"] .response-content .focus-thread-slice .message.user,
body .stage > section.view.focus-view.is-active[data-view="focus"] .focus-message.user {
  border-color: color-mix(in srgb, var(--amber, #c77a4b) 24%, transparent) !important;
  border-left: 1px solid color-mix(in srgb, var(--amber, #c77a4b) 20%, transparent) !important;
  border-right: 2px solid var(--ab-message-user-line) !important;
  background: var(--ab-message-user-bg) !important;
}

body .stage > section.view.page-view.is-active[data-view="messenger"] .thread-body .message:not(.user) .message-name,
body .stage > section.view.focus-view.is-active[data-view="focus"] .response-content .focus-thread-slice .message:not(.user) .message-name,
body .stage > section.view.focus-view.is-active[data-view="focus"] .focus-message:not(.user) .message-name {
  color: color-mix(in srgb, var(--sage, #a5b5a5) 74%, var(--cream, #e4d6bd) 26%) !important;
}

body .stage > section.view.page-view.is-active[data-view="messenger"] .thread-body .message.user .message-name,
body .stage > section.view.focus-view.is-active[data-view="focus"] .response-content .focus-thread-slice .message.user .message-name,
body .stage > section.view.focus-view.is-active[data-view="focus"] .focus-message.user .message-name {
  color: color-mix(in srgb, var(--amber, #c77a4b) 72%, var(--cream, #e4d6bd) 28%) !important;
}

/* -----------------------------
   Text and code return/wrap fix: long returned text cannot force the app sideways.
   ----------------------------- */
.message,
.focus-message,
.message-text,
.rich-text,
.rich-text p,
.rich-text ul,
.rich-text ol,
.rich-text li,
.rich-heading,
.code-card,
.code-card-head,
.code-card pre,
.code-card code {
  min-width: 0 !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

.message-text,
.rich-text,
.rich-text p,
.rich-text li,
.rich-heading,
.rich-text code,
.code-card-head,
.code-card pre,
.code-card code {
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
}

.message-text,
.message-text > .rich-text,
.rich-text,
.code-card {
  width: 100% !important;
}

.rich-text p,
.rich-text ul,
.rich-text ol {
  max-width: 100% !important;
}

.rich-text code {
  white-space: normal !important;
}

.code-card {
  overflow: hidden !important;
}

.code-card-head span {
  min-width: 0 !important;
  overflow: hidden !important;
  overflow-wrap: anywhere !important;
  text-overflow: clip !important;
}

.code-card pre {
  width: 100% !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  white-space: pre-wrap !important;
}

.code-card code {
  display: block !important;
  width: 100% !important;
  white-space: inherit !important;
}

.message-image,
.message-image img,
.message-attachments,
.message-attachment,
.attachment-preview,
.attachment-preview img {
  min-width: 0 !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* -----------------------------
   Phone portrait guard: active views and their cards must stay inside the viewport.
   ----------------------------- */
@media (max-width: 900px) {
  html,
  body,
  .app,
  .shell,
  .stage {
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }

  body .stage > section.view.is-active,
  body .stage > section.view.page-view.is-active,
  body .stage > section.view.focus-view.is-active,
  body .stage > section.view.page-view.master-console-view.is-active {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }

  body .stage > section.view.focus-view.is-active[data-view="focus"],
  body .stage > section.view.page-view.is-active[data-view="messenger"] {
    padding-left: var(--mobile-content-pad, 12px) !important;
    padding-right: var(--mobile-content-pad, 12px) !important;
  }

  .page-header,
  .page-view > *,
  .focus-stage,
  .response,
  .response-content,
  .focus-console,
  .messenger-layout,
  .thread-list,
  .thread-main,
  .thread-head,
  .thread-body,
  .thread-compose,
  .dashboard-layout,
  .dashboard-grid-two,
  .atticus-dashboard,
  .abdash-panel,
  .panel,
  .system-card,
  .tools-layout,
  .apps-grid,
  .settings-layout,
  .settings-page-scroll,
  .settings-card,
  .file-explorer-layout,
  .contacts-directory,
  .master-console,
  .master-console-shell,
  .master-section-view,
  .master-section-card,
  .master-command-card,
  .master-rollup-card {
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  body .stage > section.view.page-view.is-active[data-view="messenger"] .thread-body .message,
  body .stage > section.view.focus-view.is-active[data-view="focus"] .response-content .focus-thread-slice .message,
  body .stage > section.view.focus-view.is-active[data-view="focus"] .focus-message {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  body .stage > section.view.page-view.is-active[data-view="messenger"] .thread-body .message.user,
  body .stage > section.view.focus-view.is-active[data-view="focus"] .response-content .focus-thread-slice .message.user,
  body .stage > section.view.focus-view.is-active[data-view="focus"] .focus-message.user {
    align-self: stretch !important;
    margin-left: 0 !important;
  }

  .terminal,
  .terminal textarea,
  .attachment-tray,
  .composer-actions,
  .focus-context-bar,
  .focus-context-selects {
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .focus-context-selects {
    overflow-x: auto !important;
    overflow-y: hidden !important;
  }
}

@media (max-width: 420px) {
  body .stage > section.view.focus-view.is-active[data-view="focus"],
  body .stage > section.view.page-view.is-active[data-view="messenger"] {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  .code-card pre {
    padding: 12px !important;
    font-size: 12px !important;
  }
}
