/* ================================
   Family chat floating widget
   ============================== */

.chat-widget
{
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 40;
}

#family-chat-launcher,
.chat-launcher
{
    position: relative;
    width: 100%;
    max-width: 320px;
    border-radius: 999px;
    border-width: 1px;
    border-style: solid;
    border-color: rgba(148, 163, 184, 0.6);
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
    padding-left: 0.85rem;
    padding-right: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    background-color: rgba(15, 23, 42, 0.96);
    cursor: pointer;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.95);
    font-size: 0.9rem;
    backdrop-filter: blur(12px);
}

.chat-launcher-icon
{
    font-size: 1.1rem;
}

.chat-badge
{
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding-left: 4px;
    padding-right: 4px;
    border-radius: 999px;
    background-color: #ef4444;
    color: #f9fafb;
    font-size: 0.7rem;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
}

.chat-badge.chat-badge-visible
{
    display: inline-flex;
}

#family-chat-launcher:hover,
.chat-launcher:hover
{
    border-color: rgba(129, 140, 248, 1);
    background-image: linear-gradient(
        135deg,
        rgba(30, 64, 175, 0.98),
        rgba(15, 23, 42, 0.98)
    );
}

#family-chat-launcher.chat-launcher-attention,
.chat-launcher.chat-launcher-attention
{
    animation-name: chat-launcher-pulse;
    animation-duration: 1.4s;
    animation-iteration-count: infinite;
    animation-timing-function: ease-out;
}

@keyframes chat-launcher-pulse
{
    0%
    {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5);
    }
    70%
    {
        transform: scale(1.06);
        box-shadow: 0 0 0 14px rgba(16, 185, 129, 0);
    }
    100%
    {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* ================================
   Chat window popup
   ============================== */

#family-chat-window,
.chat-window
{
    position: fixed;
    bottom: 4rem;
    right: 1rem;
    width: 100%;
    max-width: 420px;
    max-height: 70vh;
    border-radius: 1.1rem;
    border-width: 1px;
    border-style: solid;
    border-color: rgba(148, 163, 184, 0.7);
    background-color: rgba(15, 23, 42, 0.98);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.98);
    overflow: hidden;
    display: none;
    flex-direction: column;
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    pointer-events: none;
    transition-property: opacity, transform;
    transition-duration: 160ms;
    transition-timing-function: ease-out;
    z-index: 45;
    backdrop-filter: blur(18px);
}

#family-chat-window.chat-window-open,
.chat-window.chat-window-open
{
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.chat-window-header
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
    padding-left: 0.85rem;
    padding-right: 0.6rem;
    border-bottom-width: 1px;
    border-bottom-style: solid;
    border-bottom-color: rgba(148, 163, 184, 0.45);
    background-image: linear-gradient(
        135deg,
        rgba(30, 64, 175, 0.96),
        rgba(15, 23, 42, 0.98)
    );
    color: #e5e7eb;
    font-size: 0.85rem;
}

.chat-window-title
{
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
}

.chat-window-title::before
{
    content: "💬";
    font-size: 1rem;
}

.chat-window-close,
#family-chat-close
{
    border-width: 1px;
    border-style: solid;
    border-color: rgba(148, 163, 184, 0.9);
    background-color: rgba(15, 23, 42, 0.95);
    color: #e5e7eb;
    border-radius: 999px;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0;
}

.chat-window-close:hover,
#family-chat-close:hover
{
    border-color: rgba(248, 113, 113, 0.9);
    background-color: rgba(239, 68, 68, 0.2);
}

/* ================================
   Chat window body + scroll
   ============================== */

