/**
 * Chat Interface V2
 * Mobile-first chat interface similar to ChatGPT/Claude
 */

/* ==================== Chat Container ==================== */
.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
    min-height: 0; /* Important for flex children to respect overflow */
    position: relative; /* For scroll-to-bottom button positioning */
    background: var(--color-bg-primary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

/* ==================== Chat Page Layout ==================== */
/* Make chat page fixed height - no page scroll, only messages scroll */
/* Using dvh (dynamic viewport height) for iOS Safari compatibility */
.chat-page {
    height: 100vh;
    height: 100dvh; /* Fallback for browsers that support dvh */
    overflow: hidden;
}

.chat-page .app-layout {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.chat-page .app-main {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.chat-page .app-mobile-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    margin-top: var(--mobile-header-height);
    margin-bottom: 0; /* No footer on chat page */
}

.chat-page .app-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

/* Hide mobile footer on chat page */
.chat-page .app-mobile-footer {
    display: none !important;
}

/* Desktop: account for sidebar */
@media (min-width: 1024px) {
    .chat-page .app-main {
        height: 100vh;
        height: 100dvh;
        margin-left: var(--sidebar-width);
    }
    
    .chat-page .app-mobile-content {
        margin-top: 0;
    }
    
    .chat-page .app-sidebar.collapsed ~ .app-main {
        margin-left: var(--sidebar-collapsed-width);
    }
}

/* Desktop padding for chat page */
@media (min-width: 768px) {
    .chat-page .app-content {
        padding: var(--space-md) !important;
    }
}

@media (min-width: 1024px) {
    .chat-page .app-content {
        padding: var(--space-lg) !important;
    }
}

/* ==================== Mobile Chat Layout ==================== */
@media (max-width: 1023px) {
    .chat-page .app-content {
        padding: var(--space-md) !important;
    }
    
    /* Full-screen chat mode on mobile */
    .chat-container.mobile-active {
        position: fixed;
        top: var(--mobile-header-height);
        left: 0;
        right: 0;
        bottom: 0;
        z-index: var(--z-fixed);
        background: var(--color-bg-secondary);
    }
    
    /* Hide mobile footer when chat is active */
    body.chat-mode-active .app-mobile-footer.nav-footer {
        display: none;
    }
    
    body.chat-mode-active .chat-footer-input {
        bottom: 0;
    }
}

/* ==================== Chat Messages Area ==================== */
.chat-messages {
    flex: 1;
    min-height: 0; /* Critical for flex child to scroll */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    position: relative;
}

@media (min-width: 768px) {
    .chat-messages {
        padding: var(--space-lg);
    }
}

/* Scroll to Bottom Button - floats above input area */
.chat-scroll-to-bottom {
    position: absolute;
    right: 20px;
    bottom: var(--scroll-btn-bottom, 100px); /* Will be updated by JS */
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-bg-tertiary);
    color: var(--color-primary);
    border: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: none; /* Hidden by default, shown via JS */
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    z-index: 50;
}

/* Show button */
.chat-scroll-to-bottom.show {
    display: flex;
}

.chat-scroll-to-bottom:hover {
    background: var(--color-bg-secondary);
    transform: scale(1.1);
    box-shadow: var(--shadow-xl);
}

.chat-scroll-to-bottom:active {
    transform: scale(0.95);
}

/* Empty state */
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.chat-empty-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: var(--space-xl);
}

/* Suggestion chips in empty state */
.chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    width: 100%;
    max-width: 100%;
}

.chat-suggestion-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-primary);
}

.chat-suggestion-chip:hover {
    background: var(--color-bg-card-hover);
    border-color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

@media (min-width: 768px) {
    .chat-suggestions {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-md);
    }
    
    /* Center the 5th chip if there are 5 items */
    .chat-suggestion-chip:nth-child(5):last-child {
        grid-column: 1 / -1;
        max-width: 50%;
        margin: 0 auto;
    }
}

/* ==================== Chat Message Bubbles ==================== */
.chat-message {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    margin-bottom: var(--space-lg);
    animation: fadeInUp 0.3s ease-out;
    width: 100%;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.chat-message-sender-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.chat-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
}

.chat-message-user .chat-message-avatar {
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
}

.chat-message-assistant .chat-message-avatar {
    background: var(--color-bg-tertiary);
    color: var(--color-primary);
}

.chat-message-sender {
    font-weight: 600;
    font-size: 0.875rem;
}

.chat-message-user .chat-message-sender {
    color: var(--color-text-primary);
}

.chat-message-assistant .chat-message-sender {
    color: var(--color-text-primary);
}

.chat-message-time {
    font-size: 0.75rem;
    color: var(--color-text-tertiary);
}

.chat-message-content {
    width: 100%;
}

/* Chat Message Actions (feedback + copy) */
.chat-message-content {
    position: relative;
}

.chat-message-actions {
    display: flex;
    gap: 2px;
    justify-content: flex-end;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.chat-message-content:hover .chat-message-actions,
.chat-message-actions:has(.active) {
    opacity: 1;
}

.chat-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    transition: color 0.1s ease, background 0.1s ease;
    font-size: 12px;
}

