/* =============================================================================
   DM — Inbox · Conversation · Settings · New-DM modal
   All values sourced from static/css/tokens.css — no hex codes.
   ============================================================================= */

/* -----------------------------------------------------------------------------
   1. SHARED HEADER (used by list.html + settings.html)
   64px paper header, 3 slots: left · centered mono-caps title · right
----------------------------------------------------------------------------- */
.dm-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: 64px;
    padding: 0 var(--space-4);
    background: var(--surface-primary);
    border-bottom: 1px solid var(--border-default);
    flex-shrink: 0;
    position: relative;
    z-index: var(--z-sticky);
}

.dm-header__left,
.dm-header__right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
}

.dm-header__right { justify-content: flex-end; }

.dm-header__center {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dm-header__title {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--text-primary);
}

.dm-header__icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--size-10);
    height: var(--size-10);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
    text-decoration: none;
    transition: background var(--duration-fast) var(--ease-default),
                color var(--duration-fast) var(--ease-default);
}

.dm-header__icon-btn:hover {
    background: var(--interactive-hover);
    color: var(--text-primary);
}

/* -----------------------------------------------------------------------------
   2. SEARCH BAR (inbox)
----------------------------------------------------------------------------- */
.dm-search {
    padding: var(--space-3) var(--space-4);
    background: var(--surface-app);
    flex-shrink: 0;
}

.dm-search__field {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: var(--size-10);
    padding: 0 var(--space-4);
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    transition: box-shadow var(--duration-fast) var(--ease-default),
                border-color var(--duration-fast) var(--ease-default);
}

.dm-search__field:focus-within {
    border-color: var(--accent-tertiary);
    box-shadow: 0 0 0 3px var(--accent-tertiary-subtle);
}

.dm-search__icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

.dm-search__input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--text-primary);
    outline: none;
    min-width: 0;
}

.dm-search__input::placeholder { color: var(--text-muted); }

/* -----------------------------------------------------------------------------
   3. INBOX LIST
----------------------------------------------------------------------------- */
.dm-list {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: var(--surface-app);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.dm-list__rooms {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.dm-room-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-5);
    text-decoration: none;
    color: inherit;
    transition: background var(--duration-fast) var(--ease-default);
}

.dm-room-item:hover { background: var(--interactive-hover); }

.dm-room-item--hidden { display: none; }

/* Hairline separator starts after avatar (left:76px = 20 + 44 + 12) */
.dm-room-item + .dm-room-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 76px;
    right: var(--space-5);
    height: 1px;
    background: var(--border-soft);
}

.dm-room-item__avatar {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    position: relative;
}

.dm-room-item__avatar .profile-avatar,
.dm-room-item__avatar .profile-avatar__image {
    width: 44px !important;
    height: 44px !important;
}

.dm-room-item__info {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
    flex: 1;
}

.dm-room-item__name-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.dm-room-item__name {
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: var(--font-bold);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dm-room-item__kicker {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-2);
    background: var(--highlight-yellow);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: var(--font-bold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    border-radius: var(--radius-sm);
}

.dm-room-item__preview {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dm-room-item--unread {
    background: var(--accent-tertiary-subtle);
    border-left: 3px solid var(--accent-tertiary);
    padding-left: calc(var(--space-5) - 3px);
}

.dm-room-item--unread .dm-room-item__avatar::after {
    content: '';
    position: absolute;
    inset: -3px;
    border: 2px solid var(--accent-tertiary);
    border-radius: var(--radius-full);
    box-shadow: 0 0 0 3px var(--accent-tertiary-subtle);
    pointer-events: none;
}

.dm-room-item--unread .dm-room-item__name {
    color: var(--text-primary);
    font-weight: 800;
}

.dm-room-item--unread .dm-room-item__preview {
    color: var(--text-primary);
    font-weight: var(--font-bold);
}

.dm-room-item--unread .dm-room-item__time {
    color: var(--accent-tertiary);
    font-weight: var(--font-bold);
}

.dm-room-item__meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--space-1);
    flex-shrink: 0;
}

.dm-room-item__time {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

.dm-room-item__unread-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: var(--radius-full);
    background: var(--accent-tertiary);
    border: 2px solid var(--surface-primary);
    box-shadow: 0 0 0 3px var(--accent-tertiary-subtle);
}

.dm-room-item__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 var(--space-2);
    background: var(--accent-tertiary);
    color: var(--text-inverse);
    border-radius: var(--radius-full);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: var(--font-bold);
    box-shadow: 0 0 0 3px var(--accent-tertiary-subtle);
}

.dm-list__tail {
    padding: var(--space-6) var(--space-5);
    text-align: center;
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 13px;
    color: var(--text-muted);
}

.dm-list__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-12) var(--space-6);
    text-align: center;
}

.dm-list__empty-icon { color: var(--text-muted); }

.dm-list__empty-title {
    margin: 0;
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    color: var(--text-primary);
}

.dm-list__empty-text {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* Lock cover banner inside DM list (observer flow) — kill link underline */
.dm-list .lock-cover--banner { text-decoration: none; }

/* -----------------------------------------------------------------------------
   4. CONVERSATION PAGE
----------------------------------------------------------------------------- */
.dm-conversation {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
    position: relative;
    isolation: isolate;
    overflow: hidden;
    background: var(--surface-app);
}

.fullscreen-panel .dm-conversation {
    height: 100%;
    flex: 1;
}

/* ----- Conversation header (68px) ----- */
.dm-conversation__header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: 68px;
    padding: 0 var(--space-4);
    background: var(--surface-primary);
    border-bottom: 1px solid var(--border-default);
    flex-shrink: 0;
}

