/**
 * Family Chat CSS - Professional Modern Design
 * Inspired by WhatsApp/Telegram UI
 */

/* ============================================
   VARIABLES & RESET
   ============================================ */
:root {
    --primary-blue: #0084ff;
    --primary-blue-dark: #0066cc;
    --bg-main: #ffffff;
    --bg-sidebar: #f0f2f5;
    --bg-messages: #e5ddd5;
    --bg-bubble-own: #dcf8c6;
    --bg-bubble-other: #ffffff;
    --text-primary: #111;
    --text-secondary: #667781;
    --border-color: #e9edef;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.08);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.12);
}

* {
    box-sizing: border-box;
}

/* ============================================
   MAIN CONTAINER
   ============================================ */
.family-chat-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    background: var(--bg-main);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Loading State */
.family-chat-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 500px;
    background: var(--bg-sidebar);
}

.family-chat-loading .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e0e0e0;
    border-top-color: var(--primary-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   MAIN LAYOUT
   ============================================ */
.family-chat-main {
    display: flex;
    height: 700px;
}

/* ============================================
   SIDEBAR
   ============================================ */
.family-chat-sidebar {
    width: 340px;
    background: var(--bg-main);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.chat-sidebar-header {
    padding: 18px 20px;
    background: #f0f2f5;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-sidebar-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-create-house-chat {
    background: var(--primary-blue);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-create-house-chat:hover {
    background: var(--primary-blue-dark);
    transform: scale(1.05);
}

.chat-room-search {
    padding: 12px 16px;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-color);
}

.room-search-input {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    background: var(--bg-sidebar);
    transition: all 0.2s;
}

.room-search-input:focus {
    border-color: var(--primary-blue);
    background: var(--bg-main);
}

.chat-room-section {
    overflow-y: auto;
    flex: 1;
}

.section-title {
    padding: 12px 20px 8px;
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.chat-room-list {
    display: flex;
    flex-direction: column;
}

.no-rooms {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Room Item */
.room-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(0,0,0,0.03);
}

.room-item:hover {
    background: var(--bg-sidebar);
}

.room-item.active {
    background: #e7f3ff;
    border-left: 4px solid var(--primary-blue);
}

.room-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    margin-right: 14px;
    flex-shrink: 0;
}

.room-info {
    flex: 1;
    min-width: 0;
}

.room-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.room-name {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.unread-badge {
    background: var(--primary-blue);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
}

.room-latest-message {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   CHAT CONTENT AREA
   ============================================ */
.family-chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
}

/* Chat Header */
.chat-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    background: #f0f2f5;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-info h3 {
    margin: 0 0 2px 0;
    font-size: 17px;
    font-weight: 500;
    color: var(--text-primary);
}

.chat-room-description {
    margin: 0;
    font-size: 13px;
    color: var(--text-secondary);
    display: block;
}

.chat-header-actions button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.chat-header-actions button:hover {
    background: rgba(0,0,0,0.05);
}

/* ============================================
   MESSAGES AREA - PROFESSIONAL DESIGN
   ============================================ */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #e5ddd5;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><rect fill="%23e5ddd5" width="100" height="100"/><circle fill="%23d1c4b8" opacity="0.05" cx="50" cy="50" r="30"/></svg>');
    display: flex;
    flex-direction: column;
}

.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.chat-empty-state svg {
    margin-bottom: 15px;
    opacity: 0.3;
}

.chat-empty-state p {
    margin: 0;
    font-size: 16px;
}

/* ============================================
   MESSAGE BUBBLES - WHATSAPP STYLE
   ============================================ */
.message {
    display: flex;
    margin-bottom: 6px;
    max-width: 65%;
    animation: slideIn 0.2s ease-out;
    align-items: flex-start;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Avatar */
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    margin-right: 8px;
    flex-shrink: 0;
    margin-top: 0;
}

/* ============================================
   MESSAGE CONTENT - HORIZONTAL LAYOUT
   ============================================ */
.message-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.message-content-row {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    gap: 6px;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
    width: auto !important;
    height: auto !important;
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-blue);
    margin-bottom: 3px;
    margin-left: 8px;
}

