/* محادثات داخلية — واجهة احترافية */
#viewChatPanel.app-workspace.tab-view.active {
    display: flex !important;
    flex-direction: column;
    grid-template-columns: 1fr !important;
    gap: 0;
    width: 100%;
    padding: 0;
}

#viewChatPanel #chatPanelRoot {
    width: 100%;
    flex: 1;
}

.chat-shell {
    width: 100%;
    background: var(--card-bg, #fff);
    border: 1px solid var(--card-border, #e2e8f0);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(15, 23, 42, 0.08);
    display: flex;
    flex-direction: column;
    min-height: 76vh;
    max-height: 84vh;
}

.chat-settings-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    align-items: center;
    padding: 10px 16px;
    background: linear-gradient(90deg, #f8fafc, #f1f5f9);
    border-bottom: 1px solid #e2e8f0;
}

.chat-setting-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: #475569;
    cursor: pointer;
}

.chat-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    flex: 1;
    min-height: 0;
}

/* ─── Sidebar ─── */
.chat-sidebar {
    background: #f8fafc;
    border-left: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: calc(100% - 16px);
    margin: 10px 8px 4px;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    color: #334155;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.chat-back-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #0f172a;
}

.chat-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px 10px;
    background: #fff;
    border-bottom: 1px solid #eef2f7;
}

.chat-sidebar-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-sidebar-title h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #0f172a;
}

.chat-sidebar-count {
    background: #e0e7ff;
    color: #3730a3;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
}

.chat-sidebar-tools {
    display: flex;
    gap: 4px;
}

.chat-icon-btn {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 10px;
    background: #f1f5f9;
    color: #475569;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-icon-btn:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.chat-icon-btn.active {
    background: #dbeafe;
    color: #2563eb;
}

.chat-sidebar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 12px;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.chat-sidebar-search i {
    color: #94a3b8;
    font-size: 0.85rem;
}

.chat-sidebar-search input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.85rem;
    font-family: inherit;
    color: #334155;
}

.chat-sidebar-tabs {
    display: flex;
    gap: 4px;
    padding: 0 12px 8px;
}

.chat-tab {
    flex: 1;
    border: none;
    background: transparent;
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
}

.chat-tab:hover { background: #eef2ff; color: #4338ca; }
.chat-tab.active { background: #2563eb; color: #fff; }

.chat-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px 12px;
    min-height: 0;
}

.chat-list-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 10px 8px 4px;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: right;
    padding: 10px;
    border: none;
    border-radius: 12px;
    background: transparent;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
}

.chat-list-item:hover { background: #eef2ff; }
.chat-list-item.active {
    background: #fff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
    border: 1px solid #bfdbfe;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    flex-shrink: 0;
}

.chat-avatar--group,
.chat-avatar--broadcast { font-size: 0.9rem; }

.chat-list-body { flex: 1; min-width: 0; }

.chat-list-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    font-size: 0.88rem;
    color: #0f172a;
}

.chat-list-sub {
    font-size: 0.75rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.chat-list-time {
    font-size: 0.68rem;
    color: #94a3b8;
    margin-top: 2px;
}

.chat-thread-unread {
    background: #2563eb;
    color: #fff;
    font-size: 0.65rem;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    font-weight: 700;
}

.chat-quick-action {
    display: flex;
    align-items: center;
    gap: 8px;
    width: calc(100% - 8px);
    margin: 4px 4px 8px;
    padding: 10px 12px;
    border: 1px dashed #fcd34d;
    border-radius: 12px;
    background: #fffbeb;
    color: #92400e;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.chat-quick-action:hover {
    background: #fef3c7;
    border-style: solid;
}

.chat-hint {
    text-align: center;
    padding: 20px 12px;
    color: #94a3b8;
    font-size: 0.82rem;
}

/* ─── Main panel ─── */
.chat-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    background: #fff;
}

.chat-main-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid #eef2f7;
    background: #fff;
    flex-shrink: 0;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
}

.chat-main-head .chat-avatar {
    width: 46px;
    height: 46px;
    font-size: 0.95rem;
}

.chat-main-head-text { flex: 1; min-width: 0; }

.chat-main-head-text h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #0f172a;
}

.chat-main-head-text p {
    margin: 2px 0 0;
    font-size: 0.78rem;
    color: #64748b;
}

.chat-head-badge {
    font-size: 0.72rem;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 600;
}