.chat-action-btn:hover {
    background: #f1f5f9;
    color: #64748b;
}

.chat-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-action-btn.active.liked {
    color: #16a34a;
}

.chat-action-btn.active.disliked {
    color: #dc2626;
}

.chat-action-btn.copied {
    color: #16a34a;
}

.chat-action-btn.loading i.fa-spinner {
    display: inline-block;
    animation: action-spin 0.6s linear infinite;
}

@keyframes action-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.chat-message-text {
    color: var(--color-text-primary);
    line-height: 1.6;
    word-wrap: break-word;
}

/* AI message HTML formatting */
.chat-message-assistant .chat-message-text hr {
    border: 0;
    height: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    margin: 16px 0;
}

.chat-message-assistant .chat-message-text h1,
.chat-message-assistant .chat-message-text h2,
.chat-message-assistant .chat-message-text h3,
.chat-message-assistant .chat-message-text h4 {
    margin: var(--space-md) 0 var(--space-sm) 0 !important;
    color: var(--color-text-primary) !important;
    line-height: 1.3 !important;
    font-weight: 600 !important;
}

.chat-message-assistant .chat-message-text h3 {
    font-size: 1.125rem !important;
}

.chat-message-assistant .chat-message-text h2 {
    font-size: 1.25rem !important;
}

.chat-message-assistant .chat-message-text h1 {
    font-size: 1.5rem !important;
}

.chat-message-assistant .chat-message-text p {
    margin: var(--space-sm) 0 !important;
    line-height: 1.6 !important;
}

.chat-message-assistant .chat-message-text ul,
.chat-message-assistant .chat-message-text ol {
    margin: var(--space-sm) 0 !important;
    padding-left: var(--space-xl) !important;
    list-style-position: outside !important;
}

.chat-message-assistant .chat-message-text ul {
    list-style-type: disc !important;
}

.chat-message-assistant .chat-message-text ol {
    list-style-type: decimal !important;
}

.chat-message-assistant .chat-message-text li {
    margin: var(--space-xs) 0 !important;
    line-height: 1.6 !important;
}

.chat-message-assistant .chat-message-text a {
    color: var(--color-primary) !important;
    text-decoration: underline !important;
}

.chat-message-assistant .chat-message-text a:hover {
    color: var(--color-primary-hover) !important;
}

.chat-message-assistant .chat-message-text strong {
    font-weight: 600 !important;
    color: var(--color-text-primary) !important;
}

.chat-message-assistant .chat-message-text em {
    font-style: italic !important;
}

.chat-message-assistant .chat-message-text code {
    background: var(--color-bg-secondary) !important;
    padding: 2px 6px !important;
    border-radius: var(--radius-sm) !important;
    font-family: 'Courier New', monospace !important;
    font-size: 0.875em !important;
}

.chat-message-assistant .chat-message-text blockquote {
    border-left: 3px solid var(--color-primary) !important;
    padding-left: var(--space-md) !important;
    margin: var(--space-sm) 0 !important;
    font-style: italic !important;
    color: var(--color-text-secondary) !important;
}

.chat-message-bubble {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-lg);
    line-height: 1.6;
    word-wrap: break-word;
}

.chat-message.ai .chat-message-bubble {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
}

.chat-message.user .chat-message-bubble {
    background: var(--color-primary);
    color: white;
}

.chat-message-time {
    font-size: 0.75rem;
    color: var(--color-text-tertiary);
    display: block;
}

/* Typing indicator */
.chat-typing-indicator {
    display: flex;
    gap: 0.25rem;
    padding: var(--space-sm);
}

.chat-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--color-text-tertiary);
    border-radius: 50%;
    animation: pulse 1.4s infinite;
}

.chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* ==================== Chat Input Area (Mobile) ==================== */
.chat-footer-input {
    position: fixed;
    bottom: var(--mobile-footer-height);
    left: 0;
    right: 0;
    background: var(--color-bg-primary);
    border-top: 1px solid var(--color-border);
    padding: var(--space-md);
    z-index: var(--z-sticky);
}

@media (min-width: 1024px) {
    .chat-footer-input {
        position: relative;
        bottom: 0;
        border-top: 1px solid var(--color-border);
    }
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-xs);
    transition: all var(--transition-base);
}

.chat-input-wrapper:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.chat-input-actions-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-input-actions-btn:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
}

.chat-input-actions-btn.active {
    background: var(--color-primary);
    color: white;
}

.chat-input-field {
    flex: 1;
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.9375rem;
    font-family: var(--font-primary);
    background: transparent;
    border: none;
    outline: none;
    color: var(--color-text-primary);
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
}

.chat-input-field::placeholder {
    color: var(--color-text-tertiary);
}

.chat-input-send-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-tertiary);
    border: none;
    border-radius: 50%;
    color: var(--color-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-input-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: var(--shadow-glow);
}

