:root {
    --bg-dark: #121212;
    --bg-panel: #1e1e1e;
    --bg-light: #2c2c2c;
    --accent: #646cff;
    --accent-hover: #535bf2;
    --text-main: #ffffff;
    --text-muted: #rgba(255, 255, 255, 0.7);
    --border: #444;
}

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.main-header {
    background: var(--bg-panel);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 1.2rem;
    font-weight: bold;
}
.logo span { color: var(--accent); }

.mode-selector {
    display: flex;
    gap: 10px;
}

.mode-btn {
    background: transparent;
    border: 1px solid transparent;
    color: #ccc;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: 0.2s;
}

.mode-btn:hover { background: var(--bg-light); }
.mode-btn.active {
    background: var(--bg-light);
    color: var(--accent);
    border-color: var(--accent);
}

/* Workspace */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Controls Panel */
.controls-panel {
    width: 300px;
    background: var(--bg-panel);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.upload-btn-sidebar {
    width: 100%;
    margin-bottom: 20px;
    padding: 24px 20px;
    background: #ffffff;
    color: #1e1e1e;
    border: 2px solid var(--accent);
    display: flex;
    justify-content: center;
    gap: 14px;
    align-items: center;
    font-size: 1.25rem;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.15);
}
.upload-btn-sidebar i {
    font-size: 1.5rem;
}
.upload-btn-sidebar:hover {
    background: #f0f0f0;
    border-color: var(--accent-hover);
    color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 255, 255, 0.25);
}

.panel-section {
    border-bottom: 1px solid var(--border);
    padding-bottom: 20px;
}

.panel-section h3 {
    font-size: 0.9rem;
    color: #aaa;
    margin-top: 0;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.control-group {
    margin-bottom: 15px;
}

.control-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

.hidden { display: none !important; }

select, textarea, input[type="text"] {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: #fff;
    padding: 8px;
    border-radius: 4px;
    font-family: inherit;
}
textarea { resize: vertical; min-height: 80px; }

.btn-primary {
    width: 100%;
    background: var(--accent);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
    background: var(--bg-light);
    color: #aaa;
    border: 1px solid var(--border);
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}
.btn-text {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    text-decoration: underline;
    font-size: 0.8rem;
    padding: 0;
}

.hint { font-size: 0.75rem; color: #666; margin-top: 4px; }

/* Tool buttons row */
.tool-row {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

.tool-btn {
    flex: 1;
    padding: 10px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: #888;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-btn:hover {
    background: var(--bg-light);
    color: white;
}

.tool-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.full-width {
    width: 100%;
    margin-top: 10px;
}

.color-picker {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    align-items: center;
}

.color-opt {
    width: 24px; 
    height: 24px; 
    border-radius: 50%; 
    cursor: pointer; 
    border: 2px solid transparent;
    transition: all 0.2s;
}
.color-opt:hover { transform: scale(1.15); }
.color-opt.active { border-color: white; transform: scale(1.15); box-shadow: 0 0 8px rgba(255,255,255,0.5); }

#custom-color {
    width: 30px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}

/* Slider controls */
input[type="range"] {
    width: 100%;
    margin: 8px 0 15px 0;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-dark);
    border-radius: 4px;
    height: 6px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

/* Multi-Image Mode Upload Box */
.upload-box {
    position: relative;
    width: 100%;
    height: 150px;
    background: var(--bg-dark);
    border: 1px dashed var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 10px;
}

.upload-box input[type="file"] {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

.upload-label {
    color: #666;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 5px;
    pointer-events: none;
}

#ref-preview {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    margin: auto;
}

#ref-preview:not(.hidden) ~ .upload-label {
    display: none;
}

/* Viewport */
.viewport {
    flex: 1;
    padding: 20px;
    background: #000;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
}

/* Tip section */
.tip-section {
    background: rgba(100, 108, 255, 0.15);
    border: 1px solid rgba(100, 108, 255, 0.3);
    border-radius: 6px;
    padding: 10px 15px;
    font-size: 0.85rem;
    color: #ccc;
}

.tip-section strong {
    color: var(--accent);
}

.parallel-view {
    display: flex;
    gap: 20px;
    height: 45vh;
    max-height: 500px;
    min-height: 300px;
    flex-shrink: 0;
}

.region-selector-bar {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    background-color: #ffffff;
    padding: 16px 6px;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    gap: 12px;
    color: #333;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    width: 90px;
    flex-shrink: 0;
    height: 100%;
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 10;
}

.region-selector-bar::-webkit-scrollbar {
    width: 4px;
}
.region-selector-bar::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 4px;
}

.region-header {
    font-size: 0.8rem;
    font-weight: 700;
    text-align: center;
    border-bottom: 2px solid #646cff;
    padding-bottom: 6px;
    width: 80%;
    margin-bottom: 4px;
    color: #1e1e1e;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.region-checkbox {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.75rem;
    cursor: pointer;
    gap: 6px;
    font-weight: 600;
    color: #444;
    transition: all 0.2s ease;
    text-align: center;
    line-height: 1.1;
}

.region-checkbox:hover {
    color: #646cff;
    transform: translateY(-2px);
}

.region-checkbox input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    width: 20px;
    height: 20px;
    accent-color: #646cff;
}

.image-container {
    flex: 1;
    background: #1a1a1a;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border);
}

