* { margin: 0; padding: 0; box-sizing: border-box; }

/* Login Overlay */
.login-overlay {
    display: flex;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.login-box {
    background: white;
    border-radius: 16px;
    padding: 32px;
    width: 360px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-header {
    text-align: center;
    margin-bottom: 24px;
}

.login-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #2563eb;
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 12px;
}

.login-header h2 { font-size: 20px; color: #1e293b; }
.login-header p { font-size: 13px; color: #64748b; margin-top: 4px; }

#loginForm input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.2s;
}

#loginForm input:focus { border-color: #2563eb; }

#loginForm button {
    width: 100%;
    padding: 11px;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

#loginForm button:hover { background: #1d4ed8; }
#loginForm button:disabled { opacity: 0.6; cursor: not-allowed; }

.login-error {
    color: #ef4444;
    font-size: 13px;
    min-height: 20px;
    margin-bottom: 8px;
}

.login-skip {
    display: block;
    width: 100%;
    margin-top: 12px;
    background: none;
    border: none;
    color: #64748b;
    font-size: 13px;
    cursor: pointer;
    padding: 8px;
}

.login-skip:hover { color: #2563eb; text-decoration: underline; }

/* User info in header */
.user-info {
    color: rgba(255,255,255,0.9);
    font-size: 13px;
    font-weight: 500;
    padding: 4px 10px;
    background: rgba(255,255,255,0.15);
    border-radius: 12px;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f1f5f9;
    --chat-bg: #ffffff;
    --user-msg: #2563eb;
    --bot-msg: #f1f5f9;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.chat-header {
    background: var(--primary);
    color: white;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
    z-index: 10;
}

.chat-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.chat-header .info h2 {
    font-size: 16px;
    font-weight: 600;
}

.chat-header .info p {
    font-size: 12px;
    opacity: 0.85;
}

.chat-header .actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.chat-header .actions button {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.chat-header .actions button:hover {
    background: rgba(255,255,255,0.3);
}

/* Messages Container */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

/* Bubble wrapper + delete button */
.message .bubble-wrap {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 4px;
}

.msg-delete-btn {
    display: none;
    position: absolute;
    top: -6px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 14px;
    line-height: 18px;
    text-align: center;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
    z-index: 2;
}

.message.bot .msg-delete-btn { right: -8px; }
.message.user .msg-delete-btn { left: -8px; }

.msg-delete-btn:hover { opacity: 1; }

.message:hover .msg-delete-btn { display: block; }

.message .bubble {
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
    word-break: break-word;
}

.message.user .bubble {
    background: var(--user-msg);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.bot .bubble {
    background: var(--chat-bg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

/* Debug Panel */
.debug-panel {
    background: #fffbeb;
    border: 1px solid #f59e0b;
    border-radius: 12px;
    overflow: hidden;
    font-size: 13px;
    max-width: 100%;
}

.debug-header {
    background: #fef3c7;
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #92400e;
    user-select: none;
}

.debug-header:hover { background: #fde68a; }

.debug-toggle {
    margin-left: auto;
    font-size: 10px;
    transition: transform 0.2s;
}

.debug-panel.collapsed .debug-body { display: none; }
.debug-panel.collapsed .debug-toggle { transform: rotate(-90deg); }

.debug-body { padding: 8px 12px; }

.debug-section { margin-bottom: 8px; }
.debug-section:last-child { margin-bottom: 0; }

.debug-label {
    font-weight: 600;
    font-size: 11px;
    color: #b45309;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.debug-panel pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 11px;
    line-height: 1.4;
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.debug-msg { max-width: 90%; }

.message .bot-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

/* Tool indicator */
.tool-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #fef3c7;
    color: #92400e;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    margin-bottom: 6px;
}

/* Typing indicator */
.typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: var(--chat-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.typing-indicator.show { display: flex; gap: 4px; align-items: center; }

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--text-light);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Input Area */
.chat-input {
    padding: 12px 20px;
    background: var(--chat-bg);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input textarea {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input textarea:focus {
    border-color: var(--primary);
}

.chat-input button {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.chat-input button:hover { background: var(--primary-dark); }
.chat-input button:disabled { opacity: 0.5; cursor: not-allowed; }

.location-toggle-btn {
    background: #f1f5f9;
    color: #64748b;
    font-size: 16px;
    border: 1px solid var(--border);
    transition: background 0.2s, color 0.2s;
}
.location-toggle-btn:hover { background: #e2e8f0; color: #334155; }
.location-toggle-btn.active { background: #dcfce7; color: #16a34a; border-color: #86efac; }

.location-status {
    font-size: 11px;
    color: #16a34a;
    padding: 2px 20px 4px;
    background: #f0fdf4;
    cursor: pointer;
    border-top: 1px solid #bbf7d0;
}
.location-status:hover { text-decoration: underline; }

/* Quick Actions */
.quick-actions {
    padding: 8px 20px 0;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.quick-actions button {
    background: var(--chat-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}

.quick-actions button:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Welcome */
.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

.welcome-message h3 { color: var(--text); margin-bottom: 8px; font-size: 18px; }
.welcome-message p { font-size: 14px; }

/* Markdown in messages */
.bubble table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 13px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.bubble th { background: var(--bg); font-weight: 600; }
.bubble code { background: #f1f5f9; padding: 1px 4px; border-radius: 3px; font-size: 13px; }
.bubble pre { background: #1e293b; color: #e2e8f0; padding: 10px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }
.bubble pre code { background: none; color: inherit; }
.bubble ul, .bubble ol { padding-left: 20px; margin: 4px 0; }
.bubble strong { font-weight: 600; }
.bubble a { color: #2563eb; text-decoration: underline; pointer-events: auto; cursor: pointer; }
.bubble a:hover { color: #1d4ed8; }

/* Nút hỏi thêm về sản phẩm */
.ask-product-btn {
    display: inline-flex;
    align-items: center;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    padding: 1px 6px;
    font-size: 12px;
    cursor: pointer;
    color: #2563eb;
    vertical-align: middle;
    transition: background 0.15s;
}
.ask-product-btn:hover { background: #dbeafe; }

/* Scrollbar */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* Responsive */
@media (max-width: 600px) {
    .message { max-width: 95%; }
    .chat-header .actions button span.label { display: none; }
}
