/*
 * PadniSi Design System - Messaging
 * ----------------------------------
 * Chat drawer, conversation list, message bubbles.
 */

/* --- Chat Product Context --- */
#chatDrawer.padnisi-offcanvas {
    transition: transform 0.18s cubic-bezier(0.2, 0, 0, 1);
    will-change: transform;
}

#chatDrawer.padnisi-offcanvas:not(.show) {
    pointer-events: none;
}

.chat-product-context {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid var(--gray-light);
    gap: 12px;
    overflow: hidden;
}

.chat-product-context__image {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px;
    min-height: 44px;
    flex-shrink: 0;
    border-radius: 6px;
    object-fit: cover;
    background: white;
    border: 1px solid var(--gray-light);
}

.chat-product-context__info {
    flex: 1;
    min-width: 0;
}

.chat-product-context__title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--dark-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-product-context__price {
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 700;
}

.btn-back-to-item {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px 8px;
    margin-right: -4px;
    transition: color 0.2s;
}

.btn-back-to-item:hover {
    color: var(--primary);
}

/* --- Chat Messages Container --- */
.chat-messages {
    display: flex;
    flex-direction: column-reverse;
    overflow-y: auto;
    padding: 20px 16px;
    gap: 12px;
    min-height: 200px;
    max-height: calc(100vh - 240px);
    background: #f9fafc;
}

/* --- Message Bubbles --- */
.chat-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    position: relative;
    transition: transform 0.2s ease;
}