.dm-conversation__back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--size-10);
    height: var(--size-10);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-full);
    transition: background var(--duration-fast) var(--ease-default);
    flex-shrink: 0;
}

.dm-conversation__back:hover { background: var(--interactive-hover); color: var(--text-primary); }

.dm-conversation__user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex: 1;
    min-width: 0;
}

.dm-conversation__avatar-wrapper {
    position: relative;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
}

.dm-conversation__avatar-wrapper .profile-avatar,
.dm-conversation__avatar-wrapper .profile-avatar__image {
    width: 44px !important;
    height: 44px !important;
}

.dm-conversation__presence-dot {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 12px;
    height: 12px;
    background: var(--accent-primary);
    border: 2px solid var(--surface-primary);
    border-radius: var(--radius-full);
    z-index: var(--z-content);
}

.dm-conversation__user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.dm-conversation__name-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.dm-conversation__name {
    font-family: var(--font-heading);
    font-size: var(--text-base);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dm-conversation__kicker {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-2);
    background: var(--highlight-yellow);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: var(--font-bold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    border-radius: var(--radius-sm);
}

.dm-conversation__presence {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

.dm-conversation__header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-shrink: 0;
}

.dm-conversation__icon-btn,
.dm-conversation__add-friend {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--size-10);
    height: var(--size-10);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-default),
                color var(--duration-fast) var(--ease-default);
}

.dm-conversation__icon-btn:hover,
.dm-conversation__add-friend:hover {
    background: var(--interactive-hover);
    color: var(--text-primary);
}

.dm-conversation__icon-btn--active {
    background: var(--accent-primary-subtle);
    color: var(--accent-primary);
}

.dm-agent-menu {
    position: relative;
}

.dm-agent-menu__dropdown {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    min-width: calc(var(--size-32) + var(--size-24));
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    z-index: var(--z-dropdown);
    /* ticket #3655: bound the panel to the viewport so tall Goals + identity
       file lists scroll inside the panel instead of overflowing the page. */
    max-height: min(70vh, calc(100vh - 96px));
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.dm-agent-menu__header {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-default);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    width: min(320px, calc(100vw - var(--space-6)));
    max-height: 360px;
    overflow-y: auto;
    background: var(--surface-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    padding: var(--space-2);
}

.dm-agent-menu__header {
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: var(--font-bold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--text-muted);
}

.dm-agent-menu__list {
    display: flex;
    flex-direction: column;
    padding: var(--space-1);
    gap: var(--space-1);
}

.dm-agent-menu__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-3);
    border: none;
    background: transparent;
    color: var(--text-primary);
    border-radius: var(--radius-md);
    min-height: var(--size-10);
    padding: var(--space-2) var(--space-3);
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    text-align: left;
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-default),
                color var(--duration-fast) var(--ease-default);
}

.dm-agent-menu__item:hover,
.dm-agent-menu__item:focus-visible {
    background: var(--interactive-hover);
    color: var(--text-primary);
    outline: none;
}

.dm-agent-menu__item small,
.dm-agent-menu__empty {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.dm-agent-menu__item:hover {
    background: var(--interactive-hover);
}

.dm-agent-menu__item span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dm-agent-menu__item small {
    flex-shrink: 0;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 10px;
}

.dm-agent-menu__empty {
    display: block;
    padding: var(--space-3);
}

.dm-agent-menu__dropdown {
    /* Widen so goal text breathes; cap so it doesn't blow past the viewport. */
    min-width: var(--size-64, 320px);
    max-width: 380px;
}

.dm-agent-menu__goal {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--border-default);
}

.dm-agent-menu__goal + .dm-agent-menu__goal {
    border-top: 1px solid var(--border-default);
}

.dm-agent-menu__goal--active        { border-left-color: var(--success, #16a34a); }
.dm-agent-menu__goal--pending_approval { border-left-color: var(--warning, #d97706); }
.dm-agent-menu__goal--draft         { border-left-color: var(--text-muted); }
.dm-agent-menu__goal--drift         { border-left-color: var(--danger, #dc2626); }
.dm-agent-menu__goal--done          { border-left-color: var(--purple); opacity: 0.65; }

.dm-agent-menu__goal-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
}

.dm-agent-menu__goal-title {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    line-height: var(--leading-tight);
}

.dm-agent-menu__goal-status {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    white-space: nowrap;
}

.dm-agent-menu__goal-next,
.dm-agent-menu__goal-blocker {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
    line-height: var(--leading-snug);
}

.dm-agent-file-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: var(--surface-overlay);
    z-index: var(--z-modal);
}

.dm-agent-file-modal--open {
    display: flex;
}

.dm-agent-file-modal__panel {
    width: min(100%, calc(var(--size-32) + var(--size-32) + var(--size-32) + var(--size-32) + var(--size-32)));
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

.dm-agent-file-modal__header,
.dm-agent-file-modal__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-default);
}

.dm-agent-file-modal__footer {
    border-top: 1px solid var(--border-default);
    border-bottom: none;
}

.dm-agent-file-modal__eyebrow,
.dm-agent-file-modal__status {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

.dm-agent-file-modal__status[data-tone="success"] {
    color: var(--status-success);
}

.dm-agent-file-modal__status[data-tone="error"] {
    color: var(--status-error);
}

.dm-agent-file-modal__title {
    margin: 0;
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    color: var(--text-primary);
}

.dm-agent-file-modal__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--size-10);
    height: var(--size-10);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-default),
                color var(--duration-fast) var(--ease-default);
}

.dm-agent-file-modal__close:hover,
.dm-agent-file-modal__close:focus-visible {
    background: var(--interactive-hover);
    color: var(--text-primary);
    outline: none;
}

.dm-agent-file-modal__editor {
    min-height: calc(var(--size-32) + var(--size-32));
    max-height: 60vh;
    flex: 1;
    width: 100%;
    padding: var(--space-4);
    border: none;
    resize: vertical;
    background: var(--surface-secondary);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
}

.dm-agent-file-modal__editor:focus {
    outline: none;
    background: var(--surface-primary);
    color: var(--text-muted);
    font-size: var(--text-sm);
}

/* ----- Transcript ----- */
.dm-conversation__messages {
    flex: 1;
    min-height: 0;
    position: relative;
    z-index: var(--z-base);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    /* Messages are pushed to the bottom by the JS-inserted
       .dm-messages-spacer (flex: 1). We deliberately do NOT use
       justify-content: flex-end here — when the transcript overflows,
       flex-end clamps content to the bottom edge so the overflow lives
       ABOVE scrollOrigin and the user can not scroll up (Steven
       2026-06-25). The spacer alone handles short-thread bottom-anchor
       cleanly; if a race ever leaves a single message at the top, fix
       the race in dm-core.js, do not paper over it here. */
    gap: var(--space-0);
    background: var(--surface-app);
}

.dm-messages-spacer { flex: 1; }

.dm-scroll-anchor {
    flex: 0 0 auto;
    height: 0;
    overflow: hidden;
}

.dm-messages-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-8);
    color: var(--text-muted);
    font-size: var(--text-sm);
}