.chat-window-body
{
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

.chat-family-tabs
{
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding-top: 0.7rem;
    padding-bottom: 0.35rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    scrollbar-width: thin;
}

.chat-family-tab
{
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
    max-width: 100%;
    border-width: 1px;
    border-style: solid;
    border-color: rgba(148, 163, 184, 0.35);
    background-color: rgba(255, 255, 255, 0.06);
    color: inherit;
    border-radius: 999px;
    padding-top: 0.42rem;
    padding-bottom: 0.42rem;
    padding-left: 0.78rem;
    padding-right: 0.78rem;
    cursor: pointer;
    white-space: nowrap;
    font-size: 0.78rem;
    flex-shrink: 0;
    line-height: 1;
}

.chat-family-tab:hover
{
    border-color: rgba(129, 140, 248, 0.8);
    background-color: rgba(129, 140, 248, 0.12);
}

.chat-family-tab-active
{
    background-color: rgba(129, 140, 248, 0.18);
    border-color: rgba(129, 140, 248, 0.9);
}

.chat-family-tab-name
{
    display: block;
    min-width: 0;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.1;
}

.chat-family-tab-badge
{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    border-radius: 999px;
    padding-left: 0.3rem;
    padding-right: 0.3rem;
    background-color: #ef4444;
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
}

.chat-family-meta
{
    display: none;
}

/* ================================
   Messages area
   ============================== */

.chat-messages,
#family-chat-messages
{
    flex: 1 1 auto;
    min-height: 0;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    position: relative;
}

.chat-message-system
{
    font-size: 0.85rem;
    text-align: center;
    opacity: 0.7;
    margin-top: 0.6rem;
    margin-bottom: 0.75rem;
}

.chat-date-divider
{
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.55rem;
    margin-bottom: 0.7rem;
    font-size: 0.72rem;
    color: rgba(229, 231, 235, 0.58);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    clear: both;
}

/* ================================
   Chat bubbles + avatars
   ============================== */

.chat-message-row
{
    display: flex;
    align-items: flex-end;
    gap: 0.65rem;
    margin-bottom: 0.4rem;
    width: 100%;
    max-width: 100%;
    overflow: visible;
    position: relative;
}

.chat-message-row-me
{
    justify-content: flex-end;
}

.chat-message-row-them
{
    justify-content: flex-start;
}

.chat-message-row-continued
{
    margin-top: -0.15rem;
}

.chat-message-avatar
{
    width: 38px;
    height: 38px;
    min-width: 38px;
    max-width: 38px;
    border-radius: 999px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 255, 255, 0.08);
    border-width: 1px;
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.10);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.22);
    flex-shrink: 0;
}

