/* Base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 20px;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
}

header h1 {
    font-size: 2rem;
    margin-bottom: 5px;
}

header .subtitle {
    opacity: 0.9;
    font-size: 1rem;
}

/* Controls section */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.upload-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a6fd6;
}

.btn-secondary {
    background: #28a745;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #218838;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
    background: #6c757d;
    color: white;
}

.btn-small:hover {
    background: #5a6268;
}

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

.status {
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.9rem;
    min-width: 200px;
    text-align: center;
}

.status:empty {
    display: none;
}

.status-info {
    background: #e3f2fd;
    color: #1565c0;
}

.status-success {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-error {
    background: #ffebee;
    color: #c62828;
}

/* Display mode controls */
.display-mode-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.display-mode-controls .label {
    font-weight: 500;
    color: #555;
}

.mode-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    border: 2px solid #764ba2;
    border-radius: 20px;
    background: white;
    color: #764ba2;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    background: #f5f0ff;
}

.mode-btn.active {
    background: #764ba2;
    color: white;
}

/* Metric controls */
.metric-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.metric-controls .label {
    font-weight: 500;
    color: #555;
}

.metric-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    border: 2px solid #667eea;
    border-radius: 20px;
    background: white;
    color: #667eea;
    cursor: pointer;
    transition: all 0.2s ease;
}

.metric-btn:hover {
    background: #f0f4ff;
}

.metric-btn.active {
    background: #667eea;
    color: white;
}

/* Trace view controls */
.trace-view-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.trace-view-controls .label {
    font-weight: 500;
    color: #555;
}

.view-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    border: 2px solid #28a745;
    border-radius: 20px;
    background: white;
    color: #28a745;
    cursor: pointer;
    transition: all 0.2s ease;
}

.view-btn:hover {
    background: #f0fff4;
}

.view-btn.active {
    background: #28a745;
    color: white;
}

.summary-metric-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    border: 2px solid #667eea;
    border-radius: 20px;
    background: white;
    color: #667eea;
    cursor: pointer;
    transition: all 0.2s ease;
}

.summary-metric-btn:hover {
    background: #f0f4ff;
}

.summary-metric-btn.active {
    background: #667eea;
    color: white;
}

#reset-zoom-btn {
    margin-left: auto;
}

/* Protocol note */
.protocol-note {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    padding: 10px 20px;
    background: #fffbf0;
    border-radius: 8px;
    border: 1px solid #f0e68c;
}

/* Time window controls */
.time-window-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.time-window-controls .label {
    font-weight: 500;
    color: #555;
}

.time-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.time-input-group label {
    font-size: 0.9rem;
    color: #666;
}

.time-input-group input {
    width: 100px;
    padding: 6px 10px;
    font-size: 0.9rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: right;
}

.time-input-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

#export-graph-btn {
    margin-left: auto;
}

/* Work scale controls */
.work-scale-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.work-scale-controls .label {
    font-weight: 500;
    color: #555;
}

.scale-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.scale-input-group label {
    font-size: 0.9rem;
    color: #666;
}

.scale-input-group input {
    width: 120px;
    padding: 6px 10px;
    font-size: 0.9rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: right;
}

.scale-input-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.help-text {
    font-size: 0.85rem;
    color: #888;
    font-style: italic;
}

/* Chart section */
.chart-section {
    position: relative;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 20px;
    margin-bottom: 20px;
}

#chart-container {
    width: 100%;
    height: 500px;
}

#chart-container svg {
    width: 100%;
    height: 100%;
}

/* Chart elements */
.axis path,
.axis line {
    stroke: #ccc;
}

.axis text {
    fill: #666;
    font-size: 12px;
}

.axis-label {
    font-size: 14px;
    font-weight: 500;
    fill: #333;
}

