/* Basic Dark Mode Theme & Layout Improvements */
body {
    background-color: #333;
    color: #e0e0e0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0; /* Remove body padding, container will handle it */
    line-height: 1.6;
    font-size: 16px;
}

.container {
    max-width: 1200px; /* Increased width */
    margin: 20px auto; /* Add top/bottom margin */
    background-color: #242424; /* Main content area background */
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

header h1 {
    color: #bb86fc;
    text-align: center;
    margin-bottom: 30px;
    font-size: 2.5em;
}

/* Section Styling */
.form-section,
.result-section-area {
    background-color: #2c2c2c; /* Background for sections */
    padding: 25px;
    border-radius: 8px;
    margin-bottom: 30px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.form-section h2, .result-section-area h2 {
    color: #03dac6;
    border-bottom: 2px solid #03dac6;
    padding-bottom: 15px;
    margin-top: 0; /* Remove default h2 margin top for section title */
    margin-bottom: 25px;
    font-size: 1.8em;
}

/* Parameters Grid Layout */
.parameters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
}

.parameter-group {
    background-color: #333333; /* Background for parameter groups */
    padding: 20px;
    border-radius: 6px;
    /* No separate border, background implies grouping */
}

.parameter-group legend {
    color: #bb86fc;
    font-weight: bold;
    font-size: 1.2em;
    padding: 0 10px;
    margin-left: -10px; /* Align with content */
}

/* Priors Grid Layout */
.priors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); /* Adjust minmax for prior items */
    gap: 20px;
}

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

/* Form elements */
form div, fieldset div:not(.priors-grid):not(.prior-item) { /* More specific selector for direct children */
    margin-bottom: 18px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500; /* Slightly less bold */
    color: #b0b0b0; /* Lighter label color */
}

input[type="file"],
input[type="number"],
input[type="text"] {
    width: 100%; /* Use 100% and let padding be handled by box-sizing */
    padding: 12px;
    background-color: #3a3a3a;
    border: 1px solid #555;
    color: #e0e0e0;
    border-radius: 6px;
    box-sizing: border-box;
    font-size: 0.95em;
}

input[type="file"] {
    padding: 8px;
    background-color: #3a3a3a;
}

.submit-section {
    text-align: center; /* Center the button */
    padding-top: 10px; /* Add some space above the button */
}

/* Custom Tooltip Styles */
.has-tooltip {
    position: relative;
    cursor: help;
}

.has-tooltip:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 110%; /* Position above the element */
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    
    background-color: #03dac6;
    color: #121212;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 1.25em; /* Larger font size for the tooltip */
    line-height: 1.4;
    width: max-content;
    max-width: 300px; /* Max width to prevent very long tooltips from breaking layout */
    text-align: center;
    font-weight: normal; /* Normal font weight for tooltip text */
}

#status-message {
    margin-top: 20px;
    padding: 15px;
    border-radius: 6px;
    font-size: 1.05em;
    text-align: center;
}

.status-success {
    background-color: #2E7D32; /* Darker green */
    color: #e0e0e0;
}

.status-error {
    background-color: #C62828; /* Darker red */
    color: #e0e0e0;
}

#exr-viewer-container a {
    color: #bb86fc;
    font-weight: bold;
}

#viewer-controls {
    background-color: #333;
    padding: 10px 15px;
    border-radius: 6px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
}

#viewer-controls label {
    margin-bottom: 0; /* Align with slider */
    color: #03dac6;
}

#viewer-controls input[type="range"] {
    flex-grow: 1;
}

#exr-viewer-container {
    /* border: 2px dashed blue; */
}

/* Force the wrapper into a 2:1 aspect ratio */
#hdr-canvas-wrapper {
    position: relative;
    width: 100%;
    max-width: 800px; /* Limit the max size to prevent it from becoming too large on wide screens */
    padding-bottom: 50%; /* 1024 / 2048 = 0.5 */
    height: 0;
    background-color: #111;
    margin: 10px auto;
    border: 2px dashed gold;
}

#hdr-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 1px solid hotpink;
    background-color: #222;
}

