/* ===========================================
   UNIFIED MESSAGING INTERFACE
   =========================================== */

.messaging-interface {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

.messaging-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e9ecef;
}

.messaging-title {
    margin: 0 0 8px 0;
    color: #2d3748;
    font-size: 2rem;
    font-weight: 700;
}

.messaging-subtitle {
    margin: 0;
    color: #718096;
    font-size: 1.1rem;
}

/* Conversation Selector (Tutor only) */
.conversation-selector {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.conversation-selector label {
    font-weight: 600;
    color: #4a5568;
    white-space: nowrap;
}

.conversation-selector select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    font-size: 0.95rem;
}

.conversation-selector button {
    white-space: nowrap;
}

/* Messages Container */
.messages-container {
    background: white;
    border: 1px solid #e0e6ed;
    border-radius: 12px;
    min-height: 400px;
    max-height: 500px;
    overflow-y: auto;
    margin-bottom: 20px;
    padding: 0;
}

/* Message Items */
.message-item {
    padding: 16px 20px;
    border-bottom: 1px solid #f0f4f8;
}

.message-item:last-child {
    border-bottom: none;
}

.message-from-user {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message-from-user .message-header {
    color: rgba(255, 255, 255, 0.9);
}

.message-from-other {
    background: #f8fafc;
    color: #2d3748;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.875rem;
}

.message-sender {
    font-weight: 600;
}

.message-time {
    opacity: 0.7;
    font-size: 0.8rem;
}

.message-content {
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
}

/* Sending State */
.message-sending {
    opacity: 0.7;
    position: relative;
}

.message-sending::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 16px;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    animation: message-spinner 1s linear infinite;
}

@keyframes message-spinner {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Empty States */
.no-messages {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: #718096;
}

.no-messages-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.6;
}

.no-messages h3 {
    margin: 0 0 8px 0;
    color: #4a5568;
}

.no-messages p {
    margin: 0;
    font-size: 0.9rem;
}

/* Error States */
.messaging-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: #e53e3e;
    background: #fed7d7;
    border-radius: 8px;
    margin: 20px;
}

.error-icon {
    font-size: 2rem;
    margin-bottom: 12px;
}

.messaging-error p {
    margin: 0 0 16px 0;
    font-weight: 500;
}

/* Message Compose */
.message-compose {
    background: white;
    border: 1px solid #e0e6ed;
    border-radius: 12px;
    padding: 20px;
}

.message-input-container {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.message-input-container textarea {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.2s ease;
}

.message-input-container textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.message-input-container button {
    height: 48px;
    min-width: 120px;
    white-space: nowrap;
}

/* Real-time Connection Status */
.connection-status {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    z-index: 1000;
    transition: all 0.3s ease;
}

.connection-status.connected {
    background: #c6f6d5;
    color: #22543d;
    border: 1px solid #9ae6b4;
}

.connection-status.disconnected {
    background: #fed7d7;
    color: #742a2a;
    border: 1px solid #feb2b2;
}

.connection-status.connecting {
    background: #feebc8;
    color: #7b341e;
    border: 1px solid #f6ad55;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .messaging-interface {
        padding: 16px;
    }

    .messaging-header {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .messaging-title {
        font-size: 1.5rem;
    }

    .conversation-selector {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .conversation-selector label {
        font-size: 0.9rem;
    }

    .message-input-container {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .message-input-container button {
        height: 44px;
        min-width: unset;
    }

    .messages-container {
        max-height: 350px;
    }

    .connection-status {
        position: relative;
        top: auto;
        right: auto;
        margin-bottom: 16px;
        text-align: center;
    }
}

/* Focus and hover states */
.conversation-selector select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
}

/* Scrollbar styling */
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}