/**
 * ═══════════════════════════════════════════════════════════════════════════
 *  PORIKKHADAW AI CHATBOT — Ultra Clean & Minimalist Design System
 * ═══════════════════════════════════════════════════════════════════════════
 */

:root {
    --ms-bg: #ffffff;
    --ms-viewport-bg: #fafbfc;
    --ms-card-bg: #ffffff;
    --ms-border: #f1f5f9;
    --ms-border-subtle: #e2e8f0;
    --ms-text-main: #0f172a;
    --ms-text-muted: #64748b;
    --ms-text-subtle: #94a3b8;
    --ms-primary: #6366f1;
    --ms-primary-hover: #4f46e5;
    --ms-primary-light: #eef2ff;
    --ms-user-bubble: #6366f1;
    --ms-user-text: #ffffff;
    --ms-bot-bubble: #ffffff;
    --ms-code-bg: #0f172a;
    --ms-code-text: #f8fafc;
    --ms-radius: 16px;
    --ms-radius-sm: 10px;
    --ms-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
    --ms-shadow-md: 0 4px 14px rgba(0, 0, 0, 0.06);
    --ms-shadow-lg: 0 12px 36px -4px rgba(15, 23, 42, 0.14);
}

.dark {
    --ms-bg: #0f172a;
    --ms-viewport-bg: #0b0f19;
    --ms-card-bg: #1e293b;
    --ms-border: #1e293b;
    --ms-border-subtle: #334155;
    --ms-text-main: #f8fafc;
    --ms-text-muted: #94a3b8;
    --ms-text-subtle: #64748b;
    --ms-primary: #818cf8;
    --ms-primary-hover: #6366f1;
    --ms-primary-light: rgba(99, 102, 241, 0.12);
    --ms-user-bubble: #4f46e5;
    --ms-user-text: #ffffff;
    --ms-bot-bubble: #1e293b;
    --ms-code-bg: #020617;
    --ms-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
    --ms-shadow-md: 0 4px 14px rgba(0, 0, 0, 0.3);
    --ms-shadow-lg: 0 12px 36px -4px rgba(0, 0, 0, 0.45);
}

/* ═══════════════════════════════════════════════════
   ✨ FLOATING TRIGGER BUTTON (Bottom-Right)
   ═══════════════════════════════════════════════════ */

.ai-floating-trigger-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1055;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-floating-trigger-btn {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #ffffff;
    border: none;
    box-shadow: 0 8px 24px -2px rgba(99, 102, 241, 0.42);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    outline: none;
}

.ai-floating-trigger-btn:hover {
    transform: scale(1.06) translateY(-2px);
    box-shadow: 0 12px 28px -2px rgba(99, 102, 241, 0.55);
}

.ai-floating-trigger-btn:active {
    transform: scale(0.96);
}

.ai-trigger-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(99, 102, 241, 0.45);
    animation: cleanPulse 2.4s cubic-bezier(0.24, 0, 0.38, 1) infinite;
    pointer-events: none;
}

@keyframes cleanPulse {
    0% { transform: scale(0.95); opacity: 0.8; }
    60% { transform: scale(1.25); opacity: 0; }
    100% { transform: scale(1.25); opacity: 0; }
}

.ai-trigger-icon-close {
    display: none;
    font-size: 1.25rem;
}

.ai-floating-trigger-btn.is-active .ai-trigger-icon-robot {
    display: none;
}
.ai-floating-trigger-btn.is-active .ai-trigger-icon-close {
    display: block;
}
.ai-floating-trigger-btn.is-active .ai-trigger-pulse {
    display: none;
}

.ai-trigger-tooltip {
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: #0f172a;
    color: #ffffff;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.76rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
}

.ai-floating-trigger-btn:hover .ai-trigger-tooltip {
    opacity: 1;
    transform: translateY(-50%) translateX(-2px);
}

/* ═══════════════════════════════════════════════════
   ✨ CLEAN FLOATING CHATBOT MODAL
   ═══════════════════════════════════════════════════ */

.ai-floating-widget {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 410px;
    max-width: calc(100vw - 32px);
    height: 590px;
    max-height: calc(100vh - 115px);
    z-index: 1055;
    background: var(--ms-card-bg);
    border: 1px solid var(--ms-border-subtle);
    border-radius: 20px;
    box-shadow: var(--ms-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease, width 0.25s ease, height 0.25s ease;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

.ai-floating-widget[data-state="closed"] {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.88) translateY(16px);
}

.ai-floating-widget[data-state="open"] {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) translateY(0);
}

.ai-floating-widget.is-expanded {
    width: 740px;
    height: calc(100vh - 110px);
}

@media (max-width: 480px) {
    .ai-floating-widget {
        bottom: 84px;
        right: 12px;
        width: calc(100vw - 24px);
        height: calc(100vh - 98px);
        border-radius: 16px;
    }
}

