/* ==========================================================================
   Messaging System Styles
   ========================================================================== */

/* --------------------------------------------------------------------------
   Container & Layout
   -------------------------------------------------------------------------- */

.messaging-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    /* Uses ui-panel for glass effect border/shadow */
}

.loading-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */

.messaging-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background-color: var(--card-bg-solid);
    border-bottom: 1px solid var(--fluent-border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.messaging-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--fluent-text-primary);
    margin: 0;
}

.unread-badge {
    background-color: var(--fluent-primary);
    color: white;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.compose-btn {
    font-weight: 500;
}

/* --------------------------------------------------------------------------
   Main Content
   -------------------------------------------------------------------------- */

.messaging-content {
    display: flex;
    flex: 1;
    min-height: 0;  /* Required for nested flex shrinking */
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */

.messaging-sidebar {
    width: 360px;
    min-width: 280px;
    max-width: 420px;
    background-color: var(--card-bg-solid);
    border-right: 1px solid var(--fluent-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Filter Tabs */
.filter-tabs {
    display: flex;
    padding: 12px 16px;
    gap: 4px;
    border-bottom: 1px solid var(--fluent-border);
}

.filter-tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--fluent-text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-tab:hover {
    background-color: var(--fluent-bg-tertiary);
}

.filter-tab.active {
    background-color: var(--badge-info-bg);
    color: var(--fluent-primary);
}

.filter-count {
    background-color: var(--fluent-text-secondary);
    color: white;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 10px;
}

.filter-tab.active .filter-count {
    background-color: var(--fluent-primary);
}

/* Search */
.search-container {
    padding: 12px 16px;
}

.search-input {
    width: 100%;
}

/* Course Filter */
.course-filter {
    padding: 0 16px 12px;
}

.course-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--fluent-border);
    border-radius: 6px;
    font-size: 14px;
    background-color: var(--input-bg);
}

/* --------------------------------------------------------------------------
   Conversation List
   -------------------------------------------------------------------------- */

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.loading-spinner {
    display: flex;
    justify-content: center;
    padding: 24px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    color: var(--fluent-text-secondary);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-text {
    font-size: 16px;
    font-weight: 500;
    margin: 0;
}

.empty-subtext {
    font-size: 14px;
    margin: 4px 0 0;
}

/* Conversation Item */
.conversation-item {
    display: flex;
    align-items: flex-start;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    margin-bottom: 4px;
}

.conversation-item:hover {
    background-color: var(--fluent-bg-tertiary);
}

.conversation-item.selected {
    background-color: var(--badge-info-bg);
}

.conversation-item.unread {
    background-color: var(--badge-info-bg);
}

.conversation-item.unread:hover {
    background-color: var(--badge-info-bg);
}

.conversation-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: var(--fluent-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 12px;
}

.conversation-avatar .avatar-image {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-text {
    color: white;
    font-weight: 600;
    font-size: 16px;
}

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

.conversation-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.conversation-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--fluent-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 12px;
    color: var(--fluent-text-muted);
    flex-shrink: 0;
    margin-left: 8px;
}

.conversation-preview {
    font-size: 13px;
    color: var(--fluent-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.pin-icon {
    font-size: 12px;
}

.conversation-context {
    margin-top: 4px;
}

.context-badge {
    font-size: 11px;
    padding: 2px 6px;
    background-color: var(--fluent-bg-secondary);
    border-radius: 4px;
    color: var(--fluent-text-secondary);
}

.unread-indicator {
    background-color: var(--fluent-primary);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    flex-shrink: 0;
    margin-left: 8px;
}

.load-more {
    display: flex;
    justify-content: center;
    padding: 12px;
}

/* --------------------------------------------------------------------------
   Main View - No Conversation Selected
   -------------------------------------------------------------------------- */

.messaging-main {
    flex: 1;
    min-height: 0;  /* Required for nested flex shrinking */
    display: flex;
    flex-direction: column;
    background-color: var(--fluent-bg-primary);
    overflow: hidden;
}

.no-conversation-selected {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--fluent-text-secondary);
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.no-conversation-selected h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 8px;
    color: var(--fluent-text-primary);
}

.no-conversation-selected p {
    font-size: 14px;
    margin: 0;
}

/* --------------------------------------------------------------------------
   Conversation View
   -------------------------------------------------------------------------- */

.conversation-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;  /* Required for nested flex shrinking */
    overflow: hidden;  /* Prevent children from overflowing */
    background-color: var(--card-bg-solid);
}

/* Conversation Header */
.conversation-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background-color: var(--card-bg-solid);
    border-bottom: 1px solid var(--fluent-border);
    position: relative;
}

.back-button {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    margin-right: 8px;
    color: var(--fluent-text-secondary);
}

.conversation-info {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.conversation-avatar-lg {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--fluent-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
}

.conversation-avatar-lg .avatar-image {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.conversation-details {
    min-width: 0;
}

.conversation-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.typing-indicator {
    font-size: 12px;
    color: var(--fluent-success);
    font-style: italic;
}

.member-count {
    font-size: 12px;
    color: var(--fluent-text-muted);
}

.conversation-actions {
    display: flex;
    gap: 4px;
}

.action-btn {
    padding: 8px;
}

/* Options Menu */
.options-menu {
    position: absolute;
    top: 100%;
    right: 16px;
    background-color: var(--card-bg-solid);
    border: 1px solid var(--fluent-border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100;
    min-width: 180px;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    text-align: left;
    font-size: 14px;
    cursor: pointer;
    color: var(--fluent-text-primary);
}

.menu-item:hover {
    background-color: var(--fluent-bg-tertiary);
}

.menu-item.danger {
    color: var(--fluent-danger);
}

/* --------------------------------------------------------------------------
   Messages Container
   -------------------------------------------------------------------------- */

.messages-container {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.loading-messages,
.no-messages {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: var(--fluent-text-secondary);
}

.load-more-messages {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
}

/* Date Divider */
.date-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
}

.date-divider span {
    background-color: var(--fluent-bg-secondary);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    color: var(--fluent-text-secondary);
}

/* Message */
.message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 70%;
    position: relative;
}

.message.own-message {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message.other-message {
    margin-right: auto;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--fluent-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-avatar .avatar-image-sm {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-text-sm {
    color: white;
    font-size: 12px;
    font-weight: 600;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    max-width: 100%;
}

.own-message .message-bubble {
    background-color: var(--fluent-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.other-message .message-bubble {
    background-color: var(--fluent-bg-secondary);
    color: var(--fluent-text-primary);
    border-bottom-left-radius: 4px;
}

.message.deleted .message-bubble {
    background-color: var(--fluent-bg-secondary);
    color: var(--fluent-text-muted);
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--fluent-primary);
}

.message-subject {
    font-weight: 600;
    margin-bottom: 4px;
}

.message-content {
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.message-content p {
    margin: 0;
}

.deleted-content {
    font-style: italic;
}

/* Message Attachments */
.message-attachments {
    margin-top: 8px;
}

.attachment-item {
    margin-top: 4px;
}

.attachment-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
}

.attachment-link {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    text-decoration: none;
    color: inherit;
    font-size: 13px;
}

.attachment-icon {
    font-size: 16px;
}

.attachment-size {
    font-size: 11px;
    opacity: 0.7;
}

/* Message Reactions */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.reaction-badge {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    background-color: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 12px;
}

.reaction-badge:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

.reaction-emoji {
    font-size: 14px;
}

.reaction-count {
    font-size: 11px;
}

/* Message Meta */
.message-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.7;
}

.read-indicator {
    color: var(--fluent-success);
}

.own-message .read-indicator {
    color: rgba(255, 255, 255, 0.8);
}

.star-indicator,
.important-indicator {
    font-size: 10px;
}

/* Message Actions */
.message-actions {
    position: relative;
    z-index: 1001;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message:hover .message-actions {
    opacity: 1;
}

.action-btn-sm {
    padding: 4px 6px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    border-radius: 4px;
}

.action-btn-sm:hover {
    background-color: var(--fluent-bg-tertiary);
}

/* --------------------------------------------------------------------------
   Compose Area
   -------------------------------------------------------------------------- */

.compose-area {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 12px 16px;
    background-color: var(--card-bg-solid);
    border-top: 1px solid var(--fluent-border);
}

.compose-input-container {
    flex: 1;
}

.message-editor {
    min-height: 60px;
}

.compose-actions {
    display: flex;
    gap: 8px;
}

.send-btn {
    height: 40px;
    min-width: 80px;
}

/* --------------------------------------------------------------------------
   Reaction Picker - Glass Panel Popup (matches .floating-glass-content)
   -------------------------------------------------------------------------- */

.reaction-picker-popup {
    position: absolute;
    bottom: 100%;
    left: 0;
    z-index: 1000;
    margin-bottom: 8px;

    /* Match .floating-glass-content exactly */
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);

    /* 3 rows x 4 columns grid layout */
    display: grid;
    grid-template-columns: repeat(4, 48px);
    grid-template-rows: repeat(3, 48px);
    gap: 4px;

    animation: reactionPickerFadeIn 0.15s ease-out;
}

@keyframes reactionPickerFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.reaction-picker-popup .emoji-btn {
    font-size: 1.75rem;
    width: 48px;
    height: 48px;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.15s ease, background-color 0.2s ease;
}

.reaction-picker-popup .emoji-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    transform: scale(1.3);
}

.reaction-picker-popup .emoji-btn:active {
    transform: scale(1.15);
}

/* Own message - position on the right */
.own-message .reaction-picker-popup {
    left: auto;
    right: 0;
}

/* Open downward when in top portion of screen */
.reaction-picker-popup.open-downward {
    bottom: auto;
    top: 100%;
    margin-bottom: 0;
    margin-top: 8px;
}

@keyframes reactionPickerFadeInDown {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.reaction-picker-popup.open-downward {
    animation: reactionPickerFadeInDown 0.15s ease-out;
}

/* Click-outside overlay */
.reaction-picker-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
}

/* Dark mode support - match .floating-glass-content dark mode */
@media (prefers-color-scheme: dark) {
    .reaction-picker-popup {
        background: rgba(30, 30, 30, 0.85);
        border-color: rgba(255, 255, 255, 0.12);
        box-shadow:
            0 8px 32px rgba(0, 0, 0, 0.4),
            0 2px 8px rgba(0, 0, 0, 0.3),
            0 0 20px rgba(59, 130, 246, 0.15),
            inset 0 1px 0 rgba(255, 255, 255, 0.1);
    }

    .reaction-picker-popup .emoji-btn:hover {
        background: rgba(255, 255, 255, 0.12);
    }
}

[data-theme="dark"] .reaction-picker-popup {
    background: rgba(30, 30, 30, 0.85);
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.4),
        0 2px 8px rgba(0, 0, 0, 0.3),
        0 0 20px rgba(59, 130, 246, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .reaction-picker-popup .emoji-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* --------------------------------------------------------------------------
   Report Dialog
   -------------------------------------------------------------------------- */

.report-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.report-form label {
    font-weight: 500;
    font-size: 14px;
}

.report-select {
    padding: 8px 12px;
    border: 1px solid var(--fluent-border);
    border-radius: 6px;
    font-size: 14px;
}

.report-description {
    padding: 8px 12px;
    border: 1px solid var(--fluent-border);
    border-radius: 6px;
    font-size: 14px;
    min-height: 80px;
    resize: vertical;
}

.report-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

/* --------------------------------------------------------------------------
   Compose Message Component
   -------------------------------------------------------------------------- */

.compose-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
}

.compose-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.compose-field-grow {
    flex: 1;
}

.field-label {
    font-weight: 500;
    font-size: 14px;
    color: var(--fluent-text-secondary);
}

.recipients-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.selected-recipients {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.recipient-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 4px 12px;
    background-color: var(--badge-info-bg);
    border-radius: 16px;
    font-size: 13px;
}

.remove-chip {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    font-size: 12px;
    color: var(--fluent-text-secondary);
}

.remove-chip:hover {
    color: var(--fluent-danger);
}

.recipient-search {
    width: 100%;
}

.recipient-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
}

.recipient-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--fluent-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
}

.recipient-info {
    flex: 1;
}

.recipient-name {
    font-weight: 500;
    font-size: 14px;
}

.recipient-email {
    font-size: 12px;
    color: var(--fluent-text-muted);
}

.recipient-role {
    font-size: 11px;
    padding: 1px 6px;
    background-color: var(--fluent-bg-secondary);
    border-radius: 4px;
    margin-top: 2px;
    display: inline-block;
}

.course-dropdown,
.subject-input {
    width: 100%;
}

.compose-options {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 12px;
    background-color: var(--fluent-bg-secondary);
    border-radius: 8px;
}

.option-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.option-group label {
    font-size: 13px;
    color: var(--fluent-text-secondary);
}

.priority-dropdown {
    width: 120px;
}

.schedule-picker {
    width: 200px;
}

.error-message {
    color: var(--fluent-danger);
    font-size: 13px;
    padding: 8px 12px;
    background-color: var(--badge-danger-bg);
    border-radius: 6px;
}

.compose-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--fluent-border);
}

/* --------------------------------------------------------------------------
   Responsive Design
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
    .messaging-content {
        position: relative;
    }

    .messaging-sidebar {
        width: 100%;
        max-width: none;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
    }

    .messaging-sidebar.hidden-mobile {
        display: none;
    }

    .messaging-main {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 20;
    }

    .messaging-main.hidden-mobile {
        display: none;
    }

    .back-button {
        display: block;
    }

    .mobile-only {
        display: block;
    }

    .message {
        max-width: 85%;
    }
}

@media (max-width: 480px) {
    .messaging-header {
        padding: 12px 16px;
    }

    .messaging-title {
        font-size: 20px;
    }

    .filter-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .filter-tab {
        white-space: nowrap;
    }
}

/* --------------------------------------------------------------------------
   Compose Dialog
   -------------------------------------------------------------------------- */

.compose-dialog .e-dlg-content {
    padding: 0;
}
