/**
 * SoiMenh AI Advisor — Styles v3 PREMIUM
 * BEM: sm-aiv-*  |  Mystic Imperial Fusion  |  Mobile-first
 */

/* ══════════════════════════════════════════════
 * BUBBLE — Bát Quái La Bàn (Bagua Compass)
 * ══════════════════════════════════════════════ */

.sm-aiv-bubble {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 2;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #1a1815 0%, #0c0b09 100%);
    border: 1.5px solid rgba(201, 169, 110, 0.5);
    color: #c9a96e;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 24px rgba(201, 169, 110, 0.3),
                0 0 50px rgba(201, 169, 110, 0.1),
                inset 0 0 20px rgba(201, 169, 110, 0.05);
    transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 250ms ease,
                border-color 250ms ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.sm-aiv-bubble:hover {
    transform: scale(1.1);
    border-color: rgba(201, 169, 110, 0.8);
    box-shadow: 0 4px 30px rgba(201, 169, 110, 0.5),
                0 0 60px rgba(201, 169, 110, 0.2),
                inset 0 0 25px rgba(201, 169, 110, 0.08);
}
.sm-aiv-bubble:hover .sm-aiv-bubble__orbit {
    animation-duration: 12s;
    opacity: 1;
}

.sm-aiv-bubble:active {
    transform: scale(0.95);
}

.sm-aiv-bubble--hidden {
    display: none;
}

/* Bagua orbit ring — spins slowly */
.sm-aiv-bubble__orbit {
    position: absolute;
    inset: -8px;
    width: calc(100% + 16px);
    height: calc(100% + 16px);
    animation: smAivOrbitSpin 25s linear infinite;
    pointer-events: none;
    opacity: 0.85;
    transition: opacity 300ms ease, animation-duration 300ms ease;
}

@keyframes smAivOrbitSpin {
    to { transform: rotate(360deg); }
}

/* Pulse glow — mystical breathing */
.sm-aiv-bubble--pulse {
    animation: smAivPulse 3s ease-in-out infinite;
}

@keyframes smAivPulse {
    0%, 100% { box-shadow: 0 4px 24px rgba(201, 169, 110, 0.35), 0 -12px 40px rgba(201, 169, 110, 0.08), 0 0 50px rgba(201, 169, 110, 0.1); }
    50% { box-shadow: 0 4px 35px rgba(201, 169, 110, 0.55), 0 -16px 50px rgba(201, 169, 110, 0.15), 0 0 70px rgba(201, 169, 110, 0.2); }
}

/* Thái Cực center icon */
.sm-aiv-bubble__icon {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    filter: drop-shadow(0 0 6px rgba(201, 169, 110, 0.35));
}

/* Notification badge */
.sm-aiv-bubble__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: linear-gradient(135deg, #ef5350, #c62828);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 2px 8px rgba(239, 83, 80, 0.5);
    border: 2px solid #0c0b09;
    animation: smAivBadgePulse 2s ease-in-out infinite;
}

@keyframes smAivBadgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}

/* ══════════════════════════════════════════════
 * LAUNCHER + PREVIEW — one joined “seal and silk rail”
 * ══════════════════════════════════════════════ */

.sm-aiv-launcher {
    position: fixed;
    right: 16px;
    bottom: 80px;
    z-index: 999991;
    width: 278px;
    height: 62px;
    pointer-events: none;
    transition: opacity 200ms ease, transform 200ms ease;
}

.sm-aiv-launcher .sm-aiv-bubble {
    pointer-events: auto;
}