.chat-input-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.chat-input-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==================== Bottom Sheet (Mobile Options) ==================== */
.chat-bottom-sheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-modal-backdrop);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.chat-bottom-sheet-overlay.active {
    display: block;
    opacity: 1;
}

.chat-bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-bg-primary);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    z-index: var(--z-modal);
    transform: translateY(100%);
    transition: transform var(--transition-base);
    max-height: 80vh;
    max-height: 80dvh;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.chat-bottom-sheet.active {
    transform: translateY(0);
}

.chat-bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--color-border);
    border-radius: var(--radius-full);
    margin: var(--space-sm) auto;
}

.chat-bottom-sheet-header {
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--color-border);
}

.chat-bottom-sheet-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.chat-bottom-sheet-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
}

.chat-option-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.chat-option-item:hover {
    background: var(--color-bg-tertiary);
}

.chat-option-item.active {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid var(--color-primary);
}

.chat-option-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-primary);
    border-radius: var(--radius-md);
    font-size: 1.25rem;
}

.chat-option-content {
    flex: 1;
}

.chat-option-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: 2px;
}

.chat-option-description {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

.chat-option-toggle {
    width: 48px;
    height: 28px;
    background: var(--color-border);
    border-radius: var(--radius-full);
    position: relative;
    transition: background var(--transition-fast);
}

.chat-option-item.active .chat-option-toggle {
    background: var(--color-primary);
}

.chat-option-toggle::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition-fast);
}

.chat-option-item.active .chat-option-toggle::after {
    transform: translateX(20px);
}

/* ==================== Chat History Sidebar (Mobile) ==================== */
.chat-history-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-modal-backdrop);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.chat-history-overlay.active {
    display: block;
    opacity: 1;
}

.chat-history-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80%;
    max-width: 320px;
    background: var(--color-bg-primary);
    z-index: var(--z-modal);
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.chat-history-sidebar.active {
    transform: translateX(0);
}

.chat-history-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-history-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.chat-history-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.chat-history-close:hover {
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
}

.chat-history-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: var(--space-xs);
}

.chat-history-item:hover {
    background: var(--color-bg-secondary);
}

.chat-history-item.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--color-primary);
    font-weight: 600;
}

.chat-history-item-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.chat-history-item.active .chat-history-item-icon {
    background: var(--color-primary);
    color: white;
}

.chat-history-item-content {
    flex: 1;
    min-width: 0;
}

.chat-history-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history-item-time {
    font-size: 0.75rem;
    color: var(--color-text-tertiary);
}

/* ==================== Desktop Chat Layout ==================== */
@media (min-width: 1024px) {
    .chat-messages {
        padding: var(--space-xl);
    }
    
    .chat-footer-input {
        padding: var(--space-lg);
    }
    
    .chat-empty-title {
        font-size: 2rem;
    }
}

/* ==================== Responsive Adjustments ==================== */
@media (max-width: 480px) {
    .chat-empty-title {
        font-size: 1.25rem;
    }
    
    .chat-message-content {
        max-width: 85%;
    }
    
    .chat-message-avatar {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }
}

/* Hide floating chat button */
.chat-fab,
.chat-floating-button,
.ai-chat-button {
    display: none !important;
}

/* ==================== Chat Header ==================== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-primary);
    flex-shrink: 0;
}

.chat-header-left {
    flex: 1;
}

.chat-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.chat-header-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none; /* Remove underline for links */
}

.chat-header-btn:hover {
    background: var(--color-bg-secondary);
    border-color: var(--color-primary);
    color: var(--color-primary);
    text-decoration: none; /* Ensure no underline on hover */
}

@media (max-width: 768px) {
    .chat-header {
        padding: var(--space-sm) var(--space-md);
    }
    
    .chat-title {
        font-size: 1rem;
    }
}

/* ==================== Chat Input Area (Desktop) ==================== */
.chat-input-area {
    padding: var(--space-sm) var(--space-md);
    padding-bottom: calc(var(--space-sm) + env(safe-area-inset-bottom, 0px));
    background: var(--color-bg-primary);
    border-top: 1px solid var(--color-border);
    position: relative;
    flex-shrink: 0;
    overflow: visible;
}

/* AI Disclaimer Row (below input) */
.chat-disclaimer-row {
    padding: 6px 12px 8px;
    display: flex;
    justify-content: flex-start;
}

/* ==================== Unified Chips Container ==================== */
.chat-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: var(--space-sm);
    padding: 0 2px;
}

.chat-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.chat-chip:hover {
    background: var(--color-bg-secondary);
    border-color: var(--color-primary);
    color: var(--color-text-primary);
}

.chat-chip i {
    font-size: 0.7rem;
    opacity: 0.8;
}

.chat-chip-remove {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 50%;
    color: currentColor;
    cursor: pointer;
    padding: 0;
    margin-left: 2px;
    transition: background var(--transition-fast);
}

.chat-chip-remove:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* Chip color variants */
.chat-chip.portfolio {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.3);
    color: rgb(59, 130, 246);
}

.chat-chip.web-search {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
    color: rgb(16, 185, 129);
}

