/* Analytics Styles - Enhanced Visual Data Analysis */

/* Query Builder Styles */
.query-builder-container {
    display: grid;
    grid-template-columns: 250px 1fr 250px;
    gap: 20px;
    height: 600px;
}

.query-sidebar {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    overflow-y: auto;
}

.query-canvas {
    background: #fff;
    border: 2px dashed #ddd;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.query-panel {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    overflow-y: auto;
}

/* Table Item Styles */
.table-item {
    background: white;
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid #e0e0e0;
}

.table-item:hover {
    background: #e3f2fd;
    border-color: #2196f3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.table-item .table-name {
    font-weight: bold;
    color: #333;
    margin-bottom: 5px;
}

.table-item .table-info {
    font-size: 0.85rem;
    color: #666;
}

/* Canvas Table Styles */
.canvas-table {
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    position: absolute;
    min-width: 200px;
    cursor: move;
    transition: all 0.3s ease;
    z-index: 10;
}

.canvas-table:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
    z-index: 20;
}

.canvas-table.selected {
    border-color: #28a745;
    box-shadow: 0 0 0 4px rgba(40, 167, 69, 0.4);
    z-index: 30;
}

/* Canvas Empty State */
.canvas-empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #666;
    z-index: 5;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    color: #667eea;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.canvas-table .table-header {
    font-weight: bold;
    color: #2196f3;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 2px solid #2196f3;
}

.canvas-table .table-columns {
    font-size: 0.85rem;
    color: #666;
    max-height: 150px;
    overflow-y: auto;
}

.canvas-table .table-column {
    padding: 3px 0;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: color 0.2s ease;
}

.canvas-table .table-column:hover {
    color: #2196f3;
}

.canvas-table .table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #2196f3;
    color: white;
    padding: 5px 10px;
    border-radius: 5px 5px 0 0;
    cursor: move;
}

.btn-remove-sm {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
}

.table-column {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px;
    position: relative;
    background: white;
}

.port {
    width: 10px;
    height: 10px;
    background: #667eea;
    border-radius: 50%;
    cursor: crosshair;
    transition: transform 0.2s;
}

.port:hover {
    transform: scale(1.5);
}

.port-in {
    margin-right: 5px;
}

.port-out {
    margin-left: 5px;
}

/* Function Library Styles */
.function-library {
    margin-top: 20px;
}

.function-category {
    margin-bottom: 15px;
}

.function-category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: white;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    color: #333;
    transition: background 0.3s ease;
}

.function-category-header:hover {
    background: #e3f2fd;
}

.function-category-header .collapse-icon {
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

.function-category-header.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.function-items-container {
    max-height: 200px;
    overflow-y: auto;
    margin-top: 5px;
}

.function-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: white;
    margin-bottom: 5px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.function-item:hover {
    background: #f5f5f5;
    border-left-color: #2196f3;
    transform: translateX(3px);
}

.function-favorite-btn {
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    margin-right: 8px;
    transition: transform 0.2s ease;
}

.function-favorite-btn:hover {
    transform: scale(1.2);
}

.function-favorite-btn.active {
    color: #ffc107;
}

.function-usage-count {
    background: #2196f3;
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.7rem;
    margin-left: 5px;
}

/* Query Panel Styles */
.query-section {
    margin-bottom: 20px;
}

.query-section h4 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 0.9rem;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
}

.filter-item, .calculated-field {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: white;
    margin-bottom: 5px;
    border-radius: 3px;
}

.filter-item select,
.filter-item input {
    padding: 4px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 0.85rem;
}

.btn-remove {
    background: #dc3545;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s ease;
}

.btn-remove:hover {
    background: #c82333;
}

/* Results Panel Styles */
.results-panel {
    margin-top: 20px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.results-header h3 {
    margin: 0;
    color: #333;
}

.results-summary {
    display: flex;
    gap: 15px;
    color: #666;
    font-size: 0.9rem;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.results-table th,
.results-table td {
    padding: 8px;
    text-align: left;
    border-bottom: 1px solid #eee;
    font-size: 0.85rem;
}

.results-table th {
    background: #f8f9fa;
    font-weight: bold;
    color: #333;
}

.results-table tbody tr:hover {
    background: #f5f5f5;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .query-builder-container {
        grid-template-columns: 200px 1fr 200px;
    }
}

@media (max-width: 768px) {
    .query-builder-container {
        grid-template-columns: 1fr;
        height: auto;
    }
    
    .query-sidebar,
    .query-canvas,
    .query-panel {
        height: 400px;
        margin-bottom: 20px;
    }
    
    .canvas-table {
        min-width: 150px;
        font-size: 0.8rem;
    }
}

/* Loading and Error States */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: #666;
}