@keyframes dm-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.spinning { animation: dm-spin 1s linear infinite; }

/* Day rule */
.dm-date-separator {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin: var(--space-5) 0 var(--space-3);
    flex-shrink: 0;
}

.dm-date-separator::before,
.dm-date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-default);
}

.dm-date-separator span {
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: var(--font-bold);
    color: var(--text-muted);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    white-space: nowrap;
}

/* ----- Message bubble ----- */
.dm-message {
    display: flex;
    gap: var(--space-2);
    /* 2026-05-21: bubbles span nearly the full row width — color +
     * left/right alignment already signal who the sender is, so the
     * old 78% cap was leaving precious horizontal real estate
     * unused. Keep a small breathing room on the opposite side. */
    max-width: 96%;
    flex-shrink: 0;
    align-items: flex-end;
}

.dm-message--own {
    flex-direction: row-reverse;
    margin-left: auto;
}

.dm-message__avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    overflow: visible;
    flex-shrink: 0;
    position: relative;
}

.dm-message__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-full);
}

.dm-message__avatar a {
    display: block;
    border-radius: var(--radius-full);
}

/* Group chaining — collapse follow-up avatars & name rows */
.dm-message--group-middle .dm-message__avatar,
.dm-message--group-start .dm-message__avatar {
    visibility: hidden;
}

/* Meta row (time / name / DELIVERED) lives BELOW the bubble body. Only
   shown at the bottom-end of a same-sender run (group-end) or on isolated
   messages (group-solo). Hidden on group-start / group-middle. */
.dm-message--group-middle .dm-message__header,
.dm-message--group-start .dm-message__header {
    display: none;
}

/* iMessage parity: incoming bubbles have no meta row underneath. The page
   header already names who you're DMing — so a per-bubble "Rex — 10:47 AM"
   line at the bottom is just noise, and (because the avatar uses
   align-items: flex-end on the row) it pulls the identicon below the white
   bubble instead of aligning with its bottom edge. Suppress the entire
   header for incoming messages; outgoing keeps DELIVERED + time. */
.dm-message:not(.dm-message--own) .dm-message__header {
    display: none;
}

.dm-message--group-start { margin-bottom: var(--space-0); }
.dm-message--group-middle { margin-bottom: var(--space-0); margin-top: calc(var(--space-1) / 2); }
.dm-message--group-end { margin-top: calc(var(--space-1) / 2); margin-bottom: var(--space-2); }
.dm-message--group-solo { margin-bottom: var(--space-2); }

.dm-message__content {
    display: flex;
    flex-direction: column;
    gap: calc(var(--space-1) / 2);
    min-width: 0;
    overflow: hidden;
}

.dm-message__header {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    flex-wrap: wrap;
    min-width: 0;
    margin-top: var(--space-1);
    padding: 0 var(--space-1);
}

.dm-message--own .dm-message__header {
    flex-direction: row-reverse;
    padding-right: var(--space-1);
}

