/*
|--------------------------------------------------------------------------
| MANSION AI – Luxury UI
| MANSION.VN
|--------------------------------------------------------------------------
*/

:root {
    --mansion-gold: #D4AF37;
    --mansion-gold-soft: #e8c96a;
    --mansion-gold-dim: rgba(212, 175, 55, 0.22);
    --mansion-black: #0a0a0a;
    --mansion-dark: #121212;
    --mansion-panel: #161616;
    --mansion-border: rgba(212, 175, 55, 0.18);
    --mansion-text: #f5f5f5;
    --mansion-muted: #9a9a9a;
    --mansion-shadow: 0 28px 70px rgba(0, 0, 0, 0.55);
}

#mansion {
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ========== Floating launcher ========== */

/*
 * v2.9.10-ai-os — Premium AI launcher.
 * Vòng tròn vàng cũ (border: 2px solid var(--mansion-gold)) đã được BỎ.
 * Nền: kính mờ tối + quầng sáng xanh/tím rất nhẹ, không neon, không nhấp nháy.
 * Logo hiển thị ĐẦY ĐỦ (object-fit: contain), không còn bị cắt tròn.
 */
#mansion-toggle {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 58px;
    height: 58px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background:
        radial-gradient(120% 120% at 30% 18%, rgba(96, 165, 250, 0.16) 0%, rgba(96, 165, 250, 0) 58%),
        radial-gradient(130% 130% at 78% 86%, rgba(167, 139, 250, 0.16) 0%, rgba(167, 139, 250, 0) 62%),
        linear-gradient(160deg, rgba(23, 27, 36, 0.92) 0%, rgba(10, 11, 15, 0.94) 100%);
    -webkit-backdrop-filter: blur(14px) saturate(130%);
    backdrop-filter: blur(14px) saturate(130%);
    box-shadow:
        0 14px 34px rgba(0, 0, 0, 0.50),
        0 0 22px rgba(56, 189, 248, 0.13),
        0 0 40px rgba(139, 92, 246, 0.09),
        inset 0 1px 0 rgba(255, 255, 255, 0.07);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 999999;
    transition: transform 0.28s ease, box-shadow 0.28s ease, border-color 0.28s ease;
    overflow: visible;
    padding: 9px;
    box-sizing: border-box;
}

#mansion-toggle:hover {
    transform: translateY(-3px);
    border-color: rgba(125, 211, 252, 0.26);
    box-shadow:
        0 18px 40px rgba(0, 0, 0, 0.58),
        0 0 28px rgba(56, 189, 248, 0.20),
        0 0 52px rgba(139, 92, 246, 0.13),
        inset 0 1px 0 rgba(255, 255, 255, 0.09);
}

/* Keyboard focus: rõ ràng nhưng tinh tế. Trước 2.9.10 không có focus style nào. */
#mansion-toggle:focus-visible {
    outline: none;
    border-color: rgba(125, 211, 252, 0.60);
    box-shadow:
        0 0 0 3px rgba(56, 189, 248, 0.34),
        0 14px 34px rgba(0, 0, 0, 0.50),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/*
 * Logo giữ nguyên 100%: không filter, không đổi màu, không crop.
 * contain + không bo tròn ảnh → thấy trọn artwork gốc kể cả khi không vuông.
 */
#mansion-toggle img {
    width: 100%;
    height: 100%;
    border-radius: 0;
    object-fit: contain;
    object-position: center;
    background: transparent;
    padding: 0;
    display: block;
    filter: none;
    mix-blend-mode: normal;
}

#mansion-toggle span {
    display: none;
}

/* Online pulse */
#mansion-toggle .mansion-pulse {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 8px;
    height: 8px;
    background: #3ddc84;
    border-radius: 50%;
    border: 1.5px solid rgba(12, 14, 19, 0.92);
    box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.5);
    animation: mansion-pulse 2s infinite;
}

@keyframes mansion-pulse {
    0% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.45); }
    70% { box-shadow: 0 0 0 8px rgba(61, 220, 132, 0); }
    100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); }
}

/* Tôn trọng người dùng tắt hiệu ứng chuyển động (WCAG 2.3.3). */
@media (prefers-reduced-motion: reduce) {
    #mansion-toggle,
    #mansion-toggle:hover {
        transition: none;
        transform: none;
    }
    #mansion-toggle .mansion-pulse {
        animation: none;
    }
}

/* ========== Chat window ========== */