.chat-chip.instrument {
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.3);
    color: rgb(139, 92, 246);
}

.chat-chip.report {
    background: rgba(236, 72, 153, 0.1);
    border-color: rgba(236, 72, 153, 0.3);
    color: rgb(236, 72, 153);
}

.chat-chip.news {
    background: rgba(14, 165, 233, 0.1);
    border-color: rgba(14, 165, 233, 0.3);
    color: rgb(14, 165, 233);
}

/* Mobile optimization */
@media (max-width: 768px) {
    .chat-chips-container {
        gap: 4px;
    }
    
    .chat-chip {
        padding: 3px 8px;
        font-size: 0.7rem;
        gap: 4px;
    }
}

/* ==================== Two-tier Input Container ==================== */
.chat-input-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--color-bg-secondary);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: 8px;
    transition: border-color var(--transition-fast);
    min-height: 56px;
    overflow: visible;
}

.chat-input-container:focus-within {
    border-color: var(--color-primary);
}

/* Text wrapper for inline dropdown positioning */
.chat-input-text-wrapper {
    position: relative;
    overflow: visible;
}

/* Bottom row: actions + model + send */
.chat-input-bottom-row {
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
    overflow: visible;
}

/* Left action buttons container (includes model selector) */
.chat-input-actions-left {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

/* Spacer to push send button to the right */
.chat-input-spacer {
    flex: 1;
}

/* Action buttons inside input */
.chat-input-action-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    font-size: 0.875rem;
}

.chat-input-action-btn:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
}

.chat-input-action-btn.active {
    background: var(--color-primary);
    color: white;
}

.chat-input-action-btn.active:hover {
    background: var(--color-primary-hover);
}

.chat-input {
    width: 100%;
    padding: 4px 4px 8px 4px;
    font-size: 0.9375rem;
    font-family: var(--font-primary);
    background: transparent;
    border: none;
    outline: none;
    color: var(--color-text-primary);
    resize: none;
    max-height: 120px;
    min-height: 24px;
    overflow-y: auto;
    line-height: 1.5;
}

.chat-input::placeholder {
    color: var(--color-text-tertiary);
}

/* ContentEditable specific styles */
.chat-input-editable {
    overflow-wrap: break-word;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-input-editable:empty:before {
    content: attr(data-placeholder);
    color: var(--color-text-tertiary);
    pointer-events: none;
}

/* Inline ticker chips inside input */
.chat-input-editable .inline-ticker-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    margin: 0 2px;
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.4);
    border-radius: var(--radius-full);
    font-size: 0.875em;
    font-weight: 600;
    color: rgb(139, 92, 246);
    cursor: pointer;
    vertical-align: middle;
    user-select: none;
    white-space: nowrap;
}

.inline-ticker-chip:hover {
    background: rgba(139, 92, 246, 0.25);
    border-color: rgba(139, 92, 246, 0.6);
}

.inline-ticker-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 2px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    font-size: 0.7em;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.inline-ticker-chip-remove:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* ==================== Model Selector ==================== */
.chat-model-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    margin-left: 6px;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 0.75rem;
    font-weight: 500;
    flex-shrink: 0;
}

.chat-model-btn:hover {
    background: var(--color-bg-tertiary);
    border-color: var(--color-primary);
    color: var(--color-text-primary);
}

.chat-model-btn i {
    font-size: 0.7rem;
}

#chat-model-name {
    white-space: nowrap;
}

/* Model Dropdown (Compact) */
.chat-model-dropdown {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 8px;
    width: 300px;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    z-index: 100;
    overflow: hidden;
}

@media (max-width: 768px) {
    .chat-model-dropdown {
        width: 260px;
    }
}

.chat-model-option {
    padding: 8px 10px;
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--color-border);
}

.chat-model-option:last-child {
    border-bottom: none;
}

.chat-model-option:hover {
    background: var(--color-bg-secondary);
}

.chat-model-option.active {
    background: rgba(99, 102, 241, 0.1);
    border-left: 3px solid var(--color-primary);
}

.chat-model-option-name {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--color-text-primary);
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-model-badge {
    display: inline-flex;
    padding: 2px 6px;
    background: var(--color-primary);
    color: white;
    border-radius: var(--radius-full);
    font-size: 0.6875rem; /* 11px - minimum for badges per HIG */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.chat-model-option-desc {
    font-size: 0.7rem;
    color: var(--color-text-secondary);
}

.chat-send-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-tertiary); 
    border: none;
    border-radius: 50%;
    color: var(--color-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--color-bg-secondary);
    transform: scale(1.05);
}

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

/* Character counter */
.chat-char-counter {
    font-size: 12px;
    color: var(--color-text-tertiary);
    margin-right: 8px;
    white-space: nowrap;
}