.dm-message__delivered {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

.dm-message__sender,
a.dm-message__sender--link {
    font-family: var(--font-heading);
    font-size: var(--text-sm);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    text-decoration: none;
}

a.dm-message__sender--link:hover { color: var(--accent-tertiary); text-decoration: underline; }

.dm-message__time {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

.dm-message__points,
.dm-message__role { display: none; }

/* Bubble body — incoming */
.dm-message__body {
    padding: var(--space-2) var(--space-3);
    background: var(--surface-primary);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
    box-shadow: var(--shadow-sm);
}

/* Standalone incoming tail at bottom-left */
.dm-message:not(.dm-message--own) .dm-message__body { border-bottom-left-radius: 6px; }

/* Grouped incoming — reset tail on middle/start, keep tail only on end/solo */
.dm-message--group-start:not(.dm-message--own) .dm-message__body { border-bottom-left-radius: 18px; border-top-left-radius: 18px; }
.dm-message--group-middle:not(.dm-message--own) .dm-message__body { border-bottom-left-radius: 18px; border-top-left-radius: 6px; }
.dm-message--group-end:not(.dm-message--own) .dm-message__body { border-top-left-radius: 6px; border-bottom-left-radius: 6px; }

/* Bubble body — self (purple) */
.dm-message--own .dm-message__body {
    background: var(--accent-tertiary);
    color: var(--text-inverse);
    border: none;
    box-shadow: 0 2px 10px var(--accent-tertiary-subtle);
    border-bottom-right-radius: 6px;
}

.dm-message--own.dm-message--group-start .dm-message__body { border-bottom-right-radius: 18px; border-top-right-radius: 18px; }
.dm-message--own.dm-message--group-middle .dm-message__body { border-bottom-right-radius: 18px; border-top-right-radius: 6px; }
.dm-message--own.dm-message--group-end .dm-message__body { border-top-right-radius: 6px; border-bottom-right-radius: 6px; }

.dm-message--own .dm-message__body a { color: var(--text-inverse); text-decoration: underline; }

.dm-message--ack {
    max-width: 72%;
}

/* Inline reply preview header (2026-05-21).
 * Sits above .dm-message__body-text when this message threads to an earlier one.
 * Tappable — jumps to + pulse-highlights the parent. */
.dm-message__reply-to {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px;
    width: 100%;
    margin: 0 0 6px;
    padding: 6px 10px;
    border: 0;
    border-left: 3px solid var(--accent-tertiary, #6b46c1);
    border-radius: 6px;
    background: var(--surface-muted, rgba(107, 70, 193, 0.06));
    color: var(--text-secondary, #6b7280);
    font: inherit;
    font-size: 12px;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s ease;
}
.dm-message__reply-to:hover,
.dm-message__reply-to:focus-visible {
    background: var(--surface-muted-hover, rgba(107, 70, 193, 0.12));
    outline: none;
}
.dm-message__reply-arrow {
    color: var(--accent-tertiary, #6b46c1);
    font-weight: 700;
    margin-right: 4px;
}
.dm-message__reply-label {
    font-weight: 700;
    color: var(--text-secondary);
}
.dm-message__reply-excerpt {
    flex-basis: 100%;
    color: var(--text-secondary);
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.dm-message--own .dm-message__reply-to {
    background: rgba(255, 255, 255, 0.14);
    border-left-color: rgba(255, 255, 255, 0.45);
    color: var(--text-inverse);
}
.dm-message--own .dm-message__reply-arrow,
.dm-message--own .dm-message__reply-label,
.dm-message--own .dm-message__reply-excerpt { color: var(--text-inverse); }
.dm-message--own .dm-message__reply-to:hover { background: rgba(255, 255, 255, 0.22); }

/* Pulse animation when DMCore.jumpToMessage targets a parent. */
@keyframes dm-message-jump-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(107, 70, 193, 0.55); }
    60%  { box-shadow: 0 0 0 14px rgba(107, 70, 193, 0);   }
    100% { box-shadow: 0 0 0 0 rgba(107, 70, 193, 0);      }
}
.dm-message--jump-pulse .dm-message__body {
    animation: dm-message-jump-pulse 1.6s ease-out;
}

.dm-message--ack .dm-message__body {
    padding: var(--space-2) var(--space-3);
    background: var(--surface-secondary);
    border-color: var(--border-soft);
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-style: italic;
    box-shadow: none;
}

.dm-message--ack:not(.dm-message--own) .dm-message__body,
.dm-message--ack.dm-message--group-start:not(.dm-message--own) .dm-message__body,
.dm-message--ack.dm-message--group-middle:not(.dm-message--own) .dm-message__body,
.dm-message--ack.dm-message--group-end:not(.dm-message--own) .dm-message__body {
    border-radius: var(--radius-lg);
}

.dm-message--ack .dm-message__header {
    color: var(--text-muted);
}

.dm-message__subject {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin-bottom: var(--space-2);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--border-soft);
}

.dm-message__subject-label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: var(--font-bold);
    color: var(--text-muted);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}

.dm-message__subject-text {
    font-family: var(--font-heading);
    font-size: var(--text-sm);
    line-height: 1.25;
    color: var(--text-primary);
}

/* Inline image bubble */
.dm-message__image {
    margin: var(--space-0);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    overflow: hidden;
    max-width: 100%;
    background: var(--surface-primary);
    box-shadow: var(--shadow-sm);
}

.dm-message--own .dm-message__image {
    border: none;
    background: var(--accent-tertiary-subtle);
    box-shadow: 0 var(--space-1) var(--space-3) var(--accent-tertiary-subtle);
}

.dm-message__image img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    cursor: zoom-in;
    background: var(--surface-secondary);
}

.dm-message__file {
    display: inline-grid;
    grid-template-columns: var(--size-10) minmax(0, 1fr);
    align-items: center;
    gap: var(--space-2);
    max-width: min(100%, 28rem);
    min-height: var(--size-12);
    padding: var(--space-2);
    color: var(--text-primary);
    background: var(--surface-primary);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
}

.dm-message--own .dm-message__file {
    background: var(--accent-tertiary-subtle);
    border-color: transparent;
}

.dm-message__file-badge,
.dm-pending-chip__file-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--size-10);
    height: var(--size-10);
    border-radius: var(--radius-sm);
    background: var(--surface-secondary);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    text-transform: uppercase;
}

.dm-message__file-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
}

/* Failed message retry */
.dm-message--failed .dm-message__body { opacity: 0.6; }

.dm-message--agent-failed .dm-message__body {
    background: var(--status-error-subtle);
    border: 1px solid var(--status-error);
}

.dm-message--agent-failed .dm-message__body-text {
    color: var(--status-error);
    font-weight: var(--font-medium);
}

.dm-message__failed-strip {
    margin-top: var(--space-1);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    background: var(--status-error-subtle);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    color: var(--status-error);
}

.dm-message__retry-btn {
    border: none;
    background: transparent;
    color: var(--status-error);
    font-weight: var(--font-bold);
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

/* Empty state */
.dm-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    flex: 1;
    padding: var(--space-12) var(--space-6);
    text-align: center;
    color: var(--text-muted);
}

