/* ============================================
   SLD Editor — Page-specific styles
   ============================================ */

.sld-layout {
    display: flex;
    height: calc(100vh - var(--navbar-height));
}

/* --- Editor Panel --- */
.editor-panel {
    width: 500px;
    min-width: 360px;
    display: flex;
    flex-direction: column;
    background: #0d1526;
    border-right: 1px solid rgba(255,255,255,0.08);
}

/* --- Toolbar --- */
.toolbar {
    display: flex;
    flex-direction: column;
    gap: 0;
    background: rgba(0,0,0,0.28);
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.toolbar-row {
    padding: 7px 12px;
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar-row-2 {
    padding-top: 0;
    padding-bottom: 7px;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.toolbar-sep {
    width: 1px;
    height: 18px;
    background: rgba(255,255,255,0.12);
    margin: 0 3px;
    flex-shrink: 0;
}

.toolbar select, .toolbar button {
    padding: 5px 10px;
    border-radius: var(--radius-md);
    font-size: 12px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.05);
    color: var(--text-secondary);
    cursor: pointer;
    outline: none;
    font-family: var(--font-sans);
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.toolbar select:focus, .toolbar button:focus { border-color: var(--accent); }
.toolbar button:hover {
    background: rgba(59,130,246,0.12);
    color: var(--text-primary);
    border-color: rgba(59,130,246,0.3);
}
.toolbar button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Apply button */
.toolbar .btn-apply {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
    gap: 5px;
}
.toolbar .btn-apply:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* kbd shortcut badge */
.toolbar kbd {
    display: inline-block;
    background: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 3px;
    padding: 0 4px;
    font-size: 10px;
    line-height: 14px;
    font-family: var(--font-mono);
    color: rgba(255,255,255,0.9);
}

/* Icon-only button */
.toolbar .btn-icon {
    padding: 5px 7px;
    color: var(--text-muted);
}
.toolbar .btn-icon:hover { color: var(--accent); }

/* Legend toggle active state */
.toolbar .btn-legend.active {
    background: rgba(124,58,237,0.2);
    border-color: rgba(124,58,237,0.5);
    color: #a78bfa;
}

/* --- Editor Area --- */
.editor-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.editor-area textarea {
    flex: 1;
    width: 100%;
    padding: 12px 16px;
    background: #0d1117;
    color: #c9d1d9;
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    tab-size: 2;
}
.editor-area textarea::selection { background: rgba(59,130,246,0.3); }

/* CodeMirror overrides */
.editor-area .CodeMirror {
    flex: 1;
    height: 100%;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
}
.editor-area .CodeMirror-gutters {
    border-right: 1px solid rgba(255,255,255,0.08);
}
.editor-area .CodeMirror + textarea { display: none; }

/* --- Editor Status --- */
.editor-status {
    padding: 5px 14px;
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(0,0,0,0.2);
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.status-ok { color: #50fa7b; }
.status-error { color: #ff5555; }
.status-warn { color: #f1fa8c; }

/* --- Compile Result --- */
.compile-result {
    max-height: 200px;
    overflow-y: auto;
    padding: 10px 14px;
    font-size: 11px;
    font-family: var(--font-mono);
    line-height: 1.5;
    background: rgba(0,0,0,0.35);
    border-top: 1px solid rgba(255,255,255,0.08);
    display: none;
    flex-shrink: 0;
}
.compile-result.visible { display: block; }

.compile-result-header {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Type badge */
.type-badge {
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.type-ramp    { background: rgba(59,130,246,0.2); color: #60a5fa; border: 1px solid rgba(59,130,246,0.3); }
.type-intervals { background: rgba(16,185,129,0.2); color: #34d399; border: 1px solid rgba(16,185,129,0.3); }
.type-values  { background: rgba(245,158,11,0.2); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3); }

/* Gradient bar visualization */
.gradient-bar {
    height: 16px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.12);
    margin-bottom: 8px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
}

/* Discrete swatches for VALUES type */
.discrete-row {
    display: flex;
    height: 16px;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.12);
    margin-bottom: 8px;
}
.discrete-swatch {
    flex: 1;
}

/* Entry list */
.compile-result .entry-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 2px 0;
}
.compile-result .color-swatch {
    width: 20px;
    height: 13px;
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,0.2);
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
}
.compile-result .color-swatch:hover {
    transform: scale(1.25);
    box-shadow: 0 0 0 2px var(--accent);
}
.compile-result .entry-value {
    color: var(--text-secondary);
    font-size: 11px;
    min-width: 50px;
}
.compile-result .entry-label {
    color: var(--text-dim);
    font-size: 10px;
}

/* --- Legend Preview Panel --- */
.legend-preview {
    display: none;
    background: rgba(0,0,0,0.3);
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 10px 14px;
    flex-shrink: 0;
}
.legend-preview.visible { display: block; }

.legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
}
.legend-layer-name {
    font-size: 10px;
    color: var(--accent);
    font-style: normal;
    text-transform: none;
    letter-spacing: 0;
    font-family: var(--font-mono);
}
.legend-img-wrap {
    display: flex;
    align-items: flex-start;
    min-height: 20px;
}
.legend-img {
    max-width: 100%;
    display: block;
    image-rendering: pixelated;
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,0.1);
}
.legend-na {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-sans);
}

/* --- Map Panel --- */
.map-panel { flex: 1; display: flex; flex-direction: column; }
#map { flex: 1; }

.map-toolbar {
    padding: 7px 12px;
    display: flex;
    gap: 8px;
    align-items: center;
    background: rgba(0,0,0,0.25);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}
.map-toolbar label {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}
.map-toolbar select {
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    border: 1px solid rgba(255,255,255,0.15);
    background: var(--bg-input);
    color: var(--text-primary);
    outline: none;
    cursor: pointer;
}
.map-toolbar .toolbar-sep {
    width: 1px;
    height: 18px;
    background: rgba(255,255,255,0.12);
    margin: 0 2px;
    flex-shrink: 0;
}
.map-toolbar .spacer { flex: 1; }
.map-toolbar .coord-info {
    font-size: 11px;
    color: var(--text-dim);
    font-family: var(--font-mono);
}

/* Opacity slider */
#opacitySlider {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
#opacitySlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.3);
}
#opacitySlider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}
.opacity-value {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    min-width: 32px;
}

/* --- Resizer --- */
.resizer {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.2s;
    flex-shrink: 0;
}
.resizer:hover, .resizer.active { background: var(--accent); }

/* --- Template Dropdown --- */
.template-dropdown {
    position: relative;
    display: inline-block;
}
.template-list {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 200;
    background: var(--bg-secondary);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: var(--radius-md);
    max-height: 340px;
    overflow-y: auto;
    display: none;
    min-width: 230px;
    box-shadow: var(--shadow-md);
    margin-top: 3px;
}
.template-list.visible { display: block; }

.template-group-label {
    padding: 6px 12px 4px;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    margin-top: 2px;
}
.template-group-label:first-child { margin-top: 0; }

.template-item {
    padding: 7px 12px;
    cursor: pointer;
    font-size: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: var(--text-primary);
}
.template-item:hover { background: rgba(59,130,246,0.15); }
.template-item:last-child { border-bottom: none; }

/* --- Color Picker Popover --- */
.color-picker-popover {
    position: fixed;
    z-index: 9000;
    background: #111827;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    min-width: 210px;
    display: none;
}
.color-picker-popover.visible { display: block; }
.color-picker-popover .cp-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    margin-bottom: 10px;
}
.color-picker-popover .cp-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.color-picker-popover input[type="color"] {
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: var(--radius-md);
    cursor: pointer;
    background: none;
    padding: 2px;
    flex-shrink: 0;
}
.color-picker-popover input[type="text"] {
    flex: 1;
    padding: 7px 10px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}
.color-picker-popover input[type="text"]:focus { border-color: var(--accent); }
.color-picker-popover .cp-preview {
    width: 100%;
    height: 24px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 10px;
    transition: background 0.1s;
}
.color-picker-popover .cp-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}
.color-picker-popover .cp-btn-cancel {
    padding: 5px 12px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font-sans);
}
.color-picker-popover .cp-btn-cancel:hover { background: rgba(255,255,255,0.1); }
.color-picker-popover .cp-btn-apply {
    padding: 5px 14px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-sans);
}
.color-picker-popover .cp-btn-apply:hover { background: var(--accent-hover); }

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    .sld-layout { flex-direction: column; }
    .editor-panel { width: 100% !important; min-width: 0; max-height: 50vh; }
    .resizer { display: none; }
    .map-panel { min-height: 300px; }
    #opacitySlider { width: 60px; }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
    .resizer { transition: none; }
}

/* --- Focus visible --- */
.toolbar button:focus-visible,
.toolbar select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