.sm-aiv-preview {
    box-sizing: border-box;
    position: absolute;
    top: 3px;
    right: 50px;
    z-index: 1;
    width: 228px;
    height: 56px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    background: radial-gradient(ellipse at 85% 85%, #1a1815 0%, #0c0b09 100%);
    border: 1.5px solid rgba(201, 169, 110, 0.25);
    border-radius: 18px 7px 7px 18px;
    color: #e8e0d0;
    box-shadow: 0 4px 24px rgba(201, 169, 110, 0.08),
                0 8px 32px rgba(0, 0, 0, 0.5),
                inset 0 0 20px rgba(201, 169, 110, 0.03);
    opacity: 0;
    transform: translateX(8px);
    transform-origin: right center;
    transition: opacity 200ms ease, transform 200ms ease;
    pointer-events: none;
    overflow: hidden;
}

.sm-aiv-preview--visible {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.sm-aiv-preview__content,
.sm-aiv-preview__close {
    appearance: none;
    border: 0;
    color: inherit;
    font-family: 'Be Vietnam Pro', sans-serif;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    cursor: pointer;
}

.sm-aiv-preview__content {
    min-width: 0;
    min-height: 44px;
    padding: 7px 4px 7px 16px;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 1px;
    text-align: left;
}

.sm-aiv-preview__title,
.sm-aiv-preview__text {
    display: block;
    width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.sm-aiv-preview__title {
    color: #f5d58c;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.25;
}

.sm-aiv-preview__text {
    color: #e8e0d0;
    font-size: 11.5px;
    line-height: 1.35;
}

.sm-aiv-preview__close {
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 8px 0 0;
    background: transparent;
    color: rgba(232, 224, 208, 0.25);
    font-size: 16px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 180ms ease, background-color 180ms ease;
}

.sm-aiv-preview__content:hover,
.sm-aiv-preview__content:focus-visible {
    background: rgba(201, 169, 110, 0.05);
}

.sm-aiv-preview__close:hover,
.sm-aiv-preview__close:focus-visible {
    color: rgba(232, 224, 208, 0.7);
    background: rgba(201, 169, 110, 0.05);
}

.sm-aiv-preview__content:focus-visible,
.sm-aiv-preview__close:focus-visible,
.sm-aiv-bubble:focus-visible {
    outline: 1px solid rgba(201, 169, 110, 0.8);
    outline-offset: -3px;
}

body.smc-aiv-open .sm-aiv-launcher {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.92);
}

/* ══════════════════════════════════════════════
 * PANEL — Chat container
 * ══════════════════════════════════════════════ */

.sm-aiv-panel {
    position: fixed;
    z-index: 9990;
    display: flex;
    flex-direction: column;
    background: linear-gradient(170deg, #1a1814 0%, #100e0c 50%, #0c0c0a 100%);
    border: none;
    outline: none;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 280ms ease, transform 280ms cubic-bezier(0.34, 1.2, 0.64, 1);

    /* Mobile: bottom sheet */
    bottom: 0;
    left: 0;
    right: 0;
    height: 72vh;
    height: 72dvh;
    max-height: 600px;
    border-radius: 4px 4px 0 0;
    transform: translateY(100%);
    box-shadow: 0 -4px 40px rgba(0, 0, 0, 0.6),
                0 0 6px rgba(201, 169, 110, 0.2);
}

.sm-aiv-panel--open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

/* L-bracket corners on panel — disabled to avoid jagged seams */
.sm-aiv-panel::before,
.sm-aiv-panel::after {
    display: none;
}

/*
 * Lock body scroll when chat is open.
 * NO position:fixed — that shifts page layout.
 * overflow:hidden alone is enough with touchmove prevention in JS.
 */
body.smc-aiv-open {
    overflow: hidden !important;
}

/* Overlay backdrop */
.sm-aiv-overlay {
    position: fixed;
    inset: 0;
    z-index: 9989;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 280ms ease;
    -webkit-tap-highlight-color: transparent;
}

.sm-aiv-overlay--visible {
    opacity: 1;
    pointer-events: auto;
}

/* Desktop: panel grows FROM the FAB */
@media (min-width: 1025px) {
    .sm-aiv-panel {
        bottom: 140px;
        right: max(12px, calc(50% - 650px));
        left: auto;
        width: 390px;
        height: 580px;
        max-height: calc(100vh - 160px);
        border-radius: 4px;
        transform: scale(0) translateY(20px);
        transform-origin: bottom right;
        box-shadow: 0 8px 50px rgba(0, 0, 0, 0.65),
                    0 0 6px rgba(201, 169, 110, 0.2);
    }

    .sm-aiv-panel--open {
        transform: scale(1) translateY(0);
    }
}

/* ── Panel Header — Imperial Seal ── */

.sm-aiv-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
    background: linear-gradient(180deg, rgba(201, 169, 110, 0.07) 0%, rgba(201, 169, 110, 0.02) 100%);
    position: relative;
}

/* Gold shimmer line — disabled, conflicts with panel border */
.sm-aiv-panel__header::before {
    display: none;
}

@keyframes smAivShimmer {
    0%, 100% { background-position: 200% 0; }
    50% { background-position: -200% 0; }
}

/* Meander line under header — simplified to clean divider */
.sm-aiv-panel__header::after {
    display: none;
}

.sm-aiv-panel__header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* AI Avatar — Âm Dương seal */
.sm-aiv-panel__avatar {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    box-shadow: 0 0 12px rgba(201, 169, 110, 0.2);
}

.sm-aiv-panel__avatar svg {
    width: 100%;
    height: 100%;
}

.sm-aiv-avatar__orbit {
    animation: smAivOrbitSpin 12s linear infinite;
    transform-origin: 20px 20px;
}

.sm-aiv-panel__header-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.sm-aiv-panel__header-name {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 16px;
    color: #e0c88f;
    letter-spacing: 0.04em;
    line-height: 1.2;
}

.sm-aiv-panel__header-sub {
    font-size: 10px;
    color: rgba(201, 169, 110, 0.5);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 500;
}

.sm-aiv-panel__header-status {
    font-size: 11px;
    color: #9E9484;
    font-style: italic;
    margin-left: 4px;
}

.sm-aiv-panel__close {
    background: none;
    border: 1px solid transparent;
    color: #5C5548;
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    transition: color 150ms ease, border-color 150ms ease, background 150ms ease;
}

.sm-aiv-panel__close:hover {
    color: #F5F0E8;
    border-color: rgba(201, 169, 110, 0.2);
    background: rgba(201, 169, 110, 0.05);
}

/* ── Context Bar ── */

.sm-aiv-panel__context-bar {
    padding: 6px 16px;
    font-size: 12px;
    color: #9E9484;
    background: rgba(201, 169, 110, 0.04);
    border-bottom: 1px solid rgba(201, 169, 110, 0.08);
    flex-shrink: 0;
}

/* ── Messages Area ── */

.sm-aiv-panel__messages-wrap {
    position: relative;
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sm-aiv-panel__messages-wrap .sm-aiv-panel__messages {
    flex: 1;
}

.sm-aiv-panel__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* Scrollbar — thin gold */
.sm-aiv-panel__messages::-webkit-scrollbar { width: 3px; }
.sm-aiv-panel__messages::-webkit-scrollbar-track { background: transparent; }
.sm-aiv-panel__messages::-webkit-scrollbar-thumb { background: rgba(201, 169, 110, 0.2); border-radius: 2px; }
.sm-aiv-panel__messages::-webkit-scrollbar-thumb:hover { background: rgba(201, 169, 110, 0.35); }

/* ── Message Bubbles — Refined ── */

.sm-aiv-panel__msg {
    max-width: 85%;
    padding: 10px 14px;
    font-size: 14.5px;
    line-height: 1.65;
    word-wrap: break-word;
    animation: smAivMsgIn 250ms cubic-bezier(0.34, 1.2, 0.64, 1);
    position: relative;
}

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

/* Assistant bubble */
.sm-aiv-panel__msg--assistant {
    align-self: flex-start;
    background: linear-gradient(160deg, rgba(201, 169, 110, 0.08) 0%, rgba(201, 169, 110, 0.03) 100%);
    border: none;
    outline: none;
    border-radius: 2px 4px 4px 0;
    color: #F5F0E8;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.2),
                0 0 4px rgba(201, 169, 110, 0.1);
}

/* Subtle inner glow on assistant messages */
.sm-aiv-panel__msg--assistant::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(180deg, rgba(201, 169, 110, 0.4), transparent);
    border-radius: 2px 0 0 0;
}

.sm-aiv-panel__msg--assistant a {
    color: #f5d58c;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.sm-aiv-panel__msg--assistant a:hover {
    color: #c9a96e;
}

.sm-aiv-panel__msg--assistant strong {
    color: #f5d58c;
    font-weight: 600;
}

.sm-aiv-panel__msg--assistant em {
    color: #e8dcc8;
    font-style: italic;
}

.sm-aiv-panel__msg--assistant code {
    background: rgba(201, 169, 110, 0.1);
    padding: 1px 4px;
    border-radius: 2px;
    font-size: 0.9em;
}

/* User bubble — gold gradient */
.sm-aiv-panel__msg--user {
    align-self: flex-end;
    background: linear-gradient(135deg, #c9a96e 0%, #a87840 100%);
    color: #0c0c0a;
    border-radius: 4px 2px 0 4px;
    font-weight: 500;
    box-shadow: 0 2px 12px rgba(201, 169, 110, 0.2);
    border: none;
}

/* Typing indicator */
.sm-aiv-panel__msg--typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
    animation: none;
    min-height: 34px;
}

.sm-aiv-panel__msg--typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #c9a96e;
    opacity: 1;
    animation: smAivTyping 1.4s ease-in-out infinite;
}

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

@keyframes smAivTyping {
    0%, 80%, 100% { opacity: 0.5; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-5px); }
}