#mansion-window {
    position: fixed;
    right: 22px;
    bottom: 90px;
    width: 380px;
    height: 580px;
    max-height: calc(100vh - 110px);
    background: linear-gradient(165deg, #1a1a1a 0%, #0d0d0d 45%, #0a0a0a 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--mansion-border);
    border-radius: 20px;
    overflow: hidden;
    display: none;
    flex-direction: column;
    z-index: 999999;
    box-shadow: var(--mansion-shadow);
}

#mansion-window::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--mansion-gold), transparent);
    opacity: 0.85;
    z-index: 2;
    pointer-events: none;
}

/* Header */

.mansion-header {
    padding: 12px 14px;
    background: linear-gradient(180deg, #1c1c1c 0%, #141414 100%);
    border-bottom: 1px solid rgba(212, 175, 55, 0.12);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 1;
}

.mansion-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mansion-user .mansion-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.mansion-user img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1.5px solid var(--mansion-gold);
    object-fit: cover;
    object-position: center;
    background: transparent;
    padding: 0;
    display: block;
}

.mansion-user .mansion-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #3ddc84;
    border-radius: 50%;
    border: 2px solid #141414;
}

.mansion-user h3 {
    margin: 0 0 2px;
    color: #fff;
    font-size: 15px;
    font-weight: 650;
    letter-spacing: 0.04em;
}

.mansion-user small {
    color: var(--mansion-gold);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: 500;
}

#mansion-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #ccc;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: 0.25s;
}

#mansion-close:hover {
    background: rgba(212, 175, 55, 0.15);
    color: var(--mansion-gold);
    border-color: rgba(212, 175, 55, 0.35);
}

/* Body */

#mansion-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px 12px;
    scroll-behavior: smooth;
}

#mansion-body::-webkit-scrollbar {
    width: 5px;
}
#mansion-body::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.35);
    border-radius: 10px;
}

.mansion-message {
    max-width: 88%;
    padding: 13px 16px;
    border-radius: 16px;
    line-height: 1.65;
    margin-bottom: 12px;
    font-size: 14px;
    word-wrap: break-word;
}

.mansion-message.ben {
    background: linear-gradient(145deg, #222 0%, #1a1a1a 100%);
    color: var(--mansion-text);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-bottom-left-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.mansion-message.ben strong {
    color: var(--mansion-gold-soft);
}

.mansion-message.ben ul {
    margin: 8px 0 0 18px;
    padding: 0;
}

.mansion-message.ben li {
    margin-bottom: 4px;
}

.mansion-message.ben p {
    margin: 0 0 12px;
}

.mansion-message.ben p:last-child {
    margin-bottom: 0;
}

.mansion-message.ben h1,
.mansion-message.ben h2,
.mansion-message.ben h3,
.mansion-message.ben h4 {
    margin: 4px 0 10px;
    color: #fff;
    line-height: 1.35;
    font-weight: 650;
}

.mansion-message.ben h3 { font-size: 15px; }
.mansion-message.ben h4 { font-size: 14px; }

.mansion-message.ben ol {
    margin: 8px 0 12px 22px;
    padding: 0;
}

.mansion-message.ben li {
    margin-bottom: 6px;
    padding-left: 2px;
}

.mansion-message.ben li:last-child { margin-bottom: 0; }

.mansion-message.ben blockquote {
    margin: 10px 0;
    padding: 8px 12px;
    border-left: 2px solid var(--mansion-gold);
    color: #cfcfcf;
    background: rgba(255, 255, 255, 0.025);
}

.mansion-message.ben code {
    padding: 2px 5px;
    border-radius: 5px;
    background: rgba(212, 175, 55, 0.09);
    color: var(--mansion-gold-soft);
    font-size: 0.92em;
}

.mansion-message.ben pre {
    margin: 10px 0;
    padding: 12px;
    overflow-x: auto;
    border-radius: 10px;
    background: #0a0a0a;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.mansion-message.ben pre code {
    padding: 0;
    background: transparent;
    color: #ddd;
    white-space: pre;
}

.mansion-message.ben hr {
    margin: 14px 0;
    border: 0;
    border-top: 1px solid rgba(212, 175, 55, 0.14);
}

.mansion-message.ben a {
    color: var(--mansion-gold-soft);
    text-decoration: underline;
    text-decoration-color: rgba(232, 201, 106, 0.4);
    text-underline-offset: 2px;
}

.mansion-message.user {
    margin-left: auto;
    background: linear-gradient(135deg, #e0bc4a 0%, #D4AF37 50%, #c4a030 100%);
    color: #111;
    font-weight: 500;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 14px rgba(212, 175, 55, 0.25);
}

#mansion-typing {
    opacity: 0.75;
    font-style: italic;
    color: var(--mansion-muted);
}

/* Suggest chips */

.mansion-suggest {
    padding: 8px 14px 10px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.mansion-suggest::-webkit-scrollbar {
    height: 0;
}

.mansion-q {
    white-space: nowrap;
    border: 1px solid rgba(212, 175, 55, 0.35);
    background: rgba(212, 175, 55, 0.06);
    color: var(--mansion-gold);
    border-radius: 50px;
    padding: 9px 14px;
    cursor: pointer;
    transition: 0.25s;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.mansion-q:hover {
    background: var(--mansion-gold);
    color: #111;
    border-color: var(--mansion-gold);
    box-shadow: 0 4px 14px rgba(212, 175, 55, 0.3);
}

/* Footer input */

.mansion-footer {
    padding: 12px 14px 14px;
    border-top: 1px solid rgba(212, 175, 55, 0.1);
    display: flex;
    flex-direction: column;
    gap: 0;
    background: rgba(0, 0, 0, 0.25);
    align-items: stretch;
}

#mansion-input {
    flex: 1;
    min-height: 48px;
    max-height: 120px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    outline: none;
    border-radius: 14px;
    padding: 12px 14px;
    resize: none;
    background: #1a1a1a;
    color: #fff;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.25s;
}

#mansion-input:focus {
    border-color: rgba(212, 175, 55, 0.45);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.08);
}

#mansion-input::placeholder {
    color: #8a8a8a;
}

