/* ============================================
   E.D.I.T.H CHAT — Discord-style
   ============================================ */

/* Chat view wrapper — fills main content area */
.chat-view {
    display: none;
    width: 100%;
    height: 100%;
    flex-direction: row;
    overflow: hidden;
    background: hsl(var(--background));
}
.chat-view.active {
    display: flex;
}

/* ── LEFT: Server / Channel Sidebar ─────────── */
.chat-sidebar {
    width: 240px;
    min-width: 240px;
    background: hsl(var(--card));
    border-right: 1px solid hsl(var(--border));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-server-header {
    padding: 0 16px;
    height: 48px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid hsl(var(--border));
    font-weight: 600;
    font-size: 0.9rem;
    color: hsl(var(--foreground));
    gap: 8px;
    flex-shrink: 0;
}
.chat-server-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.chat-channels-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.chat-category {
    padding: 16px 8px 4px 8px;
}
.chat-category-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: hsl(var(--muted-foreground));
    padding: 0 8px;
}

.chat-channel-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    margin: 1px 8px;
    border-radius: 6px;
    cursor: pointer;
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
    transition: background 0.1s, color 0.1s;
    user-select: none;
}
.chat-channel-item:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
}
.chat-channel-item.active {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
    font-weight: 500;
}
.chat-channel-hash {
    font-size: 1rem;
    opacity: 0.6;
    flex-shrink: 0;
}
.chat-channel-unread {
    margin-left: auto;
    background: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* ── CENTER: Message Area ───────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.chat-channel-header {
    height: 48px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid hsl(var(--border));
    flex-shrink: 0;
}
.chat-channel-header-hash {
    font-size: 1.2rem;
    color: hsl(var(--muted-foreground));
}
.chat-channel-header-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: hsl(var(--foreground));
}
.chat-channel-header-divider {
    width: 1px;
    height: 20px;
    background: hsl(var(--border));
    margin: 0 6px;
}
.chat-channel-header-topic {
    font-size: 0.8rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Message group */
.chat-msg-group {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 12px;
    padding: 2px 16px;
    border-radius: 4px;
    transition: background 0.1s;
}
.chat-msg-group:hover {
    background: hsl(var(--muted) / 0.4);
}
.chat-msg-group.continued {
    padding-top: 1px;
    padding-bottom: 1px;
}
.chat-msg-group.continued .chat-msg-avatar {
    visibility: hidden;
}
.chat-msg-group.continued .chat-msg-meta {
    display: none;
}

.chat-msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-top: 2px;
}
.chat-msg-avatar-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-msg-body {
    flex: 1;
    min-width: 0;
}
.chat-msg-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}
.chat-msg-author {
    font-weight: 600;
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    cursor: pointer;
}
.chat-msg-author:hover { text-decoration: underline; }
.chat-msg-author.is-human { color: #22c55e; }
.chat-msg-author.is-lead { color: #3b82f6; }
.chat-msg-author.is-reviewer { color: #f59e0b; }
.chat-msg-time {
    font-size: 0.7rem;
    color: hsl(var(--muted-foreground));
}
.chat-msg-text {
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    line-height: 1.5;
    word-break: break-word;
}
.chat-mention {
    background: hsl(var(--primary) / 0.15);
    color: hsl(var(--primary));
    border-radius: 3px;
    padding: 0 3px;
    font-weight: 500;
    cursor: pointer;
}
.chat-mention:hover { background: hsl(var(--primary) / 0.25); }

/* Date divider */
.chat-date-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 8px;
    color: hsl(var(--muted-foreground));
    font-size: 0.72rem;
    font-weight: 600;
}
.chat-date-divider::before,
.chat-date-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: hsl(var(--border));
}

/* ── Input Bar ─────────────────────────────── */
.chat-input-bar {
    padding: 0 16px 16px;
    flex-shrink: 0;
}
.chat-input-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border));
    border-radius: 8px;
    padding: 10px 14px;
    transition: border-color 0.2s;
}
.chat-input-inner:focus-within {
    border-color: hsl(var(--ring));
}
.chat-text-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    font-family: inherit;
}
.chat-text-input::placeholder { color: hsl(var(--muted-foreground)); }
.chat-send-btn {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: none;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
.chat-send-btn:hover { opacity: 0.85; }

/* ── RIGHT: Members Sidebar ─────────────────── */
.chat-members-sidebar {
    width: 200px;
    min-width: 200px;
    background: hsl(var(--card));
    border-left: 1px solid hsl(var(--border));
    overflow-y: auto;
    padding: 16px 0;
}
.chat-members-header {
    padding: 0 12px 8px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: hsl(var(--muted-foreground));
}
.chat-member-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px;
    border-radius: 6px;
    margin: 1px 6px;
    cursor: pointer;
    transition: background 0.1s;
}
.chat-member-item:hover { background: hsl(var(--accent)); }
.chat-member-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    position: relative;
}
.chat-member-avatar-placeholder {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.7rem;
    flex-shrink: 0;
}
.chat-member-info { flex: 1; min-width: 0; }
.chat-member-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-member-role {
    font-size: 0.68rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-member-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.chat-member-status.online { background: #22c55e; }
.chat-member-status.away { background: #f59e0b; }
.chat-member-status.offline { background: hsl(var(--muted-foreground)); }

/* Mention autocomplete */
.mention-dropdown {
    position: absolute;
    bottom: 70px;
    left: 16px;
    right: 216px;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: 8px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}
.mention-dropdown.visible { display: block; }
.mention-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.1s;
}
.mention-item:hover, .mention-item.selected {
    background: hsl(var(--accent));
}
.mention-item-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    flex-shrink: 0;
}
.mention-item-name { font-weight: 500; color: hsl(var(--foreground)); }
.mention-item-role { font-size: 0.72rem; color: hsl(var(--muted-foreground)); }

/* Header chat nav button */
.chat-nav-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid hsl(var(--border));
    background: transparent;
    color: hsl(var(--muted-foreground));
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.chat-nav-btn:hover, .chat-nav-btn.active {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
    border-color: hsl(var(--ring));
}
.chat-nav-btn.active { color: hsl(var(--foreground)); }

/* Board/Chat toggle area */
.view-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 8px;
}
.view-toggle-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid hsl(var(--border));
    background: transparent;
    color: hsl(var(--muted-foreground));
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.view-toggle-btn.active {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border-color: hsl(var(--primary));
}

@media (max-width: 900px) {
    .chat-members-sidebar { display: none; }
    .chat-sidebar { width: 180px; min-width: 180px; }
}
@media (max-width: 600px) {
    .chat-sidebar { width: 56px; min-width: 56px; }
    .chat-channel-item span { display: none; }
    .chat-category-label { display: none; }
    .chat-server-header span { display: none; }
}