/* ── Scroll FAB ── */

.sm-aiv-panel__scroll-fab {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(201, 169, 110, 0.3);
    background: linear-gradient(135deg, #1a1814, #0c0c0a);
    color: #c9a96e;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    transition: opacity 200ms ease, transform 200ms ease, border-color 200ms ease;
    z-index: 2;
}

.sm-aiv-panel__scroll-fab:hover {
    border-color: rgba(201, 169, 110, 0.55);
    transform: scale(1.1);
}

/* ── Action Bar — Polished ── */

.sm-aiv-panel__action-bar {
    display: flex;
    gap: 8px;
    padding: 6px 14px;
    flex-shrink: 0;
    border-top: 1px solid rgba(201, 169, 110, 0.06);
    background: rgba(12, 12, 10, 0.4);
}

.sm-aiv-panel__action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 2px;
    border: 1px solid rgba(201, 169, 110, 0.1);
    background: transparent;
    color: rgba(158, 148, 132, 0.65);
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 180ms ease, color 180ms ease, border-color 180ms ease;
    letter-spacing: 0.03em;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
.sm-aiv-panel__action-btn:focus-visible {
    border-color: rgba(201, 169, 110, 0.3);
}

.sm-aiv-panel__action-btn:hover {
    color: #F5F0E8;
}

.sm-aiv-panel__action-btn--clear:hover {
    border-color: rgba(239, 83, 80, 0.35);
    background: rgba(239, 83, 80, 0.06);
    color: #ff6b6b;
}

.sm-aiv-panel__action-btn--reset:hover {
    border-color: rgba(201, 169, 110, 0.35);
    background: rgba(201, 169, 110, 0.06);
    color: #d4b876;
}

.sm-aiv-panel__action-btn--close {
    margin-left: auto;
}
.sm-aiv-panel__action-btn--close:hover {
    border-color: rgba(245, 240, 232, 0.3);
    background: rgba(245, 240, 232, 0.06);
    color: #F5F0E8;
}

/* ── Message Wrapper (timestamp + actions) ── */

.sm-aiv-panel__msg-wrap {
    display: flex;
    flex-direction: column;
    gap: 3px;
    animation: smAivMsgIn 250ms cubic-bezier(0.34, 1.2, 0.64, 1);
}

.sm-aiv-panel__msg-wrap .sm-aiv-panel__msg {
    animation: none;
}

.sm-aiv-panel__msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 4px;
    opacity: 0;
    transition: opacity 200ms ease;
}

