/* Chat: a button in the corner of every page, and the panel it opens. */

.chat-toggle {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1040;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border: 0;
    border-radius: 999px;
    background: var(--stp-text);
    color: var(--stp-bg);
    font: 600 14px var(--font-sans);
    box-shadow: 0 4px 14px rgb(0 0 0 / 0.25);
}

.chat-toggle:hover {
    filter: brightness(1.15);
}

.chat-toggle[aria-expanded="true"] {
    display: none;
}

.chat-dot {
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--stp-accent);
    color: #fff;
    font: 600 12px/18px var(--font-mono);
    text-align: center;
}

.chat-panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1041;
    display: flex;
    flex-direction: column;
    width: min(370px, calc(100vw - 24px));
    height: min(540px, calc(100vh - 40px));
    border: 1px solid var(--stp-border);
    border-radius: 10px;
    background: var(--stp-surface);
    box-shadow: 0 12px 36px rgb(0 0 0 / 0.28);
    font-size: 13.5px;
    overflow: hidden;
}

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

.chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 8px 8px 0 12px;
    border-bottom: 1px solid var(--stp-border);
}

.chat-tabs {
    display: flex;
    gap: 14px;
    min-width: 0;
    overflow-x: auto;
}

.chat-tab {
    flex: none;
    padding: 6px 0 8px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--stp-muted);
    font-weight: 600;
}

.chat-tab:hover {
    color: var(--stp-text);
}

.chat-tab.active {
    color: var(--stp-text);
    border-bottom-color: var(--stp-accent);
}

.chat-count {
    margin-left: 5px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--stp-accent);
    color: #fff;
    font: 600 11px/16px var(--font-mono);
}

.chat-about {
    padding: 8px 12px;
    background: var(--stp-surface-2);
    border-bottom: 1px solid var(--stp-border);
    font-size: 12px;
    line-height: 1.45;
}

.chat-about strong,
.chat-about span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-about span {
    color: var(--stp-muted);
}

.chat-live {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 6px;
    border-radius: 50%;
    background: #3f9d5d;
}

.chat-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 10px 12px;
}

.chat-empty {
    padding: 24px 8px;
    text-align: center;
    color: var(--stp-muted);
}

.chat-msg {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 3px;
}

.chat-msg.mine {
    align-items: flex-end;
}

.chat-by {
    margin: 8px 2px 2px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--stp-muted);
}

.chat-bubble {
    max-width: 86%;
    padding: 6px 10px;
    border-radius: 10px;
    background: var(--stp-surface-2);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.35;
}

.chat-msg.mine .chat-bubble {
    background: color-mix(in srgb, var(--stp-accent) 16%, var(--stp-surface));
}

.chat-bubble time {
    margin-left: 8px;
    font: 10.5px var(--font-mono);
    color: var(--stp-muted);
    white-space: nowrap;
}

.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px;
    border-top: 1px solid var(--stp-border);
}

.chat-form textarea {
    resize: none;
    min-height: 36px;
}

.chat-form .btn {
    flex: none;
    height: 36px;
    padding: 0 10px;
}

.chat-form .btn .icon {
    margin: 0;
}

.chat-error {
    padding: 0 10px 8px;
    font-size: 12px;
    color: var(--bs-danger, #b3261e);
}

@media print {
    .chat-toggle,
    .chat-panel {
        display: none;
    }
}

/* ---- Bigger, for reading back or a long discussion ---- */

.chat-panel.wide {
    width: min(780px, calc(100vw - 24px));
    height: calc(100vh - 40px);
}

.chat-head-buttons {
    display: flex;
    flex: none;
}

/* ---- Chat, Discussions, History ---- */

.chat-views {
    display: flex;
    gap: 4px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--stp-border);
}

.chat-view {
    padding: 3px 10px;
    border: 0;
    border-radius: 999px;
    background: none;
    color: var(--stp-muted);
    font-size: 12.5px;
    font-weight: 600;
}

.chat-view:hover {
    color: var(--stp-text);
}

.chat-view.active {
    background: color-mix(in srgb, var(--stp-text) 10%, transparent);
    color: var(--stp-text);
}

.chat-more,
.chat-start {
    display: block;
    margin: 0 auto 8px;
}

.chat-start {
    margin: 0 0 10px;
}

.chat-topic {
    display: block;
    width: 100%;
    margin-bottom: 6px;
    padding: 8px 10px;
    border: 1px solid var(--stp-border);
    border-radius: 8px;
    background: var(--stp-surface);
    color: var(--stp-text);
    text-align: left;
}

.chat-topic:hover {
    border-color: var(--stp-border-strong);
    background: var(--stp-surface-2);
}

.chat-topic strong,
.chat-topic span {
    display: block;
    overflow-wrap: anywhere;
}

.chat-topic span,
.chat-sub {
    font-size: 11.5px;
    color: var(--stp-muted);
}

.chat-thread-head {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--stp-border);
}

.chat-thread-head .btn {
    margin: 0 0 4px -8px;
}

.chat-thread-head h3 {
    margin: 0;
    font-size: 15px;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.chat-new {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border-top: 1px solid var(--stp-border);
}

.chat-new[hidden],
.chat-form[hidden],
.chat-search[hidden] {
    display: none;
}

.chat-new textarea {
    resize: none;
}

.chat-new-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.chat-search {
    padding: 8px;
    border-bottom: 1px solid var(--stp-border);
}

.chat-day {
    position: sticky;
    top: -10px;
    margin: 0 -12px 6px;
    padding: 4px 12px;
    background: var(--stp-surface-2);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--stp-muted);
}

.chat-past {
    margin-bottom: 9px;
}

.chat-past-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    font-size: 12.5px;
}

.chat-past-head time {
    font: 11px var(--font-mono);
    color: var(--stp-muted);
}

.chat-tag {
    max-width: 100%;
    padding: 0 7px;
    border: 0;
    border-radius: 999px;
    background: color-mix(in srgb, var(--stp-accent) 16%, var(--stp-surface));
    color: var(--stp-text);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-past-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.35;
}
