:root {
    /* Palette: Slate Premium SaaS */
    --bg-app: #f8fafc;
    --bg-panel: #ffffff;
    --bg-input: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-light: #e2e8f0;
    --border-hover: #cbd5e1;
    --brand-primary: #0f172a;
    --brand-fg: #ffffff;
    --msg-user: #f1f5f9;
    --msg-ai: transparent;
    --error: #ef4444;
    --success: #10b981;
    
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-float: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
}

[data-theme="dark"] {
    --bg-app: #0f172a; /* Slate 900 */
    --bg-panel: #1e293b; /* Slate 800 */
    --bg-input: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-light: #334155;
    --border-hover: #475569;
    --brand-primary: #ffffff;
    --brand-fg: #0f172a;
    --msg-user: #334155;
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4);
    --shadow-float: 0 10px 15px -3px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', -apple-system, sans-serif; }
html, body { height: 100dvh; width: 100vw; overflow: hidden; background: var(--bg-app); color: var(--text-primary); transition: background 0.3s; }

/* === CUSTOM SCROLLBAR === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* === UTILITAS & ANIMASI === */
.fade-in { animation: fadeIn 0.4s ease-out forwards; }
.slide-up { animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* === SPLASH SCREEN === */
.splash-screen { position: fixed; inset: 0; background: var(--bg-app); z-index: 99999; display: flex; flex-direction: column; justify-content: center; align-items: center; transition: 0.4s; }
.splash-logo { width: 80px; height: 80px; margin-bottom: 25px; animation: fadeIn 1s ease-out; border-radius: 20%; font-size: 1.5rem; font-weight: bold; display: flex; align-items: center; justify-content: center; background: var(--brand-primary); color: var(--brand-fg);}
.splash-loader { width: 150px; height: 3px; background: var(--border-light); border-radius: 3px; overflow: hidden; position: relative; }
.splash-loader::after { content: ''; position: absolute; left: -50px; width: 50px; height: 100%; background: var(--brand-primary); animation: loadingBar 1s ease-in-out infinite; }
@keyframes loadingBar { 0% { left: -50px; width: 30%; } 50% { width: 50%; } 100% { left: 100%; width: 30%; } }

/* === TOAST === */
.toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 100000; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { background: var(--bg-panel); color: var(--text-primary); padding: 12px 20px; border-radius: var(--radius-full); box-shadow: var(--shadow-float); font-size: 0.85rem; font-weight: 500; display: flex; align-items: center; border: 1px solid var(--border-light); animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes slideDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
.toast-out { animation: fadeOut 0.3s forwards; }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-10px); } }

/* === AUTENTIKASI UI === */
.auth-container { display: flex; justify-content: center; align-items: center; height: 100dvh; padding: 20px; background: var(--bg-app); }
.auth-box { background: var(--bg-panel); padding: 40px; border-radius: var(--radius-lg); width: 100%; max-width: 400px; box-shadow: var(--shadow-md); border: 1px solid var(--border-light); }
.brand-header { text-align: center; margin-bottom: 30px; }
.brand-header h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.5px; }
.brand-header p { color: var(--text-secondary); font-size: 0.9rem; margin-top: 5px; }