.chat-char-counter.near-limit {
    color: var(--color-warning, #f59e0b);
}

.chat-char-counter.over-limit {
    color: var(--color-danger, #ef4444);
    font-weight: 600;
}

/* ==================== Chat Options Panel (Removed - now using inline buttons) ==================== */

/* ==================== Context Selector Dropdown (Compact) ==================== */
.chat-context-selector {
    width: 320px;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    z-index: 100;
    overflow: hidden;
}

/* Inline mode: positioned above text input */
.chat-context-selector-inline {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
}

/* Button mode: positioned above bottom row */
.chat-context-selector-button {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 8px;
}

@media (max-width: 768px) {
    .chat-context-selector {
        width: 280px;
    }
}

.chat-context-search-wrapper {
    padding: 6px;
    border-bottom: 1px solid var(--color-border);
}

.chat-context-search-input {
    width: 100%;
    padding: 6px 8px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    color: var(--color-text-primary);
    outline: none;
    transition: border-color var(--transition-fast);
}

.chat-context-search-input:focus {
    border-color: var(--color-primary);
}

.chat-context-search-input::placeholder {
    color: var(--color-text-tertiary);
}

.chat-context-results {
    max-height: 240px;
    overflow-y: auto;
    padding: 4px;
}

.chat-context-result-item {
    display: flex;
    flex-direction: column;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chat-context-result-item:hover {
    background: var(--color-bg-secondary);
}

.chat-context-result-item.highlighted {
    background: rgba(99, 102, 241, 0.1);
    border-left: 3px solid var(--color-primary);
}

.chat-context-result-symbol {
    font-weight: 600;
    color: var(--color-text-primary);
    font-size: 0.875rem;
}

.chat-context-result-name {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-context-empty {
    padding: 12px;
    text-align: center;
    color: var(--color-text-tertiary);
    font-size: 0.75rem;
}

/* ==================== Message Styling ==================== */
.chat-message-user .chat-message-avatar {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
}

.chat-message-assistant .chat-message-avatar {
    background: var(--color-bg-tertiary);
    color: var(--color-primary);
}

.chat-message-text {
    line-height: 1.6;
    color: var(--color-text-primary);
}

.chat-message-user .chat-message-text {
    color: var(--color-text-primary);
}

/* ==================== Responsive Adjustments ==================== */
@media (max-width: 768px) {
    .chat-input-area {
        padding: var(--space-xs) var(--space-sm);
    }
    
    .chat-context-selector {
        max-width: 100%;
    }
}

/* Agent Status Indicator (standalone) */
.agent-status-indicator {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin: 8px 0;
    background: rgba(99, 102, 241, 0.1);
    border-left: 3px solid #6366f1;
    border-radius: 8px;
    font-size: 14px;
    color: #6366f1;
    animation: fadeIn 0.3s ease;
}

.agent-status-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Agent Status Inline (inside message) */
.agent-status-inline {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(99, 102, 241, 0.05);
    border-left: 3px solid rgba(99, 102, 241, 0.3);
    border-radius: 8px;
    font-size: 14px;
    color: rgba(99, 102, 241, 0.9);
    animation: fadeIn 0.3s ease;
}

.agent-status-inline .agent-status-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.agent-status-inline .agent-status-text {
    flex: 1;
    line-height: 1.5;
}

.agent-status-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.agent-status-icon .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(99, 102, 241, 0.2);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.agent-status-icon .fa-tools,
.agent-status-icon .fa-comment-dots,
.agent-status-icon .fa-spinner {
    font-size: 16px;
    color: #6366f1;
}

.agent-status-inline .agent-status-icon .fa-tools,
.agent-status-inline .agent-status-icon .fa-comment-dots,
.agent-status-inline .agent-status-icon .fa-spinner {
    font-size: 16px;
    color: rgba(99, 102, 241, 0.9);
}

/* Agent Thinking Text - intermediate reasoning shown under status */
.agent-thinking-text {
    margin-top: 12px;
    padding: 10px 14px;
    background: rgba(99, 102, 241, 0.03);
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--color-text-tertiary);
    max-height: 300px;
    overflow-y: auto;
    word-break: break-word;
    opacity: 0.8;
}

/* Markdown formatting in thinking text */
.agent-thinking-text p {
    margin: 0 0 8px 0;
}

.agent-thinking-text p:last-child {
    margin-bottom: 0;
}

.agent-thinking-text ul, .agent-thinking-text ol {
    margin: 8px 0;
    padding-left: 20px;
}

.agent-thinking-text code {
    background: rgba(99, 102, 241, 0.1);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 12px;
}

.agent-thinking-text:empty {
    display: none;
}

.agent-thinking-text:hover {
    opacity: 1;
}

/* Scrollbar for thinking text */
.agent-thinking-text::-webkit-scrollbar {
    width: 4px;
}

.agent-thinking-text::-webkit-scrollbar-track {
    background: transparent;
}

.agent-thinking-text::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.2);
    border-radius: 2px;
}

.pulse-animation {
    animation: pulse 0.3s ease;
}

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

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

/* Thinking indicator with animated dots */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(99, 102, 241, 0.05);
    border-left: 3px solid rgba(99, 102, 241, 0.3);
    border-radius: 8px;
    font-size: 14px;
    color: rgba(99, 102, 241, 0.9);
    animation: fadeIn 0.3s ease;
}

