/* dashboard/messaging/styles.css — Emerald Legacy */

body {
    margin: 0;
    font-family: var(--font-sans);
    color: var(--text-main);
    background: var(--surface);
    height: 100vh;
    overflow: hidden;
}

/* ------------------------------------------------------------------
   Layout
   ------------------------------------------------------------------ */
.messaging-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.messaging-container {
    flex: 1;
    display: flex;
    margin: 20px;
    border: 2px solid var(--border);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    overflow: hidden;
    min-width: 0;
}

/* Desktop: offset for fixed sidebar (280px) */
@media (min-width: 1024px) {
    .messaging-container {
        margin-left: calc(280px + 20px);
        margin-right: 20px;
    }
}

/* ------------------------------------------------------------------
   Inbox pane
   ------------------------------------------------------------------ */
.inbox-pane {
    width: 360px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 2px solid var(--border);
    background: rgba(249, 249, 247, 0.6);
}

.inbox-header {
    padding: 20px 24px;
    border-bottom: 2px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.inbox-header h2 {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-main);
}

.inbox-header > .material-symbols-rounded {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    color: var(--text-light);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.inbox-header > .material-symbols-rounded:hover {
    background: var(--surface-soft);
}

.thread-list {
    flex: 1;
    overflow-y: auto;
}

.thread-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    min-height: 76px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    position: relative;
    transition: background-color 0.2s ease;
}

.thread-item:hover {
    background: #EEF3F0;
}

.thread-item.active {
    background: rgba(1, 50, 32, 0.08);
    border-left: 4px solid var(--primary);
}

.thread-item:focus-visible {
    outline: 3px solid var(--gold);
    outline-offset: -3px;
}

.thread-avatar {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-serif);
    font-size: 1.2rem;
    font-weight: 600;
    border: 2px solid rgba(212, 175, 55, 0.5);
}

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

.thread-info h4 {
    margin: 0 0 4px;
    font-family: var(--font-serif);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-info p {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-light);
}

.thread-item.unread .thread-name {
    font-weight: 800;
}

.thread-item.unread::after {
    content: '';
    position: absolute;
    top: 24px;
    right: 24px;
    width: 10px;
    height: 10px;
    background: #2E8B57;
    border-radius: 50%;
}

.thread-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 5px;
}

.thread-property {
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 5px;
}

.thread-snippet {
    font-size: 0.95rem;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ------------------------------------------------------------------
   Chat pane
   ------------------------------------------------------------------ */
.chat-pane {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
}

.chat-header {
    padding: 18px 24px;
    border-bottom: 2px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(249, 249, 247, 0.8);
    flex-shrink: 0;
}

.chat-header-avatar {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-serif);
    font-size: 1.2rem;
    font-weight: 600;
    border: 2px solid rgba(212, 175, 55, 0.5);
}

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

.chat-header-info h3 {
    margin: 0 0 2px;
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-info p {
    margin: 0;
    font-size: 1rem;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--surface);
}

.message {
    max-width: 70%;
    display: flex;
    flex-direction: column;
}

.message.sent {
    align-self: flex-end;
    align-items: flex-end;
}

.message.received {
    align-self: flex-start;
    align-items: flex-start;
}

.message-bubble {
    position: relative;
    padding: 14px 20px;
    border-radius: 16px;
    font-size: 1.05rem;
    line-height: 1.5;
}

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