.chat-message-avatar img
{
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-message-avatar-hidden
{
    visibility: hidden;
}

.chat-message-avatar-fallback
{
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1;
    color: #f9fafb;
}

.chat-message-bubble-wrap
{
    display: flex;
    flex-direction: column;
    min-width: 0;
    width: auto;
    max-width: calc(100% - 54px);
    flex: 0 1 auto;
}

.chat-message-row-me .chat-message-bubble-wrap
{
    align-items: flex-end;
}

.chat-message-bubble
{
    position: relative;
    width: auto;
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
    word-wrap: break-word;
    word-break: break-word;
    padding-top: 0.4rem;
    padding-bottom: 0.5rem;
    padding-left: 0.65rem;
    padding-right: 0.7rem;
    border-radius: 1rem;
    background-color: #111827;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    font-size: 0.9rem;
    line-height: 1.35;
}

.chat-message-row-me .chat-message-bubble
{
    background-color: #16a34a;
    color: #f9fafb;
    border-bottom-right-radius: 0.35rem;
}

.chat-message-row-them .chat-message-bubble
{
    background-color: #1f2937;
    color: #e5e7eb;
    border-bottom-left-radius: 0.35rem;
}

.chat-message-header
{
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
    min-width: 0;
}

.chat-message-name
{
    font-size: 0.8rem;
    font-weight: 600;
    opacity: 0.95;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-message-time
{
    font-size: 0.72rem;
    opacity: 0.68;
    flex-shrink: 0;
}

.chat-message-body
{
    font-size: 0.9rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
}

.chat-message-meta
{
    margin-top: 0.2rem;
    font-size: 0.72rem;
    opacity: 0.78;
}

.chat-message-meta-deleted
{
    font-style: italic;
    opacity: 0.62;
}

.chat-message-deleted
{
    opacity: 0.6;
    font-style: italic;
}

/* ================================
   Link chips + preview cards
   ============================== */

.chat-inline-link-chip
{
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.12rem;
    margin-bottom: 0.12rem;
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
    padding-left: 0.55rem;
    padding-right: 0.55rem;
    border-radius: 999px;
    text-decoration: none;
    font-size: 0.76rem;
    font-weight: 600;
    line-height: 1.2;
    border-width: 1px;
    border-style: solid;
    max-width: 100%;
    vertical-align: middle;
}

.chat-inline-link-chip-internal
{
    background-color: rgba(99, 102, 241, 0.16);
    border-color: rgba(129, 140, 248, 0.55);
    color: #c7d2fe;
}

.chat-inline-link-chip-external
{
    background-color: rgba(255, 255, 255, 0.08);
    border-color: rgba(148, 163, 184, 0.45);
    color: #e5e7eb;
}

.chat-inline-link-chip-warn
{
    background-color: rgba(239, 68, 68, 0.14);
    border-color: rgba(248, 113, 113, 0.55);
    color: #fecaca;
}

.chat-link-preview-card
{
    display: block;
    margin-top: 0.55rem;
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
    padding-left: 0.8rem;
    padding-right: 0.8rem;
    border-radius: 0.95rem;
    text-decoration: none;
    border-width: 1px;
    border-style: solid;
    border-color: rgba(148, 163, 184, 0.3);
    background-color: rgba(15, 23, 42, 0.45);
    max-width: 100%;
    overflow: hidden;
    transition-property: border-color, transform, background-color;
    transition-duration: 120ms;
    transition-timing-function: ease-out;
}

.chat-link-preview-card:hover
{
    border-color: rgba(129, 140, 248, 0.75);
    transform: translateY(-1px);
}

.chat-link-preview-card-internal
{
    background-image: linear-gradient(
        135deg,
        rgba(79, 70, 229, 0.18),
        rgba(15, 23, 42, 0.45)
    );
}

.chat-link-preview-card-external
{
    background-color: rgba(255, 255, 255, 0.05);
}

.chat-link-preview-card-warn
{
    border-color: rgba(248, 113, 113, 0.55);
    background-color: rgba(127, 29, 29, 0.18);
}

.chat-link-preview-badge
{
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.8;
    margin-bottom: 0.3rem;
}

.chat-link-preview-title
{
    font-size: 0.92rem;
    font-weight: 700;
    margin-bottom: 0.2rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-link-preview-description
{
    font-size: 0.8rem;
    opacity: 0.88;
    margin-bottom: 0.35rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-link-preview-url
{
    font-size: 0.72rem;
    opacity: 0.68;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Reactions row */

.chat-message-reactions
{
    display: none;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
    justify-content: flex-start;
    margin-top: 0.45rem;
    position: static;
    max-width: 100%;
}

.chat-reaction-pill
{
    border-radius: 999px;
    padding-top: 0.12rem;
    padding-bottom: 0.12rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    font-size: 0.72rem;
    background-color: rgba(15, 23, 42, 0.98);
    border-width: 1px;
    border-style: solid;
    border-color: rgba(75, 85, 99, 0.9);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.55);
    color: #f9fafb;
    cursor: pointer;
    max-width: 100%;
}

.chat-message-seen
{
    display: none;
    margin-top: 0.25rem;
    font-size: 0.72rem;
    opacity: 0.72;
}

/* Typing indicator */

.chat-typing
{
    min-height: 1.2rem;
    margin-top: 0.2rem;
    margin-bottom: 0.25rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    font-size: 0.8rem;
    opacity: 0;
    transition-property: opacity;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.chat-typing.chat-typing-visible
{
    opacity: 0.9;
}

/* ================================
   Input row
   ============================== */

.chat-input-row,
#family-chat-form
{
    display: flex;
    align-items: flex-end;
    gap: 0.4rem;
    padding-top: 0.45rem;
    padding-bottom: 0.55rem;
    padding-left: 0.55rem;
    padding-right: 0.55rem;
    border-top-width: 1px;
    border-top-style: solid;
    border-top-color: rgba(148, 163, 184, 0.4);
    flex-shrink: 0;
    background-color: rgba(15, 23, 42, 0.98);
}

.chat-input,
#family-chat-input,
#family-chat-form .chat-input
{
    flex: 1;
    min-height: 2.1rem;
    max-height: 8.75rem;
    resize: none;
    border-radius: 0.75rem;
    border-width: 1px;
    border-style: solid;
    border-color: rgba(148, 163, 184, 0.7);
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
    padding-left: 0.6rem;
    padding-right: 0.6rem;
    font-size: 0.82rem;
    background-color: rgba(15, 23, 42, 0.98);
    color: inherit;
    line-height: 1.4;
}

.chat-input:focus,
#family-chat-input:focus
{
    outline: none;
    border-color: rgba(129, 140, 248, 1);
    box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.5);
}

.chat-send-button,
.family-chat-send
{
    border-radius: 999px;
    border-width: 1px;
    border-style: solid;
    border-color: rgba(148, 163, 184, 0.9);
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
    padding-left: 0.8rem;
    padding-right: 0.8rem;
    font-size: 0.8rem;
    cursor: pointer;
    background-image: linear-gradient(
        135deg,
        #4f46e5,
        #22c55e
    );
    color: #0b1120;
    white-space: nowrap;
    font-weight: 700;
}

.chat-send-button:hover,
.family-chat-send:hover
{
    filter: brightness(1.05);
}

/* ================================
   Inline edit UI
   ============================== */

.chat-inline-edit
{
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-inline-edit-input
{
    width: 100%;
    min-height: 78px;
    resize: vertical;
    border-radius: 0.8rem;
    border-width: 1px;
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.18);
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
    padding-left: 0.65rem;
    padding-right: 0.65rem;
    background-color: rgba(15, 23, 42, 0.92);
    color: #f9fafb;
    font-size: 0.85rem;
    line-height: 1.4;
}

.chat-inline-edit-input:focus
{
    outline: none;
    border-color: rgba(129, 140, 248, 1);
    box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.5);
}

.chat-inline-edit-actions
{
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.chat-inline-edit-save,
.chat-inline-edit-cancel
{
    border-width: 1px;
    border-style: solid;
    border-radius: 999px;
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    cursor: pointer;
    font-size: 0.76rem;
    font-weight: 600;
}

.chat-inline-edit-save
{
    border-color: rgba(74, 222, 128, 0.45);
    background-color: rgba(74, 222, 128, 0.18);
    color: #f0fdf4;
}

.chat-inline-edit-cancel
{
    border-color: rgba(148, 163, 184, 0.4);
    background-color: rgba(255, 255, 255, 0.08);
    color: #e5e7eb;
}

/* ================================
   Action menu pills
   ============================== */

.chat-action-menu
{
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.35rem;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    padding-left: 0.4rem;
    padding-right: 0.4rem;
    border-radius: 999px;
    background-color: rgba(15, 23, 42, 0.95);
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.95);
    max-width: 100%;
}

.chat-action-pill
{
    border-radius: 999px;
    border-width: 1px;
    border-style: solid;
    border-color: rgba(148, 163, 184, 0.9);
    background-image: linear-gradient(
        135deg,
        rgba(30, 64, 175, 0.96),
        rgba(15, 23, 42, 0.98)
    );
    padding-top: 0.18rem;
    padding-bottom: 0.18rem;
    padding-left: 0.6rem;
    padding-right: 0.6rem;
    font-size: 0.75rem;
    line-height: 1.3;
    color: #e5e7eb;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    transition-property: transform, box-shadow, border-color, background-color;
    transition-duration: 120ms;
    transition-timing-function: ease-out;
}

.chat-action-pill:hover
{
    transform: translateY(-1px);
    border-color: rgba(129, 140, 248, 1);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.9);
}

.chat-action-pill-danger
{
    border-color: rgba(248, 113, 113, 0.9);
    background-image: linear-gradient(
        135deg,
        rgba(127, 29, 29, 0.98),
        rgba(15, 23, 42, 0.98)
    );
    color: #fee2e2;
}

.chat-action-pill-muted
{
    border-color: rgba(148, 163, 184, 0.5);
    background-image: none;
    background-color: rgba(15, 23, 42, 0.98);
    color: #9ca3af;
}

/* ================================
   Mobile / tablet tweaks
   ============================== */

@media (max-width: 768px)
{
    .chat-widget
    {
        bottom: 0.6rem;
        right: 0.75rem;
        left: auto;
    }

    #family-chat-launcher,
    .chat-launcher
    {
        max-width: 52px;
        width: 52px;
        height: 52px;
        border-radius: 999px;
        padding-top: 0;
        padding-bottom: 0;
        padding-left: 0;
        padding-right: 0;
        justify-content: center;
    }

    #family-chat-window,
    .chat-window
    {
        left: 0.5rem;
        right: 0.5rem;
        width: auto;
        bottom: 3.75rem;
        max-width: none;
        max-height: 75vh;
        border-radius: 1.1rem;
    }

    .chat-message-avatar
    {
        width: 34px;
        height: 34px;
        min-width: 34px;
        max-width: 34px;
    }

    .chat-message-bubble-wrap
    {
        max-width: calc(100% - 48px);
    }
}

@media (max-width: 480px)
{
    #family-chat-window,
    .chat-window
    {
        bottom: 3.25rem;
        max-height: 80vh;
    }

    .chat-family-tabs
    {
        padding-right: 0.55rem;
        padding-left: 0.55rem;
    }

    .chat-family-tab-name
    {
        max-width: 100px;
    }

    .chat-messages,
    #family-chat-messages
    {
        padding-left: 0.6rem;
        padding-right: 0.6rem;
    }

    .chat-message-bubble-wrap
    {
        max-width: calc(100% - 44px);
    }

    .chat-link-preview-title
    {
        white-space: normal;
    }

    .chat-link-preview-description
    {
        white-space: normal;
    }
}

/* ================================
   Footer
   ============================== */

.site-footer
{
    margin-top: 1.5rem;
    border-top-width: 1px;
    border-top-style: solid;
    border-top-color: rgba(148, 163, 184, 0.35);
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    padding-left: 1rem;
    padding-right: 1rem;
}

.footer-inner
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.8rem;
}

.footer-links
{
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.footer-links a
{
    text-decoration: none;
    font-size: 0.8rem;
}

@media (max-width: 640px)
{
    .footer-inner
    {
        flex-direction: column;
        align-items: flex-start;
    }
}