/* Mbah Man Chat Styles - Modern Clean Chat UI */
/* ============================================================
   Container: menyesuaikan dengan layout SB Admin 2
   - MainLayout punya: sidebar kiri + topbar navbar (mb-4) + footer
   - container-fluid memberi padding 1.5rem kiri-kanan
   - Gunakan margin negatif & height yang pas agar fit sempurna
   ============================================================ */
.mbahman-chat-container {
    display: flex;
    /* 100vh dikurangi: navbar ~70px + mb-4 ~24px + footer ~60px = ~154px, dibulatkan 160px */
    height: calc(100vh - 160px);
    background: #f1f5f9;
    font-family: 'Segoe UI', system-ui, sans-serif;
    /* Negatifkan padding container-fluid agar chat melebar penuh */
    margin-left: -1.5rem;
    margin-right: -1.5rem;
    overflow: hidden;
}

/* Sidebar Chat */
.chat-sidebar {
    width: 300px;
    background: #1e293b;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-left 0.3s ease;
    z-index: 50;
}
.chat-sidebar:not(.sidebar-open) {
    margin-left: -300px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid #334155;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #fff;
    font-size: 1.2rem;
}
.brand-name {
    font-size: 1rem;
    font-weight: 600;
    color: #f1f5f9;
}
.brand-sub {
    font-size: .7rem;
    color: #94a3b8;
}

.btn-new-session {
    margin: 12px;
    padding: 10px 16px;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background .2s;
}
.btn-new-session:hover {
    background: #2563eb;
}

.sidebar-selectors {
    display: flex;
    gap: 6px;
    padding: 0 12px 12px;
}
.select-sm {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #334155;
    border-radius: 6px;
    font-size: .75rem;
    background: #0f172a;
    color: #e2e8f0;
    cursor: pointer;
}

.sidebar-sessions {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px;
}
.sessions-label {
    font-size: .7rem;
    text-transform: uppercase;
    color: #64748b;
    padding: 8px 12px 4px;
    letter-spacing: .5px;
}
.sessions-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    color: #64748b;
    font-size: .85rem;
    gap: 8px;
}

.session-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .2s;
    margin-bottom: 2px;
}
.session-item:hover {
    background: #334155;
}
.session-item.session-active {
    background: #3b82f6;
}
.session-icon {
    margin-right: 8px;
    color: #64748b;
    font-size: .85rem;
}
.session-info {
    flex: 1;
    min-width: 0;
}
.session-title {
    font-size: .85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-meta {
    font-size: .7rem;
    color: #94a3b8;
}
.btn-session-delete {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px;
    opacity: 0;
    transition: opacity .2s;
}
.session-item:hover .btn-session-delete {
    opacity: 1;
}
.btn-session-delete:hover {
    color: #ef4444;
}

.sidebar-footer {
    padding: 10px 16px;
    border-top: 1px solid #334155;
    font-size: .7rem;
    text-align: center;
    color: #64748b;
}

/* Overlay untuk mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 40;
}

/* ============================================================
   Main Chat Area
   ============================================================ */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
}

/* Header Chat */
.chat-header {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    gap: 12px;
    flex-shrink: 0;
}
.chat-header-info {
    flex: 1;
}
.chat-header-info h1 {
    margin: 0;
    font-size: 1rem;
    color: #1e293b;
}
.chat-subtitle {
    font-size: .75rem;
    color: #64748b;
}
.chat-header-right {
    display: flex;
    gap: 8px;
}
.btn-hamburger {
    display: none;
}
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #64748b;
    border-radius: 8px;
    transition: background .2s;
    font-size: 1rem;
}
.btn-icon:hover {
    background: #f1f5f9;
    color: #1e293b;
}

/* Area Pesan */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Welcome Screen */
.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}
.welcome-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: bold;
    color: #fff;
    margin-bottom: 16px;
    box-shadow: 0 4px 15px rgba(245,158,11,.3);
}
.chat-welcome h2 {
    font-size: 1.5rem;
    color: #1e293b;
    margin: 0 0 8px;
}
.chat-welcome p {
    color: #64748b;
    margin: 0 0 24px;
    max-width: 400px;
}
.welcome-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-width: 500px;
}
.suggestion-chip {
    padding: 10px 18px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    cursor: pointer;
    font-size: .875rem;
    color: #334155;
    transition: all .2s;
}
.suggestion-chip:hover {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}

