        :root {
            --primary: #38b6ff;
            --primary-dark: #2da1e6;
            --secondary: #e3b93d;
            --bg-dark: #0f172a;
            --bg-card: #1e293b;
            --bg-input: #334155;
            --text-primary: #f1f5f9;
            --text-secondary: #94a3b8;
            --text-muted: #64748b;
            --border-color: #334155;
            --user-msg-bg: linear-gradient(135deg, #38b6ff, #0ea5e9);
            --bot-msg-bg: #1e293b;
            --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
            --shadow-lg: 0 10px 40px rgba(0,0,0,0.4);
            --header-bg: rgba(15, 23, 42, 0.98);
            --header-bg-end: rgba(15, 23, 42, 0.95);
        }

        /* Light Mode */
        [data-theme="light"] {
            --bg-dark: #f8fafc;
            --bg-card: #ffffff;
            --bg-input: #e2e8f0;
            --text-primary: #1e293b;
            --text-secondary: #475569;
            --text-muted: #64748b;
            --border-color: #cbd5e1;
            --bot-msg-bg: #ffffff;
            --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
            --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);
            --header-bg: rgba(248, 250, 252, 0.98);
            --header-bg-end: rgba(248, 250, 252, 0.95);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html, body {
            height: 100%;
            overflow: hidden;
            position: fixed;
            width: 100%;
        }

        body {
            font-family: 'Prompt', sans-serif;
            background: var(--bg-dark);
            color: var(--text-primary);
            display: flex;
            flex-direction: column;
        }
        
        /* ป้องกัน SweetAlert2 ทำให้หน้าเว็บเลื่อน */
        body.swal2-height-auto {
            height: 100% !important;
        }

        /* HEADER */
        .header {
            background: linear-gradient(180deg, var(--header-bg) 0%, var(--header-bg-end) 100%);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            padding: 10px 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid var(--border-color);
            position: relative;
            z-index: 100;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .back-btn {
            width: 40px;
            height: 40px;
            border-radius: 12px;
            background: var(--bg-card);
            border: 0px solid var(--border-color);
            color: var(--text-secondary);
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.2s;
            text-decoration: none;
        }

        .back-btn:hover {
            background: var(--bg-input);
            color: var(--text-primary);
            transform: translateX(-2px);
        }

        .logo-section {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .logo-icon {
            width: 44px;
            height: 44px;
            border-radius: 14px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
            box-shadow: var(--shadow-sm);
        }

        .logo-text h1 {
            font-size: 1.1rem;
            font-weight: 600;
            color: var(--text-primary);
            line-height: 1.2;
        }

        .logo-text span {
            font-size: 0.75rem;
            color: var(--text-muted);
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .logo-text span i {
            color: #22c55e;
            font-size: 0.5rem;
        }

        .header-right {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        /* Social Menu */
        .social-menu {
            position: relative;
        }

        .social-toggle {
            width: 38px;
            height: 38px;
            border-radius: 10px;
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            color: var(--text-secondary);
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.2s;
            font-size: 1rem;
        }

        .social-toggle:hover {
            background: var(--bg-input);
            color: var(--primary);
            transform: scale(1.05);
        }

        .social-dropdown {
            position: absolute;
            top: calc(100% + 8px);
            right: 0;
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            border-radius: 12px;
            padding: 6px;
            display: flex;
            flex-direction: column;
            gap: 6px;
            opacity: 0;
            visibility: hidden;
            transform: translateY(-10px);
            transition: all 0.3s ease;
            box-shadow: var(--shadow-lg);
            z-index: 1000;
        }

        .social-menu:hover .social-dropdown {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }

        .social-btn {
            width: 38px;
            height: 38px;
            border-radius: 10px;
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            color: var(--text-secondary);
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.2s;
            text-decoration: none;
            font-size: 1rem;
        }

        .social-btn:hover {
            background: var(--bg-input);
            transform: translateX(-3px);
        }

        .social-btn.ig:hover { color: #e4405f; border-color: #e4405f; }
        .social-btn.tt:hover { color: #00f2ea; border-color: #00f2ea; }
        .social-btn.yt:hover { color: #ff0000; border-color: #ff0000; }

        /* Theme Toggle */
        .theme-toggle {
            width: 38px;
            height: 38px;
            border-radius: 10px;
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            color: var(--text-secondary);
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.3s ease;
            font-size: 1rem;
            position: relative;
            overflow: hidden;
        }

        .theme-toggle:hover {
            background: var(--bg-input);
            transform: rotate(15deg);
        }

        .theme-toggle i {
            transition: all 0.3s ease;
        }

        .theme-toggle .fa-sun {
            color: var(--secondary);
        }

        .theme-toggle .fa-moon {
            color: var(--primary);
        }

        /* Theme transition */
        body, .header, .chat-container, .input-container, .welcome-card, .msg-content, .input-wrapper {
            transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
        }

        /* CHAT CONTAINER */
        .chat-container {
            flex: 1;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            position: relative;
        }

        /* CHAT MESSAGES */
        #chat-box {
            flex: 1;
            overflow-y: auto;
            padding: 15px 8px;
            display: flex;
            flex-direction: column;
            gap: 16px;
            scroll-behavior: smooth;
        }

        @media (min-width: 768px) {
            #chat-box {
                padding: 13px;
                max-width: 900px;
                margin: 0 auto;
                width: 100%;
            }
        }

        .message {
            max-width: 85%;
            animation: slideIn 0.3s ease;
        }

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

        /* User Message */
        .user-message {
            align-self: flex-end;
        }

        .user-message .msg-content {
            background: var(--user-msg-bg);
            color: white;
            padding: 12px 18px;
            border-radius: 23px 23px 3px 23px;
            font-size: 0.9rem;
            line-height: 1.5;
            box-shadow: var(--shadow-sm);
        }

        /* Bot Message */
        .bot-message {
            align-self: flex-start;
            display: flex;
            gap: 12px;
            max-width: 90%;
        }

        .bot-avatar {
            width: 36px;
            height: 36px;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1rem;
            flex-shrink: 0;
            margin-top: 2px;
        }

        .bot-message .msg-wrapper {
            flex: 1;
        }

        .bot-message .msg-content {
            background: var(--bot-msg-bg);
            color: var(--text-primary);
            padding: 12px 18px;
            border-radius: 3px 23px 23px 23px;
            font-size: 0.93rem;
            line-height: 1.6;
            border: 1px solid var(--border-color);
        }

        /* Thought Toggle */
        .thought-toggle {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            background: transparent;
            color: var(--text-muted);
            border: 1px solid var(--border-color);
            padding: 6px 12px;
            border-radius: 8px;
            font-size: 0.75rem;
            cursor: pointer;
            margin-bottom: 3px;
            transition: all 0.2s;
        }

        .thought-toggle:hover {
            background: var(--bg-input);
            color: var(--text-secondary);
        }

        .thought-process {
            font-size: 0.8rem;
            color: var(--text-muted);
            background: rgba(56, 182, 255, 0.05);
            border-left: 3px solid var(--primary);
            padding: 0;
            margin-bottom: 10px;
            border-radius: 0 8px 8px 0;
            max-height: 0;
            overflow: hidden;
            transition: all 0.3s ease;
        }

        .thought-process.expanded {
            max-height: 300px;
            padding: 12px 14px;
        }

        /* SUGGESTION CHIPS */
        .suggestions {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-top: 16px;
        }

        .suggestion-chip {
            background: transparent;
            color: var(--primary);
            border: 1px solid var(--primary);
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 0.85rem;
            cursor: pointer;
            transition: all 0.25s ease;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            font-weight: 400;
        }

        .suggestion-chip:hover {
            background: var(--primary);
            color: white;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(56, 182, 255, 0.3);
        }

        .suggestion-chip i {
            font-size: 0.8rem;
            opacity: 0.8;
        }

        /* TYPING INDICATOR */
        .typing-indicator {
            display: flex;
            gap: 4px;
            padding: 4px 0;
        }

        .typing-indicator span {
            width: 8px;
            height: 8px;
            background: var(--text-muted);
            border-radius: 50%;
            animation: typing 1.4s infinite;
        }

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

        @keyframes typing {
            0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
            30% { transform: translateY(-8px); opacity: 1; }
        }

        /* INPUT AREA */
        .input-container {
            background: linear-gradient(180deg, transparent 0%, var(--bg-dark) 20%);
            padding: 8px 10px;
            padding-top: 12px;
        }

        /* Question Counter */
        .question-counter {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 2px;
            font-size: 0.6rem;
            color: var(--text-muted);
            padding: 2px 5px;
            background: var(--bg-input);
            border-radius: 10px;
            white-space: nowrap;
            transition: all 0.3s ease;
        }


        .question-counter #question-count {
            font-weight: 600;
            color: var(--primary);
        }

        .question-counter.warning {
            background: rgba(255, 193, 7, 0.15);
            color: #ffc107;
        }

        .question-counter.warning i,
        .question-counter.warning #question-count {
            color: #ffc107;
        }

        .question-counter.danger {
            background: rgba(220, 53, 69, 0.15);
            color: #dc3545;
        }

        .question-counter.danger i,
        .question-counter.danger #question-count {
            color: #dc3545;
        }

        @media (min-width: 768px) {
            .input-container {
                padding: 20px 32px 24px;
                max-width: 900px;
                margin: 0 auto;
                width: 100%;
            }
        }

        .input-wrapper {
            display: flex;
            gap: 8px;
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            border-radius: 16px;
            padding: 6px;
            transition: all 0.2s;
            align-items: center;
        }

        .input-wrapper:focus-within {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(56, 182, 255, 0.1);
        }

        #userInput {
            flex: 1;
            background: transparent;
            border: none;
            padding: 10px 8px;
            color: var(--text-primary);
            font-family: 'Prompt', sans-serif;
            font-size: 0.85rem;
            outline: none;
        }

        #userInput::placeholder {
            color: var(--text-muted);
        }

        #send-btn {
            width: 36px;
            height: 40px;
            background: var(--bg-input);
            border: none;
            border-radius: 12px;
            color: var(--text-muted);
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1rem;
            transition: all 0.2s;
        }

        #send-btn.has-text {
            background: var(--primary);
            color: white;
            cursor: pointer;
        }

        #send-btn.has-text:hover:not(:disabled) {
            background: var(--primary-dark);
            transform: scale(1.05);
        }

        #send-btn:disabled {
            background: var(--bg-input);
            color: var(--text-muted);
            cursor: not-allowed;
            opacity: 0.5;
        }

        /* Retry Button */
        .retry-btn {
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 8px;
            padding: 8px 16px;
            font-size: 0.85rem;
            font-family: 'Prompt', sans-serif;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            gap: 6px;
            margin-top: 8px;
            transition: all 0.2s;
        }

        .retry-btn:hover {
            background: var(--primary-dark);
            transform: translateY(-1px);
        }

        .retry-btn i {
            font-size: 0.9rem;
        }

        /* Footer Info */
        .footer-info {
            text-align: center;
            padding: 5px 5px 12px;
            color: var(--text-muted);
            font-size: 0.7rem;
            line-height: 1.5;
        }

        .footer-info a {
            color: var(--primary);
            text-decoration: none;
        }

        .footer-info a:hover {
            text-decoration: underline;
        }

        /* LOADING & ERROR STATES */
        .loading-bar {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 3px;
            background: var(--bg-card);
            overflow: hidden;
            z-index: 50;
        }

        .loading-bar::after {
            content: '';
            position: absolute;
            top: 0;
            left: -50%;
            width: 50%;
            height: 100%;
            background: linear-gradient(90deg, transparent, var(--primary), transparent);
            animation: loading 1.5s infinite;
        }

        @keyframes loading {
            0% { left: -50%; }
            100% { left: 100%; }
        }

        .loading-bar.hidden {
            display: none;
        }

        /* Error Message */
        .error-toast {
            position: fixed;
            top: 80px;
            left: 50%;
            transform: translateX(-50%);
            background: #dc2626;
            color: white;
            padding: 12px 20px;
            border-radius: 12px;
            font-size: 0.85rem;
            display: flex;
            align-items: center;
            gap: 10px;
            z-index: 200;
            box-shadow: var(--shadow-lg);
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s;
        }

        .error-toast.show {
            opacity: 1;
            visibility: visible;
        }

        /* WELCOME MESSAGE */
        .welcome-card {
            background: var(--bot-msg-bg);
            border: 1px solid var(--border-color);
            border-radius: 20px;
            padding: 24px;
            text-align: center;
            max-width: 500px;
            margin: 0 auto;
        }

        .welcome-icon {
            width: 120px;
            height: 120px;
            border-radius: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2rem;
            margin: 0 auto 20px;
        }

        .welcome-card h2 {
            font-size: 1.2rem;
            font-weight: 600;
            margin-bottom: 8px;
            color: var(--text-primary);
        }

        .welcome-card p {
            font-size: 0.9rem;
            color: var(--text-secondary);
            margin-bottom: 20px;
            line-height: 1.6;
        }

        .welcome-badge {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            background: linear-gradient(135deg, rgba(56, 182, 255, 0.15), rgba(227, 185, 61, 0.1));
            color: var(--primary);
            padding: 10px 20px;
            border-radius: 25px;
            font-size: 0.85rem;
            margin-bottom: 20px;
            border: 1px solid rgba(56, 182, 255, 0.2);
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .welcome-badge:hover {
            transform: scale(1.02);
            box-shadow: 0 4px 15px rgba(56, 182, 255, 0.2);
        }

        .welcome-badge i {
            color: var(--secondary);
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.5; }
        }

        /* SCROLLBAR */
        #chat-box::-webkit-scrollbar {
            width: 6px;
        }

        #chat-box::-webkit-scrollbar-track {
            background: transparent;
        }

        #chat-box::-webkit-scrollbar-thumb {
            background: var(--bg-input);
            border-radius: 3px;
        }

        #chat-box::-webkit-scrollbar-thumb:hover {
            background: var(--text-muted);
        }

        /* Message Text Formatting */
        .msg-paragraph {
            margin: 0 0 4px 0;
            line-height: 1.6;
        }

        .msg-paragraph:last-child {
            margin-bottom: 0;
        }

        .msg-paragraph:empty {
            display: none;
        }

        .answer-content br + br {
            display: block;
            content: '';
            margin-top: 4px;
        }

        .list-item {
            margin-left: 16px;
            margin-bottom: 4px;
            padding-left: 4px;
        }

        /* Chat Links */
        .chat-link {
            color: var(--primary);
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 2px 8px;
            background: rgba(56, 182, 255, 0.1);
            border-radius: 6px;
            font-size: 0.9em;
            transition: all 0.2s;
            word-break: break-all;
        }

        .chat-link:hover {
            background: var(--primary);
            color: white;
            text-decoration: none;
        }

        .chat-link i {
            font-size: 0.75em;
            opacity: 0.8;
        }

        .chat-link.ig-link {
            background: rgba(228, 64, 95, 0.1);
            color: #E4405F;
        }

        .chat-link.ig-link:hover {
            background: #E4405F;
            color: white;
        }

        [data-theme="light"] .chat-link {
            background: rgba(56, 182, 255, 0.15);
        }

        /* RESPONSIVE */
        @media (max-width: 480px) {
            .header {
                padding: 8px 12px;
            }

            .logo-icon {
                width: 38px;
                height: 38px;
                font-size: 1.2rem;
            }

            .logo-text h1 {
                font-size: 1rem;
            }

            .social-btn {
                width: 34px;
                height: 34px;
                font-size: 0.9rem;
            }

            .bot-avatar {
                width: 32px;
                height: 32px;
                font-size: 0.9rem;
            }

            .message {
                max-width: 90%;
            }

            .suggestion-chip {
                padding: 5px 11px;
                font-size: 0.8rem;
            }
            
            .welcome-icon {
                width: 100px;
                height: 100px;
            }
        }

        /* Model Badge in Response */
        .model-badge {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            margin-top: 12px;
            padding: 2px 6px;
            background: rgba(56, 182, 255, 0.08);
            border: 1px solid rgba(56, 182, 255, 0.15);
            border-radius: 12px;
            font-size: 0.6rem;
            color: var(--text-secondary);
            opacity: 0.7;
        }

        .model-badge i {
            color: var(--primary);
            font-size: 0.65rem;
        }

        /* Disclaimer Modal */
        .disclaimer-modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.85);
            backdrop-filter: blur(8px);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 9999;
            padding: 20px;
            opacity: 1;
            transition: opacity 0.3s ease;
        }

        .disclaimer-modal.hidden {
            opacity: 0;
            pointer-events: none;
        }

        .disclaimer-content {
            background: var(--bg-card);
            border-radius: 20px;
            padding: 24px;
            max-width: 600px;
            width: 100%;
            max-height: 90vh;
            overflow-y: auto;
            border: 1px solid var(--border-color);
            box-shadow: var(--shadow-lg);
            animation: slideUp 0.4s ease;
        }

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

        .disclaimer-icon {
            font-size: 3rem;
            text-align: center;
            margin-bottom: 16px;
        }

        .disclaimer-content h2 {
            text-align: center;
            color: var(--text-primary);
            font-size: 1.1rem;
            font-weight: 600;
            margin-bottom: 10px;
        }

        .disclaimer-intro {
            text-align: center;
            color: var(--text-secondary);
            font-size: 0.8rem;
            margin-bottom: 20px;
            line-height: 1.6;
        }

        .disclaimer-terms {
            display: flex;
            flex-direction: column;
            gap: 16px;
            margin-bottom: 28px;
        }

        .term-item {
            display: flex;
            gap: 14px;
            align-items: flex-start;
        }

        .term-number {
            flex-shrink: 0;
            width: 28px;
            height: 28px;
            background: linear-gradient(135deg, var(--primary), var(--primary-dark));
            color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.8rem;
            font-weight: 600;
        }

        .term-text {
            color: var(--text-secondary);
            font-size: 0.78rem;
            line-height: 1.6;
        }

        .term-text strong {
            color: var(--text-primary);
        }

        .accept-btn {
            width: 100%;
            padding: 12px 20px;
            background: linear-gradient(135deg, var(--primary), var(--primary-dark));
            color: white;
            border: none;
            border-radius: 12px;
            font-family: 'Prompt', sans-serif;
            font-size: 0.9rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        .accept-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(56, 182, 255, 0.35);
        }

        .accept-btn:active {
            transform: translateY(0);
        }

        @media (max-width: 480px) {
            .disclaimer-content {
                padding: 20px 16px;
            }

            .disclaimer-content h2 {
                font-size: 1rem;
            }

            .term-text {
                font-size: 0.75rem;
            }
            
            .welcome-icon {
                width: 100px;
                height: 100px;
            }
        }