/* ============================================
   AI Data Scientist Widget Styles
   ============================================ */

/* Data Scientist Button */
#ai-ds-button {
    position: fixed;
    bottom: 20px;
    left: 110px; /* 30px right of chat button (20px + 60px width + 30px gap) */
    width: 60px;
    height: 60px;
    border-radius: 30px;
    background: linear-gradient(135deg, #2d3436 0%, #1a1a1a 50%, #000000 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 2px 10px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 999998;
    overflow: hidden;
}

#ai-ds-button::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent,
        rgba(255, 255, 255, 0.1),
        transparent
    );
    transform: rotate(45deg);
    transition: all 0.5s ease;
}

#ai-ds-button img {
    width: 32px;
    height: 32px;
    filter: brightness(0) invert(1) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    position: relative;
    z-index: 1;
}

/* Show widget by default */
#ai-ds-button { 
    display: flex; 
}

/* Hide original launcher button (replaced by AI Toolbox) */
#ai-ds-button {
    display: none !important;
}

#ai-ds-button:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.6), 0 4px 15px rgba(0, 0, 0, 0.5);
}

#ai-ds-button:hover::before {
    left: 100%;
}

#ai-ds-button.active {
    width: 72px;
    height: 72px;
    border-radius: 36px;
    transform: scale(1.2);
    box-shadow: 0 8px 35px rgba(0, 0, 0, 0.6), 0 4px 15px rgba(0, 0, 0, 0.5);
}

#ai-ds-button.active img {
    width: 38px;
    height: 38px;
}

/* Data Scientist Panel */
#ai-ds-panel {
    position: fixed;
    bottom: 100px;
    left: 20px;
    width: 450px;
    max-width: calc(100vw - 60px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    z-index: 999999;
    overflow: hidden;
    transition: all 0.3s ease;
}

#ai-ds-panel.open,
#ai-ds-panel.is-open {
    display: flex;
}

#ai-ds-panel.fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    right: 0 !important;
    border-radius: 0 !important;
    z-index: 2147483647 !important;
}

/* Hide all widget buttons when analytics agent is in fullscreen */
body:has(#ai-ds-panel.fullscreen) #ghost-chat-button,
body:has(#ai-ds-panel.fullscreen) #relationship-mapper-button,
body:has(#ai-ds-panel.fullscreen) #briefing-button,
body:has(#ai-ds-panel.fullscreen) #ai-ds-button {
    display: none !important;
    z-index: -1 !important;
    pointer-events: none !important;
}

/* Header */
#ai-ds-header {
    background: linear-gradient(135deg, #2d3436 0%, #000000 100%);
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    overflow: hidden;
    min-width: 0;
}

#ai-ds-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    min-width: 0;
}

#ai-ds-header-left > div:first-child {
    flex-shrink: 0;
}

#ai-ds-header-left img {
    height: 28px;
    width: auto;
    display: block;
}

#ai-ds-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: white;
}

#ai-ds-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 1;
    min-width: 0;
}

.ai-ds-usage-display {
    white-space: nowrap;
    min-width: fit-content;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.ai-ds-header-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    transition: all 0.2s;
    font-weight: 500;
}

.ai-ds-header-btn:hover {
    background: rgba(255,255,255,0.25);
}

#ai-ds-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
    padding: 0;
    width: 24px;
    height: 24px;
    margin-left: 8px;
}

/* Content Area */
#ai-ds-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f7f8fa;
}

/* Status Message */
.ds-status {
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
}

.ds-status.loading {
    background: #f7f8fa;
    color: #2d3436;
    border: 1px solid #e1e4e8;
}

.ds-status.error {
    background: #fff5f5;
    color: #e74c3c;
    border: 1px solid #fdd;
}

.ds-status.warning {
    background: #fff8e1;
    color: #f57c00;
    border: 1px solid #ffcc80;
    text-align: left;
}

.ds-status.info {
    background: #e3f2fd;
    color: #1976d2;
    border: 1px solid #90caf9;
    text-align: left;
}