/* Message Rows */
.message-row {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: fadeIn .3s;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.message-user-row {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.message-assistant-row {
    align-self: flex-start;
}
.message-avatar {
    flex-shrink: 0;
}
.avatar-user {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: .9rem;
}
.avatar-assistant {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: bold;
    font-size: 1rem;
}

.message-body {
    min-width: 0;
}
.message-meta {
    display: flex;
    gap: 8px;
    margin-bottom: 2px;
}
.message-sender {
    font-size: .75rem;
    font-weight: 600;
    color: #64748b;
}
.message-time {
    font-size: .7rem;
    color: #94a3b8;
}
.message-content {
    padding: 12px 16px;
    border-radius: 16px;
    background: #f1f5f9;
    color: #1e293b;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.message-user-row .message-content {
    background: #3b82f6;
    color: #fff;
}

.message-attachments {
    margin-bottom: 8px;
}
.attachment-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    object-fit: cover;
    cursor: pointer;
}
.attachment-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #fff;
    border-radius: 8px;
    color: #3b82f6;
    text-decoration: none;
    font-size: .85rem;
    border: 1px solid #e2e8f0;
}

.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}
.btn-msg-action {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    color: #94a3b8;
    font-size: .75rem;
    border-radius: 4px;
}
.btn-msg-action:hover {
    color: #3b82f6;
    background: #f1f5f9;
}

/* Markdown Content */
.markdown-body p { margin: 0 0 8px; }
.markdown-body p:last-child { margin-bottom: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 12px 0 6px; }
.markdown-body ul, .markdown-body ol { margin: 6px 0; padding-left: 20px; }
.markdown-body li { margin: 2px 0; }
.code-block {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px 16px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: .85rem;
    margin: 8px 0;
    font-family: Consolas, monospace;
    white-space: pre-wrap;
}
.inline-code {
    background: #e2e8f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: .85rem;
    font-family: Consolas, monospace;
}
.message-user-row .inline-code {
    background: rgba(255,255,255,.2);
}
.markdown-body blockquote {
    border-left: 3px solid #3b82f6;
    padding: 8px 12px;
    margin: 8px 0;
    background: #f8fafc;
    color: #475569;
}
.markdown-body a {
    color: #3b82f6;
    text-decoration: none;
}
.markdown-body a:hover {
    text-decoration: underline;
}
.markdown-body img {
    max-width: 100%;
    border-radius: 8px;
    margin: 8px 0;
}
.markdown-body hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 12px 0;
}
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: .85rem;
}
.markdown-body th {
    background: #f1f5f9;
    padding: 8px 12px;
    text-align: left;
    border: 1px solid #e2e8f0;
    font-weight: 600;
}
.markdown-body td {
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}
.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

/* Input Area */
.chat-input-area {
    padding: 12px 20px 20px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.attachment-preview-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.attachment-preview-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: .8rem;
}
.preview-thumb {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: cover;
}
.preview-file-icon {
    width: 32px;
    height: 32px;
    background: #e2e8f0;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
}
.preview-name {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.preview-remove {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.btn-attach {
    cursor: pointer;
    padding: 10px;
    color: #64748b;
    border-radius: 8px;
    transition: background .2s;
    display: flex;
}
.btn-attach:hover {
    background: #f1f5f9;
    color: #3b82f6;
}
.file-input-hidden {
    display: none;
}
.chat-textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    font-size: .95rem;
    resize: none;
    outline: none;
    font-family: inherit;
    transition: border-color .2s;
    max-height: 150px;
    min-width: 0;
}
.chat-textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
.chat-textarea:disabled {
    background: #f8fafc;
}
.btn-send {
    padding: 10px 14px;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background .2s;
    font-size: 1rem;
}
.btn-send:hover:not(:disabled) {
    background: #2563eb;
}
.btn-send:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

.input-footer {
    text-align: center;
    padding-top: 6px;
    font-size: .7rem;
    color: #94a3b8;
}

/* Error Banner */
.error-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #dc2626;
    font-size: .85rem;
    width: 100%;
}
.btn-error-dismiss {
    background: none;
    border: none;
    color: #dc2626;
    cursor: pointer;
    margin-left: auto;
}

/* ============================================================
   RESPONSIVE - Mobile / Tablet
   ============================================================ */
@media (max-width: 768px) {
    .mbahman-chat-container {
        /* Mobile: navbar topbar ~70px + footer ~35px = 105px */
        height: calc(100vh - 105px);
        margin-left: -0.75rem;
        margin-right: -0.75rem;
    }

    .chat-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1050;
    }
    .chat-sidebar:not(.sidebar-open) {
        margin-left: -300px;
    }

    .sidebar-overlay {
        display: block;
        z-index: 1040;
    }

    .btn-hamburger {
        display: block;
    }

    .message-row {
        max-width: 95%;
    }

    .chat-messages {
        padding: 16px;
    }
}

/* Tablet kecil */
@media (max-width: 576px) {
    .mbahman-chat-container {
        height: calc(100vh - 95px);
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }
}
