/* ─── Pub place chat panel ─────────────────────────────────────────── */

.chat-panel {
    display: flex;
    flex-direction: column;
}

/* ── Header ── */
.chat-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-surface);
    flex-wrap: wrap;
}
.chat-header-title {
    flex: 1;
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    flex-wrap: wrap;
    min-width: 0;
}
.chat-header-h3 {
    margin: 0;
    font-size: var(--font-size-md);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.chat-header-divider {
    color: var(--color-text-muted);
}
.chat-header-channel {
    font-size: var(--font-size-md);
    font-weight: 700;
    color: var(--color-text);
}
.chat-header-desc {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    font-style: italic;
}
.chat-header-desc:empty { display: none; }

.chat-poll-status {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
    background: var(--color-bg-subtle);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

/* ── Body: sidebar + main ── */
.chat-body {
    display: flex;
    height: 480px;
}

.chat-sidebar {
    width: 200px;
    flex-shrink: 0;
    border-right: 1px solid var(--color-border);
    background: var(--color-bg-surface);
    display: flex;
    flex-direction: column;
    padding: var(--space-2);
    gap: var(--space-2);
}

.chat-channel-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.chat-channel-item {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--color-text);
    font-size: var(--font-size-sm);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}
.chat-channel-item:hover {
    background: var(--color-bg-subtle);
}
.chat-channel-item.is-active {
    background: var(--color-primary);
    color: white;
}

.chat-channel-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-channel-edit {
    display: none;
    width: 18px;
    height: 18px;
    line-height: 16px;
    text-align: center;
    border-radius: 50%;
    font-size: 12px;
    color: var(--color-text-muted);
    cursor: pointer;
}
.chat-channel-item:hover .chat-channel-edit {
    display: inline-block;
}
.chat-channel-edit:hover {
    background: rgba(0, 0, 0, 0.15);
    color: var(--color-text);
}
.chat-channel-item.is-active .chat-channel-edit {
    color: rgba(255, 255, 255, 0.7);
}
.chat-channel-item.is-active .chat-channel-edit:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.chat-channel-new {
    background: transparent;
    border: 1px dashed var(--color-border);
    color: var(--color-text-muted);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-family: inherit;
    cursor: pointer;
    text-align: center;
}
.chat-channel-new:hover {
    background: var(--color-bg-subtle);
    color: var(--color-text);
}

/* ── Main message area ── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-surface);
    display: flex;
    flex-direction: column;
}

.chat-load-more {
    align-self: center;
    background: var(--color-bg-subtle);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    margin-bottom: var(--space-3);
    cursor: pointer;
}
.chat-load-more:hover { color: var(--color-text); }

.chat-msg {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
}
.chat-msg:last-child { border-bottom: none; }

.chat-msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--color-bg-subtle);
}
.chat-msg-avatar-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--color-text-muted);
    font-size: 14px;
}

.chat-msg-content {
    flex: 1;
    min-width: 0;
}

.chat-msg-meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-bottom: 2px;
}
.chat-msg-name {
    color: var(--color-text);
    font-weight: 600;
    text-decoration: none;
}
.chat-msg-name:hover { color: var(--color-value); }
.chat-msg-edited { font-style: italic; }

.chat-msg-actions {
    margin-left: auto;
    display: none;
    gap: 6px;
}
.chat-msg:hover .chat-msg-actions { display: inline-flex; }

.chat-msg-edit, .chat-msg-delete {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: var(--font-size-xs);
    padding: 0;
    font-family: inherit;
}
.chat-msg-edit:hover { color: var(--color-value); }
.chat-msg-delete:hover { color: var(--color-error, #c0392b); }

.chat-msg-body {
    font-size: var(--font-size-sm);
    line-height: 1.5;
    color: var(--color-text);
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.chat-msg-body a {
    color: var(--color-value);
    text-decoration: underline;
}

/* ── Send form ── */
.chat-send-form {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3);
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-surface);
}
.chat-send-form textarea {
    flex: 1;
    resize: vertical;
    min-height: 40px;
    max-height: 200px;
    padding: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: var(--font-size-sm);
    background: var(--color-bg-surface);
    color: var(--color-text);
}
.chat-send-form textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}
.chat-send-form button { align-self: flex-end; }

.chat-readonly-notice {
    padding: var(--space-3);
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-surface);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    text-align: center;
    font-style: italic;
}

/* ── Modal ── */
.chat-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}
.chat-modal-panel {
    position: relative;
    background: var(--color-bg-surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    margin: var(--space-4);
}
.chat-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
}
.chat-modal-title {
    font-weight: 700;
    font-size: var(--font-size-md);
}
.chat-modal-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px;
    line-height: 0;
}
.chat-modal-close:hover { color: var(--color-text); }
.chat-modal-body {
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}
.chat-modal-foot {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-subtle);
}

/* ── Responsive: collapse sidebar on narrow screens ── */
@media (max-width: 640px) {
    .chat-body {
        flex-direction: column;
        height: auto;
    }
    .chat-sidebar {
        width: auto;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }
    .chat-channel-list {
        flex-direction: row;
        flex-wrap: wrap;
        flex: none;
    }
    .chat-channel-new {
        align-self: flex-start;
    }
    .chat-main {
        height: 480px;
    }
}
