/* ---
           Global styles (unchanged)
        --------------------------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    gap: 20px;
    padding: 20px;
}

.toolbar,
.sidepanel {
    width: 250px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
}

.sidepanel {
    width: 280px;
}

.canvas-container {
    flex: 1;
    position: relative;
    overflow: auto;
    padding: 20px;
    /* optional, gives space around canvas */
}


.canvas {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;


    /* Ensure size is applied */
    min-width: max-content;
    min-height: max-content;
}

/* Widgets --------------------------------------------------------- */
.widget {
    position: absolute;
    border: 2px solid transparent;
    cursor: move;
    transition: all 0.2s ease;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    word-wrap: break-word;
    text-overflow: ellipsis;
    user-select: none;
}

.widget:hover {
    transform: scale(1.02);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

.widget.selected {
    border-color: #00d4ff;
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.5);
}

.widget.resizing:hover {
    transform: none;
}

.widget.dragging {
    transition: none;
    z-index: 9999 !important;
}

/* Form & list helpers -------------------------------------------- */
.section {
    margin-bottom: 25px;
}

.section h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 16px;
    border-bottom: 2px solid #667eea;
    padding-bottom: 5px;
}

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

.control-group label {
    display: block;
    margin-bottom: 5px;
    color: #555;
    font-size: 14px;
    font-weight: 500;
}

.control-group input,
.control-group select,
.control-group button {
    width: 100%;
    padding: 10px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 14px;
    transition: all .2s;
}

.control-group textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 14px;
    transition: .2s;
    font-family: inherit;
    resize: vertical;
}

.control-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.2);
}

.btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: .2s;
    margin-bottom: 10px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, .4);
}

.btn:active {
    transform: translateY(0);
}

.btn.layer-btn {
    padding: 8px 16px;
    margin: 2px;
    font-size: 12px;
    min-width: auto;
    width: auto;
    display: inline-block;
}

.btn-danger {
    background-color: #dc3545;
    color: white;
    border-radius: 4px;
}

.color-input {
    height: 40px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.canvas-info {
    background: rgba(102, 126, 234, 0.1);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    border-left: 4px solid #667eea;
}

.widget-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    padding: 10px;
}

.widget-item {
    padding: 8px;
    margin-bottom: 5px;
    background: #f8f9fa;
    border-radius: 5px;
    cursor: pointer;
    transition: .2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.widget-item:hover {
    background: #e9ecef;
}

.widget-item.selected {
    background: #667eea;
    color: #fff;
}

.layer-controls {
    display: flex;
    gap: 5px;
    margin-top: 10px;
}

.layer-info {
    font-size: 12px;
    color: #666;
    margin-top: 5px;
}