/* Copyright 2026 BQ Octantis. All rights reserved. */
/* Version 2.4.4 */

/* --- Theme Variables --- */
:root {
    --bg-color: #ffffff;
    --text-color: #333333;
    --secondary-text: #555555;
    --panel-bg: #f4f4f4;
    --border-color: #dddddd;
    --placeholder-bg: #f0f0f0;
    --button-secondary-bg: #e0e0e0;
    --button-secondary-hover: #d0d0d0;
    --chart-bg: #ffffff;
    --info-shadow: rgba(0,0,0,0.05);
    --separator-color: #ccc;
}

[data-theme="dark"] {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --secondary-text: #aaaaaa;
    --panel-bg: #1e1e1e;
    --border-color: #444444;
    --placeholder-bg: #252525;
    --button-secondary-bg: #333333;
    --button-secondary-hover: #444444;
    --chart-bg: #000000;
    --info-shadow: rgba(0,0,0,0.3);
    --separator-color: #444;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    padding: 20px; 
    margin: 0; 
    background-color: var(--bg-color); 
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
}

.app-switcher {
    text-align: center;
    margin-bottom: 20px;
    font-size: 0.9em;
}
.app-switcher a {
    color: #007bff;
    text-decoration: none;
}
.app-switcher a:hover {
    text-decoration: underline;
}
.app-switcher .active-app {
    color: var(--text-color);
    font-weight: bold;
}
.app-switcher .separator {
    margin: 0 10px;
    color: var(--separator-color);
    user-select: none;
}

/* Theme Toggle Button */
.theme-toggle-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    padding: 2px 8px;
    font-size: 1.1em;
    color: var(--text-color);
    vertical-align: middle;
    transition: background-color 0.2s;
    margin-left: 5px;
}
.theme-toggle-btn:hover {
    background-color: var(--button-secondary-bg);
}

.controls { margin-top: 15px; margin-bottom: 15px; height: 40px; display: flex; justify-content: center; align-items: center; gap: 15px; }

/* --- THE ANALYZER CONTAINER (THE YARD) --- */
.analyzer-container { 
    display: flex; 
    flex-wrap: nowrap;     /* Force side-by-side, no wrapping */
    gap: 40px; 
    width: 92%;           /* Fill 95% of the screen width */
    max-width: none;      /* Remove hard pixel caps */
    justify-content: center; 
    align-items: flex-start; 
}

/* --- THE SECTIONS (THE ROOMS) --- */
.image-section, .chart-section { 
    flex: 1;              /* Share space equally 50/50 */
    min-width: 0;         /* Allow content to shrink correctly inside flex */
    max-width: none;      /* Remove hard pixel caps */
    display: flex; 
    flex-direction: column; 
    align-items: center; 
}

.section-title { font-weight: bold; margin-bottom: 8px; font-size: 0.9em; color: var(--secondary-text); text-align: center; }
.section-footer { 
    font-weight: normal; 
    margin-top: 15px;       /* Tighter spacing to the box above */
    font-size: 0.75em;     /* Slightly smaller to stay unobtrusive */
    color: var(--secondary-text); 
    text-align: left;      /* Left-justified as requested */
    width: 95%;            /* Matches the width of the #colorInfo box */
    align-self: center;    /* Keeps the text block centered in the column while text is left-aligned */
}

/* --- THE CANVAS WRAPPER --- */
.canvas-wrapper { 
    position: relative; 
    width: 100%; 
    max-width: none;      /* Allow the wrapper to fill the section */
    display: flex; 
    justify-content: center; 
    overflow: hidden; 
    min-height: 200px; 
    background-color: var(--placeholder-bg); 
    border: 1px solid var(--border-color); 
    box-sizing: border-box; 
}

#imageCanvas { 
    max-width: 100%; 
    max-height: 85vh;     /* Prevents huge images from exceeding screen height */
    display: block; 
    cursor: crosshair; 
}
#imageCanvas.grabbable { cursor: grab; }
#imageCanvas.grabbing { cursor: grabbing; }

#canvasPlaceholder { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; text-align: center; box-sizing: border-box; transition: opacity 0.3s ease; opacity: 1; pointer-events: auto; z-index: 10; }
#canvasPlaceholder.hidden { opacity: 0; pointer-events: none; }
.placeholder-content { display: flex; flex-direction: column; align-items: center; gap: 15px; padding: 20px; background-color: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.placeholder-content p { margin: 0 0 5px 0; font-weight: bold; color: var(--secondary-text); }

#imageLoader { display: none; }
.file-label-button { padding: 8px 15px; cursor: pointer; background-color: var(--button-secondary-bg); border: 1px solid var(--border-color); border-radius: 4px; font-size: 0.9em; transition: background-color 0.2s ease; display: inline-block; color: var(--text-color); }
.file-label-button:hover { background-color: var(--button-secondary-hover); }

#colorInfo { margin-top: 10px; font-size: 0.9em; line-height: 1.5; background-color: var(--panel-bg); padding: 10px 15px; border: 1px solid var(--border-color); border-radius: 5px; min-height: 90px; width: 95%; text-align: left; box-shadow: 0 1px 3px var(--info-shadow); font-family: monospace; }

#chromaticityChart {
    width: 100% !important;
    height: auto !important;
    max-width: 100%;
    border: 1px solid var(--border-color);
    background-color: var(--chart-bg);
    cursor: default;
}

