/**
 * Training Insights Modal Styles
 * Mobile-first responsive design
 * Uses main app CSS variables for consistent theming
 */

/* ===========================
   Additional Color Variables
   =========================== */
:root {
    --insights-primary: var(--primary-color);
    --insights-secondary: var(--secondary-color);
    --insights-success: var(--success-color);
    --insights-warning: var(--warning-color);
    --insights-danger: var(--danger-color);
    --insights-background: var(--white);
    --insights-border: var(--gray-200);
    --insights-text: var(--gray-700);
    --insights-text-muted: var(--gray-500);
    --insights-backdrop: rgba(0, 0, 0, 0.5);
}

/* Dark theme support */
[data-theme="dark"] {
    --insights-background: var(--gray-800);
    --insights-border: var(--gray-700);
    --insights-text: var(--gray-100);
    --insights-text-muted: var(--gray-400);
    --insights-backdrop: rgba(0, 0, 0, 0.7);
}

/* ===========================
   Insights Button Styles
   =========================== */
.insights-button {
    display: block;
    width: 100%;
    padding: 16px 24px;
    margin-top: 10px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--white);
    border: none;
    border-radius: 0;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    letter-spacing: -0.025em;
    box-shadow: var(--shadow-md);
}

.insights-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.6s;
}

.insights-button:hover:not(:disabled)::before {
    left: 100%;
}

.insights-button:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
    color: var(--gray-500);
    box-shadow: none;
    opacity: 1;
}

.insights-button:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.insights-button:not(:disabled):active {
    transform: translateY(0);
}

/* Pulse animation for attention */
.insights-button.pulse-animation {
    animation: pulse 2s ease-in-out;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: var(--shadow-md);
    }
    50% {
        box-shadow: 0 8px 20px rgba(99, 102, 241, 0.5);
    }
}

/* ===========================
   Modal Container
   =========================== */
.insights-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9500;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease-out;
}

.insights-modal.show {
    opacity: 1;
}

.insights-modal.hide {
    opacity: 0;
}

.insights-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--insights-backdrop);
}

/* ===========================
   Modal Content - Mobile First
   =========================== */
.insights-modal-content {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--insights-background);
    display: flex;
    flex-direction: column;
    z-index: 9501;
    overflow: hidden;
}

/* ===========================
   Modal Header
   =========================== */
.insights-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--insights-border);
    background: var(--insights-background);
    flex-shrink: 0;
}

.insights-modal-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--insights-text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.insights-modal-title i {
    color: var(--insights-primary);
}

.insights-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--insights-text-muted);
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    transition: all 0.2s;
}

.insights-modal-close:hover {
    background: var(--insights-border);
    color: var(--insights-text);
}

/* ===========================
   Modal Body
   =========================== */
.insights-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
}

/* ===========================
   Sections
   =========================== */
.insights-section {
    margin-bottom: 30px;
}

.insights-section:last-child {
    margin-bottom: 0;
}

.insights-section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--insights-text);
    margin: 0 0 16px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.insights-section-title i {
    color: var(--insights-primary);
}

/* ===========================
   Overview Grid - Mobile
   =========================== */
.insights-overview-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.insights-metric-card {
    background: var(--insights-background);
    border: 1px solid var(--insights-border);
    border-radius: var(--border-radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: all 0.2s;
}

.insights-metric-card:hover {
    border-color: var(--insights-primary);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
}

.insights-metric-icon {
    font-size: 24px;
    color: var(--insights-primary);
    margin-bottom: 8px;
}

.insights-metric-label {
    font-size: 13px;
    color: var(--insights-text-muted);
    margin-bottom: 4px;
}

.insights-metric-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--insights-text);
}

/* ===========================
   Charts
   =========================== */
.insights-chart-container {
    background: var(--insights-background);
    border: 1px solid var(--insights-border);
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 16px;
    height: 220px;
}

.insights-chart-container:last-child {
    margin-bottom: 0;
}

.insights-chart-container canvas {
    max-width: 100%;
    height: 100% !important;
}

/* ===========================
   Loading and Error States
   =========================== */
.insights-loading,
.insights-error {
    text-align: center;
    padding: 40px 20px;
    font-size: 16px;
    color: var(--insights-text-muted);
}

.insights-loading i,
.insights-error i {
    font-size: 32px;
    display: block;
    margin-bottom: 12px;
}

.insights-error {
    color: var(--insights-danger);
}

/* ===========================
   Evaluate Button & GradCAM Generate Button
   =========================== */