.thinking-indicator-text {
    display: flex;
    align-items: center;
    gap: 2px;
}

.thinking-dot {
    display: inline-block;
    width: 4px;
    height: 4px;
    background: rgba(99, 102, 241, 0.9);
    border-radius: 50%;
    animation: thinkingDot 1.4s infinite;
}

.thinking-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

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

/* Context stats display */
.chat-context-stats {
    position: absolute;
    bottom: 80px;
    right: 20px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    font-size: 12px;
    color: #fff;
    font-family: 'Monaco', monospace;
    z-index: 10;
    pointer-events: none;
}

.context-stats-bar {
    width: 100px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
}

.context-stats-fill {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #f59e0b, #ef4444);
    transition: width 0.3s ease;
}

/* Mobile adjustment */
@media (max-width: 768px) {
    .chat-context-stats {
        bottom: 70px;
        right: 10px;
        font-size: 10px;
    }
    
    .context-stats-bar {
        width: 80px;
    }
}

/* ==================== Markdown Tables ==================== */
.ai-chat-bubble .markdown-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ai-chat-bubble .markdown-table thead {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
}

.ai-chat-bubble .markdown-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.ai-chat-bubble .markdown-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
    color: #334155;
}

.ai-chat-bubble .markdown-table tbody tr:last-child td {
    border-bottom: none;
}

.ai-chat-bubble .markdown-table tbody tr:hover {
    background-color: #f8fafc;
}

.ai-chat-bubble .markdown-table tbody tr:nth-child(even) {
    background-color: #f8fafc;
}

.ai-chat-bubble .markdown-table tbody tr:nth-child(even):hover {
    background-color: #f1f5f9;
}

/* Responsive table on mobile */
@media (max-width: 640px) {
    .ai-chat-bubble .markdown-table {
        font-size: 11px;
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .ai-chat-bubble .markdown-table th,
    .ai-chat-bubble .markdown-table td {
        padding: 8px 10px;
        min-width: 80px;
    }
}

/* ==================== AI Action Buttons ==================== */
.chat-action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
}

.chat-action-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.chat-action-button i {
    font-size: 0.9rem;
}

/* Primary action - Add to Portfolio */
.chat-action-button.action-portfolio {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border-color: transparent;
}

.chat-action-button.action-portfolio:hover {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* Secondary action - Add to Watchlist */
.chat-action-button.action-watchlist {
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    border-color: var(--color-border);
}

.chat-action-button.action-watchlist:hover {
    background: var(--color-bg-tertiary);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* Tertiary action - View Report */
.chat-action-button.action-report {
    background: transparent;
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.chat-action-button.action-report:hover {
    background: var(--color-primary);
    color: white;
}

/* Loading state */
.chat-action-button.loading {
    opacity: 0.7;
    pointer-events: none;
}

.chat-action-button.loading i {
    animation: spin 1s linear infinite;
}

/* Success state */
.chat-action-button.success {
    background: #10b981 !important;
    color: white !important;
    border-color: transparent !important;
}

/* Mobile responsive */
@media (max-width: 640px) {
    .chat-action-buttons {
        flex-direction: column;
    }
    
    .chat-action-button {
        width: 100%;
        justify-content: center;
    }
}

/* ==================== Portfolio Add Modal ==================== */
.chat-portfolio-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.chat-portfolio-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.chat-portfolio-modal-content {
    position: relative;
    background: var(--color-bg-primary);
    border-radius: 12px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chat-portfolio-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.chat-portfolio-modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.chat-portfolio-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--color-text-tertiary);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.chat-portfolio-modal-close:hover {
    color: var(--color-text-primary);
}

.chat-portfolio-modal-body {
    padding: 20px;
    max-height: 50vh;
    overflow-y: auto;
}

.chat-portfolio-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 20px;
    color: var(--color-text-secondary);
}

.chat-portfolio-loading i {
    font-size: 1.25rem;
}

.chat-portfolio-positions {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-portfolio-position {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 12px 16px;
}

.chat-portfolio-position-header {
    margin-bottom: 12px;
}

.chat-portfolio-position-ticker {
    font-weight: 700;
    color: var(--color-primary);
    margin-right: 8px;
}

.chat-portfolio-position-name {
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}

.chat-portfolio-position-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.chat-portfolio-input-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 4px;
}

.chat-portfolio-input-group input {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.9375rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    transition: border-color 0.2s;
}

.chat-portfolio-input-group input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.chat-portfolio-modal-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 16px 20px;
    border-top: 1px solid var(--color-border);
}

.chat-portfolio-btn-cancel {
    padding: 10px 20px;
    font-size: 0.875rem;
    font-weight: 500;
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-portfolio-btn-cancel:hover {
    background: var(--color-bg-tertiary);
}

.chat-portfolio-btn-save {
    padding: 10px 20px;
    font-size: 0.875rem;
    font-weight: 600;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chat-portfolio-btn-save:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.chat-portfolio-btn-save:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.chat-portfolio-btn-save.success {
    background: #10b981;
}

/* ==================== Ticker Links ==================== */
.ticker-link {
    color: var(--color-primary);
    font-weight: 700;
    text-decoration: none;
}

.ticker-link:hover {
    border-bottom-style: solid;
}

/* ==================== Quick Reply Suggestions ==================== */
.chat-quick-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    animation: fadeInUp 0.3s ease-out;
}

.chat-quick-suggestion {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.chat-quick-suggestion:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--color-primary);
    color: var(--color-primary);
    transform: translateY(-1px);
}

.chat-quick-suggestion:active {
    transform: translateY(0);
}

.chat-quick-suggestion i {
    font-size: 0.7rem;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    transform: translateX(-4px);
}

.chat-quick-suggestion:hover i {
    opacity: 1;
    transform: translateX(0);
}

/* Mobile optimization */
@media (max-width: 640px) {
    .chat-quick-suggestions {
        gap: 6px;
    }
    
    .chat-quick-suggestion {
        padding: 6px 12px;
        font-size: 0.75rem;
    }
    
    .chat-quick-suggestion i {
        display: none;
    }
}

/* ==================== Error & Retry Styles ==================== */
.chat-error-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.25);
    border-radius: 8px;
}

