/* Portal chat panel — slide-in from right */

.portal-chat-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 300;
    opacity: 0;
    transition: opacity 240ms ease;
}

.portal-chat-backdrop.is-open {
    display: block;
}

.portal-chat-backdrop.is-visible {
    opacity: 1;
}

/* Panel */
.portal-chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 25%;
    min-width: 320px;
    background: var(--white-color);
    z-index: 400;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 280ms cubic-bezier(0.4, 0, 0.2, 1);
}

.portal-chat-panel.is-open {
    transform: translateX(0);
}

/* Header */
.portal-chat-panel__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--gray-color);
    flex-shrink: 0;
}

.portal-chat-panel__title {
    flex: 1;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.portal-chat-panel__subtitle {
    font-size: 0.78rem;
    color: var(--secondary-text-color);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.portal-chat-panel__close {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--dark-gray-color);
    transition: background 150ms ease, color 150ms ease;
}

.portal-chat-panel__close:hover {
    background: var(--light-gray-color);
    color: var(--black-color);
}

/* Messages */
.portal-chat-panel__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.portal-chat-panel__empty {
    margin: auto;
    text-align: center;
    color: var(--secondary-text-color);
    font-size: 0.88rem;
    line-height: 1.6;
    padding: 24px 16px;
}

.portal-chat-panel__empty svg {
    display: block;
    margin: 0 auto 12px;
    color: var(--dark-gray-color);
    opacity: 0.5;
}

/* Message bubbles */
.portal-chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.portal-chat-msg--in {
    align-self: flex-end;
    align-items: flex-end;
}

.portal-chat-msg--out {
    align-self: flex-start;
    align-items: flex-start;
}

.portal-chat-msg__bubble {
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.portal-chat-msg--in .portal-chat-msg__bubble {
    background: var(--primary-color);
    color: var(--white-color);
    border-bottom-right-radius: 4px;
}

.portal-chat-msg--out .portal-chat-msg__bubble {
    background: var(--light-gray-color);
    color: var(--black-color);
    border-bottom-left-radius: 4px;
}

.portal-chat-msg__time {
    font-size: 0.72rem;
    color: var(--secondary-text-color);
    margin-top: 3px;
    padding: 0 2px;
}

/* Loading state */
.portal-chat-panel__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--secondary-text-color);
    font-size: 0.88rem;
    gap: 8px;
}

/* Bottom input area */
.portal-chat-panel__bottom {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--gray-color);
    flex-shrink: 0;
}

.portal-chat-panel__textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--input-border-color);
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 0.88rem;
    line-height: 1.5;
    background: var(--input-background-color);
    font-family: inherit;
    outline: none;
    transition: border-color 150ms ease;
    overflow-y: hidden;
}

.portal-chat-panel__textarea:focus {
    border-color: var(--primary-color);
}

.portal-chat-panel__textarea::placeholder {
    color: var(--input-placeholder-color);
}

.portal-chat-panel__send {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: var(--primary-color);
    color: var(--white-color);
    cursor: pointer;
    transition: opacity 150ms ease;
}

.portal-chat-panel__send:hover {
    opacity: 0.85;
}

.portal-chat-panel__send:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Mobile: fullscreen */
@media (max-width: 767px) {
    .portal-chat-panel {
        width: 100%;
        min-width: 0;
    }

    /* Prevent auto-zoom on input focus in iOS/Android */
    .portal-chat-panel__textarea {
        font-size: 16px;
    }
}

/* ---------- Kebab menu + delete confirm modal ---------- */

.portal-chat-msg {
    position: relative;
}

.portal-chat-msg__kebab {
    position: absolute;
    top: 4px;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: rgba(0, 0, 0, 0.55);
    cursor: pointer;
    border-radius: 50%;
    display: grid;
    place-items: center;
    padding: 0;
    opacity: 0;
    transition: opacity 120ms ease, background-color 120ms ease;
}

.portal-chat-msg--in .portal-chat-msg__kebab {
    left: -26px;
}

.portal-chat-msg--out .portal-chat-msg__kebab {
    right: -26px;
}

.portal-chat-msg:hover .portal-chat-msg__kebab,
.portal-chat-msg__kebab[aria-expanded="true"] {
    opacity: 1;
}

.portal-chat-msg__kebab:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

.portal-chat-msg__kebab svg {
    width: 14px;
    height: 14px;
}

.portal-chat-menu {
    position: fixed;
    z-index: 410;
    min-width: 180px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.06);
    padding: 4px;
    display: none;
    flex-direction: column;
}

.portal-chat-menu.is-open {
    display: flex;
}

.portal-chat-menu__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border: none;
    background: transparent;
    color: #1a1a1a;
    font-size: 14px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
}

.portal-chat-menu__item:hover {
    background-color: #f3f4f6;
}

.portal-chat-menu__item--danger {
    color: #d4351c;
}

.portal-chat-menu__item--danger:hover {
    background-color: rgba(212, 53, 28, 0.08);
}

.portal-chat-menu__item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.portal-chat-msg__deleted {
    font-style: italic;
    opacity: 0.65;
}

.portal-confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 420;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.portal-confirm-modal.is-open {
    display: flex;
}

.portal-confirm-modal__dialog {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.25);
    padding: 24px;
    max-width: 380px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.portal-confirm-modal__title {
    font-size: 17px;
    font-weight: 600;
    margin: 0;
    color: #1a1a1a;
}

.portal-confirm-modal__text {
    color: #4b5563;
    margin: 0;
    font-size: 14px;
}

.portal-confirm-modal__actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 4px;
}

.portal-confirm-modal__btn {
    padding: 9px 18px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
}

.portal-confirm-modal__btn--secondary {
    background: #f3f4f6;
    color: #1a1a1a;
}

.portal-confirm-modal__btn--secondary:hover {
    background: #e5e7eb;
}

.portal-confirm-modal__btn--danger {
    background: #d4351c;
    color: #fff;
}

.portal-confirm-modal__btn--danger:hover {
    background: #b8301a;
}