.insights-evaluate-button,
.insights-heatmap-generate {
    display: inline-block;
    padding: 16px 28px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--white);
    border: none;
    border-radius: 0;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    letter-spacing: -0.025em;
    box-shadow: var(--shadow-md);
    min-width: 240px;
}

.insights-evaluate-button::before,
.insights-heatmap-generate::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.6s;
}

.insights-evaluate-button:hover:not(:disabled)::before,
.insights-heatmap-generate:hover:not(:disabled)::before {
    left: 100%;
}

.insights-evaluate-button:hover:not(:disabled),
.insights-heatmap-generate:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.insights-evaluate-button:active:not(:disabled),
.insights-heatmap-generate:active:not(:disabled) {
    transform: translateY(0);
}

.insights-evaluate-button:disabled,
.insights-heatmap-generate:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 1;
}

.insights-evaluate-button i,
.insights-heatmap-generate i {
    font-size: 18px;
    margin-right: 8px;
}

/* ===========================
   Tablet Breakpoint (768px+)
   =========================== */
@media (min-width: 768px) {
    .insights-modal-content {
        width: 90vw;
        height: 90vh;
        max-width: 900px;
        max-height: 90vh;
        border-radius: var(--border-radius-lg);
        box-shadow: var(--shadow-xl);
    }

    .insights-modal-header {
        padding: 20px 24px;
    }

    .insights-modal-title {
        font-size: 22px;
    }

    .insights-modal-body {
        padding: 24px;
    }

    .insights-overview-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .insights-section-title {
        font-size: 20px;
    }

    .insights-metric-label {
        font-size: 14px;
    }

    .insights-chart-container {
        height: 260px;
        padding: 20px;
    }
}

/* ===========================
   Desktop Breakpoint (1024px+)
   =========================== */
@media (min-width: 1024px) {
    .insights-modal-content {
        width: 900px;
        height: 85vh;
        max-height: 85vh;
    }

    .insights-modal-body {
        padding: 32px;
    }

    .insights-overview-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 16px;
    }

    .insights-section-title {
        font-size: 22px;
    }

    .insights-chart-container {
        height: 300px;
        padding: 24px;
    }

    .insights-metric-card:hover {
        transform: translateY(-2px);
    }
}

/* ===========================
   Per-Class Accuracy Styles
   =========================== */
.insights-per-class {
    margin-top: 20px;
}

.insights-class-item {
    background: var(--insights-background);
    border: 1px solid var(--insights-border);
    border-radius: var(--border-radius);
    padding: 12px 16px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.insights-class-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.insights-class-name {
    font-weight: 500;
    color: var(--insights-text);
    font-size: 15px;
}

.insights-class-accuracy {
    font-weight: 600;
    font-size: 16px;
}

.insights-class-accuracy.high {
    color: var(--insights-success);
}

.insights-class-accuracy.medium {
    color: var(--insights-warning);
}

.insights-class-accuracy.low {
    color: var(--insights-danger);
}

.insights-class-bar {
    width: 100%;
    height: 8px;
    background: var(--insights-border);
    border-radius: 4px;
    overflow: hidden;
}

.insights-class-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.insights-class-bar-fill.high {
    background: var(--insights-success);
}

.insights-class-bar-fill.medium {
    background: var(--insights-warning);
}

.insights-class-bar-fill.low {
    background: var(--insights-danger);
}

.insights-class-metrics {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--insights-text-muted);
    flex-wrap: wrap;
}

.insights-class-metrics span {
    cursor: help;
}

.insights-class-metrics strong {
    color: var(--insights-text);
}

.insights-class-samples {
    font-size: 13px;
    color: var(--insights-text-muted);
}

/* ===========================
   Confusion Matrix Styles
   =========================== */
.insights-confusion-matrix {
    margin-top: 32px;
}

.cm-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 16px 0;
    width: 100%;
}

.cm-axis-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cm-axis-predicted {
    margin-bottom: 8px;
    text-align: center;
}

.cm-table-container {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: center;
}