.message-bubble {
    padding: 8px 12px !important;
    border-radius: 8px !important;
    font-size: 14.5px !important;
    line-height: 1.5 !important;
    position: relative;
    box-shadow: var(--shadow-sm) !important;
    word-wrap: break-word;
    margin: 0 !important;
    border: none !important;
    outline: none !important;
    display: inline-block !important;
}

.message-bubble p {
    margin: 0 !important;
    padding: 0 !important;
    color: inherit;
}

/* Other user messages (left side) */
.message-other {
    align-self: flex-start;
}

.message-other .message-bubble {
    background: var(--bg-bubble-other);
    color: var(--text-primary);
    border-bottom-left-radius: 2px !important;
}

/* Own messages (right side) */
.message-own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-own .message-avatar {
    margin-right: 0;
    margin-left: 8px;
}

.message-own .message-content {
    align-items: flex-end;
}

.message-own .message-sender {
    display: none;
}

.message-own .message-bubble {
    background: #d9fdd3;
    color: var(--text-primary);
    border-bottom-right-radius: 2px !important;
}

/* Reply block */
.message-reply {
    background: rgba(0, 0, 0, 0.06);
    border-left: 3px solid var(--primary-blue);
    padding: 6px 10px;
    border-radius: 6px;
    margin-bottom: 6px;
    margin-left: 8px;
    font-size: 13px;
}

.message-reply strong {
    color: var(--primary-blue);
    display: block;
    margin-bottom: 2px;
    font-size: 12px;
}

.message-reply p {
    margin: 0;
    color: var(--text-secondary);
}

.message-own .message-reply {
    background: rgba(0, 0, 0, 0.08);
    margin-left: 0;
    margin-right: 8px;
}

.edited-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 6px;
    font-style: italic;
}

/* ============================================
   MESSAGE METADATA - COMPACT & ALIGNED
   ============================================ */
.message-meta {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 4px !important;
    opacity: 0;
    transition: opacity 0.2s ease;
    margin: 0 !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
    height: auto !important;
    vertical-align: top !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

.message:hover .message-meta {
    opacity: 1;
}

.message-time {
    font-size: 11px !important;
    color: var(--text-secondary) !important;
    white-space: nowrap !important;
    line-height: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    border: none !important;
    outline: none !important;
}

.message-actions {
    display: inline-flex !important;
    gap: 3px !important;
    align-items: center !important;
    line-height: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    border: none !important;
    outline: none !important;
}

.btn-message-action {
    background: rgba(0,0,0,0.05) !important;
    border: none !important;
    cursor: pointer;
    padding: 3px !important;
    border-radius: 50% !important;
    color: var(--text-secondary);
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s;
    width: 20px !important;
    height: 20px !important;
    line-height: 1 !important;
    margin: 0 !important;
    outline: none !important;
    box-shadow: none !important;
}

.btn-message-action:hover {
    background: rgba(0,0,0,0.1) !important;
    color: var(--primary-blue);
    transform: scale(1.1);
}

.btn-message-action svg {
    width: 12px !important;
    height: 12px !important;
    display: block !important;
}

/* Reactions below the row */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
    margin-left: 8px;
}

.reaction {
    background: rgba(0,0,0,0.05);
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.reaction:hover {
    background: rgba(0,0,0,0.1);
    transform: scale(1.1);
}

.reaction-picker {
    position: absolute;
    bottom: 100%;
    right: 0;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 8px;
    display: flex;
    gap: 6px;
    box-shadow: var(--shadow-md);
    z-index: 10;
    margin-bottom: 8px;
}

.reaction-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: all 0.2s;
    line-height: 1;
}