.dm-empty-state__title {
    margin: 0;
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    color: var(--text-primary);
}

.dm-empty-state__text {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* -----------------------------------------------------------------------------
   5. TYPING INDICATOR
----------------------------------------------------------------------------- */
.dm-composer-dock {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: relative;
    z-index: var(--z-sticky);
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    background: var(--surface-app);
    border-top: 1px solid var(--border-default);
}

.dm-typing-indicator {
    display: none;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4) 0;
    flex-shrink: 0;
    min-width: 0;
}

.dm-typing-indicator.visible,
.dm-typing-indicator.active { display: flex; }

.dm-typing-indicator__bubble {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    max-width: 100%;
    min-width: 0;
    padding: var(--space-2) var(--space-3);
    background: var(--surface-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-sm);
}

.dm-typing-indicator__dot {
    width: var(--space-2);
    height: var(--space-2);
    border-radius: var(--radius-full);
    background: var(--text-secondary);
    animation: dm-typing-bounce calc(var(--duration-slow) * 4) var(--ease-default) infinite;
    flex-shrink: 0;
}

.dm-typing-indicator__dot:nth-child(2) { animation-delay: var(--duration-fast); }
.dm-typing-indicator__dot:nth-child(3) { animation-delay: calc(var(--duration-fast) * 2); }

.dm-typing-indicator__label {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-body);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    line-height: var(--leading-tight);
}

@keyframes dm-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(calc(var(--space-1) * -1)); opacity: 1; }
}

/* -----------------------------------------------------------------------------
   6. COMPOSER
----------------------------------------------------------------------------- */
.dm-pending-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    max-height: calc((var(--size-12) * 2) + var(--space-3));
    overflow-y: auto;
    padding: var(--space-2) var(--space-4) 0;
    flex-shrink: 0;
    min-width: 0;
}

.dm-pending-chips--panel { padding: 0 var(--space-3) var(--space-2); }

.dm-pending-chips:empty,
.dm-pending-chips[aria-hidden="true"] {
    display: none;
    padding: 0;
}

.dm-pending-chip {
    display: inline-grid;
    grid-template-columns: var(--size-10) minmax(0, 1fr) var(--size-6);
    align-items: center;
    gap: var(--space-2);
    max-width: 100%;
    min-width: 0;
    min-height: var(--size-12);
    padding: var(--space-1);
    background: var(--surface-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
}

.dm-pending-chip--uploading {
    background: var(--accent-tertiary-subtle);
    color: var(--accent-tertiary);
}

.dm-pending-chip__thumb {
    width: var(--size-10);
    height: var(--size-10);
    object-fit: cover;
    border-radius: var(--radius-sm);
}

.dm-pending-chip--uploading .dm-pending-chip__thumb {
    opacity: 0.72;
}

.dm-pending-chip__label {
    min-width: 0;
    max-width: 18ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

.dm-pending-chip__remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--size-6);
    height: var(--size-6);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-base);
    line-height: var(--leading-tight);
    cursor: pointer;
    border-radius: var(--radius-full);
}

.dm-pending-chip--uploading .dm-pending-chip__remove { color: var(--accent-tertiary); }

.dm-pending-chip__remove:hover { background: var(--interactive-hover); color: var(--text-primary); }

.dm-composer {
    display: flex;
    align-items: flex-end;
    gap: var(--space-1);
    position: relative;
    z-index: var(--z-base);
    padding: var(--space-3) var(--space-4);
    padding: var(--space-3) var(--space-4) max(var(--space-3), env(safe-area-inset-bottom));
    background: transparent;
    border-top: 0;
    flex-shrink: 0;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.dm-composer__plus,
.dm-composer__mic,
.dm-composer__voice {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--size-10);
    height: var(--size-10);
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-default),
                color var(--duration-fast) var(--ease-default);
}

.dm-composer__plus:hover,
.dm-composer__mic:hover,
.dm-composer__voice:hover { background: var(--interactive-hover); color: var(--text-primary); }

.dm-composer [data-ios-composer-action] {
    touch-action: manipulation;
}


.dm-panel-conversation__attach {
    align-self: flex-end;
}

.dm-panel-conversation__photo-input {
    display: none;
}

.dm-composer__mic {
    position: relative;
}

.dm-composer__mic.dm-mic-btn--recording,
.dm-mic-btn.dm-mic-btn--recording {
    color: var(--status-error);
    background: var(--status-error-subtle, rgba(239, 68, 68, 0.12));
    animation: dmMicPulse 1.2s ease-in-out infinite;
}

.dm-composer__mic .dm-mic-btn__timer,
.dm-mic-btn .dm-mic-btn__timer {
    position: absolute;
    top: -18px;
    right: 0;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--status-error);
    white-space: nowrap;
    pointer-events: none;
}

@keyframes dmMicPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.24); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.dm-composer__voice {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-default);
    background: var(--surface-primary);
    color: var(--text-secondary);
}

.dm-composer__voice::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--radius-full);
    background: var(--accent-primary-subtle);
    opacity: 0;
    transform: scale(0.7);
    transition: opacity var(--duration-fast) var(--ease-default),
                transform var(--duration-fast) var(--ease-default);
}

.dm-composer__voice::after {
    content: "";
    position: absolute;
    inset: -3px;
    border: 2px solid var(--accent-primary);
    border-radius: var(--radius-full);
    opacity: 0;
}

.dm-composer__voice-bars {
    position: relative;
    z-index: var(--z-content);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    height: 16px;
}