.cm-axis-actual {
    writing-mode: vertical-rl;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.confusion-matrix-table {
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
    background: var(--insights-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    width: auto;
    max-width: 100%;
}

.confusion-matrix-table th,
.confusion-matrix-table td {
    padding: 16px 20px;
    text-align: center;
    border: 1px solid var(--insights-border);
    min-width: 80px;
}

.cm-corner-cell {
    background: var(--insights-bg-alt);
    border: none !important;
    padding: 12px;
    min-width: 60px;
}

.cm-header-cell {
    background: var(--gray-100);
    color: var(--insights-text);
    font-weight: 600;
    border: none !important;
    border-bottom: 2px solid var(--insights-border) !important;
    padding: 12px 16px;
}

.cm-row-header {
    background: var(--gray-100);
    color: var(--insights-text);
    font-weight: 600;
    border: none !important;
    border-right: 2px solid var(--insights-border) !important;
    padding: 12px 16px;
    min-width: 100px;
}

.cm-class-badge {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.cm-predicted-badge {
    background: var(--gray-200);
    color: var(--insights-text);
}

.cm-actual-badge {
    background: var(--gray-200);
    color: var(--insights-text);
}

.cm-cell {
    transition: all 0.2s ease;
    position: relative;
    background: white;
    cursor: help;
}

.cm-cell-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.cm-cell-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
}

.cm-cell-percent {
    font-size: 12px;
    opacity: 0.7;
    font-weight: 500;
}

.cm-cell-correct {
    background: #f0fdf4;
    border: 3px solid #10b981 !important;
    font-weight: 700;
}

.cm-cell-correct .cm-cell-value {
    color: #059669;
}

.cm-cell-correct .cm-cell-percent {
    color: #10b981;
}

.cm-cell-error {
    background: #fef2f2;
}

.cm-cell-error .cm-cell-value {
    color: #dc2626;
}

.cm-cell-error .cm-cell-percent {
    color: #ef4444;
}

.cm-cell-empty {
    background: #fafafa;
    color: #d1d5db;
}

.cm-cell-empty .cm-cell-value {
    color: #d1d5db;
    font-size: 20px;
}

/* Legend */
.cm-legend {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-top: 20px;
    padding: 14px 20px;
    background: var(--insights-bg-alt);
    border-radius: 8px;
    flex-wrap: wrap;
}

.cm-legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--insights-text);
}

.cm-legend-box {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 2px solid transparent;
    flex-shrink: 0;
}

.cm-legend-correct {
    background: #f0fdf4;
    border-color: #10b981;
}

.cm-legend-error {
    background: #fef2f2;
}

.cm-legend-empty {
    background: #fafafa;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .confusion-matrix-table th,
    .confusion-matrix-table td {
        padding: 12px 14px;
        min-width: 70px;
    }
    
    .cm-cell-value {
        font-size: 20px;
    }
    
    .cm-legend {
        gap: 16px;
    }
}

@media (max-width: 480px) {
    .cm-table-container {
        gap: 4px;
    }
    
    .confusion-matrix-table th,
    .confusion-matrix-table td {
        padding: 10px 12px;
        min-width: 60px;
    }
    
    .cm-cell-value {
        font-size: 18px;
    }
    
    .cm-class-badge {
        padding: 4px 10px;
        font-size: 12px;
    }
    
    .cm-legend {
        gap: 12px;
        font-size: 12px;
    }
}

/* Dark theme support */
[data-theme="dark"] .confusion-matrix-table {
    background: var(--insights-bg);
}

[data-theme="dark"] .cm-header-cell {
    background: var(--gray-700);
    color: var(--gray-100);
}

[data-theme="dark"] .cm-row-header {
    background: var(--gray-700);
    color: var(--gray-100);
}

[data-theme="dark"] .cm-predicted-badge {
    background: var(--gray-600);
    color: var(--gray-100);
}

[data-theme="dark"] .cm-actual-badge {
    background: var(--gray-600);
    color: var(--gray-100);
}

[data-theme="dark"] .cm-cell {
    background: #1f2937;
}

[data-theme="dark"] .cm-cell-correct {
    background: #064e3b;
}

[data-theme="dark"] .cm-cell-correct .cm-cell-value {
    color: #6ee7b7;
}

[data-theme="dark"] .cm-cell-correct .cm-cell-percent {
    color: #a7f3d0;
}

[data-theme="dark"] .cm-cell-error {
    background: #7f1d1d;
}

[data-theme="dark"] .cm-cell-error .cm-cell-value {
    color: #fca5a5;
}

[data-theme="dark"] .cm-cell-error .cm-cell-percent {
    color: #fecaca;
}

[data-theme="dark"] .cm-cell-empty {
    background: #111827;
}

[data-theme="dark"] .cm-legend-correct {
    background: #064e3b;
}

[data-theme="dark"] .cm-legend-error {
    background: #7f1d1d;
}