.img-header {
    background: #252525;
    padding: 8px 12px;
    font-size: 0.8rem;
    text-align: center;
    color: #888;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.img-header span {
    flex: 1;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-controls {
    display: flex;
    gap: 5px;
    align-items: center;
}

.icon-btn {
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 5px 8px;
    font-size: 0.85rem;
    transition: all 0.2s;
    border-radius: 4px;
}

.icon-btn.small-text {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 5px 6px;
}

.icon-btn:hover {
    color: var(--accent);
    background: rgba(100, 108, 255, 0.1);
}

.zoom-label {
    font-size: 0.75rem;
    color: #888;
    min-width: 40px;
    text-align: center;
}

.download-btn {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 0.85rem;
    transition: color 0.2s;
}

.download-btn:hover {
    color: var(--accent);
}

.canvas-wrapper, .result-wrapper {
    flex: 1;
    position: relative;
    background-image: 
        linear-gradient(45deg, #151515 25%, transparent 25%), 
        linear-gradient(-45deg, #151515 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #151515 75%), 
        linear-gradient(-45deg, transparent 75%, #151515 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    padding: 10px;
    overflow: auto;  /* Allow scrolling when zoomed larger than container */
}

/* Zoom container for pan/zoom support */
.zoom-container, .result-zoom-container {
    position: relative;
    display: inline-block;
    margin: auto;
    transition: transform 0.05s ease-out;
}

#main-image, #result-image {
    /* Remove max constraints so image can zoom larger than container */
    max-width: none;
    max-height: none;
    display: block;
    z-index: 10;
    pointer-events: none;
}

/* Canvas Overlay - positioned exactly over the image */
#drawing-canvas {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 20;
    cursor: crosshair;
}

#click-overlay {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 20;
    cursor: crosshair;
}

/* Layer indicator */
.layer-indicator {
    position: absolute;
    bottom: 15px;
    right: 15px;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    color: #888;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 30;
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #555;
    cursor: pointer;
    padding: 20px;
}
.upload-placeholder:hover { color: var(--accent); }
.upload-placeholder i { font-size: 3rem; margin-bottom: 10px; }

/* Comparison Slider */
.comparison-section {
    flex: 1;
    min-height: 250px;
    background: #1a1a1a;
    border-radius: 8px;
    padding: 0;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.comparison-header {
    background: #252525;
    padding: 8px 12px;
    font-size: 0.8rem;
    color: #888;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.comparison-header span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.comparison-section h4 { text-align: center; margin: 0 0 10px 0; font-size: 0.9rem; color: #888; }

.slider-container {
    position: relative;
    flex: 1; /* Fill the section */
    width: 100%;
    overflow: hidden;
    max-width: 800px; /* Slightly wider */
    margin: 0 auto;
    /* Ensure aspect ratio isn't lost but we need JS to set height or use aspect-ratio css if image loaded */
}

.slider-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.bottom-layer {
    z-index: 1;
}

.top-layer {
    z-index: 2;
    clip-path: inset(0 50% 0 0);
    border-right: 3px solid white;
    box-sizing: border-box;
}

.layer-inner {
    /* Not needed with clip-path approach */
    display: none;
}

input.slider {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 10;
    opacity: 0;
    cursor: col-resize;
    margin: 0;
}

.slider-button {
    pointer-events: none;
    position: absolute;
    top: 50%;
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 11;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.slider-button::after {
    content: '\f337'; /* FontAwesome arrows-left-right */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    color: #333;
    font-size: 16px;
}

input.slider {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 10;
    opacity: 0;
    cursor: col-resize;
    margin: 0;
}

/* Loader */
.loader {
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top: 3px solid white;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Aesthetic Mode Styles */
.aesthetic-options {
    margin: 10px 0;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.aesthetic-info {
    margin-top: 15px;
    padding: 12px;
    background: rgba(100, 108, 255, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(100, 108, 255, 0.3);
}

.aesthetic-info strong {
    color: var(--accent);
    font-size: 0.9rem;
}

.dimension-list {
    margin: 8px 0 0 0;
    padding-left: 20px;
    font-size: 0.8rem;
    color: #aaa;
}

.dimension-list li {
    margin: 4px 0;
}

/* Smart Prompt routing receipt */
.intent-status {
    margin-top: 15px;
    padding: 12px;
    background: #16181f;
    border: 1px solid rgba(100, 108, 255, 0.35);
    border-radius: 8px;
    color: #d8d8e8;
}

.intent-route {
    font-size: 0.9rem;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 6px;
}

.intent-detail,
.intent-confidence {
    font-size: 0.78rem;
    color: #aaa;
}

.intent-reasons {
    margin: 8px 0;
    padding-left: 18px;
    font-size: 0.78rem;
    color: #b8b8c8;
}

.intent-reasons li {
    margin: 4px 0;
}

.intent-signals {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.intent-signals span {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 3px 7px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #cfcfff;
    font-size: 0.72rem;
    word-break: break-word;
}

.intent-aesthetic {
    border-color: rgba(144, 202, 249, 0.65);
}

.intent-aesthetic .intent-route {
    color: #90caf9;
}

.intent-standard {
    border-color: rgba(165, 214, 167, 0.65);
}

.intent-standard .intent-route {
    color: #a5d6a7;
}

.intent-analyzing .intent-route {
    color: #ffd166;
}