.chat-bubble__text {
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-bubble__image {
    margin-bottom: 10px;
}

.chat-bubble__image a {
    display: block;
    line-height: 0;
}

.chat-bubble__image img {
    display: block;
    max-width: 100%;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    object-fit: cover;
}

.chat-bubble:hover {
    transform: translateY(-1px);
}

.chat-bubble--sent {
    margin-left: auto;
    background: linear-gradient(135deg, var(--primary) 0%, #3a5bd9 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-bubble--received {
    margin-right: auto;
    background: white;
    color: var(--dark-text);
    border-top-left-radius: 4px; border-bottom-left-radius: 18px;
    border: 1px solid #edf1f7;
}

.chat-bubble__meta {
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 6px;
    opacity: 0.8;
}

.chat-bubble--sent .chat-bubble__meta {
    color: rgba(255, 255, 255, 0.8);
    text-align: right;
}

.chat-bubble__sender {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* --- Chat Input Area --- */
.chat-input-area {
    position: sticky;
    bottom: 0;
    padding: 16px;
    border-top: 1px solid var(--gray-light);
    background: white;
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.chat-attach-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(74, 107, 255, 0.2);
    background: white;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(74, 107, 255, 0.08);
}

.chat-attach-btn:hover {
    border-color: var(--primary);
    background: #f8fafc;
    transform: scale(1.05);
}

.chat-attach-btn:active {
    transform: scale(0.95);
}

.chat-image-preview {
    padding: 12px 16px 0;
    background: white;
}

.chat-image-preview__inner {
    position: relative;
    display: inline-block;
    max-width: min(220px, 100%);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.chat-image-preview__inner img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 220px;
    object-fit: cover;
}

.chat-image-preview__clear {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.72);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.chat-image-upload-progress {
    margin-top: 10px;
    height: 4px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(74, 107, 255, 0.12);
}

.chat-image-upload-progress__bar {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, #6f8bff 100%);
    animation: chat-upload-pulse 1.2s ease-in-out infinite;
    transform-origin: left center;
}

.chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 10px 18px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    resize: none;
    outline: none;
    max-height: 120px;
    overflow-y: auto;
    background: #f8fafc;
    transition: all 0.2s ease;
}

.chat-input:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(74, 107, 255, 0.1);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(74, 107, 255, 0.3);
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.chat-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.chat-inline-error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    border-radius: 14px;
    padding: 10px 14px;
    font-size: 0.9rem;
    line-height: 1.4;
}

/* --- Loading indicator --- */
.chat-loading {
    text-align: center;
    padding: 12px;
    color: var(--muted);
    font-size: 0.85rem;
}

.chat-load-more {
    text-align: center;
    padding: 8px;
}

.chat-load-more button {
    background: none;
    border: 1px solid var(--gray-light);
    border-radius: 16px;
    padding: 4px 16px;
    font-size: 0.8rem;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.2s;
}

.chat-load-more button:hover {
    background: var(--light);
    color: var(--dark-text);
}

/* --- Conversation List (Inbox) --- */
.messages-inbox-panel {
    margin: 10px 0 16px;
    padding: 28px 28px 24px;
    border: 1px solid #dfe7f2;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
}

.messages-inbox-panel__intro {
    display: flex;
    align-items: flex-start;
    gap: 22px;
    min-width: 0;
}

.messages-inbox-panel__icon {
    flex: 0 0 auto;
    width: 76px;
    height: 76px;
    border-radius: 8px;
    background: #eef6ff;
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.messages-inbox-panel__copy {
    min-width: 0;
    padding-top: 2px;
}

.messages-inbox-panel__title {
    margin: 0 0 12px;
    color: var(--dark-text);
    font-family: var(--font-heading);
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: 0;
}

.messages-retention-note {
    max-width: 100%;
    margin: 0;
    color: #1f2a44;
    font-family: var(--font-body);
    font-size: 0.98rem;
    line-height: 1.55;
}

.messages-retention-note__text {
    display: block;
    min-width: 0;
    overflow-wrap: break-word;
}

.conversation-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    max-width: 100%;
    margin: 28px 0 0;
}

.conversation-tab {
    min-width: 0;
    height: 56px;
    padding: 0 18px;
    border: 1px solid #dbe4f0;
    border-radius: 8px;
    background: #fff;
    color: var(--dark-text);
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.conversation-tab:hover {
    color: var(--dark-text);
    border-color: #c8d6e8;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.07);
    transform: translateY(-1px);
}

.conversation-tab.active,
.conversation-tab[aria-selected="true"] {
    color: var(--dark-text);
    border-color: #bfd5f4;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.1);
}

.conversation-tab__icon {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.conversation-tab--all .conversation-tab__icon {
    color: var(--primary);
}

.conversation-tab--unread .conversation-tab__icon {
    color: #7b8493;
}

.conversation-tab--archived .conversation-tab__icon {
    color: #ff4a16;
}

.conversation-tab__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-tab__count {
    flex: 0 0 auto;
    min-width: 3.2ch;
    height: 26px;
    margin-left: auto;
    padding: 0 8px;
    border-radius: 8px;
    background: #e9eef8;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.84rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.conversation-tab--all .conversation-tab__count {
    background: rgba(74, 107, 255, 0.12);
    color: var(--primary);
}

.conversation-tab--unread .conversation-tab__count {
    background: #eef1f6;
    color: #1f2a44;
}

.conversation-tab--archived .conversation-tab__count {
    background: rgba(255, 74, 22, 0.12);
    color: #ff4a16;
}

.conversation-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.conversation-item {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) minmax(58px, auto) auto;
    align-items: center;
    column-gap: 12px;
    padding: 12px 16px;
    border: 1px solid var(--gray-light);
    border-left: 3px solid transparent;
    border-radius: 8px;
    cursor: default;
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    background: white;
    text-decoration: none;
    color: inherit;
    min-width: 0;
}

.conversation-item:hover {
    background: var(--light);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.conversation-item--unread {
    font-weight: 600;
    border-left-color: var(--primary);
}

.conversation-item__image {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--light);
}

.conversation-item__image-placeholder {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    background: var(--light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
}

.conversation-item__content {
    flex: 1;
    overflow: hidden;
    min-width: 0;
}

.conversation-item__title {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item__preview {
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.conversation-item__party {
    font-family: var(--font-body);
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--dark-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.conversation-item--unread .conversation-item__preview {
    color: var(--dark-text);
}

.conversation-item__meta {
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    min-width: 58px;
    font-variant-numeric: tabular-nums;
}

.conversation-item__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    min-width: 0;
}

.conversation-item__open,
.conversation-item__archive,
.conversation-item__restore {
    height: 34px;
    border: 1px solid #d8e1ee;
    border-radius: 8px;
    background: #fff;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 10px;
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.conversation-item__open {
    width: 96px;
    color: var(--primary);
}

.conversation-item__archive {
    width: 116px;
}

.conversation-item__restore {
    width: 160px;
}

.conversation-item__open:hover,
.conversation-item__restore:hover {
    border-color: rgba(74, 107, 255, 0.28);
    background: #f8fafc;
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.conversation-item__archive:hover {
    border-color: rgba(255, 74, 22, 0.28);
    background: #fff7ed;
    color: #ff4a16;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.conversation-item__open:disabled,
.conversation-item__archive:disabled,
.conversation-item__restore:disabled {
    cursor: wait;
    opacity: 0.5;
    box-shadow: none;
}

.conversation-item__open span,
.conversation-item__archive span,
.conversation-item__restore span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item__unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
}

/* --- Nav Badge --- */
.pds-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    background: var(--danger);
    border-radius: 9px;
    margin-left: 6px;
}

/* --- Empty State --- */
.chat-empty,
.conversations-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    color: var(--muted);
    text-align: center;
}

.chat-empty i,
.conversations-empty i {
    font-size: 3rem;
    margin-bottom: 20px;
    color: var(--primary);
    opacity: 0.15;
}

.chat-empty p,
.conversations-empty p {
    font-size: 1rem;
    font-weight: 500;
}

/* --- Mobile --- */
@media (max-width: 768px) {
    .chat-bubble {
        max-width: 85%;
    }

    .chat-messages {
        max-height: calc(100vh - 180px);
    }

    .conversation-item__image,
    .conversation-item__image-placeholder {
        width: 40px;
        height: 40px;
    }

    .messages-inbox-panel {
        padding: 18px;
        margin-bottom: 14px;
    }

    .messages-inbox-panel__intro {
        gap: 14px;
    }

    .messages-inbox-panel__icon {
        width: 56px;
        height: 56px;
        font-size: 1.45rem;
    }

    .messages-retention-note {
        font-size: 0.9rem;
        line-height: 1.5;
    }

    .messages-retention-note__text {
        text-align: justify;
        text-align-last: left;
        hyphens: auto;
    }

    .messages-inbox-panel__title {
        margin-bottom: 8px;
        font-size: 1.18rem;
    }

    .conversation-tabs {
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
        margin-top: 16px;
        padding-bottom: 0;
        overflow: visible;
    }

    .conversation-tab {
        width: 100%;
        height: 46px;
        padding: 0 12px;
        gap: 10px;
        font-size: 0.9rem;
    }

    .conversation-tab__icon {
        width: 28px;
        height: 28px;
        font-size: 1.18rem;
    }

    .conversation-tab__count {
        min-width: 3.2ch;
        height: 26px;
        font-size: 0.82rem;
    }

    .conversation-item {
        grid-template-columns: 40px minmax(0, 1fr) minmax(48px, auto);
        align-items: start;
        column-gap: 10px;
        row-gap: 10px;
        padding: 10px;
    }

    .conversation-item__content {
        align-self: center;
    }

    .conversation-item__meta {
        align-self: center;
        min-width: 48px;
        font-size: 0.74rem;
    }

    .conversation-item__actions {
        grid-column: 1 / -1;
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .conversation-item__open,
    .conversation-item__archive,
    .conversation-item__restore {
        width: 100%;
        height: 36px;
        padding: 0 8px;
    }

    .chat-image-preview__inner {
        max-width: 180px;
    }
}

@media (max-width: 420px) {
    .messages-inbox-panel {
        padding: 14px;
    }

    .messages-inbox-panel__intro {
        gap: 12px;
    }

    .messages-inbox-panel__icon {
        width: 48px;
        height: 48px;
        font-size: 1.25rem;
    }

    .messages-retention-note {
        font-size: 0.86rem;
    }

    .conversation-tab {
        height: 44px;
        padding: 0 10px;
        gap: 8px;
    }

    .conversation-tab__icon {
        width: 26px;
        height: 26px;
    }
}

@keyframes chat-upload-pulse {
    0% {
        transform: scaleX(0.25);
        opacity: 0.55;
    }

    50% {
        transform: scaleX(1);
        opacity: 1;
    }

    100% {
        transform: scaleX(0.25);
        opacity: 0.55;
    }
}