[data-theme="dark"] .cm-legend-empty {
    background: #111827;
}

/* Overall accuracy display */
.insights-overall-accuracy {
    margin-top: 16px;
    padding: 16px;
    background: var(--gray-50);
    border: 1px solid var(--insights-border);
    border-radius: var(--border-radius);
    text-align: center;
}

[data-theme="dark"] .insights-overall-accuracy {
    background: var(--gray-800);
}

.insights-overall-label {
    font-size: 14px;
    color: var(--insights-text-muted);
    margin-bottom: 8px;
}

.insights-overall-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--insights-success);
}

/* ===========================
   Responsive Adjustments
   =========================== */
@media (max-width: 767px) {
    .confusion-matrix-table {
        font-size: 12px;
    }

    .confusion-matrix-table th,
    .confusion-matrix-table td {
        padding: 8px 4px;
    }
    
    .insights-class-metrics {
        font-size: 12px;
        gap: 12px;
    }
}

/* ===========================
   GRADCAM HEATMAP STYLES
   =========================== */

/* Heatmap Section */
.insights-heatmaps {
    padding: 24px;
    background: var(--insights-background);
    border: 1px solid var(--insights-border);
    border-radius: var(--border-radius);
    margin-bottom: 20px;
}

/* Metrics Section - Same styling as heatmaps */
.insights-metrics {
    padding: 24px;
    background: var(--insights-background);
    border: 1px solid var(--insights-border);
    border-radius: var(--border-radius);
    margin-bottom: 20px;
}

.insights-section-description {
    font-size: 14px;
    color: var(--insights-text-muted);
    margin-bottom: 16px;
    line-height: 1.5;
}

/* Heatmap Generator Modal */
.heatmap-generator-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--insights-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9502;
    padding: 20px;
}

.heatmap-generator-modal {
    background: var(--insights-background);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.heatmap-generator-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--insights-border);
}

.heatmap-generator-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--insights-text);
}

.heatmap-close-btn {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--insights-text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--border-radius);
    transition: all 0.2s;
}

.heatmap-close-btn:hover {
    background: var(--insights-border);
    color: var(--insights-text);
}

.heatmap-generator-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

/* Generator Steps */
.heatmap-step {
    margin-bottom: 24px;
}

.heatmap-step h4 {
    font-size: 16px;
    font-weight: 600;
    color: var(--insights-text);
    margin: 0 0 12px 0;
}

/* Sample Actions */
.sample-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.select-all-btn,
.select-none-btn {
    padding: 8px 16px;
    background: var(--insights-background);
    border: 1px solid var(--insights-border);
    border-radius: var(--border-radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--insights-text);
}

.select-all-btn:hover,
.select-none-btn:hover {
    background: var(--insights-border);
    border-color: var(--insights-primary);
}

.selection-count {
    font-size: 14px;
    color: var(--insights-text-muted);
    font-weight: 500;
}

/* Sample Grid */
.sample-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px;
}

.sample-item {
    position: relative;
}

.sample-item input[type="checkbox"] {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 20px;
    height: 20px;
    z-index: 2;
    cursor: pointer;
}

.sample-item label {
    display: block;
    cursor: pointer;
    border: 2px solid var(--insights-border);
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: all 0.2s;
    position: relative;
}

.sample-item input[type="checkbox"]:checked + label {
    border-color: var(--insights-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.sample-item label img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    display: block;
}

.sample-class {
    display: block;
    padding: 6px 8px;
    background: var(--insights-background);
    font-size: 12px;
    text-align: center;
    color: var(--insights-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Configuration Panel */
.heatmap-config {
    background: var(--insights-background);
    border: 1px solid var(--insights-border);
    border-radius: var(--border-radius);
    padding: 16px;
}

.config-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.config-row:last-child {
    margin-bottom: 0;
}

.config-row label {
    font-size: 14px;
    font-weight: 500;
    color: var(--insights-text);
    min-width: 120px;
}

.algorithm-select,
.class-select,
.layer-select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--insights-border);
    border-radius: var(--border-radius);
    font-size: 14px;
    background: var(--insights-background);
    color: var(--insights-text);
}

/* Layer Selection Styles */
.layer-select {
    font-weight: 500;
}

.layer-info-icon {
    font-size: 14px;
    color: var(--insights-primary);
    cursor: help;
    margin-left: 4px;
}

.layer-info {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
    padding: 8px;
    background: rgba(99, 102, 241, 0.05);
    border-radius: var(--border-radius);
    width: 100%;
}

.layer-detail-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--insights-background);
    border: 1px solid var(--insights-border);
    border-radius: 4px;
    font-size: 12px;
    color: var(--insights-text-muted);
}