#mansion-send {
    height: 48px;
    min-width: 72px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #e0bc4a, #D4AF37 40%, #b8962e);
    color: #111;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: 0.25s;
    box-shadow: 0 4px 14px rgba(212, 175, 55, 0.28);
}

#mansion-send:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

#mansion-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

/* Mobile */

@media (max-width: 768px) {
    #mansion-window {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }

    #mansion-toggle {
        right: 16px;
        bottom: 16px;
        width: 48px;
        height: 48px;
    }

    #mansion-toggle img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
}

/* ========== Header actions ========== */

.mansion-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.mansion-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #ccc;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    padding: 0;
}

.mansion-icon-btn:hover {
    background: rgba(212, 175, 55, 0.15);
    color: var(--mansion-gold);
    border-color: rgba(212, 175, 55, 0.35);
}

.mansion-chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.mansion-bottom {
    flex-shrink: 0;
}

.mansion-input-wrap {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 22px;
    padding: 4px 4px 4px 12px;
    transition: border-color 0.25s, box-shadow 0.25s;
}

.mansion-input-wrap:focus-within {
    border-color: rgba(212, 175, 55, 0.45);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.08);
}

#mansion-input {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    min-height: 44px;
    max-height: 160px;
}

#mansion-send {
    width: 40px;
    min-width: 40px;
    height: 40px;
    border-radius: 12px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e0bc4a, #D4AF37 40%, #b8962e);
    box-shadow: 0 2px 10px rgba(212, 175, 55, 0.35);
}

.mansion-disclaimer {
    margin: 8px 0 0;
    text-align: center;
    font-size: 11px;
    color: #8a8a8a;
    letter-spacing: 0.02em;
}

/* Message rows (avatar + bubble) */

.mansion-message-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    max-width: 100%;
}

.mansion-message-row.user {
    flex-direction: row-reverse;
}

.mansion-msg-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
}

.mansion-msg-avatar img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: contain;
    background: #fff;
    border: 1px solid rgba(212, 175, 55, 0.35);
}

.mansion-message-row .mansion-message {
    margin-bottom: 0;
}

.mansion-message-row.user .mansion-message {
    margin-left: 0;
}

/* ========== EXPANDED – ChatGPT / Claude / Grok style ========== */

body.mansion-expanded-open {
    overflow: hidden !important;
}

#mansion-window.mansion-expanded {
    position: fixed !important;
    inset: 0 !important;
    right: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    border: none !important;
    z-index: 1000000 !important;
    background: #0c0c0c !important;
    box-shadow: none !important;
    display: flex !important;
    flex-direction: column !important;
    animation: mansion-expand-in 0.28s ease;
}

@keyframes mansion-expand-in {
    from { opacity: 0.6; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

#mansion-window.mansion-expanded::before {
    opacity: 0.5;
}

/* Top bar full width */
#mansion-window.mansion-expanded .mansion-header {
    padding: 12px 20px;
    background: rgba(18, 18, 18, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(12px);
}

#mansion-window.mansion-expanded .mansion-user h3 {
    font-size: 16px;
    letter-spacing: 0.06em;
}

