/* Inbox — two-pane live chat. Colours come from the variables in styles.css so
   dark mode needs no extra rules. */

.inbox-shell {
    display: grid;
    grid-template-columns: 340px 1fr;
    height: calc(100vh - 210px);
    min-height: 480px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: var(--radius-lg, 14px);
    overflow: hidden;
    background: var(--card-bg, #fff);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, .05));
}

/* ---------- chat list ---------- */

.inbox-list-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Without min-height:0 a flex/grid item refuses to shrink below its content,
       so the chat list grew past the shell and got clipped instead of scrolling. */
    min-height: 0;
    overflow: hidden;
    border-right: 1px solid var(--border-color, #e2e8f0);
    background: var(--bg-secondary, #fff);
}

.inbox-list-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.inbox-session-dropdown {
    flex: 1;
    min-width: 0;
}

.inbox-session-dropdown .dropdown-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.inbox-session-dropdown .dropdown-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inbox-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: var(--radius-md, 10px);
    background: var(--bg-secondary, #fff);
    color: var(--text-secondary, #55657a);
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.inbox-icon-btn:hover {
    background: var(--bg-tertiary, #f1f5f9);
    color: var(--text-primary, #334155);
    border-color: var(--border-color-hover, #cbd5e1);
}

.inbox-icon-btn svg {
    width: 17px;
    height: 17px;
}

/* Muted: an icon alone is a weak signal in a row of identical buttons, so the
   button dims once the sound is off. */
.inbox-icon-btn.muted {
    opacity: .6;
}

.inbox-search-wrap {
    position: relative;
    padding: 10px 12px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.inbox-search-icon {
    position: absolute;
    left: 22px;
    top: 50%;
    transform: translateY(-50%);
    width: 15px;
    height: 15px;
    color: var(--text-tertiary, #5f6f83);
    pointer-events: none;
}

.inbox-search {
    width: 100%;
    padding: 9px 12px 9px 34px;
    border: 1px solid var(--input-border, #e2e8f0);
    border-radius: var(--radius-pill, 999px);
    background: var(--input-bg, #f8fafc);
    color: var(--text-primary, #334155);
    font-family: var(--font-family);
    font-size: 13px;
    outline: none;
}

.inbox-search:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--focus-ring, rgba(99, 102, 241, .15));
}

.inbox-chat-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.inbox-chat-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    transition: background .12s ease;
}

.inbox-chat-row:hover {
    background: var(--table-row-hover, #f8fafc);
}

/* Match the sidebar's own active style: --nav-active-bg is dark in light mode and
   lime in dark mode, so the foreground has to come from --nav-active-fg. Without
   this the row keeps --text-primary and becomes light-on-lime (dark) or
   dark-on-black (light) - unreadable in both themes. */
.inbox-chat-row.active {
    background: var(--nav-active-bg, #f1f5f9);
}

.inbox-chat-row.active .inbox-chat-name,
.inbox-chat-row.active .inbox-chat-time,
.inbox-chat-row.active .inbox-chat-preview-text {
    color: var(--nav-active-fg, inherit);
}

.inbox-chat-row.active .inbox-chat-preview-text {
    opacity: .85;
}

/* New since you last opened it here. WAHA has no unread count to show, so this is
   a dot rather than a number - see the info popover, and the note in AGENTS.md. */
.inbox-chat-row.unread .inbox-chat-name {
    font-weight: 700;
}

.inbox-chat-row.unread .inbox-chat-preview-text {
    color: var(--text-primary, #334155);
    font-weight: 500;
}

.inbox-unread-dot {
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    margin-left: 6px;
    border-radius: 50%;
    background: var(--accent-primary);
}

/* On the selected row the background is --nav-active-bg, so the dot must flip to
   the matching foreground or it disappears into it. */
.inbox-chat-row.active .inbox-unread-dot {
    background: var(--nav-active-fg, inherit);
}

/* ---------- info popover ---------- */

.inbox-info-popover {
    position: fixed;
    z-index: 2500;
    display: none;
    width: 300px;
    max-width: calc(100vw - 24px);
    padding: 14px 16px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: var(--radius-md, 10px);
    background: var(--dropdown-bg, #fff);
    box-shadow: var(--shadow-lg, 0 10px 30px rgba(0, 0, 0, .18));
    color: var(--text-secondary, #55657a);
    font-size: 12.5px;
    line-height: 1.5;
}

.inbox-info-popover.show {
    display: block;
}

.inbox-info-popover h4 {
    margin: 0 0 8px;
    font-size: 13px;
    color: var(--text-primary, #334155);
}

.inbox-info-popover ul {
    margin: 0;
    padding-left: 16px;
}

.inbox-info-popover li + li {
    margin-top: 6px;
}

.inbox-info-popover strong {
    color: var(--text-primary, #334155);
}

.inbox-avatar {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary, #f1f5f9);
    color: var(--text-secondary, #55657a);
}

.inbox-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.inbox-avatar-initials {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: .02em;
}

.inbox-chat-body {
    flex: 1;
    min-width: 0;
}

.inbox-chat-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.inbox-chat-name {
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text-primary, #334155);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inbox-chat-time {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-tertiary, #5f6f83);
}

.inbox-chat-preview-text {
    display: block;
    font-size: 12.5px;
    color: var(--text-secondary, #55657a);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inbox-list-empty {
    padding: 28px 16px;
    text-align: center;
    font-size: 13px;
    color: var(--text-tertiary, #5f6f83);
}

.inbox-load-more {
    display: block;
    width: calc(100% - 24px);
    margin: 12px;
    padding: 10px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: var(--radius-md, 10px);
    background: var(--bg-tertiary, #f1f5f9);
    color: var(--text-secondary, #55657a);
    font-family: var(--font-family);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease;
}

.inbox-load-more:hover:not(:disabled) {
    background: var(--bg-secondary, #fff);
    border-color: var(--border-color-hover, #cbd5e1);
    color: var(--text-primary, #334155);
}

.inbox-load-more:disabled {
    opacity: .7;
    cursor: default;
}

.inbox-list-note {
    padding: 14px 16px 18px;
    text-align: center;
    font-size: 12px;
    color: var(--text-tertiary, #5f6f83);
}

.inbox-list-loading {
    padding: 12px;
    display: block;
}

.inbox-skeleton-row {
    height: 52px;
    margin-bottom: 8px;
    border-radius: var(--radius-md, 10px);
    background: linear-gradient(90deg, var(--skeleton-base, #eef2f7) 25%, var(--skeleton-highlight, #f8fafc) 37%, var(--skeleton-base, #eef2f7) 63%);
    background-size: 400% 100%;
    animation: inbox-shimmer 1.4s ease infinite;
}

@keyframes inbox-shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* ---------- thread ---------- */

.inbox-thread-pane {
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--bg-primary, #f8fafc);
}

.inbox-thread-header {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    background: var(--bg-secondary, #fff);
}

.inbox-back-btn {
    display: none;
}

.inbox-thread-meta {
    flex: 1;
    min-width: 0;
}

.inbox-thread-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary, #334155);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inbox-thread-sub {
    font-size: 12px;
    color: var(--text-tertiary, #5f6f83);
}

.inbox-autoreply-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    flex-shrink: 0;
    border-radius: var(--radius-pill, 999px);
    background: var(--warning-text, #b45309);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.inbox-autoreply-badge svg {
    width: 13px;
    height: 13px;
}

.inbox-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Like WhatsApp: with only a few messages they sit just above the composer
   instead of floating at the top. margin-top:auto (not justify-content) so that
   once the content overflows it resolves to 0 and scrolls normally. */
.inbox-messages > :first-child {
    margin-top: auto;
}

/* Placeholder bubbles while an uncached thread loads */
.inbox-msg-skeleton {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.inbox-skeleton-bubble {
    height: 42px;
    border-radius: var(--radius-md, 12px);
    background: linear-gradient(90deg, var(--skeleton-base, #eef2f7) 25%, var(--skeleton-highlight, #f8fafc) 37%, var(--skeleton-base, #eef2f7) 63%);
    background-size: 400% 100%;
    animation: inbox-shimmer 1.4s ease infinite;
}

.inbox-skeleton-bubble.in {
    align-self: flex-start;
    width: 55%;
}

.inbox-skeleton-bubble.out {
    align-self: flex-end;
    width: 45%;
}

.inbox-blank {
    margin: auto;
    text-align: center;
    font-size: 13px;
    color: var(--text-tertiary, #5f6f83);
}

/* Overlays the pane rather than sitting in the flex column: as a flex child it
   either split the height with the (empty) message list or, once hidden, let the
   composer ride up under the header instead of staying pinned to the bottom. */
.inbox-placeholder {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 32px;
    text-align: center;
    color: var(--text-tertiary, #5f6f83);
    background: var(--bg-primary, #f8fafc);
}

.inbox-placeholder svg {
    width: 34px;
    height: 34px;
    opacity: .6;
}

.inbox-placeholder h3 {
    margin: 6px 0 0;
    font-size: 15px;
    color: var(--text-primary, #334155);
}

.inbox-placeholder p {
    margin: 0;
    max-width: 380px;
    font-size: 13px;
    line-height: 1.5;
}

/* ---------- messages ---------- */

.inbox-msg {
    display: flex;
    flex-direction: column;
    max-width: 72%;
}

.inbox-msg.in {
    align-self: flex-start;
    align-items: flex-start;
}

.inbox-msg.out {
    align-self: flex-end;
    align-items: flex-end;
}

/* Who sent it, inside a group. Only ever rendered for an incoming bubble. */
.inbox-msg-sender {
    margin: 0 2px 3px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary, #64748b);
}

.inbox-bubble {
    position: relative;
    padding: 8px 12px;
    border-radius: var(--radius-md, 12px);
    background: var(--bg-secondary, #fff);
    color: var(--text-primary, #334155);
    border: 1px solid var(--border-color, #e2e8f0);
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}

.inbox-msg.out .inbox-bubble {
    background: var(--brand-lime, #ddf24b);
    border-color: var(--brand-lime, #ddf24b);
    color: var(--brand-ink, #14160f);
}

.inbox-bubble-empty {
    min-height: 6px;
}

.inbox-msg-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
    padding: 0 2px;
    font-size: 10.5px;
    color: var(--text-tertiary, #5f6f83);
}

.inbox-ack.pending { opacity: .55; }
.inbox-ack.sent { opacity: .7; }
.inbox-ack.delivered { opacity: .85; }
.inbox-ack.read { color: #3b82f6; opacity: 1; }
.inbox-ack.error { color: #dc2626; opacity: 1; }

.inbox-media-img,
.inbox-media-video {
    display: block;
    max-width: 260px;
    max-height: 300px;
    border-radius: var(--radius-sm, 8px);
}

/* Holds the space and shimmers while the image is still downloading, so the bubble
   is never a bare download button over empty space. */
.inbox-media-wrap {
    position: relative;
    display: inline-block;
    border-radius: var(--radius-sm, 8px);
    overflow: hidden;
    line-height: 0;
}

.inbox-media-wrap.is-loading {
    width: 220px;
    height: 160px;
    line-height: normal;
    background: linear-gradient(90deg, var(--skeleton-base, #eef2f7) 25%, var(--skeleton-highlight, #f8fafc) 37%, var(--skeleton-base, #eef2f7) 63%);
    background-size: 400% 100%;
    animation: inbox-shimmer 1.4s ease infinite;
}

.inbox-media-wrap.is-loading .inbox-media-img,
.inbox-media-wrap.is-loading .inbox-media-download {
    visibility: hidden;
}

.inbox-media-img {
    opacity: 0;
    transition: opacity .18s ease;
}

.inbox-media-wrap:not(.is-loading) .inbox-media-img {
    opacity: 1;
}

.inbox-media-fallback {
    display: none;
}

.inbox-media-wrap.is-broken {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 200px;
    height: 90px;
    background: var(--bg-tertiary, #f1f5f9);
    color: var(--text-tertiary, #5f6f83);
    font-size: 12px;
    line-height: normal;
}

.inbox-media-wrap.is-broken .inbox-media-img {
    display: none;
}

.inbox-media-wrap.is-broken .inbox-media-fallback {
    display: block;
}

.inbox-media-audio {
    width: 240px;
    max-width: 100%;
}

.inbox-bubble-text + .inbox-media-img,
.inbox-bubble-text + .inbox-media-video {
    margin-top: 6px;
}

.inbox-media-download {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    cursor: pointer;
}

.inbox-media-download svg {
    width: 15px;
    height: 15px;
}

.inbox-media-placeholder {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 4px;
    font-size: 12px;
    color: var(--text-tertiary, #5f6f83);
}

.inbox-media-placeholder svg {
    width: 15px;
    height: 15px;
}

.inbox-media-failed {
    font-size: 12px;
    color: var(--text-tertiary, #5f6f83);
}

.inbox-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 11px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: var(--radius-md, 10px);
    background: var(--bg-tertiary, #f1f5f9);
    color: var(--text-primary, #334155);
    font-size: 12.5px;
    cursor: pointer;
    max-width: 240px;
}

.inbox-file-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- compose ---------- */

.inbox-compose {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color, #e2e8f0);
    background: var(--bg-secondary, #fff);
}

.inbox-compose-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

/* Staged attachments: nothing is uploaded or sent until Send is pressed */
.inbox-attachments {
    display: none;
    gap: 8px;
    flex-wrap: wrap;
}

.inbox-attachment {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: var(--radius-md, 10px);
    background: var(--bg-tertiary, #f1f5f9);
    overflow: hidden;
}

.inbox-attachment img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.inbox-attachment-ext {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .04em;
    color: var(--text-secondary, #55657a);
}

.inbox-attachment-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, .6);
    color: #fff;
    cursor: pointer;
}

.inbox-attachment-remove svg {
    width: 11px;
    height: 11px;
}

.inbox-input {
    flex: 1;
    min-height: 38px;
    max-height: 140px;
    padding: 9px 12px;
    border: 1px solid var(--input-border, #e2e8f0);
    border-radius: var(--radius-md, 10px);
    background: var(--input-bg, #f8fafc);
    color: var(--text-primary, #334155);
    font-family: var(--font-family);
    font-size: 13.5px;
    line-height: 1.4;
    resize: none;
    outline: none;
}

.inbox-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--focus-ring, rgba(99, 102, 241, .15));
}

.inbox-send-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: none;
    border-radius: var(--radius-md, 10px);
    background: var(--accent-primary);
    color: var(--on-accent, #fff);
    cursor: pointer;
    transition: background .15s ease;
}

/* Sending: swap the glyph for a spinner so it is obvious the message is on its way.
   currentColor keeps it readable on both the lime (dark) and ink (light) accent. */
.inbox-send-btn.is-sending svg {
    visibility: hidden;
}

.inbox-send-btn.is-sending::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: inbox-spin .7s linear infinite;
}

@keyframes inbox-spin {
    to { transform: rotate(360deg); }
}

.inbox-send-btn:hover:not(:disabled) {
    background: var(--accent-hover, var(--accent-primary));
}

/* Only the button locks while sending - the message box stays typable, so there is
   no .inbox-input:disabled state to style. */
.inbox-send-btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.inbox-send-btn svg {
    width: 17px;
    height: 17px;
}

/* ---------- lightbox ---------- */

.inbox-lightbox {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, .88);
}

.inbox-lightbox.show {
    display: flex;
}

.inbox-lightbox-img {
    max-width: 92vw;
    max-height: 92vh;
    object-fit: contain;
    border-radius: var(--radius-md, 10px);
    cursor: default;
}

.inbox-lightbox-close,
.inbox-lightbox-download {
    position: absolute;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .16);
    color: #fff;
    cursor: pointer;
    transition: background .15s ease;
}

.inbox-lightbox-close:hover,
.inbox-lightbox-download:hover {
    background: rgba(255, 255, 255, .3);
}

.inbox-lightbox-close {
    top: 20px;
    right: 20px;
}

.inbox-lightbox-download {
    right: 24px;
    bottom: 24px;
}

.inbox-lightbox-close svg,
.inbox-lightbox-download svg {
    width: 20px;
    height: 20px;
}

/* ---------- responsive: one pane at a time ---------- */

@media (max-width: 900px) {
    .inbox-shell {
        grid-template-columns: 1fr;
        height: calc(100vh - 150px);
    }

    .inbox-list-pane {
        border-right: none;
    }

    .inbox-thread-pane {
        display: none;
    }

    .inbox-shell.inbox-thread-open .inbox-list-pane {
        display: none;
    }

    .inbox-shell.inbox-thread-open .inbox-thread-pane {
        display: flex;
    }

    .inbox-back-btn {
        display: inline-flex;
    }

    .inbox-msg {
        max-width: 86%;
    }
}
