/* ==========================================================================
   PCA Tool Specific Styles
   Provides styling for the PCA Tool interface including data tables, 
   plots, loading states, and custom UI components.
   ========================================================================== */

/* ==========================================================================
   1. Theme Variables & Configuration
   ========================================================================== */
:root {
    /* Theme Colors */
    --pca-border-color: #dee2e6;
    --pca-bg-light: #f8f9fa;
    --pca-bg-zebra: rgba(0, 0, 0, 0.03);
    --pca-empty-bg: rgba(0, 0, 0, 0.02);
    --pca-empty-border: #ced4da;
    --pca-text-muted: #6c757d;

    /* Plotly Specific Colors (read by JS for plotting) */
    --pca-plot-text: rgba(0, 0, 0, 0.7);
    --pca-plot-legend-bg: rgba(255, 255, 255, 0.5);
    --pca-plot-primary: #1f77b4;
    --pca-plot-secondary: #d62728;
    --pca-plot-marker-line: white;
    --pca-plot-grid-line: rgba(0, 0, 0, 0.5);
    --pca-plot-default-palette: #1f77b4, #ff7f0e, #2ca02c, #d62728, #9467bd, #8c564b, #e377c2, #7f7f7f, #bcbd22, #17becf;
    
    /* Layout Dimensions */
    --pca-plot-height: 600;
    --scree-plot-height: 500;

    /* Typography */
    --pca-font-small: 0.85rem;
}

/* ==========================================================================
   2. Layout & Form Elements
   ========================================================================== */
/* Container for data format radio buttons */
#data-format-container {
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--pca-border-color);
    margin-bottom: 1rem;
}

/* Grouping level row inputs flexbox distribution */
.grouping-input-group {
    flex: 1;
}

/* Legend/Info style for mapping warning */
#csv-mapping-warning {
    font-size: 0.9rem;
}

/* ==========================================================================
   3. DataTables Styling
   ========================================================================== */
/* Header formatting */
#pca-tool-container .dataTable thead th {
    white-space: nowrap;
    background-color: var(--pca-bg-light);
    font-size: var(--pca-font-small);
    padding: 0.5rem;
    border-bottom-width: 2px;
}

/* Cell formatting - restricts width to prevent table overflow on long strings */
#pca-tool-container .dataTable tbody td {
    white-space: nowrap;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis; /* Truncate long content with ... */
    font-size: var(--pca-font-small);
    /* !important is used to override DataTables default vertical alignment */
    vertical-align: middle !important;
    /* !important is used to override DataTables default padding for denser look */
    padding: 0.4rem 0.5rem !important;
}

/* Ensure zebra striping looks good with custom padding overrides */
#pca-tool-container .table-striped tbody tr:nth-of-type(odd) {
    background-color: var(--pca-bg-zebra);
}

/* Responsive container for tables with vertical scrolling limit */
#pca-tool-container .table-responsive {
    overflow-y: auto;
    max-height: 1200px;
    border: 1px solid var(--pca-border-color);
    border-radius: 4px;
}

/* Sticky controls for DataTables extension (e.g. fixed columns) */
#pca-tool-container .dt-controls {
    position: sticky;
    left: 0;
    /* z-index ensures controls stay on top of scrolling table content */
    z-index: 10;
}

/* Data table custom caption styling */
.pca-table-caption {
    caption-side: top;
    font-size: 1.5rem;
    color: var(--pca-text-muted);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

/* ==========================================================================
   4. Loading States & Buttons
   ========================================================================== */
/* Loading state for buttons - hides text and shows spinner */
#pca-tool-container .btn.loading {
    position: relative;
    /* !important used to guarantee text hiding regardless of button variant */
    color: transparent !important; 
    pointer-events: none; /* Prevent double-clicks while loading */
}

/* CSS Spinner implementation */
#pca-tool-container .btn.loading::after {
    content: "";
    position: absolute;
    width: 1rem;
    height: 1rem;
    top: 50%;
    left: 50%;
    margin-top: -0.5rem;
    margin-left: -0.5rem;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

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

/* ==========================================================================
   5. Plots & Modals
   ========================================================================== */
/* Ensure plots fill their containers */
#pca-plot,
#screeplot-plot {
    width: 100%;
}

/* Allow vertical resizing for citation modal textarea */
#citation-text-content {
    resize: vertical;
}

/* ==========================================================================
   6. Empty States
   ========================================================================== */
/* Placeholder styling before data is loaded or plot is generated */
.pca-empty-state {
    min-height: 250px;
    background: var(--pca-empty-bg);
    border: 1px dashed var(--pca-empty-border);
    border-radius: 5px;
}

/* Mute the icon inside the empty state */
.pca-empty-state i {
    opacity: 0.3;
}