.ds-data-indicators {
    background: #f7f8fa;
    padding: 12px;
    border-radius: 8px;
    border-left: 3px solid #2d3436;
    margin-bottom: 12px;
}

/* Article Info */
.ds-article-info {
    background: #f7f8fa;
    padding: 16px;
    border-radius: 8px;
    border-left: 4px solid #2d3436;
}

.ds-article-info h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: #2d3436;
    font-weight: 600;
}

.ds-article-info p {
    margin: 0;
    font-size: 13px;
    color: #666;
}

/* Suggestions */
.ds-suggestions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ds-suggestion-card {
    background: white;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.ds-suggestion-card:hover {
    border-color: #2d3436;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

.ds-suggestion-card:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.ds-suggestion-card h5 {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: #2d3436;
    font-weight: 600;
}

.ds-suggestion-card p {
    margin: 0;
    font-size: 13px;
    color: #666;
    line-height: 1.5;
}

/* Chart Display */
.ds-chart-container {
    background: white;
    border-radius: 8px;
    padding: 16px;
    border: 1px solid #e1e4e8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.ds-chart-container h4 {
    color: #2d3436;
    font-weight: 600;
}

.ds-chart-container canvas {
    width: 100% !important;
    max-height: 400px;
    border-radius: 4px;
}

.ds-chart-container img {
    width: 100%;
    border-radius: 4px;
}

.ds-chart-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.ds-chart-actions button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.ds-btn-download {
    background: linear-gradient(135deg, #2d3436 0%, #000000 100%);
    color: white;
}

.ds-btn-download:hover {
    opacity: 0.9;
}

.ds-btn-new {
    background: #f7f8fa;
    color: #2d3436;
    border: 1px solid #e1e4e8;
}

.ds-btn-new:hover {
    background: #e1e4e8;
}

/* Custom Request */
.ds-custom-request {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ds-custom-request textarea {
    width: 100%;
    min-height: 80px;
    padding: 12px;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.2s;
}

.ds-custom-request textarea:focus {
    outline: none;
    border-color: #2d3436;
}

.ds-custom-request button {
    padding: 12px 20px;
    background: linear-gradient(135deg, #2d3436 0%, #000000 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.ds-custom-request button:hover {
    opacity: 0.9;
}

.ds-custom-request button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #ai-ds-button {
        display: none !important;
    }
    
    #ai-ds-panel {
        left: 15px;
        width: calc(100vw - 30px);
        height: calc(100vh - 120px);
    }
    
    /* Header optimizations for small screens */
    #ai-ds-header {
        padding: 10px 12px;
    }
    
    #ai-ds-header-left {
        gap: 8px;
    }
    
    #ai-ds-header-left > div:first-child {
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        min-height: 28px !important;
    }
    
    #ai-ds-header-left img {
        height: 20px !important;
    }
    
    #ai-ds-header h3 {
        font-size: 14px !important;
    }
    
    #ai-ds-header-right {
        gap: 4px;
    }
    
    .ai-ds-header-btn {
        padding: 4px 6px !important;
        min-width: 28px !important;
        height: 28px !important;
    }
    
    .ai-ds-header-btn i {
        font-size: 14px !important;
    }
    
    #ai-ds-usage {
        display: none !important;
    }
}

/* Dark mode support */
.dark-mode #ai-ds-panel {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
}

.dark-mode #ai-ds-content {
    background: var(--color-bg-secondary);
}

.dark-mode .ds-article-info {
    background: var(--color-bg-primary);
    border-left-color: var(--color-accent);
}

.dark-mode .ds-article-info h4 {
    color: var(--color-text-primary);
}

.dark-mode .ds-article-info p {
    color: var(--color-text-secondary);
}

.dark-mode .ds-suggestion-card {
    background: var(--color-bg-primary);
    border-color: var(--color-border);
}

.dark-mode .ds-suggestion-card:hover {
    border-color: var(--color-accent);
}

.dark-mode .ds-suggestion-card h5 {
    color: var(--color-text-primary);
}