.chat-head-badge--group { background: #dcfce7; color: #166534; }
.chat-head-badge--broadcast { background: #fef3c7; color: #92400e; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background:
        radial-gradient(circle at 20% 20%, rgba(37, 99, 235, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(5, 150, 105, 0.03) 0%, transparent 50%),
        #f8fafc;
    min-height: 0;
}

.chat-welcome {
    margin: auto;
    text-align: center;
    padding: 32px 24px;
    max-width: 360px;
}

.chat-welcome-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: linear-gradient(135deg, #dbeafe, #e0e7ff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    color: #2563eb;
}

.chat-welcome h3 {
    margin: 0 0 8px;
    color: #1e293b;
    font-size: 1.1rem;
}

.chat-welcome p {
    margin: 0 0 16px;
    color: #64748b;
    font-size: 0.88rem;
    line-height: 1.6;
}

.chat-welcome-tips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.chat-welcome-tips span {
    font-size: 0.75rem;
    color: #475569;
    background: #fff;
    border: 1px solid #e2e8f0;
    padding: 4px 10px;
    border-radius: 20px;
}

.chat-welcome--small {
    margin: auto;
    padding: 16px;
    color: #94a3b8;
    font-size: 0.85rem;
}

/* ─── Bubbles ─── */
.chat-bubble {
    max-width: 68%;
    padding: 10px 14px 6px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.55;
    position: relative;
    animation: chatBubbleIn 0.2s ease;
}

@keyframes chatBubbleIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-bubble.mine {
    align-self: flex-end;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.chat-bubble.theirs {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e8edf4;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.chat-bubble-sender {
    font-size: 0.72rem;
    font-weight: 700;
    color: #2563eb;
    margin-bottom: 4px;
}

.chat-bubble-body { word-break: break-word; }

.chat-bubble-foot {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
}

.chat-bubble-time {
    font-size: 0.65rem;
    opacity: 0.75;
}

.chat-bubble.mine .chat-bubble-time { color: #dbeafe; }
.chat-bubble.theirs .chat-bubble-time { color: #94a3b8; }

/* ─── Compose ─── */
.chat-compose {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid #eef2f7;
    background: #fff;
    flex-shrink: 0;
}

.chat-input-box {
    flex: 1;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 4px 4px 4px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-compose--active .chat-input-box:focus-within {
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
    background: #fff;
}

.chat-input-box textarea {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    padding: 8px 0;
    font-family: inherit;
    font-size: 0.92rem;
    line-height: 1.5;
    color: #1e293b;
}

.chat-send-round {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.chat-send-round:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.45);
}

.chat-send-round:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

/* ─── Role badges ─── */
.chat-role-badge {
    font-size: 0.65rem;
    padding: 2px 7px;
    border-radius: 6px;
    font-weight: 600;
}

.chat-role-admin { background: #fee2e2; color: #991b1b; }
.chat-role-manager { background: #fef3c7; color: #92400e; }
.chat-role-user { background: #e0f2fe; color: #0369a1; }

/* ─── Modals ─── */
.chat-new-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 50000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.chat-new-card {
    width: min(460px, 100%);
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
}

.chat-new-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.chat-new-head h4 { margin: 0; font-size: 0.95rem; color: #0f172a; }

.chat-group-form {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-group-name-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
}

.chat-group-member-list {
    max-height: 260px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px;
    background: #f8fafc;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
}

.chat-group-member-check {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
}

.chat-group-member-check:hover { background: #fff; }

.chat-disabled-card {
    text-align: center;
    padding: 60px 24px;
    color: #64748b;
}

.chat-disabled-card i {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* ─── Header chat button ─── */
.header-chat-btn {
    position: relative;
    background: rgba(37, 99, 235, 0.15);
    border: 1px solid rgba(96, 165, 250, 0.35);
    color: #93c5fd;
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.25s ease;
    font-size: 15px;
}

.header-chat-btn:hover {
    background: rgba(37, 99, 235, 0.28);
    color: #bfdbfe;
    transform: scale(1.05);
}

.header-chat-btn.active {
    background: #2563eb;
    border-color: #3b82f6;
    color: #fff;
    box-shadow: 0 0 12px rgba(37, 99, 235, 0.45);
}

body.light-mode .header-chat-btn {
    background: rgba(37, 99, 235, 0.1);
    border-color: rgba(37, 99, 235, 0.25);
    color: #2563eb;
}

body.light-mode .header-chat-btn.active {
    background: #2563eb;
    color: #fff;
}

#chatNavBadge {
    position: absolute;
    top: -4px;
    left: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 0.6rem;
    min-width: 15px;
    height: 15px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    font-weight: 700;
    border: 2px solid var(--bg-dark, #0f172a);
}

body.light-mode #chatNavBadge { border-color: #f0f4f8; }

/* Dark mode tweaks */
body:not(.light-mode) .chat-sidebar { background: rgba(15, 23, 42, 0.4); }
body:not(.light-mode) .chat-sidebar-head,
body:not(.light-mode) .chat-main-head,
body:not(.light-mode) .chat-compose { background: rgba(30, 41, 59, 0.6); }
body:not(.light-mode) .chat-list-item.active { background: rgba(37, 99, 235, 0.15); border-color: rgba(96, 165, 250, 0.3); }
body:not(.light-mode) .chat-bubble.theirs { background: rgba(51, 65, 85, 0.8); border-color: rgba(71, 85, 105, 0.6); color: #e2e8f0; }
body:not(.light-mode) .chat-input-box { background: rgba(51, 65, 85, 0.5); border-color: rgba(71, 85, 105, 0.5); }
body:not(.light-mode) .chat-input-box textarea { color: #e2e8f0; }

@media (max-width: 900px) {
    .chat-layout { grid-template-columns: 1fr; }
    .chat-sidebar { max-height: 240px; border-left: none; border-bottom: 1px solid #e2e8f0; }
    .chat-bubble { max-width: 85%; }
}