#pixel-value-display {
    margin-top: 10px;
    padding: 10px;
    background-color: #333;
    border-radius: 4px;
    font-family: monospace;
    min-height: 25px;
    color: #03dac6;
    font-size: 0.9em;
    word-break: break-all;
}

footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #333;
    color: #888;
    font-size: 0.9em;
}

/* Styles for Applied Priors Display */
#applied-priors-section h3 {
    color: #03dac6;
    margin-bottom: 10px;
}

.priors-display-list {
    list-style-type: none;
    padding-left: 0;
    max-height: 200px; /* Example max height */
    overflow-y: auto; /* Add scroll for long lists */
    background-color: #333;
    padding: 10px;
    border-radius: 4px;
    font-size: 0.9em;
}

.priors-display-list li {
    padding: 5px 0;
    border-bottom: 1px solid #444;
}

.priors-display-list li:last-child {
    border-bottom: none;
}

.priors-display-list strong {
    color: #bb86fc; /* Highlight the label */
}

.priors-info {
    font-size: 0.95em;
    padding: 10px;
    background-color: #333333;
    border: 1px dashed #555;
    border-radius: 4px;
    margin-top: 10px;
}

.priors-info code {
    background-color: #424242;
    padding: 2px 5px;
    border-radius: 3px;
    font-family: monospace;
    color: #03dac6;
}

.main-layout {
    display: flex;
    flex-wrap: wrap; /* Allow sidebar to wrap on smaller screens if needed */
    gap: 30px; /* Space between content and sidebar */
}

.content-area {
    flex: 2; /* Takes up 2/3 of the space */
    min-width: 400px; /* Minimum width before wrapping or squishing too much */
}

.sidebar {
    flex: 1; /* Takes up 1/3 of the space */
    min-width: 300px; /* Minimum width for the sidebar */
    /* Sidebar specific background can be added if different from .form-section */
    /* background-color: #2a2a2a; */ 
    /* padding: 20px; */ /* If it directly contains elements not in sections */
    /* border-radius: 8px; */
}

.sidebar .form-section:last-child,
.sidebar .submit-section {
    margin-bottom: 0; /* Remove bottom margin from the last section in sidebar if it's submit */
}

/* Section Styling */
/* ... existing .form-section, .result-section-area styles ... */
/* Ensure sections within sidebar also look good */
.sidebar .form-section {
    margin-bottom: 25px; /* Consistent spacing for sections in sidebar */
}

/* Parameters Grid Layout */
/* ... existing .parameters-grid styles ... */
/* Ensure it applies well within sidebar context if needed */
.sidebar .parameters-grid .parameter-group {
    /* background-color: #363636; */ /* Slightly different if needed for visual distinction */
}

/* ... (rest of your existing CSS, including .prior-item, form elements, button, status messages, viewer styles etc.) ... */

/* Responsive adjustments (example) */
@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
    }
    .content-area,
    .sidebar {
        flex: 1 1 100%; /* Full width on smaller screens */
        min-width: auto;
    }
}

