/* Messages Page Styling - Following Auth.css patterns */

.messages-container {
    min-height: calc(100vh - 200px);
    padding: 2rem 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.messages-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.messages-header h1 {
    font-size: 1.8rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: -0.5px;
    margin: 0;
}

/* Button Styles - matching auth-button.secondary */
.msg-btn {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.msg-btn:hover:not(:disabled) {
    background: var(--background);
    border-color: var(--text-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
}

.msg-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.msg-btn.primary {
    background: var(--text-color);
    color: var(--background);
    border-color: var(--text-color);
}

.msg-btn.primary:hover:not(:disabled) {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.msg-btn.danger {
    background: #ef4444;
    border-color: #ef4444;
    color: #ffffff;
}

.msg-btn.danger:hover:not(:disabled) {
    background: #b91c1c;
    border-color: #b91c1c;
}

.msg-btn.success {
    background: #10b981;
    border-color: #10b981;
    color: #ffffff;
}

.msg-btn.success:hover:not(:disabled) {
    background: #059669;
    border-color: #059669;
}

/* Form Card */
.msg-form-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 2rem;
    margin-bottom: 2rem;
}

.msg-form-card h2 {
    font-size: 1rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 1.5rem;
}

.msg-input {
    width: 100%;
    padding: 1rem;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    border-radius: 0;
    outline: none;
    transition: border-color 0.2s;
}

.msg-input:focus {
    border-color: var(--text-color);
}

.msg-input::placeholder {
    color: var(--text-secondary);
}

/* Grid Layout */
.messages-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .messages-grid {
        grid-template-columns: 1fr;
    }
}

/* Conversation List */
.conversation-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 550px;
    overflow-y: auto;
}

.conversation-item {
    width: 100%;
    text-align: left;
    padding: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.conversation-item:hover {
    border-color: var(--text-color);
}

.conversation-item.active {
    background: var(--text-color);
    color: var(--background);
    border-color: var(--text-color);
}

.conversation-item.closed {
    opacity: 0.6;
}

.conversation-subject {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.conversation-preview {
    font-size: 0.8rem;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-meta {
    font-size: 0.7rem;
    opacity: 0.5;
    margin-top: 0.25rem;
}

.unread-badge {
    background: #ef4444;
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.4rem;
    border-radius: 999px;
    flex-shrink: 0;
}

/* Chat Panel */
.chat-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-height: 550px;
}

.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.chat-header h2 {
    font-weight: 700;
    font-size: 1rem;
    margin: 0;
}

.chat-header .product-link {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message-wrapper {
    display: flex;
}

.message-wrapper.mine {
    justify-content: flex-end;
}

.message-wrapper.theirs {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
}

.message-wrapper.mine .message-bubble {
    background: var(--text-color);
    color: var(--background);
    border-bottom-right-radius: 4px;
}

.message-wrapper.theirs .message-bubble {
    background: var(--input-bg);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
}

.message-sender {
    font-size: 0.7rem;
    font-weight: 700;
    opacity: 0.7;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.message-content {
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Chat Input */
.chat-input-area {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
}

.chat-input-area input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.9rem;
    outline: none;
}

.chat-input-area input:focus {
    border-color: var(--text-color);
}

/* Resolved Banner - matches auth-success */
.resolved-banner {
    background: #f0fdf4;
    color: #166534;
    border-top: 1px solid #10b981;
    padding: 1rem 1.5rem;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
}

:root[class~="dark"] .resolved-banner {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

/* Empty State */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    padding: 3rem;
}

.empty-state svg {
    opacity: 0.3;
    margin-bottom: 1rem;
}

/* Modal Overlay - high z-index to cover navbar */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 2rem;
    max-width: 400px;
    width: 100%;
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 700;
}

.modal-header.danger {
    color: #ef4444;
}

.modal-header.success {
    color: #10b981;
}

.modal-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
}

.modal-actions .msg-btn {
    flex: 1;
}

/* Action buttons on conversation items */
.conversation-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.25rem;
}

.action-btn {
    padding: 0.35rem;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn.resolve {
    background: #10b981;
    color: white;
}

.action-btn.resolve:hover {
    background: #059669;
}

.action-btn.delete {
    background: #ef4444;
    color: white;
}

.action-btn.delete:hover {
    background: #b91c1c;
}