.data-line {
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.data-line.hidden {
    display: none;
}

.grid line {
    stroke: #e0e0e0;
    stroke-opacity: 0.7;
}

.grid path {
    stroke-width: 0;
}

/* Tooltip */
.tooltip {
    position: absolute;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    border-radius: 6px;
    font-size: 0.85rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 100;
    max-width: 250px;
}

.tooltip.visible {
    opacity: 1;
}

.tooltip-title {
    font-weight: 600;
    margin-bottom: 5px;
    border-bottom: 1px solid rgba(255,255,255,0.3);
    padding-bottom: 5px;
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.tooltip-label {
    color: #aaa;
}

.tooltip-value {
    font-weight: 500;
}

/* Legend section */
.legend-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 15px 20px;
    margin-bottom: 20px;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.legend-header span {
    font-weight: 500;
    color: #555;
}

#legend-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: #f8f9fa;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

.legend-item:hover {
    background: #e9ecef;
}

.legend-item.hidden {
    opacity: 0.4;
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

.legend-label {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: #666;
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .upload-group {
        flex-direction: column;
    }

    .metric-controls {
        flex-direction: column;
        align-items: flex-start;
    }

    #reset-zoom-btn {
        margin-left: 0;
        margin-top: 10px;
    }

    #chart-container {
        height: 350px;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #eee;
}

.tab-btn {
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-bottom: 3px solid transparent;
    background: none;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: #667eea;
    border-bottom-color: #667eea;
}

.tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Perfusion Specific Styles */
.perfusion-params {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 20px;
    margin-bottom: 20px;
}

.perfusion-params h3 {
    margin: 0 0 15px 0;
    color: #333;
}

.param-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.param-input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.param-input-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #555;
}

.param-input-group input {
    padding: 8px 12px;
    font-size: 0.9rem;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.param-input-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.perfusion-file-list {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 15px 20px;
    margin-bottom: 20px;
}

#perfusion-files-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.perfusion-file-item {
    padding: 8px 16px;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.perfusion-file-item:hover {
    background: #e9ecef;
}

.perfusion-file-item.active {
    background: #667eea;
    color: white;
}

#perfusion-chart-container {
    width: 100%;
    height: 500px;
    min-height: 420px;
}

.perfusion-results {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 20px;
    margin-bottom: 20px;
}

.perfusion-results h3,
.perfusion-results h4 {
    color: #333;
    margin: 0 0 15px 0;
}

#perfusion-summary-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: 600;
    color: #333;
}

.table-container {
    margin-top: 20px;
    overflow-x: auto;
}

#perfusion-table-container table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

#perfusion-table-container th,
#perfusion-table-container td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

#perfusion-table-container th {
    background: #f8f9fa;
    font-weight: 600;
    color: #555;
    position: sticky;
    top: 0;
}

#perfusion-table-container tr:hover {
    background: #f8f9fa;
}

/* Peak markers in perfusion chart */
.peak-marker {
    cursor: pointer;
    transition: all 0.2s ease;
}

.peak-marker:hover {
    r: 6;
    fill: #ff4444;
}

.baseline-rect {
    fill: rgba(102, 126, 234, 0.1);
    stroke: rgba(102, 126, 234, 0.3);
    stroke-width: 1;
    stroke-dasharray: 4,2;
}

.highflux-line,
.highflux-start-line,
.highflux-end-line {
    stroke: rgba(255, 68, 68, 0.5);
    stroke-width: 2;
    stroke-dasharray: 6,3;
}

/* Parameter Selection Grid */
.param-selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.param-picker {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.param-picker label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #555;
}

.picker-buttons {
    display: flex;
    gap: 8px;
}

.pick-btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 0.85rem;
    background: white;
    border: 2px solid #667eea;
    color: #667eea;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pick-btn:hover {
    background: #f0f4ff;
}