/* ── Minimalist Clean Header ── */
.ai-widget-header {
    padding: 12px 16px;
    background: var(--ms-card-bg);
    border-bottom: 1px solid var(--ms-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
}

.ai-widget-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.ai-widget-avatar {
    position: relative;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #eef2ff;
    color: var(--ms-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.ai-widget-status-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    border: 2px solid var(--ms-card-bg);
}

.ai-widget-info {
    min-width: 0;
}

.ai-widget-title {
    margin: 0;
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--ms-text-main);
    line-height: 1.2;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-widget-title .ai-badge {
    background: #eef2ff;
    color: var(--ms-primary);
    font-size: 0.64rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
}

.ai-widget-subtitle {
    font-size: 0.72rem;
    color: var(--ms-text-muted);
    display: block;
    line-height: 1.2;
}

.ai-widget-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-widget-persona-select {
    background: #f8fafc;
    border: 1px solid var(--ms-border-subtle);
    border-radius: 8px;
    color: var(--ms-text-main);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 8px;
    outline: none;
    cursor: pointer;
    transition: all 0.15s;
}

.ai-widget-persona-select:hover {
    background: #f1f5f9;
}

.ai-widget-tool-btn {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: transparent;
    border: none;
    color: var(--ms-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    transition: all 0.15s ease;
}

.ai-widget-tool-btn:hover {
    background: #f1f5f9;
    color: var(--ms-text-main);
}

/* ── Settings Drawer ── */
.ai-widget-settings-drawer {
    background: var(--ms-card-bg);
    border-bottom: 1px solid var(--ms-border);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════
   ✨ MESSAGE SCROLLER & CHAT TRANSCRIPT
   ═══════════════════════════════════════════════════ */

.message-scroller-provider {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    overflow: hidden;
}

.message-scroller {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--ms-viewport-bg);
}

.floating-scroller-provider {
    height: calc(100% - 53px);
}

.message-scroller-viewport {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    overscroll-behavior-y: contain;
    position: relative;
    padding: 16px 16px 20px;
    outline: none;
}

.message-scroller-viewport::-webkit-scrollbar {
    width: 5px;
}
.message-scroller-viewport::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.message-scroller-content {
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ── Welcome Minimal Hero Card ── */
.welcome-hero-clean {
    text-align: center;
    padding: 18px 12px 10px;
}

.welcome-hero-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #eef2ff;
    color: var(--ms-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    margin-bottom: 10px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.12);
}

.welcome-hero-clean h6 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ms-text-main);
    margin-bottom: 4px;
}

.welcome-hero-clean p {
    font-size: 0.78rem;
    color: var(--ms-text-muted);
    margin-bottom: 12px;
}

.welcome-chip-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

.welcome-chip-btn {
    background: var(--ms-card-bg);
    border: 1px solid var(--ms-border-subtle);
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--ms-text-main);
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: var(--ms-shadow-sm);
}

.welcome-chip-btn:hover {
    border-color: var(--ms-primary);
    color: var(--ms-primary);
    background: #eef2ff;
    transform: translateY(-1px);
}

/* ── Turn: User Message (Clean Modern Bubble) ── */
.message-scroller-item {
    content-visibility: auto;
    contain-intrinsic-size: 60px;
    display: flex;
    flex-direction: column;
}

.turn-user {
    align-self: flex-end;
    max-width: 82%;
}

.user-bubble {
    background: var(--ms-user-bubble);
    color: var(--ms-user-text);
    padding: 9px 14px;
    border-radius: 16px 16px 4px 16px;
    font-size: 0.88rem;
    line-height: 1.45;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
    word-break: break-word;
}

.turn-meta {
    font-size: 0.68rem;
    color: var(--ms-text-subtle);
    margin-top: 3px;
    padding: 0 2px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.turn-user .turn-meta {
    justify-content: flex-end;
}

/* ── Turn: Assistant Message (Seamless Clean Card) ── */
.turn-assistant {
    align-self: flex-start;
    width: 100%;
    max-width: 100%;
}

.assistant-card {
    background: var(--ms-bot-bubble);
    border: 1px solid var(--ms-border);
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: var(--ms-shadow-sm);
    color: var(--ms-text-main);
    font-size: 0.88rem;
    line-height: 1.6;
    position: relative;
    word-break: break-word;
}

.assistant-card h1, .assistant-card h2, .assistant-card h3, .assistant-card h4, .assistant-card h5, .assistant-card h6 {
    margin-top: 10px;
    margin-bottom: 6px;
    font-weight: 700;
    color: var(--ms-text-main);
    line-height: 1.3;
}
.assistant-card h1 { font-size: 1.15rem; }
.assistant-card h2 { font-size: 1.05rem; }
.assistant-card h3, .assistant-card h4, .assistant-card h5, .assistant-card h6 { font-size: 0.95rem; }

.assistant-card p {
    margin-bottom: 8px;
}
.assistant-card p:last-child {
    margin-bottom: 0;
}

.assistant-card ul, .assistant-card ol {
    margin-bottom: 8px;
    padding-left: 18px;
}

.assistant-card li {
    margin-bottom: 3px;
}

.assistant-card blockquote {
    border-left: 3px solid var(--ms-primary);
    padding: 6px 10px;
    margin: 8px 0;
    color: var(--ms-text-muted);
    background: #f8fafc;
    border-radius: 0 6px 6px 0;
    font-size: 0.84rem;
}

/* Clean Math Formulas */
.katex-display {
    margin: 10px 0 !important;
    padding: 8px 12px !important;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #f1f5f9;
    overflow-x: auto;
}

/* Clean Code Blocks */
.assistant-card pre {
    background: var(--ms-code-bg);
    color: var(--ms-code-text);
    padding: 12px 14px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.8rem;
    margin: 10px 0;
}

.assistant-card code:not(pre code) {
    background: #eef2ff;
    color: var(--ms-primary);
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.84em;
    font-family: 'Fira Code', 'Consolas', monospace;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1e293b;
    color: #94a3b8;
    padding: 5px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 8px 8px 0 0;
    border-bottom: 1px solid #334155;
}

.code-copy-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.72rem;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 5px;
    border-radius: 4px;
    transition: all 0.15s;
}