.layer-detail-badge strong {
    color: var(--insights-text);
    font-weight: 600;
}

input[type="range"] {
    flex: 1;
    margin-right: 8px;
}

.range-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--insights-text);
    min-width: 40px;
    text-align: center;
}

/* Generate Button */
.generate-btn,
.compare-btn,
.compare-methods-btn {
    display: inline-block;
    padding: 14px 28px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--white);
    border: none;
    border-radius: var(--border-radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
    width: 100%;
}

.compare-btn {
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--primary-color) 100%);
    margin-top: 12px;
}

.compare-methods-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    margin-top: 12px;
    margin-left: 0;
}

.generate-btn i,
.compare-btn i,
.compare-methods-btn i {
    margin-right: 8px;
}

.generate-btn:hover:not(:disabled),
.compare-btn:hover:not(:disabled),
.compare-methods-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.generate-btn:disabled,
.compare-btn:disabled,
.compare-methods-btn:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Progress Indicator */
.heatmap-progress {
    padding: 20px;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--insights-border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 14px;
    color: var(--insights-text-muted);
}

/* Heatmap Results Gallery */
.heatmap-results {
    margin-top: 20px;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.gallery-header h4 {
    font-size: 18px;
    font-weight: 600;
    color: var(--insights-text);
    margin: 0;
}

.clear-gallery-btn {
    padding: 8px 16px;
    background: var(--insights-danger);
    color: var(--white);
    border: none;
    border-radius: var(--border-radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.clear-gallery-btn i {
    margin-right: 6px;
}

.clear-gallery-btn:hover {
    background: #dc2626;
}

/* Gallery Grid */
.heatmap-gallery {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.gallery-item {
    background: var(--insights-background);
    border: 1px solid var(--insights-border);
    border-radius: var(--border-radius);
    padding: 16px;
    transition: all 0.2s;
}

.gallery-item:hover {
    border-color: var(--insights-primary);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
}

.gallery-error {
    padding: 20px;
    text-align: center;
    color: var(--insights-danger);
}

.error-message {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.error-message i {
    font-size: 20px;
}

/* Gallery Images */
.gallery-images {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* Changed from 3 to 2 columns */
    gap: 16px; /* Increased gap for better spacing */
    margin-bottom: 12px;
}

.gallery-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.gallery-column span {
    font-size: 13px;
    font-weight: 500;
    color: var(--insights-text-muted);
}

.gallery-original,
.gallery-column canvas {
    width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    border: 1px solid var(--insights-border);
}

/* Gallery Info */
.gallery-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--insights-border);
}

.actual-label {
    font-size: 13px;
    color: var(--insights-text-muted);
}

.predicted-class {
    font-size: 14px;
    font-weight: 600;
    color: var(--insights-text);
}

.download-heatmap {
    padding: 8px 16px;
    background: var(--insights-primary);
    color: var(--white);
    border: none;
    border-radius: var(--border-radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    align-self: flex-start; /* Align to left */
}

.download-heatmap i {
    margin-right: 6px;
}

.download-heatmap:hover {
    background: var(--insights-secondary);
}

/* ===========================
   Layer Comparison Styles
   =========================== */
.layer-comparison-grid {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.comparison-sample-section {
    background: var(--insights-background);
    border: 2px solid var(--insights-border);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.comparison-sample-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--insights-border);
}

.comparison-sample-header h5 {
    font-size: 18px;
    font-weight: 600;
    color: var(--insights-text);
    margin: 0;
}

.comparison-layer-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    align-items: start;
}

.comparison-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: var(--insights-background);
    border: 1px solid var(--insights-border);
    border-radius: var(--border-radius);
    transition: all 0.2s;
}

.comparison-column:hover {
    border-color: var(--insights-primary);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
    transform: translateY(-2px);
}

.comparison-label {
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--insights-text);
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.comparison-resolution {
    font-size: 11px;
    font-weight: 500;
    color: var(--insights-primary);
    background: rgba(99, 102, 241, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
}

.comparison-column img,
.comparison-column canvas {
    width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    border: 1px solid var(--insights-border);
    box-shadow: var(--shadow-sm);
}

.comparison-info {
    font-size: 12px;
    color: var(--insights-text-muted);
    text-align: center;
    padding: 4px 8px;
    background: rgba(99, 102, 241, 0.05);
    border-radius: 4px;
    width: 100%;
}

/* Responsive Adjustments for Heatmaps */
@media (max-width: 768px) {
    .heatmap-generator-modal {
        max-height: 95vh;
    }

    .gallery-images {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .sample-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 8px;
    }

    .sample-item label img {
        height: 80px;
    }

    .config-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .config-row label {
        min-width: auto;
        margin-bottom: 4px;
    }

    .algorithm-select,
    .class-select,
    .layer-select {
        width: 100%;
    }
    
    .layer-info {
        flex-direction: column;
    }
    
    .comparison-layer-row {
        grid-template-columns: 1fr;
    }
    
    .comparison-sample-section {
        padding: 12px;
    }
}

@media (max-width: 480px) {
    .heatmap-generator-overlay {
        padding: 10px;
    }

    .heatmap-generator-header,
    .heatmap-generator-body {
        padding: 16px;
    }

    .gallery-info {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .download-heatmap {
        width: 100%;
    }
}

/* Dark Theme Adjustments for Heatmaps */
[data-theme="dark"] .heatmap-generator-modal {
    background: var(--gray-800);
}

[data-theme="dark"] .sample-item label {
    border-color: var(--gray-700);
}

[data-theme="dark"] .sample-class {
    background: var(--gray-700);
}

[data-theme="dark"] .heatmap-config {
    background: var(--gray-700);
    border-color: var(--gray-600);
}

[data-theme="dark"] .algorithm-select,
[data-theme="dark"] .class-select {
    background: var(--gray-800);
    border-color: var(--gray-600);
    color: var(--gray-100);
}

[data-theme="dark"] .gallery-item {
    background: var(--gray-700);
    border-color: var(--gray-600);
}

[data-theme="dark"] .gallery-column canvas,
[data-theme="dark"] .gallery-original {
    border-color: var(--gray-600);
}

/* ===========================
   Method Selection Styles
   =========================== */
.method-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--insights-border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--insights-background);
    color: var(--insights-text);
    cursor: pointer;
    transition: var(--transition);
}

.method-select:hover {
    border-color: var(--primary-color);
}

.method-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.method-info {
    margin-top: 8px;
    padding: 8px;
    background: var(--gray-100);
    border-radius: 4px;
}

.method-info small {
    color: var(--insights-text-muted);
    font-size: 12px;
}

/* ===========================
   Method Comparison Styles
   =========================== */

.method-comparison-grid {
    display: flex;
    flex-direction: column;
    gap: 30px;
    padding: 20px;
}

.comparison-row {
    background: var(--insights-background);
    border: 1px solid var(--insights-border);
    border-radius: 8px;
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.comparison-sample-header {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--insights-border);
}

.comparison-sample-header h5 {
    margin: 0;
    color: var(--insights-text);
    font-size: 18px;
    font-weight: 600;
}

.comparison-columns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.comparison-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.comparison-column h6 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--insights-text);
    text-align: center;
}

