* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #ede9fe 0%, #f5f3ff 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 10px;
}

.chat-container {
    width: 100%;
    max-width: 420px;
    height: 92vh;
    max-height: 780px;
    background-color: white;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(106, 13, 173, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    background: linear-gradient(135deg, #6a0dad, #9b1f8e);
    color: white;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar-logo {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    background: white;
    padding: 2px;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.4);
}

.chat-header h2 {
    font-size: 1rem;
    font-weight: 700;
}

.chat-header p {
    font-size: 0.75rem;
    opacity: 0.85;
    margin-top: 1px;
}

#clear-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: 8px;
    padding: 6px 8px;
    transition: background 0.2s;
    flex-shrink: 0;
}

#clear-btn:hover {
    background: rgba(255,255,255,0.3);
}

.chat-box {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chat-box::-webkit-scrollbar {
    width: 4px;
}
.chat-box::-webkit-scrollbar-track {
    background: transparent;
}
.chat-box::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

.message {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
    animation: fadeSlideIn 0.25s ease;
}

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

.ai-message {
    background-color: #faf5ff;
    border: 1px solid #e9d5ff;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.user-message {
    background: linear-gradient(135deg, #6a0dad, #9b1f8e);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.message-content ul, 
.message-content ol {
    padding-left: 18px;
    margin-top: 6px;
}

.message-content li {
    margin-bottom: 4px;
}

.message-content p {
    margin-bottom: 6px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content strong {
    font-weight: 600;
}

.message-content code {
    background: rgba(0,0,0,0.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.85em;
}

/* ===== Tabel & elemen markdown dari jawaban AI ===== */
.message-content table {
    display: block;          /* agar tabel lebar bisa digeser, tidak keluar bubble */
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 0.85em;
}

.message-content th,
.message-content td {
    border: 1px solid #e9d5ff;
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
}

.message-content th {
    background: #f3e8ff;
    color: #4c1d95;
    font-weight: 600;
    white-space: nowrap;
}

.message-content tbody tr:nth-child(even) td {
    background: #fdfaff;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    font-size: 1em;
    font-weight: 700;
    color: #4c1d95;
    margin: 10px 0 4px;
}

.message-content a {
    color: #6a0dad;
    word-break: break-word;
}

.message-content hr {
    border: none;
    border-top: 1px solid #e9d5ff;
    margin: 10px 0;
}

/* Bubble yang berisi tabel boleh memakai lebar penuh */
.ai-message:has(table) {
    max-width: 100%;
}

.timestamp {
    font-size: 0.68rem;
    opacity: 0.55;
    margin-top: 4px;
    text-align: right;
}

.ai-message .timestamp {
    text-align: left;
}

.loading-dots {
    display: flex;
    gap: 5px;
    padding: 4px 0;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: #6a0dad;
    border-radius: 50%;
    animation: bounce 1.2s infinite;
    opacity: 0.5;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%            { transform: translateY(-6px); opacity: 1; }
}

.quick-questions {
    padding: 6px 14px 8px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    flex-shrink: 0;
    border-top: 1px solid #f0f0f0;
}

.quick-btn {
    background: #f3e8ff;
    color: #6a0dad;
    border: 1px solid #d8b4fe;
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.quick-btn:hover {
    background: #6a0dad;
    color: white;
    border-color: #6a0dad;
}

.chat-input-area {
    display: flex;
    padding: 10px 14px 6px;
    background-color: #fff;
    border-top: 1px solid #eee;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

#user-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 0.9rem;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    transition: border-color 0.2s;
    font-family: inherit;
}

#user-input:focus {
    border-color: #6a0dad;
}

#send-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    background: linear-gradient(135deg, #6a0dad, #9b1f8e);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, opacity 0.2s;
    flex-shrink: 0;
}

#send-btn:hover:not(:disabled) {
    transform: scale(1.08);
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.disclaimer {
    text-align: center;
    font-size: 0.68rem;
    color: #999;
    padding: 4px 14px 10px;
    flex-shrink: 0;
}

/* =========================================================
   RESPONSIF — TABLET & LAPTOP
   ========================================================= */

/* Tablet / layar sedang (≥ 768px) */
@media (min-width: 768px) {
    body {
        padding: 20px;
    }

    .chat-container {
        max-width: 760px;
        height: calc(100vh - 40px);
        max-height: none;
        border-radius: 20px;
    }

    .message {
        max-width: 78%;
        font-size: 0.95rem;
    }
}

/* Laptop / desktop (≥ 1024px) */
@media (min-width: 1024px) {
    body {
        padding: 24px;
    }

    .chat-container {
        max-width: 980px;
        height: calc(100vh - 48px);
    }

    .chat-header {
        padding: 16px 28px;
    }

    .avatar-logo {
        width: 56px;
        height: 56px;
    }

    .header-info {
        gap: 14px;
    }

    .chat-header h2 {
        font-size: 1.25rem;
    }

    .chat-header p {
        font-size: 0.85rem;
    }

    #clear-btn {
        font-size: 1.2rem;
        padding: 8px 10px;
    }

    .chat-box {
        padding: 24px 32px;
        gap: 16px;
    }

    .chat-box::-webkit-scrollbar {
        width: 6px;
    }

    .message {
        max-width: 70%;
        padding: 12px 18px;
        font-size: 1rem;
        line-height: 1.6;
    }

    .message-content table {
        font-size: 0.9em;
    }

    .quick-questions {
        padding: 10px 32px;
        gap: 8px;
    }

    .quick-btn {
        font-size: 0.85rem;
        padding: 7px 16px;
    }

    .chat-input-area {
        padding: 14px 32px 8px;
        gap: 12px;
    }

    #user-input {
        font-size: 1rem;
        padding: 12px 18px;
        max-height: 140px;
    }

    #send-btn {
        width: 48px;
        height: 48px;
        min-width: 48px;
    }

    .disclaimer {
        font-size: 0.75rem;
        padding: 4px 32px 14px;
    }
}

/* Layar sangat lebar (≥ 1600px) */
@media (min-width: 1600px) {
    .chat-container {
        max-width: 1100px;
        max-height: 1000px;
    }
}