/* TAB AUTENTIKASI MODERN */
.auth-tabs { display: flex; background: var(--bg-app); border-radius: var(--radius-md); padding: 4px; margin-bottom: 25px; border: 1px solid var(--border-light); }
.auth-tab { flex: 1; padding: 10px; border: none; background: transparent; color: var(--text-secondary); font-weight: 600; font-size: 0.9rem; border-radius: var(--radius-sm); cursor: pointer; transition: 0.3s; }
.auth-tab.active { background: var(--bg-panel); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.auth-form-content { animation: fadeIn 0.3s ease; }

.input-group { margin-bottom: 15px; }
.input-field, .auth-box input { width: 100%; padding: 12px 14px; border-radius: var(--radius-md); border: 1px solid var(--border-light); background: var(--bg-app); color: var(--text-primary); font-size: 16px !important; transition: 0.2s; outline: none; }
.input-field:focus, .auth-box input:focus { border-color: var(--brand-primary); }
.otp-input { text-align: center; font-size: 1.5rem !important; letter-spacing: 12px; font-weight: 600; }

.btn-primary { width: 100%; padding: 12px; background: var(--brand-primary); color: var(--brand-fg); border: none; border-radius: var(--radius-md); font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: 0.2s; display: flex; justify-content: center; align-items: center; }
.btn-primary:hover:not(:disabled) { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-outline { width: 100%; padding: 10px 12px; background: transparent; color: var(--text-primary); border: 1px solid var(--border-light); border-radius: var(--radius-md); font-size: 0.9rem; font-weight: 500; cursor: pointer; transition: 0.2s; display: flex; justify-content: center; align-items: center; gap: 8px; }
.btn-outline:hover { background: var(--bg-app); }
.btn-danger { width: 100%; padding: 10px; background: rgba(239, 68, 68, 0.1); color: var(--error); border: 1px solid rgba(239, 68, 68, 0.3); border-radius: var(--radius-md); font-weight: 600; cursor: pointer; transition: 0.2s; }
.btn-danger:hover { background: var(--error); color: white; }

/* === APP LAYOUT & SIDEBAR === */
.app-layout { display: flex; height: 100dvh; width: 100vw; overflow: hidden; }

.sidebar { width: 260px; background: var(--bg-app); border-right: 1px solid var(--border-light); display: flex; flex-direction: column; z-index: 10000; flex-shrink: 0; transition: transform 0.3s ease; }
.sidebar-header { padding: 20px; display: flex; justify-content: space-between; align-items: center; }
.sidebar-header h2 { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.5px; }
.new-chat-btn { margin: 0 15px; width: calc(100% - 30px); justify-content: flex-start; padding: 10px 15px; background: var(--bg-panel); font-weight: 600; }

.history-menu { flex: 1; overflow-y: auto; padding: 20px 15px; }
.history-menu label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 600; margin-bottom: 10px; display: block; padding-left: 5px; }
.conversation-list { display: flex; flex-direction: column; gap: 4px; }
.history-item { padding: 10px 12px; border-radius: var(--radius-md); font-size: 0.85rem; color: var(--text-primary); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: 0.2s; display: flex; align-items: center; }
.history-item::before { content: ''; width: 14px; height: 14px; margin-right: 10px; display: inline-block; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'/%3E%3C/svg%3E"); background-size: cover; opacity: 0.7; flex-shrink: 0; }
.history-item:hover { background: var(--border-light); }
.history-item.active { background: var(--border-light); font-weight: 600; }

.sidebar-footer { padding: 15px; border-top: 1px solid var(--border-light); }
.footer-actions { display: flex; gap: 10px; margin-bottom: 15px; }
.icon-text-btn { flex: 1; padding: 8px; background: transparent; border: 1px solid var(--border-light); border-radius: var(--radius-md); color: var(--text-secondary); font-size: 0.8rem; font-weight: 500; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: 0.2s; }
.icon-text-btn:hover { background: var(--border-light); color: var(--text-primary); }
.danger-hover:hover { background: rgba(239,68,68,0.1); color: var(--error); border-color: rgba(239,68,68,0.2); }
.account-profile { display: flex; align-items: center; gap: 12px; padding: 8px 5px; }
.avatar { width: 32px; height: 32px; background: var(--brand-primary); color: var(--brand-fg); border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 0.85rem; font-weight: 600; }
.email-text { font-size: 0.85rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; display: flex; transition: 0.2s; font-size: 1.2rem; }
.icon-btn:hover { color: var(--text-primary); }
.close-sidebar-btn { display: none; }

/* === CHAT AREA === */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg-panel); height: 100dvh; position: relative; }
.mobile-header { display: none; }

.chat-wrapper { flex: 1; overflow-y: auto; padding: 40px 20px; scroll-behavior: smooth; }
.chat-box { max-width: 768px; margin: 0 auto; display: flex; flex-direction: column; gap: 30px; padding-bottom: 80px; }

/* Pesan ChatGPT/Claude Style */
.message { display: flex; flex-direction: column; gap: 8px; animation: fadeIn 0.3s ease-out; }
.user-message { align-items: flex-end; }
.user-message .text { background: var(--msg-user); color: var(--text-primary); padding: 12px 18px; border-radius: 18px 18px 4px 18px; max-width: 85%; font-size: 0.95rem; line-height: 1.6; word-wrap: break-word; }
.ai-message { align-items: flex-start; }
.ai-message .text { background: transparent; color: var(--text-primary); width: 100%; font-size: 0.95rem; line-height: 1.7; word-wrap: break-word; }

/* === MARKDOWN & CODE FORMATTING (Highlight.js Support) === */
.ai-message .text p { margin-bottom: 16px; }
.ai-message .text p:last-child { margin-bottom: 0; }
.ai-message .text strong { font-weight: 600; color: var(--text-primary); }
.ai-message .text ul, .ai-message .text ol { margin-left: 20px; margin-bottom: 16px; }
.ai-message .text li { margin-bottom: 6px; }