.sm-aiv-panel__msg-wrap:hover .sm-aiv-panel__msg-meta,
.sm-aiv-panel__msg-meta--visible {
    opacity: 1;
}

.sm-aiv-panel__msg-wrap--user .sm-aiv-panel__msg-meta {
    justify-content: flex-end;
}

.sm-aiv-panel__msg-time {
    font-size: 10px;
    color: #5C5548;
}

.sm-aiv-panel__msg-action {
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: #5C5548;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    padding: 0;
    transition: color 150ms ease, background 150ms ease;
}

.sm-aiv-panel__msg-action:hover {
    color: #F5F0E8;
    background: rgba(201, 169, 110, 0.1);
}

.sm-aiv-panel__msg-action--active {
    color: #d4b876 !important;
}

/* ── Date Divider — meander style ── */

.sm-aiv-panel__date-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
}

.sm-aiv-panel__date-divider::before,
.sm-aiv-panel__date-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(201, 169, 110, 0.15), transparent);
}

.sm-aiv-panel__date-divider span {
    font-size: 10px;
    color: rgba(201, 169, 110, 0.4);
    white-space: nowrap;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: 500;
}

/* ── Error Message + Retry ── */

.sm-aiv-panel__msg--error {
    border-color: rgba(239, 83, 80, 0.2) !important;
    background: rgba(239, 83, 80, 0.05) !important;
}