.comparison-column img {
    width: 224px;
    height: 224px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid var(--insights-border);
}

.comparison-column canvas {
    width: 224px;
    height: 224px;
    border-radius: 6px;
    border: 2px solid var(--insights-border);
    box-shadow: var(--shadow-sm);
}

.method-stats {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.stat-badge {
    padding: 4px 10px;
    background: var(--gray-100);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-700);
}

.comparison-error {
    padding: 20px;
    text-align: center;
}

.comparison-error .error-message {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--danger-color);
    font-weight: 500;
}

/* Dark Theme Adjustments for Method Comparison */
[data-theme="dark"] .method-info {
    background: var(--gray-700);
}

[data-theme="dark"] .method-select {
    background: var(--gray-800);
    border-color: var(--gray-600);
    color: var(--gray-100);
}

[data-theme="dark"] .comparison-row {
    background: var(--gray-700);
    border-color: var(--gray-600);
}

[data-theme="dark"] .comparison-sample-header {
    border-bottom-color: var(--gray-600);
}

[data-theme="dark"] .stat-badge {
    background: var(--gray-600);
    color: var(--gray-200);
}

[data-theme="dark"] .comparison-column img,
[data-theme="dark"] .comparison-column canvas {
    border-color: var(--gray-600);
}

/* ===========================
   Responsive: Method Comparison
   =========================== */
@media (max-width: 768px) {
    .comparison-columns {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .compare-methods-btn {
        width: 100%;
        margin-left: 0;
        margin-top: 10px;
    }
}

