/* =============================================================
   Öğrenci-Eğitmen Birebir Mesajlaşma (Chat) — Panel stilleri
   Modern messenger görünümü. RTL (ar-SA) uyumu için mantıksal
   özellikler (inline-start/end) kullanılmıştır.
   ============================================================= */

:root {
    --chat-primary: #8a356a;
    --chat-primary-dark: #6f2a56;
    --chat-primary-soft: #f3e9f0;
    --chat-bg: #f4f6fb;
    --chat-panel-bg: #ffffff;
    --chat-border: #e9edf5;
    --chat-text: #1f2937;
    --chat-text-muted: #7c8698;
    --chat-bubble-other: #ffffff;
    --chat-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --chat-shadow-md: 0 6px 20px rgba(16, 24, 40, 0.08);
    --chat-shadow-lg: 0 18px 48px rgba(16, 24, 40, 0.16);
    --chat-radius: 16px;
}

.chat-wrapper {
    display: flex;
    height: calc(100vh - 250px);
    min-height: 520px;
    background: var(--chat-panel-bg);
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius);
    overflow: hidden;
    box-shadow: var(--chat-shadow-md);
}

/* ---------- Sol: sohbet listesi ---------- */

.chat-sidebar {
    width: 340px;
    min-width: 280px;
    border-inline-end: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    background: var(--chat-panel-bg);
}

.chat-sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--chat-border);
    background: var(--chat-panel-bg);
}

.chat-sidebar-header h5 {
    font-weight: 700;
    color: var(--chat-text);
    letter-spacing: -0.01em;
}

.chat-conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-conversation-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-conversation-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: #d7dde8;
    border-radius: 8px;
}

.chat-list-loader,
.chat-list-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--chat-text-muted);
}

.chat-conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    cursor: pointer;
    border-radius: 12px;
    margin-bottom: 2px;
    transition: background-color .15s ease;
}

.chat-conversation-item:hover {
    background: #f5f7fb;
}

.chat-conversation-item.active {
    background: var(--chat-primary-soft);
}

.chat-conv-avatar,
.chat-thread-avatar {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .95rem;
    letter-spacing: .02em;
    box-shadow: var(--chat-shadow-sm);
}

