/* Robot AI — Floating Input Widget */
#robot-ai-wrap {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
#robot-ai-btn { display: none !important; }

/* === Floating Input Popup === */
#robot-ai-popup {
    display: none;
    position: fixed;
    bottom: 24px;
    left: 220px;
    width: 340px;
    z-index: 10000;
    background: rgba(10, 10, 12, 0.97);
    border: 1px solid rgba(201, 169, 78, 0.12);
    border-radius: 14px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 1px 14px 12px;
    animation: raSlideUp 0.2s ease;
}
@keyframes raSlideUp {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
#robot-ai-popup .ra-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    color: #7a7a7e;
    cursor: grab;
    user-select: none;
}
#robot-ai-popup .ra-header:active { cursor: grabbing; }
#robot-ai-popup .ra-header .ra-close {
    margin-left: auto;
    background: none;
    border: none;
    color: #7a7a7e;
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
}
#robot-ai-popup .ra-header .ra-close:hover {
    color: #ececed;
    background: rgba(255,255,255,0.06);
}
.ra-input-wrap {
    position: relative;
}
#robot-ai-input {
    width: 100%;
    padding: 10px 36px 10px 14px;
    border: 1px solid rgba(201, 169, 78, 0.12);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    color: #ececed;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s, height .25s ease;
    box-sizing: border-box;
    resize: none;
    line-height: 1.4;
}
#robot-ai-input:focus {
    border-color: rgba(201, 169, 78, 0.3);
}
#robot-ai-input::-webkit-scrollbar {
    display: none;
}
#robot-ai-input {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
#robot-ai-input::placeholder {
    color: #5a5a5e;
}
.ra-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin: 6px 0 4px 6px;
}
#ra-counter {
    margin-left: auto;
    margin-right: 8px;
}
.ra-upload-btn {
    background: none; border: none; cursor: pointer;
    font-size: 1.05rem; color: #c9a94e; padding: 1px 6px;
    border-radius: 4px; line-height: 1;
    opacity: .85; transition: opacity .2s, background .2s;
}
.ra-expand-btn {
    background: none; border: none; cursor: pointer;
    font-size: .75rem; color: #c9a94e; padding: 2px 5px;
    border-radius: 4px; line-height: 1;
    opacity: .85; transition: opacity .2s, background .2s;
}
.ra-clear-btn {
    background: none; border: none; cursor: pointer;
    font-size: .8rem; color: #c9a94e; padding: 1px 6px;
    border-radius: 4px; line-height: 1;
    opacity: .85; transition: opacity .2s, background .2s;
}
.ra-upload-btn:hover, .ra-expand-btn:hover, .ra-clear-btn:hover {
    opacity: 1; background: rgba(201,169,78,.2); color: #e8c96a;
}
.ra-expand-btn.expanded { opacity: 1; color: #e8c96a; }
.ra-send-btn {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer;
    font-size: 1rem; color: #c9a94e; padding: 2px 6px;
    border-radius: 4px; z-index: 2; line-height: 1;
    opacity: .9; transition: opacity .2s, background .2s;
}
.ra-send-btn:hover { opacity: 1; background: rgba(201,169,78,.15); }
.ra-send-btn:disabled { opacity: .25; cursor: default; }
.ra-send-btn:disabled:hover { background: none; }
#robot-ai-popup.expanded {
    width: min(680px, calc(100vw - 40px));
    max-height: 80vh;
    transition: width .25s ease, max-height .25s ease, transform .25s ease;
}
.ra-input-wrap textarea.expanded {
    min-height: 220px;
}

/* === Loading === */
#robot-ai-loading {
    display: none;
    align-items: center;
    gap: 6px;
    margin-left: 10px;
    font-size: 13px;
    color: #7a7a7e;
}
#robot-ai-loading .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(201, 169, 78, 0.15);
    border-top-color: #c9a94e;
    border-radius: 50%;
    animation: raSpin 0.6s linear infinite;
}
@keyframes raSpin {
    to { transform: rotate(360deg); }
}

@media (max-width: 480px) {
    #robot-ai-popup {
        right: 10px;
        width: calc(100% - 20px);
    }
}

