/* css/ai-agent.css — style riêng cho trang AI Agent (chatbot Bát Tự).
   Bám palette soft-ui (--neu-*) để đồng bộ với index/battu. */

/* ── Gate (đăng nhập / nhập sinh / thiếu xu / bảo trì) ─────────────────── */
.agent-gate {
    text-align: center;
    padding: 2rem 1.5rem;
    max-width: 640px;
    margin: 0 auto;
}

.agent-gate .gate-icon {
    width: 68px;
    height: 68px;
    margin: 0 auto 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    line-height: 1;
    border-radius: 50%;
    background: var(--neu-accent-tint, #dde6f4);
}

.agent-gate h3 {
    margin: 0 0 0.5rem;
    color: var(--neu-text-strong, #2b3139);
}

.agent-gate .gate-desc {
    color: var(--neu-text, #3d4451);
    opacity: 0.85;
    margin-bottom: 1.25rem;
    line-height: 1.6;
}

.agent-gate .gate-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.agent-gate .btn-secondary {
    display: inline-block;
    padding: 12px 22px;
    border-radius: var(--neu-radius-sm, 14px);
    background: var(--neu-bg, #eef1f6);
    color: var(--neu-text-strong, #2b3139);
    text-decoration: none;
    font-weight: 600;
    box-shadow: var(--neu-raised-xs, 2px 2px 5px #ccd6e5, -2px -2px 5px #fff);
}

/* Nút chính của các gate. Trang này KHÔNG nạp battu-luan-giai.css (nơi định nghĩa
   .btn-primary) nên phải tự định nghĩa — thiếu là nút rơi về style mặc định
   của trình duyệt (xám, thô). */
.btn-primary {
    display: inline-block;
    border: none;
    cursor: pointer;
    background: var(--neu-accent, #4a6fa5);
    color: #fff;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.92rem;
    padding: 11px 22px;
    border-radius: 999px;
    box-shadow: 0 8px 16px -8px rgba(74, 111, 165, 0.75);
    transition: background 0.2s ease, transform 0.1s ease;
}

.btn-primary:hover {
    background: var(--neu-accent-dark, #3a5a8c);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.birth-form .btn-primary {
    width: 100%;
    margin-top: 4px;
}

.birth-form {
    text-align: left;
}

.birth-form .input-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.birth-form .form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--neu-text, #3d4451);
    margin-bottom: 6px;
}

.birth-form .form-group input,
.birth-form .form-group select {
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: var(--neu-radius-xs, 10px);
    background: var(--neu-surface-sunken, #e7ebf2);
    box-shadow: var(--neu-inset-xs, inset 2px 2px 4px rgba(204, 214, 229, .85), inset -2px -2px 4px rgba(255, 255, 255, .95));
    color: var(--neu-text-strong, #2b3139);
    font-size: 0.95rem;
    font-family: inherit;
}

.gate-error {
    color: #c0392b;
    background: rgba(192, 57, 43, 0.08);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

/* ── Khung chat ────────────────────────────────────────────────────────── */
.chat-card {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    max-width: 860px;
    margin: 0 auto;
}

.agent-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    margin-bottom: 10px;
}

.agent-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.agent-chip {
    background: var(--neu-accent-tint, #dde6f4);
    color: var(--neu-accent-dark, #3a5a8c);
    font-weight: 700;
    font-size: 0.85rem;
    padding: 4px 10px;
    border-radius: 999px;
}

.agent-birth {
    font-size: 0.8rem;
    color: var(--neu-text, #3d4451);
    opacity: 0.75;
}

.agent-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.agent-price {
    font-size: 0.75rem;
    color: var(--neu-text, #3d4451);
    opacity: 0.65;
}

.btn-mini {
    border: none;
    cursor: pointer;
    background: var(--neu-bg, #eef1f6);
    color: var(--neu-text-strong, #2b3139);
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    box-shadow: var(--neu-raised-xs, 2px 2px 5px #ccd6e5, -2px -2px 5px #fff);
}

.btn-mini:hover {
    color: var(--neu-accent-dark, #3a5a8c);
}

.chat-messages {
    height: min(56vh, 560px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 8px;
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0));
    scrollbar-width: thin;
    scrollbar-color: rgba(74, 111, 165, 0.35) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(74, 111, 165, 0.3);
    border-radius: 4px;
}

.ai-message {
    max-width: 80%;
    padding: 11px 15px;
    border-radius: 18px;
    line-height: 1.6;
    font-size: 0.95rem;
    word-break: break-word;
    color: var(--neu-text-strong, #2b3139);
}

.ai-message.assistant p:last-child,
.ai-message.assistant ul:last-child,
.ai-message.assistant ol:last-child {
    margin-bottom: 0;
}

.ai-message.user {
    align-self: flex-end;
    background: var(--neu-accent, #4a6fa5);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.ai-message.assistant {
    align-self: flex-start;
    background: var(--neu-surface-raised, #f2f5f9);
    box-shadow: var(--neu-raised-xs, 2px 2px 5px #ccd6e5, -2px -2px 5px #fff);
    border-bottom-left-radius: 6px;
}

.ai-message.assistant h1,
.ai-message.assistant h2,
.ai-message.assistant h3 {
    margin: 0.5rem 0 0.35rem;
    font-size: 1rem;
}

.ai-message.assistant p {
    margin: 0 0 0.45rem;
}

.ai-message.assistant ul,
.ai-message.assistant ol {
    margin: 0.25rem 0 0.5rem 1.1rem;
}

.ai-message.error {
    align-self: center;
    background: rgba(192, 57, 43, 0.08);
    color: #c0392b;
    font-size: 0.88rem;
    max-width: 96%;
    text-align: center;
}

.ai-cost {
    align-self: flex-start;
    font-size: 0.7rem;
    font-style: italic;
    color: var(--neu-text, #3d4451);
    opacity: 0.5;
    margin: -8px 0 0 10px;
    letter-spacing: 0.01em;
}

.typing-indicator {
    align-self: flex-start;
    display: inline-flex;
    gap: 5px;
    padding: 12px 16px;
    border-radius: 16px;
    background: var(--neu-surface-raised, #f2f5f9);
    box-shadow: var(--neu-raised-xs, 2px 2px 5px #ccd6e5, -2px -2px 5px #fff);
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--neu-accent, #4a6fa5);
    opacity: 0.4;
    animation: ai-typing 1.2s infinite ease-in-out;
}

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

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

/* ── Gợi ý sản phẩm: danh sách gọn, vừa trong khung chat ───────────────── */
.product-slot {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 12px;
    background: var(--neu-surface-sunken, #e7ebf2);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.product-slot-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.product-slot-title {
    font-weight: 700;
    font-size: 0.76rem;
    color: var(--neu-accent-dark, #3a5a8c);
}

.product-slot-close {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    color: var(--neu-text, #3d4451);
    opacity: 0.55;
    padding: 0 4px;
}

.product-slot-close:hover {
    opacity: 1;
}

.product-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 6px;
    margin-top: 6px;
}

.product-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 10px;
    background: var(--neu-surface-raised, #f2f5f9);
    box-shadow: var(--neu-raised-xs, 2px 2px 5px #ccd6e5, -2px -2px 5px #fff);
    min-width: 0;
}

.product-thumb {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--neu-bg, #eef1f6);
}

.product-thumb-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    opacity: 0.45;
}

.product-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.product-name {
    font-weight: 700;
    font-size: 0.78rem;
    line-height: 1.3;
    color: var(--neu-text-strong, #2b3139);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--neu-text, #3d4451);
    min-width: 0;
    overflow: hidden;
}

.product-price {
    font-weight: 800;
    color: #b03a2e;
    white-space: nowrap;
}

.product-rating {
    opacity: 0.65;
    white-space: nowrap;
}

.product-badges {
    display: inline-flex;
    gap: 3px;
    flex: 0 0 auto;
}

.product-badge {
    font-size: 0.62rem;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--neu-accent-tint, #dde6f4);
    color: var(--neu-accent-dark, #3a5a8c);
    font-weight: 600;
}

.product-reason {
    font-size: 0.68rem;
    color: var(--neu-accent-dark, #3a5a8c);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-disclaimer {
    font-size: 0.62rem;
    font-style: italic;
    color: var(--neu-text, #3d4451);
    opacity: 0.65;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 0 0 auto;
}

.product-btn-primary,
.product-btn-ghost {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0;
}

.product-btn-primary {
    background: var(--neu-accent, #4a6fa5);
    color: #fff;
}

.product-btn-primary:hover {
    background: var(--neu-accent-dark, #3a5a8c);
}

.product-btn-ghost {
    background: transparent;
    color: var(--neu-text, #3d4451);
    opacity: 0.6;
}

.product-btn-ghost:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
}

@media (max-width: 520px) {
    .product-list {
        grid-template-columns: 1fr;
    }
}

.chat-input-area {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.chat-input-area input {
    flex: 1;
    padding: 12px 14px;
    border: none;
    border-radius: 999px;
    background: var(--neu-surface-sunken, #e7ebf2);
    box-shadow: var(--neu-inset-xs, inset 2px 2px 4px rgba(204, 214, 229, .85), inset -2px -2px 4px rgba(255, 255, 255, .95));
    color: var(--neu-text-strong, #2b3139);
    font-size: 0.95rem;
    font-family: inherit;
}

.btn-send {
    border: none;
    cursor: pointer;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--neu-accent, #4a6fa5);
    color: #fff;
    font-size: 1.1rem;
    flex: 0 0 auto;
}

.btn-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-send:hover:not(:disabled) {
    background: var(--neu-accent-dark, #3a5a8c);
}

.chat-input-area input:focus {
    outline: 2px solid rgba(74, 111, 165, 0.35);
    outline-offset: 1px;
}

/* ── Toast ─────────────────────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    right: 16px;
    bottom: 84px;
    z-index: 10050;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.agent-toast {
    background: #2b3139;
    color: #fff;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 0.88rem;
    max-width: 320px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.agent-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.agent-toast.success { background: #1e7e46; }
.agent-toast.error { background: #b03a2e; }
.agent-toast.info { background: #2b3139; }

@media (max-width: 640px) {
    .agent-bar {
        align-items: flex-start;
    }

    .chat-messages {
        height: 52vh;
    }

    .ai-message {
        max-width: 92%;
    }
}

/* ── Header gọn: 1 hàng, số dư + nút nhỏ (đè style .header mặc định) ─────── */
.main-layout .agent-header {
    display: flex;
    align-items: center;
    padding: 6px 14px;
    text-align: left;
}

.agent-header .header-tools {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.agent-header .balance-chip {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--neu-accent-dark, #3a5a8c);
    background: var(--neu-accent-tint, #dde6f4);
    padding: 3px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.agent-header .btn-compact {
    padding: 4px 12px;
    font-size: 0.76rem;
    line-height: 1.4;
    border-radius: 999px;
    min-height: 0;
    min-width: 0;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .main-layout .agent-header {
        /* Chừa chỗ cho nút ☰ absolute của mobile */
        padding: 5px 10px 5px 52px;
    }

    .agent-header .btn-compact {
        padding: 3px 10px;
        font-size: 0.72rem;
    }

    .agent-header .balance-chip {
        font-size: 0.7rem;
        padding: 2px 8px;
    }
}