/* Conversation column centered */
#mansion-window.mansion-expanded .mansion-chat-main {
    flex: 1;
    overflow: hidden;
    background:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(212, 175, 55, 0.06), transparent);
}

#mansion-window.mansion-expanded #mansion-body {
    max-width: 768px;
    width: 100%;
    margin: 0 auto;
    padding: 28px 20px 20px;
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Expanded messages – cleaner, larger text */
#mansion-window.mansion-expanded .mansion-message-row {
    margin-bottom: 22px;
    gap: 14px;
}

#mansion-window.mansion-expanded .mansion-msg-avatar {
    width: 36px;
    height: 36px;
}

#mansion-window.mansion-expanded .mansion-msg-avatar img {
    width: 36px;
    height: 36px;
    border-radius: 10px;
}

#mansion-window.mansion-expanded .mansion-message {
    max-width: 100%;
    font-size: 15.5px;
    line-height: 1.75;
    padding: 14px 18px;
    border-radius: 18px;
}

#mansion-window.mansion-expanded .mansion-message.ben {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

#mansion-window.mansion-expanded .mansion-message.user {
    background: linear-gradient(135deg, #e0bc4a 0%, #D4AF37 50%, #c4a030 100%);
}

/* Bottom composer – sticky, centered */
#mansion-window.mansion-expanded .mansion-bottom {
    background: linear-gradient(180deg, transparent, #0c0c0c 30%);
    padding: 0 16px 16px;
}

#mansion-window.mansion-expanded .mansion-suggest {
    max-width: 768px;
    margin: 0 auto;
    padding: 8px 0 12px;
    justify-content: center;
    flex-wrap: wrap;
    border-top: none;
}

#mansion-window.mansion-expanded .mansion-footer {
    max-width: 768px;
    margin: 0 auto;
    border-top: none;
    background: transparent;
    padding: 0 0 4px;
    flex-direction: column;
    align-items: stretch;
}

#mansion-window.mansion-expanded .mansion-input-wrap {
    background: #1a1a1a;
    border-radius: 20px;
    padding: 10px 10px 10px 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

#mansion-window.mansion-expanded #mansion-input {
    font-size: 15.5px;
    min-height: 48px;
    max-height: 200px;
    padding: 12px 14px;
}

#mansion-window.mansion-expanded #mansion-send {
    width: 46px;
    min-width: 46px;
    height: 46px;
    border-radius: 14px;
}

/* Expand icon becomes “thu nhỏ” when expanded */
#mansion-window.mansion-expanded #mansion-expand svg {
    transform: scale(0.9);
}

#mansion-window.mansion-expanded #mansion-expand::after {
    /* title handled by JS */
}

@media (max-width: 768px) {
    #mansion-window.mansion-expanded #mansion-body {
        padding: 16px 12px;
    }

    #mansion-window.mansion-expanded .mansion-message {
        font-size: 15px;
        padding: 12px 14px;
    }
}


/* ========== Embed mode (shortcode trong trang) ========== */

#mansion.mansion-embed {
    position: relative;
    width: 100%;
    max-width: 920px;
    margin: 24px auto;
    min-height: 560px;
}

#mansion.mansion-embed #mansion-toggle {
    display: none !important;
}

#mansion.mansion-embed #mansion-window {
    display: flex !important;
    position: relative !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    width: 100% !important;
    height: 620px !important;
    max-height: 80vh !important;
    border-radius: 20px !important;
    box-shadow: 0 20px 50px rgba(0,0,0,.35);
}

#mansion.mansion-embed #mansion-window.mansion-expanded {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
}

/* ========== v2.9.3 — Safe area + touch 44px + export ========== */
#mansion-toggle {
    bottom: max(20px, env(safe-area-inset-bottom, 0px));
    right: max(20px, env(safe-area-inset-right, 0px));
}
#mansion-window {
    bottom: max(90px, calc(20px + env(safe-area-inset-bottom, 0px) + 70px));
    right: max(20px, env(safe-area-inset-right, 0px));
    max-height: min(580px, calc(100vh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)));
}
#mansion-send,
.mansion-icon-btn {
    min-width: 44px;
    min-height: 44px;
}
#mansion-toggle {
    min-width: 52px;
    min-height: 52px;
}
@media (max-width: 768px) {
    #mansion-toggle {
        width: 46px;
        height: 46px;
        min-width: 46px;
        min-height: 46px;
    }
    #mansion-window {
        width: min(100vw - 16px, 380px);
        right: max(8px, env(safe-area-inset-right, 0px));
        bottom: max(72px, calc(8px + env(safe-area-inset-bottom, 0px) + 56px));
    }
}
