.chat-widget {
    --chat-ink: #312219;
    --chat-muted: #614d3b;
    --chat-paper: #fff9ef;
    --chat-surface: #fffdf8;
    --chat-line: #e0c7a5;
    --chat-accent: #304d3b;
    --chat-inset: max(16px, env(safe-area-inset-right));
    --chat-bottom: max(16px, env(safe-area-inset-bottom));
    color: var(--chat-ink);
    font-size: .92rem;
}

.chat-widget button, .chat-widget textarea {font: inherit}
.chat-widget button {cursor: pointer}
.chat-widget button:disabled {cursor: default}
.chat-widget [hidden] {display: none}

.chat-toggle {
    position: fixed;
    z-index: 35;
    inset: auto var(--chat-inset) var(--chat-bottom) auto;
    display: grid;
    width: 56px;
    height: 56px;
    place-items: center;
    padding: 0;
    border: 1px solid #233e2d;
    border-radius: 50%;
    background: var(--chat-accent);
    box-shadow: 0 7px 20px #261b123e;
    color: #fffaf0;
}

.chat-toggle:hover {background: #243d2d}
.chat-toggle svg {width: 29px; height: 29px}

.chat-panel {
    position: fixed;
    z-index: 35;
    inset: auto var(--chat-inset) calc(var(--chat-bottom) + 67px) auto;
    display: flex;
    flex-direction: column;
    width: min(390px, calc(100% - var(--chat-inset) - 12px));
    height: min(34rem, calc(100vh - var(--chat-bottom) - 82px));
    height: min(34rem, calc(100dvh - var(--chat-bottom) - 82px));
    overflow: hidden;
    border: 1px solid var(--chat-line);
    border-radius: 18px;
    background: var(--chat-paper);
    box-shadow: 0 18px 45px #30221945;
}

[data-chat-staff="true"] .chat-panel {
    width: min(430px, calc(100% - var(--chat-inset) - 12px));
}

[data-chat-authenticated="false"] .chat-panel {height: auto}

.chat-header {
    display: flex;
    flex: none;
    align-items: center;
    gap: .3rem;
    min-height: 68px;
    padding: .5rem .6rem .5rem 1rem;
    border-bottom: 1px solid var(--chat-line);
    background: linear-gradient(110deg, #f9e4ba, #fff0d7);
}

.chat-heading {flex: 1; min-width: 0}
.chat-heading h2 {margin: 0; color: var(--chat-ink); font: 700 1.27rem/1.12 Georgia, serif}
.chat-heading p {margin: .22rem 0 0; color: var(--chat-muted); font-size: .81rem; line-height: 1.25; overflow-wrap: anywhere}

.chat-icon-button {
    display: grid;
    flex: none;
    width: 44px;
    height: 44px;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: inherit;
}

.chat-icon-button:hover, .chat-icon-button[aria-expanded="true"] {background: #f1d8ae}
.chat-icon-button svg {width: 18px; height: 18px}

.chat-channels {
    display: grid;
    flex: none;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: .25rem;
    padding: .35rem;
    border-bottom: 1px solid var(--chat-line);
    background: var(--chat-paper);
}

.chat-channels button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .36rem;
    min-height: 44px;
    padding: .35rem .25rem;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--chat-muted);
    font-size: .85rem;
    font-weight: 700;
}

.chat-channels button:hover {background: #f8e9d0}
.chat-channels button[aria-pressed="true"] {border-color: var(--chat-line); background: #f5e7ce; color: var(--chat-ink)}

.chat-direct-indicator {
    flex: none;
    width: .52rem;
    height: .52rem;
    border-radius: 50%;
    background: var(--chat-accent);
}

.chat-guest {display: grid; justify-items: start; gap: .75rem; padding: 1rem}
.chat-guest p {margin: 0}

.chat-login {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: .5rem .9rem;
    border-radius: 9px;
    background: var(--chat-accent);
    color: #fffaf0;
    font-weight: 700;
    text-decoration: none;
}

.chat-login:hover {background: #243d2d}

.chat-history, .chat-conversations {
    flex: 1;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    padding: .85rem;
    scrollbar-width: thin;
}

.chat-log {display: flex; flex-direction: column; gap: .65rem}

.chat-empty {
    margin: .45rem .2rem;
    color: var(--chat-muted);
    font-size: .9rem;
    text-align: center;
}

.chat-members-link {
    display: flex;
    width: fit-content;
    min-height: 44px;
    align-items: center;
    margin: .15rem auto .6rem;
    padding: .45rem .75rem;
    border-radius: 8px;
    color: var(--chat-accent);
    font-weight: 700;
    text-underline-offset: .16em;
}

.chat-members-link:hover {background: #f5e7ce}

.chat-message {
    align-self: flex-start;
    max-width: 86%;
    padding: .52rem .72rem;
    border: 1px solid #e8d7bf;
    border-radius: 13px 13px 13px 4px;
    background: var(--chat-surface);
    color: var(--chat-ink);
    overflow-wrap: anywhere;
}

.chat-message--mine {
    align-self: flex-end;
    border-color: #d4dec9;
    border-radius: 13px 13px 4px 13px;
    background: #e3ecd9;
}

.chat-message-body {margin: .06rem 0; color: inherit; line-height: 1.4; white-space: pre-wrap}
.chat-message-meta {margin: 0; color: var(--chat-muted); font-size: .72rem; line-height: 1.2}
.chat-message-meta strong {font-weight: 700}
.chat-message-time {display: block; margin: .26rem 0 0; color: var(--chat-muted); font-size: .68rem; line-height: 1.2; text-align: right}

.chat-message .chat-message-delete {
    display: flex;
    min-height: 36px;
    margin: .3rem 0 -.3rem auto;
    padding: 0 .7rem;
    border: 1px solid #d8b8a5;
    border-radius: 999px;
    background: rgb(255 255 255 / 45%);
    color: #713c27;
    font-size: .76rem;
    font-weight: 600;
    text-decoration: none;
}

.chat-message-delete:hover, .chat-message-delete:focus-visible {border-color: #b77d5d; background: #f5ddd0}
.chat-message-delete:disabled {opacity: .65}

.chat-feedback {
    flex: none;
    padding: .5rem .85rem;
    border-top: 1px solid #ead7b8;
    background: #f8edd8;
    color: #674222;
    font-size: .81rem;
    line-height: 1.35;
}

.chat-feedback p {margin: 0}
.chat-feedback a {display: inline-flex; align-items: center; min-height: 30px; font-weight: 700}

.chat-composer {
    display: flex;
    flex: none;
    align-items: flex-end;
    gap: .42rem;
    padding: .62rem .7rem;
    border-top: 1px solid var(--chat-line);
    background: var(--chat-paper);
}

.chat-composer textarea {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    max-height: 100px;
    resize: vertical;
    padding: .48rem .55rem;
    border: 1px solid #bda584;
    border-radius: 9px;
    background: #fffefb;
    color: var(--chat-ink);
    font-size: max(16px, .92rem);
    line-height: 1.3;
}

.chat-composer textarea:disabled {background: #f1eae0}

.chat-send {
    display: grid;
    flex: none;
    width: 44px;
    height: 44px;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: var(--chat-accent);
    color: #fffcf3;
}

.chat-send:not(:disabled):hover {background: #243d2d}
.chat-send:disabled {background: #e2d6c3; color: #635540}
.chat-send svg {width: 19px; height: 19px}

.chat-threads {display: grid; gap: .45rem; margin: 0; padding: 0; list-style: none}

.chat-thread {
    display: flex;
    align-items: center;
    gap: .25rem;
    min-width: 0;
    padding: .2rem;
    border: 1px solid #e8d7bf;
    border-radius: 10px;
    background: var(--chat-surface);
}

.chat-thread-open {
    display: grid;
    flex: 1;
    min-width: 0;
    min-height: 44px;
    gap: .18rem;
    padding: .45rem .53rem;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: inherit;
    text-align: start;
}

.chat-thread-open:hover {background: #faedd6}
.chat-thread-name {display: flex; align-items: center; flex-wrap: wrap; gap: .2rem .45rem; overflow-wrap: anywhere}
.chat-thread-preview {overflow: hidden; color: var(--chat-muted); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap}

.chat-thread-badge {
    display: inline-flex;
    padding: .12rem .4rem;
    border-radius: 100px;
    background: #f7e0b5;
    color: #5b381a;
    font-size: .72rem;
    font-weight: 700;
}

.chat-thread-badge--restricted {background: #f4ddd5; color: #792e22}

.chat-load {
    display: block;
    min-height: 44px;
    margin: 0 auto .6rem;
    padding: .4rem .65rem;
    border: 1px solid #d8bc96;
    border-radius: 9px;
    background: #fff8ec;
    color: #694829;
    font-size: .83rem;
    font-weight: 700;
}

.chat-conversations .chat-load {margin-top: .6rem}
.chat-load:not(:disabled):hover {background: #f9e8cb}

.chat-moderation {
    position: absolute;
    z-index: 1;
    top: 4rem;
    right: .55rem;
    width: min(248px, calc(100% - 16px));
    max-height: calc(100% - 16px);
    overflow: auto;
    padding: .38rem;
    border: 1px solid #d5ba92;
    border-radius: 11px;
    background: var(--chat-surface);
    box-shadow: 0 8px 25px #241d1436;
}

.chat-moderation p {margin: .15rem 0; padding: .35rem .5rem; color: var(--chat-muted); font-size: .8rem; font-weight: 700; overflow-wrap: anywhere}

.chat-moderation button {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: .44rem .52rem;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--chat-ink);
    font-size: .82rem;
    text-align: start;
}

.chat-moderation button:hover {background: #fae9cb}
.chat-moderation button:disabled {opacity: .6}

.chat-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.member-summary .member-badges:has([data-chat-open-direct]) {align-items: center}

@media (max-width: 450px) {
    .chat-widget {
        --chat-inset: max(12px, env(safe-area-inset-right));
        --chat-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .chat-header {padding-inline-start: .65rem}
    .chat-panel {border-radius: 15px}
}
