/* ==========================================
   STYLES.CSS - PID CASCADE SIMULATOR
   ========================================== */

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: #f0f2f5;
    color: #1a202c;
    line-height: 1.5;
    min-width: 1280px;
}

/* Header */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

header .subtitle {
    font-size: 0.875rem;
    font-weight: 400;
    opacity: 0.9;
    margin-top: 0.25rem;
}

.mode-indicators {
    display: flex;
    gap: 1rem;
}

.mode-badge {
    background-color: rgba(255, 255, 255, 0.2);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 600;
}

.mode-badge.running {
    background-color: #10b981;
}

.mode-badge.stopped {
    background-color: #ef4444;
}

/* HMI Section Styling */
.hmi-layout {
    display: flex;
    gap: 1.5rem;
    align-items: stretch;
}

#svg-container {
    background-color: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.hmi-side-controls {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.hmi-side-controls .control-group {
    margin-bottom: 0;
    height: 100%;
}

/* Main Layout */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Sections */
section {
    background-color: white;
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
}

.hmi-section {
    width: 100%;
}

.chart-section {
    width: 100%;
}

.control-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.section-header {
    grid-column: 1 / -1;
    margin-bottom: 1rem;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 0.5rem;
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #2d3748;
}

/* SVG Container specifically */
#svg-container svg {
    max-width: 100%;
    height: auto;
}

/* Interactive text styling inside SVG */
[data-cell-id] foreignObject div div div {
    padding: 2px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    cursor: pointer;
    border: 1px solid transparent;
}

[data-cell-id] foreignObject div div div:hover {
    background: rgba(66, 153, 225, 0.1);
    border-color: rgba(66, 153, 225, 0.3);
}

[data-cell-id] foreignObject div div div:focus {
    background: #fff;
    outline: none;
    border: 1px solid #4299e1;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.2);
    color: #1a202c;
}

#hmi-diagram img.hmi-diagram {
    max-width: 100%;
    height: auto;
}

/* SVG interactive elements styling */
[data-cell-id] foreignObject div div div {
    padding: 2px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    cursor: pointer;
    border: 1px solid transparent;
    font-weight: 600;
}

[data-cell-id] foreignObject div div div:hover {
    background: rgba(66, 153, 225, 0.1);
    border-color: rgba(66, 153, 225, 0.3);
}

[data-cell-id="prod-temp"] foreignObject div div div {
    color: #3b82f6;
    font-size: 14px;
}

[data-cell-id="heat-water-temp"] foreignObject div div div {
    color: #10b981;
    font-size: 14px;
}

[data-cell-id="prop-valve-cv"] foreignObject div div div {
    color: #f59e0b;
    font-size: 14px;
}

/* Chart Controls */
.chart-controls {
    margin-bottom: 1rem;
    background-color: #f7fafc;
    padding: 1rem;
    border-radius: 0.5rem;
}

.chart-controls h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 0.75rem;
}

.chart-time-controls {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.chart-time-controls .control-row {
    flex: 0 0 auto;
    margin-bottom: 0;
}

.chart-time-controls .button-group {
    flex: 1 1 auto;
    margin-bottom: 0;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
}

.checkbox-grid label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: #4a5568;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: background-color 0.2s;
}

.checkbox-grid label:hover {
    background-color: #edf2f7;
}

.checkbox-grid input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.color-marker {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    margin: 0 4px;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.1);
}

/* Chart Container */
#chart-container {
    width: 100%;
    height: 500px;
    background-color: #ffffff;
    border-radius: 0.5rem;
    display: block;
    overflow: hidden;
    box-sizing: border-box;
}

#chart-container > div {
    width: 100% !important;
    height: 100% !important;
}

#chart-container canvas,
#chart-container svg {
    width: 100% !important;
    height: 100% !important;
}

.cascade-container {
    display: contents;
}

/* Control Groups */
.control-group {
    background-color: #f7fafc;
    border-radius: 0.5rem;
    padding: 1rem;
}

.control-group h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 1rem;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.control-row label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #4a5568;
    min-width: 100px;
}