.sm-aiv-panel__retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding: 4px 12px;
    border-radius: 2px;
    border: 1px solid rgba(201, 169, 110, 0.2);
    background: transparent;
    color: #d4b876;
    font-size: 12px;
    cursor: pointer;
    transition: background 150ms ease;
}

.sm-aiv-panel__retry-btn:hover {
    background: rgba(201, 169, 110, 0.08);
}

/* ── History Loading ── */

.sm-aiv-panel__history-loading {
    display: flex;
    gap: 5px;
    justify-content: center;
    padding: 24px;
}

.sm-aiv-panel__history-loading span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #c9a96e;
    animation: smAivTyping 1.2s ease-in-out infinite;
}

.sm-aiv-panel__history-loading span:nth-child(2) { animation-delay: 0.15s; }
.sm-aiv-panel__history-loading span:nth-child(3) { animation-delay: 0.3s; }

/* ══════════════════════════════════════════════
 * FOOTER / INPUT — Premium
 * ══════════════════════════════════════════════ */

.sm-aiv-panel__footer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 14px 14px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    border-top: 1px solid rgba(201, 169, 110, 0.06);
    flex-shrink: 0;
    background: transparent;
    position: relative;
}

/* Meander above footer — disabled for clean look */
.sm-aiv-panel__footer::before {
    display: none;
}

.sm-aiv-panel__input-wrap {
    flex: 1;
    min-width: 0;
    position: relative;
}

.sm-aiv-panel__input {
    width: 100%;
    box-sizing: border-box;
    resize: none;
    border: 1px solid rgba(255, 255, 255, 0.06) !important;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.03);
    color: #F5F0E8;
    padding: 10px 14px;
    font-size: 16px; /* 16px prevents iOS auto-zoom */
    font-family: inherit;
    line-height: 1.45;
    max-height: 100px;
    overflow-y: auto;
    scrollbar-width: none;
    outline: none !important;
    box-shadow: none !important;
    -webkit-appearance: none;
    touch-action: manipulation;
    transition: border-color 200ms ease;
}
.sm-aiv-panel__input::-webkit-scrollbar { display: none; }

.sm-aiv-panel__input:focus {
    border-color: rgba(255, 255, 255, 0.1) !important;
    outline: none !important;
    box-shadow: none !important;
}

.sm-aiv-panel__input::placeholder {
    color: rgba(158, 148, 132, 0.45);
    font-style: italic;
}

/* Send button — arrow with gold ring */
.sm-aiv-panel__send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.06) !important;
    background: rgba(255, 255, 255, 0.03);
    color: rgba(201, 169, 110, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none !important;
    box-shadow: none !important;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    transition: transform 150ms ease, background 150ms ease, border-color 150ms ease, color 150ms ease;
    touch-action: manipulation;
}

