:root {
    --bg-dark: #09090b;
    --bg-panel: #121214;
    --bg-surface: #18181b;
    --bg-card: #27272a;
    --border-color: #27272a;
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --danger: #ef4444;
    --success: #22c55e;
    --stale: #eab308;
    --glass-bg: rgba(18, 18, 20, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
}

/* Global Custom Scrollbar */
*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 10px;
    border: 2px solid transparent;
    /* Gives some spacing */
    background-clip: content-box;
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    overflow: hidden;
    width: 100vw;
}

/* Sidebar Styling */
.sidebar,
.property-panel {
    width: 280px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow-y: auto;
}

.sidebar.collapsed,
.property-panel.collapsed {
    width: 0 !important;
    padding: 0 !important;
    border: none !important;
    overflow: hidden;
}

.property-panel {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.sidebar-header,
.panel-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-primary);
}

.search-container {
    padding: 12px;
}

.palette-list {
    padding: 16px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    overflow-y: auto;
}

.palette-item {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: grab;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.palette-item:hover {
    border-color: var(--accent);
    background-color: var(--bg-card);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.palette-item svg {
    width: 32px;
    height: 32px;
    color: var(--text-primary);
    stroke-width: 1.5;
}

.palette-item span {
    font-size: 10px;
    font-weight: 500;
    text-align: center;
    color: var(--text-secondary);
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.main-content {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

#palette-search {
    background-color: var(--bg-panel);
    color: lime;
    width: 200px;
    height: 28px;
}

#palette-search:focus {
    outline: var(--bg-panel);
}

.toolbar {
    max-height: fit-content;
    background-color: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 0 16px;
    padding: 12px;
    gap: 8px;
    z-index: 20;
}

.btn {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn:hover {
    background-color: var(--bg-card);
    border-color: #3f3f46;
    transform: translateY(-1px);
}

.btn.primary {
    color: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

#btn-json {
    width: 100px;
}

.btn.primary:hover {
    color: var(--text-primary);
    background-color: var(--accent-hover);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.3);
}

.btn.danger {
    background-color: rgba(239, 68, 68, 0.05);
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.btn.danger:hover {
    background-color: rgba(239, 68, 68, 0.15);
    border-color: var(--danger);
}

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

.canvas-container {
    flex: 1;
    background-image:
        linear-gradient(to right, #1a1a1a 1px, transparent 1px),
        linear-gradient(to bottom, #1a1a1a 1px, transparent 1px);
    background-size: 40px 40px;
    background-color: #0b0b0b;
    position: relative;
    overflow: auto;
    /* Specifically scrollable area */
}

#sld-canvas {
    width: 2400px;
    height: 2400px;
    background-color: transparent;
    display: block;
    transform-origin: top left;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 16px;
    padding: 0 12px;
    border-right: 1px solid var(--border-color);
}

#zoom-level {
    font-size: 13px;
    min-width: 45px;
    text-align: center;
    color: var(--text-secondary);
}

/* Property Panel */
.prop-section {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.prop-section label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.prop-section input,
.prop-section select {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px;
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 13px;
}

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

.prop-section input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    margin-top: 8px;
    border: none;
}

.prop-section input[type="range"]::-webkit-slider-runnable-track {
    background: var(--bg-card);
    height: 6px;
    border-radius: 3px;
}

.prop-section input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: -5px;
    transition: transform 0.1s ease;
}

.prop-section input[type="range"]:active::-webkit-slider-thumb {
    transform: scale(1.2);
}

.placeholder-list {
    margin-top: 8px;
}

.placeholder-item {
    font-size: 11px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
}

/* SVG Rendering Styles */
.node-group {
    cursor: grab;
}

.node-group:active {
    cursor: grabbing;
}

/* 
.node-group>rect.bounds {
    fill: #0b0b0b;
} */

.node-group.selected>rect.bounds {
    stroke: var(--accent);
    stroke-width: 2;
    stroke-dasharray: 4, 4;
}

/* The actual element sizing and defaults */
.node-symbol {
    color: var(--text-primary);
    stroke: currentColor;
}

.node-symbol * {
    fill: #0b0b0b;
    vector-effect: non-scaling-stroke;
}

.node-symbol text {
    fill: white;
}

.node-symbol line.transparent {
    fill: transparent !important;
}

.slot-text {
    font-size: 12px;
    fill: var(--text-primary);
    font-family: inherit;
    pointer-events: none;
    font-weight: 500;
}

.slot-bg {
    fill: rgba(0, 0, 0, 0.8);
    rx: 4;
}

.connection-line {
    fill: none;
    stroke: var(--text-secondary);
    stroke-width: 2;
    cursor: pointer;
    transition: stroke 0.2s, stroke-width 0.2s;
}

.connection-line:hover {
    stroke: var(--text-primary);
    stroke-width: 3;
}

.connection-line.selected {
    stroke: var(--accent);
    stroke-width: 3;
}

.tracer-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-dasharray: 6, 4;
    pointer-events: none;
}

.interactive-layer {
    pointer-events: all;
}

/* Status dots */
.status-indicator {
    transition: fill 0.3s ease;
}

.status-indicator.blink {
    animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
    0% {
        fill: var(--danger);
        opacity: 1;
    }

    50% {
        opacity: 0.2;
    }

    100% {
        fill: var(--danger);
        opacity: 1;
    }
}

/* Modal / JSON Preview */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 600px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

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

#json-export-preview {
    margin: 0;
    padding: 20px;
    background: var(--bg-dark);
    color: var(--success);
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    overflow: auto;
    flex: 1;
}
/* Rotation Grid */
.rotation-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}
.rot-input {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.rot-input small {
    font-size: 10px;
    color: var(--text-secondary);
}
.rot-input input {
    margin-bottom: 0 !important;
}
/* Sidebar Toggles */
.sidebar-toggle-left,
.sidebar-toggle-right {
    position: fixed;
    bottom: 20px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.sidebar-toggle-left:hover,
.sidebar-toggle-right:hover {
    background: var(--bg-card);
    border-color: var(--accent);
}

.sidebar-toggle-left { left: 16px; }
.sidebar-toggle-right { right: 16px; }

/* Responsive Media Queries */
@media (max-width: 1024px) {
    .sidebar, .property-panel {
        width: 240px;
    }
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .sidebar, .property-panel {
        width: 100%;
        height: auto;
        max-height: 300px;
        order: 2;
    }

    .main-content {
        order: 1;
        height: 50vh;
    }

    .toolbar {
        overflow-x: auto;
        white-space: nowrap;
        flex-wrap: nowrap;
        justify-content: flex-start;
        padding-bottom: 8px;
    }

    .zoom-controls {
        padding: 0 4px;
        border: none;
    }

    .sidebar-toggle-left,
    .sidebar-toggle-right {
        display: none;
    }
    
    .sidebar.collapsed,
    .property-panel.collapsed {
        height: 0 !important;
        max-height: 0 !important;
    }
}