.control-row input[type="number"],
.control-row input[type="range"],
.control-row select {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.control-row input[type="number"]:focus,
.control-row select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Buttons */
.button-group {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.btn {
    flex: 1;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background-color: #5568d3;
}

.btn-primary:active {
    background-color: #4c51bf;
}

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

.btn-secondary:hover {
    background-color: #4a5568;
}

.btn-secondary:active {
    background-color: #2d3748;
}

.btn-danger {
    background-color: #ef4444;
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-danger:active {
    background-color: #b91c1c;
}

.btn-warning {
    background-color: #f59e0b;
    color: white;
}

.btn-warning:hover {
    background-color: #d97706;
}

.btn-warning:active {
    background-color: #b45309;
}

.btn.active {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    background-color: #4c51bf;
}

.btn-micro {
    padding: 0.125rem 0.5rem;
    border: 1px solid #cbd5e0;
    background-color: white;
    color: #4a5568;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: 0.5rem;
}

.btn-micro:hover {
    background-color: #edf2f7;
    border-color: #a0aec0;
}

.btn-micro:active {
    background-color: #e2e8f0;
}

/* Slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    transition: background 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #5568d3;
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
}

#valve_slider_value {
    min-width: 50px;
    font-weight: 600;
    color: #4a5568;
}

/* Score Display */
.score-value {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.125rem;
    font-weight: 600;
}

.score-value label {
    color: #4a5568;
}

.score-value span {
    color: #667eea;
    font-size: 1.25rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 1rem;
    background-color: #2d3748;
    color: #a0aec0;
    font-size: 0.875rem;
}

/* Responsive Design */
@media (max-width: 1400px) {
    main {
        max-width: 1200px;
    }
}

@media (min-width: 1600px) {
    main {
        max-width: 1600px;
    }
}

/* Utility Classes */
.text-success {
    color: #10b981;
}

.text-warning {
    color: #f59e0b;
}

.text-danger {
    color: #ef4444;
}

/* Animation */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.pulse {
    animation: pulse 2s ease-in-out infinite;
}

.hidden {
    display: none !important;
}

/* uPlot Tooltip */
.chart-tooltip {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    padding: 8px 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    z-index: 9999;
    font-size: 0.8rem;
    color: #1a202c;
    min-width: 200px;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.tooltip-hint {
    font-size: 0.75rem;
    color: #718096;
    font-style: italic;
    margin-top: 4px;
    text-align: right;
    display: block;
}

/* UI Tooltips (General) */
.ui-tooltip {
    background: #2d3748;
    color: white;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    max-width: 250px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    z-index: 10001;
    position: absolute;
    pointer-events: none;
    line-height: 1.4;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.ui-tooltip b {
    color: #6366f1;
    display: block;
    margin-bottom: 4px;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

/* Highlighting elements that have hints when ALT is pressed */
body.alt-pressed [data-hint] {
    cursor: help !important;
}

body.alt-pressed .control-row:hover, 
body.alt-pressed .button-group button:hover,
body.alt-pressed .score-value:hover {
    outline: 2px solid #6366f1;
    outline-offset: 2px;
    background-color: rgba(99, 102, 241, 0.05);
    border-radius: 4px;
}

.tooltip-time {
    font-weight: 700;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 6px;
    padding-bottom: 4px;
    color: #4a5568;
}

.tooltip-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.tooltip-item:last-child {
    margin-bottom: 0;
}

.tooltip-color {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

.tooltip-label {
    flex: 1;
    color: #4a5568;
}

.tooltip-value {
    font-weight: 600;
    font-family: monospace;
    color: #2d3748;
}

/* ==========================================
   SCORE MODAL STYLES
   ========================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
    text-align: center;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-content h2 {
    color: #10b981;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.modal-score {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.score-label {
    display: block;
    font-size: 0.875rem;
    opacity: 0.9;
    margin-bottom: 0.25rem;
}

.score-number {
    display: block;
    font-size: 2.5rem;
    font-weight: 700;
    font-family: monospace;
}

.modal-info {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    color: #718096;
}

.modal-info strong {
    color: #2d3748;
}

.modal-input-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.modal-input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 0.5rem;
}

.modal-input-group input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

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

.modal-buttons {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.modal-buttons .btn {
    flex: 1;
    padding: 0.75rem 1rem;
}

.btn-link {
    background: none;
    border: none;
    color: #667eea;
    cursor: pointer;
    font-size: 0.875rem;
    text-decoration: underline;
    margin-top: 0.5rem;
}

.btn-link:hover {
    color: #5568d3;
}

.save-status {
    margin-top: 0.75rem;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
}

.save-status.success {
    background: #d1fae5;
    color: #065f46;
}

.save-status.error {
    background: #fee2e2;
    color: #991b1b;
}

/* ==========================================
   LEADERBOARD PANEL STYLES
   ========================================== */

.leaderboard-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s ease-out;
}

.leaderboard-panel.hidden {
    display: none;
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px 12px 0 0;
}

.leaderboard-header h3 {
    margin: 0;
    color: white;
    font-size: 1.25rem;
}

.btn-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 1.5rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.leaderboard-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

.leaderboard-table th {
    text-align: left;
    padding: 0.75rem 0.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #718096;
    border-bottom: 2px solid #e2e8f0;
}

.leaderboard-table td {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.875rem;
}

.leaderboard-table tr:hover td {
    background: #f7fafc;
}

.leaderboard-table tr:first-child td {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(101, 126, 234, 0.1) 100%);
    font-weight: 600;
}

.leaderboard-table .loading {
    text-align: center;
    color: #718096;
    padding: 2rem;
}

.leaderboard-table .rank-1 { color: #f59e0b; font-weight: 700; }
.leaderboard-table .rank-2 { color: #9ca3af; font-weight: 700; }
.leaderboard-table .rank-3 { color: #d97706; font-weight: 700; }

.leaderboard-table .mode-badge-small {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.mode-badge-small.single {
    background: #dbeafe;
    color: #1e40af;
}

.mode-badge-small.cascade {
    background: #fce7f3;
    color: #9d174d;
}

.leaderboard-footer {
    padding: 1rem;
    border-top: 1px solid #e2e8f0;
    text-align: center;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
}

.schemes-section {
    width: 100%;
}

.schemes-section .section-header {
    margin-bottom: 1rem;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 0.5rem;
}

.schemes-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.schemes-image {
    max-width: 100%;
    height: auto;
    border: 1px solid #cbd5e1;
    border-radius: 0.375rem;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.schemes-caption {
    color: #64748b;
    font-size: 0.875rem;
    text-align: center;
    font-style: italic;
}
