/**
 * Messages Page Styling
 * Clean, professional chat interface
 * Simplified from original - no gradients, minimal custom CSS
 */

/* ==========================================================================
   MESSAGES LAYOUT
   ========================================================================== */
/* Height comes from the hub flex column in app.css; this element is the flex
   item that fills what is left under the tab bar. */
.messages-container {
    overflow-x: hidden;
}

.conversations-panel {
    width: 320px;
    min-width: 320px;
    max-width: 320px;
    background: white;
    border-right: 1px solid var(--hub-border);
    overflow-x: hidden;
    height: 100%; /* Ensure full height within container */
}

/* --------------------------------------------------------------------------
   CONVERSATIONS HEADER (design 1a) — title + New on one row, then search,
   then filter pills. Replaces the stacked h5 / sub-tabs / btn-group / button.
   -------------------------------------------------------------------------- */
.conversations-header {
    padding: 1rem 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.conversations-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.conversations-header-title {
    font-weight: 700;
    font-size: 0.9375rem;
    color: var(--hub-ink);
}

.conversations-new-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    border-radius: var(--hub-radius);
    padding: 0.4375rem 0.75rem;
    font-weight: 600;
    font-size: 0.78125rem;
    line-height: 1.2;
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background-color: var(--hub-canvas);
    position: relative;
}

/* Chat header (design 1a): tighter than the old p-3 h5 block.
   Hidden until a conversation is open — needs !important to beat .d-flex. */
#chat-header.chat-header-hidden {
    display: none !important;
}

#chat-header {
    padding: 0.75rem 1.25rem !important;
    border-bottom: 1px solid var(--hub-border) !important;
}

#chat-header-title {
    font-size: 0.84375rem;
    font-weight: 600;
    color: var(--hub-ink);
}

#chat-header-subtitle {
    font-size: 0.71875rem;
    color: var(--hub-faint);
}

#ai-toggle-container .form-check-label {
    font-size: 0.78125rem;
    font-weight: 600;
    color: #374151;
}

.messages-area .no-conversation-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* ==========================================================================
   CONVERSATION LIST
   ========================================================================== */
.conversation-item {
    cursor: pointer;
    transition: background-color 0.15s ease;
    overflow: hidden;
    display: flex;
    gap: 0.6875rem;
    padding: 0.75rem 1rem;
    /* 3px of the left padding is reserved for the active/unread rule so rows
       don't shift horizontally when they gain one */
    border-left: 3px solid transparent;
    padding-left: 0.8125rem;
    border-top: 1px solid var(--hub-border-soft);
}

.conversation-item:hover {
    background-color: #f8f9fa;
}

.conversation-item.active {
    background-color: var(--hub-row-active);
    border-left-color: var(--primary-color);
}

.conversation-item.conversation-unread {
    background-color: #fef7ef;
    border-left-color: #e67e22;
}

.conversation-item.conversation-unread .conversation-name {
    font-weight: 700;
}

.conversation-item.conversation-unread.active {
    background-color: var(--hub-row-active);
    border-left-color: var(--primary-color);
}

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

.conversation-top {
    display: flex;
    align-items: baseline;
    gap: 0.375rem;
}

.conversation-name {
    font-weight: 600;
    font-size: 0.84375rem;
    color: var(--hub-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-time {
    margin-left: auto;
    flex: none;
    font-size: 0.71875rem;
    color: var(--hub-faint);
}

.conversation-info-btn {
    flex: none;
    font-size: 0.875rem;
    line-height: 1;
    color: var(--hub-faint);
}

.conversation-info-btn:hover {
    color: var(--primary-color);
}

.conversation-stage {
    margin-top: 0.3125rem;
}

.hub-avatar-team {
    background: #e0f5fa;
    color: #0e7490;
}

.conversation-preview {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    display: block;
    color: var(--hub-muted);
    font-size: 0.78125rem;
    margin-top: 0.0625rem;
}

/* ==========================================================================
   MESSAGE BUBBLES - Simplified, no gradients
   ========================================================================== */
.message-wrapper {
    margin-bottom: 8px;
    animation: fadeIn 0.2s ease-in;
}

.message-group {
    max-width: 70%;
}

.sender-label {
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 4px;
    padding-left: 8px;
    color: #6c757d;
}

.message-bubble {
    position: relative;
    word-wrap: break-word;
    border-radius: 18px;
    padding: 0.75rem 1rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* Guest Messages - Light gray, left aligned */
.message-guest {
    background-color: #e9ecef;
    color: #212529;
    border: 1px solid #dee2e6;
    margin-right: auto;
    max-width: 70%;
}

/* AI/Staff Messages - Solid blue, right aligned */
.message-ai,
.message-staff {
    background-color: #0d6efd;  /* Solid blue, no gradient */
    color: white;
    border: none;
    margin-left: auto;
    max-width: 70%;
}

/* Message alignment */
.message-wrapper.justify-content-start .message-bubble {
    margin-right: auto;
}

.message-wrapper.justify-content-end .message-bubble {
    margin-left: auto;
}

/* Message Text */
.message-text {
    font-size: 0.95rem;
    line-height: 1.4;
    margin: 0;
    white-space: pre-line;
}

/* Message Links */
.message-link {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}
.message-link:hover {
    opacity: 0.8;
}

/* Message Time */
.message-time {
    font-size: 0.7rem;
    margin-top: 4px;
    opacity: 0.8;
}

/* ==========================================================================
   DATE SEPARATOR
   ========================================================================== */
.date-separator {
    position: relative;
    margin: 20px 0;
    text-align: center;
}

.date-separator::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #dee2e6;
    z-index: 0;
}

.date-separator .badge {
    position: relative;
    z-index: 1;
    background: #e9ecef;
    color: #495057;
    font-weight: 500;
    font-size: 0.875rem;
    padding: 0.35rem 0.75rem;
}

/* ==========================================================================
   MESSAGE INPUT AREA
   ========================================================================== */
#message-input-area {
    background: white;
    border-top: 1px solid #dee2e6;
    padding: 15px;
}

#message-input-area .input-group {
    gap: 12px;
}