.message.received .message-bubble,
.message-bubble.received {
    background: var(--white);
    color: var(--text-main);
    border: 2px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-time {
    display: block;
    margin-top: 6px;
    font-size: 0.8rem;
    line-height: 1.2;
    opacity: 0.75;
    text-align: right;
}

/* ------------------------------------------------------------------
   Input area
   ------------------------------------------------------------------ */
.chat-input-area {
    padding: 20px 24px;
    border-top: 2px solid var(--border);
    background: rgba(249, 249, 247, 0.8);
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    min-height: 56px;
    padding: 14px 22px;
    border: 2px solid var(--border);
    border-radius: 28px;
    font-family: var(--font-sans);
    font-size: 1.05rem;
    color: var(--text-main);
    background: var(--white);
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-input:focus {
    border-color: var(--primary);
    outline: 3px solid var(--gold);
    outline-offset: 2px;
}

.btn-send {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.btn-send .material-symbols-rounded {
    font-size: 1.5rem;
}

.btn-send:focus-visible {
    outline: 3px solid var(--gold);
    outline-offset: 2px;
}

/* ------------------------------------------------------------------
   Empty chat state
   ------------------------------------------------------------------ */
.empty-chat-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 24px;
    text-align: center;
}

.empty-chat-state .material-symbols-rounded {
    font-size: 4rem;
    color: var(--border);
    margin-bottom: 10px;
}

.empty-chat-state h3 {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-main);
}

.empty-chat-state p {
    margin: 0;
    font-size: 1.05rem;
    color: var(--text-light);
}

/* ------------------------------------------------------------------
   Back button
   ------------------------------------------------------------------ */
.chat-back-btn {
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.chat-back-btn:hover {
    background: var(--border);
}

.chat-back-btn:focus-visible {
    outline: 3px solid var(--gold);
    outline-offset: 2px;
}

.chat-back-btn .material-symbols-rounded {
    font-size: 1.5rem;
}

/* ------------------------------------------------------------------
   Motion, forced-colors & responsive
   ------------------------------------------------------------------ */
@media (prefers-reduced-motion: no-preference) {
    .messaging-container {
        box-shadow: 0 8px 24px rgba(1, 50, 32, 0.08);
    }

    .btn-send:hover {
        background: var(--primary-hover);
        transform: scale(1.05);
    }
}

@media (forced-colors: active) {
    .messaging-container {
        border-color: CanvasText;
    }

    .message .message-bubble {
        border: 2px solid CanvasText;
    }
}

@media (max-width: 767px) {
    body {
        height: 100dvh;
    }

    .messaging-layout {
        height: 100dvh;
    }

    .messaging-container {
        margin: 10px;
    }

    .inbox-pane {
        width: 100%;
        border-right: none;
    }

    .chat-pane {
        display: none;
    }

    .messaging-container:has(#activeChatContent[style*="flex"]) .inbox-pane {
        display: none;
    }

    .messaging-container:has(#activeChatContent[style*="flex"]) .chat-pane {
        display: flex;
    }

    .chat-back-btn {
        display: flex;
    }

    .message {
        max-width: 85%;
    }

    .chat-input-area {
        padding: 14px 16px;
        gap: 12px;
    }

    .chat-history {
        padding: 16px;
    }

    .chat-header {
        padding: 14px 16px;
    }

    .chat-input {
        min-height: 52px;
        padding: 12px 18px;
    }
}

@media (max-width: 480px) {
    .messaging-container {
        margin: 0;
        border-radius: 0;
        border: none;
        border-top: 2px solid var(--border);
        height: 100%;
    }

    .inbox-header {
        padding: 15px;
    }

    .thread-item {
        padding: 14px 16px;
    }
}

/* Tablet (768-1023px): persistent split pane (38/62), search-ready inbox, hidden back btn */
@media (min-width: 768px) and (max-width: 1023px) {
    .messaging-container {
        margin: 16px;
    }

    .inbox-pane {
        width: 38%;
        border-right: 2px solid var(--border);
    }

    .chat-pane {
        display: flex;
    }

    .chat-back-btn {
        display: none;
    }

    .inbox-header {
        flex-wrap: wrap;
        gap: 12px;
        padding: 16px 20px;
    }

    .inbox-header h2 {
        font-size: 1.3rem;
    }

    .inbox-search {
        flex: 1 1 100%;
        order: 3;
        margin-top: 2px;
    }

    .inbox-search input {
        min-height: 56px;
    }

    .inbox-header > .material-symbols-rounded,
    .inbox-header .mobile-menu-btn {
        width: 56px;
        height: 56px;
    }

    .thread-item {
        padding: 14px 20px;
    }

    .chat-header {
        padding: 16px 20px;
    }

    .chat-history {
        padding: 20px;
    }

    .chat-input-area {
        padding: 16px 20px;
    }
}