.sm-aiv-panel__send:hover {
    background: linear-gradient(135deg, #c9a96e, #a87840);
    color: #0c0c0a;
    border-color: #c9a96e;
    transform: scale(1.05);
}

.sm-aiv-panel__send:active {
    transform: scale(0.92);
}

.sm-aiv-panel__send:disabled {
    opacity: 0.2;
    cursor: not-allowed;
    transform: none;
    background: transparent;
}

/* ══════════════════════════════════════════════
 * INLINE INSIGHT — Card in tool results
 * ══════════════════════════════════════════════ */

.sm-aiv-insight {
    margin-top: 24px;
    padding: 20px;
    background: rgba(12, 12, 10, 0.85);
    border: 1px solid rgba(201, 169, 110, 0.18);
    border-radius: 4px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.sm-aiv-insight__header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.sm-aiv-insight__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #c9a96e, #e0c88f);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0c0c0a;
    font-size: 16px;
    flex-shrink: 0;
}

.sm-aiv-insight__name {
    font-weight: 600;
    font-size: 14px;
    color: #e0c88f;
}

.sm-aiv-insight__text {
    font-size: 14px;
    line-height: 1.6;
    color: #F5F0E8;
    margin-bottom: 14px;
}

.sm-aiv-insight__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.sm-aiv-insight__ask-more {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 4px;
    border: 1px solid rgba(201, 169, 110, 0.25);
    background: transparent;
    color: #d4b876;
    font-size: 13px;
    cursor: pointer;
    transition: background 150ms ease;
}

.sm-aiv-insight__ask-more:hover {
    background: rgba(201, 169, 110, 0.1);
}

.sm-aiv-insight__cross-tool {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: 4px;
    background: rgba(201, 169, 110, 0.06);
    color: #9E9484;
    font-size: 12px;
    text-decoration: none;
    transition: color 150ms ease;
}

.sm-aiv-insight__cross-tool:hover {
    color: #d4b876;
}

/* Skeleton loading */
.sm-aiv-insight--loading .sm-aiv-insight__text {
    background: linear-gradient(90deg, rgba(201, 169, 110, 0.05) 25%, rgba(201, 169, 110, 0.1) 50%, rgba(201, 169, 110, 0.05) 75%);
    background-size: 200% 100%;
    animation: smAivSkeleton 1.5s infinite;
    height: 48px;
    border-radius: 4px;
}

@keyframes smAivSkeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ══════════════════════════════════════════════
 * RESPONSIVE — ALL DEVICES
 * ══════════════════════════════════════════════ */

/* Firefox Android — no backdrop-filter */
@supports not (backdrop-filter: blur(1px)) {
    .sm-aiv-panel {
        background: #1a1814;
    }
    .sm-aiv-preview {
        background: #1e1c18;
    }
}

/* ── All mobile ≤1024px — touch optimizations ── */
@media (max-width: 1024px) {
    .sm-aiv-panel__close,
    .sm-aiv-panel__action-btn,
    .sm-aiv-panel__msg-action,
    .sm-aiv-panel__scroll-fab,
    .sm-aiv-panel__send,
    .sm-aiv-panel__retry-btn {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}

/* ── Tablet 769–1024px — compact joined launcher above utility controls ── */
@media (min-width: 769px) and (max-width: 1024px) {
    .sm-aiv-launcher {
        right: 20px;
        bottom: 134px;
        width: 260px;
    }

    .sm-aiv-preview {
        width: 210px;
    }
}

/* ── Mobile ≤768px — icon only; preview never covers content ── */
@media (max-width: 768px) {
    .sm-aiv-launcher {
        right: 16px;
        bottom: 102px;
        width: 62px;
    }

    .sm-aiv-preview {
        display: none;
    }
}

/* ── Desktop ≥1025px — follow the content edge ── */
@media (min-width: 1025px) {
    .sm-aiv-launcher {
        right: max(12px, calc(50% - 675px));
        bottom: 140px;
    }
}

/* ── Small phones ≤480px ── */
@media (max-width: 480px) {
    .sm-aiv-launcher {
        width: 54px;
        height: 54px;
    }

    .sm-aiv-bubble {
        width: 54px;
        height: 54px;
    }

    .sm-aiv-bubble__icon {
        width: 32px;
        height: 32px;
    }


    /* Full-screen on small phones */
    .sm-aiv-panel {
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
    }

    .sm-aiv-panel__close,
    .sm-aiv-panel__action-btn,
    .sm-aiv-panel__msg-action {
        min-height: 44px;
        min-width: 44px;
    }

    .sm-aiv-panel__header-name {
        font-size: 15px;
    }

    .sm-aiv-panel__msg {
        font-size: 14px;
    }
}

/* ── Tablets 481–1024px ── */
@media (min-width: 481px) and (max-width: 1024px) {
    .sm-aiv-panel {
        height: 80vh;
        height: 80dvh;
        max-height: 680px;
    }

}

/* ── Landscape phones ── */
@media (max-height: 500px) and (max-width: 1024px) {
    .sm-aiv-panel {
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
    }

    .sm-aiv-panel__header {
        padding: 6px 14px;
    }

    .sm-aiv-panel__avatar {
        width: 28px;
        height: 28px;
    }

    .sm-aiv-panel__action-bar {
        padding: 4px 14px;
    }

    .sm-aiv-panel__msg {
        font-size: 13px;
        padding: 8px 12px;
    }

    .sm-aiv-panel__footer {
        padding: 6px 12px max(8px, env(safe-area-inset-bottom));
    }
}

/* Hide bubble + tool FABs when panel is open */
body.smc-aiv-open .sm-aiv-bubble {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
}

/* Tool FABs (z-index 999990) cover chat panel footer — hide them when chat open */
body.smc-aiv-open [id$="-toc-fab"],
body.smc-aiv-open .tsh-fab-wrapper,
body.smc-aiv-open .tt-fab-wrapper,
body.smc-aiv-open .smfb-fab {
    display: none !important;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
    .sm-aiv-launcher,
    .sm-aiv-bubble,
    .sm-aiv-panel,
    .sm-aiv-preview,
    .sm-aiv-panel__msg,
    .sm-aiv-bubble__orbit,
    .sm-aiv-avatar__orbit,
    .sm-aiv-panel__header::before {
        transition: none;
        animation: none;
    }
}

/* ══════════════════════════════════════════════
 * CUSTOM CONFIRM DIALOG — Mystic Imperial
 * ══════════════════════════════════════════════ */

.sm-aiv-confirm {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    transition: background 300ms ease, backdrop-filter 300ms ease, -webkit-backdrop-filter 300ms ease;
}

.sm-aiv-confirm--visible {
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.sm-aiv-confirm__box {
    position: relative;
    width: 100%;
    max-width: 320px;
    background: linear-gradient(160deg, #1e1c18 0%, #161410 100%);
    border: 1px solid rgba(201, 169, 110, 0.35);
    border-radius: 4px;
    padding: 28px 24px 24px;
    box-shadow: 0 0 0 1px rgba(201, 169, 110, 0.08),
                0 8px 40px rgba(0, 0, 0, 0.7),
                inset 0 1px 0 rgba(201, 169, 110, 0.1);
    opacity: 0;
    transform: scale(0.88) translateY(10px);
    transition: opacity 280ms cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.sm-aiv-confirm--visible .sm-aiv-confirm__box {
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* Corner L-brackets */
.sm-aiv-confirm__box::before,
.sm-aiv-confirm__box::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border-color: rgba(201, 169, 110, 0.55);
    border-style: solid;
}

.sm-aiv-confirm__box::before {
    top: -1px; left: -1px;
    border-width: 2px 0 0 2px;
    border-radius: 4px 0 0 0;
}

.sm-aiv-confirm__box::after {
    bottom: -1px; right: -1px;
    border-width: 0 2px 2px 0;
    border-radius: 0 0 4px 0;
}

.sm-aiv-confirm__inner::before,
.sm-aiv-confirm__inner::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border-color: rgba(201, 169, 110, 0.35);
    border-style: solid;
}

.sm-aiv-confirm__inner::before {
    top: -1px; right: -1px;
    border-width: 2px 2px 0 0;
    border-radius: 0 4px 0 0;
}

.sm-aiv-confirm__inner::after {
    bottom: -1px; left: -1px;
    border-width: 0 0 2px 2px;
    border-radius: 0 0 0 4px;
}

.sm-aiv-confirm__inner {
    position: relative;
}

.sm-aiv-confirm__icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 20px;
}

.sm-aiv-confirm__icon--danger {
    background: rgba(239, 83, 80, 0.1);
    border: 1px solid rgba(239, 83, 80, 0.25);
    color: #ef5350;
}

.sm-aiv-confirm__icon--reset {
    background: rgba(201, 169, 110, 0.1);
    border: 1px solid rgba(201, 169, 110, 0.25);
    color: #c9a96e;
}

.sm-aiv-confirm__title {
    font-family: 'Playfair Display', serif;
    font-size: 15px;
    font-weight: 600;
    color: #e0c88f;
    text-align: center;
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

.sm-aiv-confirm__msg {
    font-size: 13px;
    color: #9E9484;
    text-align: center;
    line-height: 1.55;
    margin-bottom: 22px;
}

.sm-aiv-confirm__divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(201, 169, 110, 0.2), transparent);
    margin-bottom: 18px;
}

.sm-aiv-confirm__actions {
    display: flex;
    gap: 10px;
}

.sm-aiv-confirm__btn {
    flex: 1;
    padding: 10px 16px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 150ms ease, transform 150ms ease, box-shadow 150ms ease;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
}

.sm-aiv-confirm__btn:active {
    transform: scale(0.97);
}

.sm-aiv-confirm__btn--cancel {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.1);
    color: #9E9484;
}

.sm-aiv-confirm__btn--cancel:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #F5F0E8;
}