.dm-composer__voice-bars span {
    display: block;
    width: 3px;
    height: 9px;
    border-radius: var(--radius-full);
    background: currentColor;
}

.dm-composer__voice-bars span:nth-child(1) { height: 6px; }
.dm-composer__voice-bars span:nth-child(2) { height: 14px; }
.dm-composer__voice-bars span:nth-child(3) { height: 8px; }

.dm-composer__voice-stop {
    position: relative;
    z-index: var(--z-content);
    display: none;
    width: 11px;
    height: 11px;
    border-radius: var(--radius-sm);
    background: currentColor;
}

.dm-composer__voice--active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.dm-composer__voice--active::before {
    opacity: 1;
    transform: scale(1);
}

.dm-composer__voice--active .dm-composer__voice-bars {
    display: none;
}

.dm-composer__voice--active .dm-composer__voice-stop {
    display: block;
}

.dm-composer__voice--listening::after,
.dm-composer__voice--waiting::after,
.dm-composer__voice--speaking::after {
    animation: dmVoiceRing 1.4s ease-out infinite;
}

.dm-composer__voice--waiting {
    background: var(--highlight-yellow);
    border-color: var(--highlight-yellow);
    color: var(--text-primary);
}

.dm-composer__voice--speaking {
    background: var(--accent-tertiary);
    border-color: var(--accent-tertiary);
    color: var(--text-inverse);
}

.dm-voice-health {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0 var(--space-4) var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--status-warning-subtle);
    border: 1px solid var(--status-warning);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    line-height: var(--leading-snug);
}

.dm-voice-health[hidden] {
    display: none;
}

.dm-voice-health::before {
    content: "";
    flex-shrink: 0;
    width: var(--space-2);
    height: var(--space-2);
    border-radius: var(--radius-full);
    background: var(--status-warning);
}

.dm-voice-health--recovered {
    background: var(--status-success-subtle);
    border-color: var(--status-success);
}

.dm-voice-health--recovered::before {
    background: var(--status-success);
}

.dm-voice-health--error {
    background: var(--status-error-subtle);
    border-color: var(--status-error);
}

.dm-voice-health--error::before {
    background: var(--status-error);
}

.dm-voice-health--panel {
    margin: var(--space-2) var(--space-3) 0;
}

@keyframes dmVoiceRing {
    0% { transform: scale(0.78); opacity: 0.45; }
    100% { transform: scale(1.22); opacity: 0; }
}

.dm-composer__input {
    flex: 1;
    min-width: 0;
    min-height: var(--size-10);
    max-height: 140px;
    padding: var(--space-2) var(--space-4);
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    line-height: 1.45;
    color: var(--text-primary);
    resize: none;
    outline: none;
    overflow-y: auto;
    transition: border-color var(--duration-fast) var(--ease-default),
                box-shadow var(--duration-fast) var(--ease-default);
    /* Hide native scrollbar */
    scrollbar-width: thin;
}

.dm-composer__input:focus {
    border-color: var(--accent-tertiary);
    box-shadow: 0 0 0 3px var(--accent-tertiary-subtle);
}

.dm-composer__input::placeholder { color: var(--text-muted); }

.dm-composer__send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--size-10);
    height: var(--size-10);
    flex-shrink: 0;
    border: none;
    background: var(--accent-primary);
    color: var(--text-primary);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-default),
                color var(--duration-fast) var(--ease-default),
                transform var(--duration-fast) var(--ease-default);
}

.dm-composer__send:hover {
    background: var(--accent-tertiary);
    color: var(--text-inverse);
}

.dm-composer__send:active { transform: scale(0.96); }

.dm-composer__send--disabled,
.dm-composer__send:disabled {
    background: var(--interactive-hover);
    color: var(--text-muted);
    cursor: default;
    pointer-events: none;
}

body.dm-page.dm-ios-composer-anchor .dm-composer__input {
    font-size: var(--text-base);
}

body.dm-page.dm-ios-composer-anchor {
    /* Updated by the iOS visualViewport state stylesheet. */
    --dm-visual-height: 100dvh;
    --dm-ios-keyboard-offset: 0;
    --dm-ios-composer-translate: 0;
    --dm-composer-reserved-height: calc(var(--space-16) + env(safe-area-inset-bottom));
}

/* -----------------------------------------------------------------------------
   7. LIGHTBOX
----------------------------------------------------------------------------- */
.dm-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--z-fullscreen);
    background: var(--surface-overlay);
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
}

.dm-lightbox--open { display: flex; }

.dm-lightbox__img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-md);
}

.dm-lightbox__close {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--btn-glass-bg);
    color: var(--text-inverse);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-default);
}

.dm-lightbox__close:hover { background: var(--btn-glass-bg-hover); }

.dm-agent-file-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: var(--surface-overlay);
}

.dm-agent-file-modal--open {
    display: flex;
}

