/* retoor <retoor@molodetz.nl> */

.page-messages {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    width: 100%;
    --kb-inset: 0px;
}

.messages-layout {
    display: grid;
    grid-template-columns: minmax(0, 320px) 1fr;
    gap: 0;
    flex: 1 1 auto;
    min-height: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.messages-list {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.messages-list-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.messages-list-header input {
    font-size: 0.8125rem;
}

.search-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    z-index: 100;
    max-height: 240px;
    overflow-y: auto;
}

.search-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    text-decoration: none;
}

.search-dropdown-item:hover {
    background: var(--bg-card-hover);
}

.messages-conversations {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.messages-conversations::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
}

.conversation-item:hover {
    background: var(--bg-card-hover);
}

.conversation-item.active {
    background: var(--accent-light);
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

.conversation-name {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.125rem;
}

.conversation-preview {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 0.6875rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.messages-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

.messages-main-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.messages-main-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.messages-header-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.messages-presence {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.messages-presence.online {
    color: var(--success, var(--accent));
}

.messages-presence.online::before {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success, var(--accent));
    margin-right: 0.3125rem;
    vertical-align: middle;
}

.conversation-unread-dot {
    flex-shrink: 0;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent);
    align-self: center;
}

.conversation-unread-dot[hidden] {
    display: none;
}

.message-receipt {
    font-size: 0.6875rem;
    color: rgba(255, 255, 255, 0.85);
    margin-left: 0.375rem;
    letter-spacing: -2px;
}

.message-receipt[hidden] {
    display: none;
}

.message-bubble.pending {
    opacity: 0.6;
}

.attachment-pending {
    margin-top: 0.35rem;
    font-size: 0.8rem;
    font-style: italic;
    color: var(--text-secondary);
}

.typing-indicator {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card-hover);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 4px;
}

.typing-indicator[hidden] {
    display: none;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.messages-thread {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    padding-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
}

.message-bubble {
    max-width: 70%;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    line-height: 1.5;
    position: relative;
    overflow-wrap: anywhere;
}

.message-bubble.mine {
    align-self: flex-end;
    background: var(--accent);
    color: var(--white);
    border-bottom-right-radius: 4px;
}

.message-bubble.theirs {
    align-self: flex-start;
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    display: block;
}

.message-bubble.mine .message-time {
    color: rgba(255, 255, 255, 0.7);
}

.messages-input-area {
    padding: 0.75rem 1rem;
    padding-bottom: calc(0.75rem + var(--kb-inset) + env(safe-area-inset-bottom));
    padding-left: calc(1rem + env(safe-area-inset-left));
    padding-right: calc(1rem + env(safe-area-inset-right));
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    min-height: 56px;
    background: var(--bg-card);
}

.messages-input-area input[type="text"] {
    flex: 1;
    min-width: 0;
}

.messages-input-area dp-upload {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.messages-input-area dp-upload .dp-upload-chips {
    flex: 0 0 100%;
    order: -1;
    margin-top: 0;
    margin-bottom: 0.5rem;
}

.messages-send-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--accent);
    color: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.messages-send-btn:hover {
    background: var(--accent-hover);
}

.messages-send-btn .send-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid var(--white);
    border-right-color: transparent;
    border-radius: 50%;
    animation: messages-send-spin 0.6s linear infinite;
}

.messages-send-btn.is-sending {
    cursor: default;
    opacity: 0.75;
}

.messages-send-btn.is-sending .send-icon {
    display: none;
}

.messages-send-btn.is-sending .send-spinner {
    display: block;
}

.messages-send-btn:disabled {
    cursor: default;
}

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

.messages-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 0.5rem;
}

.messages-empty p {
    font-size: 0.875rem;
}

.messages-back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.25rem;
    padding: 0.25rem;
    cursor: pointer;
    line-height: 1;
    margin-right: 0.25rem;
}

.messages-back-btn:hover {
    color: var(--accent);
}

@media (max-width: 768px) {
    .messages-layout {
        grid-template-columns: 1fr;
        min-height: 0;
        height: 100%;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    .messages-list {
        display: flex;
        min-height: 0;
        height: 100%;
    }
    .messages-list.hide {
        display: none;
    }
    .messages-main {
        min-height: 0;
        height: 100%;
    }
    .messages-main.hide {
        display: none;
    }
    .messages-back-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .messages-input-area input[type="text"] {
        font-size: 16px;
    }
}

@media (max-width: 360px) {
    .messages-thread {
        padding: 0.75rem;
    }

    .messages-input-area {
        padding: 0.5rem 0.75rem;
        padding-bottom: calc(0.5rem + var(--kb-inset) + env(safe-area-inset-bottom));
        padding-left: calc(0.75rem + env(safe-area-inset-left));
        padding-right: calc(0.75rem + env(safe-area-inset-right));
    }

    .message-bubble {
        max-width: 85%;
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }
}

@media (hover: none) and (pointer: coarse) {
    .messages-send-btn {
        width: 44px;
        height: 44px;
    }
}