/* Markdown trong search panel + ra-messages */
.search-panel .sp-title strong,
.ra-messages .sp-title strong { color: #e8c96a; }
.search-panel .sp-title em,
.ra-messages .sp-title em { font-style: italic; opacity: 0.9; }
.search-panel .sp-title code,
.ra-messages .sp-title code {
    background: rgba(201,169,78,0.08);
    color: #e8c96a;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.82rem;
    font-family: 'Consolas','Monaco',monospace;
}
.search-panel .sp-title pre,
.ra-messages .sp-title pre {
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(201,169,78,0.1);
    border-radius: 6px;
    padding: 8px 12px;
    margin: 6px 0;
    overflow-x: auto;
    font-size: 0.82rem;
}
.search-panel .sp-title pre code,
.ra-messages .sp-title pre code {
    background: none;
    padding: 0;
    color: #ececed;
}
.search-panel .sp-title a,
.ra-messages .sp-title a {
    color: #c9a94e;
    text-decoration: underline;
}
.search-panel .sp-title h2,
.search-panel .sp-title h3,
.search-panel .sp-title h4,
.ra-messages .sp-title h2,
.ra-messages .sp-title h3,
.ra-messages .sp-title h4 {
    margin: 10px 0 4px;
    color: #ececed;
}
.search-panel .sp-title h2,
.ra-messages .sp-title h2 { font-size: 1rem; }
.search-panel .sp-title h3,
.ra-messages .sp-title h3 { font-size: 0.95rem; }
.search-panel .sp-title h4,
.ra-messages .sp-title h4 { font-size: 0.9rem; }

/* Blockquote + Table + List + hr — bổ sung chuẩn như planners (theme vàng gold) */
.search-panel .sp-title blockquote,
.ra-messages .sp-title blockquote {
    border-left: 3px solid rgba(201,169,78,0.3);
    padding: 6px 14px;
    margin: 8px 0;
    background: rgba(201,169,78,0.04);
    color: #aaa;
    font-style: italic;
}
.search-panel .sp-title ul,
.search-panel .sp-title ol,
.ra-messages .sp-title ul,
.ra-messages .sp-title ol {
    margin: 6px 0;
    padding-left: 20px;
}
.search-panel .sp-title li,
.ra-messages .sp-title li {
    margin: 2px 0;
    font-size: 0.88rem;
}
.search-panel .sp-title table,
.ra-messages .sp-title table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 0.82rem;
}
.search-panel .sp-title th,
.search-panel .sp-title td,
.ra-messages .sp-title th,
.ra-messages .sp-title td {
    padding: 6px 10px;
    border: 1px solid rgba(201,169,78,0.15);
    text-align: left;
}
.search-panel .sp-title th,
.ra-messages .sp-title th { background: rgba(201,169,78,0.08); font-weight: 600; }
.search-panel .sp-title hr,
.ra-messages .sp-title hr {
    border: none;
    border-top: 1px solid rgba(201,169,78,0.15);
    margin: 10px 0;
}
.search-panel .sp-title > p,
.ra-messages .sp-title > p {
    margin: 4px 0;
    line-height: 1.5;
}
.search-panel .sp-title > p:first-child,
.ra-messages .sp-title > p:first-child { margin-top: 0; }
.search-panel .sp-title > p:last-child,
.ra-messages .sp-title > p:last-child { margin-bottom: 0; }