.dark-mode .ds-suggestion-card p {
    color: var(--color-text-secondary);
}

.dark-mode .ds-chart-container {
    background: var(--color-bg-primary);
    border-color: var(--color-border);
}

.dark-mode .ds-chart-container h4 {
    color: var(--color-text-primary);
}

.dark-mode .ds-status.loading {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    border-color: var(--color-border);
}

.dark-mode .ds-custom-request textarea {
    background: var(--color-bg-secondary);
    border-color: var(--color-border);
    color: var(--color-text-primary);
}

.dark-mode .ds-btn-new {
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    border-color: var(--color-border);
}

.dark-mode .ds-btn-new:hover {
    background: var(--color-bg-primary);
}

/* Initial Screen */
.ai-ds-initial-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 40px 20px;
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

.ai-ds-initial-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.ai-ds-initial-screen h3 {
    font-size: 24px;
    font-weight: 700;
    color: #2d3436;
    margin: 0 0 12px 0;
}

.ai-ds-initial-screen > p {
    font-size: 16px;
    color: #636e72;
    margin: 0 0 8px 0;
    line-height: 1.5;
}

.ai-ds-initial-info {
    font-size: 14px;
    color: #636e72;
    margin: 16px 0 8px 0;
    font-weight: 600;
}

.ai-ds-features-list {
    list-style: none;
    padding: 0;
    margin: 0 0 24px 0;
    text-align: left;
    display: inline-block;
}

.ai-ds-features-list li {
    font-size: 14px;
    color: #636e72;
    margin: 8px 0;
    padding-left: 20px;
    position: relative;
}

.ai-ds-features-list li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: #2d3436;
    font-weight: 600;
}

.ai-ds-btn {
    padding: 12px 24px;
    border-radius: 8px;
    border: none;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-ds-btn-primary {
    background: #2d3436;
    color: white;
}

.ai-ds-btn-primary:hover {
    background: #1a1a1a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Saved Analyses Section */
.ai-ds-saved-section {
    margin-top: 40px;
    width: 100%;
    max-width: 500px;
    display: block !important;
    visibility: visible !important;
}

.ai-ds-saved-empty {
    padding: 24px 20px;
    text-align: center;
}

.ai-ds-saved-empty-text {
    color: #636e72;
    font-size: 14px;
    margin: 0;
    line-height: 1.5;
}

.ai-ds-saved-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
}

.ai-ds-saved-title {
    font-size: 16px;
    font-weight: 600;
    color: #2d3436;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-ds-saved-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    background: #2d3436;
    color: white;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
}

.ai-ds-saved-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 8px;
}

.ai-ds-saved-item {
    background: white;
    border: 2px solid #e1e4e8;
    border-radius: 8px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
    cursor: pointer;
}

.ai-ds-saved-item:hover {
    border-color: #2d3436;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.ai-ds-saved-item-content {
    flex: 1;
    min-width: 0;
}

.ai-ds-saved-item-title {
    font-size: 14px;
    font-weight: 600;
    color: #2d3436;
    margin: 0 0 4px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-ds-saved-item-date {
    font-size: 12px;
    color: #636e72;
    margin: 0;
}

.ai-ds-saved-item-actions {
    display: flex;
    gap: 8px;
    margin-left: 12px;
    flex-shrink: 0;
}

.ai-ds-saved-btn {
    background: #f7f8fa;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    padding: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    color: #2d3436;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.ai-ds-saved-btn svg {
    display: block;
}

.ai-ds-saved-btn:hover {
    background: #e1e4e8;
    border-color: #2d3436;
}

.ai-ds-saved-btn-delete:hover {
    background: #fff5f5;
    border-color: #e74c3c;
    color: #e74c3c;
}

.ai-ds-saved-list::-webkit-scrollbar {
    width: 6px;
}

.ai-ds-saved-list::-webkit-scrollbar-track {
    background: #f7f8fa;
    border-radius: 3px;
}

.ai-ds-saved-list::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.ai-ds-saved-list::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