.button-primary {
    background-color: #03dac6; /* Primary accent for button */
    color: #121212;
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1.0em;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.button-primary:hover {
    background-color: #01bfa5;
}

.button-primary:disabled {
    background-color: #444;
    color: #777;
    cursor: not-allowed;
}

/* Progress Bar Styles */
.progress-bar-container {
    width: 100%;
    margin-bottom: 20px;
    padding: 15px;
    background-color: #2c2c2c;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}
.progress-bar-label {
    text-align: center;
    margin-bottom: 10px;
    font-weight: bold;
    color: #03dac6;
}
.progress-bar {
    width: 100%;
    background-color: #3a3a3a;
    border-radius: 6px;
    overflow: hidden;
}
.progress-bar-value {
    width: 100%;
    height: 12px;
    background-color: #bb86fc;
    border-radius: 6px;
    animation: indeterminate-progress 2s infinite linear;
}

@keyframes indeterminate-progress {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* --- HARDWARE UI REDESIGN STYLES --- */
:root {
    --hw-bg-light-gray: #E9E9E9;
    --hw-bg-dark-gray: #D1D1D1;
    --hw-bg-black: #1C1C1C;
    --hw-accent-orange: #FF4E00;
    --hw-accent-red: #F23D3D;
    --hw-accent-blue: #3D99F2;
    --hw-text-dark: #222222;
    --hw-text-light: #FFFFFF;
    --hw-text-lcd: #EFEFEF;
    --hw-led-on: #FF1111;
    --hw-led-off: #3a2222;
    --hw-led-on-glow: 0 0 5px #ff0000, 0 0 10px #ff0000;
}

.device-container {
    background: linear-gradient(180deg, var(--hw-bg-light-gray) 0%, var(--hw-bg-dark-gray) 100%);
    border: 1px solid #B0B0B0;
    border-top-color: #FDFDFD;
    border-radius: 12px;
    padding: 24px;
    padding-top: 60px; /* Make space for theme button */
    box-shadow: 0 10px 30px rgba(0,0,0,0.4), inset 0 1px 1px #fff;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--hw-text-dark);
    max-width: 1400px; /* Constrain width */
    margin: 40px auto; /* Center with vertical margin */
    position: relative;
    transition: background 0.3s ease, color 0.3s ease;
}

.hw-button-theme {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid #B0B0B0;
    background-color: var(--hw-bg-dark-gray);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 10;
}

.hw-button-theme::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    background-color: #333; /* Dark icon on light theme */
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.3s ease;
}

/* --- Dark Mode Styles --- */
body.dark-mode .device-container {
    --hw-bg-light-gray: #3a3a3a;
    --hw-bg-dark-gray: #2a2a2a;
    --hw-text-dark: #cccccc;
    --hw-button-white-bg: #444; /* New var for dark mode white buttons */
    --hw-button-gray-bg: #555;
    
    border-color: #333;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6), inset 0 1px 1px #555;
}

body.dark-mode .hw-button.white {
    background: linear-gradient(180deg, #666 0%, #444 100%);
    color: #f0f0f0;
    border-color: #222;
}

body.dark-mode .hw-button.gray {
    background: linear-gradient(180deg, #777 0%, #555 100%);
    color: #f0f0f0;
    border-color: #333;
}

body.dark-mode .hw-button-theme::before {
    background-color: #DDD; /* Light icon on dark theme */
    box-shadow: inset -3px -3px 0 0 #333; /* Turn it into a moon */
}

.device-screen {
    background: var(--hw-bg-black);
    border-radius: 8px;
    border: 3px solid #333;
    box-shadow: inset 0 4px 8px rgba(0,0,0,0.7);
    /* padding: 20px; */ /* REMOVED */
    margin-bottom: 24px;
    color: var(--hw-text-light);
    height: 500px; /* Placeholder for viewer */
    display: flex;
    align-items: stretch; /* CHANGED */
    justify-content: center;
    position: relative;
    overflow: hidden;
}

#image-preview-container, #hdr-canvas-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

#hdr-canvas, #image-preview, #paint-overlay-canvas, #debug-overlay-canvas {
    max-width: 100%;
    max-height: 100%;
    position: absolute; /* Overlay canvases on top of each other */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 30px;
}

.control-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.hw-label {
    font-size: 0.75em; /* 12px */
    letter-spacing: 0.05em;
    text-align: center;
    color: var(--hw-text-dark);
    opacity: 0.8;
}

.button-group, .button-stack {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.button-stack {
    flex-direction: column;
    align-items: center;
}

.hw-button {
    position: relative;
    border: none;
    cursor: pointer;
    font-family: inherit;
    text-transform: uppercase;
    font-weight: 700;
    font-size: 0.875em; /* 14px */
    letter-spacing: 0.05em;
    padding-top: 2px;
    transition: all 0.1s ease-out;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hw-button:active {
    transform: translateY(2px);
    box-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

.hw-button.rect-md {
    width: 80px;
    height: 40px;
    border-radius: 6px;
}

.hw-button.square-lg {
    width: 70px;
    height: 70px;
    border-radius: 8px;
}

.hw-button.black {
    background: linear-gradient(180deg, #383838 0%, #1A1A1A 100%);
    color: var(--hw-text-light);
    border: 1px solid #111;
    box-shadow: 0 3px 6px rgba(0,0,0,0.5), inset 0 1px 1px rgba(255,255,255,0.15);
}

.hw-button.gray {
    background: linear-gradient(180deg, #D5D5D5 0%, #B0B0B0 100%);
    color: var(--hw-text-dark);
    border: 1px solid #999;
    box-shadow: 0 3px 6px rgba(0,0,0,0.3), inset 0 1px 1px rgba(255,255,255,0.7);
}


.hw-button.white {
    background: linear-gradient(180deg, #FFFFFF 0%, #DCDCDC 100%);
    color: var(--hw-text-dark);
    border: 1px solid #B0B0B0;
    box-shadow: 0 3px 6px rgba(0,0,0,0.2), inset 0 1px 1px rgba(255,255,255,1);
}

.hw-button.orange {
    background: linear-gradient(180deg, #FF7D4D 0%, #FF4E00 100%);
    color: var(--hw-text-light);
    border: 1px solid #D94200;
    box-shadow: 0 3px 6px rgba(0,0,0,0.4), inset 0 1px 1px #FF9B78;
    text-shadow: 0 -1px 1px rgba(0,0,0,0.3);
}

.led {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--hw-led-off);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
    margin: 4px auto 0;
    transition: all 0.2s ease;
}

.led.on {
    background-color: var(--hw-led-on);
    box-shadow: var(--hw-led-on-glow), inset 0 1px 1px rgba(255,255,255,0.3);
}

.control-with-led {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.hw-knob {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(180deg, #383838 0%, #1A1A1A 100%);
    border: 1px solid #111;
    box-shadow: 0 3px 6px rgba(0,0,0,0.5), inset 0 1px 1px rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: ew-resize; /* East-West (horizontal) resize cursor */
}

.hw-knob-body {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 3; /* On top of meter and track */
    transition: transform 0.05s linear;
    display: flex;
    justify-content: center;
}

.hw-knob-indicator {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: var(--hw-accent-orange);
    border-radius: 50%;
    z-index: 2; /* Ensure indicator is on top of meter */
    box-shadow: 0 0 8px var(--hw-accent-orange), 0 0 12px var(--hw-accent-orange);
    top: 6px;
}

.hw-knob-meter {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(135deg); /* Align start point to bottom-left */
    z-index: 1;
}

.hw-knob-meter circle {
    fill: transparent;
    stroke-width: 10;
}

.hw-knob-meter .meter-track {
    stroke: #111;
}

.hw-knob-meter .meter-value {
    stroke: var(--hw-accent-orange);
    transition: stroke-dasharray 0.1s linear, stroke 0.1s linear, filter 0.1s linear;
    filter: drop-shadow(0 0 2px var(--hw-accent-orange));
}

.hw-knob::after {
   display: none; /* Disable the old pseudo-element indicator */
}

.hw-knob.orange-cap {
    background: linear-gradient(180deg, #FF7D4D 0%, #FF4E00 100%);
    box-shadow: 0 3px 6px rgba(0,0,0,0.4), inset 0 1px 1px #FF9B78;
}

.hw-fader {
    position: relative;
    width: 12px;
    height: 120px;
    background-color: #333;
    border-radius: 6px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.6);
}

.hw-fader-handle {
    position: absolute;
    width: 30px;
    height: 30px;
    background: linear-gradient(180deg, #D5D5D5 0%, #B0B0B0 100%);
    border: 1px solid #999;
    border-radius: 4px;
    left: 50%;
    transform: translateX(-50%);
    top: 50%; /* JS will set this */
    cursor: ns-resize;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.hw-fader.horizontal {
    width: 150px;
    height: 12px;
}

.hw-fader.horizontal .hw-fader-handle {
    top: 50%;
    transform: translateY(-50%);
    cursor: ew-resize;
}

.hw-fader-handle::after {
    content: '';
    position: absolute;
    width: 2px;
    height: 8px;
    background-color: #555;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.option-group .hw-button {
    width: auto;
    flex-grow: 1;
    padding: 8px 10px;
    font-size: 0.75em;
    height: 35px;
}

.button-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.button-grid .hw-button {
    flex-basis: calc(33.33% - 10px); /* 3 buttons per row */
    min-width: 60px;
    width: auto; /* Override the default width */
    height: 58px; /* Keep paint buttons slightly smaller */
}

.option-group .hw-button.selected {
    background: linear-gradient(180deg, #4F4F4F 0%, #2A2A2A 100%);
    box-shadow: 0 1px 2px rgba(0,0,0,0.6), inset 0 2px 4px rgba(0,0,0,0.4);
    transform: translateY(2px);
}

.option-group .hw-button.selected .led {
    background-color: var(--hw-led-on);
    box-shadow: var(--hw-led-on-glow), inset 0 1px 1px rgba(255,255,255,0.3);
}

/* New styles for sliders and number displays */
input[type="range"] {
    display: none; /* Hide the original sliders completely */
}

.hw-value-display {
    font-size: 0.8em;
    margin-top: 8px;
    font-weight: 400;
    letter-spacing: 0.05em;
    color: var(--hw-text-dark);
    min-height: 1em;
}

.hw-button-icon {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 10;
    width: 24px;
    height: 24px;
    background-color: transparent;
    border: 2px solid rgba(204, 204, 204, 0.4); /* Subtle gray outline */
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px; /* Slightly rounded corners */
}

.hw-button-icon:hover {
    border-color: rgba(204, 204, 204, 0.8);
}

.hw-button-icon.selected {
    background-color: rgba(204, 204, 204, 0.7); /* Solid fill when selected */
    border-color: rgba(204, 204, 204, 0.7);
}

/* Hide original form elements, we will replace them */
.original-form-controls {
    display: none;
}

.control-panel .hw-button {
    height: 52px;
    width: 117px;
    padding: 0 5px;
}

.hw-value-input-edit {
    width: 80px;
    background-color: #fff;
    color: #111;
    border: 1px solid #777;
    border-radius: 4px;
    text-align: center;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: 0.9em;
    padding: 4px;
    margin-top: 8px;
}

/* New: Make the panel stretch and its content scroll */
#ai-detections-panel {
    flex: 0 0 320px; /* Slightly wider panel */
    background-color: rgba(0,0,0,0.1);
    border: 1px solid var(--hw-panel-border);
    border-radius: 6px;
    padding: 20px; /* ADDED */
    box-sizing: border-box; /* ADDED */
    overflow-y: auto;
    font-family: 'Inter', sans-serif;
    color: #e0e0e0;
    display: none; /* Hidden by default */
}

.device-screen {
    background: var(--hw-bg-black);
    border-radius: 8px;
    border: 3px solid #333;
    box-shadow: inset 0 4px 8px rgba(0,0,0,0.7);
    /* padding: 20px; */ /* REMOVED */
    margin-bottom: 24px;
    color: var(--hw-text-light);
    height: 500px; /* Placeholder for viewer */
    display: flex;
    align-items: stretch; /* CHANGED */
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.device-container {
    background: linear-gradient(180deg, var(--hw-bg-light-gray) 0%, var(--hw-bg-dark-gray) 100%);
    border: 1px solid #B0B0B0;
    border-top-color: #FDFDFD;
    border-radius: 12px;
    padding: 24px;
    padding-top: 60px; /* Make space for theme button */
    box-shadow: 0 10px 30px rgba(0,0,0,0.4), inset 0 1px 1px #fff;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--hw-text-dark);
    max-width: 1400px; /* Constrain width */
    margin: 40px auto; /* Center with vertical margin */
    position: relative;
    transition: background 0.3s ease, color 0.3s ease;
}

.hw-button .led { margin-left: auto; align-self: center; }

#processing-results-container {
    /* Removed absolute positioning and opacity transition */
    background: rgba(0,0,0,0.2);
    color: #ccc;
    padding: 8px;
    border-radius: 4px;
    font-size: 0.75em;
    font-family: monospace;
    max-height: 150px; /* Give it a max height before it scrolls */
    overflow-y: auto;
}

#processing-results-container ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
}
        
/* Disabled State Styles */
.hw-button:disabled,
.hw-knob.disabled {
    background-color: #444;
    color: #777;
    cursor: not-allowed;
}

.panel-section {
    margin-bottom: 20px;
} 