/* ========== STAGE 1: Basic Layout Styles ========== */

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

:root {
    --bg-dark: #0d0d0d;
    --bg-sidebar: #161616;
    --bg-input: #222;
    --text-primary: #f5f5f5;
    --text-secondary: #888;
    --accent: #ffffff;
    --accent-hover: #e0e0e0;
    --border: #333;
    --radius: 8px;
    --radius-sm: 4px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.logo {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
}

.logo span {
    color: var(--accent);
}

/* Control Groups */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-label {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

/* Toggle Buttons */
.toggle-group {
    display: flex;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 3px;
}

.toggle-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.toggle-btn:hover {
    color: var(--text-primary);
}

.toggle-btn.active {
    background: var(--accent);
    color: #0d0d0d;
}

/* Text Input */
.input-row {
    display: flex;
    gap: 6px;
}

.text-input {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: 'SF Mono', Monaco, monospace;
}

.text-input:focus {
    outline: none;
    border-color: var(--accent);
}

.text-input::placeholder {
    color: var(--text-secondary);
}

.icon-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--border);
    border-color: var(--accent);
}

/* Select Input */
.select-input {
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
}

.select-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Color Inputs Section */
.color-inputs-section {
    margin-top: 8px;
}

.color-inputs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.palette-upload-label {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.palette-upload-label:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

/* Slider Row */
.slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-row input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
}

.slider-value {
    min-width: 28px;
    text-align: right;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.color-input {
    width: 100%;
    height: 40px;
    padding: 2px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}

.color-input::-webkit-color-swatch {
    border-radius: var(--radius-sm);
    border: none;
}

.color-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

/* Collapsible Advanced Panel */
.collapse-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.collapse-header:hover {
    border-color: var(--accent);
}

.collapse-icon {
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.collapse-header.open .collapse-icon {
    transform: rotate(180deg);
}

.advanced-panel {
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    margin-top: -1px;
}

.method-settings {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.setting-row {
    display: grid;
    grid-template-columns: 1fr 100px 32px;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
}

.setting-row label {
    color: var(--text-secondary);
}

.setting-row input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.value-display {
    text-align: right;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 0.75rem;
    color: var(--text-primary);
}

.checkbox-row {
    grid-template-columns: 1fr auto;
}

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

/* Action Buttons */
.actions {
    margin-top: auto;
}

.primary-btn {
    width: 100%;
    padding: 14px 20px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    color: #0d0d0d;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.primary-btn:hover {
    background: var(--accent-hover);
}

.primary-btn:active {
    transform: scale(0.98);
}

.export-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.secondary-btn {
    flex: 1;
    padding: 10px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: var(--bg-input);
    border-color: var(--accent);
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg-dark);
    overflow: auto;
}

.canvas-container {
    position: relative;
    width: fit-content;
    height: fit-content;
    border-radius: var(--radius);
    overflow: visible;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#gradient-canvas {
    display: block;
    width: auto;
    height: auto;
    max-width: calc(100vw - 330px);
    max-height: calc(100vh - 48px);
}

#svg-container {
    display: block;
}

#svg-container svg {
    display: block;
    width: auto;
    height: auto;
    max-width: calc(100vw - 330px);
    max-height: calc(100vh - 48px);
}

/* Fixed Size Display */
.size-display {
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    text-align: center;
    font-family: 'SF Mono', Monaco, monospace;
}

/* Preset Heightmaps Grid */
.preset-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}

.preset-btn {
    aspect-ratio: 1;
    padding: 0;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-dark);
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s;
}

.preset-btn:hover {
    border-color: var(--accent);
    transform: scale(1.05);
}

.preset-btn.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}

.preset-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: grayscale(1) contrast(1.1);
    transition: all 0.2s;
}

.preset-btn:hover img {
    filter: grayscale(0.5) contrast(1.2);
}

.preset-btn.active img {
    filter: grayscale(0) contrast(1);
}

.divider-text {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: center;
    margin: 8px 0;
    position: relative;
}

.divider-text::before,
.divider-text::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 25%;
    height: 1px;
    background: var(--border);
}

.divider-text::before { left: 0; }
.divider-text::after { right: 0; }

/* Mini Toggle for Source Selection */
.source-toggle {
    grid-template-columns: 1fr !important;
    gap: 6px !important;
}

.source-toggle label {
    margin-bottom: 4px;
}

.mini-toggle {
    display: flex;
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.mini-btn {
    flex: 1;
    padding: 6px 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.mini-btn:hover {
    color: var(--text-primary);
}

.mini-btn.active {
    background: var(--accent);
    color: #0d0d0d;
}

/* Upload Section */
.upload-section {
    margin: 8px 0;
}

.upload-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
}

.upload-label:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.upload-label.dragover {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
}

.preview-container {
    position: relative;
    margin-top: 8px;
    border-radius: var(--radius);
    overflow: hidden;
}

.preview-container img {
    width: 100%;
    height: 60px;
    object-fit: cover;
    filter: grayscale(1);
    border-radius: var(--radius);
}

.clear-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 12px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-btn:hover {
    background: var(--accent);
}

/* Toggle Switch */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.2s;
}

.toggle-row:hover {
    border-color: var(--accent);
}

.toggle-checkbox {
    display: none;
}

.toggle-slider {
    width: 40px;
    height: 22px;
    background: var(--border);
    border-radius: 11px;
    position: relative;
    transition: all 0.2s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: all 0.2s;
}

.toggle-checkbox:checked + .toggle-slider {
    background: var(--accent);
}

.toggle-checkbox:checked + .toggle-slider::after {
    left: 21px;
}

/* Text Preview Overlay */
.text-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    pointer-events: none;
    z-index: 100;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Scrollbar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    .app {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        min-width: unset;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    
    .canvas-area {
        padding: 16px;
    }
}
