/* ===== Variables ===== */
:root {
    --primary-color: #f97316;
    --primary-hover: #ea580c;
    --secondary-color: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

/* ===== Reset ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
}

/* ===== Chat Button ===== */
.chat-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 30px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(249, 115, 22, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9998;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.chat-button svg {
    flex-shrink: 0;
}

.chat-button-text {
    white-space: nowrap;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
}

.chat-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 30px rgba(249, 115, 22, 0.45);
    background: linear-gradient(135deg, var(--primary-hover), #c2410c);
}

.chat-button:active {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(249, 115, 22, 0.35);
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 0 0 0 rgba(249, 115, 22, 0.4);
    }
    50% {
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 0 0 15px rgba(249, 115, 22, 0);
    }
}

/* ===== Chat Container ===== */
.chat-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 400px;
    height: 600px;
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
}

.chat-container.hidden {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
}

/* ===== Chat Header ===== */
.chat-header {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bot-avatar {
    width: 42px;
    height: 42px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.header-text h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--success-color);
    border-radius: 50%;
    display: inline-block;
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.close-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.close-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* ===== Chat Messages ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--secondary-color);
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===== Messages ===== */
.message {
    display: flex;
    gap: 10px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
}

.message-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-content p {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    line-height: 1.6;
    white-space: pre-wrap;
}

.bot-message .message-content p {
    background: white;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-content {
    align-items: flex-end;
}

.user-message .message-content p {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-sm);
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    padding: 0 16px;
}

/* ===== Markdown Formatting in Messages ===== */
.message-content p strong {
    font-weight: 700;
    color: inherit;
}

.message-content p em {
    font-style: italic;
    color: inherit;
}

.message-content p h3,
.message-content p h4 {
    font-weight: 700;
    margin: 12px 0 8px 0;
    color: inherit;
}

.message-content p h3 {
    font-size: 16px;
}

.message-content p h4 {
    font-size: 14px;
}

.message-content p code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 13px;
    color: #e11d48;
}

.user-message .message-content p code {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.message-content p pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
}

.message-content p pre code {
    background: transparent;
    padding: 0;
    color: #e2e8f0;
    font-size: 13px;
}

.message-content p ul,
.message-content p ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content p ul {
    list-style-type: disc;
}

.message-content p ol {
    list-style-type: decimal;
}

.message-content p li {
    margin: 4px 0;
    line-height: 1.5;
}

.message-content p a {
    color: var(--primary-color);
    text-decoration: underline;
    transition: color 0.2s;
}

.message-content p a:hover {
    color: var(--primary-hover);
}

.user-message .message-content p a {
    color: #fff;
    text-decoration: underline;
}

.message-content p br {
    content: "";
    display: block;
    margin: 2px 0;
}

