/* WhatsApp-inspired chat surface for the staff inbox. */
.chat-page,
.chat-shell,
.chat-list-pane,
.chat-main,
.chat-active {
    max-width: 100%;
    min-width: 0;
}

.chat-page { width: 100%; }

.chat-shell {
    border-color: #d7dbd9;
    box-shadow: 0 2px 8px rgb(11 20 26 / 8%);
    grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
    height: min(680px, calc(100dvh - 270px));
    min-height: 0;
    overflow: hidden;
}

.chat-list-pane { background: #fff; border-right-color: #d7dbd9; }
.chat-list-toolbar { background: #f0f2f5; padding-bottom: 13px; }
.chat-list-toolbar strong { font-size: 15px; }
.chat-refresh { background: #e7f3ef; color: #008069; }
.chat-search { background: #f0f2f5; border-color: #f0f2f5; border-radius: 8px; }
.chat-filters { flex-wrap: wrap; }
.chat-filter.active { background: #d9fdd3; color: #075e54; }
.chat-list-item { min-width: 0; padding-bottom: 13px; padding-top: 13px; }
.chat-list-item:hover,
.chat-list-item.selected { background: #f0f2f5; }
.chat-list-item.selected { box-shadow: inset 3px 0 #00a884; }
.list-avatar,
.customer-avatar { background: #dfe5e7; color: #52616b; }

.chat-main { background: #efeae2; overflow: hidden; }
.chat-active {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    min-height: 0;
    width: 100%;
}
.chat-header { background: #f0f2f5; border-bottom-color: #d7dbd9; padding-left: 14px; padding-right: 14px; }
.chat-back { color: #54656c; }
.chat-status-pill { background: #d9fdd3; color: #075e54; margin-left: auto; }
.chat-header-actions { display: none; }

.chat-messages {
    background-color: #efeae2;
    background-image: radial-gradient(rgb(84 98 92 / 12%) .7px, transparent .7px);
    background-size: 14px 14px;
    min-height: 0;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 18px 14px 12px;
}
.incoming .chat-bubble { background: #fff; border-top-left-radius: 2px; }
.outgoing .chat-bubble { background: #d9fdd3; border-top-right-radius: 2px; }
.chat-message-row { align-items: flex-end; min-width: 0; padding-inline: 2px; width: 100%; }
.chat-message-row.incoming .chat-bubble { margin-inline-end: auto; }
.chat-message-row.outgoing .chat-bubble { margin-inline-start: auto; }
.chat-bubble {
    border-radius: 8px;
    box-shadow: 0 1px 1px rgb(11 20 26 / 13%);
    color: #111b21;
    max-width: min(78%, 560px);
    min-width: 0;
    overflow-wrap: anywhere;
}
.chat-bubble small { color: #667781; }

.chat-claim-panel {
    align-items: center;
    background: #fff8df;
    border-top: 1px solid #efdf9a;
    display: flex;
    gap: 10px;
    justify-content: space-between;
    min-width: 0;
    padding: 10px 15px;
}
.chat-claim-copy { flex: 1 1 220px; min-width: 0; }
.chat-claim-panel p {
    color: #67551a;
    font-size: 12px;
    margin: 0;
    min-width: 0;
}
.chat-display-profile { color: #67551a; display: grid; font-size: 11px; font-weight: 700; gap: 4px; margin-top: 7px; }
.chat-display-profile select { background: #fff; border: 1px solid #dfcc79; border-radius: 7px; color: #3f3510; min-height: 34px; min-width: 0; padding: 6px 8px; width: 100%; }
.chat-claim-actions { display: flex; flex: 0 0 auto; flex-direction: column; gap: 6px; }
.chat-claim-button,
.chat-release-button {
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    flex: 0 0 auto;
    font-size: 12px;
    font-weight: 700;
    min-height: 38px;
    padding: 8px 12px;
}
.chat-claim-button { background: #008069; color: #fff; }
.chat-release-button { background: #fff; border: 1px solid #d2bd66; color: #67551a; }
.chat-claim-button:disabled,
.chat-release-button:disabled { cursor: wait; opacity: .6; }

/* Only the message history scrolls; the reply controls remain available. */
.chat-composer {
    align-items: stretch;
    background: #f0f2f5;
    border-top-color: #d7dbd9;
    display: block;
    flex: 0 0 auto;
    padding: 10px 15px calc(8px + env(safe-area-inset-bottom));
    position: sticky;
    bottom: 0;
    width: 100%;
    z-index: 2;
}
.chat-composer-row {
    align-items: flex-end;
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) auto;
    min-width: 0;
    width: 100%;
}
.chat-composer textarea {
    background: #fff;
    border-color: #fff;
    border-radius: 8px;
    grid-column: 1;
    min-width: 0;
    width: 100%;
}
.chat-composer-row #reply-type { display: none; }
.chat-composer .chat-send {
    align-items: center;
    appearance: none;
    background: #008069;
    border: 0;
    border-radius: 50%;
    color: #fff;
    display: inline-flex;
    flex: 0 0 42px;
    grid-column: 2;
    grid-row: 1;
    height: 42px;
    justify-content: center;
    margin: 0;
    min-height: 42px;
    min-width: 42px;
    padding: 0;
    width: 42px;
}
.chat-composer .chat-send:hover { background: #006f5b; }
.chat-composer .chat-send svg { fill: none; height: 18px; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; width: 18px; }
.chat-composer .chat-send:focus-visible { outline: 3px solid #7bcdb7; outline-offset: 2px; }
.chat-composer p { bottom: auto; left: auto; margin: 4px 0 0; position: static; }
.chat-composer p:empty { display: none; }
.chat-empty-state { background: #efeae2; }
.chat-empty-icon { background: #d9fdd3; color: #008069; }

/* Desktop keeps the conversation list and selected conversation side by side. */
@media (min-width: 769px) {
    .chat-shell.is-selected { display: grid; }
    .chat-shell.is-selected .chat-list-pane { display: flex; }
    .chat-shell.is-selected .chat-main { display: flex; }
}

/* Mobile follows the familiar list → conversation → back pattern. */
@media (max-width: 768px) {
    .chat-page { min-width: 0; overflow-x: clip; }
    .chat-shell {
        display: block;
        height: min(72dvh, calc(100dvh - 180px));
        min-height: 440px;
        width: 100%;
    }
    .chat-list-pane,
    .chat-main,
    .chat-active { height: 100%; width: 100%; }
    .chat-list-pane { border-right: 0; }
    .chat-main { display: none; }
    .chat-shell.is-selected .chat-list-pane { display: none; }
    .chat-shell.is-selected .chat-main { display: flex; }
    .chat-back {
        align-items: center;
        display: inline-flex;
        flex: 0 0 36px;
        font-size: 28px;
        height: 36px;
        justify-content: center;
        padding: 0;
        width: 36px;
    }
    .chat-header {
        display: grid;
        gap: 7px;
        grid-template-columns: 36px 34px minmax(0, 1fr) auto;
        min-height: 60px;
        padding: 8px 10px;
    }
    .customer-avatar { flex-basis: 34px; height: 34px; width: 34px; }
    .customer-heading { min-width: 0; }
    .profile-heading { display: none !important; }
    .chat-status-pill {
        margin-left: 0;
        max-width: 76px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .chat-messages { padding: 14px 10px 10px; }
    .chat-message-row .chat-bubble { max-width: 84%; }
    .chat-claim-panel { align-items: stretch; flex-direction: column; gap: 8px; padding: 10px; }
    .chat-claim-actions { width: 100%; }
    .chat-claim-button,
    .chat-release-button { width: 100%; }
    .chat-composer { padding: 9px 10px calc(8px + env(safe-area-inset-bottom)); }
}

@media (max-width: 390px) {
    .chat-shell { min-height: 410px; }
    .chat-status-pill { display: none; }
    .chat-header { grid-template-columns: 36px 34px minmax(0, 1fr); }
}