.dm-agent-file-modal__panel {
    display: flex;
    flex-direction: column;
    width: min(960px, 100%);
    height: min(760px, calc(100vh - var(--space-8)));
    min-height: 420px;
    background: var(--surface-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.dm-agent-file-modal__header,
.dm-agent-file-modal__footer {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--surface-primary);
    border-bottom: 1px solid var(--border-default);
}

.dm-agent-file-modal__footer {
    justify-content: space-between;
    border-top: 1px solid var(--border-default);
    border-bottom: none;
}

.dm-agent-file-modal__eyebrow {
    display: block;
    margin-bottom: var(--space-1);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: var(--font-bold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--text-muted);
}

.dm-agent-file-modal__title {
    margin: 0;
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    line-height: 1.2;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.dm-agent-file-modal__close {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--size-10);
    height: var(--size-10);
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.dm-agent-file-modal__close:hover {
    background: var(--interactive-hover);
    color: var(--text-primary);
}

.dm-agent-file-modal__editor {
    flex: 1;
    min-height: 0;
    width: 100%;
    padding: var(--space-4);
    border: none;
    resize: none;
    outline: none;
    background: var(--surface-card);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: 1.6;
}

.dm-agent-file-modal__status {
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.dm-agent-file-modal__status[data-tone="success"] {
    color: var(--accent-primary);
}

.dm-agent-file-modal__status[data-tone="error"] {
    color: var(--status-error);
}

.dm-agent-file-modal__save {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--size-10);
    padding: 0 var(--space-4);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--surface-card);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    cursor: pointer;
}

.dm-agent-file-modal__save:hover:not(:disabled) {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: var(--text-inverse);
}

.dm-agent-file-modal__save:disabled {
    cursor: default;
    opacity: var(--opacity-disabled);
}

@media (max-width: 640px) {
    .dm-agent-file-modal {
        padding: 0;
    }

    .dm-agent-file-modal__panel {
        width: 100%;
        height: 100%;
        min-height: 0;
        border-radius: 0;
    }

    .dm-agent-file-modal__header,
    .dm-agent-file-modal__footer {
        padding: var(--space-3);
    }
}

/* -----------------------------------------------------------------------------
   8. SETTINGS PAGE
----------------------------------------------------------------------------- */
.dm-settings {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: var(--space-4) var(--space-4) var(--space-8);
    background: var(--surface-app);
}

.dm-settings__hero {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-2) var(--space-6);
}

.dm-settings__hero-avatar {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
}

.dm-settings__hero-avatar .profile-avatar,
.dm-settings__hero-avatar .profile-avatar__image {
    width: 48px !important;
    height: 48px !important;
}

.dm-settings__hero-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
}

.dm-settings__hero-name {
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    color: var(--text-primary);
}

.dm-settings__hero-motto {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
}

.dm-settings__group { margin-bottom: var(--space-6); }

.dm-settings__group-title {
    margin: 0 var(--space-1) var(--space-2);
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: var(--font-bold);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

.dm-settings__card {
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.dm-settings__row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-soft);
    color: var(--text-primary);
}

.dm-settings__row:last-child { border-bottom: none; }

.dm-settings__row--nav {
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-default);
}

.dm-settings__row--nav:hover { background: var(--interactive-hover); }

.dm-settings__row--danger {
    cursor: pointer;
    color: var(--status-error);
}

.dm-settings__row--danger:hover { background: var(--status-error-subtle); }

.dm-settings__row-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: var(--surface-secondary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
}

.dm-settings__row--danger .dm-settings__row-icon {
    background: var(--status-error-subtle);
    color: var(--status-error);
}

.dm-settings__row-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 1;
    min-width: 0;
}

.dm-settings__row-label {
    font-family: var(--font-heading);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: inherit;
}

.dm-settings__row-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.dm-settings__row-value {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    flex-shrink: 0;
}

.dm-settings__row-chevron {
    color: var(--text-muted);
    flex-shrink: 0;
}

/* -----------------------------------------------------------------------------
   9. NEW DM MODAL (picker)
----------------------------------------------------------------------------- */
.new-dm-modal__overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--surface-overlay);
    z-index: var(--z-modal);
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.new-dm-modal__overlay.open { display: flex; }

.new-dm-modal {
    width: 100%;
    max-width: 440px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background: var(--surface-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

.new-dm-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-default);
}

.new-dm-modal__title {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--text-primary);
}

.new-dm-modal__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--size-8);
    height: var(--size-8);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
}

.new-dm-modal__close:hover { background: var(--interactive-hover); color: var(--text-primary); }

.new-dm-modal__search {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-soft);
}

.new-dm-modal__search input {
    width: 100%;
    height: var(--size-10);
    padding: 0 var(--space-4);
    background: var(--surface-app);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--text-primary);
    outline: none;
}

.new-dm-modal__search input:focus {
    border-color: var(--accent-tertiary);
    box-shadow: 0 0 0 3px var(--accent-tertiary-subtle);
}

.new-dm-modal__results {
    overflow-y: auto;
    flex: 1;
}

.new-dm-modal__no-results {
    padding: var(--space-6);
    text-align: center;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.new-dm-modal__user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-default);
}

.new-dm-modal__user:hover { background: var(--interactive-hover); }

.new-dm-modal__user-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    overflow: hidden;
    flex-shrink: 0;
}

.new-dm-modal__user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.new-dm-modal__user-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
}

.new-dm-modal__user-name {
    font-family: var(--font-heading);
    font-size: var(--text-sm);
    font-weight: var(--font-bold);
    color: var(--text-primary);
}