#message-input {
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 0.95rem;
    line-height: 1.4;
    resize: none;
    overflow-y: hidden;      /* grows with content up to max-height, then scrolls */
    max-height: 200px;       /* ~8 lines */
    min-height: 42px;
}
#message-input.is-scrollable {
    overflow-y: auto;
}
#message-input-area .input-group {
    align-items: flex-end;   /* keep Templates + Send anchored to the bottom as the box grows */
}

#send-message {
    border-radius: 20px;
    padding: 8px 20px;
}

/* ==========================================================================
   TYPING INDICATOR
   ========================================================================== */
.typing-indicator {
    display: inline-block;
    padding: 10px 15px;
    background: #e9ecef;
    border-radius: 18px;
    margin-bottom: 10px;
}

.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6c757d;
    margin: 0 2px;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* ==========================================================================
   STATUS INDICATORS
   ========================================================================== */
.status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 5px;
}

.status-indicator.sent {
    background: #28a745;
}

.status-indicator.delivered {
    background: #007bff;
}

.status-indicator.failed {
    background: #dc3545;
}

.status-indicator.pending {
    background: #ffc107;
    animation: pulse 1s infinite;
}

.status-active {
    background-color: #198754;
}

.status-pending {
    background-color: #ffc107;
}

.status-resolved {
    background-color: #6c757d;
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 1;
    }
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */
@media (max-width: 768px) {
    .message-group {
        max-width: 85%;
    }

    .conversations-panel {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }
}

/* ==========================================================================
   SCROLLBAR STYLING - Using global auto-hide from app.css
   ========================================================================== */
/* Scrollbar styles are now handled globally in app.css for consistent behavior */

/* ==========================================================================
   AI FEEDBACK BUTTONS
   ========================================================================== */
.ai-feedback-buttons {
    display: flex;
    align-items: center;
    border-top-color: rgba(255, 255, 255, 0.2) !important;
}

.ai-feedback-buttons .feedback-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.ai-feedback-buttons .feedback-btn:hover:not(:disabled) {
    transform: scale(1.1);
}

.ai-feedback-buttons .feedback-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-feedback-buttons .feedback-btn.btn-outline-success {
    border-color: rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 0.9);
}

.ai-feedback-buttons .feedback-btn.btn-outline-success:hover:not(:disabled) {
    background-color: rgba(25, 135, 84, 0.8);
    border-color: #198754;
}

.ai-feedback-buttons .feedback-btn.btn-outline-danger {
    border-color: rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 0.9);
}

.ai-feedback-buttons .feedback-btn.btn-outline-danger:hover:not(:disabled) {
    background-color: rgba(220, 53, 69, 0.8);
    border-color: #dc3545;
}

/* Message templates (composer dropdown + manage modal) */
.message-templates-menu {
    width: 360px;
    max-width: 90vw;
}
.message-templates-list {
    max-height: 320px;
    overflow-y: auto;
}
.message-template-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.75rem;
    border: 0;
    border-bottom: 1px solid #f1f3f5;
    background: #fff;
}
.message-template-item:hover, .message-template-item:focus {
    background: #f4f7fb;
    outline: none;
}
.message-template-item .mt-name { font-weight: 600; font-size: 0.875rem; }
.message-template-item .mt-snippet {
    font-size: 0.8rem;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.message-template-list { max-height: 420px; overflow-y: auto; }
.message-template-list .list-group-item { cursor: pointer; }