.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 10px;
    border-radius: 5px;
    margin: 10px 0;
    font-size: 0.9rem;
}

.success-message {
    background: #d4edda;
    color: #155724;
    padding: 10px;
    border-radius: 5px;
    margin: 10px 0;
    font-size: 0.9rem;
}

/* Dashboard Styles */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.dashboard-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.dashboard-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
}

.dashboard-card h3 {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dashboard-value {
    font-size: 2rem;
    font-weight: bold;
    color: #2196f3;
    margin-bottom: 10px;
}

.dashboard-change {
    font-size: 0.9rem;
    color: #666;
}

.dashboard-change.positive {
    color: #28a745;
}

.dashboard-change.negative {
    color: #dc3545;
}

/* Charts Container */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.chart-container {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: relative;
}

.chart-container h4 {
    margin: 0 0 15px 0;
    color: #333;
}

.chart-wrapper {
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* File Upload Styles */
.page-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.page-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.files-panel {
    width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.data-viewer {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.upload-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.files-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.file-item {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.file-item:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.file-item.active {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.sheets-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.sheet-checkbox-item {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    gap: 0.5rem;
    border-bottom: 1px solid #f0f0f0;
}

.sheet-checkbox-item:hover {
    background: var(--bg-tertiary);
}

.sheet-checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.sheet-checkbox-label {
    flex: 1;
    cursor: pointer;
    user-select: none;
}

.data-preview {
    flex: 1;
    overflow: auto;
    padding: 1rem;
    max-height: calc(100vh - 200px);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

.data-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    position: sticky;
    top: 0;
}

.upload-drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
}

.upload-drop-zone:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.upload-drop-zone.drag-over {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.action-buttons {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.progress-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.progress-overlay.active {
    display: flex;
}

.progress-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    min-width: 300px;
    max-width: 500px;
}

.progress-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.progress-message {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
}

.progress-details {
    font-size: 0.9rem;
    color: #666;
}

/* Responsive File Upload */
@media (max-width: 768px) {
    .page-content {
        flex-direction: column;
    }
    
    .files-panel {
        width: 100%;
        height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .data-preview {
        max-height: calc(100vh - 400px);
    }
    
    .upload-drop-zone {
        min-height: 120px !important;
        padding: 1rem !important;
    }
    
    .action-buttons {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* Responsive Charts */
@media (max-width: 768px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .chart-wrapper {
        height: 250px;
    }
}

/* Advanced Filtering Styles */
.filter-group {
    border: 2px solid #667eea;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    background: #f8f9fa;
    transition: all 0.3s ease;
}

.filter-group:hover {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.filter-condition {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
    background: white;
    padding: 10px;
    border-radius: 5px;
    transition: all 0.2s ease;
}

.filter-condition:hover {
    background: #f0f0f0;
}

.group-logic-select {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: white;
    cursor: pointer;
    font-weight: 600;
}

.group-logic-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Data Preview Modal Styles */
.data-preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.data-preview-modal .modal-content {
    max-width: 90vw;
    max-height: 80vh;
    overflow: auto;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Enhanced Results Actions */
.results-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 15px;
}

.results-actions .btn {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.results-actions .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Statistics Modal Styles */
.stat-card {
    padding: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 10px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.stat-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
}

.stat-card h4 {
    margin-top: 0;
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    padding-bottom: 10px;
    margin-bottom: 10px;
}

/* Function Library Modal */
.function-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
}

.function-cat {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.function-cat h4 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #667eea;
}

.function-cat button {
    display: block;
    width: 100%;
    margin-bottom: 8px;
    text-align: left;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow: auto;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid #f0f0f0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 0 0;
}

.modal-header h3 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-body {
    padding: 20px;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(1.1);
}

/* Calculated Fields Styles */
.calculated-field {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px;
    background: white;
    border-radius: 5px;
    border: 1px solid #e0e0e0;
    transition: all 0.2s ease;
}

.calculated-field:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}

/* Port Styles for Joins */
.port {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #667eea;
    cursor: crosshair;
    transition: all 0.2s ease;
}

.port:hover {
    transform: scale(1.3);
    box-shadow: 0 0 8px rgba(102, 126, 234, 0.5);
}

.port-in {
    background: #28a745;
}

.port-out {
    background: #667eea;
}

/* Responsive Styles */
@media (max-width: 768px) {
    .query-builder-container {
        grid-template-columns: 1fr;
        height: auto;
    }
    
    .query-sidebar,
    .query-panel {
        max-height: 400px;
    }
    
    .filter-group {
        padding: 10px;
    }
    
    .filter-condition {
        flex-direction: column;
        align-items: stretch;
    }
    
    .results-actions {
        flex-direction: column;
    }
    
    .results-actions .btn {
        width: 100%;
    }
}