.chart-controls {
    margin-top: 10px;
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
    font-size: 0.9em;
    width:100%;
}
.chart-bottom-controls {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    width: 100%;
}

#imageSamplesControlsContainer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    width: 100%;
}

.checkbox-group { display: flex; align-items: center; gap: 5px; margin-bottom: 0; flex-shrink: 0; }
.checkbox-group input[type="checkbox"] { cursor: pointer; margin: 0; }
.checkbox-group label {
    font-size: 0.9em;
    white-space: nowrap;
}

.slider-sub-label,
#clipSliderControl .slider-main-label,
#clipSliderControl .clip-value-input,
#sliderValueLabel {
    font-size: 0.6em;
    white-space: nowrap;
    color: var(--secondary-text);
}

.slider-control {
    margin-top: 0;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    color: var(--secondary-text);
    width: 100%;
}

#pixelDensityControl { display: grid; }
#clipSliderControl { 
    display: grid;
    margin-top: 8px;
}

#pixelDensityControl.visible,
#clipSliderControl.visible {
    display: grid;
}

.slider-panel-left {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}
.slider-panel-right {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
}

#samplingSlider, .dual-slider-container {
    width: 100%;
}

#removeButton { padding: 8px 15px; cursor: pointer; background-color: #f8d7da; border: 1px solid #f5c6cb; border-radius: 4px; font-size: 0.9em; transition: background-color 0.2s ease; color: #721c24; }
#removeButton:hover { background-color: #f5c6cb; }

[data-theme="dark"] #removeButton {
    background-color: #442727;
    border-color: #613333;
    color: #f8d7da;
}

#clearSelectedButton {
    padding: 8px 15px;
    cursor: pointer;
    background-color: #cfe2ff;
    border: 1px solid #b6d4fe;
    border-radius: 4px;
    font-size: 0.9em;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    color: #084298;
}
#clearSelectedButton:hover:not(:disabled) {
    background-color: #b6d4fe;
}
#clearSelectedButton:disabled {
    background-color: var(--button-secondary-bg);
    border-color: var(--border-color);
    color: var(--secondary-text);
    cursor: not-allowed;
}

[data-theme="dark"] #clearSelectedButton {
    background-color: #1a2a40;
    border-color: #2c4260;
    color: #cfe2ff;
}

#sampleControl {
    display: flex; 
    align-items: center;
    gap: 5px;
}
#sampleControl label {
    font-size: 0.9em;
    color: var(--secondary-text);
}
#sampleSizeSelector {
    padding: 4px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    font-size: 0.9em;
    cursor: pointer;
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* --- Slider Styling --- */
input[type="range"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 5px;
    background: var(--border-color);
    border-radius: 3px;
}
input[type="range"]::-moz-range-track {
    height: 5px;
    background: var(--border-color);
    border-radius: 3px;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    pointer-events: auto;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background-color: #007bff;
    cursor: grab;
    border: 1px solid rgba(0,0,0,0.5);
    box-shadow: 0 0 5px rgba(0,0,0,0.3);
    margin-top: -5px;
    position: relative;
    z-index: 2;
}
input[type="range"]::-moz-range-thumb {
    pointer-events: auto;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #007bff;
    cursor: grab;
    border: 1px solid rgba(0,0,0,0.5);
    box-shadow: 0 0 5px rgba(0,0,0,0.3);
    position: relative;
    z-index: 2;
}

.dual-slider-container {
    position: relative;
    height: 20px;
}
.dual-slider-container > input[type="range"] {
    width: 100%;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}
.dual-slider-container > input[type="range"]::-webkit-slider-thumb {
    pointer-events: auto;
}
.dual-slider-container > input[type="range"]::-moz-range-thumb {
    pointer-events: auto;
}
#clipSliderHigh::-webkit-slider-runnable-track {
    background: transparent;
}
#clipSliderHigh::-moz-range-track {
    background: transparent;
}

#clipRangeBar {
    position: absolute;
    left: 0%;
    right: 0%;
    top: 50%;
    transform: translateY(-50%);
    height: 5px;
    background-color: #007bff;
    border-radius: 3px;
    z-index: 1;
}
.clip-value-input {
    width: 35px;
    font-family: monospace;
    text-align: center;
    border: 1px solid var(--border-color);
    background-color: var(--bg-color);
    color: var(--text-color);
    border-radius: 3px;
    padding: 2px;
    -moz-appearance: textfield;
}

/* Remove up/down arrows from the clipping value inputs */
.clip-value-input::-webkit-outer-spin-button,
.clip-value-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.clip-value-input {
    -moz-appearance: textfield; /* Firefox */
}

/* Mobile Fallback: Only wrap on very narrow screens */
@media (max-width: 600px) {
    .analyzer-container { flex-direction: column; flex-wrap: wrap; }
    .image-section, .chart-section { width: 100%; }
}