/* ============================================================================
   Project chat — modules/Project + www/.../project/chat.latte
   Scoped under .project-chat. Uses Velzon --vz-* tokens (light + dark).
   ========================================================================== */

.project-chat {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 15rem);
    min-height: 26rem;
    position: relative;
    background: var(--vz-secondary-bg, var(--vz-light, #f3f3f9));
    border: 1px solid var(--vz-border-color, #e9ebec);
    border-radius: .75rem;
    overflow: hidden;
}

/* ---- scroll area --------------------------------------------------------- */
.project-chat-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem clamp(.75rem, 3vw, 2rem);
    scroll-behavior: smooth;
    background-image: radial-gradient(circle at 1px 1px,
        rgba(var(--vz-dark-rgb, 49, 52, 55), .05) 1px, transparent 0);
    background-size: 22px 22px;
}
@media (prefers-reduced-motion: reduce) {
    .project-chat-body { scroll-behavior: auto; }
}

.project-chat-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    max-width: 60rem;
    margin: 0 auto;
    padding: 0;
}

/* ---- day separator ----------------------------------------------------- */
.chat-day {
    align-self: center;
    margin: .75rem 0 .25rem;
    padding: .2rem .8rem;
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: var(--vz-secondary-color, #878a99);
    background: var(--vz-card-bg, #fff);
    border: 1px solid var(--vz-border-color, #e9ebec);
    border-radius: 50rem;
}

/* ---- one message ------------------------------------------------------- */
.chat-msg {
    display: grid;
    grid-template-columns: 2rem 1fr;
    gap: .6rem;
    max-width: min(80%, 40rem);
    list-style: none;
}
.chat-msg.is-mine {
    grid-template-columns: 1fr 2rem;
    margin-left: auto;
}
.chat-msg.is-mine .chat-msg-avatar { order: 2; }
.chat-msg.is-mine .chat-msg-col    { order: 1; align-items: flex-end; }
.chat-msg.is-mine .chat-msg-head   { flex-direction: row-reverse; }

.chat-msg-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    font-weight: 700;
    color: #fff;
    background: hsl(var(--chat-hue, 210) 45% 55%);
    overflow: hidden;
    flex-shrink: 0;
}
.chat-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

.chat-msg-col {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
}

.chat-msg-head {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    margin-bottom: .15rem;
    font-size: .72rem;
    line-height: 1.2;
}
.chat-msg-name { font-weight: 600; }
.chat-msg-time { color: var(--vz-secondary-color, #878a99); }

.chat-msg-bubble {
    padding: .5rem .75rem;
    border-radius: 1rem;
    background: var(--vz-card-bg, #fff);
    border: 1px solid var(--vz-border-color, #e9ebec);
    color: var(--vz-body-color, #212529);
    font-size: .9rem;
    line-height: 1.45;
    word-break: break-word;
    overflow-wrap: anywhere;
    border-top-left-radius: .25rem;
}
.chat-msg.is-mine .chat-msg-bubble {
    background: var(--vz-primary, #1E527A);
    border-color: var(--vz-primary, #1E527A);
    color: #fff;
    border-top-left-radius: 1rem;
    border-top-right-radius: .25rem;
}

.chat-msg-text { margin: 0; white-space: pre-wrap; }

/* ---- grouped (same sender, < 5 min) ----------------------------------- */
.chat-msg.is-grouped { margin-top: -.35rem; }
.chat-msg.is-grouped .chat-msg-avatar { visibility: hidden; }
.chat-msg.is-grouped .chat-msg-head   { display: none; }
.chat-msg.is-grouped .chat-msg-bubble { border-top-left-radius: 1rem; }
.chat-msg.is-grouped.is-mine .chat-msg-bubble { border-top-right-radius: 1rem; }

/* ---- image message --------------------------------------------------- */
.chat-msg-bubble:has(.chat-msg-image),
.chat-msg-bubble:has(.chat-msg-file) { padding: .3rem; }
.chat-msg-image { display: block; }
.chat-msg-image img {
    display: block;
    max-width: min(16rem, 60vw);
    max-height: 18rem;
    border-radius: .6rem;
    object-fit: cover;
    cursor: zoom-in;
}

/* ---- file message --------------------------------------------------- */
.chat-msg-file {
    display: flex;
    align-items: center;
    gap: .6rem;
    min-width: 12rem;
    max-width: 18rem;
    padding: .5rem .6rem;
    border-radius: .6rem;
    text-decoration: none;
    color: inherit;
    transition: background-color .15s ease;
}
.chat-msg-file:hover { background: rgba(var(--vz-dark-rgb, 49, 52, 55), .06); }
.chat-msg.is-mine .chat-msg-file:hover { background: rgba(255, 255, 255, .12); }
.chat-msg-file-icon {
    flex-shrink: 0;
    width: 2.2rem; height: 2.2rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.15rem;
    border-radius: .5rem;
    background: rgba(var(--vz-primary-rgb, 30, 82, 122), .12);
    color: var(--vz-primary, #1E527A);
}
.chat-msg.is-mine .chat-msg-file-icon { background: rgba(255, 255, 255, .18); color: #fff; }
.chat-msg-file-meta { display: flex; flex-direction: column; min-width: 0; }
.chat-msg-file-name {
    font-weight: 600; font-size: .82rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-msg-file-size { font-size: .72rem; opacity: .75; }
.chat-msg-file-dl { margin-left: auto; opacity: .6; font-size: 1rem; }

.chat-msg-audio { display: block; max-width: 16rem; }
.chat-msg-system {
    font-size: .78rem; font-style: italic;
    color: var(--vz-secondary-color, #878a99);
}

/* ---- empty state --------------------------------------------------- */
.project-chat-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    text-align: center;
    color: var(--vz-secondary-color, #878a99);
    pointer-events: none;
}
.project-chat-empty i { font-size: 2.5rem; opacity: .5; }

/* ---- "new messages" jump button ---------------------------------- */
.project-chat-jump {
    position: absolute;
    left: 50%;
    bottom: 5.25rem;
    transform: translateX(-50%);
    z-index: 5;
    padding: .35rem .9rem;
    font-size: .78rem;
    font-weight: 600;
    color: #fff;
    background: var(--vz-primary, #1E527A);
    border: 0;
    border-radius: 50rem;
    box-shadow: 0 .4rem 1rem rgba(var(--vz-dark-rgb, 49, 52, 55), .25);
}

/* ---- drag & drop overlay ---------------------------------------- */
.project-chat-drop {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(var(--vz-primary-rgb, 30, 82, 122), .12);
    backdrop-filter: blur(2px);
}
.project-chat.is-dragover .project-chat-drop { display: flex; }
.project-chat-drop > div {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    padding: 2rem 3rem;
    border: 2px dashed var(--vz-primary, #1E527A);
    border-radius: 1rem;
    background: var(--vz-card-bg, #fff);
    color: var(--vz-primary, #1E527A);
    font-weight: 600;
}
.project-chat-drop i { font-size: 2rem; }

/* ---- footer / input ------------------------------------------- */
.project-chat-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--vz-border-color, #e9ebec);
    background: var(--vz-card-bg, #fff);
    padding: .6rem clamp(.6rem, 2vw, 1rem);
}

.project-chat-upload,
.project-chat-error {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: .5rem;
    padding: .4rem .7rem;
    font-size: .8rem;
    border-radius: .5rem;
}
.project-chat-upload {
    background: rgba(var(--vz-primary-rgb, 30, 82, 122), .1);
    color: var(--vz-primary, #1E527A);
}
.project-chat-upload button {
    margin-left: auto;
    border: 0; background: transparent; color: inherit; cursor: pointer;
    font-size: 1rem; line-height: 1;
}
.project-chat-error {
    background: rgba(var(--vz-danger-rgb, 240, 101, 72), .12);
    color: var(--vz-danger, #f06548);
}
.spin { animation: chat-spin 1s linear infinite; display: inline-block; }
@keyframes chat-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

.project-chat-input {
    display: flex;
    align-items: center;
    gap: .35rem;
}
.pci-btn,
.pci-send {
    flex-shrink: 0;
    width: 2.4rem;
    height: 2.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}
.pci-btn {
    background: transparent;
    color: var(--vz-secondary-color, #878a99);
}
.pci-btn:hover { background: var(--vz-light, #f3f3f9); color: var(--vz-primary, #1E527A); }
.pci-send {
    background: var(--vz-primary, #1E527A);
    color: #fff;
}
.pci-send:hover { filter: brightness(1.08); }
.pci-send:disabled { opacity: .5; cursor: default; }

.pci-text {
    flex: 1 1 auto;
    min-width: 0;
    height: 2.4rem;
    padding: 0 1rem;
    font-size: .9rem;
    color: var(--vz-body-color, #212529);
    background: var(--vz-light, #f3f3f9);
    border: 1px solid var(--vz-border-color, #e9ebec);
    border-radius: 50rem;
    outline: none;
}
.pci-text:focus {
    border-color: var(--vz-primary, #1E527A);
    background: var(--vz-card-bg, #fff);
}

/* ---- lightbox ------------------------------------------------ */
.chat-lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .8);
    padding: 2rem;
}
.chat-lightbox img {
    max-width: 92vw;
    max-height: 88vh;
    border-radius: .5rem;
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, .5);
}
.chat-lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1.25rem;
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.75rem;
    line-height: 1;
    color: #fff;
    background: rgba(255, 255, 255, .15);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

/* ---- emoji picker sits above the input --------------------- */
.project-chat .fg-emoji-picker { z-index: 30; }

@media (max-width: 575.98px) {
    .project-chat { height: calc(100dvh - 12rem); border-radius: 0; }
    .chat-msg { max-width: 90%; }
}
