/* ── Chat: Floating button + panel ── */

/* ── FAB (floating action button) ── */
.chat-fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 998;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--green);
    color: var(--cream);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    transition: transform 0.15s, box-shadow 0.15s;
}

.chat-fab:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}

.chat-fab:active {
    transform: translateY(0);
}

.chat-fab[hidden] {
    display: none;
}

.chat-fab svg {
    width: 26px;
    height: 26px;
}

/* Unread badge */
.chat-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #c0392b;
    border: 2px solid var(--cream);
    display: none;
}

.chat-fab-badge.visible {
    display: block;
}

/* ── Chat panel ── */
.chat-panel {
    position: fixed;
    bottom: 5.5rem;
    right: 1.5rem;
    z-index: 999;
    width: 360px;
    max-width: calc(100vw - 2rem);
    height: 500px;
    max-height: calc(100vh - 8rem);
    background: var(--cream);
    border-radius: 18px;
    border: 2px solid rgba(90, 110, 60, 0.6);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overflow-x: hidden;
    transform: translateY(10px);
    opacity: 0;
    transition: transform 0.25s ease, opacity 0.2s ease;
}

.chat-panel.open {
    transform: translateY(0);
    opacity: 1;
}

.chat-panel[hidden] {
    display: none;
}

/* ── Header ── */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1.5px dashed rgba(90, 110, 60, 0.4);
    flex-shrink: 0;
}

.chat-title {
    font-family: 'Caveat', cursive;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--green);
    flex: 1;
}

.chat-edit-name {
    appearance: none;
    border: 0;
    background: transparent;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--brown-light);
    transition: background 0.15s;
    margin-right: 0.25rem;
}

.chat-edit-name:hover {
    background: rgba(90, 110, 60, 0.1);
    color: var(--brown);
}

.chat-edit-name:focus-visible {
    box-shadow: 0 0 0 3px rgba(90, 110, 60, 0.35);
    outline: none;
}

.chat-edit-name svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chat-close {
    appearance: none;
    border: 0;
    background: transparent;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--brown);
    transition: background 0.15s;
}

.chat-close:hover {
    background: rgba(90, 110, 60, 0.1);
}

.chat-close:focus-visible {
    box-shadow: 0 0 0 3px rgba(90, 110, 60, 0.35);
    outline: none;
}

.chat-close svg {
    width: 18px;
    height: 18px;
    stroke: var(--brown);
    stroke-width: 2.6;
    stroke-linecap: round;
}

/* ── Messages area ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.8rem 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

/* ── Single message ── */
.chat-msg {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}

.chat-msg__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(90, 110, 60, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    font-weight: 700;
    color: var(--green);
}

.chat-msg__body {
    min-width: 0;
    overflow: hidden;
}

.chat-msg__name {
    font-family: 'Caveat', cursive;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--brown);
    line-height: 1.2;
}

.chat-msg__time {
    font-family: 'Lora', serif;
    font-size: 0.7rem;
    color: var(--brown-light);
    margin-left: 0.4rem;
    font-weight: 400;
}

.chat-msg__text {
    font-family: 'Lora', serif;
    font-size: 0.88rem;
    color: var(--brown);
    line-height: 1.45;
    word-break: break-word;
}

.chat-msg__image {
    max-width: min(200px, 100%);
    max-height: 200px;
    border-radius: 10px;
    margin-top: 0.25rem;
    cursor: pointer;
    object-fit: cover;
}

/* ── Announcement ── */
.chat-msg--announcement {
    display: block;
    background: rgba(90, 110, 60, 0.08);
    border-left: 3px solid var(--green);
    border-radius: 0 10px 10px 0;
    padding: 0.55rem 0.75rem;
}

.chat-msg--announcement .chat-msg__name {
    color: var(--green);
    font-size: 0.85rem;
}

.chat-msg--announcement .chat-msg__text {
    font-family: 'Caveat', cursive;
    font-size: 1.1rem;
    color: var(--green);
    font-weight: 700;
}

/* ── Name prompt ── */
.chat-name-prompt {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 0.8rem;
    border-top: 1.5px dashed rgba(90, 110, 60, 0.4);
    flex-shrink: 0;
    align-items: center;
}

.chat-name-prompt[hidden] {
    display: none;
}

.chat-name-input {
    flex: 1;
    font-family: 'Lora', serif;
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    border: 1.5px solid rgba(90, 110, 60, 0.5);
    border-radius: 10px;
    background: var(--bg);
    color: var(--brown);
    outline: none;
}

.chat-name-input:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(90, 110, 60, 0.2);
}

/* ── Input area ── */
.chat-input-area {
    border-top: 1.5px dashed rgba(90, 110, 60, 0.4);
    flex-shrink: 0;
}

.chat-input-area[hidden] {
    display: none;
}

.chat-announce-bar {
    display: flex;
    padding: 0.4rem 0.8rem 0;
}

.chat-announce-bar[hidden] {
    display: none;
}

.chat-compose {
    display: flex;
    gap: 0.35rem;
    padding: 0.55rem 0.8rem 0.65rem;
    align-items: flex-end;
}

.chat-text-input {
    flex: 1;
    font-family: 'Lora', serif;
    font-size: 0.88rem;
    padding: 0.45rem 0.7rem;
    border: 1.5px solid rgba(90, 110, 60, 0.5);
    border-radius: 10px;
    background: var(--bg);
    color: var(--brown);
    outline: none;
    min-width: 0;
    resize: none;
    overflow-y: auto;
    line-height: 1.4;
    min-height: 38px;
    max-height: 4.8em; /* ~3 lines */
}

.chat-text-input:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(90, 110, 60, 0.2);
}

.chat-img-btn,
.chat-send-btn {
    appearance: none;
    border: none;
    background: transparent;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--brown);
    flex-shrink: 0;
    transition: background 0.15s;
}

.chat-img-btn:hover,
.chat-send-btn:hover {
    background: rgba(90, 110, 60, 0.1);
}

.chat-send-btn {
    color: var(--green);
}

.chat-img-btn:focus-visible,
.chat-send-btn:focus-visible {
    box-shadow: 0 0 0 3px rgba(90, 110, 60, 0.35);
    outline: none;
}

/* ── Loading / empty states ── */
.chat-empty {
    text-align: center;
    padding: 2rem 1rem;
    font-family: 'Caveat', cursive;
    font-size: 1.15rem;
    color: var(--brown-light);
    opacity: 0.7;
}

/* ── Image uploading indicator ── */
.chat-uploading {
    font-family: 'Lora', serif;
    font-size: 0.8rem;
    color: var(--brown-light);
    padding: 0.2rem 0.8rem;
    font-style: italic;
}

/* ── Mobile: full-screen panel ── */
@media (max-width: 480px) {
    .chat-fab {
        bottom: 1rem;
        right: 1rem;
    }

    .chat-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        transform: none;
    }

    .chat-panel.open {
        transform: none;
    }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .chat-panel {
        transition: none;
    }
}