.sm-aiv-confirm__btn--ok {
    background: linear-gradient(135deg, #c9a96e, #b8904a);
    border-color: rgba(201, 169, 110, 0.5);
    color: #0c0c0a;
    font-weight: 600;
    box-shadow: 0 2px 12px rgba(201, 169, 110, 0.25);
}

.sm-aiv-confirm__btn--ok:hover {
    background: linear-gradient(135deg, #d4b876, #c9a96e);
    box-shadow: 0 4px 18px rgba(201, 169, 110, 0.35);
}

.sm-aiv-confirm__btn--ok--danger {
    background: linear-gradient(135deg, #ef5350, #c62828);
    border-color: rgba(239, 83, 80, 0.4);
    color: #fff;
    box-shadow: 0 2px 12px rgba(239, 83, 80, 0.25);
}

.sm-aiv-confirm__btn--ok--danger:hover {
    background: linear-gradient(135deg, #f44336, #d32f2f);
    box-shadow: 0 4px 18px rgba(239, 83, 80, 0.35);
}

.sm-aiv-confirm__hint {
    text-align: center;
    font-size: 10px;
    color: #5C5548;
    margin-top: 12px;
    letter-spacing: 0.03em;
}

/* Mobile perf — kill backdrop-filter on weak GPUs */
@media (max-width: 768px) {
  .sm-aiv-panel {
    backdrop-filter: none; -webkit-backdrop-filter: none;
    background: rgba(14,13,11,0.99);
  }
  .sm-aiv-preview {
    backdrop-filter: none; -webkit-backdrop-filter: none;
    background: rgba(12,12,10,0.98);
  }
  .sm-aiv-panel__msg--assistant {
    backdrop-filter: none; -webkit-backdrop-filter: none;
    background: rgba(12,12,10,0.95);
  }
  .sm-aiv-confirm--visible {
    backdrop-filter: none; -webkit-backdrop-filter: none;
    background: rgba(0,0,0,0.85);
  }
}


/* T02 — shared layer and Thiên Ấn integration */
.sm-aiv-bubble { appearance: none; padding: 0; font: inherit; }
.sm-aiv-panel__close { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.sm-aiv-panel__send { min-width: 44px; min-height: 44px; }
.sm-aiv-panel__action-btn { min-height: 44px; }
body.sm-ui-layer-menu .sm-aiv-launcher,
body.sm-ui-layer-search .sm-aiv-launcher,
body.sm-ui-layer-feedback .sm-aiv-launcher,
body.sm-ui-layer-toc .sm-aiv-launcher { opacity: 0 !important; pointer-events: none !important; }
.sm-aiv-bubble__orbit, .sm-aiv-bubble--pulse, .sm-aiv-bubble__badge { animation: none !important; }
.sm-aiv-panel { transition-duration: 220ms !important; }
.sm-aiv-panel::before {
    display: block; content: ''; position: absolute; top: 0; left: 18%; right: 18%; height: 1px;
    background: linear-gradient(90deg, transparent, rgba(201,169,110,.55), transparent);
    transform: scaleX(0); transform-origin: center; opacity: 0;
    transition: transform 220ms ease, opacity 220ms ease; pointer-events: none; z-index: 3;
}
.sm-aiv-panel--open::before { transform: scaleX(1); opacity: 1; }

body.sm-ui-layer-menu .sm-aiv-launcher .sm-aiv-bubble,
body.sm-ui-layer-search .sm-aiv-launcher .sm-aiv-bubble,
body.sm-ui-layer-feedback .sm-aiv-launcher .sm-aiv-bubble,
body.sm-ui-layer-toc .sm-aiv-launcher .sm-aiv-bubble {
    pointer-events: none !important;
}