.new-dm-modal__user-handle {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.new-dm-modal__user-shared {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

/* -----------------------------------------------------------------------------
   9b. DRAWER PANEL BACKGROUND (DM-scoped)
   The shared .drawer-panel uses a white surface by default, which leaves a
   white wedge below the inbox tail message. On the DM page we want it to
   match the inbox list's gray (--surface-app) so the panel reads as one
   continuous surface. Scoped to body.dm-page so Shop/Backpack/etc. drawers
   are unaffected.
----------------------------------------------------------------------------- */
body.dm-page .drawer-panel,
body.dm-page .drawer-panel--right {
    background: var(--surface-app);
}

/* -----------------------------------------------------------------------------
   9c. VIEWPORT LOCK (all sizes)
   The DM page owns its chrome and must pin the composer to the bottom of the
   visible viewport — no gray slack below the input. Lock the whole shell-to-
   conversation chain to 100dvh so the flex column inside .dm-conversation
   (messages flex:1 → dock) always anchors at the screen bottom regardless of
   viewport height. (Promoted out of the mobile media
   query 2026-06-17 — Steven flagged the composer floating high on desktop.)
----------------------------------------------------------------------------- */
body.dm-page .app-shell {
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
}

body.dm-page .main-area,
body.dm-page .main-area__content {
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
}

body.dm-page .dm-conversation {
    min-height: 0;
    height: 100%;
    max-height: 100%;
    box-sizing: border-box;
}

/* -----------------------------------------------------------------------------
   10. MOBILE OVERRIDES
----------------------------------------------------------------------------- */
@media (max-width: 767px) {
    .dm-conversation__messages { padding: var(--space-3); }
    .dm-message { max-width: 96%; }
    .dm-header { padding: 0 var(--space-3); }
    .dm-search { padding: var(--space-3); }
    .dm-room-item { padding: var(--space-3) var(--space-4); }
    .dm-room-item + .dm-room-item::before { left: 68px; right: var(--space-4); }

    /* iOS lock — when the keyboard is open, prevent the layout viewport
       from scrolling. Without this, dragging the messages list lets the
       document itself slide up: the header (in normal flow) scrolls off
       the top, and visualViewport.offsetTop grows, which makes the
       composer’s translate3d offset shrink and slip behind the
       keyboard. Pin the body so only .dm-conversation__messages scrolls.
       (Steven, 2026-06-24 iPhone screenshots.) */
    body.dm-page.dm-ios-composer-anchor {
        position: fixed;
        top: var(--dm-visual-offset, 0);
        left: 0;
        width: 100%;
        height: var(--dm-visual-height, 100dvh);
        max-height: var(--dm-visual-height, 100dvh);
        overflow: hidden;
        overscroll-behavior: none;
    }

    body.dm-page.dm-ios-composer-anchor .app-shell {
        height: var(--dm-visual-height, 100dvh);
        min-height: var(--dm-visual-height, 100dvh);
        max-height: var(--dm-visual-height, 100dvh);
        overflow: hidden;
    }

    body.dm-page.dm-ios-composer-anchor .main-area,
    body.dm-page.dm-ios-composer-anchor .main-area__content {
        height: 100%;
        max-height: 100%;
        min-height: 0;
        overflow: hidden;
    }

    body.dm-page.dm-ios-composer-anchor .dm-conversation {
        min-height: 0;
        height: 100%;
        max-height: 100%;
        box-sizing: border-box;
        padding-bottom: var(--dm-composer-reserved-height);
    }

    body.dm-page.dm-ios-composer-anchor .dm-conversation__messages {
        /* Parent .dm-conversation already reserves --dm-composer-reserved-height
           via padding-bottom so the fixed composer can't overlap the scroll
           area.  Don't double it here — an extra inner padding-bottom shows up
           as a tall gray slab between the last bubble and the composer
           (Steven, 2026-06-17 iPhone screenshot).  Keep scroll-padding-bottom
           only, so scrollIntoView lands the last message with breathing room. */
        scroll-padding-bottom: var(--dm-composer-reserved-height);
    }

    body.dm-page.dm-ios-composer-anchor .dm-composer-dock[data-ios-composer] {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: var(--z-sticky);
        box-sizing: border-box;
        max-width: 100vw;
        overflow-x: clip;
        transform: translate3d(0, var(--dm-ios-composer-translate, 0), 0);
        will-change: transform;
    }

    body.dm-page.dm-ios-composer-anchor .dm-composer-dock[data-ios-composer] .dm-typing-indicator,
    body.dm-page.dm-ios-composer-anchor .dm-composer-dock[data-ios-composer] .dm-pending-chips {
        padding-right: calc(var(--space-3) + env(safe-area-inset-right));
        padding-left: calc(var(--space-3) + env(safe-area-inset-left));
    }

    body.dm-page.dm-ios-composer-anchor .dm-composer-dock[data-ios-composer] .dm-voice-health {
        margin-right: calc(var(--space-3) + env(safe-area-inset-right));
        margin-left: calc(var(--space-3) + env(safe-area-inset-left));
    }

    body.dm-page.dm-ios-composer-anchor .dm-composer-dock[data-ios-composer] .dm-composer {
        padding-top: var(--space-3);
        padding-right: calc(var(--space-3) + env(safe-area-inset-right));
        padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
        padding-left: calc(var(--space-3) + env(safe-area-inset-left));
    }

    @supports not (overflow: clip) {
        body.dm-page.dm-ios-composer-anchor .dm-composer-dock[data-ios-composer] {
            overflow-x: hidden;
        }
    }

}

/* Inline-reply composer chip (2026-05-21).
 * Kept inside the bottom dock so reply state, photo previews, and the textarea
 * move as one stable composer surface. */
.dm-reply-chip {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    box-sizing: border-box;
    margin: var(--space-2) var(--space-4) 0;
    padding: var(--space-2) var(--space-3);
    background: var(--accent-tertiary-subtle);
    border-left: var(--space-1) solid var(--accent-tertiary);
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    line-height: var(--leading-tight);
    color: var(--text-secondary);
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow: hidden;
}
.dm-reply-chip__arrow {
    color: var(--accent-tertiary);
    font-weight: var(--font-bold);
    flex-shrink: 0;
}
.dm-reply-chip__text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
}
.dm-reply-chip__text strong {
    color: var(--text-primary);
    font-weight: var(--font-bold);
}
.dm-reply-chip__close {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--size-6);
    height: var(--size-6);
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-base);
    line-height: var(--leading-tight);
    border-radius: var(--radius-full);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.dm-reply-chip__close:hover,
.dm-reply-chip__close:focus-visible {
    background: var(--interactive-hover);
    outline: none;
}