.reaction-btn:hover {
    background: var(--bg-sidebar);
    transform: scale(1.2);
}

/* ============================================
   INPUT AREA
   ============================================ */
.chat-input-area {
    border-top: 1px solid var(--border-color);
    background: #f0f2f5;
    padding: 12px 20px;
}

.reply-indicator {
    background: rgba(0, 132, 255, 0.1);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 3px solid var(--primary-blue);
}

.reply-content {
    flex: 1;
}

.reply-label {
    font-size: 12px;
    color: var(--primary-blue);
    display: block;
    margin-bottom: 3px;
    font-weight: 600;
}

.reply-message {
    margin: 0;
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-cancel-reply {
    background: transparent;
    border: none;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 8px;
    line-height: 1;
    transition: color 0.2s;
}

.btn-cancel-reply:hover {
    color: var(--text-primary);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-main);
    border-radius: 24px;
    padding: 8px 16px;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(0, 132, 255, 0.1);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-size: 15px;
    font-family: inherit;
    line-height: 1.5;
    max-height: 120px;
    padding: 6px 0;
    color: var(--text-primary);
}

.chat-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-attach,
.btn-emoji {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    color: var(--text-secondary);
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-attach:hover,
.btn-emoji:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--primary-blue);
}

.btn-send {
    background: var(--primary-blue);
    color: white;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-send:hover {
    background: var(--primary-blue-dark);
    transform: scale(1.05);
}

.btn-send:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* ============================================
   MODAL
   ============================================ */
.family-chat-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.btn-close-modal {
    background: transparent;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    transition: color 0.2s;
}

.btn-close-modal:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary-blue);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel {
    background: #f0f0f0;
    color: var(--text-secondary);
}

.btn-cancel:hover {
    background: #e0e0e0;
}

.btn-primary {
    background: var(--primary-blue);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-blue-dark);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 768px) {
    .family-chat-sidebar {
        width: 100%;
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 10;
        transform: translateX(-100%);
        transition: transform 0.3s;
    }

    .family-chat-sidebar.open {
        transform: translateX(0);
    }

    .message {
        max-width: 85%;
    }

    .chat-input-wrapper {
        border-radius: 20px;
    }

    .btn-mobile-menu {
        display: flex !important;
        background: transparent;
        border: none;
        color: var(--text-primary);
        cursor: pointer;
        padding: 0;
        margin-right: 12px;
    }

    .chat-header {
        padding: 10px 16px;
    }

    .family-chat-sidebar::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
        z-index: -1;
    }

    .family-chat-sidebar.open::before {
        opacity: 1;
        pointer-events: auto;
    }
}

.btn-mobile-menu {
    display: none;
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
.chat-messages::-webkit-scrollbar,
.chat-room-section::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.chat-room-section::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-room-section::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-room-section::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* ============================================
   LOGIN REQUIRED
   ============================================ */
.family-chat-login-required {
    padding: 60px 20px;
    text-align: center;
    background: var(--bg-sidebar);
    border-radius: 12px;
}

.family-chat-login-required p {
    margin: 0;
    font-size: 16px;
    color: var(--text-secondary);
}

.family-chat-login-required a {
    color: var(--primary-blue);
    text-decoration: none;
    font-weight: 600;
}

.family-chat-login-required a:hover {
    text-decoration: underline;
}

/* Shared GP App Layout */
.gp-app-wrapper {
    display: flex;
    min-height: 85vh; /* Adjust based on your header height */
    background: #f8f9fa;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    margin: 20px 0;
}

.gp-app-sidebar {
    width: 260px;
    background: #2c3e50; /* Matches the gp-left-menu sidebar theme */
    flex-shrink: 0;
    border-right: 1px solid #e5e7eb;
}

.gp-app-main {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #ffffff;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .gp-app-wrapper {
        flex-direction: column;
    }
    .gp-app-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
    }
}