/* ==================
   Chat composer: attachments, drop target, accessibility, phone layout
   (js/chat/document-upload.js, js/chat/a11y.js)
   ================== */

/* Visually hidden, still read by screen readers (also defined by Tailwind) */
#chatPanel .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Attachment chips ---------- */

.pending-document {
    position: relative;
    max-width: 100%;
}

.pending-document-thumb {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid rgb(var(--gray-200));
}

.pending-document.is-image {
    background: rgb(var(--blue-50));
    border-color: rgb(var(--blue-200));
}

.pending-document.is-image .pending-document-name,
.pending-document.is-image .pending-document-size,
.pending-document.is-image .pending-document-remove {
    color: rgb(var(--blue-800));
}

.pending-document.is-queued,
.pending-document.is-uploading {
    background: rgb(var(--gray-50));
    border-color: rgb(var(--gray-300));
}

.pending-document.is-queued .pending-document-name,
.pending-document.is-uploading .pending-document-name,
.pending-document.is-queued .pending-document-size,
.pending-document.is-uploading .pending-document-size,
.pending-document.is-queued .pending-document-remove,
.pending-document.is-uploading .pending-document-remove {
    color: rgb(var(--gray-600));
}

.pending-document.is-error {
    background: rgb(var(--red-50));
    border-color: rgb(var(--red-300));
}

.pending-document.is-error .pending-document-name,
.pending-document.is-error .pending-document-remove,
.pending-document-error {
    color: rgb(var(--red-800));
}

.pending-document-progress-track {
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: 2px;
    height: 2px;
    border-radius: 2px;
    background: rgb(var(--gray-200));
    overflow: hidden;
}

.pending-document-progress {
    display: block;
    height: 100%;
    background: rgb(var(--blue-600));
    transition: width 0.15s ease;
}

.pending-document-retry {
    padding: 0 4px;
    font-size: 11px;
    font-weight: 600;
    color: rgb(var(--red-800));
    background: none;
    border: none;
    text-decoration: underline;
    cursor: pointer;
}

.pending-document-remove,
.pending-document-retry {
    min-width: 20px;
    min-height: 20px;
    border-radius: 4px;
}

/* Sent image thumbnails */
.chat-document-chip.is-image {
    background: rgb(var(--blue-50));
    border-color: rgb(var(--blue-200));
}

.chat-document-chip.is-image .chat-document-name,
.chat-document-chip.is-image .chat-document-size {
    color: rgb(var(--blue-800));
}

.chat-document-thumb {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 3px;
}

/* ---------- Drop target ---------- */

#chatPanel.chat-drop-active::after {
    content: 'Drop files or images to attach';
    position: absolute;
    inset: 8px;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: rgb(var(--blue-800));
    background: rgb(var(--blue-50) / 0.92);
    border: 2px dashed rgb(var(--blue-400));
    border-radius: 12px;
    pointer-events: none;
}

/* ---------- Accessibility ---------- */

/* Muted text in the chat meets 4.5:1 (gray-400 is for non-text only, tokens.css) */
#chatPanel .text-gray-400,
#chatPanel .chat-input-editable:empty::before {
    color: rgb(var(--gray-500));
}

/* Keyboard focus is visible on the composer controls (the pills drop the outline) */
.chat-control-pill:focus-visible,
.deep-mode-toggle:has(input:focus-visible),
.pending-document-remove:focus-visible,
.pending-document-retry:focus-visible,
#sendChatBtn:focus-visible,
#stopChatBtn:focus-visible {
    outline: 2px solid rgb(var(--blue-600));
    outline-offset: 2px;
}

/* Messages are focusable articles (arrow keys move between them) */
#chatMessages [data-message-index]:focus {
    outline: none;
}

#chatMessages [data-message-index]:focus-visible {
    outline: 2px solid rgb(var(--blue-600));
    outline-offset: 4px;
    border-radius: 8px;
}

#chatMessages .message-chip[role="button"]:focus-visible {
    outline: 2px solid rgb(var(--blue-600));
    outline-offset: 1px;
}

/* ---------- Phones (375px and up) ---------- */

@media (max-width: 640px) {
    /* The open chat takes the screen below the top bar, sized to the visible
       viewport so the message box stays above the iOS keyboard (a11y.js sets
       the variables). Under the top bar (z 60) and modals (z 50+), over the
       page and the nav rail (z 40). */
    #chatPanel:not(.collapsed) {
        position: fixed;
        top: calc(var(--chat-viewport-top, 0px) + var(--topbar-height, 56px));
        right: 0;
        bottom: auto;
        left: 0;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        height: calc(var(--chat-viewport-height, 100dvh) - var(--topbar-height, 56px));
        z-index: 49;
        border-left: none;
    }

    #chatPanel:not(.collapsed) .chat-resize-handle {
        display: none;
    }

    #chatPanel #chatMessages {
        padding: 12px;
    }

    /* iOS zooms into inputs with text under 16px */
    #chatPanel .chat-input-editable,
    #chatPanel .chat-history-search-input {
        font-size: 16px;
    }

    #chatPanel .chat-input-editable {
        max-height: 30vh;
    }

    /* Composer controls wrap instead of overflowing */
    #chatPanel .chat-input-container > div:last-child {
        gap: 6px;
    }

    #chatPanel .chat-input-container > div:last-child > div:first-child {
        flex-wrap: wrap;
        min-width: 0;
        row-gap: 6px;
    }

    #chatPanel select.chat-control-pill {
        max-width: 9.5rem;
        text-overflow: ellipsis;
    }

    #chatPanel .mention-dropdown {
        min-width: 0;
        width: calc(100vw - 24px);
        max-width: none;
    }

    #chatPanel .mention-results-list {
        max-height: 40vh;
    }

    /* Bigger touch targets */
    #chatPanel .pending-document-remove,
    #chatPanel .pending-document-retry {
        min-width: 32px;
        min-height: 32px;
    }

    #chatPanel .chat-sidebar-drawer {
        width: min(320px, 92%);
    }
}