.pick-btn.active {
    background: #667eea;
    color: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

.param-value {
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #333;
    font-family: 'Courier New', monospace;
}

.param-value.set {
    background: #e8f5e9;
    color: #2e7d32;
    font-weight: 600;
}

/* Peak Status Display */
.peak-status {
    padding: 12px 16px;
    background: #f0f4ff;
    border-radius: 6px;
    border-left: 4px solid #667eea;
    margin-bottom: 15px;
    font-size: 0.95rem;
}

.peak-status strong {
    color: #667eea;
    font-weight: 700;
}

/* Process Controls */
.process-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.process-controls .help-text {
    color: #999;
}

#perfusion-process-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Peak Curation */
.peak-curation {
    background: white;
    border-radius: 8px;
    border: 2px solid #667eea;
    padding: 15px 20px;
    margin-bottom: 20px;
}

.peak-curation h4 {
    margin: 0 0 12px 0;
    color: #667eea;
    font-size: 1rem;
}

.curation-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.curation-input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.curation-input-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #555;
}

.curation-input-group input {
    padding: 8px 12px;
    font-size: 0.9rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
}

.curation-input-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.curation-buttons {
    display: flex;
    gap: 8px;
}

.curation-mode-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Chart Controls */
.chart-controls {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

/* Threshold Line (draggable) */
.threshold-line {
    stroke: #ff9800;
    stroke-width: 3;
    stroke-dasharray: 8,4;
    cursor: ns-resize;
    transition: stroke-width 0.2s ease;
}

.threshold-line:hover {
    stroke-width: 5;
    stroke: #ff5722;
}

.threshold-line.dragging {
    stroke-width: 5;
    stroke: #ff5722;
}

.threshold-label {
    fill: #ff9800;
    font-size: 12px;
    font-weight: bold;
    pointer-events: none;
}

/* Visual feedback for picking mode */
.click-capture.picking {
    cursor: crosshair !important;
}

.click-capture.picking-baseline-start,
.click-capture.picking-baseline-end {
    cursor: crosshair !important;
}

.click-capture.picking-highflux {
    cursor: crosshair !important;
}

/* Baseline selection visual guides */
.baseline-start-line,
.baseline-end-line {
    stroke: rgba(102, 126, 234, 0.7);
    stroke-width: 2;
    stroke-dasharray: 4,2;
}

.highflux-start-marker {
    stroke: rgba(255, 68, 68, 0.7);
    stroke-width: 2;
    stroke-dasharray: 6,3;
}

/* Perfusion Contraction-Level Plots */
.perfusion-plots-section {
    margin: 20px 0 30px 0;
}

.perfusion-plots-section h4 {
    margin-bottom: 15px;
    font-size: 1.1rem;
    color: #333;
}

.perfusion-plots-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.plot-container {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Add Peak Confirmation UI */
.add-peak-confirm-ui {
    margin-top: 15px;
    padding: 15px;
    background: #fff3e0;
    border: 2px solid #ff9800;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(255, 152, 0, 0.2);
}

.add-peak-confirm-ui .confirm-header {
    margin-bottom: 10px;
    font-size: 0.95rem;
    color: #e65100;
}

.add-peak-confirm-ui .confirm-index {
    margin-bottom: 12px;
    font-size: 0.9rem;
}

.add-peak-confirm-ui .confirm-index strong {
    color: #ff9800;
    font-size: 1.1rem;
}

.add-peak-confirm-ui .confirm-adjust-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    justify-content: center;
}

.add-peak-confirm-ui .confirm-adjust-buttons .btn {
    min-width: 50px;
}

.add-peak-confirm-ui .confirm-action-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
    justify-content: center;
}

.add-peak-confirm-ui .confirm-help-text {
    text-align: center;
    color: #666;
    font-style: italic;
}

@media (max-width: 768px) {
    .tab-nav {
        flex-direction: column;
    }

    .param-grid {
        grid-template-columns: 1fr;
    }

    .param-selection-grid {
        grid-template-columns: 1fr;
    }

    .perfusion-plots-grid {
        grid-template-columns: 1fr;
    }

    #perfusion-chart-container {
        height: 350px;
    }
}