.code-copy-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* Streaming Cursor */
.streaming-cursor {
    display: inline-block;
    width: 6px;
    height: 14px;
    background: var(--ms-primary);
    vertical-align: middle;
    margin-left: 2px;
    animation: blinkCursor 0.8s infinite;
}

@keyframes blinkCursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Action Bar below response */
.turn-action-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--ms-border);
}

.action-btn-sm {
    background: transparent;
    border: none;
    color: var(--ms-text-muted);
    font-size: 0.72rem;
    font-weight: 500;
    border-radius: 5px;
    padding: 2px 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
}

.action-btn-sm:hover {
    background: #f1f5f9;
    color: var(--ms-text-main);
}

/* ── Jump to Latest Button ── */
.message-scroller-button {
    position: absolute;
    bottom: 84px;
    left: 50%;
    transform: translateX(-50%) translateY(14px);
    background: #0f172a;
    color: #ffffff;
    border: none;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.message-scroller-button[data-active="true"] {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

.message-scroller-button:hover {
    background: #1e293b;
    transform: translateX(-50%) translateY(-2px);
}

.scroller-badge-pulse {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    animation: pulseDot 1.4s infinite;
}

@keyframes pulseDot {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { box-shadow: 0 0 0 5px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* ═══════════════════════════════════════════════════
   ✨ CLEAN PROMPT INPUT DOCK
   ═══════════════════════════════════════════════════ */

.scroller-input-dock {
    padding: 10px 14px 14px;
    background: var(--ms-card-bg);
    border-top: 1px solid var(--ms-border);
    position: relative;
    z-index: 20;
}

.quick-prompts-row {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 4px;
    scrollbar-width: none;
}
.quick-prompts-row::-webkit-scrollbar { display: none; }

.quick-chip {
    background: #f8fafc;
    border: 1px solid var(--ms-border-subtle);
    color: var(--ms-text-muted);
    border-radius: 16px;
    padding: 3px 10px;
    font-size: 0.72rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.quick-chip:hover {
    background: #eef2ff;
    color: var(--ms-primary);
    border-color: rgba(99, 102, 241, 0.25);
}

.prompt-input-container {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    background: #f8fafc;
    border: 1px solid var(--ms-border-subtle);
    border-radius: 20px;
    padding: 5px 6px 5px 14px;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.prompt-input-container:focus-within {
    border-color: var(--ms-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
    background: #ffffff;
}

.prompt-textarea {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--ms-text-main);
    font-size: 0.88rem;
    line-height: 1.4;
    resize: none;
    max-height: 120px;
    min-height: 22px;
    padding: 4px 0;
    font-family: inherit;
}

.prompt-textarea::placeholder {
    color: var(--ms-text-subtle);
}

.prompt-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.send-prompt-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--ms-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.send-prompt-btn:hover:not(:disabled) {
    background: var(--ms-primary-hover);
    transform: scale(1.05);
}

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

.stop-gen-btn {
    background: #ef4444;
    color: #fff;
}
.stop-gen-btn:hover {
    background: #dc2626 !important;
}

/* History Load Row */
.load-history-banner {
    display: flex;
    justify-content: center;
    padding: 4px 0 10px;
}

.load-history-btn {
    background: var(--ms-card-bg);
    border: 1px solid var(--ms-border-subtle);
    color: var(--ms-text-muted);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 0.74rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    box-shadow: var(--ms-shadow-sm);
    transition: all 0.15s ease;
}

.load-history-btn:hover {
    background: #eef2ff;
    color: var(--ms-primary);
    border-color: rgba(99, 102, 241, 0.25);
}
/* ── AI Sparkle SVG Icon Styles ── */
.ai-sparkle-svg {
    display: inline-block;
    vertical-align: middle;
    width: 24px;
    height: 24px;
    color: currentColor;
    transition: transform 0.25s ease;
}

.ai-sparkle-svg-sm {
    display: inline-block;
    vertical-align: middle;
    width: 18px;
    height: 18px;
    color: var(--ms-primary);
}

.ai-trigger-icon-main {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-floating-trigger-btn.is-active .ai-trigger-icon-main {
    display: none;
}

.ai-floating-trigger-btn:hover .ai-sparkle-svg {
    transform: rotate(15deg) scale(1.1);
}