/* ===== Typing Indicator ===== */
.typing-indicator {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border-radius: var(--radius-lg);
    width: fit-content;
    box-shadow: var(--shadow-sm);
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ===== Chat Input ===== */
.chat-input-container {
    background: white;
    border-top: 1px solid var(--border-color);
    padding: 16px;
}

.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-family: inherit;
    font-size: 14px;
    resize: none;
    max-height: 120px;
    transition: all 0.2s;
    line-height: 1.5;
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

.send-button {
    width: 44px;
    height: 44px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.send-button:active:not(:disabled) {
    transform: translateY(0);
}

.send-button:disabled {
    background: var(--border-color);
    cursor: not-allowed;
}

.input-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

.character-count {
    font-size: 11px;
    color: var(--text-secondary);
}

/* ===== Loading Indicator ===== */
.loading-indicator {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
}

.loading-indicator.hidden {
    display: none;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Responsive Design ===== */
@media (max-width: 480px) {
    .chat-button {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .chat-container {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    .chat-messages {
        padding: 16px;
    }
}

/* ===== Error Message ===== */
.error-message {
    background: #fee;
    color: var(--danger-color);
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    border-left: 4px solid var(--danger-color);
    font-size: 13px;
}

/* ===== Success Animation ===== */
.message-sent {
    animation: messageSent 0.3s ease-out;
}

@keyframes messageSent {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.95);
    }
    100% {
        transform: scale(1);
    }
}
/* ===== DARK MODE PROTECTION ===== */
/* Protect chatbot dari dark mode CSS overrides */

/* Chat Button Protection */
body.dark-mode .chat-button,
body[class*="dark"] .chat-button,
html.dark-mode .chat-button,
html[class*="dark"] .chat-button {
    background: linear-gradient(135deg, #f97316, #ea580c) !important;
    color: white !important;
    border-color: transparent !important;
}

body.dark-mode .chat-button svg,
body[class*="dark"] .chat-button svg {
    fill: white !important;
}

body.dark-mode .chat-button-text,
body[class*="dark"] .chat-button-text {
    color: white !important;
}

/* Chat Container Background */
body.dark-mode .chat-container,
body[class*="dark"] .chat-container,
html.dark-mode .chat-container,
html[class*="dark"] .chat-container {
    background: white !important;
    color: #1e293b !important;
}

/* Chat Header Protection */
body.dark-mode .chat-header,
body[class*="dark"] .chat-header,
html.dark-mode .chat-header,
html[class*="dark"] .chat-header {
    background: linear-gradient(135deg, #1e293b, #0f172a) !important;
    color: white !important;
}

body.dark-mode .chat-header h3,
body.dark-mode .chat-header .status,
body[class*="dark"] .chat-header h3,
body[class*="dark"] .chat-header .status {
    color: white !important;
}

body.dark-mode .bot-avatar,
body[class*="dark"] .bot-avatar {
    background: rgba(255, 255, 255, 0.2) !important;
}

body.dark-mode .bot-avatar svg,
body[class*="dark"] .bot-avatar svg {
    fill: white !important;
}

/* Chat Messages Protection */
body.dark-mode .chat-messages,
body[class*="dark"] .chat-messages,
html.dark-mode .chat-messages,
html[class*="dark"] .chat-messages {
    background: white !important;
}

/* Bot Message */
body.dark-mode .bot-message .message-content,
body[class*="dark"] .bot-message .message-content {
    background: #f1f5f9 !important;
    color: #1e293b !important;
}

body.dark-mode .bot-message p,
body.dark-mode .bot-message span,
body.dark-mode .bot-message strong,
body.dark-mode .bot-message em,
body.dark-mode .bot-message code,
body[class*="dark"] .bot-message p,
body[class*="dark"] .bot-message span,
body[class*="dark"] .bot-message strong,
body[class*="dark"] .bot-message em,
body[class*="dark"] .bot-message code {
    color: #1e293b !important;
}

body.dark-mode .message-time,
body[class*="dark"] .message-time {
    color: #64748b !important;
}

/* User Message */
body.dark-mode .user-message .message-content,
body[class*="dark"] .user-message .message-content {
    background: linear-gradient(135deg, #f97316, #ea580c) !important;
    color: white !important;
}

body.dark-mode .user-message p,
body.dark-mode .user-message span,
body[class*="dark"] .user-message p,
body[class*="dark"] .user-message span {
    color: white !important;
}

/* Input Area Protection */
body.dark-mode .chat-input-container,
body[class*="dark"] .chat-input-container {
    background: white !important;
    border-top-color: #e2e8f0 !important;
}

body.dark-mode #messageInput,
body[class*="dark"] #messageInput {
    background: white !important;
    color: #1e293b !important;
    border-color: #e2e8f0 !important;
}

body.dark-mode #messageInput::placeholder,
body[class*="dark"] #messageInput::placeholder {
    color: #94a3b8 !important;
}

body.dark-mode .send-button,
body[class*="dark"] .send-button {
    background: linear-gradient(135deg, #f97316, #ea580c) !important;
    color: white !important;
}

body.dark-mode .send-button svg,
body[class*="dark"] .send-button svg {
    fill: white !important;
}

body.dark-mode .close-button,
body[class*="dark"] .close-button {
    color: white !important;
}

body.dark-mode .close-button svg,
body[class*="dark"] .close-button svg {
    stroke: white !important;
}

body.dark-mode .character-count,
body[class*="dark"] .character-count {
    color: #64748b !important;
}

/* Typing Indicator Protection */
body.dark-mode .typing-indicator,
body[class*="dark"] .typing-indicator {
    background: #f1f5f9 !important;
}

body.dark-mode .typing-dot,
body[class*="dark"] .typing-dot {
    background: #94a3b8 !important;
}

/* Links & Code in Messages */
body.dark-mode .message-content a,
body[class*="dark"] .message-content a {
    color: #f97316 !important;
}

body.dark-mode .message-content code,
body[class*="dark"] .message-content code {
    background: #e2e8f0 !important;
    color: #1e293b !important;
}

body.dark-mode .message-content pre,
body[class*="dark"] .message-content pre {
    background: #f1f5f9 !important;
    border-color: #e2e8f0 !important;
}

body.dark-mode .message-content pre code,
body[class*="dark"] .message-content pre code {
    color: #1e293b !important;
}