/* sp-item + related classes cho ra-messages */
.ra-messages .sp-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
    text-decoration: none;
    color: var(--text);
    border: 1px solid transparent;
    border-radius: var(--radius);
    transition: background 0.15s, border-color 0.15s;
    margin-bottom: 6px;
}
.ra-messages .sp-item:hover {
    background: rgba(201,169,78,0.05);
    border-color: rgba(201,169,78,0.12);
}
.ra-messages .sp-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
    width: 28px;
    text-align: center;
    margin-top: 2px;
}
.ra-messages .sp-body { flex: 1; min-width: 0; }
.ra-messages .sp-type {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--primary);
    background: rgba(201,169,78,0.08);
    padding: 1px 8px;
    border-radius: 8px;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.ra-messages .sp-highlight {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.ra-messages .sp-highlight b { color: var(--primary); font-weight: 600; }
.ra-messages .sp-more {
    display: block;
    padding: 14px 16px;
    text-align: center;
    font-size: 0.88rem;
    color: var(--primary);
    text-decoration: none;
    border: 1px solid rgba(201,169,78,0.12);
    border-radius: var(--radius);
    margin-top: 8px;
    transition: background 0.15s;
}

/* Mermaid diagrams */
.mermaid { display: flex; justify-content: center; margin: 12px 0; overflow-x: auto; }
.mermaid svg { max-width: 100%; }

/* Streaming cursor */
@keyframes ra-blink { 0%,100%{opacity:1} 50%{opacity:0} }
.ra-cursor { animation: ra-blink 1s step-end infinite; }
.ra-streaming { word-break: break-word; }
/* Thời gian AI trả lời — nhỏ, xám nhẹ */
.ra-time { display: inline-block; font-size: 10px; color: #999; opacity: 0.75; margin-left: 6px; font-weight: 400; vertical-align: middle; }

/* === Robot AI Popup === */

/* Image preview */
#ra-image-preview { display: none; position: relative; margin-top: 6px; }
#ra-image-preview img {
    max-width: 100%; max-height: 120px; border-radius: 8px;
    border: 1px solid rgba(201,169,78,0.15);
    background: rgba(0,0,0,0.2);
    display: block;
}
#ra-remove-img {
    position: absolute; top: 4px; right: 4px;
    background: rgba(0,0,0,0.6); color: #fff; border: none;
    border-radius: 50%; width: 22px; height: 22px;
    font-size: 12px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    line-height: 1; z-index: 2;
}
#ra-remove-img:hover { background: rgba(200,50,50,0.8); }

/* === aiPanel Chat Mode === */
#aiPanel.in-chat {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    height: calc(100vh - var(--sys-bottom, 0px));
    z-index: 999;
    background: var(--surface, #111);
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
}
#aiPanel.in-chat.w34 { width: 34%; min-width: 250px; }
#aiPanel.in-chat.w50 { width: 50%; }
#aiPanel.in-chat.w100 { width: calc(100vw - var(--sb-w, 220px)); }
#aiPanel.in-chat .sp-header {
    flex-shrink: 0;
}
#aiPanel.in-chat .ra-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    padding-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: rgb(12 12 14 / 58%);
}
/* Popup inside panel: no floating styles */
#aiPanel.in-chat #robot-ai-popup {
    position: sticky;
    bottom: 0;
    left: 0;
    width: 100%;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    animation: none;
    z-index: auto;
    margin: 0;
    flex-shrink: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
}
/* Hide drag handle when inside panel */
#aiPanel.in-chat #robot-ai-popup .ra-header {
    display: none;
}
#aiPanel.in-chat #robot-ai-wrap {
    flex-shrink: 0;
}
/* Custom scrollbar for messages */
#aiPanel.in-chat .ra-messages::-webkit-scrollbar { width: 5px; }
#aiPanel.in-chat .ra-messages::-webkit-scrollbar-thumb { background: rgba(201,169,78,0.25); border-radius: 3px; }
#aiPanel.in-chat .ra-messages::-webkit-scrollbar-thumb:hover { background: rgba(201,169,78,0.4); }
#aiPanel.in-chat .ra-messages::-webkit-scrollbar-track { background: transparent; }
/* Firefox */
#aiPanel.in-chat .ra-messages { scrollbar-width: thin; scrollbar-color: rgba(201,169,78,0.25) transparent; }
/* Fullscreen mode */
#aiPanel.in-chat:fullscreen {
    width: 100vw !important;
    left: 0 !important;
    min-width: 0 !important;
    padding: 0;
    background: var(--surface, #111);
}
#aiPanel.in-chat:fullscreen .ra-messages {
    max-width: 800px;
    margin: 0 auto;
    padding: 16px 24px;
}

/* Mobile: full-width panel */
@media (max-width: 768px) {
    #aiPanel.in-chat {
        left: 0 !important;
        width: 100vw !important;
        min-width: 0 !important;
        height: calc(100dvh - var(--sys-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}