.chat-error-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    color: #dc2626;
    font-size: 0.9rem;
    line-height: 1.5;
}

.chat-error-message i {
    flex-shrink: 0;
    margin-top: 3px;
}

.chat-retry-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    transition: all 0.2s ease;
    align-self: flex-start;
}

.chat-retry-btn:hover {
    background: #6366f1;
    border-color: #6366f1;
    color: white;
}

.chat-retry-btn i {
    font-size: 0.8rem;
}

/* ==================== Resend Banner ==================== */
.chat-resend-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    margin: 16px 0;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: 10px;
    animation: fadeInUp 0.3s ease-out;
}

.chat-resend-banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #b45309;
    font-size: 0.9rem;
    font-weight: 500;
}

.chat-resend-banner-content i {
    font-size: 1.1rem;
    color: #d97706;
}

.chat-resend-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    border: none;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(217, 119, 6, 0.2);
}

.chat-resend-btn:hover {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(217, 119, 6, 0.3);
}

.chat-resend-btn:active {
    transform: translateY(0);
}

.chat-resend-btn i {
    font-size: 0.75rem;
}

/* Mobile optimization */
@media (max-width: 640px) {
    .chat-resend-banner {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 12px 14px;
    }
    
    .chat-resend-btn {
        justify-content: center;
        width: 100%;
    }
}

/* ==================== Mobile Typography (Apple HIG Compliance) ==================== */
@media (max-width: 767px) {
    /* Chat messages - body text should be 16-17px per HIG */
    .chat-message-text {
        font-size: 1rem; /* 16px */
        line-height: 1.5;
    }
    
    /* Chat input - 16px minimum to prevent iOS zoom */
    .chat-input,
    .chat-input-field {
        font-size: 1rem !important; /* 16px */
    }
    
    /* Empty state title */
    .chat-empty-title {
        font-size: 1.5rem; /* 24px */
    }
    
    /* Suggestion chips - ensure readable */
    .chat-suggestion-chip {
        font-size: 0.9375rem; /* 15px */
        min-height: 44px; /* Touch target */
    }
    
    /* Quick suggestions */
    .chat-quick-suggestion {
        font-size: 0.875rem; /* 14px */
        min-height: 40px;
        padding: 10px 16px;
    }
    
    /* Chat header */
    .chat-title {
        font-size: 1.125rem; /* 18px */
    }
    
    /* Message sender name */
    .chat-message-sender {
        font-size: 0.9375rem; /* 15px */
    }
    
    /* Time stamps - footnote size per HIG */
    .chat-message-time {
        font-size: 0.8125rem; /* 13px */
    }
    
    /* Action buttons - minimum touch size */
    .chat-action-button {
        font-size: 0.9375rem; /* 15px */
        min-height: 44px;
        padding: 12px 18px;
    }
    
    /* Model selector */
    .chat-model-btn {
        font-size: 0.8125rem; /* 13px */
        min-height: 36px;
    }
    
    /* Context search */
    .chat-context-search-input {
        font-size: 1rem; /* 16px - prevents zoom */
    }
    
    /* Chips - slightly larger on mobile */
    .chat-chip {
        font-size: 0.8125rem; /* 13px */
        padding: 6px 12px;
        min-height: 32px;
    }
    
    /* Send button - touch target */
    .chat-send-btn {
        width: 44px;
        height: 44px;
    }
    
    /* Header buttons - touch target */
    .chat-header-btn {
        width: 44px;
        height: 44px;
    }
}

/* ==================== Trading Idea Card in Chat ==================== */
.trading-idea-card,
.personal-alert-card {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    margin: 12px 0;
    max-width: 400px;
}

/* Inline Personal Alert - Compact Design */
.personal-alert-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 14px;
    margin: 8px 0;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 1px solid #fbbf24;
    border-radius: 8px;
    font-size: 13px;
}