/* Code Blocks Styling */
.ai-message .text pre { 
    background: transparent; 
    border-radius: var(--radius-md); 
    overflow: hidden; 
    border: 1px solid var(--border-light); 
    margin: 16px 0; 
}
.ai-message .text pre code.hljs { 
    padding: 16px; 
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; 
    font-size: 0.85rem; 
    line-height: 1.5;
    overflow-x: auto;
}
/* Inline Code Styling */
.ai-message .text p code, .ai-message .text li code { 
    background: var(--bg-app); 
    padding: 2px 6px; 
    border-radius: 4px; 
    font-family: monospace; 
    font-size: 0.85rem; 
    color: var(--brand-primary);
    border: 1px solid var(--border-light); 
}

/* === INPUT AREA === */
.input-container { position: absolute; bottom: 0; left: 0; width: 100%; padding: 0 20px max(20px, env(safe-area-inset-bottom)); background: linear-gradient(180deg, transparent, var(--bg-panel) 40%); z-index: 10; display: flex; flex-direction: column; align-items: center; pointer-events: none; }
.input-box { pointer-events: auto; max-width: 768px; width: 100%; display: flex; background: var(--bg-input); border: 1px solid var(--border-light); border-radius: 24px; padding: 8px 10px 8px 20px; align-items: center; box-shadow: var(--shadow-md); transition: 0.2s; }
.input-box:focus-within { border-color: var(--brand-primary); box-shadow: var(--shadow-float); }
#user-input { flex: 1; border: none; background: transparent; color: var(--text-primary); font-size: 16px !important; outline: none; }
#send-btn { background: var(--brand-primary); color: var(--brand-fg); border: none; width: 36px; height: 36px; border-radius: 50%; display: flex; justify-content: center; align-items: center; cursor: pointer; transition: 0.2s; font-size: 1rem; }
#send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* === MODAL PENGATURAN === */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); z-index: 999999; display: flex; justify-content: center; align-items: center; padding: 20px; }
.modal-box { background: var(--bg-panel); width: 100%; max-width: 500px; border-radius: var(--radius-lg); box-shadow: var(--shadow-float); border: 1px solid var(--border-light); max-height: 90dvh; display: flex; flex-direction: column; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 25px; border-bottom: 1px solid var(--border-light); }
.modal-header h2 { font-size: 1.1rem; font-weight: 600; }
.modal-body { overflow-y: auto; padding: 25px; }
.form-section { margin-bottom: 25px; padding-bottom: 25px; border-bottom: 1px solid var(--border-light); }
.form-section h3 { font-size: 0.9rem; font-weight: 600; margin-bottom: 15px; color: var(--text-primary); }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 8px; }
.form-row { display: flex; gap: 15px; }

/* BAR PENYIMPANAN DATA */
.storage-bar-container { width: 100%; height: 8px; background: var(--border-light); border-radius: 4px; overflow: hidden; margin-bottom: 10px; }
.storage-bar-fill { height: 100%; background: var(--brand-primary); width: 0%; transition: width 1s ease-out; }
.storage-bar-fill.warning { background: var(--error); }
.storage-text { font-size: 0.8rem; color: var(--text-secondary); font-weight: 500; }

/* === ANIMASI MENGETIK (PROFESIONAL) === */
.typing-indicator { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.typing-dot { width: 6px; height: 6px; background: var(--text-secondary); border-radius: 50%; animation: typingFade 1.4s infinite ease-in-out both; }
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typingFade { 0%, 80%, 100% { transform: scale(0); opacity: 0.3; } 40% { transform: scale(1); opacity: 1; } }

/* === RESPONSIVE MOBILE === */
.sidebar-overlay { display: none; }
@media screen and (max-width: 768px) {
    .mobile-header { display: flex; justify-content: space-between; align-items: center; padding: 0 20px; background: rgba(255,255,255,0.85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border-light); height: 60px; flex-shrink: 0; position: sticky; top: 0; z-index: 50; }
    [data-theme="dark"] .mobile-header { background: rgba(30,41,59,0.85); }
    .mobile-title { font-size: 1.1rem; font-weight: 700; }
    
    .chat-wrapper { padding: 20px 15px; padding-bottom: 120px; } 
    .input-container { padding: 15px; background: var(--bg-panel); border-top: 1px solid var(--border-light); pointer-events: auto; }
    
    .sidebar { position: fixed; top: 0; left: 0; height: 100dvh; width: 85vw; max-width: 320px; transform: translateX(-100%); z-index: 100000; }
    .sidebar.open { transform: translateX(0); }
    .close-sidebar-btn { display: flex; font-size: 1.2rem; }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99999; opacity: 0; transition: opacity 0.3s; }
    .sidebar-overlay.open { display: block; opacity: 1; }
    
    .form-row { flex-direction: column; gap: 0; }
}