/* Kişi bazlı avatar renkleri (JS data-avatar-color ile atanır) */
.chat-avatar-c0 { background: linear-gradient(135deg, #8a356a, #6f2a56); }
.chat-avatar-c1 { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.chat-avatar-c2 { background: linear-gradient(135deg, #0891b2, #0e7490); }
.chat-avatar-c3 { background: linear-gradient(135deg, #16a34a, #15803d); }
.chat-avatar-c4 { background: linear-gradient(135deg, #ea580c, #c2410c); }
.chat-avatar-c5 { background: linear-gradient(135deg, #9333ea, #7e22ce); }
.chat-avatar-c6 { background: linear-gradient(135deg, #e11d48, #be123c); }
.chat-avatar-c7 { background: linear-gradient(135deg, #0d9488, #0f766e); }

.chat-conv-body {
    flex: 1;
    min-width: 0;
}

.chat-conv-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.chat-conv-name {
    font-weight: 600;
    color: var(--chat-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: .95rem;
}

.chat-conv-time {
    flex-shrink: 0;
    font-size: .72rem;
    color: var(--chat-text-muted);
}

.chat-conv-bottom {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
}

.chat-conv-preview {
    flex: 1;
    min-width: 0;
    font-size: .84rem;
    color: var(--chat-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conversation-item.has-unread .chat-conv-name {
    font-weight: 700;
}

.chat-conversation-item.has-unread .chat-conv-preview {
    color: var(--chat-text);
    font-weight: 600;
}

.chat-conv-unread {
    flex-shrink: 0;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--chat-primary);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.chat-conv-passive {
    flex-shrink: 0;
    color: #b6bdca;
    font-size: .72rem;
}

/* ---------- Sağ: mesaj akışı ---------- */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--chat-bg);
}

.chat-main-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--chat-text-muted);
}

.chat-main-empty i {
    opacity: .35;
}

.chat-thread {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-thread-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--chat-border);
    background: var(--chat-panel-bg);
    box-shadow: var(--chat-shadow-sm);
    z-index: 2;
}

.chat-thread-avatar {
    width: 44px;
    height: 44px;
}

.chat-back-btn {
    color: #52607a;
    padding: 4px 8px;
    font-size: 1.1rem;
}

.chat-thread-user {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chat-thread-name {
    font-weight: 700;
    color: var(--chat-text);
    font-size: 1rem;
}

.chat-thread-status {
    font-size: .78rem;
    color: #16a34a;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 1px;
}

.chat-thread-status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #16a34a;
    display: inline-block;
}

.chat-thread-status.passive {
    color: var(--chat-text-muted);
}

.chat-thread-status.passive::before {
    background: #c2c9d4;
}

.chat-thread-actions .btn {
    border-radius: 10px;
}

.chat-lifecycle-banner {
    padding: 12px 20px;
    background: #fff7ed;
    color: #9a3412;
    font-size: .84rem;
    border-bottom: 1px solid #fed7aa;
    display: flex;
    align-items: center;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background:
        radial-gradient(circle at 100% 0, rgba(138, 53, 106, 0.04), transparent 240px),
        var(--chat-bg);
}

.chat-messages-inner {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 860px;
    margin: 0 auto;
}

/* Gün ayırıcı çipi */
.chat-day-divider {
    align-self: center;
    margin: 14px 0 10px;
    padding: 4px 14px;
    background: rgba(31, 41, 55, 0.06);
    color: #52607a;
    font-size: .72rem;
    font-weight: 600;
    border-radius: 20px;
}

.chat-msg {
    display: flex;
    margin-top: 2px;
    animation: chatMsgIn .18s ease-out;
}

@keyframes chatMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg.own {
    justify-content: flex-end;
}

.chat-msg.other {
    justify-content: flex-start;
}

/* Aynı kişinin ardışık mesajları arası daha az boşluk */
.chat-msg.same-sender {
    margin-top: 1px;
}

.chat-msg-bubble {
    max-width: 68%;
    padding: 9px 14px;
    border-radius: 18px;
    background: var(--chat-bubble-other);
    box-shadow: var(--chat-shadow-sm);
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
}

.chat-msg.own .chat-msg-bubble {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: #fff;
    border-end-end-radius: 5px;
}

.chat-msg.other .chat-msg-bubble {
    border-end-start-radius: 5px;
}

.chat-msg-text {
    white-space: pre-wrap;
    font-size: .93rem;
    line-height: 1.5;
}

.chat-msg-image {
    max-width: 280px;
    max-height: 320px;
    border-radius: 12px;
    display: block;
    cursor: pointer;
}

.chat-msg-image + .chat-msg-text {
    margin-top: 6px;
}

.chat-msg-audio {
    max-width: 260px;
    width: 250px;
    display: block;
    height: 40px;
}

.chat-msg-file {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    padding: 4px 2px;
}

.chat-msg-file-icon {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(138, 53, 106, 0.1);
    color: var(--chat-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.chat-msg.own .chat-msg-file {
    color: #fff;
}

.chat-msg.own .chat-msg-file-icon {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.chat-msg-file-meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-msg-file-name {
    font-weight: 600;
    font-size: .88rem;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-msg-file-size {
    font-size: .74rem;
    opacity: .75;
}

.chat-msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
}

.chat-msg-time {
    font-size: .66rem;
    opacity: .65;
}

.chat-msg-ticks {
    font-size: .68rem;
    opacity: .7;
}

.chat-msg-ticks.read {
    color: #38bdf8;
    opacity: 1;
}

/* ---------- Yazıyor göstergesi (üç nokta) ---------- */

.chat-typing {
    padding: 6px 20px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--chat-bg);
}

.chat-typing-bubble {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 9px 14px;
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--chat-shadow-sm);
}

.chat-typing-bubble span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #b6bdca;
    animation: chatTyping 1.2s infinite ease-in-out;
}

.chat-typing-bubble span:nth-child(2) { animation-delay: .18s; }
.chat-typing-bubble span:nth-child(3) { animation-delay: .36s; }

@keyframes chatTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30% { transform: translateY(-5px); opacity: 1; }
}

.chat-typing-name {
    font-size: .76rem;
    color: var(--chat-text-muted);
}

/* ---------- Mesaj yazma alanı ---------- */

.chat-composer {
    border-top: 1px solid var(--chat-border);
    background: var(--chat-panel-bg);
    padding: 12px 16px;
}

.chat-composer-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.chat-composer-btn {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: #52607a;
    background: transparent;
    border: none;
    transition: background-color .15s ease, color .15s ease;
}

.chat-composer-btn:hover {
    background: #f0f2f7;
    color: var(--chat-primary);
}

.chat-composer-input {
    flex: 1;
    resize: none;
    border-radius: 22px;
    padding: 10px 16px;
    max-height: 120px;
    font-size: .93rem;
    background: #f4f6fb;
    border: 1px solid transparent;
    transition: border-color .15s ease, background-color .15s ease;
}

.chat-composer-input:focus {
    background: #fff;
    border-color: var(--chat-primary);
    box-shadow: none;
    outline: none;
}

.chat-send-btn {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    border: none;
    color: #fff;
    box-shadow: var(--chat-shadow-sm);
}

.chat-send-btn:hover {
    color: #fff;
    filter: brightness(1.05);
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
}

.chat-composer-disabled {
    border-top: 1px solid var(--chat-border);
    background: #f8fafc;
    color: var(--chat-text-muted);
    padding: 16px 20px;
    text-align: center;
    font-size: .88rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ---------- Ses kaydı ---------- */

.chat-voice-recording {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 8px;
    color: #dc2626;
    font-size: .9rem;
    font-weight: 500;
}

.chat-recording-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #dc2626;
    animation: chatRecordingPulse 1s infinite;
}

.chat-recording-time {
    font-variant-numeric: tabular-nums;
    min-width: 42px;
}

.chat-voice-recording .btn {
    margin-inline-start: auto;
    border-radius: 20px;
}

.chat-voice-recording .btn + .btn {
    margin-inline-start: 4px;
}

@keyframes chatRecordingPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .3; }
}

/* ---------- Mobil ---------- */

@media (max-width: 767.98px) {
    .chat-wrapper {
        height: calc(100vh - 190px);
        min-height: 440px;
    }

    .chat-sidebar {
        width: 100%;
        min-width: 0;
        border-inline-end: none;
    }

    .chat-main {
        display: none;
    }

    .chat-wrapper.mobile-thread .chat-sidebar {
        display: none;
    }

    .chat-wrapper.mobile-thread .chat-main {
        display: flex;
    }

    .chat-msg-bubble {
        max-width: 82%;
    }
}

/* ---------- RTL (ar-SA) ---------- */

html[dir="rtl"] .chat-back-btn i {
    transform: scaleX(-1);
}