.personal-alert-inline .alert-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.personal-alert-inline .alert-text {
    color: #92400e;
    font-weight: 500;
    flex: 1;
    min-width: 0;
}

.personal-alert-inline .ticker-tag {
    display: inline-block;
    padding: 2px 6px;
    background: rgba(251, 191, 36, 0.3);
    color: #92400e;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.personal-alert-inline .alert-create-btn {
    padding: 6px 12px;
    background: #6366f1;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.personal-alert-inline .alert-create-btn:hover {
    background: #4f46e5;
}

.personal-alert-inline .alert-create-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.personal-alert-inline.created {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    border-color: #22c55e;
}

.personal-alert-inline.created .alert-icon {
    color: #16a34a;
}

.personal-alert-inline.created .alert-text {
    color: #166534;
}

.personal-alert-inline.created .ticker-tag {
    background: rgba(34, 197, 94, 0.2);
    color: #166534;
}

.trading-idea-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.trading-idea-ticker-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.trading-idea-ticker {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
}

.trading-idea-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
}

.trading-idea-badge.direction-long {
    background: rgba(16, 185, 129, 0.15);
    color: #059669;
}

.trading-idea-badge.direction-short {
    background: rgba(239, 68, 68, 0.15);
    color: #dc2626;
}

.trading-idea-badge.strategy {
    background: #f3e8ff;
    color: #7c3aed;
}

.trading-idea-track-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 6px;
    background: #7c3aed;
    color: white;
    border: none;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
}

.trading-idea-track-btn:hover {
    background: #6d28d9;
    transform: translateY(-1px);
}

.trading-idea-track-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.trading-idea-track-btn.tracked {
    background: #e5e7eb;
    color: #4b5563;
}

.trading-idea-thesis {
    font-size: 13px;
    color: #475569;
    line-height: 1.5;
    margin: 0 0 12px 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.trading-idea-metrics {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}

.trading-idea-metric {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.trading-idea-metric .label {
    font-size: 10px;
    color: #94a3b8;
    text-transform: uppercase;
}

.trading-idea-metric .value {
    font-size: 14px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    color: #1e293b;
}

.trading-idea-metric .value.target {
    color: #10b981;
}

.trading-idea-metric .value.positive {
    color: #10b981;
}

.trading-idea-metric .value.negative {
    color: #ef4444;
}

.trading-idea-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.trading-idea-progress-bar {
    flex: 1;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}

.trading-idea-progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.trading-idea-progress-fill.positive {
    background: linear-gradient(90deg, #10b981, #34d399);
}

.trading-idea-progress-fill.negative {
    background: linear-gradient(90deg, #ef4444, #f87171);
}

.trading-idea-progress-text {
    font-size: 13px;
    font-weight: 600;
    min-width: 36px;
    text-align: right;
}

.trading-idea-progress-text.positive {
    color: #10b981;
}

.trading-idea-progress-text.negative {
    color: #ef4444;
}

.trading-idea-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #7c3aed;
    text-decoration: none;
    font-weight: 500;
}

.trading-idea-link:hover {
    text-decoration: underline;
}

.trading-idea-link i {
    font-size: 10px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .trading-idea-card {
        background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
        border-color: #334155;
    }
    
    .trading-idea-ticker {
        color: #f1f5f9;
    }
    
    .trading-idea-thesis {
        color: #94a3b8;
    }
    
    .trading-idea-metric .value {
        color: #f1f5f9;
    }
    
    .trading-idea-progress-bar {
        background: #334155;
    }
}

/* ==================== Quick Reply Suggestions ==================== */
.quick-reply-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0;
    margin-left: 48px;
}

.quick-reply-btn {
    padding: 8px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    font-size: 13px;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.quick-reply-btn:hover {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.quick-reply-btn:active {
    transform: scale(0.98);
}

@media (max-width: 768px) {
    .quick-reply-suggestions {
        margin-left: 0;
        padding: 8px 12px;
    }
    
    .quick-reply-btn {
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* ==================== Action Chips (Snippet Buttons) ==================== */
.chat-actions-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.action-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
}

.action-chip:hover {
    background: var(--color-bg-hover);
    transform: translateY(-1px);
}

.action-chip:active {
    transform: translateY(0);
}

.action-chip i {
    font-size: 1rem;
}

.action-chip.chip-primary {
    background: rgba(var(--color-primary-rgb), 0.1);
    color: var(--color-primary);
    border-color: rgba(var(--color-primary-rgb), 0.2);
}

.action-chip.chip-primary:hover {
    background: rgba(var(--color-primary-rgb), 0.15);
}

.action-chip.chip-secondary {
    background: rgba(var(--color-secondary-rgb), 0.1);
    color: var(--color-secondary);
    border-color: rgba(var(--color-secondary-rgb), 0.2);
}

.action-chip.chip-secondary:hover {
    background: rgba(var(--color-secondary-rgb), 0.15);
}

.action-chip.chip-success {
    background: rgba(16, 185, 129, 0.1); /* Green-500 equivalent */
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.2);
    cursor: default;
}

.action-chip:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}
